@@ -50,6 +50,8 @@ namespace sp
50
50
51
51
DB_EnumXAssets_FastFile_t DB_EnumXAssets_FastFile = reinterpret_cast <DB_EnumXAssets_FastFile_t>(0x822AEF88 );
52
52
53
+ Load_MapEntsPtr_t Load_MapEntsPtr = reinterpret_cast <Load_MapEntsPtr_t>(0x822B9788 );
54
+
53
55
Scr_AddSourceBuffer_t Scr_AddSourceBuffer = reinterpret_cast <Scr_AddSourceBuffer_t>(0x821C5A18 );
54
56
Scr_ReadFile_FastFile_t Scr_ReadFile_FastFile = reinterpret_cast <Scr_ReadFile_FastFile_t>(0x821C5978 );
55
57
@@ -87,6 +89,70 @@ namespace sp
87
89
}
88
90
}
89
91
92
+ Detour Load_MapEntsPtr_Detour;
93
+
94
+ void Load_MapEntsPtr_Hook ()
95
+ {
96
+ // TODO: don't write null byte to file
97
+ // and add null byte to entityString when reading from file
98
+
99
+ xbox::DbgPrint (" Load_MapEntsPtr_Hook\n " );
100
+
101
+ // TODO: write comment what this is ***
102
+ // Get pointer to pointer stored at 0x82475914
103
+ MapEnts **varMapEntsPtr = *(MapEnts ***)0x825875D8 ;
104
+
105
+ Load_MapEntsPtr_Detour.GetOriginal <decltype (&Load_MapEntsPtr_Hook)>()();
106
+
107
+ // Validate pointer before dereferencing
108
+ if (varMapEntsPtr && *varMapEntsPtr)
109
+ {
110
+ MapEnts *mapEnts = *varMapEntsPtr;
111
+
112
+ // Write stock map ents to disk
113
+ std::string file_path = " game:\\ dump\\ " ;
114
+ file_path += mapEnts->name ;
115
+ file_path += " .ents" ; // iw4x naming convention
116
+ std::replace (file_path.begin (), file_path.end (), ' /' , ' \\ ' ); // Replace forward slashes with backslashes
117
+ filesystem::write_file_to_disk (file_path.c_str (), mapEnts->entityString , mapEnts->numEntityChars );
118
+
119
+ // Load map ents from file
120
+ // Path to check for existing entity file
121
+ std::string raw_file_path = " game:\\ raw\\ " ;
122
+ raw_file_path += mapEnts->name ;
123
+ raw_file_path += " .ents" ; // IW4x naming convention
124
+ std::replace (raw_file_path.begin (), raw_file_path.end (), ' /' , ' \\ ' ); // Replace forward slashes with backslashes
125
+
126
+ // If the file exists, replace entityString
127
+ if (filesystem::file_exists (raw_file_path))
128
+ {
129
+ xbox::DbgPrint (" Found entity file: %s\n " , raw_file_path.c_str ());
130
+ std::string new_entity_string = filesystem::read_file_to_string (raw_file_path);
131
+ if (!new_entity_string.empty ())
132
+ {
133
+ // Allocate new memory and copy the data
134
+ size_t new_size = new_entity_string.size () + 1 ; // Include null terminator
135
+ char *new_memory = static_cast <char *>(malloc (new_size));
136
+
137
+ if (new_memory)
138
+ {
139
+ memcpy (new_memory, new_entity_string.c_str (), new_size); // Copy with null terminator
140
+ mapEnts->entityString = new_memory;
141
+ xbox::DbgPrint (" Replaced entityString from file: %s\n " , raw_file_path.c_str ());
142
+ }
143
+ else
144
+ {
145
+ xbox::DbgPrint (" Failed to allocate memory for entityString replacement.\n " );
146
+ }
147
+ }
148
+ }
149
+ }
150
+ else
151
+ {
152
+ xbox::DbgPrint (" Hooked Load_MapEntsPtr: varMapEntsPtr is NULL or invalid.\n " );
153
+ }
154
+ }
155
+
90
156
Detour Scr_ReadFile_FastFile_Detour;
91
157
92
158
char *Scr_ReadFile_FastFile_Hook (const char *filename, const char *extFilename, const char *codePos, bool archive)
@@ -184,6 +250,9 @@ namespace sp
184
250
CL_GamepadButtonEvent_Detour = Detour (CL_GamepadButtonEvent, CL_GamepadButtonEvent_Hook);
185
251
CL_GamepadButtonEvent_Detour.Install ();
186
252
253
+ Load_MapEntsPtr_Detour = Detour (Load_MapEntsPtr, Load_MapEntsPtr_Hook);
254
+ Load_MapEntsPtr_Detour.Install ();
255
+
187
256
Scr_ReadFile_FastFile_Detour = Detour (Scr_ReadFile_FastFile, Scr_ReadFile_FastFile_Hook);
188
257
Scr_ReadFile_FastFile_Detour.Install ();
189
258
0 commit comments