From cf25b88e8a82a887b1e98dd35139f50ee56549a9 Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Sat, 23 Sep 2023 19:40:27 +0200 Subject: [PATCH] add `activate_tiamat_position_hack` --- docs/examples/activate_tiamat_position_hack.lua | 9 +++++++++ src/game_api/entities_monsters.hpp | 4 ++++ src/game_api/rpc.cpp | 13 +++++++++++++ src/game_api/rpc.hpp | 1 + src/game_api/script/lua_vm.cpp | 5 +++++ .../script/usertypes/entities_monsters_lua.cpp | 4 ++++ src/game_api/search.cpp | 10 ++++++++++ 7 files changed, 46 insertions(+) create mode 100644 docs/examples/activate_tiamat_position_hack.lua diff --git a/docs/examples/activate_tiamat_position_hack.lua b/docs/examples/activate_tiamat_position_hack.lua new file mode 100644 index 000000000..431b65f3c --- /dev/null +++ b/docs/examples/activate_tiamat_position_hack.lua @@ -0,0 +1,9 @@ +activate_tiamat_position_hack(true); + +set_post_entity_spawn(function(ent) + + -- make them same as in the game, but relative to the tiamat entity + ent.attack_x = ent.x - 1 + ent.attack_y = ent.y + 2 + +end, SPAWN_TYPE.ANY, 0, ENT_TYPE.MONS_TIAMAT) \ No newline at end of file diff --git a/src/game_api/entities_monsters.hpp b/src/game_api/entities_monsters.hpp index e03e58784..e9aec55c6 100644 --- a/src/game_api/entities_monsters.hpp +++ b/src/game_api/entities_monsters.hpp @@ -796,6 +796,10 @@ class Tiamat : public Monster float tail_radian; // Counts from 0 to 2*pi, Used to calculate tail angle float tail_move_speed; float right_arm_angle; + /// This is cusome variable, you need [activate_tiamat_position_hack](#activate_tiamat_position_hack) to use it + float attack_x; + /// This is cusome variable, you need [activate_tiamat_position_hack](#activate_tiamat_position_hack) to use it + float attack_y; }; class GiantFrog : public Monster diff --git a/src/game_api/rpc.cpp b/src/game_api/rpc.cpp index a1331e500..976e7504f 100644 --- a/src/game_api/rpc.cpp +++ b/src/game_api/rpc.cpp @@ -1891,3 +1891,16 @@ void set_tiamat_cutscene_enabled(bool enable) { set_skip_tiamat_cutscene(!enable); } + +void activate_tiamat_position_hack(bool activate) +{ + static const auto code_addr = get_address("tiamat_attack_position"); + + static const std::string_view code{"\xF3\x0F\x5C\xBE\x78\x01\x00\x00"sv // subss xmm7,DWORD PTR [rsi+0x178] + "\xF3\x0F\x5C\xB6\x7C\x01\x00\x00"sv}; // subss xmm6,DWORD PTR [rsi+0x17C] + + if (activate) + write_mem_recoverable("activate_tiamat_position_hack", code_addr, code, true); + else + recover_mem("activate_tiamat_position_hack"); +} diff --git a/src/game_api/rpc.hpp b/src/game_api/rpc.hpp index 44b36aa8e..07c84cee8 100644 --- a/src/game_api/rpc.hpp +++ b/src/game_api/rpc.hpp @@ -139,3 +139,4 @@ void set_level_string(std::u16string_view text); void set_ending_unlock(ENT_TYPE type); void set_olmec_cutscene_enabled(bool enable); void set_tiamat_cutscene_enabled(bool enable); +void activate_tiamat_position_hack(bool activate); diff --git a/src/game_api/script/lua_vm.cpp b/src/game_api/script/lua_vm.cpp index 8d1d84a09..555119dfd 100644 --- a/src/game_api/script/lua_vm.cpp +++ b/src/game_api/script/lua_vm.cpp @@ -2018,6 +2018,11 @@ end lua["set_tiamat_cutscene_enabled"] = set_tiamat_cutscene_enabled; + /// Activate custom variables for position used for detecting the player (normally hardcoded) + /// note: because those variables are custom and game does not initiate them, you need to do it yourself for each Tiamat entity, recommending `set_post_entity_spawn` + /// default game values are: attack_x = 17.5 attack_y = 62.5 + lua["activate_tiamat_position_hack"] = activate_tiamat_position_hack; + lua.create_named_table("INPUTS", "NONE", 0, "JUMP", 1, "WHIP", 2, "BOMB", 4, "ROPE", 8, "RUN", 16, "DOOR", 32, "MENU", 64, "JOURNAL", 128, "LEFT", 256, "RIGHT", 512, "UP", 1024, "DOWN", 2048); lua.create_named_table( diff --git a/src/game_api/script/usertypes/entities_monsters_lua.cpp b/src/game_api/script/usertypes/entities_monsters_lua.cpp index c99b830e0..f9ac95a2e 100644 --- a/src/game_api/script/usertypes/entities_monsters_lua.cpp +++ b/src/game_api/script/usertypes/entities_monsters_lua.cpp @@ -947,6 +947,10 @@ void register_usertypes(sol::state& lua) &Tiamat::tail_move_speed, "right_arm_angle", &Tiamat::right_arm_angle, + "attack_x", + &Tiamat::attack_x, + "attack_y", + &Tiamat::attack_y, sol::base_classes, sol::bases()); diff --git a/src/game_api/search.cpp b/src/game_api/search.cpp index 56ff2bdec..b44962496 100644 --- a/src/game_api/search.cpp +++ b/src/game_api/search.cpp @@ -2002,6 +2002,16 @@ std::unordered_map g_address_rules{ .offset(0x6) // after the jump instruction .at_exe(), }, + { + "tiamat_attack_position"sv, + // default 17.5, 62.5 + PatternCommandBuffer{} + .get_virtual_function_address(VTABLE_OFFSET::MONS_TIAMAT, (VIRT_FUNC)78) + .find_after_inst("45 0F 57 C0"_gh) + .find_inst("\xF3"sv) + .offset(0xA) + .at_exe(), + }, }; std::unordered_map g_cached_addresses;