From 761fdfb7c048bbdc7cdcc0842b63fa5f40152727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sun, 19 Jun 2016 23:03:05 +0200 Subject: [PATCH] Integrate gTotalNoImages --- src/object.c | 15 ++++++++------- src/object.h | 1 + src/object_list.c | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/object.c b/src/object.c index 2cb315bfdf..80594f71fc 100644 --- a/src/object.c +++ b/src/object.c @@ -31,6 +31,7 @@ #include "world/water.h" char gTempObjectLoadName[9] = { 0 }; +uint32 gTotalNoImages = 0; int object_load_entry(const utf8 *path, rct_object_entry *outEntry) { @@ -113,7 +114,7 @@ int object_load_file(int groupIndex, const rct_object_entry *entry, int* chunkSi return 0; } - if (RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_NO_IMAGES, uint32) >= 0x4726E){ + if (gTotalNoImages >= 0x4726E){ log_error("Object Load failed due to too many images loaded."); free(chunk); return 0; @@ -292,7 +293,7 @@ int object_load_packed(SDL_RWops* rw) return 0; } - if (RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_NO_IMAGES, uint32) >= 0x4726E){ + if (gTotalNoImages >= 0x4726E){ log_error("Packed object has too many images."); free(chunk); return 0; @@ -446,7 +447,7 @@ int object_calculate_checksum(const rct_object_entry *entry, const uint8 *data, */ int object_chunk_load_image_directory(uint8_t** chunk) { - int image_start_no = RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_NO_IMAGES, uint32_t); + int image_start_no = gTotalNoImages; // First dword of chunk is no_images int no_images = *((uint32_t*)(*chunk)); @@ -455,7 +456,7 @@ int object_chunk_load_image_directory(uint8_t** chunk) int length_of_data = *((uint32_t*)(*chunk)); *chunk += 4; - RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_NO_IMAGES, uint32_t) = no_images + image_start_no; + gTotalNoImages = no_images + image_start_no; rct_g1_element* g1_dest = &g1Elements[image_start_no]; @@ -1711,11 +1712,11 @@ int object_get_scenario_text(rct_object_entry *entry) } // Save the real total images. - int total_no_images = RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_NO_IMAGES, uint32); + int total_no_images = gTotalNoImages; // This is being changed to force the images to be loaded into a different // image id. - RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_NO_IMAGES, uint32) = 0x726E; + gTotalNoImages = 0x726E; gStexTempChunk = (rct_stex_entry*)chunk; // Not used anywhere. RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_TEXT_TEMP_OBJECT, rct_object_entry) = openedEntry; @@ -1730,7 +1731,7 @@ int object_get_scenario_text(rct_object_entry *entry) RCT2_GLOBAL(0x009ADAFC, uint8) = 0; // Not used?? RCT2_GLOBAL(0x009ADAFD, uint8) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_NO_IMAGES, uint32) = total_no_images; + gTotalNoImages = total_no_images; return 1; } log_error("Opened object didn't match."); diff --git a/src/object.h b/src/object.h index c991489913..3c9b1a3ea2 100644 --- a/src/object.h +++ b/src/object.h @@ -106,6 +106,7 @@ extern uint32 gInstalledObjectsCount; extern rct_object_entry *gInstalledObjects; extern uint32 gNumInstalledRCT2Objects; extern uint32 gNumInstalledCustomObjects; +extern uint32 gTotalNoImages; extern void *gLastLoadedObjectChunkData; diff --git a/src/object_list.c b/src/object_list.c index b39b7aec39..99dced7f34 100644 --- a/src/object_list.c +++ b/src/object_list.c @@ -230,7 +230,7 @@ void reset_loaded_objects() { reset_type_to_ride_entry_index_map(); - RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_NO_IMAGES, uint32) = 0xF26E; + gTotalNoImages = 0xF26E; for (int type = 0; type < 11; ++type){ for (int j = 0; j < object_entry_group_counts[type]; j++){ @@ -786,7 +786,7 @@ static uint32 install_object_entry(rct_object_entry* entry, rct_object_entry* in *((uint16*)(installed_entry_pointer + 9)) = 0; *((uint32*)(installed_entry_pointer + 11)) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_NO_IMAGES, uint32) = 0xF26E; + gTotalNoImages = 0xF26E; gInstalledObjectsCount++; @@ -839,7 +839,7 @@ static uint32 install_object_entry(rct_object_entry* entry, rct_object_entry* in // This is deceptive. Due to setting the total no images earlier to 0xF26E // this is actually the no_images in this entry. - *((uint32*)installed_entry_pointer) = RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_NO_IMAGES, uint32) - 0xF26E; + *((uint32*)installed_entry_pointer) = gTotalNoImages - 0xF26E; installed_entry_pointer += 4; uint8* esi = RCT2_ADDRESS(0x00F42BDB, uint8);