Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit 1c5e7a6

Browse files
committed
Game Update 7.3 support
1 parent 2c74217 commit 1c5e7a6

File tree

4 files changed

+98
-46
lines changed

4 files changed

+98
-46
lines changed

libs/anno-api/src/random_game_functions.cc

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,63 @@ bool FindAddresses()
8181
initialized = true;
8282

8383
ADDRESSES[GET_CONTAINER_BLOCK_INFO] = {[](std::optional<std::string_view> game_file) {
84-
auto match = meow_hook::pattern(
85-
"48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 20 48 83 79 78 00 44 89 C6",
86-
game_file)
87-
.count(1)
88-
.get(0)
89-
.as<uintptr_t>();
84+
try {
85+
auto match =
86+
meow_hook::pattern(
87+
"48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 20 48 83 79 78 00 44 89 C6",
88+
game_file)
89+
.count(1)
90+
.get(0)
91+
.as<uintptr_t>();
92+
if (game_file) {
93+
return RebaseFileOffsetToMemoryAddess(
94+
match - reinterpret_cast<intptr_t>(game_file->data()));
95+
}
96+
return match;
97+
} catch (...) {
98+
}
99+
100+
// Game Update 7.3
101+
try {
102+
auto match = meow_hook::pattern("E8 ? ? ? ? 84 C0 75 7C", game_file)
103+
.count(1)
104+
.get(0);
105+
if (game_file) {
106+
match = match.adjust(
107+
RebaseFileOffsetToMemoryAddess(
108+
match.as<uintptr_t>() - reinterpret_cast<intptr_t>(game_file->data()))
109+
- match.as<uintptr_t>());
110+
}
111+
return match.extract_call();
112+
} catch (...) { }
113+
114+
try {
115+
auto match =
116+
meow_hook::pattern("E8 ? ? ? ? 84 C0 0F 84 ? ? ? ? F7 85 ? ? ? ? ? ? ? ?", game_file).count(1).get(0);
117+
if (game_file) {
118+
match = match.adjust(
119+
RebaseFileOffsetToMemoryAddess(
120+
match.as<uintptr_t>() - reinterpret_cast<intptr_t>(game_file->data()))
121+
- match.as<uintptr_t>());
122+
}
123+
return match.extract_call();
124+
} catch (...) {
125+
}
126+
127+
// If this fails, we dead
128+
auto match =
129+
meow_hook::pattern(
130+
"48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 20 48 83 79 78 00",
131+
game_file)
132+
.count(1)
133+
.get(0)
134+
.as<uintptr_t>();
90135
if (game_file) {
91136
return RebaseFileOffsetToMemoryAddess(
92137
match - reinterpret_cast<intptr_t>(game_file->data()));
93138
}
94139
return match;
140+
95141
}}; //
96142

