-
-
Notifications
You must be signed in to change notification settings - Fork 230
/
Copy pathdllmain.cpp
146 lines (132 loc) · 5.43 KB
/
dllmain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "stdafx.h"
#include <random>
struct Screen
{
int32_t Width;
int32_t Height;
float fWidth;
float fHeight;
int32_t Width43;
float fAspectRatio;
float fAspectRatioDiff;
int32_t FOV;
float fHUDScaleX;
float fHudOffset;
float fHudOffsetReal;
} Screen;
void Init()
{
CIniReader iniReader("");
Screen.Width = iniReader.ReadInteger("MAIN", "ResX", 0);
Screen.Height = iniReader.ReadInteger("MAIN", "ResY", 0);
bool bFixHUD = iniReader.ReadInteger("MAIN", "FixHUD", 1) != 0;
bool bRandomSongOrderFix = iniReader.ReadInteger("MAIN", "RandomSongOrderFix", 1) != 0;
if (!Screen.Width || !Screen.Height)
std::tie(Screen.Width, Screen.Height) = GetDesktopRes();
Screen.fWidth = static_cast<float>(Screen.Width);
Screen.fHeight = static_cast<float>(Screen.Height);
Screen.Width43 = static_cast<int32_t>(Screen.fHeight * (4.0f / 3.0f));
Screen.fAspectRatio = (Screen.fWidth / Screen.fHeight);
Screen.fAspectRatioDiff = 1.0f / (Screen.fAspectRatio / (4.0f / 3.0f));
Screen.fHUDScaleX = 1.0f / Screen.fWidth * (Screen.fHeight / 480.0f);
Screen.fHudOffset = ((480.0f * Screen.fAspectRatio) - 640.0f) / 2.0f;
Screen.fHudOffsetReal = (Screen.fWidth - Screen.fHeight * (4.0f / 3.0f)) / 2.0f;
//Resolution
auto pattern = hook::pattern("C7 05 ? ? ? ? ? ? ? ? C7 05 ? ? ? ? ? ? ? ? B0 01 5F 5E"); //40B349
static int32_t* dword_851084 = *pattern.get_first<int32_t*>(2);
static int32_t* dword_851088 = *pattern.get_first<int32_t*>(12);
injector::MakeNOP(pattern.get_first(-12), 2, true);
struct SetResHook
{
void operator()(injector::reg_pack& regs)
{
*dword_851084 = Screen.Width;
*dword_851088 = Screen.Height;
}
};
injector::MakeInline<SetResHook>(pattern.get_first(0), pattern.get_first(20));
pattern = hook::pattern("C7 05 ? ? ? ? ? ? ? ? C7 05 ? ? ? ? ? ? ? ? C7 05 ? ? ? ? ? ? ? ? 89 2D"); //40B5B8
injector::MakeInline<SetResHook>(pattern.get_first(0), pattern.get_first(20));
pattern = hook::pattern("A3 ? ? ? ? 8B 04 AE 85 C0"); //40B835 40B84B
injector::MakeInline<SetResHook>(pattern.count(2).get(0).get<void*>(0));
injector::MakeInline<SetResHook>(pattern.count(2).get(1).get<void*>(0));
//Aspect Ratio
pattern = hook::pattern("89 4E 68 8B 50 04 89 56 6C 8B 46 04"); //0x5591B1
struct AspectRatioHook
{
void operator()(injector::reg_pack& regs)
{
*(float*)(regs.esi + 0x68) = *(float*)®s.ecx / Screen.fAspectRatioDiff;
*(float*)®s.edx = *(float*)(regs.eax + 0x04);
}
}; injector::MakeInline<AspectRatioHook>(pattern.get_first(0), pattern.get_first(6));
//HUD
if (bFixHUD)
{
pattern = hook::pattern("D8 0D ? ? ? ? 8B CF 89 5C 24 50 D8"); //0x58DDC8
injector::WriteMemory(*pattern.get_first<float*>(2), Screen.fHUDScaleX, true);
pattern = hook::pattern("0B F2 89 70 64 A1 8C 67 90"); //0x4F65B1
struct HUDHook //sub_4F62A0
{
void operator()(injector::reg_pack& regs)
{
if (*(float*)(regs.eax + 0x00) == 0.0f && *(float*)(regs.eax + 0x1C) == 0.0f
&& (int32_t)(*(float*)(regs.eax + 0x38)) == Screen.Width43
&& (int32_t)(*(float*)(regs.eax + 0x54)) == Screen.Width43)
{
//blood overlay, maybe more
//*(float*)(regs.eax + 0x00) += Screen.fHudOffsetReal;
//*(float*)(regs.eax + 0x1C) += Screen.fHudOffsetReal;
*(float*)(regs.eax + 0x38) += Screen.fHudOffsetReal * 2.0f;
*(float*)(regs.eax + 0x54) += Screen.fHudOffsetReal * 2.0f;
}
else
{
*(float*)(regs.eax + 0x00) += Screen.fHudOffsetReal;
*(float*)(regs.eax + 0x1C) += Screen.fHudOffsetReal;
*(float*)(regs.eax + 0x38) += Screen.fHudOffsetReal;
*(float*)(regs.eax + 0x54) += Screen.fHudOffsetReal;
}
regs.esi |= regs.edx;
*(uint32_t*)(regs.eax + 0x64) = regs.esi;
}
}; injector::MakeInline<HUDHook>(pattern.get_first(0));
pattern = hook::pattern("8B 81 A4 00 00 00 89 46"); //0x4F66F0
struct HUDHook2 //sub_4F65E0
{
void operator()(injector::reg_pack& regs)
{
*(float*)(regs.esi - 0x04) += Screen.fHudOffsetReal;
regs.eax = *(uint32_t*)(regs.ecx + 0xA4);
}
}; injector::MakeInline<HUDHook2>(pattern.get_first(0), pattern.get_first(6));
}
if (bRandomSongOrderFix)
{
pattern = hook::pattern("E8 ? ? ? ? 8B 96 E8");
struct RandomHook
{
void operator()(injector::reg_pack& regs)
{
std::mt19937 r{ std::random_device{}() };
std::uniform_int_distribution<uint32_t> uid(0, regs.eax);
regs.eax = uid(r);
}
}; injector::MakeInline<RandomHook>(pattern.get_first(0));
}
}
CEXP void InitializeASI()
{
std::call_once(CallbackHandler::flag, []()
{
CallbackHandler::RegisterCallback(Init, hook::pattern("53 55 56 57 52 6A 00"));
});
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID lpReserved)
{
if (reason == DLL_PROCESS_ATTACH)
{
if (!IsUALPresent()) { InitializeASI(); }
}
return TRUE;
}