Skip to content

Commit 1a7a3b4

Browse files
committed
Minor improvements
1 parent ec1f42d commit 1a7a3b4

3 files changed

Lines changed: 25 additions & 26 deletions

File tree

ModelVariations/Hooks.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ inline void hookCall(std::uintptr_t address, void* pFunction, std::string name,
6767
}
6868

6969
template <std::uintptr_t address, typename... Args>
70-
inline void callOriginal(Args... args)
70+
void callOriginal(Args... args)
7171
{
7272
auto it = hookedCalls.find(address);
7373
if (it != hookedCalls.end())
7474
reinterpret_cast<void(__cdecl*)(Args...)>(it->second.originalFunction)(args...);
7575
}
7676

7777
template <typename Ret, std::uintptr_t address, typename... Args>
78-
inline Ret callOriginalAndReturn(Args... args)
78+
Ret callOriginalAndReturn(Args... args)
7979
{
8080
auto it = hookedCalls.find(address);
8181
if (it != hookedCalls.end())
@@ -86,15 +86,15 @@ inline Ret callOriginalAndReturn(Args... args)
8686

8787

8888
template <std::uintptr_t address, typename C, typename... Args>
89-
inline void callMethodOriginal(C _this, Args... args)
89+
void callMethodOriginal(C _this, Args... args)
9090
{
9191
auto it = hookedCalls.find(address);
9292
if (it != hookedCalls.end())
9393
reinterpret_cast<void(__thiscall*)(C, Args...)>(it->second.originalFunction)(_this, args...);
9494
}
9595

9696
template <typename Ret, std::uintptr_t address, typename C, typename... Args>
97-
inline Ret callMethodOriginalAndReturn(C _this, Args... args)
97+
Ret callMethodOriginalAndReturn(C _this, Args... args)
9898
{
9999
auto it = hookedCalls.find(address);
100100
if (it != hookedCalls.end())
@@ -105,7 +105,7 @@ inline Ret callMethodOriginalAndReturn(C _this, Args... args)
105105

106106

107107
template <std::uintptr_t at, std::uintptr_t len = 5, class FuncT>
108-
inline void MakeInline(const char *funcName, const char* originalData, FuncT func)
108+
void MakeInline(const char *funcName, const char* originalData, FuncT func)
109109
{
110110
if (forceEnable || memcmp(at, originalData))
111111
injector::MakeInline<at, at+len>(func);

ModelVariations/ModelVariations.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,23 @@ std::string getDatetime(bool printDate, bool printTime, bool printMs)
202202
SYSTEMTIME systime;
203203
GetSystemTime(&systime);
204204
std::stringstream ss;
205-
std::string ms;
206-
207-
if (printMs)
208-
ms += "." + std::to_string(systime.wMilliseconds);
209205

210206
if (printDate)
211207
{
212208
ss << systime.wDay << "/" << systime.wMonth << "/" << systime.wYear;
213209

214-
if (!printTime)
215-
return ss.str();
216-
217-
ss << " ";
210+
if (printTime)
211+
ss << " ";
218212
}
219213

220-
ss << std::setfill('0') << std::setw(2) << systime.wHour << ":"
221-
<< std::setfill('0') << std::setw(2) << systime.wMinute << ":"
222-
<< std::setfill('0') << std::setw(2) << systime.wSecond << ms;
214+
if (printTime)
215+
{
216+
ss << std::setfill('0') << std::setw(2) << systime.wHour << ":"
217+
<< std::setfill('0') << std::setw(2) << systime.wMinute << ":"
218+
<< std::setfill('0') << std::setw(2) << systime.wSecond;
219+
if (printMs)
220+
ss << "." << std::setfill('0') << std::setw(3) << systime.wMilliseconds;
221+
}
223222

224223
return ss.str();
225224
}
@@ -235,7 +234,7 @@ bool LoadPESection(const char* filePath, int section, std::vector<unsigned char>
235234

236235
auto functionError = [&](const char* msg, int errorType)
237236
{
238-
std::cerr << msg << std::endl;
237+
Log::Write("Error logging jumps. %s.\n", msg);
239238
switch (errorType)
240239
{
241240
case 3:
@@ -250,11 +249,8 @@ bool LoadPESection(const char* filePath, int section, std::vector<unsigned char>
250249
};
251250

252251
hFile = CreateFileA(filePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
253-
if (hFile == INVALID_HANDLE_VALUE)
254-
{
255-
std::cerr << "Failed to open file" << std::endl;
256-
return false;
257-
}
252+
if (hFile == INVALID_HANDLE_VALUE)
253+
return functionError("Failed to open file", 0);
258254

259255
// Create a file mapping
260256
hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
@@ -853,6 +849,9 @@ class ModelVariations {
853849
{
854850
for (auto &it : hookedCalls)
855851
{
852+
if (it.second.name.empty())
853+
continue;
854+
856855
const std::uintptr_t functionAddress = (it.second.isVTableAddress == false) ? injector::GetBranchDestination(it.first).as_int() : *reinterpret_cast<unsigned int*>(it.first);
857856
std::pair<std::string, MODULEINFO> moduleInfo = LoadedModules::GetModuleAtAddress(functionAddress);
858857
std::string moduleName = moduleInfo.first.substr(moduleInfo.first.find_last_of("/\\") + 1);

ModelVariations/PedWeapons.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ int16_t __fastcall CollectParametersHooked(CRunningScript * _this, void*, unsign
310310

311311
void PedWeaponVariations::InstallHooks()
312312
{
313-
hookCall(0x62A12E, GiveWeaponAtStartOfFightHooked<0x62A12E>, "CPed::GiveWeaponAtStartOfFight");
314-
hookCall(0x47D335, GiveWeaponHooked<0x47D335>, "CPed::GiveWeapon");
315-
hookCall(0x47D4AC, CollectParametersHooked<0x47D4AC>, "CRunningScript::CollectParameters"); //SET_CURRENT_CHAR_WEAPON
316-
hookCall(0x48AE9E, CollectParametersHooked<0x48AE9E>, "CRunningScript::CollectParameters"); //HAS_CHAR_GOT_WEAPON
313+
hookCall(0x62A12E, GiveWeaponAtStartOfFightHooked<0x62A12E>, "CPed::GiveWeaponAtStartOfFight"); //CTaskSimpleFightingControl::ProcessPed
314+
hookCall(0x47D335, GiveWeaponHooked<0x47D335>, "CPed::GiveWeapon"); //01B2: GIVE_WEAPON_TO_CHAR
315+
hookCall(0x47D4AC, CollectParametersHooked<0x47D4AC>, "CRunningScript::CollectParameters"); //01B9: SET_CURRENT_CHAR_WEAPON
316+
hookCall(0x48AE9E, CollectParametersHooked<0x48AE9E>, "CRunningScript::CollectParameters"); //0491: HAS_CHAR_GOT_WEAPON
317317
}

0 commit comments

Comments
 (0)