Skip to content

Commit 3895c88

Browse files
Implement mod string arrays.
1 parent fb090e6 commit 3895c88

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

Source/DivaModLoader/DatabaseLoader.cpp

+73-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "DatabaseLoader.h"
22

3+
#include "Context.h"
34
#include "ModLoader.h"
45
#include "Types.h"
56
#include "Utilities.h"
@@ -45,6 +46,75 @@ HOOK(size_t, __fastcall, ResolveFilePath, sigResolveFilePath(), prj::string& fil
4546
return originalResolveFilePath(filePath, a2);
4647
}
4748

49+
// Custom string arrays.
50+
std::unordered_map<size_t, std::string> strArray;
51+
52+
void addStrArray(const toml::table* table)
53+
{
54+
if (!table)
55+
return;
56+
57+
for (auto&& [key, value] : *table)
58+
{
59+
if (value.is_table())
60+
continue;
61+
62+
// Convert to integer and check for success.
63+
char* end = nullptr;
64+
const int id = strtol(key.data(), &end, 10);
65+
66+
if (end && strArray.find(id) == strArray.end())
67+
strArray[id] = value.value_or("YOU FORGOT QUOTATION MARKS");
68+
}
69+
}
70+
71+
void loadStrArray(const std::string& filePath)
72+
{
73+
if (!std::filesystem::exists(filePath))
74+
return;
75+
76+
toml::table table;
77+
78+
try
79+
{
80+
table = toml::parse_file(filePath);
81+
}
82+
catch (std::exception& exception)
83+
{
84+
char text[0x400];
85+
sprintf(text, "Failed to parse \"%s\".\nDid you forget to add quotation marks to your string?\n\nDetails:\n%s",
86+
std::filesystem::path(filePath).lexically_normal().string().c_str(), exception.what());
87+
88+
LOG("%s", text)
89+
MessageBoxA(nullptr, text, "DIVA Mod Loader", MB_ICONERROR);
90+
91+
return;
92+
}
93+
94+
uint8_t* instrAddr = (uint8_t*)sigLoadStrArray() + 0x55;
95+
FUNCTION_PTR(const char*, __fastcall, getLangDir, instrAddr + readUnalignedU32(instrAddr + 0x1) + 0x5);
96+
97+
addStrArray(table.get_as<toml::table>(strstr(getLangDir(), "/") + 1));
98+
addStrArray(&table);
99+
}
100+
101+
HOOK(void, __fastcall, LoadStrArray, sigLoadStrArray())
102+
{
103+
originalLoadStrArray();
104+
105+
for (auto& dir : ModLoader::modDirectoryPaths)
106+
loadStrArray(dir + "/rom/lang2/mod_str_array.toml");
107+
}
108+
109+
HOOK(const char*, __fastcall, GetStr, sigGetStr(), int id)
110+
{
111+
const auto str = strArray.find(id);
112+
if (str != strArray.end())
113+
return str->second.c_str();
114+
115+
return originalGetStr(id);
116+
}
117+
48118
void DatabaseLoader::init()
49119
{
50120
INSTALL_HOOK(ResolveFilePath);
@@ -68,5 +138,7 @@ void DatabaseLoader::init()
68138

69139
list.push_back(path);
70140
}
71-
}
72141

142+
INSTALL_HOOK(LoadStrArray);
143+
INSTALL_HOOK(GetStr);
144+
}

Source/DivaModLoader/Pch.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <string>
2323
#include <vector>
2424
#include <list>
25+
#include <unordered_map>
2526

2627
#undef _ITERATOR_DEBUG_LEVEL
2728
#pragma pop_macro("_ITERATOR_DEBUG_LEVEL")

