Skip to content

Commit 16662b2

Browse files
committed
Fix cases where early texture preloading tramples over the texture hack.
1 parent 86d8c6d commit 16662b2

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

gmloader/libyoyo.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ ABI_ATTR char (*Variable_SetBuiltIn_Direct)(void* inst, int var_slot, int array_
4747
ABI_ATTR void (*Code_Function_GET_the_function)(int numb,char **name,void **code,int *args, int *unk) = NULL;
4848
ABI_ATTR void (*_RefThing__dec)(void *ref) = NULL;
4949
ABI_ATTR int (*Variable_BuiltIn_Find)(const char *name) = NULL;
50+
ABI_ATTR long (*PrepareGame)(void) = NULL;
5051
ABI_ATTR int (*Code_Variable_Find_Slot_From_Name)(void *instance, const char *name) = NULL;
5152
ABI_ATTR int (*Variable_FindName)(const char *name) = NULL; /* Unavailable in GMS 1.4+, very old symbol */
5253
ABI_ATTR long (*ExecuteIt)(void *self, void *other, void *code, RValue *args) = NULL;
5354
ABI_ATTR long (*ExecuteIt_flags)(void *self, void *other, void *code, RValue *args, int argc) = NULL;
5455

55-
5656
bionic_off_t *g_GameFileLength = NULL; //android had 32bit off_t???
5757
char **g_pWorkingDirectory = NULL;
5858
char *g_fNoAudio = NULL;
@@ -87,6 +87,8 @@ void **g_pGameFileBuffer = NULL;
8787
void **g_ppYYStackTrace = NULL;
8888
int *Extension_Main_number = NULL;
8989

90+
ReentrantHook REHPrepareGame = {};
91+
9092
uint8_t prev_kbd_state[N_KEYS] = {};
9193
uint8_t cur_keys[N_KEYS] = {};
9294

@@ -246,6 +248,16 @@ ABI_ATTR void game_change_reimpl(RValue *ret, void *self, void *other, int argc,
246248
}
247249
}
248250

251+
extern int setup_ended;
252+
ABI_ATTR long PrepareGame_hook()
253+
{
254+
setup_ended = 1;
255+
rehook_unhook(&REHPrepareGame);
256+
long ret = PrepareGame();
257+
warning("- PrepareGame done.\n");
258+
return ret;
259+
}
260+
249261
void patch_libyoyo(so_module *mod)
250262
{
251263
// Load all of the native symbols referenced
@@ -323,6 +335,11 @@ void patch_libyoyo(so_module *mod)
323335
// Depth disable
324336
FIND_SYMBOL(mod, surface_depth_disable, "_Z21F_SurfaceDepthDisableR6RValueP9CInstanceS2_iPS_");
325337

338+
// Hook the start of the game so we know setup is done
339+
ENSURE_SYMBOL(mod, PrepareGame, "_Z11PrepareGamev");
340+
rehook_new(mod, &REHPrepareGame, (uintptr_t)PrepareGame, (uintptr_t)&PrepareGame_hook);
341+
rehook_hook(&REHPrepareGame);
342+
326343
// Disable extension support
327344
FIND_SYMBOL(mod, Extension_Main_number, "Extension_Main_number");
328345
if (gmloader_config.disable_extensions == 1) {

gmloader/libyoyo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ extern void **g_nYYCode;
325325
extern void **g_pGameFileBuffer;
326326
extern void **g_ppYYStackTrace;
327327
extern int *Extension_Main_number;
328+
extern ReentrantHook REHPrepareGame;
328329

329330
extern const char *gc_workdir;
330331
extern int relaunch_flag;

gmloader/texture.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,16 @@ uint32_t png_get_IHDR_hook(struct png_struct *png_ptr, png_info *info_ptr, uint3
211211
else {
212212
path = fs::path(gmloader_config.save_dir) / "textures" / (std::to_string(image_preload_idx) + ".pvr");
213213
}
214-
uint32_t _sz;
215-
uint32_t *buffer;
216-
217-
*width = 0;
218-
*height = 0;
219214

220215
FILE *f = fopen(path.c_str(), "rb");
221216
if (f) {
222217
fseek(f, 0x18, SEEK_SET);
223218
fread(height, 1, 4, f);
224219
fread(width, 1, 4, f);
225220
fclose(f);
226-
}
227-
228-
if (*width == 0 || *height == 0) {
229-
warning("Texture %d metadata preload failure.\n", image_preload_idx);
221+
} else {
222+
fatal_error("Texture %d metadata preload failure.\n", image_preload_idx);
223+
exit(-1);
230224
}
231225

232226
image_preload_idx++;

0 commit comments

Comments
 (0)