mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +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 "string_ids.h"
|
||||||
#include "window.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
|
// HACK These were originally passed back through registers
|
||||||
int gLastDrawStringX;
|
int gLastDrawStringX;
|
||||||
int gLastDrawStringY;
|
int gLastDrawStringY;
|
||||||
@@ -41,39 +48,43 @@ static void gfx_draw_dirty_blocks(int x, int y, int columns, int rows);
|
|||||||
*
|
*
|
||||||
* rct2: 0x00678998
|
* rct2: 0x00678998
|
||||||
*/
|
*/
|
||||||
void gfx_load_g1()
|
int gfx_load_g1()
|
||||||
{
|
{
|
||||||
HANDLE hFile;
|
FILE *file;
|
||||||
DWORD bytesRead;
|
rct_g1_header header;
|
||||||
DWORD header[2];
|
unsigned int i;
|
||||||
|
|
||||||
int i;
|
|
||||||
int g1BufferSize;
|
|
||||||
void* g1Buffer;
|
|
||||||
|
|
||||||
rct_g1_element *g1Elements = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element);
|
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 = fopen(get_file_path(PATH_ID_G1), "rb");
|
||||||
FILE_FLAG_RANDOM_ACCESS | FILE_ATTRIBUTE_NORMAL, NULL);
|
if (file != NULL) {
|
||||||
if (hFile != INVALID_HANDLE_VALUE) {
|
if (fread(&header, 8, 1, file) == 1) {
|
||||||
ReadFile(hFile, header, 8, &bytesRead, NULL);
|
// number of elements is stored in g1.dat, but because the entry headers are static, this can't be variable until
|
||||||
if (bytesRead == 8) {
|
// made into a dynamic array
|
||||||
g1BufferSize = header[1];
|
header.num_entries = 29294;
|
||||||
g1Buffer = rct2_malloc(g1BufferSize);
|
|
||||||
ReadFile(hFile, g1Elements, 29294 * sizeof(rct_g1_element), &bytesRead, NULL);
|
|
||||||
ReadFile(hFile, g1Buffer, g1BufferSize, &bytesRead, NULL);
|
|
||||||
CloseHandle(hFile);
|
|
||||||
|
|
||||||
for (i = 0; i < 29294; i++)
|
// Read element headers
|
||||||
g1Elements[i].offset += (int)g1Buffer;
|
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
|
// Unsuccessful
|
||||||
fprintf(stderr, "Unable to load g1.dat");
|
RCT2_ERROR("Unable to load g1.dat");
|
||||||
assert(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ typedef struct {
|
|||||||
extern int gLastDrawStringX;
|
extern int gLastDrawStringX;
|
||||||
extern int gLastDrawStringY;
|
extern int gLastDrawStringY;
|
||||||
|
|
||||||
void gfx_load_g1();
|
int gfx_load_g1();
|
||||||
|
|
||||||
void gfx_clear(rct_drawpixelinfo *dpi, int colour);
|
void gfx_clear(rct_drawpixelinfo *dpi, int colour);
|
||||||
void gfx_draw_pixel(rct_drawpixelinfo *dpi, int x, int y, 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
|
19, // scenery sets
|
||||||
1, // park entrance
|
1, // park entrance
|
||||||
1, // water
|
1, // water
|
||||||
1 // stex
|
1 // scenario text
|
||||||
};
|
};
|
||||||
|
|
||||||
struct { void **data; rct_object_entry_extended *entries; } object_entry_groups[] = {
|
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 + ( 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 + ( 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)), // 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