1
1
#include " DatabaseLoader.h"
2
2
3
+ #include " Context.h"
3
4
#include " ModLoader.h"
4
5
#include " Types.h"
5
6
#include " Utilities.h"
@@ -45,6 +46,75 @@ HOOK(size_t, __fastcall, ResolveFilePath, sigResolveFilePath(), prj::string& fil
45
46
return originalResolveFilePath (filePath, a2);
46
47
}
47
48
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\" .\n Did you forget to add quotation marks to your string?\n\n Details:\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
+
48
118
void DatabaseLoader::init ()
49
119
{
50
120
INSTALL_HOOK (ResolveFilePath);
@@ -68,5 +138,7 @@ void DatabaseLoader::init()
68
138
69
139
list.push_back (path);
70
140
}
71
- }
72
141
142
+ INSTALL_HOOK (LoadStrArray);
143
+ INSTALL_HOOK (GetStr);
144
+ }
0 commit comments