Skip to content

Commit afda4d5

Browse files
committed
Fix compatibility with new mods which use the C runtime of soku
This commit lets mods be loaded after the C runtime is initialized but before other static objects of soku are constructed. - Soku2 probably hooks constructors of static objects of soku. So it is too late to load Soku2 after these constructors are called. - Some new mods depend on the C runtime of soku. So they should be loaded after the C runtime of soku is initialized. `SetUnhandledExceptionFilter` is now called before mods are loaded, so that mods can easily get the unhandled exception filter of SWRSToys and set their own ones when being initialized.
1 parent a40e3b1 commit afda4d5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

swrstoys/dummy.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ FARPROC p_Direct3DCreate9Ex = NULL;
2525
HMODULE orig_module = NULL;
2626
HMODULE this_module = NULL;
2727

28-
int (*ogSecurityInitCookie)();
28+
typedef int (*PIFV)(void);
29+
int (*ogInittermE)(PIFV* start, PIFV* end);
2930
int (*ogSokuMain)(int a, int b, int c, int d);
3031

3132
LONG WINAPI UnhandledExFilter(PEXCEPTION_POINTERS ExPtr)
@@ -82,14 +83,18 @@ LONG WINAPI UnhandledExFilter(PEXCEPTION_POINTERS ExPtr)
8283

8384
int SokuMain(int a, int b, int c, int d)
8485
{
85-
SetUnhandledExceptionFilter(UnhandledExFilter);
8686
return ogSokuMain(a, b, c, d);
8787
}
8888

89-
int mySecurityInitCookie()
89+
int myInittermE(PIFV* start, PIFV* end)
9090
{
91-
Hook(this_module);
92-
return ogSecurityInitCookie();
91+
int ret = ogInittermE(start, end);
92+
if (ret == 0) {
93+
// if initialize successfully
94+
SetUnhandledExceptionFilter(UnhandledExFilter);
95+
Hook(this_module);
96+
}
97+
return ret;
9398
}
9499

95100
BOOL APIENTRY DllMain(HMODULE this_module_, DWORD ul_reason_for_call, LPVOID) {
@@ -125,7 +130,7 @@ BOOL APIENTRY DllMain(HMODULE this_module_, DWORD ul_reason_for_call, LPVOID) {
125130

126131
VirtualProtect((PVOID)TEXT_SECTION_OFFSET, TEXT_SECTION_SIZE, PAGE_EXECUTE_WRITECOPY, &old);
127132
ogSokuMain = SokuLib::TamperNearJmpOpr(0x821844, SokuMain);
128-
ogSecurityInitCookie = SokuLib::TamperNearJmpOpr(0x8218b2, mySecurityInitCookie);
133+
ogInittermE = SokuLib::TamperNearJmpOpr(0x8240b3, myInittermE);
129134
VirtualProtect((PVOID)TEXT_SECTION_OFFSET, TEXT_SECTION_SIZE, old, &old);
130135
break;
131136
}

0 commit comments

Comments
 (0)