@@ -36,22 +36,41 @@ void AddDataFileToLoadList(const std::string& type, const std::string& path);
36
36
#include " Hooking.h"
37
37
#include " Hooking.Stubs.h"
38
38
39
+ #ifdef GTA_FIVE
40
+ #define LEVEL_NAME " gta5"
41
+ #else
42
+ #define LEVEL_NAME " rdr3"
43
+ #endif
44
+
39
45
static std::string g_overrideNextLoadedLevel;
40
46
static std::string g_nextLevelPath;
41
47
42
48
static bool g_wasLastLevelCustom;
43
49
static bool g_gameUnloaded = false ;
44
50
45
51
static void (*g_origLoadLevelByIndex)(int );
46
- static void (*g_loadLevel)(const char * levelPath);
52
+ #ifdef IS_RDR3
53
+ static int * g_levelIndex;
54
+ #endif
55
+ static void (*g_loadLevel)(const char * levelPath);
47
56
48
57
enum NativeIdentifiers : uint64_t
49
58
{
59
+ #ifdef GTA_FIVE
50
60
PLAYER_PED_ID = 0xD80958FC74E988A6 ,
51
61
SET_ENTITY_COORDS = 0x621873ECE1178967 ,
52
62
LOAD_SCENE = 0x4448EB75B4904BDB ,
53
63
SHUTDOWN_LOADING_SCREEN = 0x078EBE9809CCD637 ,
54
- DO_SCREEN_FADE_IN = 0xD4E8E24955024033
64
+ DO_SCREEN_FADE_IN = 0xD4E8E24955024033 ,
65
+ FREEZE_ENTITY_POSITION = 0x428CA6DBD1094446 ,
66
+ ACTIVATE_ROCKSTAR_EDITOR = 0x49DA8145672B2725
67
+ #else
68
+ PLAYER_PED_ID = 0x096275889B8E0EE0 ,
69
+ SET_ENTITY_COORDS = 0x06843DA7060A026B ,
70
+ SHUTDOWN_LOADING_SCREEN = 0xFC179D7E8886DADF ,
71
+ DO_SCREEN_FADE_IN = 0x6A053CF596F67DF7 ,
72
+ FREEZE_ENTITY_POSITION = 0x7D9EFB7AD6B19754
73
+ #endif
55
74
};
56
75
57
76
class SpawnThread : public CfxThread
@@ -79,14 +98,23 @@ class SpawnThread : public CfxThread
79
98
NativeInvoke::Invoke<SHUTDOWN_LOADING_SCREEN, int >();
80
99
NativeInvoke::Invoke<DO_SCREEN_FADE_IN, int >(0 );
81
100
82
- NativeInvoke::Invoke<SET_ENTITY_COORDS, int >(playerPedId, 293 .089f , 180 .466f , 104 .301f );
83
- NativeInvoke::Invoke<0x428CA6DBD1094446 , int >(NativeInvoke::Invoke<0xD80958FC74E988A6 , int >(), false );
84
-
101
+ NativeInvoke::Invoke<SET_ENTITY_COORDS, int >(playerPedId,
102
+ #ifdef GTA_FIVE
103
+ 293 .089f , 180 .466f , 104 .301f
104
+ #else
105
+ 35 .0f , 35 .0f , 102 .0f
106
+ #endif
107
+ );
108
+
109
+ NativeInvoke::Invoke<FREEZE_ENTITY_POSITION, int >(NativeInvoke::Invoke<PLAYER_PED_ID, int >(), false );
110
+
111
+ #ifdef GTA_FIVE
85
112
if (Instance<ICoreGameInit>::Get ()->HasVariable (" editorMode" ))
86
113
{
87
- NativeInvoke::Invoke<0x49DA8145672B2725 , int >();
114
+ NativeInvoke::Invoke<ACTIVATE_ROCKSTAR_EDITOR , int >();
88
115
Instance<ICoreGameInit>::Get ()->ClearVariable (" editorMode" );
89
116
}
117
+ #endif
90
118
91
119
m_doInityThings = false ;
92
120
}
@@ -158,14 +186,18 @@ static void DoLoadLevel(int index)
158
186
}
159
187
160
188
// mark the level as being custom
161
- g_wasLastLevelCustom = (g_overrideNextLoadedLevel != " gta5 " && g_overrideNextLoadedLevel.find (" /gta5 " ) == std::string::npos);
189
+ g_wasLastLevelCustom = (g_overrideNextLoadedLevel != LEVEL_NAME && g_overrideNextLoadedLevel.find (" /" LEVEL_NAME ) == std::string::npos);
162
190
163
191
// clear the 'next' level
164
192
g_overrideNextLoadedLevel.clear ();
165
193
166
194
// save globally to prevent va() reuse messing up
167
195
g_nextLevelPath = levelPath;
168
196
197
+ #ifdef IS_RDR3
198
+ // Manually set the level index.
199
+ *g_levelIndex = index;
200
+ #endif
169
201
// load the level
170
202
g_loadLevel (g_nextLevelPath.c_str ());
171
203
}
@@ -191,6 +223,7 @@ static bool DoesLevelHashMatch(void* evaluator, uint32_t* hash)
191
223
return (!g_wasLastLevelCustom);
192
224
}
193
225
226
+ #ifdef GTA_FIVE
194
227
struct CDataFileMgr__ContentChangeSet
195
228
{
196
229
// technically, some atString?
@@ -215,9 +248,11 @@ static void CFileLoader__BuildContentChangeSetActionList_Hook(const CDataFileMgr
215
248
216
249
return g_orig_CFileLoader__BuildContentChangeSetActionList (changeset, outArray, a3, a4, a5);
217
250
}
251
+ #endif
218
252
219
253
static HookFunction hookFunction ([] ()
220
254
{
255
+ #ifdef GTA_FIVE
221
256
char * levelCaller = xbr::IsGameBuildOrGreater<2060 >() ? hook::pattern (" 33 D0 81 E2 FF 00 FF 00 33 D1 48" ).count (1 ).get (0 ).get <char >(0x33 ) : hook::pattern (" 0F 94 C2 C1 C1 10 33 CB 03 D3 89 0D" ).count (1 ).get (0 ).get <char >(46 );
222
257
char * levelByIndex = hook::get_call (levelCaller);
223
258
@@ -237,6 +272,26 @@ static HookFunction hookFunction([] ()
237
272
238
273
hook::jump (location + *(int32_t *)location + 4 , DoesLevelHashMatch);
239
274
}
275
+ #else
276
+ char * levelCaller = hook::get_pattern<char >(" F3 0F 10 0D ? ? ? ? 48 8D 0D ? ? ? ? 83 25" , 61 );
277
+ char * levelByIndex = hook::get_call (levelCaller);
278
+
279
+ hook::set_call (&g_origLoadLevelByIndex, levelCaller);
280
+ hook::call (levelCaller, DoLoadLevel);
281
+
282
+ g_loadLevel = (decltype (g_loadLevel))hook::get_pattern (" B9 ? ? ? ? E8 ? ? ? ? 40 88 7C 24 ? 48 8D 0D" , -0x3B );
283
+
284
+ // change set condition evaluator's $level variable comparer
285
+ {
286
+ char * location = hook::pattern (" 48 8D 4C 24 ? 48 8B DA E8 ? ? ? ? 8B 0B" ).count (1 ).get (0 ).get <char >(-5 );
287
+ hook::trampoline (location, DoesLevelHashMatch);
288
+ }
289
+
290
+ // change set applicability
291
+ hook::jump (hook::pattern (" 4C 8B F1 B3 ? 76" ).count (1 ).get (0 ).get <void >(-0x21 ), IsLevelApplicable);
292
+
293
+ g_levelIndex = hook::get_address<int *>(hook::get_pattern<int >(" 8B 15 ? ? ? ? 0F 29 45 ? E8" , 2 ));
294
+ #endif
240
295
});
241
296
242
297
enum class Mode : uint8_t
@@ -394,15 +449,17 @@ static InitFunction initFunction([] ()
394
449
LoadLevel (level.c_str (), Mode::LEVEL_LOAD);
395
450
});
396
451
452
+ #ifdef GTA_FIVE
397
453
static ConsoleCommand storyModeyCommand (" storymode" , []()
398
454
{
399
- LoadLevel (" gta5 " , Mode::STORY_MODE);
455
+ LoadLevel (LEVEL_NAME , Mode::STORY_MODE);
400
456
});
401
457
402
458
static ConsoleCommand editorModeCommand (" replayEditor" , []()
403
459
{
404
- LoadLevel (" gta5 " , Mode::EDITOR_MODE);
460
+ LoadLevel (LEVEL_NAME , Mode::EDITOR_MODE);
405
461
});
462
+ #endif
406
463
407
464
static ConsoleCommand localGameCommand (" localGame" , [](const std::string& resourceDir)
408
465
{
@@ -491,7 +548,7 @@ static InitFunction initFunction([] ()
491
548
res->Start ();
492
549
});
493
550
494
- LoadLevel (" gta5 " , Mode::LOCAL_MODE);
551
+ LoadLevel (LEVEL_NAME , Mode::LOCAL_MODE);
495
552
});
496
553
497
554
static ConsoleCommand loadLevelCommand2 (" invoke-levelload" , [](const std::string& level)
0 commit comments