Skip to content

Commit

Permalink
Merge pull request #205 from chinosk6/main
Browse files Browse the repository at this point in the history
adapt for loader
  • Loading branch information
chinosk6 authored Dec 21, 2024
2 parents a66a482 + fc39669 commit c2c0907
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 57 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
resources/schinese/localized_data/umamusumelocalify filter=lfs diff=lfs merge=lfs -text
*.dll filter=lfs diff=lfs merge=lfs -text
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jobs:
run: |
mkdir package
cp build/bin/x64/Release/version.dll package/tlg.dll
cp version/version.dll package/version.dll
cp -r resources/schinese/localized_data package/localized_data
cp resources/config.json package/config.json
mkdir package/localized_data/config_schema
Expand All @@ -69,6 +68,8 @@ jobs:
cp resources/text_data_info_i18n_zh_tw.json package/localized_data/config_schema/text_data_info_i18n_zh_tw.json
cp resources/text_data_info_i18n_ja.json package/localized_data/config_schema/text_data_info_i18n_ja.json
cp resources/legend_g_plugin.exe package/legend_g_plugin.exe.autoupdate
cp resources/loader.dll package/loader.dll
cp resources/tlg_starter.exe package/tlg_starter.exe
cp -r resources/eventHelper package/localized_data/eventHelper_examples
- uses: actions/upload-artifact@v4
with:
Expand Down
Binary file modified resources/legend_g_plugin.exe
Binary file not shown.
Binary file added resources/loader.dll
Binary file not shown.
Binary file added resources/tlg_starter.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion src/eventHelper/eventHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace EventHelper {

const auto localLang = GetUserDefaultUILanguage();

std::filesystem::path dataPath = "localized_data/eventHelper";
std::filesystem::path dataPath = DLL_DIR / "localized_data/eventHelper";
if (sChineseLangIds.contains(localLang)) {
systemLang = L"scn";
dataPath /= "events_scn.json";
Expand Down
87 changes: 68 additions & 19 deletions src/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bool raceFollowUmaFirstPersonEnableRoll = false;
std::function<void(Il2CppString* title, Il2CppString* content, int buttonCount, int button1Text, int button2Text, int button3Text, int btn_type)> showDialog = nullptr;
bool guiStarting = false;
void (*testFunction)() = nullptr;
bool gameClosing = false;

void _set_u_stat(bool s) {
if (autoChangeLineBreakMode) {
Expand Down Expand Up @@ -69,7 +70,7 @@ namespace
{
// GameAssembly.dll code must be loaded and decrypted while loading criware library
if (path == L"cri_ware_unity.dll"sv)
{
{
path_game_assembly();
if (g_on_hook_ready)
{
Expand All @@ -78,7 +79,7 @@ namespace

MH_DisableHook(LoadLibraryW);
MH_RemoveHook(LoadLibraryW);

// use original function beacuse we have unhooked that
return LoadLibraryW(path);
}
Expand Down Expand Up @@ -422,9 +423,7 @@ namespace

std::unordered_map<void*, std::unique_ptr<ILocalizationQuery>> text_queries;

void* query_setup_orig = nullptr;
void* query_setup_hook(void* _this, void* conn, Il2CppString* sql)
{
void parseQuery(void* queryInstance, Il2CppString* sql) {
static const std::wregex statementPattern(LR"(SELECT (.+?) FROM `(.+?)`(?: WHERE (.+))?;)");
static const std::wregex columnPattern(LR"(,?`(\w+)`)");
static const std::wregex whereClausePattern(LR"((?:AND )?`(\w+)=?`)");
Expand Down Expand Up @@ -456,7 +455,8 @@ namespace
}
else
{
goto NormalPath;
// goto NormalPath;
return;
}

auto columnsPtr = columns.c_str();
Expand All @@ -483,13 +483,31 @@ namespace
}
}

text_queries.emplace(_this, std::move(query));
text_queries.emplace(queryInstance, std::move(query));
}
}

NormalPath:
void* query_setup_orig = nullptr;
void* query_setup_hook(void* _this, void* conn, Il2CppString* sql)
{
parseQuery(_this, sql);
return reinterpret_cast<decltype(query_setup_hook)*>(query_setup_orig)(_this, conn, sql);
}

void* Connection_Query_orig;
void* Connection_Query_hook(void* _this, Il2CppString* sql) {
auto ret = reinterpret_cast<decltype(Connection_Query_hook)*>(Connection_Query_orig)(_this, sql);
parseQuery(ret, sql);
return ret;
}

void* Connection_PreparedQuery_orig;
void* Connection_PreparedQuery_hook(void* _this, Il2CppString* sql) {
auto ret = reinterpret_cast<decltype(Connection_PreparedQuery_hook)*>(Connection_PreparedQuery_orig)(_this, sql);
parseQuery(ret, sql);
return ret;
}

void* query_dispose_orig = nullptr;
void query_dispose_hook(void* _this)
{
Expand All @@ -509,7 +527,17 @@ namespace
return localizedStr;
}
}
/*
auto ret = reinterpret_cast<decltype(query_getstr_hook)*>(query_getstr_orig)(_this, idx);
std::wstring target = L"もうすぐイベントだよ!\r\nワクワク…!ワクワク…!";
if (ret) {
std::wstring origRet(ret->start_char);
if (origRet == target) {
wprintf(L"query_getstr_hook: %d - %ls\n%ls\n\n", idx, origRet.c_str(), environment_get_stacktrace()->start_char);
}
}
return ret;*/
return reinterpret_cast<decltype(query_getstr_hook)*>(query_getstr_orig)(_this, idx);
}

Expand Down Expand Up @@ -637,7 +665,7 @@ namespace

void* Get3DAntiAliasingLevel_orig;
int Get3DAntiAliasingLevel_hook(void* _this, bool allowMSAA) {
if (g_antialiasing != -1) allowMSAA = true;
// if (g_antialiasing != -1) allowMSAA = true;
auto data = reinterpret_cast<decltype(Get3DAntiAliasingLevel_hook)*>(Get3DAntiAliasingLevel_orig)(_this, allowMSAA);
// printf("Get3DAntiAliasingLevel: %d %d\n", allowMSAA, data);
return data;
Expand Down Expand Up @@ -891,7 +919,6 @@ namespace
void* wndproc_orig = nullptr;

bool raceStart = false;
bool gameClosing = false;
LRESULT wndproc_hook(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_INPUT)
Expand Down Expand Up @@ -1340,8 +1367,9 @@ namespace
}

if (g_replace_assets) {
if (std::filesystem::exists(localPath)) {
auto replaceT2D = getLocalT2D(localPath);
const auto localReadPath = DLL_DIR / localPath;
if (std::filesystem::exists(localReadPath)) {
auto replaceT2D = getLocalT2D(localReadPath);
if (replaceT2D) {
result = replaceT2D;
}
Expand Down Expand Up @@ -1484,7 +1512,7 @@ namespace
static auto ImageConversion_EncodeToPNG_mtd = il2cpp_symbols::get_method(
"UnityEngine.ImageConversionModule.dll", "UnityEngine", "ImageConversion", "EncodeToPNG", 1);

const std::filesystem::path baseDumpPath = "localized_data/TextureDump";
const std::filesystem::path baseDumpPath = DLL_DIR / "localized_data/TextureDump";

std::string textureName = utility::conversions::to_utf8string(get_ObjectName(texture)->start_char);
replaceAll(textureName, "|", "_");
Expand Down Expand Up @@ -1574,7 +1602,7 @@ namespace

if (g_replace_assets) {
auto object_name = get_ObjectName(texture2D);
static std::filesystem::path baseSearchPath = "localized_data/res/texture2d";
static std::filesystem::path baseSearchPath = DLL_DIR / "localized_data/res/texture2d";

if (object_name) {
const std::wstring objName(object_name->start_char);
Expand Down Expand Up @@ -4175,7 +4203,7 @@ namespace
if (g_read_request_pack && g_save_msgpack)
{
const auto outPath = std::format("MsgPack/{}Q.msgpack", currentTime());
writeFile(outPath, src, srcSize);
writeFile((DLL_DIR / outPath).string(), src, srcSize);
printf("Save request to %s\n", outPath.c_str());
}

Expand All @@ -4200,7 +4228,7 @@ namespace
if (g_read_request_pack && g_save_msgpack)
{
const string outPath = std::format("MsgPack/{}R.msgpack", currentTime());
writeFile(outPath, dst, ret);
writeFile((DLL_DIR / outPath).string(), dst, ret);
printf("Save response to %s\n", outPath.c_str());
}

Expand Down Expand Up @@ -4424,7 +4452,7 @@ namespace
/*dump_bytes(_name_##_offset); */ \
\
MH_CreateHook(_name_##_offset, _name_##_hook, &_name_##_orig); \
MH_EnableHook(_name_##_offset);
MH_EnableHook(_name_##_offset);
#pragma endregion
#pragma region HOOK_ADDRESSES
auto populate_with_errors_addr = il2cpp_symbols::get_method_pointer(
Expand All @@ -4447,6 +4475,16 @@ namespace
"Query", "_Setup", 2
);

auto Connection_Query_addr = il2cpp_symbols::get_method_pointer(
"LibNative.Runtime.dll", "LibNative.Sqlite3",
"Connection", "Query", 1
);

auto Connection_PreparedQuery_addr = il2cpp_symbols::get_method_pointer(
"LibNative.Runtime.dll", "LibNative.Sqlite3",
"Connection", "PreparedQuery", 1
);

auto query_getstr_addr = il2cpp_symbols::get_method_pointer(
"LibNative.Runtime.dll", "LibNative.Sqlite3",
"Query", "GetText", 1
Expand Down Expand Up @@ -5241,6 +5279,8 @@ namespace
ADD_HOOK(localize_jp_get, "Gallop.Localize.JP.Get(TextId) at %p\n");
ADD_HOOK(on_exit, "Gallop.GameSystem.onApplicationQuit at %p\n");
ADD_HOOK(query_setup, "Query::_Setup at %p\n");
ADD_HOOK(Connection_Query, "Connection_Query at %p\n");
ADD_HOOK(Connection_PreparedQuery, "Connection_PreparedQuery at %p\n");
ADD_HOOK(query_getstr, "Query::GetString at %p\n");
ADD_HOOK(query_dispose, "Query::Dispose at %p\n");
ADD_HOOK(PreparedQuery_BindInt, "PreparedQuery::BindInt at %p\n");
Expand Down Expand Up @@ -5534,8 +5574,17 @@ bool init_hook()
mh_inited = true;
onPluginReload.push_back(reloadAssetBundle);

MH_CreateHook(LoadLibraryW, load_library_w_hook, &load_library_w_orig);
MH_EnableHook(LoadLibraryW);
auto cri_ware_handle = GetModuleHandleW(L"cri_ware_unity.dll");
if (cri_ware_handle) {
std::thread([]() {
load_library_w_hook(L"cri_ware_unity.dll");
}).detach();
}
else {
MH_CreateHook(LoadLibraryW, load_library_w_hook, &load_library_w_orig);
MH_EnableHook(LoadLibraryW);
}

return true;
}

Expand Down
11 changes: 9 additions & 2 deletions src/imgui/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,8 @@ CODE
#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
#endif

#include <stdinclude.hpp>

// Debug options
#define IMGUI_DEBUG_NAV_SCORING 0 // Display navigation scoring preview when hovering items. Display last moving direction matches when holding CTRL
#define IMGUI_DEBUG_NAV_RECTS 0 // Display the reference navigation rectangle for each window
Expand Down Expand Up @@ -1189,6 +1191,11 @@ void ImGuiStyle::ScaleAllSizes(float scale_factor)
MouseCursorScale = ImFloor(MouseCursorScale * scale_factor);
}

ImGuiIO::~ImGuiIO() {
free((void*)IniFilename);
free((void*)LogFilename);
}

ImGuiIO::ImGuiIO()
{
// Most fields are initialized with zero
Expand All @@ -1201,8 +1208,8 @@ ImGuiIO::ImGuiIO()
DisplaySize = ImVec2(-1.0f, -1.0f);
DeltaTime = 1.0f / 60.0f;
IniSavingRate = 5.0f;
IniFilename = "imgui.ini"; // Important: "imgui.ini" is relative to current working dir, most apps will want to lock this to an absolute path (e.g. same path as executables).
LogFilename = "imgui_log.txt";
IniFilename = strdup((DLL_DIR / "imgui.ini").string().c_str()); // Important: "imgui.ini" is relative to current working dir, most apps will want to lock this to an absolute path (e.g. same path as executables).
LogFilename = strdup((DLL_DIR / "imgui_log.txt").string().c_str());
MouseDoubleClickTime = 0.30f;
MouseDoubleClickMaxDist = 6.0f;
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
Expand Down
1 change: 1 addition & 0 deletions src/imgui/imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,7 @@ struct ImGuiKeyData

struct ImGuiIO
{
~ImGuiIO();
//------------------------------------------------------------------
// Configuration // Default value
//------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/logger/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace logger

void open_test_log_file() {
test_log_opened = true;
test_log_file.open("legendtest.log", ios::app | ios::out);
test_log_file.open(DLL_DIR / "legendtest.log", ios::app | ios::out);
}

void write_test_log(wstring text) {
Expand All @@ -73,7 +73,7 @@ namespace logger
if (g_enable_logger)
{
enabled = true;
log_file.open("dump.txt", ios::app | ios::out);
log_file.open(DLL_DIR / "dump.txt", ios::app | ios::out);

thread t([]() {
while (!request_exit)
Expand Down
Loading

0 comments on commit c2c0907

Please sign in to comment.