@@ -26,7 +26,7 @@ namespace Hooks
26
26
std::uint16_t gameCamOffset = 0 ;
27
27
std::uint16_t gameCamPosOffset = 0 ;
28
28
29
- void __cdecl CameraEvent (uintptr_t gameCamAddr)
29
+ void __fastcall CameraEvent (uintptr_t gameCamAddr)
30
30
{
31
31
auto pGameCam = reinterpret_cast <prism::InteriorCamera*>(gameCamAddr + gameCamOffset);
32
32
auto pGameCamPos = reinterpret_cast <prism::InteriorCameraPos*>(gameCamAddr + gameCamPosOffset);
@@ -89,57 +89,79 @@ namespace Hooks
89
89
uintptr_t CameraEvent_addr;
90
90
91
91
92
- uint8_t baseBytes[34 ] = { 0 };
92
+ uint8_t baseBytes[35 ] = { 0 };
93
93
94
94
#if defined(X64)
95
95
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" ;
97
98
extern " C"
98
99
{
99
- uintptr_t CameraEvent_Address = 0 ;
100
+ uintptr_t CameraEvent_CallAddress = 0 ;
100
101
uintptr_t CameraEvent_RetnAddress = 0 ;
101
- void Asm_CameraEvent ();
102
+ void Asm_CameraEvent_V1 ();
103
+ void Asm_CameraEvent_V2 ();
102
104
}
103
105
104
106
#elif defined(X86)
105
107
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 ;
108
111
uintptr_t CameraEvent_RetnAddress = 0 ;
109
112
110
- void __declspec (naked) Asm_CameraEvent ()
113
+ void __declspec (naked) Asm_CameraEvent_V1 ()
111
114
{
112
115
__asm
113
116
{
114
117
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
116
132
popad
117
133
118
134
jmp CameraEvent_RetnAddress
119
135
}
120
136
}
121
137
122
138
#endif
139
+ // Temporary code. Just quick fix, I will rewrite it later
123
140
124
- bool Hook_CameraEvent ()
141
+ // ETS2: 1.27 - 1.36 ATS: 1.6 - 1.36
142
+ bool Hook_V1 ()
125
143
{
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);
127
149
128
150
if (pattern.size () > 0 )
129
151
{
130
152
CameraEvent_addr = reinterpret_cast <uintptr_t >(pattern.count (1 ).get (0 ).get <void >(0 ));
131
153
132
- #ifdef TESTING
154
+ #ifdef TESTING
133
155
std::cout << " CameraEvent addr: " << std::hex << CameraEvent_addr << " \n " ;
134
- #endif
156
+ #endif
135
157
136
158
gameCamOffset = *reinterpret_cast <std::uint16_t *>(CameraEvent_addr + 2 ) - 4 ;
137
159
gameCamPosOffset = *reinterpret_cast <std::uint16_t *>(CameraEvent_addr + 8 );
138
160
139
- #ifdef TESTING
161
+ #ifdef TESTING
140
162
printf (" Offsets: %i %i\n " , gameCamOffset, gameCamPosOffset);
141
163
printf (" Number of bytes to backup: %lld\n " , sizeof (baseBytes));
142
- #endif
164
+ #endif
143
165
144
166
// backup bytes
145
167
for (int i = 0 ; i < sizeof (baseBytes); ++i)
@@ -149,38 +171,100 @@ namespace Hooks
149
171
150
172
MemMgr::UnprotectMemory (CameraEvent_addr, sizeof (baseBytes));
151
173
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
155
181
156
182
return true ;
157
183
}
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 )
159
202
{
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 ;
165
235
}
236
+
237
+ #ifdef TESTING
238
+ printf (" HOOK V2 don't work\n " );
239
+ #endif
240
+
241
+ return false ;
166
242
}
167
243
244
+
168
245
bool Init ()
169
246
{
170
- #ifdef TESTING
247
+ g_pMod = Mod::Get ();
248
+
249
+ #ifdef TESTING
171
250
std::cout << " Initializing hooks...\n " ;
172
251
#endif
173
252
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
+ }
180
257
181
- g_pMod = Mod::Get ();
258
+ if (Hook_V2 ())
259
+ {
260
+ return true ;
261
+ }
182
262
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 ;
184
268
}
185
269
186
270
void Unhook ()
0 commit comments