97143
ADDRESSES[READ_FILE_FROM_CONTAINER] = {[](std::optional<std::string_view> game_file) {

libs/python35/src/main.cc

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,16 @@ static std::string GetLatestVersion()
9292
return data;
9393
}
9494

95+
static std::once_flag hooking_once_flag;
9596
static bool checked_hooking = false;
9697
HANDLE CreateFileW_S(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
9798
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
9899
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
99100
{
100101
if (!checked_hooking && std::wstring(lpFileName).find(L"maindata/file.db") != std::string::npos) {
101102
checked_hooking = true;
102-
static std::once_flag flag1;
103-
std::call_once(flag1, []() { events.DoHooking(); });
103+
104+
std::call_once(hooking_once_flag, []() { events.DoHooking(); });
104105
}
105106
return CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes,
106107
dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
@@ -126,7 +127,7 @@ FARPROC GetProcAddress_S(HMODULE hModule, LPCSTR lpProcName)
126127
// those would have usually been in the import table.
127128
// This means we are ready to do some hooking
128129
// But only do hooking once.
129-
130+
std::call_once(hooking_once_flag, []() { events.DoHooking(); });
130131

131132
if ((uintptr_t)lpProcName > 0x1000) {
132133
if (lpProcName == std::string("CreateFileW")) {
@@ -247,6 +248,43 @@ HANDLE GetParentProcess()
247248
return OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, ProcessEntry.th32ParentProcessID);
248249
}
249250

251+
static void CheckVersion()
252+
{
253+
// Version Check
254+
try {
255+
auto body = GetLatestVersion();
256+
const auto& data = nlohmann::json::parse(body);
257+
const auto& version_str = data["version"].get<std::string>();
258+
259+
static int32_t current_version[3] = {VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION};
260+
261+
int32_t latest_version[3] = {0};
262+
std::sscanf(version_str.c_str(), "%d.%d.%d", &latest_version[0], &latest_version[1],
263+
&latest_version[2]);
264+
265+
if (std::lexicographical_compare(current_version, current_version + 3, latest_version,
266+
latest_version + 3)) {
267+
std::string msg = "Verion " + version_str + " of " + VER_FILE_DESCRIPTION_STR
268+
+ " is available for download.\n\n";
269+
msg.append("Do you want to go to the release page on GitHub?\n(THIS IS "
270+
"HIGHLY RECOMMENDED!!!)");
271+
272+
if (MessageBoxA(NULL, msg.c_str(), VER_FILE_DESCRIPTION_STR,
273+
MB_ICONQUESTION | MB_YESNO | MB_SYSTEMMODAL)
274+
== IDYES) {
275+
auto result =
276+
ShellExecuteA(nullptr, "open",
277+
"https://github.com/xforce/anno1800-mod-loader/releases/latest",
278+
nullptr, nullptr, SW_SHOWNORMAL);
279+
result = result;
280+
TerminateProcess(GetCurrentProcess(), 0);
281+
}
282+
}
283+
} catch (...) {
284+
// TODO(alexander): Logging
285+
}
286+
}
287+
250288
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
251289
{
252290
switch (ul_reason_for_call) {
@@ -302,8 +340,9 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
302340
}
303341
}
304342

305-
// Version Check
306343
events.DoHooking.connect([]() {
344+
CheckVersion();
345+
307346
// Let's start loading the list of files we want to have
308347
HMODULE module;
309348
if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
@@ -343,40 +382,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
343382
return;
344383
}
345384

346-
try {
347-
auto body = GetLatestVersion();
348-
const auto& data = nlohmann::json::parse(body);
349-
const auto& version_str = data["version"].get<std::string>();
350-
351-
static int32_t current_version[3] = {VERSION_MAJOR, VERSION_MINOR,
352-
VERSION_REVISION};
353-
354-
int32_t latest_version[3] = {0};
355-
std::sscanf(version_str.c_str(), "%d.%d.%d", &latest_version[0],
356-
&latest_version[1], &latest_version[2]);
357-
358-
if (std::lexicographical_compare(current_version, current_version + 3,
359-
latest_version, latest_version + 3)) {
360-
std::string msg = "Verion " + version_str + " of "
361-
+ VER_FILE_DESCRIPTION_STR
362-
+ " is available for download.\n\n";
363-
msg.append("Do you want to go to the release page on GitHub?\n(THIS IS "
364-
"HIGHLY RECOMMENDED!!!)");
365-
366-
if (MessageBoxA(NULL, msg.c_str(), VER_FILE_DESCRIPTION_STR,
367-
MB_ICONQUESTION | MB_YESNO | MB_SYSTEMMODAL)
368-
== IDYES) {
369-
auto result = ShellExecuteA(
370-
nullptr, "open",
371-
"https://github.com/xforce/anno1800-mod-loader/releases/latest",
372-
nullptr, nullptr, SW_SHOWNORMAL);
373-
result = result;
374-
TerminateProcess(GetCurrentProcess(), 0);
375-
}
376-
}
377-
} catch (...) {
378-
// TODO(alexander): Logging
379-
}
385+
380386
});
381387

382388
EnableExtenalFileLoading(events);

libs/python35/src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// clang-format off
44
#define VERSION_MAJOR 0
55
#define VERSION_MINOR 7
6-
#define VERSION_REVISION 7
6+
#define VERSION_REVISION 8
77

88
#define STRINGIFY_(s) #s
99
#define STRINGIFY(s) STRINGIFY_(s)

third_party/meow-hook

0 commit comments

Comments
 (0)