Skip to content

Commit 1b33d80

Browse files
committed
Ported DrawRect, AllocateDrawRect & WorldToScreen to Enhanced
1 parent d0378e0 commit 1b33d80

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

ChaosMod/Memory/Drawing.h

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
// Adapted by MoneyWasted for ChaosModV
77
// https://github.com/citizenfx/fivem/blob/master/code/components/extra-natives-five/src/Draw2dNatives.cpp
88

9-
// This file is manually formatted.
10-
// clang-format off
11-
129
#define MAX_LINES 5000
1310

1411
namespace Memory
@@ -24,28 +21,44 @@ namespace Memory
2421

2522
if (!drawRects)
2623
{
27-
// Get our base handle at the beginning of the DRAW_RECT function.
28-
Handle handle = Memory::FindPattern("48 8B C4 48 89 58 08 57 48 83 EC 70 48 63");
29-
if (!handle.IsValid())
24+
if (IsLegacy())
3025
{
31-
return;
26+
// Get our base handle at the beginning of the DRAW_RECT function.
27+
Handle handle = Memory::FindPattern("48 8B C4 48 89 58 08 57 48 83 EC 70 48 63");
28+
if (!handle.IsValid())
29+
return;
30+
31+
AllocateDrawRect = handle.At(0x56).Into().Get<char *(void *)>();
32+
33+
auto offsetSDC = getGameVersion() < eGameVersion::VER_1_0_3407_0 ? 0x92 : 0x97;
34+
SetDrawRectCoords = handle.At(offsetSDC).Into().Get<void(void *, float, float, float, float)>();
35+
36+
drawRects = handle.At(0x32).Into().Get<char>();
37+
drawRectsSize = handle.At(0x2C).Value<int>();
38+
mainThreadFrameIndex = handle.At(0x0E).Into().Get<int>();
3239
}
40+
else
41+
{
42+
Handle handle = Memory::FindPattern("44 0F 28 C8 48 63 05");
43+
if (!handle.IsValid())
44+
return;
3345

34-
AllocateDrawRect = handle.At(0x56).Into().Get<char *(void *)>();
46+
AllocateDrawRect = handle.At(0x1C).Into().Get<char *(void *)>();
47+
drawRects = handle.At(0x14).Into().Get<char>();
48+
drawRectsSize = handle.At(0x0D).Value<int>();
49+
mainThreadFrameIndex = handle.At(0x06).Into().Get<int>();
3550

36-
auto offsetSDC = getGameVersion() < eGameVersion::VER_1_0_3407_0 ? 0x92 : 0x97;
37-
SetDrawRectCoords = handle.At(offsetSDC).Into().Get<void(void *, float, float, float, float)>();
51+
handle = Memory::FindPattern("E8 ?? ?? ?? ?? B9 70 FF FF FF");
52+
if (!handle.IsValid())
53+
return;
3854

39-
drawRects = handle.At(0x32).Into().Get<char>();
40-
drawRectsSize = handle.At(0x2C).Value<int>();
41-
mainThreadFrameIndex = handle.At(0x0E).Into().Get<int>();
55+
SetDrawRectCoords = handle.Into().Get<void(void *, float, float, float, float)>();
56+
}
4257

4358
// At the instruction 'cmp edx, 500' in AllocateDrawRect.
44-
handle = Memory::FindPattern("81 FA F4 01 00 00 73 13");
59+
Handle handle = Memory::FindPattern("81 FA F4 01 00 00 73 13", "81 FA ?? ?? ?? ?? 77 14 48 8D 04 52");
4560
if (!handle.IsValid())
46-
{
4761
return;
48-
}
4962

5063
// Increase the number of lines that can be drawn.
5164
Memory::Write<int>(handle.At(2).Get<int>(), MAX_LINES);
@@ -57,10 +70,10 @@ namespace Memory
5770
SetDrawRectCoords(rect, x1, y1, x2, y2);
5871

5972
// Set unknown structure pointers.
60-
*(std::uint32_t *)(rect + 0x34) &= 0xFA;
61-
*(std::uint32_t *)(rect + 0x34) |= 0x8A;
62-
*(float *)(rect + 0x1C) = width;
63-
*(std::uint32_t *)(rect + 0x28) = color;
73+
*(std::uint32_t *)(rect + (IsLegacy() ? 0x34 : 0x48)) &= 0xFA;
74+
*(std::uint32_t *)(rect + (IsLegacy() ? 0x34 : 0x48)) |= 0x8A;
75+
*(float *)(rect + (IsLegacy() ? 0x1C : 0x30)) = width;
76+
*(std::uint32_t *)(rect + (IsLegacy() ? 0x28 : 0x3C)) = color;
6477
}
6578
}
6679

ChaosMod/Memory/WorldToScreen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Memory
88

99
if (!WorldToScreen)
1010
{
11-
Handle handle = Memory::FindPattern("48 89 5C 24 ? 55 56 57 48 83 EC 70 65 4C 8B 0C 25");
11+
Handle handle = Memory::FindPattern("48 89 5C 24 ? 55 56 57 48 83 EC 70 65 4C 8B 0C 25", "41 56 56 57 53 48 83 EC 78 0F 29 7C 24 60 0F 29 74 24 50 4D");
1212
if (!handle.IsValid())
1313
return false;
1414

0 commit comments

Comments
 (0)