Files
@ r27443:1150c64644d0
Branch filter:
Location: cpp/openttd-patchpack/source/src/saveload/oldloader.h - annotation
r27443:1150c64644d0
4.6 KiB
text/x-c
Fix: Check max member count in squirrel classes (#10883)
Manual cherry-pick from https://github.com/albertodemichelis/squirrel/commit/23a0620658714b996d20da3d4dd1a0dcf9b0bd98
Manual cherry-pick from https://github.com/albertodemichelis/squirrel/commit/23a0620658714b996d20da3d4dd1a0dcf9b0bd98
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r14248:a9050881acd7 r10839:dea6c92d8e6d r15173:a59afd6301a6 r15173:a59afd6301a6 r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10881:c67980c1ee57 r10881:c67980c1ee57 r10881:c67980c1ee57 r10888:c2a7c3906efa r10881:c67980c1ee57 r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10935:662e8d56289a r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r18737:1ee35da7fa2f r10839:dea6c92d8e6d r10839:dea6c92d8e6d r14900:c679fdaeebe6 r10839:dea6c92d8e6d r10839:dea6c92d8e6d r24754:d4186fe759b7 r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r24754:d4186fe759b7 r24754:d4186fe759b7 r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r24521:57ec498b9221 r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10881:c67980c1ee57 r10881:c67980c1ee57 r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r10839:dea6c92d8e6d r14126:f23988064e74 r10839:dea6c92d8e6d r10839:dea6c92d8e6d r24754:d4186fe759b7 r24754:d4186fe759b7 r24754:d4186fe759b7 r24754:d4186fe759b7 r24754:d4186fe759b7 r24754:d4186fe759b7 r10881:c67980c1ee57 r10881:c67980c1ee57 r10839:dea6c92d8e6d r10839:dea6c92d8e6d | /*
* This file is part of OpenTTD.
* OpenTTD 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, version 2.
* OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file oldloader.h Declarations of strctures and function used in loader of old savegames */
#ifndef OLDLOADER_H
#define OLDLOADER_H
#include "saveload.h"
#include "../tile_type.h"
static const uint BUFFER_SIZE = 4096;
static const uint OLD_MAP_SIZE = 256 * 256;
struct LoadgameState {
FILE *file;
uint chunk_size;
bool decoding;
byte decode_char;
uint buffer_count;
uint buffer_cur;
byte buffer[BUFFER_SIZE];
uint total_read;
};
/* OldChunk-Type */
enum OldChunkType {
OC_SIMPLE = 0,
OC_NULL = 1,
OC_CHUNK = 2,
OC_ASSERT = 3,
/* 4 bits allocated (16 max) */
OC_TTD = 1 << 4, ///< chunk is valid ONLY for TTD savegames
OC_TTO = 1 << 5, ///< -//- TTO (default is neither of these)
/* 4 bits allocated */
OC_VAR_I8 = 1 << 8,
OC_VAR_U8 = 2 << 8,
OC_VAR_I16 = 3 << 8,
OC_VAR_U16 = 4 << 8,
OC_VAR_I32 = 5 << 8,
OC_VAR_U32 = 6 << 8,
OC_VAR_I64 = 7 << 8,
OC_VAR_U64 = 8 << 8,
/* 8 bits allocated (256 max) */
OC_FILE_I8 = 1 << 16,
OC_FILE_U8 = 2 << 16,
OC_FILE_I16 = 3 << 16,
OC_FILE_U16 = 4 << 16,
OC_FILE_I32 = 5 << 16,
OC_FILE_U32 = 6 << 16,
/* 8 bits allocated (256 max) */
OC_INT8 = OC_VAR_I8 | OC_FILE_I8,
OC_UINT8 = OC_VAR_U8 | OC_FILE_U8,
OC_INT16 = OC_VAR_I16 | OC_FILE_I16,
OC_UINT16 = OC_VAR_U16 | OC_FILE_U16,
OC_INT32 = OC_VAR_I32 | OC_FILE_I32,
OC_UINT32 = OC_VAR_U32 | OC_FILE_U32,
OC_TILE = OC_VAR_U32 | OC_FILE_U16,
/**
* Dereference the pointer once before writing to it,
* so we do not have to use big static arrays.
*/
OC_DEREFERENCE_POINTER = 1 << 31,
OC_END = 0, ///< End of the whole chunk, all 32 bits set to zero
};
DECLARE_ENUM_AS_BIT_SET(OldChunkType)
typedef bool OldChunkProc(LoadgameState *ls, int num);
typedef void *OffsetProc(void *base);
struct OldChunks {
OldChunkType type; ///< Type of field
uint32 amount; ///< Amount of fields
void *ptr; ///< Pointer where to save the data (takes precedence over #offset)
OffsetProc *offset; ///< Pointer to function that returns the actual memory address of a member (ignored if #ptr is not nullptr)
OldChunkProc *proc; ///< Pointer to function that is called with OC_CHUNK
};
/* If it fails, check lines above.. */
static_assert(sizeof(TileIndex) == 4);
extern uint _bump_assert_value;
byte ReadByte(LoadgameState *ls);
bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks);
bool LoadTTDMain(LoadgameState *ls);
bool LoadTTOMain(LoadgameState *ls);
static inline uint16 ReadUint16(LoadgameState *ls)
{
byte x = ReadByte(ls);
return x | ReadByte(ls) << 8;
}
static inline uint32 ReadUint32(LoadgameState *ls)
{
uint16 x = ReadUint16(ls);
return x | ReadUint16(ls) << 16;
}
/* Help:
* - OCL_SVAR: load 'type' to offset 'offset' in a struct of type 'base', which must also
* be given via base in LoadChunk() as real pointer
* - OCL_VAR: load 'type' to a global var
* - OCL_END: every struct must end with this
* - OCL_NULL: read 'amount' of bytes and send them to /dev/null or something
* - OCL_CHUNK: load another proc to load a part of the savegame, 'amount' times
* - OCL_ASSERT: to check if we are really at the place we expect to be.. because old savegames are too binary to be sure ;)
*/
#define OCL_SVAR(type, base, offset) { type, 1, nullptr, [] (void *b) -> void * { return std::addressof(static_cast<base *>(b)->offset); }, nullptr }
#define OCL_VAR(type, amount, pointer) { type, amount, pointer, nullptr, nullptr }
#define OCL_END() { OC_END, 0, nullptr, nullptr, nullptr }
#define OCL_CNULL(type, amount) { OC_NULL | type, amount, nullptr, nullptr, nullptr }
#define OCL_CCHUNK(type, amount, proc) { OC_CHUNK | type, amount, nullptr, nullptr, proc }
#define OCL_ASSERT(type, size) { OC_ASSERT | type, 1, (void *)(size_t)size, nullptr, nullptr }
#define OCL_NULL(amount) OCL_CNULL((OldChunkType)0, amount)
#define OCL_CHUNK(amount, proc) OCL_CCHUNK((OldChunkType)0, amount, proc)
#endif /* OLDLOADER_H */
|