Skip to content

Commit

Permalink
Add 'staticEntriesUseHash' option
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimjio committed Sep 29, 2022
1 parent 5048f97 commit e3369f4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,9 @@ namespace
void* localizeextension_text_orig = nullptr;
Il2CppString* localizeextension_text_hook(int id)
{
Il2CppString* localized = local::get_localized_string(id);
return localized ? localized
: reinterpret_cast<decltype(localizeextension_text_hook)*>(localizeextension_text_orig)(
id
);
auto orig_result = reinterpret_cast<decltype(localizeextension_text_hook)*>(localizeextension_text_orig)(id);
auto result = g_static_entries_use_hash ? local::get_localized_string(orig_result) : local::get_localized_string(id);
return result ? result : orig_result;
}

void ReplaceTextMeshFont(Il2CppObject* textMesh, Il2CppObject* meshRenderer) {
Expand Down Expand Up @@ -142,7 +140,7 @@ namespace
Il2CppString* localize_get_hook(int id)
{
auto orig_result = reinterpret_cast<decltype(localize_get_hook)*>(localize_get_orig)(id);
auto result = local::get_localized_string(id);
auto result = g_static_entries_use_hash ? local::get_localized_string(orig_result) : local::get_localized_string(id);

return result ? result : orig_result;
}
Expand Down Expand Up @@ -1144,14 +1142,22 @@ namespace

void dump_all_entries()
{
vector<wstring> static_entries;
// 0 is None
for (int i = 1;; i++)
{
auto* str = reinterpret_cast<decltype(localize_get_hook)*>(localize_get_orig)(i);

if (str && *str->start_char)
{
logger::write_entry(i, str->start_char);
if (g_static_entries_use_hash)
{
static_entries.push_back(str->start_char);
}
else
{
logger::write_entry(i, str->start_char);
}
}
else
{
Expand All @@ -1161,6 +1167,9 @@ namespace
break;
}
}
if (g_static_entries_use_hash) {
logger::write_static_dict(static_entries);
}
}

void path_game_assembly()
Expand Down
33 changes: 33 additions & 0 deletions src/logger/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace logger
bool enabled = false;
bool request_exit = false;
bool has_change = false;

fstream static_json;
}

void init_logger()
Expand Down Expand Up @@ -58,4 +60,35 @@ namespace logger

has_change = true;
}

void write_static_dict(std::vector<std::wstring> dict)
{
if (g_enable_logger)
{
static_json.open("static.json", ios::out);
static_json << "{\n";
thread t([dict]() {
for (int i = 0; i < dict.size(); i++)
{
auto hash = std::hash<wstring>{}(dict[i]);
auto u8str = local::wide_u8(dict[i]);
replaceAll(u8str, "\n", "\\n");
replaceAll(u8str, "\"", "\\\"");
if (i == dict.size() - 1)
{
static_json << "\"" << hash << "\": \"" << u8str << "\"\n";
}
else
{
static_json << "\"" << hash << "\": \"" << u8str << "\",\n";
}
}
static_json << "}\n";
static_json.close();
});

t.detach();
}

}
}
1 change: 1 addition & 0 deletions src/logger/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ namespace logger
void init_logger();
void close_logger();
void write_entry(size_t hash, std::wstring text);
void write_static_dict(std::vector<std::wstring> dict);
}
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern void uninit_hook();
extern void start_console();

bool g_dump_entries = false;
bool g_static_entries_use_hash = false;
bool g_enable_logger = false;
bool g_enable_console = false;
int g_max_fps = -1;
Expand Down Expand Up @@ -70,6 +71,9 @@ namespace
if (document.HasMember("dumpStaticEntries")) {
g_dump_entries = document["dumpStaticEntries"].GetBool();
}
if (document.HasMember("staticEntriesUseHash")) {
g_static_entries_use_hash = document["staticEntriesUseHash"].GetBool();
}
if (document.HasMember("maxFps")) {
g_max_fps = document["maxFps"].GetInt();
}
Expand Down
1 change: 1 addition & 0 deletions src/stdinclude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct ReplaceAsset {
extern bool g_dump_entries;
extern bool g_enable_logger;
extern bool g_enable_console;
extern bool g_static_entries_use_hash;
extern int g_max_fps;
extern bool g_unlock_size;
extern float g_ui_scale;
Expand Down

0 comments on commit e3369f4

Please sign in to comment.