mirror of https://github.com/OpenRCT2/OpenRCT2.git
Added a fixed version of read_chunk requires more testing before joining
This commit is contained in:
parent
81121db634
commit
5cf517c789
23
src/object.c
23
src/object.c
|
@ -65,15 +65,16 @@ int object_load(int groupIndex, rct_object_entry *entry)
|
||||||
// Read chunk
|
// Read chunk
|
||||||
int chunkSize = *((uint32*)pos);
|
int chunkSize = *((uint32*)pos);
|
||||||
char *chunk;
|
char *chunk;
|
||||||
//if (chunkSize == 0xFFFFFFFF) {
|
|
||||||
|
if (chunkSize == 0xFFFFFFFF) {
|
||||||
chunk = malloc(0x600000);
|
chunk = malloc(0x600000);
|
||||||
chunkSize = sawyercoding_read_chunk(file, chunk);
|
chunkSize = sawyercoding_read_chunk_variable(file, &chunk);
|
||||||
chunk = realloc(chunk, chunkSize);
|
chunk = realloc(chunk, chunkSize);
|
||||||
//}
|
}
|
||||||
//else {
|
else {
|
||||||
// chunk = malloc(chunkSize);
|
chunk = malloc(chunkSize);
|
||||||
// chunkSize = sawyercoding_read_chunk(file, chunk);
|
chunkSize = sawyercoding_read_chunk_variable(file, &chunk);
|
||||||
//}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
// Calculate and check checksum
|
// Calculate and check checksum
|
||||||
|
@ -83,10 +84,10 @@ int object_load(int groupIndex, rct_object_entry *entry)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object_paint(openedEntry.flags & 0x0F, 2, 0, 0, 0, (int)chunk, 0, 0)) {
|
if (object_paint(openedEntry.flags & 0x0F, 2, 0, openedEntry.flags & 0x0F, 0, (int)chunk, 0, 0)) {
|
||||||
RCT2_GLOBAL(0x00F42BD9, uint8) = 3;
|
//RCT2_GLOBAL(0x00F42BD9, uint8) = 3;
|
||||||
free(chunk);
|
//free(chunk);
|
||||||
return 0;
|
//return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int yyy = RCT2_GLOBAL(0x009ADAF0, uint32);
|
int yyy = RCT2_GLOBAL(0x009ADAF0, uint32);
|
||||||
|
|
|
@ -68,6 +68,85 @@ int sawyercoding_validate_checksum(FILE *file)
|
||||||
return checksum == fileChecksum;
|
return checksum == fileChecksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int decode_chunk_rle_variable(uint8 *src_buffer, uint8** dst_buffer, int src_length);
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* rct2: 0x0067685F
|
||||||
|
* buffer (esi)
|
||||||
|
* this is a temp function
|
||||||
|
*/
|
||||||
|
int sawyercoding_read_chunk_variable(FILE *file, uint8 **dst_buffer)
|
||||||
|
{
|
||||||
|
sawyercoding_chunk_header chunkHeader;
|
||||||
|
|
||||||
|
// Read chunk header
|
||||||
|
if (fread(&chunkHeader, sizeof(sawyercoding_chunk_header), 1, file) != 1) {
|
||||||
|
RCT2_ERROR("Unable to read chunk header!");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8* src_buffer = malloc(chunkHeader.length);
|
||||||
|
// Read chunk data
|
||||||
|
if (fread(src_buffer, chunkHeader.length, 1, file) != 1) {
|
||||||
|
free(src_buffer);
|
||||||
|
RCT2_ERROR("Unable to read chunk data!");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Decode chunk data
|
||||||
|
switch (chunkHeader.encoding) {
|
||||||
|
case CHUNK_ENCODING_RLE:
|
||||||
|
chunkHeader.length = decode_chunk_rle_variable(src_buffer, dst_buffer, chunkHeader.length);
|
||||||
|
break;
|
||||||
|
case CHUNK_ENCODING_ROTATE:
|
||||||
|
decode_chunk_rotate(src_buffer, chunkHeader.length);
|
||||||
|
memcpy(*dst_buffer, src_buffer, chunkHeader.length);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// For now this is temp function
|
||||||
|
free(src_buffer);
|
||||||
|
RCT2_ERROR("Unable to read chunk data!");
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(src_buffer);
|
||||||
|
// Set length
|
||||||
|
RCT2_GLOBAL(0x009E3828, uint32) = chunkHeader.length;
|
||||||
|
return chunkHeader.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Temp function
|
||||||
|
* rct2: 0x0067693A
|
||||||
|
*/
|
||||||
|
int decode_chunk_rle_variable(uint8* src_buffer, uint8 **dst_buffer, int src_length)
|
||||||
|
{
|
||||||
|
int i, j, count;
|
||||||
|
unsigned char *src, *dst, rleCodeByte;
|
||||||
|
|
||||||
|
src = src_buffer;
|
||||||
|
dst = *dst_buffer;
|
||||||
|
|
||||||
|
for (i = 0; i < src_length; i++) {
|
||||||
|
rleCodeByte = src[i];
|
||||||
|
if (rleCodeByte & 128) {
|
||||||
|
i++;
|
||||||
|
count = 257 - rleCodeByte;
|
||||||
|
for (j = 0; j < count; j++)
|
||||||
|
*dst++ = src[i];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (j = 0; j <= rleCodeByte; j++)
|
||||||
|
*dst++ = src[++i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return final size
|
||||||
|
return dst - *dst_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* rct2: 0x0067685F
|
* rct2: 0x0067685F
|
||||||
|
|
|
@ -38,5 +38,6 @@ enum {
|
||||||
|
|
||||||
int sawyercoding_validate_checksum(FILE *file);
|
int sawyercoding_validate_checksum(FILE *file);
|
||||||
int sawyercoding_read_chunk(FILE *file, uint8 *buffer);
|
int sawyercoding_read_chunk(FILE *file, uint8 *buffer);
|
||||||
|
int sawyercoding_read_chunk_variable(FILE *file, uint8 **buffer);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue