1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-31 10:45:16 +01:00

refactor object loading, part 2

This commit is contained in:
Duncan Frost
2014-12-07 21:58:19 +00:00
committed by IntelOrca
parent 1ed6e443ca
commit 68fe54cfdd
4 changed files with 201 additions and 257 deletions

View File

@@ -42,9 +42,9 @@ int object_load_entry(const char *path, rct_object_entry *outEntry)
return 1;
}
static int object_load_file(int groupIndex, const rct_object_entry *entry, int* chunkSize, const rct_object_entry *installedObject)
int object_load_file(int groupIndex, const rct_object_entry *entry, int* chunkSize, const rct_object_entry *installedObject)
{
int i, objectType;
uint8 objectType;
rct_object_entry openedEntry;
char path[260];
FILE *file;
@@ -64,13 +64,12 @@ static int object_load_file(int groupIndex, const rct_object_entry *entry, int*
}
// Get chunk size
char *pos = (char*)installedObject + 16;
do {
pos++;
} while (*(pos - 1) != 0);
uint8 *installedObject_pointer = (uint8*)installedObject + 16;
// Skip file name
while (*installedObject_pointer++);
// Read chunk
*chunkSize = *((uint32*)pos);
// Read chunk size
*chunkSize = *((uint32*)installedObject_pointer);
char *chunk;
if (*chunkSize == 0xFFFFFFFF) {
@@ -94,7 +93,9 @@ static int object_load_file(int groupIndex, const rct_object_entry *entry, int*
return 0;
}
if (object_paint(openedEntry.flags & 0x0F, 2, 0, openedEntry.flags & 0x0F, 0, (int)chunk, 0, 0)) {
objectType = openedEntry.flags & 0x0F;
if (object_paint(objectType, 2, 0, objectType, 0, (int)chunk, 0, 0)) {
log_error("Object Load failed due to paint failure.");
RCT2_GLOBAL(0x00F42BD9, uint8) = 3;
rct2_free(chunk);
@@ -109,31 +110,29 @@ static int object_load_file(int groupIndex, const rct_object_entry *entry, int*
rct2_free(chunk);
return 0;
}
//B84 is openedEntry
objectType = openedEntry.flags & 0x0F;
int esi = RCT2_ADDRESS(0x98D97C, uint32)[objectType * 2];
uint8** chunk_list = object_entry_groups[objectType].chunks;
if (groupIndex == -1) {
for (i = 0; ((sint32*)esi)[i] != -1; i++) {
if (i + 1 >= object_entry_group_counts[objectType]) {
log_error("Object Load failed due to ??? failure.");
for (groupIndex = 0; chunk_list[groupIndex] != (uint8*)-1; groupIndex++) {
if (groupIndex + 1 >= object_entry_group_counts[objectType]) {
log_error("Object Load failed due to too many objects of a certain type.");
RCT2_GLOBAL(0x00F42BD9, uint8) = 5;
rct2_free(chunk);
return 0;
}
}
groupIndex = i;
}
((char**)esi)[groupIndex] = chunk;
chunk_list[groupIndex] = chunk;
int* edx = (int*)(groupIndex * 20 + RCT2_ADDRESS(0x98D980, uint32)[objectType * 2]);
memcpy(edx, (int*)&openedEntry, 20);
rct_object_entry_extended* extended_entry = &object_entry_groups[objectType].entries[groupIndex];
memcpy(extended_entry, &openedEntry, sizeof(rct_object_entry));
extended_entry->chunk_size = *chunkSize;
RCT2_GLOBAL(RCT2_ADDRESS_CURR_OBJECT_CHUNK_POINTER, char*) = chunk;
if (RCT2_GLOBAL(0x9ADAFD, uint8) == 0)
return 1;
object_paint(objectType, 0, groupIndex, objectType, 0, (int)chunk, 0, 0);
if (RCT2_GLOBAL(0x9ADAFD, uint8) != 0)
object_paint(objectType, 0, groupIndex, objectType, 0, (int)chunk, 0, 0);
return 1;
}
@@ -180,20 +179,20 @@ int sub_6A9F42(FILE *file, rct_object_entry* entry){
object_paint(type, 1, entryGroupIndex, type, edx, chunk, edi, ebp);
rct_object_entry* installed_entry = (rct_object_entry*)(entryGroupIndex * 20 + RCT2_ADDRESS(0x98D980, uint32)[type * 2]);
rct_object_entry_extended* installed_entry = &object_entry_groups[type].entries[entryGroupIndex];
uint8* dst_buffer = malloc(0x600000);
memcpy(dst_buffer, (void*)installed_entry, 16);
memcpy(dst_buffer, (uint8*)installed_entry, sizeof(rct_object_entry));
uint32 size_dst = 16;
uint32 size_dst = sizeof(rct_object_entry);
sawyercoding_chunk_header chunkHeader;
// Encoding type (not used anymore)
RCT2_GLOBAL(0x9E3CBD, uint8) = object_entry_group_encoding[type];
chunkHeader.encoding = object_entry_group_encoding[type];
chunkHeader.length = *(uint32*)(((uint8*)installed_entry + 16));
chunkHeader.length = installed_entry->chunk_size;
size_dst += sawyercoding_write_chunk_buffer(dst_buffer+16, (uint8*)chunk, chunkHeader);
size_dst += sawyercoding_write_chunk_buffer(dst_buffer + sizeof(rct_object_entry), (uint8*)chunk, chunkHeader);
fwrite(dst_buffer, 1, size_dst, file);
free(dst_buffer);
@@ -242,7 +241,7 @@ int object_load_packed(FILE *file)
int entryGroupIndex = 0;
for (; entryGroupIndex < object_entry_group_counts[type]; entryGroupIndex++){
if (RCT2_ADDRESS(0x98D97C, uint32*)[type * 2][entryGroupIndex] == -1){
if (object_entry_groups[type].chunks[entryGroupIndex] == (uint8*)-1){
break;
}
}
@@ -252,10 +251,10 @@ int object_load_packed(FILE *file)
return 0;
}
RCT2_ADDRESS(0x98D97C, uint8**)[type * 2][entryGroupIndex] = chunk;
int* edx = (int*)(entryGroupIndex * 20 + RCT2_ADDRESS(0x98D980, uint32)[type * 2]);
memcpy(edx, (int*)entry, 16);
*(edx + 4) = chunkSize;
object_entry_groups[type].chunks[entryGroupIndex] = chunk;
rct_object_entry_extended* edx = &object_entry_groups[type].entries[entryGroupIndex];
memcpy(edx, (int*)entry, sizeof(rct_object_entry));
edx->chunk_size = chunkSize;
//esi
rct_object_entry *installedObject = RCT2_GLOBAL(RCT2_ADDRESS_INSTALLED_OBJECT_LIST, rct_object_entry*);
@@ -307,7 +306,7 @@ int object_load_packed(FILE *file)
// The following section cannot be finished until 6A9F42 is finished
// Run the game once with vanila rct2 to not reach this part of code.
RCT2_ERROR("Function not finished. Please run this save once with vanila rct2.");
log_verbose("Function might not be finished.");
FILE* obj_file = fopen(path, "wb");
if (obj_file){
// Removed progress bar code
@@ -326,7 +325,7 @@ int object_load_packed(FILE *file)
//6aa48C
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;
return 1;
}
/**
@@ -407,7 +406,7 @@ int object_scenario_load_custom_text(char* chunk){
int object_paint(int type, int eax, int ebx, int ecx, int edx, int esi, int edi, int ebp)
{
//if (type == 10){
//if (type == OBJECT_TYPE_SCENARIO_TEXT){
// if (eax == 0) return object_scenario_load_custom_text((char*)esi);
//}
return RCT2_CALLPROC_X(RCT2_ADDRESS(0x0098D9D4, uint32)[type], eax, ebx, ecx, edx, esi, edi, ebp) & 0x100;
@@ -437,9 +436,8 @@ int object_get_scenario_text(rct_object_entry *entry)
// Get chunk size
char *pos = (char*)installedObject + 16;
do {
pos++;
} while (*(pos - 1) != 0);
// Skip file name
while (*pos++);
// Read chunk
int chunkSize = *((uint32*)pos);
@@ -515,17 +513,13 @@ rct_object_entry *object_get_next(rct_object_entry *entry)
pos += 16;
// Skip filename
do {
pos++;
} while (*(pos - 1) != 0);
while (*pos++);
// Skip
pos += 4;
// Skip name
do {
pos++;
} while (*(pos - 1) != 0);
while (*pos++);
// Skip size of chunk
pos += 4;
@@ -540,4 +534,4 @@ rct_object_entry *object_get_next(rct_object_entry *entry)
pos += 4;
return (rct_object_entry*)pos;
}
}