From 4bffc4b1317ebdfa3b61c965b57a38f014395457 Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 30 Dec 2016 02:21:18 +0000 Subject: [PATCH] Add ability to import RCT1 graphics --- src/openrct2/drawing/drawing.h | 2 + src/openrct2/drawing/sprite.c | 72 +++++++++++++++++++++++++++++++++- src/openrct2/rct2.c | 1 + 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/openrct2/drawing/drawing.h b/src/openrct2/drawing/drawing.h index 07f59bca8f..30318873c7 100644 --- a/src/openrct2/drawing/drawing.h +++ b/src/openrct2/drawing/drawing.h @@ -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); diff --git a/src/openrct2/drawing/sprite.c b/src/openrct2/drawing/sprite.c index 229dc3726a..2ba2de2bcc 100644 --- a/src/openrct2/drawing/sprite.c +++ b/src/openrct2/drawing/sprite.c @@ -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. diff --git a/src/openrct2/rct2.c b/src/openrct2/rct2.c index 09693b6ea3..c3e14c80f6 100644 --- a/src/openrct2/rct2.c +++ b/src/openrct2/rct2.c @@ -167,6 +167,7 @@ bool rct2_init() if (!gfx_load_g2()) { return false; } + gfx_load_csg(); font_sprite_initialise_characters(); if (!gOpenRCT2Headless) {