[mod] Simplify. Split injections header. Force include mod header.

This commit is contained in:
lzwdgc 2024-04-22 15:23:19 +03:00
parent 0d5b4462e3
commit 5dc41c1d24
5 changed files with 52 additions and 45 deletions

View file

@ -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

View file

@ -1,32 +1,11 @@
#include <stdint.h>
#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 <string>
#include <string_view>
@ -446,7 +425,6 @@ BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) {
}
return TRUE;
}
#endif
#ifdef DONT_OPTIMIZE
#pragma optimize("", on)

View file

@ -0,0 +1,33 @@
#pragma once
#include <stdint.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 DONT_OPTIMIZE
#pragma optimize("", on)
#endif

View file

@ -1,5 +1,7 @@
#pragma once
#include "aim.exe.injections.h"
#include <db2.h>
#include <mmo2.h>
@ -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 <aim.exe.fixes.h>)");
//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);

5
sw.cpp
View file

@ -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");
{