Add ability to import RCT1 graphics

This commit is contained in:
Ted John 2016-12-30 02:21:18 +00:00 committed by Gymnasiast
parent 55972f17f8
commit 4bffc4b131
3 changed files with 74 additions and 1 deletions

View File

@ -313,8 +313,10 @@ void gfx_filter_rect(rct_drawpixelinfo *dpi, sint32 left, sint32 top, sint32 rig
// sprite
bool gfx_load_g1();
bool gfx_load_g2();
bool gfx_load_csg();
void gfx_unload_g1();
void gfx_unload_g2();
void gfx_unload_csg();
rct_g1_element* gfx_get_g1_element(sint32 image_id);
uint32 gfx_object_allocate_images(const rct_g1_element * images, uint32 count);
void gfx_object_free_images(uint32 baseImageId, uint32 count);

View File

@ -14,9 +14,10 @@
*****************************************************************************/
#pragma endregion
#include "../rct2/addresses.h"
#include "../common.h"
#include "../config.h"
#include "../OpenRCT2.h"
#include "../rct2/addresses.h"
#include "../sprites.h"
#include "../util/util.h"
#include "drawing.h"
@ -24,6 +25,7 @@
void *_g1Buffer = NULL;
rct_gx g2;
rct_gx csg;
#ifdef NO_RCT2
rct_g1_element *g1Elements = NULL;
@ -121,6 +123,11 @@ void gfx_unload_g2()
SafeFree(g2.elements);
}
void gfx_unload_csg()
{
SafeFree(csg.elements);
}
bool gfx_load_g2()
{
log_verbose("loading g2 graphics");
@ -159,6 +166,69 @@ bool gfx_load_g2()
return false;
}
bool gfx_load_csg()
{
if (str_is_null_or_empty(gConfigGeneral.rct1_path)) {
return false;
}
bool success = false;
log_verbose("loading csg graphics");
char pathHeader[MAX_PATH];
safe_strcpy(pathHeader, gConfigGeneral.rct1_path, sizeof(pathHeader));
safe_strcat_path(pathHeader, "Data", sizeof(pathHeader));
safe_strcat_path(pathHeader, "csg1i.dat", sizeof(pathHeader));
char pathData[MAX_PATH];
safe_strcpy(pathData, gConfigGeneral.rct1_path, sizeof(pathData));
safe_strcat_path(pathData, "Data", sizeof(pathData));
safe_strcat_path(pathData, "csg1.1", sizeof(pathData));
SDL_RWops * fileHeader = SDL_RWFromFile(pathHeader, "rb");
SDL_RWops * fileData = SDL_RWFromFile(pathData, "rb");
if (fileHeader != NULL && fileData != NULL) {
SDL_RWseek(fileHeader, 0, RW_SEEK_END);
SDL_RWseek(fileData, 0, RW_SEEK_END);
size_t fileHeaderSize = SDL_RWtell(fileHeader);
size_t fileDataSize = SDL_RWtell(fileData);
SDL_RWseek(fileHeader, 0, RW_SEEK_SET);
SDL_RWseek(fileData, 0, RW_SEEK_SET);
csg.header.num_entries = (uint32)(fileHeaderSize / sizeof(rct_g1_element_32bit));
csg.header.total_size = (uint32)fileDataSize;
// Read element headers
csg.elements = malloc(csg.header.num_entries * sizeof(rct_g1_element));
read_and_convert_gxdat(fileHeader, csg.header.num_entries, csg.elements);
// Read element data
csg.data = malloc(csg.header.total_size);
SDL_RWread(fileData, csg.data, csg.header.total_size, 1);
// Fix entry data offsets
for (uint32 i = 0; i < csg.header.num_entries; i++) {
csg.elements[i].offset += (uintptr_t)csg.data;
}
success = true;
}
if (fileHeader != NULL) {
SDL_RWclose(fileHeader);
}
if (fileData != NULL) {
SDL_RWclose(fileData);
}
if (success) {
return true;
} else {
log_error("Unable to load csg graphics");
return false;
}
}
/**
* This function looks like it initialises the 0x009E3CE4 array which references sprites used for background / palette mixing or
* something. Further investigation is needed.

View File

@ -167,6 +167,7 @@ bool rct2_init()
if (!gfx_load_g2()) {
return false;
}
gfx_load_csg();
font_sprite_initialise_characters();
if (!gOpenRCT2Headless) {