与metamod兼容
This commit is contained in:
@@ -154,6 +154,7 @@
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<Optimization>Disabled</Optimization>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
||||
@@ -37,6 +37,7 @@ auto init(void* ctx) -> bool {
|
||||
|
||||
Sleep(200);
|
||||
}
|
||||
global::isMetaModInit = (GetModuleHandleA("metamod.2.cs2.dll") != nullptr);
|
||||
if (Offset::Init() == false) {
|
||||
LOG("Offset::Init() == false !\n");
|
||||
return false;
|
||||
|
||||
@@ -7,4 +7,5 @@ namespace global {
|
||||
CGlobalVars* GlobalVars;
|
||||
float m_flUniversalTime;
|
||||
float m_flLastTickedTime;
|
||||
bool isMetaModInit;
|
||||
}
|
||||
@@ -10,4 +10,5 @@ namespace global {
|
||||
extern CGlobalVars* GlobalVars;
|
||||
extern float m_flUniversalTime;
|
||||
extern float m_flLastTickedTime;
|
||||
extern bool isMetaModInit;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "memory.h"
|
||||
namespace Memory {
|
||||
auto PathVscript() -> void {
|
||||
CModule vscript_old("vscript_old.dll");
|
||||
CModule vscript("vscript.dll");
|
||||
|
||||
uint64_t vscriptPathAddr = 0;
|
||||
if (vscript_old.IsLoaded() == true) {
|
||||
vscript_old.FindPattern(Offset::pattern_VscriptPath).Get(vscriptPathAddr);
|
||||
}
|
||||
else {
|
||||
vscript.FindPattern(Offset::pattern_VscriptPath).Get(vscriptPathAddr);
|
||||
}
|
||||
if (vscriptPathAddr != 0) {
|
||||
const static char PatchVScriptEnable[] = { 0xBE, 0x02 };
|
||||
DWORD oldProtect;
|
||||
VirtualProtect(reinterpret_cast<void*>(vscriptPathAddr), sizeof(PatchVScriptEnable), PAGE_EXECUTE_READWRITE, &oldProtect);
|
||||
memcpy(reinterpret_cast<void*>(vscriptPathAddr), PatchVScriptEnable, sizeof(PatchVScriptEnable));
|
||||
VirtualProtect(reinterpret_cast<void*>(vscriptPathAddr), sizeof(PatchVScriptEnable), oldProtect, &oldProtect);
|
||||
LOG("success patch vscript at %llx \n", vscriptPathAddr);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -14,5 +14,5 @@ namespace Memory {
|
||||
ReadProcessMemory(GetCurrentProcess(), (void*)address, &buffer, sizeof(T), 0);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
auto PathVscript() -> void;
|
||||
};
|
||||
@@ -2,6 +2,10 @@
|
||||
#include "head.h"
|
||||
#define IS_WINDOWS 1
|
||||
class InterfaceReg;
|
||||
//cancer fix me plz
|
||||
namespace global {
|
||||
extern bool isMetaModInit;
|
||||
};
|
||||
// Pointer arithmetic utility class.
|
||||
struct UTILPtr {
|
||||
public:
|
||||
@@ -65,10 +69,8 @@ class CModule {
|
||||
UTILPtr GetProcAddress(const char* procName) const {
|
||||
UTILPtr rv = 0;
|
||||
if (this->IsLoaded()) {
|
||||
#ifdef IS_WINDOWS
|
||||
rv = ::GetProcAddress(static_cast<HMODULE>(this->m_handle),
|
||||
procName);
|
||||
#endif
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@@ -77,11 +79,7 @@ class CModule {
|
||||
if (this->IsLoaded()) {
|
||||
UTILPtr pCreateInterface = this->GetProcAddress("CreateInterface");
|
||||
if (!pCreateInterface.IsValid()) return rv;
|
||||
|
||||
InterfaceReg* s_pInterfaceRegs = pCreateInterface.ToAbsolute(3, 0)
|
||||
.Dereference(1)
|
||||
.Get<InterfaceReg*>();
|
||||
|
||||
auto s_pInterfaceRegs = pCreateInterface.ToAbsolute(3, 0).Dereference(1).Get<InterfaceReg*>();
|
||||
for (; s_pInterfaceRegs;
|
||||
s_pInterfaceRegs = s_pInterfaceRegs->m_pNext) {
|
||||
if (strcmp(version, s_pInterfaceRegs->m_pName) == 0) {
|
||||
@@ -121,9 +119,36 @@ class CModule {
|
||||
|
||||
private:
|
||||
void InitializeHandle() {
|
||||
#ifdef IS_WINDOWS
|
||||
if (global::isMetaModInit == false) {
|
||||
this->m_handle = static_cast<void*>(GetModuleHandleA(this->GetName()));
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
DWORD cbNeeded;
|
||||
|
||||
// Call EnumProcessModules with a null hMods parameter to get the needed size.
|
||||
EnumProcessModules(hProcess, nullptr, 0, &cbNeeded);
|
||||
int moduleCount = cbNeeded / sizeof(HMODULE);
|
||||
std::vector<HMODULE> hMods(moduleCount);
|
||||
|
||||
if (EnumProcessModules(hProcess, hMods.data(), cbNeeded, &cbNeeded))
|
||||
{
|
||||
for (const auto& hMod : hMods)
|
||||
{
|
||||
char szModName[MAX_PATH];
|
||||
|
||||
if (GetModuleFileNameExA(hProcess, hMod, szModName, sizeof(szModName) / sizeof(char)))
|
||||
{
|
||||
const auto fullModulePath = std::string(szModName);
|
||||
if (fullModulePath.find("metamod") == std::string::npos && fullModulePath.ends_with(this->GetName()) == true) {
|
||||
this->m_handle = static_cast<void*>(hMod);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
void InitializeBounds() {
|
||||
if (!this->IsLoaded()) return;
|
||||
|
||||
@@ -49,33 +49,14 @@ auto SafeDelayInit(void* ctx) -> void {
|
||||
LOG("m_bForceTeamChangeSilent: %d \n",
|
||||
InterFaces::CCSGameRulesInterFace->m_bForceTeamChangeSilent());
|
||||
}
|
||||
auto PathVscript() -> void {
|
||||
CModule vscript_old("vscript_old.dll");
|
||||
CModule vscript("vscript.dll");
|
||||
|
||||
uint64_t vscriptPathAddr = 0;
|
||||
if (vscript_old.IsLoaded() == true) {
|
||||
vscript_old.FindPattern(pattern_VscriptPath).Get(vscriptPathAddr);
|
||||
}
|
||||
else {
|
||||
vscript.FindPattern(pattern_VscriptPath).Get(vscriptPathAddr);
|
||||
}
|
||||
if (vscriptPathAddr != 0) {
|
||||
const static char PatchVScriptEnable[] = {0xBE, 0x02};
|
||||
DWORD oldProtect;
|
||||
VirtualProtect(reinterpret_cast<void*>(vscriptPathAddr), sizeof(PatchVScriptEnable), PAGE_EXECUTE_READWRITE, &oldProtect);
|
||||
memcpy(reinterpret_cast<void*>(vscriptPathAddr), PatchVScriptEnable, sizeof(PatchVScriptEnable));
|
||||
VirtualProtect(reinterpret_cast<void*>(vscriptPathAddr), sizeof(PatchVScriptEnable), oldProtect, &oldProtect);
|
||||
LOG("success patch vscript at %llx \n", vscriptPathAddr);
|
||||
}
|
||||
}
|
||||
auto Init() -> bool {
|
||||
CModule server("server.dll");
|
||||
CModule schemasystem("schemasystem.dll");
|
||||
CModule engine("engine2.dll");
|
||||
CModule localize("localize.dll");
|
||||
CModule tier0("tier0.dll");
|
||||
PathVscript();
|
||||
Memory::PathVscript();
|
||||
|
||||
// engine.dll
|
||||
engine.FindPattern(pattern_MaxPlayerNumsPtr)
|
||||
|
||||
Reference in New Issue
Block a user