mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-15 20:12:35 +01:00
clean up loading of g1.dat
This commit is contained in:
59
src/gfx.c
59
src/gfx.c
@@ -29,6 +29,13 @@
|
||||
#include "string_ids.h"
|
||||
#include "window.h"
|
||||
|
||||
typedef struct {
|
||||
uint32 num_entries;
|
||||
uint32 total_size;
|
||||
} rct_g1_header;
|
||||
|
||||
void *_g1Buffer = NULL;
|
||||
|
||||
// HACK These were originally passed back through registers
|
||||
int gLastDrawStringX;
|
||||
int gLastDrawStringY;
|
||||
@@ -41,39 +48,43 @@ static void gfx_draw_dirty_blocks(int x, int y, int columns, int rows);
|
||||
*
|
||||
* rct2: 0x00678998
|
||||
*/
|
||||
void gfx_load_g1()
|
||||
int gfx_load_g1()
|
||||
{
|
||||
HANDLE hFile;
|
||||
DWORD bytesRead;
|
||||
DWORD header[2];
|
||||
|
||||
int i;
|
||||
int g1BufferSize;
|
||||
void* g1Buffer;
|
||||
FILE *file;
|
||||
rct_g1_header header;
|
||||
unsigned int i;
|
||||
|
||||
rct_g1_element *g1Elements = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element);
|
||||
|
||||
hFile = CreateFile(get_file_path(PATH_ID_G1), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
|
||||
FILE_FLAG_RANDOM_ACCESS | FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile != INVALID_HANDLE_VALUE) {
|
||||
ReadFile(hFile, header, 8, &bytesRead, NULL);
|
||||
if (bytesRead == 8) {
|
||||
g1BufferSize = header[1];
|
||||
g1Buffer = rct2_malloc(g1BufferSize);
|
||||
ReadFile(hFile, g1Elements, 29294 * sizeof(rct_g1_element), &bytesRead, NULL);
|
||||
ReadFile(hFile, g1Buffer, g1BufferSize, &bytesRead, NULL);
|
||||
CloseHandle(hFile);
|
||||
file = fopen(get_file_path(PATH_ID_G1), "rb");
|
||||
if (file != NULL) {
|
||||
if (fread(&header, 8, 1, file) == 1) {
|
||||
// number of elements is stored in g1.dat, but because the entry headers are static, this can't be variable until
|
||||
// made into a dynamic array
|
||||
header.num_entries = 29294;
|
||||
|
||||
for (i = 0; i < 29294; i++)
|
||||
g1Elements[i].offset += (int)g1Buffer;
|
||||
// Read element headers
|
||||
fread(g1Elements, header.num_entries * sizeof(rct_g1_element), 1, file);
|
||||
|
||||
return;
|
||||
// Read element data
|
||||
_g1Buffer = rct2_malloc(header.total_size);
|
||||
fread(_g1Buffer, header.total_size, 1, file);
|
||||
|
||||
fclose(file);
|
||||
|
||||
// Fix entry data offsets
|
||||
for (i = 0; i < header.num_entries; i++)
|
||||
g1Elements[i].offset += (int)_g1Buffer;
|
||||
|
||||
// Successful
|
||||
return 1;
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
// exit with error
|
||||
fprintf(stderr, "Unable to load g1.dat");
|
||||
assert(0);
|
||||
// Unsuccessful
|
||||
RCT2_ERROR("Unable to load g1.dat");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,7 +49,7 @@ typedef struct {
|
||||
extern int gLastDrawStringX;
|
||||
extern int gLastDrawStringY;
|
||||
|
||||
void gfx_load_g1();
|
||||
int gfx_load_g1();
|
||||
|
||||
void gfx_clear(rct_drawpixelinfo *dpi, int colour);
|
||||
void gfx_draw_pixel(rct_drawpixelinfo *dpi, int x, int y, int colour);
|
||||
|
||||
@@ -44,7 +44,7 @@ int object_entry_group_counts[] = {
|
||||
19, // scenery sets
|
||||
1, // park entrance
|
||||
1, // water
|
||||
1 // stex
|
||||
1 // scenario text
|
||||
};
|
||||
|
||||
struct { void **data; rct_object_entry_extended *entries; } object_entry_groups[] = {
|
||||
@@ -58,7 +58,7 @@ struct { void **data; rct_object_entry_extended *entries; } object_entry_groups[
|
||||
(void**)(0x009ACFA4 + ( 15 * 4)), (rct_object_entry_extended*)(0x00F3F03C + ( 15 * 20)), // scenery sets
|
||||
(void**)(0x009ACFA4 + ( 19 * 4)), (rct_object_entry_extended*)(0x00F3F03C + ( 19 * 20)), // park entrance
|
||||
(void**)(0x009ACFA4 + ( 1 * 4)), (rct_object_entry_extended*)(0x00F3F03C + ( 1 * 20)), // water
|
||||
(void**)(0x009ACFA4 + ( 1 * 4)), (rct_object_entry_extended*)(0x00F3F03C + ( 1 * 20)) // stex
|
||||
(void**)(0x009ACFA4 + ( 1 * 4)), (rct_object_entry_extended*)(0x00F3F03C + ( 1 * 20)) // scenario text
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user