Skip to content

Commit 4418e4b

Browse files
committed
Added minimap param functions
1 parent 890adb2 commit 4418e4b

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

ChaosMod/Components/LuaScripts.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "Memory/Hooks/AudioSettingsHook.h"
2020
#include "Memory/Hooks/GameSpeedHook.h"
2121
#include "Memory/Hooks/GetLabelTextHook.h"
22+
#include "Memory/Hooks/MinimapHook.h"
2223
#include "Memory/Hooks/PreRenderHook.h"
2324
#include "Memory/Hooks/ShaderHook.h"
2425
#include "Memory/PedModels.h"
@@ -803,6 +804,11 @@ LuaScripts::ParseScriptRaw(std::string scriptName, const std::string &script, Pa
803804
}),
804805
E("IsEntityAWeapon", Memory::IsEntityAWeapon),
805806
E("IsEntityAWeaponComponent", Memory::IsEntityAWeaponComponent),
807+
E("SetMinimapRotation", Hooks::SetMinimapRotation),
808+
E("ResetMinimapRotation", Hooks::ResetMinimapRotation),
809+
E("SetMinimapPosition", [](const LuaVector3 &vector)
810+
{ Hooks::SetMinimapPosition(Vector3(vector.X, vector.Y, vector.Z));}),
811+
E("ResetMinimapPosition", Hooks::ResetMinimapPosition)
806812
};
807813
#undef E
808814

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include <stdafx.h>
2+
3+
#include "TextOutlineHook.h"
4+
5+
#include "Memory/Hooks/Hook.h"
6+
7+
#include "Memory.h"
8+
#include "game.h"
9+
10+
#include "Memory/Allocator/MemoryBuffer.h"
11+
12+
#include "Memory/Rain.h"
13+
14+
static std::optional<float> desiredRotation;
15+
static std::optional<ChaosVector3> desiredPosition;
16+
17+
static float (*OG_GetMinimapRotation)();
18+
static float HK_GetMinimapRotation()
19+
{
20+
return OG_GetMinimapRotation() + desiredRotation.value_or(0.f);
21+
}
22+
23+
static void (*OG_GetMinimapPosition)(ChaosVector3 *out);
24+
static void HK_GetMinimapPosition(ChaosVector3 *out)
25+
{
26+
OG_GetMinimapPosition(out);
27+
28+
if (desiredPosition.has_value())
29+
{
30+
LOG(out->x << " " << desiredPosition.value().x << " " << (*out + desiredPosition.value()).x);
31+
*out = *out + desiredPosition.value();
32+
}
33+
}
34+
35+
static bool OnHook()
36+
{
37+
auto handle = Memory::FindPattern("E8 ?? ?? ?? ?? F3 0F 59 05 ?? ?? ?? ?? F3 0F 2C E8 8B C5",
38+
"E8 ?? ?? ?? ?? F3 0F 59 05 ?? ?? ?? ?? F3 0F 2C E8 41 81 FF");
39+
40+
if (!handle.IsValid())
41+
return false;
42+
43+
Memory::AddHook(handle.Into().Get<void>(), HK_GetMinimapRotation, &OG_GetMinimapRotation);
44+
45+
handle = Memory::FindPattern("E8 ?? ?? ?? ?? 33 C9 E8 ?? ?? ?? ?? 0F 57 F6",
46+
"E8 ?? ?? ?? ?? 31 C9 E8 ?? ?? ?? ?? 84 C0 74 0B 0F B6 05 ?? ?? ?? ?? 24 01 75 36");
47+
48+
if (!handle.IsValid())
49+
return false;
50+
51+
Memory::AddHook(handle.Into().Get<void>(), HK_GetMinimapPosition, &OG_GetMinimapPosition);
52+
53+
return true;
54+
}
55+
56+
static void OnCleanup()
57+
{
58+
desiredRotation = std::nullopt;
59+
}
60+
61+
namespace Hooks
62+
{
63+
void SetMinimapRotation(float rotation)
64+
{
65+
desiredRotation = rotation;
66+
}
67+
68+
void ResetMinimapRotation()
69+
{
70+
desiredRotation = std::nullopt;
71+
}
72+
73+
void SetMinimapPosition(Vector3 position)
74+
{
75+
desiredPosition = ChaosVector3(position);
76+
}
77+
78+
void ResetMinimapPosition()
79+
{
80+
desiredPosition = std::nullopt;
81+
}
82+
}
83+
84+
static RegisterHook registerHook(OnHook, OnCleanup, "_MinimapParams");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
namespace Hooks
4+
{
5+
void SetMinimapRotation(float rotation);
6+
void ResetMinimapRotation();
7+
void SetMinimapPosition(Vector3 position);
8+
void ResetMinimapPosition();
9+
}

ChaosMod/Util/Types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ struct ChaosVector3
1212
ChaosVector3(float x, float y, float z) : x(x), y(y), z(z)
1313
{
1414
}
15+
16+
ChaosVector3 operator+(const ChaosVector3& other)
17+
{
18+
return ChaosVector3(x + other.x, y + other.y, z + other.z);
19+
}
1520
};
1621

1722
struct ChaosVector2

0 commit comments

Comments
 (0)