Skip to content

Commit fe1f285

Browse files
committed
No longer call LoadLibraryA from WinMain
1 parent d9a459a commit fe1f285

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ add_library(ZLIB::ZLIB ALIAS zlibstatic)
119119
SET(BUILD_SHARED_LIBS OFF)
120120
SET(LIBZIP_DO_INSTALL OFF)
121121
SET(ENABLE_COMMONCRYPTO OFF)
122-
SET(ENABLE_GNUTLS OFF)
123122
SET(ENABLE_OPENSSL OFF)
124123
SET(ENABLE_WINDOWS_CRYPTO OFF)
125124
SET(ENABLE_BZIP2 OFF)
@@ -130,8 +129,8 @@ SET(LIBZIP_DO_INSTALL OFF)
130129
SET(ZLIB_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/zlib")
131130
SET(ZLIB_LIBRARY "${CMAKE_SOURCE_DIR}/zlib")
132131
add_subdirectory(libzip)
133-
add_dependencies(zip zlibstatic)
134-
target_include_directories(zip PRIVATE ${ZLIB_INCLUDE_DIR})
132+
#add_dependencies(zip zlibstatic)
133+
#target_include_directories(zip PRIVATE ${ZLIB_INCLUDE_DIR})
135134

136135
# detours
137136

swrstoys/SWRSToys.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "SWRSToys.h"
1515

1616
#define CRenderer_Unknown1 ((void (__thiscall *)(int, int))0x404AF0)
17-
#define REAL_VERSION_STR "alpha 0.3.1"
17+
#define REAL_VERSION_STR "alpha 0.4.1"
1818
#ifdef _NOTEX
1919
#define MOD_REAL_VERSION_STR REAL_VERSION_STR " no texture"
2020
#else
@@ -101,7 +101,7 @@ LONG WINAPI UnhandledExFilter(PEXCEPTION_POINTERS ExPtr)
101101
}
102102
printf("%S\n", buf);
103103
MessageBoxW(nullptr, buf, L"Fatal Error", MB_ICONERROR);
104-
exit(ExPtr->ExceptionRecord->ExceptionCode);
104+
return EXCEPTION_CONTINUE_SEARCH;
105105
}
106106

107107
void loadAssets()
@@ -111,7 +111,6 @@ void loadAssets()
111111
loaded = true;
112112
SokuLib::FontDescription desc;
113113

114-
SetUnhandledExceptionFilter(UnhandledExFilter);
115114
puts("Placed exception handler!");
116115
desc.r1 = 255;
117116
desc.r2 = 255;
@@ -545,6 +544,13 @@ int __fastcall myTitleOnRender(SokuLib::Title *This)
545544
return ret;
546545
}
547546

547+
void trapDebugger(bool b)
548+
{
549+
if (!b)
550+
return;
551+
DebugBreak();
552+
}
553+
548554
bool Hook(HMODULE this_module)
549555
{
550556
#ifdef _DEBUG
@@ -573,6 +579,13 @@ bool Hook(HMODULE this_module)
573579
puts("Loading settings file");
574580
loadSettings(gameHash, this_module);
575581
puts("Placing hooks");
582+
SetUnhandledExceptionFilter(UnhandledExFilter);
583+
VirtualProtect((PVOID)TEXT_SECTION_OFFSET, TEXT_SECTION_SIZE, PAGE_EXECUTE_WRITECOPY, &old);
584+
*(char *)0x81FF00 = 0x90;
585+
*(char *)0x81FF01 = 0x50;
586+
*(char *)0x81FF04 = 0x90;
587+
SokuLib::TamperNearCall(0x81FF05, trapDebugger);
588+
VirtualProtect((PVOID)TEXT_SECTION_OFFSET, TEXT_SECTION_SIZE, old, &old);
576589
VirtualProtect((PVOID)RDATA_SECTION_OFFSET, RDATA_SECTION_SIZE, PAGE_EXECUTE_WRITECOPY, &old);
577590
ogTitleOnProcess = SokuLib::TamperDword(&SokuLib::VTable_Title.onProcess, myTitleOnProcess);
578591
ogTitleOnRender = SokuLib::TamperDword(&SokuLib::VTable_Title.onRender, myTitleOnRender);

swrstoys/dummy.cpp

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "dummy.h"
22

33
#include <Windows.h>
4+
#include <SokuLib.hpp>
45
#include "SWRSToys.h"
56

67
FARPROC p_Direct3DShaderValidatorCreate9 = NULL;
@@ -19,11 +20,23 @@ FARPROC p_Direct3DCreate9 = NULL;
1920
FARPROC p_Direct3DCreate9Ex = NULL;
2021

2122
HMODULE orig_module = NULL;
23+
HMODULE this_module = NULL;
2224

23-
BOOL APIENTRY DllMain(HMODULE this_module, DWORD ul_reason_for_call, LPVOID) {
25+
int (*ogSokuMain)(int a, int b, int c, int d);
26+
27+
int SokuMain(int a, int b, int c, int d)
28+
{
29+
Hook(this_module);
30+
return ogSokuMain(a, b, c, d);
31+
}
32+
33+
BOOL APIENTRY DllMain(HMODULE this_module_, DWORD ul_reason_for_call, LPVOID) {
2434
switch (ul_reason_for_call) {
2535
case DLL_PROCESS_ATTACH: {
2636
wchar_t sys_dir[MAX_PATH];
37+
DWORD old;
38+
39+
this_module = this_module_;
2740
if (FALSE == ::GetSystemDirectoryW(sys_dir, MAX_PATH)) {
2841
return FALSE;
2942
}
@@ -48,9 +61,9 @@ BOOL APIENTRY DllMain(HMODULE this_module, DWORD ul_reason_for_call, LPVOID) {
4861
p_Direct3DCreate9 = ::GetProcAddress(orig_module, "Direct3DCreate9");
4962
p_Direct3DCreate9Ex = ::GetProcAddress(orig_module, "Direct3DCreate9Ex");
5063

51-
if (!Hook(this_module)) {
52-
return FALSE;
53-
}
64+
VirtualProtect((PVOID)TEXT_SECTION_OFFSET, TEXT_SECTION_SIZE, PAGE_EXECUTE_WRITECOPY, &old);
65+
ogSokuMain = SokuLib::TamperNearJmpOpr(0x821844, SokuMain);
66+
VirtualProtect((PVOID)TEXT_SECTION_OFFSET, TEXT_SECTION_SIZE, old, &old);
5467
break;
5568
}
5669
case DLL_THREAD_ATTACH:

0 commit comments

Comments
 (0)