diff --git a/src/game.c b/src/game.c index 68f5448448..fbf7de384f 100644 --- a/src/game.c +++ b/src/game.c @@ -726,7 +726,7 @@ int game_load_save() if (s6Header->num_packed_objects > 0) { j = 0; for (i = 0; i < s6Header->num_packed_objects; i++) - j += object_load_packed(); + j += object_load_packed(file); if (j > 0) object_list_load(); } diff --git a/src/object.c b/src/object.c index 3081f3557c..9d2e01dbb5 100644 --- a/src/object.c +++ b/src/object.c @@ -80,13 +80,13 @@ int object_load(int groupIndex, rct_object_entry *entry) // Calculate and check checksum if (object_calculate_checksum(&openedEntry, chunk, chunkSize) != openedEntry.checksum) { RCT2_GLOBAL(0x00F42BD9, uint8) = 2; - free(chunk); + rct2_free(chunk); return 0; } if (object_paint(openedEntry.flags & 0x0F, 2, 0, openedEntry.flags & 0x0F, 0, (int)chunk, 0, 0)) { RCT2_GLOBAL(0x00F42BD9, uint8) = 3; - free(chunk); + rct2_free(chunk); return 0; } @@ -94,7 +94,7 @@ int object_load(int groupIndex, rct_object_entry *entry) if (yyy >= 0x4726E){ RCT2_GLOBAL(0x00F42BD9, uint8) = 4; - free(chunk); + rct2_free(chunk); return 0; } //B84 is openedEntry @@ -105,7 +105,7 @@ int object_load(int groupIndex, rct_object_entry *entry) for (int ecx = 0; ((sint32*)esi)[ecx] != -1; ecx++){ if ((ecx + 1) >= RCT2_ADDRESS(0x98DA00, uint16)[ebp]){ RCT2_GLOBAL(0x00F42BD9, uint8) = 5; - free(chunk); + rct2_free(chunk); return 0; } } @@ -124,6 +124,8 @@ int object_load(int groupIndex, rct_object_entry *entry) installedObject = object_get_next(installedObject); } //6a991f + object_load(groupIndex, entry); + return !(RCT2_CALLPROC_X(0x006A985D, 0, 0, groupIndex, 0, 0, 0, (int)entry) & 0x400); } @@ -159,7 +161,7 @@ static int object_entry_compare(rct_object_entry *a, rct_object_entry *b) return 1; } -static int object_calculate_checksum(rct_object_entry *entry, char *data, int dataLength) +int object_calculate_checksum(rct_object_entry *entry, char *data, int dataLength) { int i; char *eee = (char*)entry; diff --git a/src/object.h b/src/object.h index 04e14eb220..70bddc040c 100644 --- a/src/object.h +++ b/src/object.h @@ -47,7 +47,7 @@ typedef struct { void object_list_load(); int object_read_and_load_entries(FILE *file); -int object_load_packed(); +int object_load_packed(FILE *file); void object_unload_all(); int object_load(int groupIndex, rct_object_entry *entry); @@ -56,5 +56,7 @@ int object_get_scenario_text(rct_object_entry *entry); void object_free_scenario_text(); int object_get_length(rct_object_entry *entry); rct_object_entry *object_get_next(rct_object_entry *entry); +int object_calculate_checksum(rct_object_entry *entry, char *data, int dataLength); +int object_paint(int type, int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp); #endif diff --git a/src/object_list.c b/src/object_list.c index fba5fabb2b..d3700f0dab 100644 --- a/src/object_list.c +++ b/src/object_list.c @@ -166,7 +166,7 @@ int object_read_and_load_entries(FILE *file) // Read all the object entries entries = malloc(OBJECT_ENTRY_COUNT * sizeof(rct_object_entry)); - sawyercoding_read_chunk(file, (uint8*)entries); + sawyercoding_read_chunk_variable(file, (uint8**)&entries); // Load each object for (i = 0; i < OBJECT_ENTRY_COUNT; i++) { @@ -202,10 +202,58 @@ int object_read_and_load_entries(FILE *file) * * rct2: 0x006AA2B7 */ -int object_load_packed() +int object_load_packed(FILE *file) { - int eax = 0, ebx = 0, ecx = 0, edx = 0, esi = 0, edi = 0, ebp = 0; - RCT2_CALLFUNC_X(0x006AA2B7, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + object_unload_all(); + + rct_object_entry* entry = RCT2_ADDRESS(0xF42B84, rct_object_entry); + + fread((void*)entry, 16, 1, file); + + uint8* chunk = rct2_malloc(0x600000); + uint32 chunkSize = sawyercoding_read_chunk_variable(file, &chunk); + chunk = rct2_realloc(chunk, chunkSize); + if (chunk == NULL){ + return 0; + } + + if (object_calculate_checksum(entry, chunk, chunkSize) != entry->checksum){ + rct2_free(chunk); + return 0; + } + + if (object_paint(entry->flags & 0x0F, 2, 0, entry->flags & 0x0F, 0, (int)chunk, 0, 0)) { + rct2_free(chunk); + return 0; + } + + int yyy = RCT2_GLOBAL(0x009ADAF0, uint32); + + if (yyy >= 0x4726E){ + rct2_free(chunk); + return 0; + } + + int type = entry->flags & 0x0F; + int ecx = 0; + + for (; ecx < RCT2_ADDRESS(0x98DA00, uint16)[type]; ecx++){ + if (RCT2_ADDRESS(0x98D97C, uint32*)[type * 2][ecx] == -1){ + break; + } + } + + if (ecx == RCT2_ADDRESS(0x98DA00, uint16)[type]){ + rct2_free(chunk); + return 0; + } + + RCT2_ADDRESS(0x98D97C, uint8**)[type * 2][ecx] = chunk; + int* edx = (int*)(ecx * 20 + RCT2_ADDRESS(0x98D980, uint32)[type * 2]); + memcpy(edx, (int*)entry, 20); + //6aa429 + int eax = 1;//, ebx = 0, ecx = 0, edx = 0, esi = 0, edi = 0, ebp = 0; + //RCT2_CALLFUNC_X(0x006AA2B7, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); return eax; } diff --git a/src/scenario.c b/src/scenario.c index 8e58d09e78..b27fd4f830 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -109,7 +109,7 @@ void scenario_load(const char *path) if (s6Header->num_packed_objects > 0) { j = 0; for (i = 0; i < s6Header->num_packed_objects; i++) - j += object_load_packed(); + j += object_load_packed(file); if (j > 0) object_list_load(); }