Skip to content

Commit 2a4a8da

Browse files
committed
优化用户使用便携性
1 parent dcedfc0 commit 2a4a8da

File tree

11 files changed

+69
-141
lines changed

11 files changed

+69
-141
lines changed

dependencies/IsaacBoxUtility.exe

-512 Bytes
Binary file not shown.

dependencies/isaac_box/main.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
WEBSOCKET_PORT = 58869
2-
VERSION = "0.3.1"
2+
VERSION = "0.3.2"
33
Mod = RegisterMod("IsaacBox", 1)
44
local callbacks = require("modules.callbacks")
55

dependencies/isaac_box/metadata.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<name>IsaacBox(auto installed)</name>
33
<directory>isaac_box</directory>
44
<description />
5-
<version>0.3.1</version>
5+
<version>0.3.2</version>
66
<visibility />
77
</metadata>

dependencies/isaac_box/modules/callbacks.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
local websocket = require("modules.websocket")
22
local bridge = require("modules.bridge")
33
local font = Font()
4-
local green = KColor(0, 1, 0, 1)
5-
local white = KColor(1, 1, 1, 1)
64
font:Load("font/cjk/lanapixel.fnt")
75

86
local function onPostRender()
97
if IsaacSocket == nil or not IsaacSocket.IsConnected() then
108
-- 因为IsaacSocket已经做了提示,故无需提示。
119
elseif websocket.state.connecting then
12-
font:DrawStringScaledUTF8("[IsaacBox]正在尝试连接...如果失败请检查IsaacBox是否已经开启", 2, 28, 0.5,
13-
0.5,
14-
green, 0, false)
10+
-- 静悄悄地,不要告诉用户,不然扎眼
1511
elseif not websocket.state.ready then
1612
websocket.init(WEBSOCKET_PORT)
1713
else
18-
font:DrawStringScaledUTF8("[IsaacBox] Version:" .. (VERSION), 216, 0, 0.5,
19-
0.5,
20-
white, 0, false)
14+
if not websocket.state.shown then
15+
local game = Game()
16+
local hud = game:GetHUD()
17+
hud:ShowItemText("IsaacBox", "Version:" .. VERSION)
18+
print("IsaacBox Version:" .. VERSION)
19+
websocket.state.shown = true
20+
end
2121
if bridge.UpdateAllCollectibles() then
2222
websocket.emit("OFFER_ITEMS", require("json").encode(Items))
2323
end

dependencies/isaac_box/modules/websocket.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
local state = {
22
connection = nil,
33
ready = false,
4-
connecting = false
4+
connecting = false,
5+
shown = false
56
}
67

78
local function emit(topic, message)
@@ -45,17 +46,17 @@ local function callbackOnMessage(messageReceieved, isBinary)
4546
end
4647

4748
local function callbackOnClose(closeStatus, statusDescription)
48-
-- print("Websocket connection closed: ", closeStatus, statusDescription)
4949
state.connection = nil
5050
state.ready = false
5151
state.connecting = false
52+
state.shown = false
5253
end
5354

5455
local function callbackOnError(message)
55-
-- print("Websocket connection error: ", message)
5656
state.connection = nil
5757
state.ready = false
5858
state.connecting = false
59+
state.shown = false
5960
end
6061

6162
local function init(port)

env.js

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const parseString = promisify(require('xml2js').parseString);
66

77
const ISAAC_BOX_MOD_DIRNAME = "isaac_box"
88
const ISAAC_BOX_MOD_NAME = "IsaacBox(auto installed)"
9-
const TARGET_ISAAC_BOX_MOD_VERSION = "0.3.1"
9+
const TARGET_ISAAC_BOX_MOD_VERSION = "0.3.2"
1010

1111
const ISAAC_SOCKET_MOD_DIRNAME = "isaac_socket"
1212
const ISAAC_SOCKET_OFFICIAL_MOD_NAME = "IsaacSocket"
@@ -138,40 +138,6 @@ const getGameDirectorySync = () => {
138138
})
139139
}
140140

