Skip to content

Commit

Permalink
Print more information during launch and update readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikuAuahDark committed Jul 26, 2024
1 parent 3abdb50 commit 7a8a7cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Put `libcs2djit.so` and `cs2djit.sh` to your CS2D server directory.
Or just use CMake to compile it.

```sh
CFLAGS=-m32 cmake -Bbuild -H. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install
CFLAGS=-m32 cmake -Bbuild -S. -DCMAKE_BUILD_TYPE=Release --install-prefix $PWD/install
cmake --build build --target install
```

Expand All @@ -70,7 +70,7 @@ LuaJIT itself. Refer to [LuaJIT page](https://luajit.org/install.html#cross) on
```sh
# Assume environment variable LUAJIT_DIR is location where the LuaJIT include and resulting libraries are
# and $PWD = current repository:
cmake -DCMAKE_TOOLCHAIN_FILE=cmake/mingw-w64.cmake -Bbuild -H. -DCMAKE_INSTALL_PREFIX=$PWD/install -DCMAKE_BUILD_TYPE=Release
cmake -DCMAKE_TOOLCHAIN_FILE=cmake/mingw-w64.cmake -Bbuild -S. --install-prefix $PWD/install -DCMAKE_BUILD_TYPE=Release
cmake --build build --target install
```

Expand All @@ -85,7 +85,7 @@ and any _funny_ problems caused by it can't (and won't) be fixed.
```cmd
rem Assume you have Visual Studio toolchain, and environment variable LUAJIT_DIR is location where the
rem LuaJIT include and resulting libraries are, plus %CD% = current repository:
cmake -Bbuild -H. -DCMAKE_INSTALL_PREFIX=%CD%/install
cmake -Bbuild -S. --install-prefix %CD%/install
cmake --build build --config Release --target install
```

Expand Down
23 changes: 16 additions & 7 deletions src/cs2djitwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ BOOL APIENTRY DllMain(HINSTANCE _, DWORD reason, LPVOID __)

if (GetModuleFileNameW(NULL, moduleName, 32767) == 0)
{
result = (int) GetLastError();
free(moduleName);
fprintf(stderr, "GetModuleFileNameW failed: %d\n", result);
return 0;
}

/* Open executable */
fileExe = _wfopen(moduleName, L"rb");
free(moduleName);
if (fileExe == NULL)
{
fwprintf(stderr, "_wfopen failed for %ls\n", moduleName);
free(moduleName);
return 0;
}
free(moduleName);

/* Init */
result = cs2djit_init((size_t) GetModuleHandleA(NULL), fileExe);
Expand All @@ -68,11 +74,9 @@ BOOL APIENTRY DllMain(HINSTANCE _, DWORD reason, LPVOID __)

#else

static wchar_t g_TempBuffer[32768]; /* uh */

int main(int argc, char* argv[])
{
wchar_t *lastSlash, *dedicatedFile = NULL, *currentDir = NULL;
wchar_t *lastSlash, *dedicatedFile = NULL, *currentDir = NULL, g_TempBuffer;
void *otherProcMem = NULL, *loadLibrary;
size_t dedicatedLen, dirLen;
HANDLE dedicated = INVALID_HANDLE_VALUE;
Expand All @@ -81,6 +85,10 @@ int main(int argc, char* argv[])
STARTUPINFOW startupInfo;
PROCESS_INFORMATION processInfo;

g_TempBuffer = calloc(32768, sizeof(wchar_t));
if (g_TempBuffer == NULL)
return 1;

/* Windows API UTF-16 is bad */
memset(g_TempBuffer, 0, 32768 * sizeof(wchar_t));
if (GetModuleFileNameW(NULL, g_TempBuffer, 32767) == 0)
Expand Down Expand Up @@ -136,7 +144,6 @@ int main(int argc, char* argv[])
&processInfo /* lpProcessInformation */
) == 0)
{
// fputs("Failed to start cs2d_dedicated.exe", stderr);
fprintf(stderr, "Failed to start cs2d_dedicated.exe: %d\n", (int) GetLastError());
free(currentDir);
free(dedicatedFile);
Expand Down Expand Up @@ -169,11 +176,13 @@ int main(int argc, char* argv[])
return 1;
}

/* Start process */
/* TODO: Handle Ctrl+C and pass it to cs2d_dedicated */
/* Wait for inject to finish */
WaitForSingleObject(otherThread, INFINITE);
CloseHandle(otherThread);
VirtualFreeEx(processInfo.hProcess, otherProcMem, 1024, MEM_RELEASE);

/* Start process */
/* TODO: Handle Ctrl+C and pass it to cs2d_dedicated */
ResumeThread(processInfo.hThread);
WaitForSingleObject(processInfo.hProcess, INFINITE);

Expand Down

0 comments on commit 7a8a7cb

Please sign in to comment.