From bbc28a0a8bd11ee805ce5e131365874464ba33cf Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 5 Jul 2017 17:57:52 +0200 Subject: [PATCH] [IW4MVM] Include IW4MVM --- .gitmodules | 3 ++ deps/iw4mvm | 1 + premake/iw4mvm.lua | 54 +++++++++++++++++++++++++++++++ premake/zlib.lua | 7 +--- premake5.lua | 13 ++++++++ src/Components/Loader.cpp | 3 ++ src/Components/Loader.hpp | 1 + src/Components/Modules/IW4MVM.cpp | 22 +++++++++++++ src/Components/Modules/IW4MVM.hpp | 11 +++++++ src/Main.cpp | 1 - 10 files changed, 109 insertions(+), 7 deletions(-) create mode 160000 deps/iw4mvm create mode 100644 premake/iw4mvm.lua create mode 100644 src/Components/Modules/IW4MVM.cpp create mode 100644 src/Components/Modules/IW4MVM.hpp diff --git a/.gitmodules b/.gitmodules index 5285d472..f055980d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -29,3 +29,6 @@ [submodule "deps/udis86"] path = deps/udis86 url = ../udis86.git +[submodule "deps/iw4mvm"] + path = deps/iw4mvm + url = ../../luckyy/IW4MVM_IW4X.git diff --git a/deps/iw4mvm b/deps/iw4mvm new file mode 160000 index 00000000..b46e28f4 --- /dev/null +++ b/deps/iw4mvm @@ -0,0 +1 @@ +Subproject commit b46e28f4cf044699433ff2dff459f498e418a430 diff --git a/premake/iw4mvm.lua b/premake/iw4mvm.lua new file mode 100644 index 00000000..c2823227 --- /dev/null +++ b/premake/iw4mvm.lua @@ -0,0 +1,54 @@ +iw4mvm = { + settings = nil +} + +function iw4mvm.setup(settings) + if not settings.source then error("Missing source.") end + + iw4mvm.settings = settings + + if not iw4mvm.settings.defines then iw4mvm.settings.defines = {} end +end + +function iw4mvm.import() + if not iw4mvm.settings then error("You need to call iw4mvm.setup first") end + + links { "iw4mvm" } + iw4mvm.includes() +end + +function iw4mvm.includes() + if not iw4mvm.settings then error("You need to call iw4mvm.setup first") end + + includedirs { iw4mvm.settings.source } + libdirs { path.join(iw4mvm.settings.source, "IW4MVM") } + defines(iw4mvm.settings.defines) +end + +function iw4mvm.project() + if not iw4mvm.settings then error("You need to call iw4mvm.setup first") end + + project "iw4mvm" + language "C++" + + characterset ("MBCS") + + defines("_CRT_SECURE_NO_WARNINGS") + + iw4mvm.includes() + files + { + path.join(iw4mvm.settings.source, "IW4MVM/*.h"), + path.join(iw4mvm.settings.source, "IW4MVM/*.cpp"), + } + + removefiles + { + --path.join(iw4mvm.settings.source, "IW4MVM/detours.cpp"), + path.join(iw4mvm.settings.source, "IW4MVM/DllMain.cpp"), + } + + -- not our code, ignore POSIX usage warnings for now + warnings "Off" + kind "StaticLib" +end \ No newline at end of file diff --git a/premake/zlib.lua b/premake/zlib.lua index 77d4c349..6657b56e 100644 --- a/premake/zlib.lua +++ b/premake/zlib.lua @@ -21,7 +21,6 @@ function zlib.includes() if not zlib.settings then error("You need to call zlib.setup first") end includedirs { zlib.settings.source } - defines { "ssize_t=int" } defines(zlib.settings.defines) end @@ -46,9 +45,5 @@ function zlib.project() -- not our code, ignore POSIX usage warnings for now warnings "Off" - kind "SharedLib" - --configuration "*Static" - defines { "_LIB" } - removedefines { "_USRDLL", "_DLL", "ZLIB_DLL" } - kind "StaticLib" + kind "StaticLib" end \ No newline at end of file diff --git a/premake5.lua b/premake5.lua index 9b0be67f..dc08828e 100644 --- a/premake5.lua +++ b/premake5.lua @@ -181,6 +181,7 @@ require "premake/pdcurses" require "premake/protobuf" require "premake/zlib" require "premake/udis86" +require "premake/iw4mvm" json11.setup { @@ -218,6 +219,7 @@ zlib.setup { defines = { "ZLIB_CONST", + "ssize_t=int" }, source = path.join(depsBasePath, "zlib"), } @@ -225,6 +227,15 @@ udis86.setup { source = path.join(depsBasePath, "udis86"), } +iw4mvm.setup +{ + defines = { + "IW4X", + "DETOURS_X86", + "DETOURS_32BIT", + }, + source = path.join(depsBasePath, "iw4mvm"), +} workspace "iw4x" location "./build" @@ -312,6 +323,7 @@ workspace "iw4x" protobuf.import() zlib.import() udis86.import() + iw4mvm.import() -- fix vpaths for protobuf sources vpaths @@ -424,6 +436,7 @@ workspace "iw4x" protobuf.project() zlib.project() udis86.project() + iw4mvm.project() rule "ProtobufCompiler" display "Protobuf compiler" diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 5f0d5c87..6000beba 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -49,6 +49,9 @@ namespace Components Loader::Register(new Zones()); Loader::Register(new Colors()); Loader::Register(new D3D9Ex()); +#if !defined(VLD_RPTHOOK_INSTALL) || defined(VLDEnable) // IW4MVM uses detours which produces memory leaks, but those are not really relevant + Loader::Register(new IW4MVM()); +#endif Loader::Register(new Logger()); Loader::Register(new Script()); Loader::Register(new Weapon()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 076d6470..3c9a5699 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -89,6 +89,7 @@ namespace Components #include "Modules/Node.hpp" #include "Modules/RCon.hpp" #include "Modules/Party.hpp" // Destroys the order, but requires network classes :D +#include "Modules/IW4MVM.hpp" #include "Modules/Logger.hpp" #include "Modules/Friends.hpp" #include "Modules/IPCPipe.hpp" diff --git a/src/Components/Modules/IW4MVM.cpp b/src/Components/Modules/IW4MVM.cpp new file mode 100644 index 00000000..5e37b9b5 --- /dev/null +++ b/src/Components/Modules/IW4MVM.cpp @@ -0,0 +1,22 @@ +#include "STDInclude.hpp" +#include + +namespace Components +{ + IW4MVM::IW4MVM() + { + DWORD oldProtect; + std::uint8_t* module = reinterpret_cast(GetModuleHandle(nullptr)); + VirtualProtect(module + 0x1000, 0x2D6000, PAGE_EXECUTE_READWRITE, &oldProtect); + + client_main::Init(); + Scheduler::Once(client_main::PostInit); + + VirtualProtect(module + 0x1000, 0x2D6000, PAGE_EXECUTE_READ, &oldProtect); + } + + IW4MVM::~IW4MVM() + { + + } +} diff --git a/src/Components/Modules/IW4MVM.hpp b/src/Components/Modules/IW4MVM.hpp new file mode 100644 index 00000000..3e1c7cd0 --- /dev/null +++ b/src/Components/Modules/IW4MVM.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace Components +{ + class IW4MVM : public Component + { + public: + IW4MVM(); + ~IW4MVM(); + }; +} diff --git a/src/Main.cpp b/src/Main.cpp index feecc890..0bbfd104 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -70,7 +70,6 @@ BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*l DWORD oldProtect; std::uint8_t* module = reinterpret_cast(GetModuleHandle(nullptr)); - //VirtualProtect(module, 0x6C73000, PAGE_EXECUTE_READWRITE, &oldProtect); // Unprotect the entire process VirtualProtect(module + 0x1000, 0x2D6000, PAGE_EXECUTE_READ, &oldProtect); // Protect the .text segment // Install entry point hook