141-
/**
142-
* Waits for the game to launch.
143-
*
144-
* @return {Promise} A promise that resolves when the game launches.
145-
* Rejects with an error if there was an error launching the game.
146-
*/
147-
const waitForGameLaunch = () => {
148-
return new Promise((resolve, reject) => {
149-
cp.execFile("./dependencies/IsaacBoxUtility.exe", ['-W'], (error) => {
150-
if (!error) {
151-
resolve();
152-
}
153-
reject(error)
154-
})
155-
})
156-
}
157-
158-
/**
159-
* Kills the game process.
160-
*
161-
* @return {Promise} A promise that resolves when the game process is killed, or rejects with an error if there was an error killing the process.
162-
*/
163-
const killGameProcess = () => {
164-
return new Promise((resolve, reject) => {
165-
cp.execFile("./dependencies/IsaacBoxUtility.exe", ['-K'], (error, stdout, stderr) => {
166-
if (!error) {
167-
resolve();
168-
}
169-
reject(error)
170-
})
171-
})
172-
}
173-
174-
175141
const openIsaacSocketUtility = () => {
176142
return new Promise((resolve,reject)=>{
177143
if(!fs.existsSync("./dependencies/IsaacSocketUtility/IsaacSocket.exe")){
@@ -192,7 +158,5 @@ module.exports = {
192158
getRequiredModsVersionInfo,
193159
patchMods,
194160
getGameDirectorySync,
195-
waitForGameLaunch,
196-
killGameProcess,
197161
openIsaacSocketUtility
198162
}

exsrc/IsaacBoxUtility.cpp

Lines changed: 49 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -9,98 +9,64 @@ char exePath[MAX_PATH];
99
DWORD GetGameProcessId();
1010
bool GetGameDirectory();
1111
void PrintGameDirectorySync();
12-
void KillGameProcess();
13-
void WaitForGameLaunch();
1412

15-
16-
int main(int argc, char* argv[])
13+
int main()
1714
{
18-
if (argc <= 1)
19-
{
20-
return -1;
21-
}
22-
char* arg = argv[1];
23-
if (strcmp(arg, "-D") == 0) {
24-
PrintGameDirectorySync();
25-
}
26-
else if (strcmp(arg, "-K") == 0) {
27-
KillGameProcess();
28-
}
29-
else if (strcmp(arg, "-W") == 0) {
30-
WaitForGameLaunch();
31-
}
32-
return 0;
15+
PrintGameDirectorySync();
16+
return 0;
3317
}
3418

35-
bool GetGameDirectory() {
36-
DWORD gamePID = GetGameProcessId();
37-
if (gamePID != 0) {
38-
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, gamePID);
39-
if (hProcess == NULL) {
40-
return false;
41-
}
42-
memset(exePath,0,sizeof(exePath));
43-
DWORD result = GetModuleFileNameExA(hProcess, NULL, exePath, MAX_PATH);
44-
CloseHandle(hProcess);
45-
return result != 0;
19+
bool GetGameDirectory()
20+
{
21+
DWORD gamePID = GetGameProcessId();
22+
if (gamePID != 0)
23+
{
24+
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, gamePID);
25+
if (hProcess == NULL)
26+
{
27+
return false;
4628
}
47-
return false;
29+
memset(exePath, 0, sizeof(exePath));
30+
DWORD result = GetModuleFileNameExA(hProcess, NULL, exePath, MAX_PATH);
31+
CloseHandle(hProcess);
32+
return result != 0;
33+
}
34+
return false;
4835
}
4936

50-
void PrintGameDirectorySync() {
51-
for (;;) {
52-
if (GetGameDirectory()) {
53-
printf("%s", exePath);
54-
break;
55-
}
56-
Sleep(1000);
37+
void PrintGameDirectorySync()
38+
{
39+
for (;;)
40+
{
41+
if (GetGameDirectory())
42+
{
43+
printf("%s", exePath);
44+
break;
5745
}
46+
Sleep(1000);
47+
}
5848
}
5949

60-
void WaitForGameLaunch() {
61-
for (;;) {
62-
if (GetGameProcessId()!=0) {
63-
break;
50+
DWORD GetGameProcessId()
51+
{
52+
DWORD processId = 0;
53+
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
54+
if (snapshot != INVALID_HANDLE_VALUE)
55+
{
56+
PROCESSENTRY32 processEntry;
57+
processEntry.dwSize = sizeof(PROCESSENTRY32);
58+
if (Process32First(snapshot, &processEntry))
59+
{
60+
do
61+
{
62+
if (wcscmp(processEntry.szExeFile, GAME_FILE_NAME) == 0)
63+
{
64+
processId = processEntry.th32ProcessID;
65+
break;
6466
}
65-
Sleep(1000);
66-
}
67-
}
68-
69-
DWORD GetGameProcessId() {
70-
DWORD processId = 0;
71-
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
72-
if (snapshot != INVALID_HANDLE_VALUE) {
73-
PROCESSENTRY32 processEntry;
74-
processEntry.dwSize = sizeof(PROCESSENTRY32);
75-
if (Process32First(snapshot, &processEntry)) {
76-
do {
77-
if (wcscmp(processEntry.szExeFile, GAME_FILE_NAME) == 0) {
78-
processId = processEntry.th32ProcessID;
79-
break;
80-
}
81-
} while (Process32Next(snapshot, &processEntry));
82-
}
83-
CloseHandle(snapshot);
84-
}
85-
return processId;
86-
}
87-
88-
void KillGameProcess() {
89-
// 获取游戏进程的PID
90-
DWORD gamePID = GetGameProcessId();
91-
if (gamePID == 0) {
92-
return;
67+
} while (Process32Next(snapshot, &processEntry));
9368
}
94-
95-
// 打开游戏进程
96-
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, gamePID);
97-
if (hProcess == NULL) {
98-
return;
99-
}
100-
101-
// 终止游戏进程
102-
TerminateProcess(hProcess, 0);
103-
104-
// 关闭进程句柄
105-
CloseHandle(hProcess);
106-
}
69+
CloseHandle(snapshot);
70+
}
71+
return processId;
72+
}

main.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const { getAllModsMetadata,
77
getRequiredModsVersionInfo,
88
patchMods,
99
getGameDirectorySync,
10-
// waitForGameLaunch,
11-
killGameProcess,
1210
openIsaacSocketUtility } = require("./env");
1311

1412
let win;
@@ -111,11 +109,10 @@ const isPortTaken = (port) => {
111109
try {
112110
isPatched = await patchMods(gameDir, requiredMods)
113111
if (isPatched) {
114-
await killGameProcess();
115112
dialog.showMessageBox({
116113
title: "提示",
117114
type: "info",
118-
message: "所需MOD已经为您安装完成,请您手动重新启动游戏"
115+
message: "所需MOD已经为您安装/更新完成,请您手动重新启动游戏"
119116
})
120117
}
121118
} catch (e) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "isaac-box",
33
"private": true,
4-
"version": "0.3.1",
4+
"version": "0.3.2",
55
"main": "main.js",
66
"author": "NOTF-API",
77
"description": "Isaac's Console Client based on IsaacSocket",

0 commit comments

Comments
 (0)