From 32dec4ab523ec0d04e5ac958ed2c221a63aeafc7 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Thu, 10 Apr 2014 17:08:41 +0100 Subject: [PATCH] add some object loading --- projects/openrct2.vcxproj | 2 ++ projects/openrct2.vcxproj.filters | 6 ++++ src/object.c | 60 +++++++++++++++++++++++++++++++ src/object.h | 41 +++++++++++++++++++++ src/sawyercoding.c | 6 ++-- src/scenario.c | 21 ++--------- 6 files changed, 115 insertions(+), 21 deletions(-) create mode 100644 src/object.c create mode 100644 src/object.h diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index 2f4f995420..5bfd10fed8 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -26,6 +26,7 @@ + @@ -55,6 +56,7 @@ + diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters index 405b3f8f65..5f5a103a82 100644 --- a/projects/openrct2.vcxproj.filters +++ b/projects/openrct2.vcxproj.filters @@ -102,6 +102,9 @@ Header Files + + Header Files + @@ -191,6 +194,9 @@ Source Files + + Source Files + diff --git a/src/object.c b/src/object.c new file mode 100644 index 0000000000..3a5356fb2c --- /dev/null +++ b/src/object.c @@ -0,0 +1,60 @@ +/***************************************************************************** + * Copyright (c) 2014 Ted John + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * This file is part of OpenRCT2. + * + * OpenRCT2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *****************************************************************************/ + +#include "addresses.h" +#include "object.h" + +/** + * + * rct2: 0x006A8B40 + */ +void object_load_list() +{ + RCT2_CALLPROC_EBPSAFE(0x006A8B40); +} + +/** + * + * rct2: 0x006AA0C6 + */ +void object_read_and_load_entries(HFILE hFile) +{ + RCT2_CALLPROC_EBPSAFE(0x006AA0C6); + + // int i; + // rct_object_entry *entries; + // entries = malloc(721 * sizeof(rct_object_entry)); + // sawyercoding_read_chunk(hFile, entries); + // for (i = 0; i < 721; i++) { + // RCT2_CALLPROC_X(0x006A985D, 0, 0, i, 0, 0, 0, 0); + // } + // free(entries); +} + +/** + * + * rct2: 0x006AA2B7 + */ +int object_load_packed() +{ + int eax, ebx, ecx, edx, esi, edi, ebp; + RCT2_CALLFUNC_X(0x006AA2B7, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + return eax; +} \ No newline at end of file diff --git a/src/object.h b/src/object.h new file mode 100644 index 0000000000..0ba15028b6 --- /dev/null +++ b/src/object.h @@ -0,0 +1,41 @@ +/***************************************************************************** + * Copyright (c) 2014 Ted John + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * This file is part of OpenRCT2. + * + * OpenRCT2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *****************************************************************************/ + +#ifndef _OBJECT_H_ +#define _OBJECT_H_ + +#include +#include "rct2.h" + +/** + * Object entry structure. + * size: 0x0100 + */ +typedef struct { + uint32 var_00; + char name[8]; // 0x04 + uint32 var_0C; +} rct_object_entry; + +void object_load_list(); +void object_read_and_load_entries(HFILE hFile); +int object_load_packed(); + +#endif \ No newline at end of file diff --git a/src/sawyercoding.c b/src/sawyercoding.c index 3e8214544e..1945e6a167 100644 --- a/src/sawyercoding.c +++ b/src/sawyercoding.c @@ -80,11 +80,11 @@ static int decode_chunk_rle(char *buffer, int length) rleCodeByte = src[i]; if (rleCodeByte & 128) { i++; - count = 1 - rleCodeByte + 256; + count = 257 - rleCodeByte; for (j = 0; j < count; j++) *dst++ = src[i]; } else { - for (j = 0; j < rleCodeByte; j++) + for (j = 0; j <= rleCodeByte; j++) *dst++ = src[++i]; } } @@ -114,7 +114,7 @@ static int decode_chunk_repeat(char *buffer, int length) if (src[i] == 0xFF) { *dst++ = src[++i]; } else { - count = src[i] & 7; + count = (src[i] & 7) + 1; copyOffset = dst + (int)(src[i] >> 3) - 32; for (j = 0; j < count; j++) *dst++ = *copyOffset++; diff --git a/src/scenario.c b/src/scenario.c index aeb96c4567..c4004a3636 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -23,6 +23,7 @@ #include #include "addresses.h" #include "map.h" +#include "object.h" #include "rct2.h" #include "sawyercoding.h" #include "scenario.h" @@ -303,17 +304,6 @@ static int scenario_load_basic(char *path) return 0; } -/** - * - * rct2: 0x006AA2B7 - */ -static int object_load_packed() -{ - int eax, ebx, ecx, edx, esi, edi, ebp; - RCT2_CALLFUNC_X(0x006AA2B7, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - return eax; -} - /** * * rct2: 0x00676053 @@ -326,10 +316,6 @@ void scenario_load(char *path) rct_s6_header *s6Header = 0x009E34E4; rct_s6_info *s6Info = 0x0141F570; - strcpy(RCT2_ADDRESS(0x0141EF68, char), path); - RCT2_CALLPROC_EBPSAFE(0x00676053); - return; - hFile = CreateFile( path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS | FILE_ATTRIBUTE_NORMAL, NULL ); @@ -348,11 +334,10 @@ void scenario_load(char *path) for (i = 0; i < s6Header->num_packed_objects; i++) j += object_load_packed(); if (j > 0) - RCT2_CALLPROC_EBPSAFE(0x006A8B40); // object_load_list + object_load_list(); } - // Read available items (721 * 16) - RCT2_CALLPROC_EBPSAFE(0x006AA0C6); + object_read_and_load_entries(hFile); // Read flags (16 bytes) sawyercoding_read_chunk(hFile, RCT2_ADDRESS_CURRENT_MONTH_YEAR);