Centralise error codes list

This commit is contained in:
UnknownShadow200 2018-08-07 22:45:45 +10:00
parent f3e8fb5678
commit 24d3fb3e2a
23 changed files with 184 additions and 263 deletions

View file

@ -11,7 +11,7 @@ void ASyncRequest_Free(struct AsyncRequest* request) {
#define ASYNCREQUESTLIST_DEFELEMS 10
struct AsyncRequestList {
UInt32 MaxElems, Count;
Int32 MaxElems, Count;
struct AsyncRequest* Requests;
struct AsyncRequest DefaultRequests[ASYNCREQUESTLIST_DEFELEMS];
};
@ -29,7 +29,7 @@ static void AsyncRequestList_Append(struct AsyncRequestList* list, struct AsyncR
static void AsyncRequestList_Prepend(struct AsyncRequestList* list, struct AsyncRequest* item) {
AsyncRequestList_EnsureSpace(list);
UInt32 i;
Int32 i;
for (i = list->Count; i > 0; i--) {
list->Requests[i] = list->Requests[i - 1];
}
@ -37,8 +37,8 @@ static void AsyncRequestList_Prepend(struct AsyncRequestList* list, struct Async
list->Count++;
}
static void AsyncRequestList_RemoveAt(struct AsyncRequestList* list, UInt32 i) {
if (i >= list->Count) ErrorHandler_Fail("Tried to remove element at list end");
static void AsyncRequestList_RemoveAt(struct AsyncRequestList* list, Int32 i) {
if (i < 0 || i >= list->Count) ErrorHandler_Fail("Tried to remove element at list end");
for (; i < list->Count - 1; i++) {
list->Requests[i] = list->Requests[i + 1];

View file

@ -8,6 +8,7 @@
#include "Block.h"
#include "Game.h"
#include "GameStructs.h"
#include "Errors.h"
StringsBuffer files;
/*########################################################################################################################*
@ -31,32 +32,35 @@ struct Soundboard {
};
#define WAV_FourCC(a, b, c, d) (((UInt32)a << 24) | ((UInt32)b << 16) | ((UInt32)c << 8) | (UInt32)d)
enum WAV_ERR {
WAV_ERR_STREAM_HDR = 329701, WAV_ERR_STREAM_TYPE, WAV_ERR_DATA_TYPE, WAV_ERR_NO_DATA
};
#define WAV_FMT_SIZE 16
static ReturnCode Sound_ReadWaveData(struct Stream* stream, struct Sound* snd) {
UInt32 fourCC, size, pos, len;
ReturnCode res;
UInt8 tmp[WAV_FMT_SIZE];
fourCC = Stream_ReadU32_BE(stream);
Stream_Read(stream, tmp, 3 * sizeof(UInt32));
fourCC = Stream_GetU32_BE(&tmp[0]);
if (fourCC != WAV_FourCC('R','I','F','F')) return WAV_ERR_STREAM_HDR;
Stream_ReadU32_LE(stream); /* file size, but we don't care */
fourCC = Stream_ReadU32_BE(stream);
/* tmp[4] (4) file size */
fourCC = Stream_GetU32_BE(&tmp[8]);
if (fourCC != WAV_FourCC('W','A','V','E')) return WAV_ERR_STREAM_TYPE;
while (!(res = stream->Position(stream, &pos)) && !(res = stream->Length(stream, &len)) && pos < len) {
fourCC = Stream_ReadU32_BE(stream);
size = Stream_ReadU32_LE(stream);
Stream_Read(stream, tmp, 2 * sizeof(UInt32));
fourCC = Stream_GetU32_BE(&tmp[0]);
size = Stream_GetU32_BE(&tmp[4]);
if (fourCC == WAV_FourCC('f','m','t',' ')) {
if (Stream_ReadU16_LE(stream) != 1) return WAV_ERR_DATA_TYPE;
Stream_Read(stream, tmp, WAV_FMT_SIZE);
if (Stream_GetU16_LE(&tmp[0]) != 1) return WAV_ERR_DATA_TYPE;
snd->Format.Channels = Stream_ReadU16_LE(stream);
snd->Format.SampleRate = Stream_ReadU32_LE(stream);
Stream_Skip(stream, 6);
snd->Format.BitsPerSample = Stream_ReadU16_LE(stream);
size -= 16;
snd->Format.Channels = Stream_GetU16_LE(&tmp[2]);
snd->Format.SampleRate = Stream_GetU32_LE(&tmp[4]);
/* tmp[8] (6) alignment data and stuff */
snd->Format.BitsPerSample = Stream_GetU16_LE(&tmp[14]);
size -= WAV_FMT_SIZE;
} else if (fourCC == WAV_FourCC('d','a','t','a')) {
snd->Data = Mem_Alloc(size, sizeof(UInt8), "WAV sound data");
snd->DataSize = size;
@ -264,7 +268,7 @@ volatile bool music_pendingStop;
#define MUSIC_MAX_FILES 512
static void Music_RunLoop(void) {
UInt32 i, count = 0;
Int32 i, count = 0;
UInt16 musicFiles[MUSIC_MAX_FILES];
String ogg = String_FromConst(".ogg");

View file

@ -5,6 +5,7 @@
#include "Deflate.h"
#include "ErrorHandler.h"
#include "Stream.h"
#include "Errors.h"
void Bitmap_Create(struct Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0) {
bmp->Width = width; bmp->Height = height; bmp->Scan0 = scan0;
@ -426,8 +427,12 @@ ReturnCode Bitmap_DecodePng(struct Bitmap* bmp, struct Stream* stream) {
struct Stream datStream;
Stream_ReadonlyPortion(&datStream, stream, dataSize);
inflate.Source = &datStream;
/* TODO: This assumes zlib header will be in 1 IDAT chunk */
while (!zlibHeader.Done) { ZLibHeader_Read(&datStream, &zlibHeader); }
while (!zlibHeader.Done) {
ReturnCode result = ZLibHeader_Read(&datStream, &zlibHeader);
if (result) return result;
}
UInt32 bufferLen = bufferRows * scanlineBytes, bufferMax = bufferLen - scanlineBytes;
while (curY < bmp->Height) {

View file

@ -21,13 +21,6 @@ void Bitmap_Allocate(struct Bitmap* bmp, Int32 width, Int32 height);
void Bitmap_AllocateClearedPow2(struct Bitmap* bmp, Int32 width, Int32 height);
bool Bitmap_DetectPng(UInt8* data, UInt32 len);
enum PNG_ERR {
PNG_ERR_INVALID_SIG = 307001,
PNG_ERR_INVALID_HEADER_SIZE, PNG_ERR_TOO_WIDE, PNG_ERR_TOO_TALL,
PNG_ERR_INVALID_COL_BPP, PNG_ERR_COMP_METHOD, PNG_ERR_FILTER, PNG_ERR_INTERLACED,
PNG_ERR_PAL_ENTRIES, PNG_ERR_PAL_SIZE, PNG_ERR_TRANS_COUNT, PNG_ERR_TRANS_INVALID,
PNG_ERR_INVALID_END_SIZE
};
/*
Partially based off information from
https://handmade.network/forums/wip/t/2363-implementing_a_basic_png_reader_the_handmade_way

View file

@ -22,7 +22,7 @@ Int64* Chat_LogTimes = Chat_DefaultLogTimes;
UInt32 Chat_LogTimesMax = CHAT_LOGTIMES_DEF_ELEMS, Chat_LogTimesCount;
void Chat_GetLogTime(UInt32 index, Int64* timeMs) {
if (index >= Chat_LogTimesCount) ErrorHandler_Fail("Tries to get time past LogTime end");
if (index >= Chat_LogTimesCount) ErrorHandler_Fail("Tried to get time past LogTime end");
*timeMs = Chat_LogTimes[index];
}

View file

@ -199,6 +199,7 @@
<ClInclude Include="EntityComponents.h" />
<ClInclude Include="EnvRenderer.h" />
<ClInclude Include="ErrorHandler.h" />
<ClInclude Include="Errors.h" />
<ClInclude Include="Event.h" />
<ClInclude Include="Formats.h" />
<ClInclude Include="Deflate.h" />

View file

@ -342,6 +342,9 @@
<ClInclude Include="Vorbis.h">
<Filter>Header Files\Audio</Filter>
</ClInclude>
<ClInclude Include="Errors.h">
<Filter>Header Files\Utils</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="WinPlatform.c">

View file

@ -3,6 +3,7 @@
#include "Funcs.h"
#include "Platform.h"
#include "Stream.h"
#include "Errors.h"
static bool Header_ReadByte(struct Stream* s, UInt8* state, Int32* value) {
*value = Stream_TryReadByte(s);
@ -31,45 +32,45 @@ void GZipHeader_Init(struct GZipHeader* header) {
header->PartsRead = 0;
}
void GZipHeader_Read(struct Stream* s, struct GZipHeader* header) {
ReturnCode GZipHeader_Read(struct Stream* s, struct GZipHeader* header) {
Int32 temp;
switch (header->State) {
case GZIP_STATE_HEADER1:
if (!Header_ReadByte(s, &header->State, &temp)) return;
if (temp != 0x1F) { ErrorHandler_Fail("Byte 1 of GZIP header must be 1F"); }
if (!Header_ReadByte(s, &header->State, &temp)) return 0;
if (temp != 0x1F) return GZIP_ERR_HEADER1;
case GZIP_STATE_HEADER2:
if (!Header_ReadByte(s, &header->State, &temp)) return;
if (temp != 0x8B) { ErrorHandler_Fail("Byte 2 of GZIP header must be 8B"); }
if (!Header_ReadByte(s, &header->State, &temp)) return 0;
if (temp != 0x8B) return GZIP_ERR_HEADER2;
case GZIP_STATE_COMPRESSIONMETHOD:
if (!Header_ReadByte(s, &header->State, &temp)) return;
if (temp != 0x08) { ErrorHandler_Fail("Only DEFLATE compression supported"); }
if (!Header_ReadByte(s, &header->State, &temp)) return 0;
if (temp != 0x08) return GZIP_ERR_METHOD;
case GZIP_STATE_FLAGS:
if (!Header_ReadByte(s, &header->State, &header->Flags)) return;
if (header->Flags & 0x04) { ErrorHandler_Fail("Unsupported GZIP header flags"); }
if (!Header_ReadByte(s, &header->State, &header->Flags)) return 0;
if (header->Flags & 0x04) return GZIP_ERR_FLAGS;
case GZIP_STATE_LASTMODIFIEDTIME:
for (; header->PartsRead < 4; header->PartsRead++) {
temp = Stream_TryReadByte(s);
if (temp == -1) return;
if (temp == -1) return 0;
}
header->State++;
header->PartsRead = 0;
case GZIP_STATE_COMPRESSIONFLAGS:
if (!Header_ReadByte(s, &header->State, &temp)) return;
if (!Header_ReadByte(s, &header->State, &temp)) return 0;
case GZIP_STATE_OPERATINGSYSTEM:
if (!Header_ReadByte(s, &header->State, &temp)) return;
if (!Header_ReadByte(s, &header->State, &temp)) return 0;
case GZIP_STATE_FILENAME:
if (header->Flags & 0x08) {
for (; ;) {
temp = Stream_TryReadByte(s);
if (temp == -1) return;
if (temp == -1) return 0;
if (temp == '\0') break;
}
}
@ -79,7 +80,7 @@ void GZipHeader_Read(struct Stream* s, struct GZipHeader* header) {
if (header->Flags & 0x10) {
for (; ;) {
temp = Stream_TryReadByte(s);
if (temp == -1) return;
if (temp == -1) return 0;
if (temp == '\0') break;
}
}
@ -89,7 +90,7 @@ void GZipHeader_Read(struct Stream* s, struct GZipHeader* header) {
if (header->Flags & 0x02) {
for (; header->PartsRead < 2; header->PartsRead++) {
temp = Stream_TryReadByte(s);
if (temp == -1) return;
if (temp == -1) return 0;
}
}
@ -97,6 +98,7 @@ void GZipHeader_Read(struct Stream* s, struct GZipHeader* header) {
header->PartsRead = 0;
header->Done = true;
}
return 0;
}
@ -113,29 +115,24 @@ void ZLibHeader_Init(struct ZLibHeader* header) {
header->LZ77WindowSize = 0;
}
void ZLibHeader_Read(struct Stream* s, struct ZLibHeader* header) {
ReturnCode ZLibHeader_Read(struct Stream* s, struct ZLibHeader* header) {
Int32 temp;
switch (header->State) {
case ZLIB_STATE_COMPRESSIONMETHOD:
if (!Header_ReadByte(s, &header->State, &temp)) return;
if ((temp & 0x0F) != 0x08) {
ErrorHandler_Fail("Only DEFLATE compression supported");
}
if (!Header_ReadByte(s, &header->State, &temp)) return 0;
if ((temp & 0x0F) != 0x08) return ZLIB_ERR_METHOD;
Int32 log2Size = (temp >> 4) + 8;
header->LZ77WindowSize = 1L << log2Size;
if (header->LZ77WindowSize > 32768) {
ErrorHandler_Fail("LZ77 window size must be 32KB or less");
}
if (header->LZ77WindowSize > 32768) return ZLIB_ERR_WINDOW_SIZE;
case ZLIB_STATE_FLAGS:
if (!Header_ReadByte(s, &header->State, &temp)) return;
if ((temp & 0x20) != 0) {
ErrorHandler_Fail("Unsupported ZLIB header flags");
}
if (!Header_ReadByte(s, &header->State, &temp)) return 0;
if ((temp & 0x20) != 0) return ZLIB_ERR_FLAGS;
header->Done = true;
}
return 0;
}

View file

@ -13,11 +13,11 @@ struct Stream;
struct GZipHeader { UInt8 State; bool Done; UInt8 PartsRead; Int32 Flags; };
void GZipHeader_Init(struct GZipHeader* header);
void GZipHeader_Read(struct Stream* s, struct GZipHeader* header);
ReturnCode GZipHeader_Read(struct Stream* s, struct GZipHeader* header);
struct ZLibHeader { UInt8 State; bool Done; Int32 LZ77WindowSize; };
void ZLibHeader_Init(struct ZLibHeader* header);
void ZLibHeader_Read(struct Stream* s, struct ZLibHeader* header);
ReturnCode ZLibHeader_Read(struct Stream* s, struct ZLibHeader* header);
#define INFLATE_MAX_INPUT 8192

46
src/Client/Errors.h Normal file
View file

@ -0,0 +1,46 @@
#ifndef CC_ERRORS_H
#define CC_ERRORS_H
/* Represents list of internal errors.
Copyright 2017 ClassicalSharp | Licensed under BSD-3
*/
enum ERRORS_ALL {
ERROR_BASE = 0xCCDED000UL,
ERR_END_OF_STREAM,
/* Ogg stream decoding errors */
OGG_ERR_INVALID_SIG, OGG_ERR_VERSION,
/* WAV audio decoding errors*/
WAV_ERR_STREAM_HDR, WAV_ERR_STREAM_TYPE, WAV_ERR_DATA_TYPE, WAV_ERR_NO_DATA,
/* Vorbis audio decoding errors */
VORBIS_ERR_HEADER,
VORBIS_ERR_WRONG_HEADER, VORBIS_ERR_FRAMING,
VORBIS_ERR_VERSION, VORBIS_ERR_BLOCKSIZE, VORBIS_ERR_CHANS,
VORBIS_ERR_TIME_TYPE, VORBIS_ERR_FLOOR_TYPE, VORBIS_ERR_RESIDUE_TYPE,
VORBIS_ERR_MAPPING_TYPE, VORBIS_ERR_MODE_TYPE,
VORBIS_ERR_CODEBOOK_SYNC, VORBIS_ERR_CODEBOOK_ENTRY, VORBIS_ERR_CODEBOOK_LOOKUP,
VORBIS_ERR_MODE_WINDOW, VORBIS_ERR_MODE_TRANSFORM,
VORBIS_ERR_MAPPING_CHANS, VORBIS_ERR_MAPPING_RESERVED,
VORBIS_ERR_FRAME_TYPE,
/* PNG image decoding errors */
PNG_ERR_INVALID_SIG, PNG_ERR_INVALID_HEADER_SIZE, PNG_ERR_TOO_WIDE, PNG_ERR_TOO_TALL,
PNG_ERR_INVALID_COL_BPP, PNG_ERR_COMP_METHOD, PNG_ERR_FILTER, PNG_ERR_INTERLACED,
PNG_ERR_PAL_ENTRIES, PNG_ERR_PAL_SIZE, PNG_ERR_TRANS_COUNT, PNG_ERR_TRANS_INVALID,
PNG_ERR_INVALID_END_SIZE,
/* ZIP archive decoding errors */
ZIP_ERR_TOO_MANY_ENTRIES, ZIP_ERR_SEEK_END_OF_CENTRAL_DIR, ZIP_ERR_NO_END_OF_CENTRAL_DIR,
ZIP_ERR_SEEK_CENTRAL_DIR, ZIP_ERR_INVALID_CENTRAL_DIR,
ZIP_ERR_SEEK_LOCAL_DIR, ZIP_ERR_INVALID_LOCAL_DIR,
/* GZIP header decoding errors */
GZIP_ERR_HEADER1, GZIP_ERR_HEADER2, GZIP_ERR_METHOD, GZIP_ERR_FLAGS,
/* ZLIB header decoding errors */
ZLIB_ERR_METHOD, ZLIB_ERR_WINDOW_SIZE, ZLIB_ERR_FLAGS,
/* FCM map decoding errors */
FCM_ERR_IDENTIFIER, FCM_ERR_REVISION,
/* LVL map decoding errors */
LVL_ERR_VERSION,
/* DAT map decoding errors */
/* CW map decoding errors */
};
#endif

View file

@ -10,6 +10,7 @@
#include "ServerConnection.h"
#include "Event.h"
#include "Funcs.h"
#include "Errors.h"
static void Map_ReadBlocks(struct Stream* stream) {
World_BlocksSize = World_Width * World_Length * World_Height;
@ -17,6 +18,17 @@ static void Map_ReadBlocks(struct Stream* stream) {
Stream_Read(stream, World_Blocks, World_BlocksSize);
}
static ReturnCode Map_SkipGZipHeader(struct Stream* stream) {
struct GZipHeader gzHeader;
GZipHeader_Init(&gzHeader);
while (!gzHeader.Done) {
ReturnCode result = GZipHeader_Read(stream, &gzHeader);
if (result) return result;
}
return 0;
}
/*########################################################################################################################*
*--------------------------------------------------MCSharp level Format---------------------------------------------------*
@ -92,36 +104,38 @@ static void Lvl_ConvertPhysicsBlocks(void) {
}
}
void Lvl_Load(struct Stream* stream) {
struct GZipHeader gzHeader;
GZipHeader_Init(&gzHeader);
while (!gzHeader.Done) { GZipHeader_Read(stream, &gzHeader); }
ReturnCode Lvl_Load(struct Stream* stream) {
ReturnCode result = Map_SkipGZipHeader(stream);
if (result) return result;
struct Stream compStream;
struct InflateState state;
Inflate_MakeStream(&compStream, &state, stream);
UInt16 header = Stream_ReadU16_LE(&compStream);
World_Width = header == LVL_VERSION ? Stream_ReadU16_LE(&compStream) : header;
World_Length = Stream_ReadU16_LE(&compStream);
World_Height = Stream_ReadU16_LE(&compStream);
UInt8 header[8 + 2];
Stream_Read(&compStream, header, 8);
if (Stream_GetU16_LE(&header[0]) != LVL_VERSION) return LVL_ERR_VERSION;
World_Width = Stream_GetU16_LE(&header[2]);
World_Length = Stream_GetU16_LE(&header[4]);
World_Height = Stream_GetU16_LE(&header[6]);
Stream_Read(&compStream, header, sizeof(header));
struct LocalPlayer* p = &LocalPlayer_Instance;
p->Spawn.X = Stream_ReadU16_LE(&compStream);
p->Spawn.Z = Stream_ReadU16_LE(&compStream);
p->Spawn.Y = Stream_ReadU16_LE(&compStream);
p->SpawnRotY = Math_Packed2Deg(Stream_ReadU8(&compStream));
p->SpawnHeadX = Math_Packed2Deg(Stream_ReadU8(&compStream));
p->Spawn.X = Stream_GetU16_LE(&header[0]);
p->Spawn.Z = Stream_GetU16_LE(&header[2]);
p->Spawn.Y = Stream_GetU16_LE(&header[4]);
p->SpawnRotY = Math_Packed2Deg(header[6]);
p->SpawnHeadX = Math_Packed2Deg(header[7]);
if (header == LVL_VERSION) {
Stream_Skip(&compStream, 1 + 1); /* permissions: (1) pervisit, (1) perbuild */
}
/* (2) pervisit, perbuild permissions */
Map_ReadBlocks(&compStream);
Lvl_ConvertPhysicsBlocks();
if (Stream_TryReadByte(&compStream) == 0xBD) {
Lvl_ReadCustomBlocks(&compStream);
}
return 0;
}
@ -134,16 +148,14 @@ static void Fcm_ReadString(struct Stream* stream) {
Stream_Skip(stream, Stream_ReadU16_LE(stream));
}
void Fcm_Load(struct Stream* stream) {
if (Stream_ReadU32_LE(stream) != FCM_IDENTIFIER) {
ErrorHandler_Fail("Invalid identifier in .fcm file");
}
if (Stream_ReadU8(stream) != FCM_REVISION) {
ErrorHandler_Fail("Invalid revision in .fcm file");
}
UInt8 header[(3 * 2) + (3 * 4) + (2 * 1) + (2 * 4) + 16 + 26 + 4];
Stream_Read(stream, header, sizeof(header));
ReturnCode Fcm_Load(struct Stream* stream) {
UInt8 header[(3 * 2) + (3 * 4) + (2 * 1) + (2 * 4) + 16 + 26 + 4];
Stream_Read(stream, header, 4 + 1);
if (Stream_GetU32_LE(&header[0]) != FCM_IDENTIFIER) return FCM_ERR_IDENTIFIER;
if (header[4] != FCM_REVISION) return FCM_ERR_REVISION;
Stream_Read(stream, header, sizeof(header));
World_Width = Stream_GetU16_LE(&header[0]);
World_Height = Stream_GetU16_LE(&header[2]);
World_Length = Stream_GetU16_LE(&header[4]);
@ -172,6 +184,7 @@ void Fcm_Load(struct Stream* stream) {
Fcm_ReadString(&compStream); /* Value */
}
Map_ReadBlocks(&compStream);
return 0;
}
@ -551,10 +564,9 @@ static bool Cw_Callback(struct NbtTag* tag) {
0 1 2 3 4 */
}
void Cw_Load(struct Stream* stream) {
struct GZipHeader gzHeader;
GZipHeader_Init(&gzHeader);
while (!gzHeader.Done) { GZipHeader_Read(stream, &gzHeader); }
ReturnCode Cw_Load(struct Stream* stream) {
ReturnCode result = Map_SkipGZipHeader(stream);
if (result) return result;
struct Stream compStream;
struct InflateState state;
@ -569,6 +581,7 @@ void Cw_Load(struct Stream* stream) {
Vector3* spawn = &LocalPlayer_Instance.Spawn;
Vector3I P; Vector3I_Floor(&P, spawn);
if (!World_IsValidPos_3I(P)) { spawn->X /= 32.0f; spawn->Y /= 32.0f; spawn->Z /= 32.0f; }
return 0;
}
@ -706,10 +719,9 @@ static Int32 Dat_I32(struct JFieldDesc* field) {
return field->Value_I32;
}
void Dat_Load(struct Stream* stream) {
struct GZipHeader gzHeader;
GZipHeader_Init(&gzHeader);
while (!gzHeader.Done) { GZipHeader_Read(stream, &gzHeader); }
ReturnCode Dat_Load(struct Stream* stream) {
ReturnCode result = Map_SkipGZipHeader(stream);
if (result) return result;
struct Stream compStream;
struct InflateState state;
@ -757,6 +769,7 @@ void Dat_Load(struct Stream* stream) {
spawn->Z = (Real32)Dat_I32(field);
}
}
return 0;
}

View file

@ -6,12 +6,12 @@
*/
/* Imports a world from a LVL map file (MCLawl server map) */
void Lvl_Load(struct Stream* stream);
ReturnCode Lvl_Load(struct Stream* stream);
/* Imports a world from a FCMv3 map file (fCraft server map)
Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov <me@matvei.org> | BSD-3 | See LICENSE.txt */
void Fcm_Load(struct Stream* stream);
ReturnCode Fcm_Load(struct Stream* stream);
void Cw_Save(struct Stream* stream);
void Cw_Load(struct Stream* stream);
void Dat_Load(struct Stream* stream);
ReturnCode Cw_Load(struct Stream* stream);
ReturnCode Dat_Load(struct Stream* stream);
void Schematic_Save(struct Stream* stream);
#endif

View file

@ -132,7 +132,7 @@ void MapRenderer_RenderNormal(Real64 deltaTime) {
Gfx_SetTexturing(true);
Gfx_SetAlphaTest(true);
UInt32 batch;
Int32 batch;
Gfx_EnableMipmaps();
for (batch = 0; batch < MapRenderer_1DUsedCount; batch++) {
if (MapRenderer_NormalPartsCount[batch] <= 0) continue;
@ -222,7 +222,7 @@ void MapRenderer_RenderTranslucent(Real64 deltaTime) {
Gfx_SetAlphaBlending(false);
Gfx_SetColourWriteMask(false, false, false, false);
UInt32 batch;
Int32 batch;
for (batch = 0; batch < MapRenderer_1DUsedCount; batch++) {
if (MapRenderer_TranslucentPartsCount[batch] <= 0) continue;
if (MapRenderer_HasTranslucentParts[batch] || MapRenderer_CheckingTranslucentParts[batch]) {

View file

@ -1549,15 +1549,17 @@ void LoadLevelScreen_LoadMap(STRING_PURE String* path) {
{
String cw = String_FromConst(".cw"); String lvl = String_FromConst(".lvl");
String fcm = String_FromConst(".fcm"); String dat = String_FromConst(".dat");
if (String_CaselessEnds(path, &dat)) {
Dat_Load(&stream);
result = Dat_Load(&stream);
} else if (String_CaselessEnds(path, &fcm)) {
Fcm_Load(&stream);
result = Fcm_Load(&stream);
} else if (String_CaselessEnds(path, &cw)) {
Cw_Load(&stream);
result = Cw_Load(&stream);
} else if (String_CaselessEnds(path, &lvl)) {
Lvl_Load(&stream);
result = Lvl_Load(&stream);
}
ErrorHandler_CheckOrFail(result, "Loading map - reading data");
}
result = stream.Close(&stream);
ErrorHandler_CheckOrFail(result, "Loading map - close file");

View file

@ -27,7 +27,7 @@ void Options_Free(void) {
}
bool Options_HasChanged(STRING_PURE String* key) {
UInt32 i;
Int32 i;
for (i = 0; i < Options_Changed.Count; i++) {
String curKey = StringsBuffer_UNSAFE_Get(&Options_Changed, i);
if (String_CaselessEquals(&curKey, key)) return true;
@ -36,7 +36,7 @@ bool Options_HasChanged(STRING_PURE String* key) {
}
static UInt32 Options_Find(STRING_PURE String* key) {
UInt32 i;
Int32 i;
for (i = 0; i < Options_Keys.Count; i++) {
String curKey = StringsBuffer_UNSAFE_Get(&Options_Keys, i);
if (String_CaselessEquals(&curKey, key)) return i;
@ -212,7 +212,7 @@ void Options_Save(void) {
UChar lineBuffer[String_BufferSize(1024)];
String line = String_InitAndClearArray(lineBuffer);
struct Stream stream; Stream_FromFile(&stream, file, &path);
UInt32 i;
Int32 i;
for (i = 0; i < Options_Keys.Count; i++) {
String key = StringsBuffer_UNSAFE_Get(&Options_Keys, i);

View file

@ -22,6 +22,7 @@
#include "ErrorHandler.h"
#include "TexturePack.h"
#include "Gui.h"
#include "Errors.h"
/*########################################################################################################################*
*-----------------------------------------------------Common handlers-----------------------------------------------------*
@ -424,7 +425,11 @@ static void Classic_LevelDataChunk(struct Stream* stream) {
Stream_Skip(stream, 1024);
UInt8 value = Stream_ReadU8(stream); /* progress in original classic, but we ignore it */
if (!gzHeader.Done) { GZipHeader_Read(&mapPartStream, &gzHeader); }
if (!gzHeader.Done) {
ReturnCode result = GZipHeader_Read(&mapPartStream, &gzHeader);
if (result && result != ERR_END_OF_STREAM) ErrorHandler_FailWithCode(result, "reading map data");
}
if (gzHeader.Done) {
if (mapSizeIndex < sizeof(UInt32)) {
UInt8* src = mapSize + mapSizeIndex;

View file

@ -181,61 +181,9 @@ int main(void) {
return 0;
}
/*
String text1 = String_FromConst("abcd");
String lines1[3] = { 0 };
WordWrap_Do(&text1, lines1, 3, 4);
String text2 = String_FromConst("abcde/fgh");
String lines2[3] = { 0 };
WordWrap_Do(&text2, lines2, 3, 4);
String text3 = String_FromConst("abc/defg");
String lines3[3] = { 0 };
WordWrap_Do(&text3, lines3, 3, 4);
String text4 = String_FromConst("ab/cdef");
String lines4[3] = { 0 };
WordWrap_Do(&text4, lines4, 3, 4);
String text5 = String_FromConst("abcd/efg");
String lines5[3] = { 0 };
WordWrap_Do(&text5, lines5, 3, 4);
String text6 = String_FromConst("abc/efg/hij/");
String lines6[3] = { 0 };
WordWrap_Do(&text6, lines6, 3, 4);
String text7 = String_FromConst("ab cde fgh");
String lines7[3] = { 0 };
WordWrap_Do(&text7, lines7, 3, 4);
String text8 = String_FromConst("ab//cd");
String lines8[3] = { 0 };
WordWrap_Do(&text8, lines8, 3, 4);
String text9 = String_FromConst("a///b");
String lines9[3] = { 0 };
WordWrap_Do(&text9, lines9, 3, 4);
String text10 = String_FromConst("/aaab");
String lines10[3] = { 0 };
WordWrap_Do(&text10, lines10, 3, 4);
*/
int main_test(int argc, char* argv[]) {
return 0;
/*
#include <Windows.h>
void* file;
String path = String_FromConstant("H:\\PortableApps\\GitPortable\\App\\Git\\ClassicalSharp\\output\\release\\texpacks\\skybox.png");
ReturnCode openCode = File_Open(&file, &path);
Stream fileStream;
Stream_FromFile(&fileStream, file, &path);
Bitmap bmp;
Bitmap_DecodePng(&bmp, &fileStream);*/
/*BITMAPFILEHEADER bmpfileheader = { 0 };
BITMAPV5HEADER bmpinfoheader = { 0 };
bmpfileheader.bfType = (Int16)(('B' << 0) | ('M' << 8));
@ -251,85 +199,5 @@ int main_test(int argc, char* argv[]) {
bmpinfoheader.bV5AlphaMask = 0xFF000000UL;
bmpinfoheader.bV5RedMask = 0x00FF0000UL;
bmpinfoheader.bV5GreenMask = 0x0000FF00UL;
bmpinfoheader.bV5BlueMask = 0x000000FFUL;
void* file2;
String path2 = String_FromConstant("H:\\PortableApps\\GitPortable\\App\\Git\\ClassicalSharp\\output\\release\\texpacks\\skybox8.bmp");
openCode = File_Create(&file2, &path2);
Stream fileStream2;
Stream_FromFile(&fileStream2, file2, &path2);
Stream_Write(&fileStream2, &bmpfileheader, sizeof(bmpfileheader));
Stream_Write(&fileStream2, &bmpinfoheader, sizeof(bmpinfoheader));
Stream_Write(&fileStream2, bmp.Scan0, Bitmap_DataSize(bmp.Width, bmp.Height));
fileStream2.Close(&fileStream2);*/
//return 0;
/*void* file;
String path = String_FromConstant("H:\\PortableApps\\GitPortable\\App\\Git\\ClassicalSharp\\output\\release\\texpacks\\default.zip");
ReturnCode openCode = File_Open(&file, &path);
Stream fileStream;
Stream_FromFile(&fileStream, file, &path);
ZipState state;
Zip_Init(&state, &fileStream);
Zip_Extract(&state);
return 0;*/
/*void* file;
String path = String_FromConst("H:\\PortableApps\\GitPortable\\App\\Git\\ClassicalSharp\\src\\x64\\Release\\canyon.lvl");
ReturnCode openCode = File_Open(&file, &path);
Stream fileStream;
Stream_FromFile(&fileStream, file, &path);
Lvl_Load(&fileStream);
return 0;*/
/*void* file;
String path = String_FromConstant("H:\\PortableApps\\GitPortable\\App\\Git\\\ClassicalSharp\\src\\Debug\\gunzip.c.gz");
ReturnCode openCode = File_Open(&file, &path);
Stream fileStream;
Stream_FromFile(&fileStream, file, &path);
GZipHeader gzip;
GZipHeader_Init(&gzip);
while (!gzip.Done) { GZipHeader_Read(&fileStream, &gzip); }
UInt32 pos = File_Position(file);
InflateState deflate;
Inflate_Init(&deflate, &fileStream);
UInt32 read;
fileStream.Read(&fileStream, deflate.Input, 8192, &read);
deflate.AvailIn = read;
UInt8 out[56000];
deflate.Output = out;
deflate.AvailOut = 56000;
//puff(out, &deflate.AvailOut, deflate.Input, &deflate.AvailIn);
Inflate_Process(&deflate);
String path2 = String_FromConstant("H:\\PortableApps\\GitPortable\\App\\Git\\ClassicalSharp\\src\\x64\\Debug\\ffff.c");
openCode = File_Create(&file, &path2);
Stream_FromFile(&fileStream, file, &path);
UInt32 written;
fileStream.Write(&fileStream, out, 56000 - deflate.AvailOut, &written);
fileStream.Close(&fileStream);
return;
String str = String_FromConstant("TEST");
Window_Create(320, 320, 640, 480, &str, NULL);
Window_SetVisible(true);
Gfx_Init();
UInt8 RGB = 0;
while (true) {
Gfx_ClearColour(PackedCol_Create3(RGB, RGB, RGB));
RGB++;
Window_ProcessEvents();
Thread_Sleep(100);
Gfx_BeginFrame();
Gfx_Clear();
Gfx_EndFrame();
}
Gfx_Free();
return 0;*/
bmpinfoheader.bV5BlueMask = 0x000000FFUL; */
}

View file

@ -448,7 +448,7 @@ static void MPConnection_Tick(struct ScheduledTask* task) {
}
/* Keep last few unprocessed bytes, don't care about rest since they'll be overwritten on socket read */
Int32 i;
UInt32 i;
for (i = 0; i < net_readStream.Meta.Mem.Left; i++) {
net_readBuffer[i] = net_readStream.Meta.Mem.Cur[i];
}

View file

@ -2,6 +2,7 @@
#include "Platform.h"
#include "Funcs.h"
#include "ErrorHandler.h"
#include "Errors.h"
/*########################################################################################################################*
*---------------------------------------------------------Stream----------------------------------------------------------*
@ -27,7 +28,7 @@ void Stream_Fail(struct Stream* stream, ReturnCode result, const UChar* operatio
void Stream_Read(struct Stream* stream, UInt8* buffer, UInt32 count) {
UInt32 read;
while (count > 0) {
while (count) {
Stream_SafeReadBlock(stream, buffer, count, read);
buffer += read;
count -= read;
@ -36,7 +37,7 @@ void Stream_Read(struct Stream* stream, UInt8* buffer, UInt32 count) {
void Stream_Write(struct Stream* stream, UInt8* buffer, UInt32 count) {
UInt32 write;
while (count > 0) {
while (count) {
Stream_SafeWriteBlock(stream, buffer, count, write);
buffer += write;
count -= write;
@ -45,10 +46,10 @@ void Stream_Write(struct Stream* stream, UInt8* buffer, UInt32 count) {
ReturnCode Stream_TryWrite(struct Stream* stream, UInt8* buffer, UInt32 count) {
UInt32 write;
while (count > 0) {
while (count) {
ReturnCode result = stream->Write(stream, buffer, count, &write);
if (result) return result;
if (!write) return 1;
if (!write) return ERR_END_OF_STREAM;
buffer += write;
count -= write;

View file

@ -14,6 +14,7 @@
#include "Deflate.h"
#include "Stream.h"
#include "Funcs.h"
#include "Errors.h"
/*########################################################################################################################*
*--------------------------------------------------------ZipEntry---------------------------------------------------------*

View file

@ -20,13 +20,6 @@ struct ZipState {
struct ZipEntry Entries[ZIP_MAX_ENTRIES];
};
enum ZIP_ERR {
ZIP_ERR_TOO_MANY_ENTRIES = 405001,
ZIP_ERR_SEEK_END_OF_CENTRAL_DIR, ZIP_ERR_NO_END_OF_CENTRAL_DIR,
ZIP_ERR_SEEK_CENTRAL_DIR, ZIP_ERR_INVALID_CENTRAL_DIR,
ZIP_ERR_SEEK_LOCAL_DIR, ZIP_ERR_INVALID_LOCAL_DIR,
};
void Zip_Init(struct ZipState* state, struct Stream* input);
ReturnCode Zip_Extract(struct ZipState* state);

View file

@ -5,6 +5,7 @@
#include "Block.h"
#include "ExtMath.h"
#include "Funcs.h"
#include "Errors.h"
/*########################################################################################################################*
*-------------------------------------------------------Ogg stream--------------------------------------------------------*
@ -1222,6 +1223,7 @@ ReturnCode Vorbis_DecodeFrame(struct VorbisState* ctx) {
/* discard remaining bits at end of packet */
Vorbis_AlignBits(ctx);
return 0;
}
Int32 Vorbis_OutputFrame(struct VorbisState* ctx, Int16* data) {

View file

@ -6,22 +6,9 @@
*/
struct IGameComponent;
struct Stream;
enum OGG_VER { OGG_ERR_INVALID_SIG = 2552401, OGG_ERR_VERSION };
#define OGG_BUFFER_SIZE (255 * 256)
void Ogg_MakeStream(struct Stream* stream, UInt8* buffer, struct Stream* source);
enum VORBIS_ERR {
VORBIS_ERR_HEADER = 5238001, VORBIS_ERR_WRONG_HEADER, VORBIS_ERR_FRAMING,
VORBIS_ERR_VERSION, VORBIS_ERR_BLOCKSIZE, VORBIS_ERR_CHANS,
VORBIS_ERR_TIME_TYPE, VORBIS_ERR_FLOOR_TYPE, VORBIS_ERR_RESIDUE_TYPE,
VORBIS_ERR_MAPPING_TYPE, VORBIS_ERR_MODE_TYPE,
VORBIS_ERR_CODEBOOK_SYNC, VORBIS_ERR_CODEBOOK_ENTRY, VORBIS_ERR_CODEBOOK_LOOKUP,
VORBIS_ERR_MODE_WINDOW, VORBIS_ERR_MODE_TRANSFORM,
VORBIS_ERR_MAPPING_CHANS, VORBIS_ERR_MAPPING_RESERVED,
VORBIS_ERR_FRAME_TYPE,
};
#define VORBIS_MAX_CHANS 8
struct Codebook; struct Floor; struct Residue; struct Mapping; struct Mode;
struct VorbisState {