1
0
mirror of https://github.com/0O0o0oOoO00/Alas.git synced 2026-05-14 13:29:25 +08:00

add: hooked lua function trace

This commit is contained in:
0O0o0oOoO00
2025-11-16 15:04:04 +08:00
parent 2f78d7352d
commit e231d4b22f
17 changed files with 99 additions and 7 deletions

View File

@@ -52,12 +52,10 @@ static fnset_TimeScaleT get_Time_set_timeScale() {
SPDLOG_INFO("Disable {}", #n); \ SPDLOG_INFO("Disable {}", #n); \
m_flag.n.store(false) m_flag.n.store(false)
#define CALLED(f) \
#ifdef DEBUG_MODE if (IS_ENABLED(HOOKED_LUA_FUNCTION_TRACE)) { \
#define CALLED(f) SPDLOG_INFO("{} called", #f) SPDLOG_INFO("{} called", #f); \
#else }
#define CALLED(f)
#endif
Cracker::Cracker() Cracker::Cracker()
: m_state([]() -> lua_State* { : m_state([]() -> lua_State* {
@@ -226,6 +224,7 @@ std::optional<Cracker::StorageItemCount> Cracker::get_storage_item_count(Storage
} }
void Cracker::disable_all() { void Cracker::disable_all() {
disable_hooked_lua_function_trace();
disable_global_ship_properties_crack(); disable_global_ship_properties_crack();
disable_fast_stage_move(); disable_fast_stage_move();
disable_remove_hard_mode_ship_properties_limit(); disable_remove_hard_mode_ship_properties_limit();
@@ -248,6 +247,14 @@ void Cracker::disable_all() {
disable_opsi_no_map_fog(); 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() { void Cracker::enable_opsi_force_auto() {
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() { Cracker::Config Cracker::get_config() {
Config config = { Config config = {
.flag = { .flag = {
SET_CONFIG_FLAG(HOOKED_LUA_FUNCTION_TRACE),
SET_CONFIG_FLAG(GLOBAL_SHIP_PROPERTIES_CRACK), SET_CONFIG_FLAG(GLOBAL_SHIP_PROPERTIES_CRACK),
SET_CONFIG_FLAG(FAST_STAGE_MOVE_CRACK), SET_CONFIG_FLAG(FAST_STAGE_MOVE_CRACK),
SET_CONFIG_FLAG(REMOVE_HARD_MODE_SHIP_PROPERTIES_LIMIT), 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 #define IS_CONFIG_ENABLED(n) config.flag.n
void Cracker::apply_config(Config& config) { 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)) { if(IS_CONFIG_ENABLED(OPSI_FORCE_AUTO)) {
enable_opsi_force_auto(); enable_opsi_force_auto();
} else { } else {

View File

@@ -69,6 +69,7 @@ public:
struct Config { struct Config {
struct { struct {
bool HOOKED_LUA_FUNCTION_TRACE = false;
bool GLOBAL_SHIP_PROPERTIES_CRACK = false; bool GLOBAL_SHIP_PROPERTIES_CRACK = false;
bool FAST_STAGE_MOVE_CRACK = false; bool FAST_STAGE_MOVE_CRACK = false;
bool REMOVE_HARD_MODE_SHIP_PROPERTIES_LIMIT = false; bool REMOVE_HARD_MODE_SHIP_PROPERTIES_LIMIT = false;
@@ -124,6 +125,9 @@ public:
void disable_all(); void disable_all();
void enable_hooked_lua_function_trace();
void disable_hooked_lua_function_trace();
void enable_opsi_force_auto(); void enable_opsi_force_auto();
void disable_opsi_force_auto(); void disable_opsi_force_auto();
@@ -206,6 +210,7 @@ private:
static void clear_hard_mode_ship_properties_limit(Lua::Table& t); static void clear_hard_mode_ship_properties_limit(Lua::Table& t);
struct { struct {
std::atomic<bool> HOOKED_LUA_FUNCTION_TRACE = false;
std::atomic<bool> GLOBAL_SHIP_PROPERTIES_CRACK = false; std::atomic<bool> GLOBAL_SHIP_PROPERTIES_CRACK = false;
std::atomic<bool> FAST_STAGE_MOVE_CRACK = false; std::atomic<bool> FAST_STAGE_MOVE_CRACK = false;
std::atomic<bool> REMOVE_HARD_MODE_SHIP_PROPERTIES_LIMIT = false; std::atomic<bool> REMOVE_HARD_MODE_SHIP_PROPERTIES_LIMIT = false;

View File

@@ -24,6 +24,28 @@ CrackerServer::CrackerServer() {
CRACK_OK(); 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) { Post("/enable_global_ship_properties_crack", [](const httplib::Request& req, httplib::Response& res) {
try { try {
Cracker::Instance().enable_global_ship_properties_crack(); Cracker::Instance().enable_global_ship_properties_crack();

View File

@@ -220,6 +220,7 @@ void CrackerUI::draw_menu() {
} }
if(ImGui::BeginTabItem("调试")) { if(ImGui::BeginTabItem("调试")) {
ImGui::Checkbox("不渲染", &g_no_rander); ImGui::Checkbox("不渲染", &g_no_rander);
ImGui::Checkbox("Lua函数追踪", &CONFIG_FLAG(HOOKED_LUA_FUNCTION_TRACE));
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
ImGui::EndTabBar(); ImGui::EndTabBar();

View File

@@ -3,6 +3,12 @@
POST http://{{Host}}:{{Port}}/disable_all 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 POST http://{{Host}}:{{Port}}/enable_global_ship_properties_crack

View File

@@ -203,7 +203,8 @@
"InjectMethod": "local_patch", "InjectMethod": "local_patch",
"RequestTimeLimit": 10, "RequestTimeLimit": 10,
"UpdateServer": null, "UpdateServer": null,
"GameLibDir": null "GameLibDir": null,
"HookedLuaFunctionTrace": false
}, },
"Misc": { "Misc": {
"GlobalSpeedup": 1.0, "GlobalSpeedup": 1.0,

View File

@@ -809,6 +809,10 @@
"GameLibDir": { "GameLibDir": {
"type": "textarea", "type": "textarea",
"value": "" "value": ""
},
"HookedLuaFunctionTrace": {
"type": "checkbox",
"value": false
} }
}, },
"Misc": { "Misc": {

View File

@@ -837,6 +837,7 @@ HookGeneral:
GameLibDir: GameLibDir:
value: "" value: ""
type: textarea type: textarea
HookedLuaFunctionTrace: false
ShipProperty: ShipProperty:
Method: Method:
value: disable value: disable

View File

@@ -493,6 +493,7 @@ class GeneratedConfig:
HookGeneral_RequestTimeLimit = 10 HookGeneral_RequestTimeLimit = 10
HookGeneral_UpdateServer = None HookGeneral_UpdateServer = None
HookGeneral_GameLibDir = None HookGeneral_GameLibDir = None
HookGeneral_HookedLuaFunctionTrace = False
# Group `ShipProperty` # Group `ShipProperty`
ShipProperty_Method = 'disable' # disable, gg_factor, final_properties ShipProperty_Method = 'disable' # disable, gg_factor, final_properties

View File

@@ -139,6 +139,7 @@ class FullGeneratedConfig:
Hook_HookGeneral_RequestTimeLimit = None Hook_HookGeneral_RequestTimeLimit = None
Hook_HookGeneral_UpdateServer = None Hook_HookGeneral_UpdateServer = None
Hook_HookGeneral_GameLibDir = None Hook_HookGeneral_GameLibDir = None
Hook_HookGeneral_HookedLuaFunctionTrace = None
Hook_Misc_GlobalSpeedup = None Hook_Misc_GlobalSpeedup = None
Hook_Misc_BetterGlobalSpeedup = None Hook_Misc_BetterGlobalSpeedup = None
Hook_Misc_ChapterMove = None Hook_Misc_ChapterMove = None

View File

@@ -2931,6 +2931,10 @@
"GameLibDir": { "GameLibDir": {
"name": "HookGeneral.GameLibDir.name", "name": "HookGeneral.GameLibDir.name",
"help": "HookGeneral.GameLibDir.help" "help": "HookGeneral.GameLibDir.help"
},
"HookedLuaFunctionTrace": {
"name": "HookGeneral.HookedLuaFunctionTrace.name",
"help": "HookGeneral.HookedLuaFunctionTrace.help"
} }
}, },
"ShipProperty": { "ShipProperty": {

View File

@@ -2931,6 +2931,10 @@
"GameLibDir": { "GameLibDir": {
"name": "HookGeneral.GameLibDir.name", "name": "HookGeneral.GameLibDir.name",
"help": "HookGeneral.GameLibDir.help" "help": "HookGeneral.GameLibDir.help"
},
"HookedLuaFunctionTrace": {
"name": "HookGeneral.HookedLuaFunctionTrace.name",
"help": "HookGeneral.HookedLuaFunctionTrace.help"
} }
}, },
"ShipProperty": { "ShipProperty": {

View File

@@ -2931,6 +2931,10 @@
"GameLibDir": { "GameLibDir": {
"name": "游戏库目录", "name": "游戏库目录",
"help": "以x86架构为例目录一般为/data/app/<一串乱码>/<一串乱码>/lib/x86" "help": "以x86架构为例目录一般为/data/app/<一串乱码>/<一串乱码>/lib/x86"
},
"HookedLuaFunctionTrace": {
"name": "Lua函数追踪",
"help": "仅供调试使用,平时使用不要开"
} }
}, },
"ShipProperty": { "ShipProperty": {

View File

@@ -2931,6 +2931,10 @@
"GameLibDir": { "GameLibDir": {
"name": "HookGeneral.GameLibDir.name", "name": "HookGeneral.GameLibDir.name",
"help": "HookGeneral.GameLibDir.help" "help": "HookGeneral.GameLibDir.help"
},
"HookedLuaFunctionTrace": {
"name": "HookGeneral.HookedLuaFunctionTrace.name",
"help": "HookGeneral.HookedLuaFunctionTrace.help"
} }
}, },
"ShipProperty": { "ShipProperty": {

View File

@@ -319,3 +319,9 @@ class CrackApi:
def disable_opsi_no_map_fog(self): def disable_opsi_no_map_fog(self):
self.post("disable_opsi_no_map_fog") 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")

View File

@@ -17,6 +17,7 @@ from module.luahook.api import CrackApi
from module.luahook.op import CrackOp from module.luahook.op import CrackOp
ALL_ENABLE_OPS = [ ALL_ENABLE_OPS = [
CrackOp.EnableHookedLuaFunctionTrace,
CrackOp.EnableGlobalShipProperties, CrackOp.EnableGlobalShipProperties,
CrackOp.EnableChapterFastMove, CrackOp.EnableChapterFastMove,
CrackOp.EnableRemoveHardModeLimit, CrackOp.EnableRemoveHardModeLimit,
@@ -95,6 +96,11 @@ def do_crack_op(config: AzurLaneConfig, device: Device, ops: Union[Type[CrackOp.
for op in l: for op in l:
if op == CrackOp.DisableAll: if op == CrackOp.DisableAll:
api.disable_all() 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: elif op == CrackOp.EnableGlobalShipProperties:
if config.full_config.Hook_ShipProperty_Method != "final_properties": if config.full_config.Hook_ShipProperty_Method != "final_properties":
continue continue
@@ -283,6 +289,7 @@ def luahook_disable_all(config: AzurLaneConfig, device: Device):
CHAPTER_CRACK_OPS = [ CHAPTER_CRACK_OPS = [
CrackOp.EnableHookedLuaFunctionTrace,
CrackOp.EnableChapterFastMove, CrackOp.EnableChapterFastMove,
CrackOp.EnableNoBBAnimation, CrackOp.EnableNoBBAnimation,
CrackOp.EnableNoEmotionWarning, CrackOp.EnableNoEmotionWarning,
@@ -309,6 +316,7 @@ def chapter_task_crack(f):
OPSI_CRACK_OPS = [ OPSI_CRACK_OPS = [
CrackOp.EnableHookedLuaFunctionTrace,
CrackOp.EnableNoBBAnimation, CrackOp.EnableNoBBAnimation,
CrackOp.EnableOpsiFastMove, CrackOp.EnableOpsiFastMove,
CrackOp.EnableGlobalShipProperties, CrackOp.EnableGlobalShipProperties,

View File

@@ -8,6 +8,12 @@ class CrackOp:
class DisableAll(Op): class DisableAll(Op):
... ...
class EnableHookedLuaFunctionTrace(Op):
...
class DisableHookedLuaFunctionTrace(Op):
...
class EnableGlobalShipProperties(Op): class EnableGlobalShipProperties(Op):
... ...