Skip to content

Commit 616cdf6

Browse files
committed
ChaosMod: Ported PedModel pool to Enhanced
1 parent 802d439 commit 616cdf6

File tree

4 files changed

+56
-27
lines changed

4 files changed

+56
-27
lines changed

ChaosMod/Components/Failsafe.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Failsafe::Failsafe() : Component()
3030
if (!ms_SearchedForMissionStateGlobal && !ms_StateGlobalIdx && !strcmp(thread->GetName(), "main"))
3131
{
3232
auto program = Memory::ScriptThreadToProgram(thread);
33-
if (program->m_CodeBlocks)
33+
if (program && program->m_CodeBlocks)
3434
{
3535
ms_SearchedForMissionStateGlobal = true;
3636

ChaosMod/Lib/scrThread.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
#include <scripthookv/inc/main.h>
4-
53
#include "game.h"
64

75
using DWORD = unsigned long;

ChaosMod/Memory/PedModels.h

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include "game.h"
4+
35
#include "Handle.h"
46
#include "Memory.h"
57

@@ -21,31 +23,60 @@ namespace Memory
2123
{
2224
Handle handle;
2325

24-
handle = FindPattern("41 F7 F0 48 8B 05 ? ? ? 00 4C");
25-
if (!handle.IsValid())
26-
return pedModels;
26+
DWORD64 archetypeMap_Map;
27+
WORD archetypeMap_Slots;
28+
DWORD64 archetypePool_ElemSize;
29+
DWORD64 archetypePool_PoolPtr;
30+
DWORD archetypePool_Size;
31+
DWORD64 archetypePool_AllocatedMap_Bits;
32+
33+
if (IsLegacy())
34+
{
35+
handle = FindPattern("41 F7 F0 48 8B 05 ? ? ? 00 4C");
36+
if (!handle.IsValid())
37+
return pedModels;
38+
39+
archetypeMap_Map = handle.At(5).Into().Value<DWORD64>();
40+
archetypeMap_Slots = handle.At(-28).Into().Value<WORD>();
2741

28-
DWORD64 qword_7FF69DB37F30 = handle.At(5).Into().Value<DWORD64>();
42+
handle = FindPattern("73 17 4C 0F AF 05");
43+
if (!handle.IsValid())
44+
return pedModels;
2945

30-
WORD word_7FF69DB37F38 = handle.At(-28).Into().Value<WORD>();
46+
archetypePool_ElemSize = handle.At(5).Into().Value<DWORD64>();
47+
archetypePool_PoolPtr = handle.At(12).Into().Value<DWORD64>();
3148

32-
handle = FindPattern("73 17 4C 0F AF 05");
33-
if (!handle.IsValid())
34-
return pedModels;
49+
handle = FindPattern("3B 05 ? ? ? 00 7D 35");
50+
if (!handle.IsValid())
51+
return pedModels;
3552

36-
DWORD64 qword_7FF69DB37EE8 = handle.At(5).Into().Value<DWORD64>();
37-
DWORD64 qword_7FF69DB37ED0 = handle.At(12).Into().Value<DWORD64>();
53+
archetypePool_Size = handle.At(1).Into().Value<DWORD>();
54+
archetypePool_AllocatedMap_Bits = handle.At(18).Into().Value<DWORD64>();
55+
}
56+
else
57+
{
58+
handle = Memory::FindPattern("74 7C 49 89 D0 4C 8B 1D");
3859

39-
handle = FindPattern("3B 05 ? ? ? 00 7D 35");
40-
if (!handle.IsValid())
41-
return pedModels;
60+
if (!handle.IsValid())
61+
return pedModels;
4262

43-
DWORD dword_7FF69DB37ED8 = handle.At(1).Into().Value<DWORD>();
44-
DWORD64 qword_7FF69DB37F00 = handle.At(18).Into().Value<DWORD64>();
63+
archetypeMap_Map = handle.At(7).Into().Value<DWORD64>();
64+
archetypeMap_Slots = handle.At(-8).Into().Value<WORD>();
65+
66+
handle = Memory::FindPattern("7D 36 48 8B 05");
67+
68+
archetypePool_Size = handle.At(-5).Into().Value<DWORD>();
69+
archetypePool_AllocatedMap_Bits = handle.At(4).Into().Value<DWORD64>();
70+
71+
archetypePool_PoolPtr = handle.At(27).Into().Value<DWORD64>();
72+
archetypePool_ElemSize = handle.At(43).Into().Value<DWORD64>();
73+
74+
DEBUG_LOG(archetypeMap_Map << " " << archetypeMap_Slots << " " << archetypePool_Size << " " << archetypePool_AllocatedMap_Bits << " " << archetypePool_PoolPtr << " " << archetypePool_ElemSize);
75+
}
4576

46-
for (WORD i = 0; i < word_7FF69DB37F38; i++)
77+
for (WORD i = 0; i < archetypeMap_Slots; i++)
4778
{
48-
auto model = *reinterpret_cast<Hash **>(qword_7FF69DB37F30 + 8 * i);
79+
auto model = *reinterpret_cast<Hash **>(archetypeMap_Map + 8 * i);
4980
if (!model)
5081
continue;
5182

@@ -59,13 +90,13 @@ namespace Memory
5990
DWORD64 v5 = *reinterpret_cast<WORD *>(model + 4);
6091
LONG v6;
6192
// IDA copy paste ftw
62-
if (static_cast<DWORD>(v5) < dword_7FF69DB37ED8
63-
&& (v6 = *reinterpret_cast<DWORD *>(qword_7FF69DB37F00 + 4 * (v5 >> 5)),
93+
if (static_cast<DWORD>(v5) < archetypePool_Size
94+
&& (v6 = *reinterpret_cast<DWORD *>(archetypePool_AllocatedMap_Bits + 4 * (v5 >> 5)),
6495
_bittest(&v6, v5 & 0x1F)))
6596
{
6697
v2 = *reinterpret_cast<__int64 *>(
67-
qword_7FF69DB37ED0
68-
+ qword_7FF69DB37EE8 * *reinterpret_cast<WORD *>(reinterpret_cast<__int64>(model) + 4));
98+
archetypePool_PoolPtr
99+
+ archetypePool_ElemSize * *reinterpret_cast<WORD *>(reinterpret_cast<__int64>(model) + 4));
69100
}
70101

71102
if (v2 && (*reinterpret_cast<BYTE *>(v2 + 157) & 31) == 6) // is a ped model

ChaosMod/game.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ enum class GameVersion
88
GTA5_ENHANCED
99
};
1010

11-
GameVersion GetGame()
11+
inline GameVersion GetGame()
1212
{
1313
static GameVersion result = getGameVersion() > 1000 ? GameVersion::GTA5_ENHANCED : GameVersion::GTA5_LEGACY;
1414
return result;
1515
}
1616

17-
bool IsEnhanced()
17+
inline bool IsEnhanced()
1818
{
1919
return GetGame() == GameVersion::GTA5_ENHANCED;
2020
}
2121

22-
bool IsLegacy()
22+
inline bool IsLegacy()
2323
{
2424
return GetGame() == GameVersion::GTA5_LEGACY;
2525
}

0 commit comments

Comments
 (0)