Skip to content

Commit

Permalink
add activate_tiamat_position_hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Auto committed Sep 23, 2023
1 parent e3b4394 commit cf25b88
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/examples/activate_tiamat_position_hack.lua
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions src/game_api/entities_monsters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/game_api/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
1 change: 1 addition & 0 deletions src/game_api/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
5 changes: 5 additions & 0 deletions src/game_api/script/lua_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions src/game_api/script/usertypes/entities_monsters_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity, Movable, PowerupCapable, Monster>());

Expand Down
10 changes: 10 additions & 0 deletions src/game_api/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,16 @@ std::unordered_map<std::string_view, AddressRule> 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<std::string_view, size_t> g_cached_addresses;

Expand Down

0 comments on commit cf25b88

Please sign in to comment.