Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 6e9383a

Browse files
committed
Added support for ETS2/ATS 1.37
1 parent 02f00af commit 6e9383a

File tree

4 files changed

+146
-41
lines changed

4 files changed

+146
-41
lines changed

src/Smooth Interior Camera/Game/Hooks.cpp

+117-33
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace Hooks
2626
std::uint16_t gameCamOffset = 0;
2727
std::uint16_t gameCamPosOffset = 0;
2828

29-
void __cdecl CameraEvent(uintptr_t gameCamAddr)
29+
void __fastcall CameraEvent(uintptr_t gameCamAddr)
3030
{
3131
auto pGameCam = reinterpret_cast<prism::InteriorCamera*>(gameCamAddr + gameCamOffset);
3232
auto pGameCamPos = reinterpret_cast<prism::InteriorCameraPos*>(gameCamAddr + gameCamPosOffset);
@@ -89,57 +89,79 @@ namespace Hooks
8989
uintptr_t CameraEvent_addr;
9090

9191

92-
uint8_t baseBytes[34] = { 0 };
92+
uint8_t baseBytes[35] = { 0 };
9393

9494
#if defined(X64)
9595

96-
auto CameraEvent_pattern = "8B 81 ?? ?? 00 00 89 81 ?? ?? 00 00 8B 81 ?? ?? 00 00 89 81 ?? ?? 00 00 C7 81 ?? ?? 00 00 00 00 00 00";
96+
auto CameraEvent_pattern_V1 = "8B 81 ?? ?? 00 00 89 81 ?? ?? 00 00 8B 81 ?? ?? 00 00 89 81 ?? ?? 00 00 C7 81 ?? ?? 00 00 00 00 00 00";
97+
auto CameraEvent_pattern_V2 = "F3 0F 10 97 ?? ?? 00 00 F3 0F 10 B7 ?? ?? 00 00 83 F8 01 75 ?? F3 0F 11 97 ?? ?? 00 00 F3 0F 11 B7 ?? ?? 00 00 89 9F ?? ?? 00 00 E9 ?? ?? 00 00";
9798
extern "C"
9899
{
99-
uintptr_t CameraEvent_Address = 0;
100+
uintptr_t CameraEvent_CallAddress = 0;
100101
uintptr_t CameraEvent_RetnAddress = 0;
101-
void Asm_CameraEvent();
102+
void Asm_CameraEvent_V1();
103+
void Asm_CameraEvent_V2();
102104
}
103105

104106
#elif defined(X86)
105107

106-
auto CameraEvent_pattern = "8B 81 ?? ?? 00 00 89 81 ?? ?? 00 00 8B 81 ?? ?? 00 00 89 81 ?? ?? 00 00 C7 81 ?? ?? 00 00 00 00 00 00 8B";
107-
uintptr_t CameraEvent_Address = 0;
108+
auto CameraEvent_pattern_V1 = "8B 81 ?? ?? 00 00 89 81 ?? ?? 00 00 8B 81 ?? ?? 00 00 89 81 ?? ?? 00 00 C7 81 ?? ?? 00 00 00 00 00 00 8B";
109+
auto CameraEvent_pattern_V2 = "F3 0F 10 9F ?? ?? 00 00 F3 0F 10 97 ?? ?? 00 00 83 F8 01 75 ?? F3 0F 11 9F ?? ?? 00 00 F3 0F 11 97 ?? ?? 00 00 E9 ?? ?? 00 00";
110+
uintptr_t CameraEvent_CallAddress = 0;
108111
uintptr_t CameraEvent_RetnAddress = 0;
109112

110-
void __declspec(naked) Asm_CameraEvent()
113+
void __declspec(naked) Asm_CameraEvent_V1()
111114
{
112115
__asm
113116
{
114117
pushad
115-
call CameraEvent_Address
118+
call CameraEvent_CallAddress
119+
popad
120+
121+
jmp CameraEvent_RetnAddress
122+
}
123+
}
124+
125+
void __declspec(naked) Asm_CameraEvent_V2()
126+
{
127+
__asm
128+
{
129+
pushad
130+
mov ecx, edi
131+
call CameraEvent_CallAddress
116132
popad
117133

118134
jmp CameraEvent_RetnAddress
119135
}
120136
}
121137

122138
#endif
139+
// Temporary code. Just quick fix, I will rewrite it later
123140

124-
bool Hook_CameraEvent()
141+
// ETS2: 1.27 - 1.36 ATS: 1.6 - 1.36
142+
bool Hook_V1()
125143
{
126-
auto pattern = hook::pattern(CameraEvent_pattern);
144+
#ifdef TESTING
145+
printf("Trying HOOK V1...\n");
146+
#endif
147+
148+
auto pattern = hook::pattern(CameraEvent_pattern_V1);
127149

128150
if (pattern.size() > 0)
129151
{
130152
CameraEvent_addr = reinterpret_cast<uintptr_t>(pattern.count(1).get(0).get<void>(0));
131153

132-
#ifdef TESTING
154+
#ifdef TESTING
133155
std::cout << "CameraEvent addr: " << std::hex << CameraEvent_addr << "\n";
134-
#endif
156+
#endif
135157

136158
gameCamOffset = *reinterpret_cast<std::uint16_t*>(CameraEvent_addr + 2) - 4;
137159
gameCamPosOffset = *reinterpret_cast<std::uint16_t*>(CameraEvent_addr + 8);
138160

139-
#ifdef TESTING
161+
#ifdef TESTING
140162
printf("Offsets: %i %i\n", gameCamOffset, gameCamPosOffset);
141163
printf("Number of bytes to backup: %lld\n", sizeof(baseBytes));
142-
#endif
164+
#endif
143165

144166
// backup bytes
145167
for (int i = 0; i < sizeof(baseBytes); ++i)
@@ -149,38 +171,100 @@ namespace Hooks
149171

150172
MemMgr::UnprotectMemory(CameraEvent_addr, sizeof(baseBytes));
151173

152-
CameraEvent_Address = reinterpret_cast<uintptr_t>(CameraEvent);
153-
CameraEvent_RetnAddress = CameraEvent_addr + sizeof(baseBytes);
154-
MemMgr::JmpHook(CameraEvent_addr, (uintptr_t)Asm_CameraEvent);
174+
CameraEvent_CallAddress = reinterpret_cast<uintptr_t>(CameraEvent);
175+
CameraEvent_RetnAddress = CameraEvent_addr + 34;
176+
MemMgr::JmpHook(CameraEvent_addr, (uintptr_t)Asm_CameraEvent_V1);
177+
178+
#ifdef TESTING
179+
printf("HOOK V1 activated\n");
180+
#endif
155181

156182
return true;
157183
}
158-
else
184+
185+
#ifdef TESTING
186+
printf("HOOK V1 don't work\n");
187+
#endif
188+
189+
return false;
190+
}
191+
192+
// ETS2: 1.37+, ATS 1.37+
193+
bool Hook_V2()
194+
{
195+
#ifdef TESTING
196+
printf("Trying HOOK V2...\n");
197+
#endif
198+
199+
auto pattern = hook::pattern(CameraEvent_pattern_V2);
200+
201+
if (pattern.size() > 0)
159202
{
160-
Mod::Get()->Log(SCS_LOG_TYPE_error, "Data structure is incorrect!");
161-
#ifdef TESTING
162-
std::cout << "Hook for CameraEvent not found!\n";
163-
#endif
164-
return false;
203+
uintptr_t data_addr = reinterpret_cast<uintptr_t>(pattern.count(1).get(0).get<uintptr_t>(0));
204+
CameraEvent_addr = data_addr + 21;
205+
206+
#ifdef TESTING
207+
std::cout << "CameraEvent addr: " << std::hex << CameraEvent_addr << "\n";
208+
#endif
209+
210+
gameCamOffset = *reinterpret_cast<std::uint16_t*>(data_addr + 4) - 4;
211+
gameCamPosOffset = *reinterpret_cast<std::uint16_t*>(CameraEvent_addr + 4);
212+
213+
#ifdef TESTING
214+
printf("Offsets: %i %i\n", gameCamOffset, gameCamPosOffset);
215+
printf("Number of bytes to backup: %lld\n", sizeof(baseBytes));
216+
#endif
217+
218+
// backup bytes
219+
for (int i = 0; i < sizeof(baseBytes); ++i)
220+
{
221+
baseBytes[i] = *reinterpret_cast<std::uint8_t*>(CameraEvent_addr + i);
222+
}
223+
224+
MemMgr::UnprotectMemory(CameraEvent_addr, sizeof(baseBytes));
225+
226+
CameraEvent_CallAddress = reinterpret_cast<uintptr_t>(CameraEvent);
227+
CameraEvent_RetnAddress = CameraEvent_addr + 16;
228+
MemMgr::JmpHook(CameraEvent_addr, (uintptr_t)Asm_CameraEvent_V2);
229+
230+
#ifdef TESTING
231+
printf("HOOK V2 activated\n");
232+
#endif
233+
234+
return true;
165235
}
236+
237+
#ifdef TESTING
238+
printf("HOOK V2 don't work\n");
239+
#endif
240+
241+
return false;
166242
}
167243

244+
168245
bool Init()
169246
{
170-
#ifdef TESTING
247+
g_pMod = Mod::Get();
248+
249+
#ifdef TESTING
171250
std::cout << "Initializing hooks...\n";
172251
#endif
173252

174-
if (!Hook_CameraEvent())
175-
return false;
176-
177-
#ifdef TESTING
178-
std::cout << "Hooks initialized!\n";
179-
#endif
253+
if (Hook_V1())
254+
{
255+
return true;
256+
}
180257

181-
g_pMod = Mod::Get();
258+
if (Hook_V2())
259+
{
260+
return true;
261+
}
182262

183-
return true;
263+
Mod::Get()->Log(SCS_LOG_TYPE_error, "Data structure is incorrect!");
264+
#ifdef TESTING
265+
std::cout << "Hook for CameraEvent not found!\n";
266+
#endif
267+
return false;
184268
}
185269

186270
void Unhook()

src/Smooth Interior Camera/Game/HooksASM.asm

+26-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
IFDEF RAX
77

8-
extern CameraEvent_Address: qword
8+
extern CameraEvent_CallAddress: qword
99
extern CameraEvent_RetnAddress: qword
1010

1111
.code
1212

13-
Asm_CameraEvent PROC
13+
Asm_CameraEvent_V1 PROC
1414

1515
; backup registers
1616
push rax
@@ -19,7 +19,7 @@ Asm_CameraEvent PROC
1919
push r8
2020

2121
; call library function
22-
call CameraEvent_Address
22+
call CameraEvent_CallAddress
2323

2424
; restore registers
2525
pop r8
@@ -29,7 +29,29 @@ Asm_CameraEvent PROC
2929

3030
; jump to End
3131
jmp CameraEvent_RetnAddress
32-
Asm_CameraEvent ENDP
32+
Asm_CameraEvent_V1 ENDP
33+
34+
Asm_CameraEvent_V2 PROC
35+
36+
; backup registers
37+
push rax
38+
push rdx
39+
push r8
40+
41+
; call library function
42+
push rcx
43+
mov rcx, rdi
44+
call CameraEvent_CallAddress
45+
pop rcx
46+
47+
; restore registers
48+
pop r8
49+
pop rdx
50+
pop rax
51+
52+
; jump to End
53+
jmp CameraEvent_RetnAddress
54+
Asm_CameraEvent_V2 ENDP
3355

3456
ENDIF
3557

0 Bytes
Binary file not shown.

src/Smooth Interior Camera/Version.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#pragma once
22

3-
#define CURRENT_VERSION "1.3.1.0"
4-
#define CURRENT_VERSION_SHORT 1310
5-
#define CURRENT_VERSION_NUMBER 1,3,1,0
6-
3+
#define CURRENT_VERSION "1.3.2.0"
4+
#define CURRENT_VERSION_SHORT 1320
5+
#define CURRENT_VERSION_NUMBER 1,3,2,0
76

87
#ifdef _WIN64
98
# define X64

0 commit comments

Comments
 (0)