diff --git a/examples/mods/aim1_community_fix/my_mod.cpp b/examples/mods/aim1_community_fix/my_mod.cpp index 48c8563..2cd84ea 100644 --- a/examples/mods/aim1_community_fix/my_mod.cpp +++ b/examples/mods/aim1_community_fix/my_mod.cpp @@ -22,13 +22,6 @@ or patch_note(...) */ -#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" - // patch note: Authors and Credits // patch note: lz, Solant, Streef // patch note: @@ -76,8 +69,6 @@ int main(int argc, char *argv[]) { #endif + "-0.0.5"s ); - mod.add_code_file_for_archive(INJECTIONS_FILE_NAME); - mod.add_code_file_for_archive(AIM_TYPES_FILE_NAME); // this mod uses aim2 files (copy finder from there), so we must set up its path mod.setup_aim2_path(); mod.files_to_distribute.insert("language_switcher.exe"); @@ -245,8 +236,6 @@ int main(int argc, char *argv[]) { for (auto &&[n,_] : db["Глайдеры"]) { m2_gliders.erase(n); } - m2_gliders.erase("GL_BOT"); - m2_gliders.erase("GL_RACE1"); for (auto &&[n, _] : m2_gliders) { mod.copy_glider_from_aim2(n); } @@ -354,4 +343,4 @@ int main(int argc, char *argv[]) { return 0; } -#endif + diff --git a/src/aim1_mod_maker/aim.exe.fixes.h b/src/aim1_mod_maker/aim.exe.fixes.h index e873e99..1daa831 100644 --- a/src/aim1_mod_maker/aim.exe.fixes.h +++ b/src/aim1_mod_maker/aim.exe.fixes.h @@ -1,32 +1,11 @@ -#include +#pragma once + +#include "aim.exe.injections.h" #ifdef DONT_OPTIMIZE #pragma optimize("", off) #endif -constexpr auto call_command_length = 5; - -// 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) { - 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 @@ -446,7 +425,6 @@ BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) { } return TRUE; } -#endif #ifdef DONT_OPTIMIZE #pragma optimize("", on) diff --git a/src/aim1_mod_maker/aim.exe.injections.h b/src/aim1_mod_maker/aim.exe.injections.h new file mode 100644 index 0000000..4a54e46 --- /dev/null +++ b/src/aim1_mod_maker/aim.exe.injections.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +#ifdef DONT_OPTIMIZE +#pragma optimize("", off) +#endif + +constexpr auto call_command_length = 5; + +// 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) { + 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 DONT_OPTIMIZE +#pragma optimize("", on) +#endif diff --git a/src/aim1_mod_maker/aim1_mod_maker.h b/src/aim1_mod_maker/aim1_mod_maker.h index 1923796..965ee25 100644 --- a/src/aim1_mod_maker/aim1_mod_maker.h +++ b/src/aim1_mod_maker/aim1_mod_maker.h @@ -1,5 +1,7 @@ #pragma once +#include "aim.exe.injections.h" + #include #include @@ -158,13 +160,13 @@ struct mod_maker { return; } for (auto &&[_, v] : m) { - if (!v.m2.empty()) { + if (!v.m2.empty()) { v.copy_from_aim2(table_name, value_name, field_name); - } else { - // fallback + } else { + // fallback v.copy_from_aim2(this->operator[]("en_US").m2, table_name, value_name, field_name); } - } + } } void copy_from_aim2(auto &&table_name, auto &&value_name) { if (!mm.aim2_available()) { @@ -396,7 +398,6 @@ 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 -#ifdef INJECTIONS_FILE_NAME constexpr static inline auto call_command_length = 5; void make_injection(uint32_t virtual_address) { make_injection(virtual_address, get_injection_size(virtual_address)); @@ -431,7 +432,6 @@ struct mod_maker { void make_script_engine_injections() { make_injection(aim1_fix::script_function__ISGLIDER); } -#endif #define ENABLE_DISABLE_FUNC(name, enable, disable) \ void enable_##name() { name(enable); } \ @@ -810,7 +810,8 @@ private: void make_injected_dll() { log("making injected dll"); - path fn = loc.file_name(); + auto fn = get_mod_dir() / "inject.cpp"; + write_file(fn, R"(#include )"); //fs::copy_file(fn, get_mod_dir() / fn.filename(), fs::copy_options::overwrite_existing); std::string contents; contents += "void build(Solution &s) {\n"; @@ -821,10 +822,11 @@ private: contents += ");\n"; contents += " t += cpp23;\n"; contents += " t += \"" + boost::replace_all_copy(fn.string(), "\\", "/") + "\";\n"; - contents += " t += \"INJECTED_DLL\"_def;\n"; + //contents += " t += \"INJECTED_DLL\"_def;\n"; #if !defined(NDEBUG) contents += " t += \"DONT_OPTIMIZE\"_def;\n"; #endif + contents += "t += \"pub.lzwdgc.polygon4.tools.aim1.mod_maker.injections-master\"_dep;\n"; contents += "}\n"; write_file(get_mod_dir() / "sw.cpp", contents); diff --git a/sw.cpp b/sw.cpp index 9b2b157..941ddcc 100644 --- a/sw.cpp +++ b/sw.cpp @@ -103,6 +103,11 @@ void build(Solution &s) auto &aim1_mod_maker = add_exe_with_common("aim1.mod_maker", "aim1_mod_maker"); // actually a library aim1_mod_maker.Public += "pub.egorpugin.primitives.command"_dep; aim1_mod_maker.Public += "org.sw.demo.nlohmann.json.natvis"_dep; + aim1_mod_maker.Interface.ForceIncludeFiles.push_back("aim1_mod_maker.h"); + + auto &aim1_mod_maker_injections = aim1_mod_maker.addStaticLibrary("injections"); + aim1_mod_maker_injections.setRootDirectory("src/aim1_mod_maker"); + aim1_mod_maker_injections += "aim\\.exe\\..*\\.h"_rr; auto &aim1_community_fix = tools.addExecutable("examples.mods.aim1.community_fix"); {