Source/DivaModLoader/SigScan.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,6 @@ SIG_SCAN(sigInitRomDirectoryPaths, 0x1402A2510, "\x48\x89\x5C\x24\x00\x48\x89\x7
9494
SIG_SCAN(sigInitSteamAPIManager, 0x1405FFE20, "\x48\x89\x5C\x24\x00\x57\x48\x83\xEC\x20\x48\x8B\xF9\x80\x79\x08\x00\x0F\x85\x00\x00\x00\x00\xB9\x00\x00\x00\x00\xFF\x15\x00\x00\x00\x00\x84\xC0\x74\x0F\xC6\x47\x08\x00\x48\x8B\x5C\x24\x00\x48\x83\xC4\x20\x5F\xC3", "xxxx?xxxxxxxxxxxxxx????x????xx????xxxxxxxxxxxx?xxxxxx")
9595
SIG_SCAN(sigResolveFilePath, 0x1402A5500, "\x48\x89\x5C\x24\x00\x55\x56\x57\x41\x54\x41\x55\x41\x56\x41\x57\x48\x83\xEC\x40\x48\x8B\x05\x00\x00\x00\x00\x48\x33\xC4\x48\x89\x44\x24\x00\x4C\x8B\xE2\x4C\x8B\xF9\x33\xC0\x0F\x57\xC9\xF3\x0F\x7F\x4C\x24\x00\x48\x89\x44\x24\x00\x48\x8D\x54\x24\x00\xE8\x00\x00\x00\x00\x83\xF8\x01\x75\x46\x49\x8B\xCF\xE8\x00\x00\x00\x00\x84\xC0\x74\x28\x4D\x85\xE4\x0F\x84\x00\x00\x00\x00\x4D\x3B\xE7\x0F\x84\x00\x00\x00\x00\x49\x8B\xD7\x49\x83\x7F\x00\x00\x72\x03\x49\x8B\x17", "xxxx?xxxxxxxxxxxxxxxxxx????xxxxxxx?xxxxxxxxxxxxxxxx?xxxx?xxxx?x????xxxxxxxxx????xxxxxxxxx????xxxxx????xxxxxx??xxxxx")
9696
SIG_SCAN(sigInitMdataMgr, 0x14043E150, "\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x41\x54\x41\x56\x41\x57\x48\x83\xEC\x60\x48\x8B\x44\x24\x00\x48\x89\x44\x24\x00\x4C\x8D\x25\x00\x00\x00\x00\x4C\x89\x64\x24\x00\x49\x8B\xCC", "xxxx?xxxx?xxxx?xxxx?xxxxxxxxxxxxxx?xxxx?xxx????xxxx?xxx")
97-
SIG_SCAN(sigLoadFileFromCpk, 0x140171880, "\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x55\x41\x54\x41\x55\x41\x56\x41\x57\x48\x8D\x6C\x24\x00\x48\x81\xEC\x00\x00\x00\x00\x48\x8B\x05\x00\x00\x00\x00\x48\x33\xC4\x48\x89\x45\x27\x45\x0F\xB6\xE8\x44\x0F\xB6\xE2\x48\x8B\xF1\x48\x83\x3D\x00\x00\x00\x00\x00\x75\x07\x33\xC0\xE9\x00\x00\x00\x00", "xxxx?xxxx?xxxx?xxxxxxxxxxxxx?xxx????xxx????xxxxxxxxxxxxxxxxxxxxx?????xxxxx????")
97+
SIG_SCAN(sigLoadFileFromCpk, 0x140171880, "\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x55\x41\x54\x41\x55\x41\x56\x41\x57\x48\x8D\x6C\x24\x00\x48\x81\xEC\x00\x00\x00\x00\x48\x8B\x05\x00\x00\x00\x00\x48\x33\xC4\x48\x89\x45\x27\x45\x0F\xB6\xE8\x44\x0F\xB6\xE2\x48\x8B\xF1\x48\x83\x3D\x00\x00\x00\x00\x00\x75\x07\x33\xC0\xE9\x00\x00\x00\x00", "xxxx?xxxx?xxxx?xxxxxxxxxxxxx?xxx????xxx????xxxxxxxxxxxxxxxxxxxxx?????xxxxx????")
98+
SIG_SCAN(sigLoadStrArray, 0x140239940, "\x48\x89\x5C\x24\x00\x57\x48\x83\xEC\x60\x48\x8B\x05\x00\x00\x00\x00\x48\x33\xC4\x48\x89\x44\x24\x00\x48\x83\x3D\x00\x00\x00\x00\x00\x0F\x85\x00\x00\x00\x00\x33\xC0\x48\x89\x44\x24\x00\x48\xC7\x44\x24\x00\x00\x00\x00\x00\x48\x89\x44\x24\x00\x88\x44\x24\x30\x44\x8D\x40\x04\x48\x8D\x15\x00\x00\x00\x00\x48\x8D\x4C\x24\x00\xE8\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x4C\x8B\xC8\x48\xC7\xC7\x00\x00\x00\x00", "xxxx?xxxxxxxx????xxxxxxx?xxx?????xx????xxxxxx?xxxx?????xxxx?xxxxxxxxxxx????xxxx?x????x????xxxxxx????")
99+
SIG_SCAN(sigGetStr, 0x14F7C37A0, "\x48\x8B\x15\x00\x00\x00\x00\x48\x85\xD2\x74\x10\x81\xF9\x00\x00\x00\x00\x7D\x08\x48\x63\xC1\x48\x8B\x04\xC2\xC3\x31\xC0\xC3", "xxx????xxxxxxx????xxxxxxxxxxxxx")

Source/DivaModLoader/SigScan.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ extern void* sigInitSteamAPIManager();
2424
extern void* sigResolveFilePath();
2525
extern void* sigInitMdataMgr();
2626

27-
extern void* sigLoadFileFromCpk();
27+
extern void* sigLoadFileFromCpk();
28+
29+
extern void* sigLoadStrArray();
30+
extern void* sigGetStr();

0 commit comments

Comments
 (0)