From e231d4b22fd6543f462366980df72a148aea88d2 Mon Sep 17 00:00:00 2001 From: 0O0o0oOoO00 <11174151+0O0o0oOoO00@users.noreply.github.com> Date: Sun, 16 Nov 2025 15:04:04 +0800 Subject: [PATCH] add: hooked lua function trace --- blcrack/cracker/cracker.cpp | 26 ++++++++++++++++++++------ blcrack/cracker/cracker.hpp | 5 +++++ blcrack/cracker/server.cpp | 22 ++++++++++++++++++++++ blcrack/cracker/ui/ui.cpp | 1 + blcrack/http/cracker.http | 6 ++++++ config/template.json | 3 ++- module/config/argument/args.json | 4 ++++ module/config/argument/argument.yaml | 1 + module/config/config_generated.py | 1 + module/config/full_config_generated.py | 1 + module/config/i18n/en-US.json | 4 ++++ module/config/i18n/ja-JP.json | 4 ++++ module/config/i18n/zh-CN.json | 4 ++++ module/config/i18n/zh-TW.json | 4 ++++ module/luahook/api.py | 6 ++++++ module/luahook/crack.py | 8 ++++++++ module/luahook/op.py | 6 ++++++ 17 files changed, 99 insertions(+), 7 deletions(-) diff --git a/blcrack/cracker/cracker.cpp b/blcrack/cracker/cracker.cpp index f362b8fde..56f653b4f 100644 --- a/blcrack/cracker/cracker.cpp +++ b/blcrack/cracker/cracker.cpp @@ -52,12 +52,10 @@ static fnset_TimeScaleT get_Time_set_timeScale() { SPDLOG_INFO("Disable {}", #n); \ m_flag.n.store(false) - -#ifdef DEBUG_MODE -#define CALLED(f) SPDLOG_INFO("{} called", #f) -#else -#define CALLED(f) -#endif +#define CALLED(f) \ + if (IS_ENABLED(HOOKED_LUA_FUNCTION_TRACE)) { \ + SPDLOG_INFO("{} called", #f); \ + } Cracker::Cracker() : m_state([]() -> lua_State* { @@ -226,6 +224,7 @@ std::optional Cracker::get_storage_item_count(Storage } void Cracker::disable_all() { + disable_hooked_lua_function_trace(); disable_global_ship_properties_crack(); disable_fast_stage_move(); disable_remove_hard_mode_ship_properties_limit(); @@ -248,6 +247,14 @@ void Cracker::disable_all() { disable_opsi_no_map_fog(); } +void Cracker::enable_hooked_lua_function_trace() { + ENABLE(HOOKED_LUA_FUNCTION_TRACE); +} + +void Cracker::disable_hooked_lua_function_trace() { + DISABLE(HOOKED_LUA_FUNCTION_TRACE); +} + void Cracker::enable_opsi_force_auto() { ENABLE(OPSI_FORCE_AUTO); } @@ -1114,6 +1121,7 @@ void Cracker::better_global_speedup_set_rate(double rate) { Cracker::Config Cracker::get_config() { Config config = { .flag = { + SET_CONFIG_FLAG(HOOKED_LUA_FUNCTION_TRACE), SET_CONFIG_FLAG(GLOBAL_SHIP_PROPERTIES_CRACK), SET_CONFIG_FLAG(FAST_STAGE_MOVE_CRACK), SET_CONFIG_FLAG(REMOVE_HARD_MODE_SHIP_PROPERTIES_LIMIT), @@ -1146,6 +1154,12 @@ Cracker::Config Cracker::get_config() { #define IS_CONFIG_ENABLED(n) config.flag.n void Cracker::apply_config(Config& config) { + if(IS_CONFIG_ENABLED(HOOKED_LUA_FUNCTION_TRACE)) { + enable_hooked_lua_function_trace(); + } else { + disable_hooked_lua_function_trace(); + } + if(IS_CONFIG_ENABLED(OPSI_FORCE_AUTO)) { enable_opsi_force_auto(); } else { diff --git a/blcrack/cracker/cracker.hpp b/blcrack/cracker/cracker.hpp index ff0cc9834..c7e54ed49 100644 --- a/blcrack/cracker/cracker.hpp +++ b/blcrack/cracker/cracker.hpp @@ -69,6 +69,7 @@ public: struct Config { struct { + bool HOOKED_LUA_FUNCTION_TRACE = false; bool GLOBAL_SHIP_PROPERTIES_CRACK = false; bool FAST_STAGE_MOVE_CRACK = false; bool REMOVE_HARD_MODE_SHIP_PROPERTIES_LIMIT = false; @@ -124,6 +125,9 @@ public: void disable_all(); + void enable_hooked_lua_function_trace(); + void disable_hooked_lua_function_trace(); + void enable_opsi_force_auto(); void disable_opsi_force_auto(); @@ -206,6 +210,7 @@ private: static void clear_hard_mode_ship_properties_limit(Lua::Table& t); struct { + std::atomic HOOKED_LUA_FUNCTION_TRACE = false; std::atomic GLOBAL_SHIP_PROPERTIES_CRACK = false; std::atomic FAST_STAGE_MOVE_CRACK = false; std::atomic REMOVE_HARD_MODE_SHIP_PROPERTIES_LIMIT = false; diff --git a/blcrack/cracker/server.cpp b/blcrack/cracker/server.cpp index 1265022db..5fc6a13b0 100644 --- a/blcrack/cracker/server.cpp +++ b/blcrack/cracker/server.cpp @@ -24,6 +24,28 @@ CrackerServer::CrackerServer() { CRACK_OK(); }); + Post("/enable_hooked_lua_function_trace", [](const httplib::Request& req, httplib::Response& res) { + try { + Cracker::Instance().enable_hooked_lua_function_trace(); + } catch (std::exception& e) { + SPDLOG_ERROR("Enable hooked lua function trace failed: {}", e.what()); + res.status = 500; + return; + } + CRACK_OK(); + }); + + Post("/disable_hooked_lua_function_trace", [](const httplib::Request& req, httplib::Response& res) { + try { + Cracker::Instance().disable_hooked_lua_function_trace(); + } catch (std::exception& e) { + SPDLOG_ERROR("Disable hooked lua function trace failed: {}", e.what()); + res.status = 500; + return; + } + CRACK_OK(); + }); + Post("/enable_global_ship_properties_crack", [](const httplib::Request& req, httplib::Response& res) { try { Cracker::Instance().enable_global_ship_properties_crack(); diff --git a/blcrack/cracker/ui/ui.cpp b/blcrack/cracker/ui/ui.cpp index 54ac742c4..458cbde0b 100644 --- a/blcrack/cracker/ui/ui.cpp +++ b/blcrack/cracker/ui/ui.cpp @@ -220,6 +220,7 @@ void CrackerUI::draw_menu() { } if(ImGui::BeginTabItem("调试")) { ImGui::Checkbox("不渲染", &g_no_rander); + ImGui::Checkbox("Lua函数追踪", &CONFIG_FLAG(HOOKED_LUA_FUNCTION_TRACE)); ImGui::EndTabItem(); } ImGui::EndTabBar(); diff --git a/blcrack/http/cracker.http b/blcrack/http/cracker.http index 86266191c..5e458798b 100644 --- a/blcrack/http/cracker.http +++ b/blcrack/http/cracker.http @@ -3,6 +3,12 @@ POST http://{{Host}}:{{Port}}/disable_all +### +POST http://{{Host}}:{{Port}}/enable_hooked_lua_function_trace + +### +POST http://{{Host}}:{{Port}}/disable_hooked_lua_function_trace + ### POST http://{{Host}}:{{Port}}/enable_global_ship_properties_crack diff --git a/config/template.json b/config/template.json index f1fe4e9bb..0cbdcada2 100644 --- a/config/template.json +++ b/config/template.json @@ -203,7 +203,8 @@ "InjectMethod": "local_patch", "RequestTimeLimit": 10, "UpdateServer": null, - "GameLibDir": null + "GameLibDir": null, + "HookedLuaFunctionTrace": false }, "Misc": { "GlobalSpeedup": 1.0, diff --git a/module/config/argument/args.json b/module/config/argument/args.json index fe0ee8a6c..58f1183bb 100644 --- a/module/config/argument/args.json +++ b/module/config/argument/args.json @@ -809,6 +809,10 @@ "GameLibDir": { "type": "textarea", "value": "" + }, + "HookedLuaFunctionTrace": { + "type": "checkbox", + "value": false } }, "Misc": { diff --git a/module/config/argument/argument.yaml b/module/config/argument/argument.yaml index b7ec5a607..b30f018b1 100644 --- a/module/config/argument/argument.yaml +++ b/module/config/argument/argument.yaml @@ -837,6 +837,7 @@ HookGeneral: GameLibDir: value: "" type: textarea + HookedLuaFunctionTrace: false ShipProperty: Method: value: disable diff --git a/module/config/config_generated.py b/module/config/config_generated.py index 677c43542..1c4d0a254 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -493,6 +493,7 @@ class GeneratedConfig: HookGeneral_RequestTimeLimit = 10 HookGeneral_UpdateServer = None HookGeneral_GameLibDir = None + HookGeneral_HookedLuaFunctionTrace = False # Group `ShipProperty` ShipProperty_Method = 'disable' # disable, gg_factor, final_properties diff --git a/module/config/full_config_generated.py b/module/config/full_config_generated.py index 7ee1b36b5..2891ecf40 100644 --- a/module/config/full_config_generated.py +++ b/module/config/full_config_generated.py @@ -139,6 +139,7 @@ class FullGeneratedConfig: Hook_HookGeneral_RequestTimeLimit = None Hook_HookGeneral_UpdateServer = None Hook_HookGeneral_GameLibDir = None + Hook_HookGeneral_HookedLuaFunctionTrace = None Hook_Misc_GlobalSpeedup = None Hook_Misc_BetterGlobalSpeedup = None Hook_Misc_ChapterMove = None diff --git a/module/config/i18n/en-US.json b/module/config/i18n/en-US.json index 3ad1313d1..38761adce 100644 --- a/module/config/i18n/en-US.json +++ b/module/config/i18n/en-US.json @@ -2931,6 +2931,10 @@ "GameLibDir": { "name": "HookGeneral.GameLibDir.name", "help": "HookGeneral.GameLibDir.help" + }, + "HookedLuaFunctionTrace": { + "name": "HookGeneral.HookedLuaFunctionTrace.name", + "help": "HookGeneral.HookedLuaFunctionTrace.help" } }, "ShipProperty": { diff --git a/module/config/i18n/ja-JP.json b/module/config/i18n/ja-JP.json index 86687d824..fd17595e4 100644 --- a/module/config/i18n/ja-JP.json +++ b/module/config/i18n/ja-JP.json @@ -2931,6 +2931,10 @@ "GameLibDir": { "name": "HookGeneral.GameLibDir.name", "help": "HookGeneral.GameLibDir.help" + }, + "HookedLuaFunctionTrace": { + "name": "HookGeneral.HookedLuaFunctionTrace.name", + "help": "HookGeneral.HookedLuaFunctionTrace.help" } }, "ShipProperty": { diff --git a/module/config/i18n/zh-CN.json b/module/config/i18n/zh-CN.json index 949edba78..12f73b413 100644 --- a/module/config/i18n/zh-CN.json +++ b/module/config/i18n/zh-CN.json @@ -2931,6 +2931,10 @@ "GameLibDir": { "name": "游戏库目录", "help": "以x86架构为例,目录一般为/data/app/<一串乱码>/<一串乱码>/lib/x86" + }, + "HookedLuaFunctionTrace": { + "name": "Lua函数追踪", + "help": "仅供调试使用,平时使用不要开" } }, "ShipProperty": { diff --git a/module/config/i18n/zh-TW.json b/module/config/i18n/zh-TW.json index c5106401f..d71c4dc61 100644 --- a/module/config/i18n/zh-TW.json +++ b/module/config/i18n/zh-TW.json @@ -2931,6 +2931,10 @@ "GameLibDir": { "name": "HookGeneral.GameLibDir.name", "help": "HookGeneral.GameLibDir.help" + }, + "HookedLuaFunctionTrace": { + "name": "HookGeneral.HookedLuaFunctionTrace.name", + "help": "HookGeneral.HookedLuaFunctionTrace.help" } }, "ShipProperty": { diff --git a/module/luahook/api.py b/module/luahook/api.py index ed1f2d8a2..3b8cf9c7b 100644 --- a/module/luahook/api.py +++ b/module/luahook/api.py @@ -319,3 +319,9 @@ class CrackApi: def disable_opsi_no_map_fog(self): self.post("disable_opsi_no_map_fog") + + def enable_hooked_lua_function_trace(self): + self.post("enable_hooked_lua_function_trace") + + def disable_hooked_lua_function_trace(self): + self.post("disable_hooked_lua_function_trace") diff --git a/module/luahook/crack.py b/module/luahook/crack.py index 9d3813b2a..522e47e66 100644 --- a/module/luahook/crack.py +++ b/module/luahook/crack.py @@ -17,6 +17,7 @@ from module.luahook.api import CrackApi from module.luahook.op import CrackOp ALL_ENABLE_OPS = [ + CrackOp.EnableHookedLuaFunctionTrace, CrackOp.EnableGlobalShipProperties, CrackOp.EnableChapterFastMove, CrackOp.EnableRemoveHardModeLimit, @@ -95,6 +96,11 @@ def do_crack_op(config: AzurLaneConfig, device: Device, ops: Union[Type[CrackOp. for op in l: if op == CrackOp.DisableAll: api.disable_all() + elif op == CrackOp.EnableHookedLuaFunctionTrace: + if full_config.Hook_HookGeneral_HookedLuaFunctionTrace: + api.enable_hooked_lua_function_trace() + elif op == CrackOp.DisableHookedLuaFunctionTrace: + api.disable_hooked_lua_function_trace() elif op == CrackOp.EnableGlobalShipProperties: if config.full_config.Hook_ShipProperty_Method != "final_properties": continue @@ -283,6 +289,7 @@ def luahook_disable_all(config: AzurLaneConfig, device: Device): CHAPTER_CRACK_OPS = [ + CrackOp.EnableHookedLuaFunctionTrace, CrackOp.EnableChapterFastMove, CrackOp.EnableNoBBAnimation, CrackOp.EnableNoEmotionWarning, @@ -309,6 +316,7 @@ def chapter_task_crack(f): OPSI_CRACK_OPS = [ + CrackOp.EnableHookedLuaFunctionTrace, CrackOp.EnableNoBBAnimation, CrackOp.EnableOpsiFastMove, CrackOp.EnableGlobalShipProperties, diff --git a/module/luahook/op.py b/module/luahook/op.py index 5ceabadcf..de626acba 100644 --- a/module/luahook/op.py +++ b/module/luahook/op.py @@ -8,6 +8,12 @@ class CrackOp: class DisableAll(Op): ... + class EnableHookedLuaFunctionTrace(Op): + ... + + class DisableHookedLuaFunctionTrace(Op): + ... + class EnableGlobalShipProperties(Op): ...