From 4a3144770216d170d9f862a8a363d22fb40a0335 Mon Sep 17 00:00:00 2001 From: sirlemonhead Date: Tue, 24 Dec 2019 21:07:36 +0000 Subject: [PATCH] NBlood: Remove std::string from libsmackerdec to fix cutscene crashing with MinGW builds. # Conflicts: # source/libsmackerdec/include/FileStream.h # source/libsmackerdec/src/FileStream.cpp --- source/libsmackerdec/include/FileStream.h | 3 +-- source/libsmackerdec/include/LogError.h | 4 ++-- source/libsmackerdec/include/SmackerDecoder.h | 4 ++-- source/libsmackerdec/src/FileStream.cpp | 4 ++-- source/libsmackerdec/src/LogError.cpp | 2 ++ source/libsmackerdec/src/SmackerDecoder.cpp | 22 +++++++++---------- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/source/libsmackerdec/include/FileStream.h b/source/libsmackerdec/include/FileStream.h index 3f00eac1a..fb0d8c696 100644 --- a/source/libsmackerdec/include/FileStream.h +++ b/source/libsmackerdec/include/FileStream.h @@ -20,7 +20,6 @@ #ifndef _SmackerFileStream_h_ #define _SmackerFileStream_h_ -#include #include "compat.h" #include #include "files.h" @@ -31,7 +30,7 @@ class FileStream { public: - bool Open(const std::string &fileName); + bool Open(const char *fileName); bool Is_Open(); void Close(); diff --git a/source/libsmackerdec/include/LogError.h b/source/libsmackerdec/include/LogError.h index 95a572961..b5b8b5f36 100644 --- a/source/libsmackerdec/include/LogError.h +++ b/source/libsmackerdec/include/LogError.h @@ -20,11 +20,11 @@ #ifndef _SmackerLogError_h_ #define _SmackerLogError_h_ -#include +//#include namespace SmackerCommon { -void LogError(const std::string &error); +//void LogError(const std::string &error); } // close namespace SmackerCommon diff --git a/source/libsmackerdec/include/SmackerDecoder.h b/source/libsmackerdec/include/SmackerDecoder.h index feb719571..d962b6564 100644 --- a/source/libsmackerdec/include/SmackerDecoder.h +++ b/source/libsmackerdec/include/SmackerDecoder.h @@ -66,7 +66,7 @@ struct SmackerAudioInfo uint32_t idealBufferSize; }; -SmackerHandle Smacker_Open (const char* fileName); +SmackerHandle Smacker_Open (const char *fileName); void Smacker_Close (SmackerHandle &handle); uint32_t Smacker_GetNumAudioTracks (SmackerHandle &handle); SmackerAudioInfo Smacker_GetAudioTrackDetails (SmackerHandle &handle, uint32_t trackIndex); @@ -110,7 +110,7 @@ class SmackerDecoder SmackerDecoder(); ~SmackerDecoder(); - bool Open(const std::string &fileName); + bool Open(const char *fileName); void GetPalette(uint8_t *palette); void GetFrame(uint8_t *frame); diff --git a/source/libsmackerdec/src/FileStream.cpp b/source/libsmackerdec/src/FileStream.cpp index 5fd112fc1..f717acd4c 100644 --- a/source/libsmackerdec/src/FileStream.cpp +++ b/source/libsmackerdec/src/FileStream.cpp @@ -23,9 +23,9 @@ namespace SmackerCommon { -bool FileStream::Open(const std::string &fileName) +bool FileStream::Open(const char *fileName) { - file = fileSystem.OpenFileReader(fileName.c_str(), 0); + file = fileSystem.OpenFileReader(fileName, 0); if (!file.isOpen()) { // log error diff --git a/source/libsmackerdec/src/LogError.cpp b/source/libsmackerdec/src/LogError.cpp index 82a648a41..46a45bb0a 100644 --- a/source/libsmackerdec/src/LogError.cpp +++ b/source/libsmackerdec/src/LogError.cpp @@ -21,11 +21,13 @@ namespace SmackerCommon { +#if 0 static std::string LastError; void LogError(const std::string &error) { LastError = error; } +#endif } // close namespace SmackerCommon diff --git a/source/libsmackerdec/src/SmackerDecoder.cpp b/source/libsmackerdec/src/SmackerDecoder.cpp index e280bcde3..786b14148 100644 --- a/source/libsmackerdec/src/SmackerDecoder.cpp +++ b/source/libsmackerdec/src/SmackerDecoder.cpp @@ -47,8 +47,8 @@ #include "LogError.h" #include #include -#include #include "compat.h" +#include "baselayer.h" std::vector classInstances; @@ -295,13 +295,13 @@ int SmackerDecoder::GetCode(SmackerCommon::BitReader &bits, std::vector &re return v; } -bool SmackerDecoder::Open(const std::string &fileName) +bool SmackerDecoder::Open(const char *fileName) { // open the file (read only) file.Open(fileName); if (!file.Is_Open()) { - SmackerCommon::LogError("Can't open file " + fileName); + buildprintf("SmackerDecoder::Open() - Can't open file %s\n", fileName); return false; } @@ -310,7 +310,7 @@ bool SmackerDecoder::Open(const std::string &fileName) if (memcmp(signature, kSMK2iD, 4) != 0 && memcmp(signature, kSMK4iD, 4) != 0) { - SmackerCommon::LogError("Unknown Smacker signature"); + buildprintf("SmackerDecoder::Open() - Unknown Smacker signature\n"); return false; } @@ -358,7 +358,7 @@ bool SmackerDecoder::Open(const std::string &fileName) if (nFrames > 0xFFFFFF) { - SmackerCommon::LogError("Too many frames!"); + buildprintf("SmackerDecoder::Open() - Too many frames\n"); return false; } @@ -447,7 +447,7 @@ int SmackerDecoder::DecodeTree(SmackerCommon::BitReader &bits, HuffContext *hc, if (!bits.GetBit()) // Leaf { if (hc->current >= 256){ - SmackerCommon::LogError("Tree size exceeded!"); + buildprintf("SmackerDecoder::DecodeTree() - Tree size exceeded\n"); return -1; } if (length){ @@ -486,7 +486,7 @@ int SmackerDecoder::DecodeBigTree(SmackerCommon::BitReader &bits, HuffContext *h i2 = 0; if (hc->current >= hc->length){ - SmackerCommon::LogError("Tree size exceeded!"); + buildprintf("SmackerDecoder::DecodeBigTree() - Tree size exceeded"); return -1; } @@ -548,7 +548,7 @@ int SmackerDecoder::DecodeHeaderTree(SmackerCommon::BitReader &bits, std::vector if ((uint32_t)size >= UINT_MAX>>4) { - SmackerCommon::LogError("Size too large"); + buildprintf("SmackerDecoder::DecodeHeaderTree() - Size too large\n"); return -1; } @@ -971,7 +971,7 @@ int SmackerDecoder::DecodeAudio(uint32_t size, SmackerAudioTrack &track) int buf_size = track.bufferSize; if (buf_size <= 4) { - SmackerCommon::LogError("packet is too small"); + buildprintf("SmackerDecoder::DecodeAudio() - Packet is too small\n"); return -1; } @@ -988,7 +988,7 @@ int SmackerDecoder::DecodeAudio(uint32_t size, SmackerAudioTrack &track) sampleBits = bits.GetBit(); if (stereo ^ (track.nChannels != 1)) { - SmackerCommon::LogError("channels mismatch"); + buildprintf("SmackerDecoder::DecodeAudio() - Channels mismatch\n"); return -1; } @@ -1112,7 +1112,7 @@ float SmackerDecoder::GetFrameRate() void SmackerDecoder::GotoFrame(uint32_t frameNum) { if (frameNum >= nFrames) { - SmackerCommon::LogError("Invalid frame number for GotoFrame"); + buildprintf("SmackerDecoder::GotoFrame() - Invalid frame number\n"); return; }