Skip to content

Commit caf8cd3

Browse files
Fix even more string array crashes.
1 parent 69df3df commit caf8cd3

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

Source/DivaModLoader/DatabaseLoader.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,17 @@ HOOK(void, __fastcall, LoadStrArray, sigLoadStrArray())
106106
loadStrArray(dir + "/rom/lang2/mod_str_array.toml");
107107
}
108108

109-
// RDX, R8 and R9 in the argument list are required to prevent memory corruptions.
110-
// I am not sure why this is required, but it is the only way to prevent crashing.
109+
// This function isn't implemented here. See DatabaseLoaderImp.asm for details.
110+
HOOK(const char*, __fastcall, GetStr, sigGetStr(), const int id);
111111

112-
HOOK(const char*, __fastcall, GetStr, sigGetStr(), const int id, void* RDX, void* R8, void* R9)
112+
const char* getStrImp(const int id)
113113
{
114114
const auto str = strArray.find(id);
115-
115+
116116
if (str != strArray.end())
117117
return str->second.c_str();
118118

119-
return originalGetStr(id, RDX, R8, R9);
119+
return originalGetStr(id);
120120
}
121121

122122
void DatabaseLoader::init()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.code
2+
3+
; THIS FUNCTION IS CURSED.
4+
; The original function barely utilizes any registers, so functions calling it don't care about their temporary registers getting corrupted.
5+
; The hook changes them, so we run into crashes.
6+
7+
; Push every register known to mankind to overcome this issue.
8+
9+
?getStrImp@@YAPEBDH@Z proto
10+
11+
?implOfGetStr@@YAPEBDH@Z:
12+
push rbx
13+
push rdx
14+
push rsi
15+
push rdi
16+
push r8
17+
push r9
18+
push r10
19+
push r11
20+
push r12
21+
push r13
22+
push r14
23+
push r15
24+
25+
call ?getStrImp@@YAPEBDH@Z
26+
27+
pop r15
28+
pop r14
29+
pop r13
30+
pop r12
31+
pop r11
32+
pop r10
33+
pop r9
34+
pop r8
35+
pop rdi
36+
pop rsi
37+
pop rdx
38+
pop rbx
39+
40+
ret
41+
42+
public ?implOfGetStr@@YAPEBDH@Z
43+
44+
end

Source/DivaModLoader/DivaModLoader.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
</PropertyGroup>
4141
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
4242
<ImportGroup Label="ExtensionSettings">
43+
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
4344
</ImportGroup>
4445
<ImportGroup Label="Shared">
4546
</ImportGroup>
@@ -126,7 +127,13 @@
126127
</ClCompile>
127128
<ClCompile Include="SigScan.cpp" />
128129
</ItemGroup>
130+
<ItemGroup>
131+
<MASM Include="DatabaseLoaderImp.asm">
132+
<FileType>Document</FileType>
133+
</MASM>
134+
</ItemGroup>
129135
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
130136
<ImportGroup Label="ExtensionTargets">
137+
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
131138
</ImportGroup>
132139
</Project>

Source/DivaModLoader/DivaModLoader.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@
2525
<ClCompile Include="DatabaseLoader.cpp" />
2626
<ClCompile Include="FileLoader.cpp" />
2727
</ItemGroup>
28+
<ItemGroup>
29+
<MASM Include="DatabaseLoaderImp.asm" />
30+
</ItemGroup>
2831
</Project>

0 commit comments

Comments
 (0)