From 0cd7f72e257a8651229d19ca1eeca7cd4851c67e Mon Sep 17 00:00:00 2001 From: lzwdgc Date: Tue, 2 Apr 2024 12:22:13 +0300 Subject: [PATCH] [mod] Use injections enums. Group up injection sizes. --- .../mods/aim1_community_fix/aim.exe.fixes.h | 40 ++++++++++++------- examples/mods/aim1_community_fix/my_mod.cpp | 20 +++++----- src/aim1_mod_maker/aim1_mod_maker.h | 5 ++- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/examples/mods/aim1_community_fix/aim.exe.fixes.h b/examples/mods/aim1_community_fix/aim.exe.fixes.h index ad3a3f6..8a4dd48 100644 --- a/examples/mods/aim1_community_fix/aim.exe.fixes.h +++ b/examples/mods/aim1_community_fix/aim.exe.fixes.h @@ -1,13 +1,32 @@ +#include + +// public enums +enum aim1_fix : uint32_t { + script_function__ISGLIDER = 0x0043A1F6, + trade_actions_weapon_checks = 0x004072FA, + setup_proper_weapon_slots_for_a_glider = 0x004D62E4, + put_weapon_into_the_right_slot_after_purchase = 0x00417A6D, + sell_correct_weapon = 0x004176BC, + empty_light_weapon_message = 0x004067C4, + empty_heavy_weapon_message = 0x0040688B, + can_leave_trade_window = 0x0040C20E, +}; +// set different size if your injection takes more than default 5 bytes +uint32_t get_injection_size(uint32_t key) { + constexpr auto call_command_length = 5; + switch (key) { + case aim1_fix::script_function__ISGLIDER: return 10; + case aim1_fix::can_leave_trade_window: return 6; + default: return call_command_length; + } +} + +#ifdef INJECTED_DLL #include #include -#include #include -/*struct char20 { - char string[20]; -};*/ - #define _BYTE uint8_t #define this #define __unaligned @@ -19,16 +38,6 @@ using namespace std::literals; constexpr auto call_command_length = 5; -enum aim1_fix : uint32_t { - script_function__ISGLIDER = 0x0043A1F6, - trade_actions_weapon_checks = 0x004072FA, - setup_proper_weapon_slots_for_a_glider = 0x004D62E4, - put_weapon_into_the_right_slot_after_purchase = 0x00417A6D, - sell_correct_weapon = 0x004176BC, - empty_light_weapon_message = 0x004067C4, - empty_heavy_weapon_message = 0x0040688B, - can_leave_trade_window = 0x0040C20E, -}; uint32_t known_caller; auto player_ptr = (Player **)0x005B7B38; auto get_player_ptr() { @@ -440,3 +449,4 @@ BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) { } return TRUE; } +#endif diff --git a/examples/mods/aim1_community_fix/my_mod.cpp b/examples/mods/aim1_community_fix/my_mod.cpp index 829d129..cbe92f0 100644 --- a/examples/mods/aim1_community_fix/my_mod.cpp +++ b/examples/mods/aim1_community_fix/my_mod.cpp @@ -16,6 +16,7 @@ deps: pub.lzwdgc.Polygon4.Tools.aim1.mod_maker-master #define AIM_TYPES_FILE_NAME "aim.exe.h" #define INJECTIONS_FILE_NAME "aim.exe.fixes.h" +#include INJECTIONS_FILE_NAME #ifndef INJECTED_DLL #include "aim1_mod_maker.h" @@ -128,7 +129,7 @@ int main(int argc, char *argv[]) { "IF(_ISGLIDER(GL_S2_PA_SINYGR)|_ISGLIDER(GL_S4_S_SINYGR))"); // patch note: * _ISGLIDER() function can check exact glider name now, for example _ISGLIDER(GL_M3_A_FIRST1) (lz) - mod.make_injection(0x0043A1F6, 10); + mod.make_injection(aim1_fix::script_function__ISGLIDER); // end of scripts section // patch note: @@ -193,13 +194,13 @@ int main(int argc, char *argv[]) { // patch note: double light weapons: GL_M2_PA_NARGOON and GL_S3_PS_FINDER1 // patch note: double heavy weapons: GL_M3_PA_EYEDSTONE and GL_S3_PS_FINDER2 // patch note: (still have many bugs related) - mod.make_injection(0x004072FA); // can trade for buy purposes - mod.make_injection(0x004D62E4); // setup proper weapon slots for a glider - mod.make_injection(0x00417A6D); // put weapon into the right slot after purchase - mod.make_injection(0x004176BC); // sell correct weapon - mod.make_injection(0x004067C4); // empty light weap - mod.make_injection(0x0040688B); // empty heavy weap - mod.make_injection(0x0040C20E, 6); // can_leave_trade_window + mod.make_injection(aim1_fix::trade_actions_weapon_checks); + mod.make_injection(aim1_fix::setup_proper_weapon_slots_for_a_glider); + mod.make_injection(aim1_fix::put_weapon_into_the_right_slot_after_purchase); + mod.make_injection(aim1_fix::sell_correct_weapon); + mod.make_injection(aim1_fix::empty_light_weapon_message); + mod.make_injection(aim1_fix::empty_heavy_weapon_message); + mod.make_injection(aim1_fix::can_leave_trade_window); // patch note: // test scripts @@ -285,7 +286,4 @@ int main(int argc, char *argv[]) { return 0; } - -#else // INJECTED_DLL -#include INJECTIONS_FILE_NAME #endif diff --git a/src/aim1_mod_maker/aim1_mod_maker.h b/src/aim1_mod_maker/aim1_mod_maker.h index 0929189..9a0c674 100644 --- a/src/aim1_mod_maker/aim1_mod_maker.h +++ b/src/aim1_mod_maker/aim1_mod_maker.h @@ -278,7 +278,10 @@ struct mod_maker { // all you need is to provide injection address (virtual) with size // handle the call instruction in 'dispatcher' symbol (naked) of your dll constexpr static inline auto call_command_length = 5; - void make_injection(uint32_t virtual_address, uint32_t size = call_command_length) { + void make_injection(uint32_t virtual_address) { + make_injection(virtual_address, get_injection_size(virtual_address)); + } + void make_injection(uint32_t virtual_address, uint32_t size) { uint32_t len = size; if (len < call_command_length) { throw std::runtime_error{"jumppad must be 5 bytes atleast"};