From 097a507bd00bfcf1b2a2a5a69c525ffba56c8e60 Mon Sep 17 00:00:00 2001 From: Antidote Date: Sun, 28 Dec 2014 20:46:43 -0800 Subject: [PATCH] * Visual Studio fixes (requires VS2013 at the minimum) --- Athena.pro | 3 +- include/Athena/ALTTPQuest.hpp | 2 +- include/Athena/ALTTPStructs.hpp | 16 +++--- include/Athena/Exception.hpp | 11 +++- include/Athena/FileNotFoundException.hpp | 2 +- include/Athena/FileWriter.hpp | 6 +-- include/Athena/Global.hpp | 24 +++++---- include/Athena/IOException.hpp | 10 +++- include/Athena/InvalidDataException.hpp | 11 +++- include/Athena/InvalidOperationException.hpp | 10 +++- include/Athena/MCFile.hpp | 6 +-- include/Athena/NotImplementedException.hpp | 2 +- include/Athena/Utility.hpp | 1 + include/lzo.h | 2 +- include/win32_largefilewrapper.h | 7 ++- src/Athena/ALTTPFile.cpp | 2 +- src/Athena/ALTTPQuest.cpp | 8 +-- src/Athena/BinaryReader.cpp | 15 +++--- src/Athena/BinaryWriter.cpp | 6 +-- src/Athena/Compression.cpp | 2 +- src/Athena/FileReader.cpp | 2 +- src/Athena/FileWriter.cpp | 5 ++ src/Athena/MCFile.cpp | 4 +- src/Athena/MCFileReader.cpp | 2 + src/Athena/Sprite.cpp | 6 +-- src/Athena/SpriteFile.cpp | 4 +- src/Athena/SpriteFrame.cpp | 2 +- src/Athena/Utility.cpp | 56 ++++++++++++-------- src/Athena/WiiFile.cpp | 6 +-- src/Athena/WiiSaveWriter.cpp | 4 +- src/LZ77/LZBase.cpp | 4 +- src/LZ77/LZLookupTable.cpp | 2 +- src/LZ77/LZType10.cpp | 2 +- src/LZ77/LZType11.cpp | 2 +- src/lzo.c | 12 ++--- src/md5.cpp | 6 ++- src/win32_largefilewrapper.c | 2 +- 37 files changed, 168 insertions(+), 99 deletions(-) diff --git a/Athena.pro b/Athena.pro index 6726e11..bad9de9 100644 --- a/Athena.pro +++ b/Athena.pro @@ -1,4 +1,4 @@ -CONFIG += staticlib +CONFIG += staticlib c++11 c11 TEMPLATE= lib DESTDIR = ./lib @@ -29,7 +29,6 @@ CONFIG(release, release|debug){ OBJECTS_DIR = obj/release } -QMAKE_CXXFLAGS += -std=c++11 INCLUDEPATH += include SOURCES += \ diff --git a/include/Athena/ALTTPQuest.hpp b/include/Athena/ALTTPQuest.hpp index e5eaf5e..dc84d7f 100644 --- a/include/Athena/ALTTPQuest.hpp +++ b/include/Athena/ALTTPQuest.hpp @@ -674,7 +674,7 @@ private: atUint8 m_bombFlag; std::vector m_unknown1; std::vector m_playerName; - atUint16 m_valid; + bool m_valid; std::vector m_dungeonDeathTotals; atUint16 m_unknown2; atUint16 m_deathSaveCount; diff --git a/include/Athena/ALTTPStructs.hpp b/include/Athena/ALTTPStructs.hpp index 9c4f5b1..744cb53 100644 --- a/include/Athena/ALTTPStructs.hpp +++ b/include/Athena/ALTTPStructs.hpp @@ -153,14 +153,14 @@ struct ALTTPPendants struct ALTTPAbilities { - char Nothing:1; //? - char Swim:1; - char Dash:1; - char Pull:1; - char Unknown1:1; //--- - char Talk:1; - char Read:1; - char Unknown2:1; //--- + bool Nothing:1; //? + bool Swim:1; + bool Dash:1; + bool Pull:1; + bool Unknown1:1; //--- + bool Talk:1; + bool Read:1; + bool Unknown2:1; //--- }; struct ALTTPCrystals diff --git a/include/Athena/Exception.hpp b/include/Athena/Exception.hpp index 954013b..d3fd4a7 100644 --- a/include/Athena/Exception.hpp +++ b/include/Athena/Exception.hpp @@ -19,6 +19,7 @@ #include #include #include "Athena/Utility.hpp" +#include "Athena/Global.hpp" #define __STRX(x) #x #define __STR(x) __STRX(x) @@ -78,10 +79,18 @@ protected: }; } // error } // Athena +#ifdef _MSC_VER +#define THROW_EXCEPTION(args,...) \ + do { \ + std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \ + throw Athena::error::Exception(std::string("Exception: ")+msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ + } while(0) +#elif defined(__GNUC__) #define THROW_EXCEPTION(args...) \ do { \ std::string msg = Athena::utility::sprintf(args); \ - throw Athena::error::Exception(std::string("Exception: ")+msg, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ + throw Athena::error::Exception(std::string("Exception: ")+msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ } while(0) +#endif #endif diff --git a/include/Athena/FileNotFoundException.hpp b/include/Athena/FileNotFoundException.hpp index 6eafa9f..1d600a6 100644 --- a/include/Athena/FileNotFoundException.hpp +++ b/include/Athena/FileNotFoundException.hpp @@ -52,6 +52,6 @@ private: } // Athena #define THROW_FILE_NOT_FOUND_EXCEPTION(msg) \ - do { throw Athena::error::FileNotFoundException(msg, __FILE__, __PRETTY_FUNCTION__, __LINE__); } while(0) + do { throw Athena::error::FileNotFoundException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); } while(0) #endif diff --git a/include/Athena/FileWriter.hpp b/include/Athena/FileWriter.hpp index 4554243..07902ba 100644 --- a/include/Athena/FileWriter.hpp +++ b/include/Athena/FileWriter.hpp @@ -62,9 +62,9 @@ private: std::string m_filename; FILE* m_fileHandle; Endian m_endian; - atUint8 m_currentByte; - atUint8 m_bytePosition; - atUint8 m_bitShift; + atUint8 m_currentByte; + atUint64 m_bytePosition; + atUint8 m_bitShift; bool m_bitValid; }; } diff --git a/include/Athena/Global.hpp b/include/Athena/Global.hpp index d6d59a3..58d1a53 100644 --- a/include/Athena/Global.hpp +++ b/include/Athena/Global.hpp @@ -20,27 +20,33 @@ #include "Athena/Utility.hpp" #include -#ifndef __PRETTY_FUNCTION__ -# ifdef __FUNCSIG__ -# define __PRETTY_FUNCTION__ __FUNCSIG__ +#ifdef _MSC_VER +#pragma warning(disable : 4996) +#endif + +#ifndef AT_PRETTY_FUNCTION +# ifdef __PRETTY_FUNCTION__ +# define AT_PRETTY_FUNCTION __PRETTY_FUNCTION__ +# elif defined(__FUNCSIG__) +# define AT_PRETTY_FUNCTION __FUNCSIG__ # elif defined(__FUNCTION__) -# define __PRETTY_FUNCTION__ __FUNCTION__ +# define AT_PRETTY_FUNCTION __FUNCTION__ # elif defined(__FUNC__) -# define __PRETTY_FUNCTION__ __FUNC__ +# define AT_PRETTY_FUNCTION __FUNC__ # elif defined(__func__) -# define __PRETTY_FUNCTION__ __func__ +# define AT_PRETTY_FUNCTION __func__ # else -# define __PRETTY_FUNCTION__ "" +# define AT_PRETTY_FUNCTION "" # endif #endif #ifndef aDebug #define aDebug() \ - std::cout << __FILE__ << "(" << __LINE__ << ") " << __PRETTY_FUNCTION__ << ": " + std::cout << __FILE__ << "(" << __LINE__ << ") " << AT_PRETTY_FUNCTION << ": " #endif #ifndef aError #define aError() \ - std::cerr << __FILE__ << "(" << __LINE__ << ") " << __PRETTY_FUNCTION__ << ": " + std::cerr << __FILE__ << "(" << __LINE__ << ") " << AT_PRETTY_FUNCTION << ": " #endif #ifndef aPrint diff --git a/include/Athena/IOException.hpp b/include/Athena/IOException.hpp index d25b9fb..6ff5d32 100644 --- a/include/Athena/IOException.hpp +++ b/include/Athena/IOException.hpp @@ -47,9 +47,17 @@ public: } // error } // Athena +#ifdef _MSC_VER +#define THROW_IO_EXCEPTION(args, ...) \ + do { \ + std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \ + throw Athena::error::IOException(std::string("IOException: ")+msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ + } while(0) +#elif defined(__GNUC__) #define THROW_IO_EXCEPTION(args...) \ do { \ std::string msg = Athena::utility::sprintf(args); \ - throw Athena::error::IOException(std::string("IOException: ")+msg, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ + throw Athena::error::IOException(std::string("IOException: ")+msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ } while(0) #endif +#endif diff --git a/include/Athena/InvalidDataException.hpp b/include/Athena/InvalidDataException.hpp index e9c0378..73d3cd2 100644 --- a/include/Athena/InvalidDataException.hpp +++ b/include/Athena/InvalidDataException.hpp @@ -43,10 +43,17 @@ public: } // error } // Athena +#ifdef _MSC_VER +#define THROW_INVALID_DATA_EXCEPTION(args, ...) \ + do { \ + std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \ + throw Athena::error::InvalidDataException(std::string("InvalidDataException: ")+msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ + } while(0) +#elif defined(__GNUC__) #define THROW_INVALID_DATA_EXCEPTION(args...) \ do { \ std::string msg = Athena::utility::sprintf(args); \ - throw Athena::error::InvalidDataException(std::string("InvalidDataException: ")+msg, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ + throw Athena::error::InvalidDataException(std::string("InvalidDataException: ")+msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ } while(0) - +#endif #endif // INVALIDDATAEXCEPTION_HPP diff --git a/include/Athena/InvalidOperationException.hpp b/include/Athena/InvalidOperationException.hpp index f703720..be05936 100644 --- a/include/Athena/InvalidOperationException.hpp +++ b/include/Athena/InvalidOperationException.hpp @@ -47,9 +47,17 @@ public: } // error } // Athena +#ifdef _MSC_VER +#define THROW_INVALID_OPERATION_EXCEPTION(args, ...) \ + do { \ + std::string msg = Athena::utility::sprintf(args, __VA_ARGS__); \ + throw Athena::error::InvalidOperationException(std::string("InvalidOperationException: ")+msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ + } while(0) +#elif defined (__GNUC__) #define THROW_INVALID_OPERATION_EXCEPTION(args...) \ do { \ std::string msg = Athena::utility::sprintf(args); \ - throw Athena::error::InvalidOperationException(std::string("InvalidOperationException: ")+msg, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ + throw Athena::error::InvalidOperationException(std::string("InvalidOperationException: ")+msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \ } while(0) +#endif #endif // __INVALID_OPERATION_EXCEPTION_HPP__ diff --git a/include/Athena/MCFile.hpp b/include/Athena/MCFile.hpp index 88ce159..80c0db2 100644 --- a/include/Athena/MCFile.hpp +++ b/include/Athena/MCFile.hpp @@ -31,8 +31,8 @@ class MCSlot; class MCFile { public: - static constexpr char* VERSION_EU_JP = (char*)"AGBZELDA:THE MINISH CAP:ZELDA 3\0"; - static constexpr char* VERSION_US = (char*)"AGBZELDA:THE MINISH CAP:ZELDA 5\0"; + static const char VERSION_EU_JP[33]; + static const char VERSION_US[33]; enum SlotType { New = 0x54494E49, @@ -42,7 +42,7 @@ public: MCFile(); - static atUint8* unscramble(atUint8* data, atUint32 length); + static atUint8* unscramble(atUint8* data, atUint64 length); private: MCSlot* m_slots[3]; }; diff --git a/include/Athena/NotImplementedException.hpp b/include/Athena/NotImplementedException.hpp index 371a48e..cb49c21 100644 --- a/include/Athena/NotImplementedException.hpp +++ b/include/Athena/NotImplementedException.hpp @@ -33,6 +33,6 @@ public: } // Athena #define THROW_NOT_IMPLEMENTED_EXCEPTION() \ - do { throw Athena::error::NotImplementedException("NotImplementedException", __FILE__, __PRETTY_FUNCTION__, __LINE__); } while(0) + do { throw Athena::error::NotImplementedException("NotImplementedException", __FILE__, AT_PRETTY_FUNCTION, __LINE__); } while(0) #endif // NOTIMPLEMENTEDEXCEPTION_HPP diff --git a/include/Athena/Utility.hpp b/include/Athena/Utility.hpp index bbe34c0..74c9edf 100644 --- a/include/Athena/Utility.hpp +++ b/include/Athena/Utility.hpp @@ -20,6 +20,7 @@ #include #include #include +#include "Athena/Global.hpp" #include "Athena/Types.hpp" namespace Athena diff --git a/include/lzo.h b/include/lzo.h index 8d917dd..d702f9a 100644 --- a/include/lzo.h +++ b/include/lzo.h @@ -36,7 +36,7 @@ typedef unsigned char uint8_t; extern "C" { #endif -int lzo1x_decode(atUint8 *out, atInt32 *outlen, const atUint8* in, atInt32 *inlen); +int lzo1x_decode(atUint8 *out, atInt32 *outlen, atUint8 *in, atInt32 *inlen); #ifdef __cplusplus } diff --git a/include/win32_largefilewrapper.h b/include/win32_largefilewrapper.h index 054c504..e9a6900 100644 --- a/include/win32_largefilewrapper.h +++ b/include/win32_largefilewrapper.h @@ -1,11 +1,16 @@ #ifndef WIN32_LARGEFILEWRAPPER_H #define WIN32_LARGEFILEWRAPPER_H -#if defined(_WIN32) && defined(_MSC_VER) +#if defined(_MSC_VER) #include +#include #ifdef __cplusplus extern "C" { #endif +#ifndef off64_t +typedef uint64_t off64_t; +#endif + int fseeko64(FILE* fp, off64_t offset, int whence); off64_t ftello64(FILE* fp); #ifdef __cplusplus diff --git a/src/Athena/ALTTPFile.cpp b/src/Athena/ALTTPFile.cpp index 5ba8956..ae2a2d6 100644 --- a/src/Athena/ALTTPFile.cpp +++ b/src/Athena/ALTTPFile.cpp @@ -52,7 +52,7 @@ ALTTPQuest* ALTTPFile::quest(atUint32 id) const atUint32 ALTTPFile::questCount() const { - return m_quests.size(); + return (atUint32)m_quests.size(); } } // zelda diff --git a/src/Athena/ALTTPQuest.cpp b/src/Athena/ALTTPQuest.cpp index 40c9eb9..1273abb 100644 --- a/src/Athena/ALTTPQuest.cpp +++ b/src/Athena/ALTTPQuest.cpp @@ -317,7 +317,7 @@ atUint8 ALTTPQuest::dungeonKeys(atUint32 id) const atUint32 ALTTPQuest::dungeonCount() const { - return m_dungeonKeys.size(); + return (atUint32)m_dungeonKeys.size(); } @@ -414,7 +414,7 @@ atUint8 ALTTPQuest::oldManFlag(atUint32 id) atUint32 ALTTPQuest::oldManFlagCount() const { - return m_oldManFlags.size(); + return (atUint32)m_oldManFlags.size(); } void ALTTPQuest::setBombFlag(atUint8 flag) @@ -450,7 +450,7 @@ atUint8 ALTTPQuest::unknown1(atUint32 id) atUint32 ALTTPQuest::unknown1Count() const { - return m_unknown1.size(); + return (atUint32)m_unknown1.size(); } void ALTTPQuest::setPlayerName(std::vector playerName) @@ -636,7 +636,7 @@ atUint16 ALTTPQuest::dungeonDeathTotal(atUint32 id) const atUint16 ALTTPQuest::dungeonDeathTotalCount() const { - return m_dungeonDeathTotals.size(); + return (atUint16)m_dungeonDeathTotals.size(); } void ALTTPQuest::setUnknown2(atUint16 val) diff --git a/src/Athena/BinaryReader.cpp b/src/Athena/BinaryReader.cpp index 7c0f04e..2008c79 100644 --- a/src/Athena/BinaryReader.cpp +++ b/src/Athena/BinaryReader.cpp @@ -177,7 +177,7 @@ bool BinaryReader::readBit() if (m_position > m_length) THROW_IO_EXCEPTION("Position %0.16X outside stream bounds ", m_position); - bool ret = (*(atUint8*)(m_data + m_position) & (1 << m_bitPosition)); + bool ret = (*(atUint8*)(m_data + m_position) & (1 << m_bitPosition)) != 0; m_bitPosition++; if (m_bitPosition > 7) @@ -444,29 +444,28 @@ void BinaryReader::setProgressCallback(std::function cb) void BinaryReader::loadData() { FILE* in; - atUint32 length; + atUint64 length; in = fopen(m_filepath.c_str(), "rb"); if (!in) THROW_FILE_NOT_FOUND_EXCEPTION(m_filepath); + rewind(in); - fseek(in, 0, SEEK_END); - length = ftell(in); - fseek(in, 0, SEEK_SET); + length = utility::fileSize(m_filepath); #ifdef HW_RVL m_data = (Uint8*)memalign(32, length); #else m_data = new atUint8[length]; #endif - atUint32 done = 0; - atUint32 blocksize = BLOCKSZ; + atUint64 done = 0; + atUint64 blocksize = BLOCKSZ; do { if (blocksize > length - done) blocksize = length - done; - atInt32 ret = fread(m_data + done, 1, blocksize, in); + atInt64 ret = fread(m_data + done, 1, blocksize, in); if (ret < 0) THROW_IO_EXCEPTION("Error reading data from disk"); diff --git a/src/Athena/BinaryWriter.cpp b/src/Athena/BinaryWriter.cpp index 39a5dc3..9fed6e5 100644 --- a/src/Athena/BinaryWriter.cpp +++ b/src/Athena/BinaryWriter.cpp @@ -185,14 +185,14 @@ void BinaryWriter::save(const std::string& filename) if (!out) THROW_FILE_NOT_FOUND_EXCEPTION(m_filepath); - atUint32 done = 0; - atUint32 blocksize = BLOCKSZ; + atUint64 done = 0; + atUint64 blocksize = BLOCKSZ; do { if (blocksize > m_length - done) blocksize = m_length - done; - atInt32 ret = fwrite(m_data + done, 1, blocksize, out); + atInt64 ret = fwrite(m_data + done, 1, blocksize, out); if (ret < 0) THROW_IO_EXCEPTION("Error writing data to disk"); diff --git a/src/Athena/Compression.cpp b/src/Athena/Compression.cpp index 3d9e92c..dac0f47 100644 --- a/src/Athena/Compression.cpp +++ b/src/Athena/Compression.cpp @@ -108,7 +108,7 @@ atInt32 compressZlib(const atUint8 *src, atUint32 srcLen, atUint8* dst, atUint32 atInt32 decompressLZO(const atUint8* source, atInt32 sourceSize, atUint8* dst, atInt32& dstSize) { int size = dstSize; - int result = lzo1x_decode(dst, &size, source, &sourceSize); + int result = lzo1x_decode(dst, &size, (atUint8*)source, &sourceSize); dstSize = size; return result; } diff --git a/src/Athena/FileReader.cpp b/src/Athena/FileReader.cpp index c5c6437..5b7fd09 100644 --- a/src/Athena/FileReader.cpp +++ b/src/Athena/FileReader.cpp @@ -140,7 +140,7 @@ bool FileReader::readBit() if (!m_bitValid) { - int size = fread(&m_currentByte, 1, 1, m_fileHandle); + size_t size = fread(&m_currentByte, 1, 1, m_fileHandle); if (size != sizeof(atUint8)) THROW_IO_EXCEPTION("Error reading from file."); diff --git a/src/Athena/FileWriter.cpp b/src/Athena/FileWriter.cpp index d848a36..aa10dce 100644 --- a/src/Athena/FileWriter.cpp +++ b/src/Athena/FileWriter.cpp @@ -18,6 +18,11 @@ #include "Athena/InvalidDataException.hpp" #include "Athena/InvalidOperationException.hpp" #include "Athena/IOException.hpp" + +#ifdef _MSC_VER +#include "win32_largefilewrapper.h" +#endif + #include "utf8.h" namespace Athena diff --git a/src/Athena/MCFile.cpp b/src/Athena/MCFile.cpp index 88ecf77..5363a08 100644 --- a/src/Athena/MCFile.cpp +++ b/src/Athena/MCFile.cpp @@ -18,6 +18,8 @@ namespace Athena { +const char MCFile::VERSION_EU_JP[33] = "AGBZELDA:THE MINISH CAP:ZELDA 3\0"; +const char MCFile::VERSION_US[33] = "AGBZELDA:THE MINISH CAP:ZELDA 5\0"; MCFile::MCFile() { } @@ -38,7 +40,7 @@ atUint8* reverse(atUint8* data, atUint32 length) return data; } -atUint8* MCFile::unscramble(atUint8* data, atUint32 length) +atUint8* MCFile::unscramble(atUint8* data, atUint64 length) { if (!data) return nullptr; diff --git a/src/Athena/MCFileReader.cpp b/src/Athena/MCFileReader.cpp index a592df0..0e3ef00 100644 --- a/src/Athena/MCFileReader.cpp +++ b/src/Athena/MCFileReader.cpp @@ -40,6 +40,8 @@ MCFile* MCFileReader::readFile() if (isScrambled) MCFile::unscramble(base::m_data, base::m_length); + + return nullptr; } diff --git a/src/Athena/Sprite.cpp b/src/Athena/Sprite.cpp index b96c9be..ddd380d 100644 --- a/src/Athena/Sprite.cpp +++ b/src/Athena/Sprite.cpp @@ -149,7 +149,7 @@ QList Sprite::stateIds() const atUint32 Sprite::stateCount() const { - return m_stateIds.size(); + return (atUint32)m_stateIds.size(); } void Sprite::setCurrentState(const atUint32 id) @@ -231,7 +231,7 @@ void Sprite::setFrames(QList frames) atUint32 Sprite::frameCount() const { - return m_frames.size(); + return (atUint32)m_frames.size(); } #ifndef ATHENA_USE_QT @@ -282,7 +282,7 @@ void Sprite::advanceFrame() { m_currentFrame++; if (m_currentFrame >= m_frames.size()) - m_currentFrame = m_frames.size() - 1; + m_currentFrame = (atUint32)m_frames.size() - 1; } void Sprite::retreatFrame() diff --git a/src/Athena/SpriteFile.cpp b/src/Athena/SpriteFile.cpp index 74fcd81..d9ecc0e 100644 --- a/src/Athena/SpriteFile.cpp +++ b/src/Athena/SpriteFile.cpp @@ -199,7 +199,7 @@ QList SpriteFile::textures() const atUint32 SpriteFile::textureCount() const { - return m_textures.size(); + return (atUint32)m_textures.size(); } void SpriteFile::addSprite(Sprite* sprite) @@ -297,7 +297,7 @@ QMap SpriteFile::sprites() const atUint32 SpriteFile::spriteCount() const { - return m_sprites.size(); + return (atUint32)m_sprites.size(); } #ifndef ATHENA_USE_QT diff --git a/src/Athena/SpriteFrame.cpp b/src/Athena/SpriteFrame.cpp index 4074c16..7d07dd6 100644 --- a/src/Athena/SpriteFrame.cpp +++ b/src/Athena/SpriteFrame.cpp @@ -60,7 +60,7 @@ QList SpriteFrame::parts() const atUint32 SpriteFrame::partCount() const { - return m_parts.size(); + return (atUint32)m_parts.size(); } float SpriteFrame::frameTime() const diff --git a/src/Athena/Utility.cpp b/src/Athena/Utility.cpp index a040121..eca57f5 100644 --- a/src/Athena/Utility.cpp +++ b/src/Athena/Utility.cpp @@ -24,6 +24,12 @@ #include #include +#ifdef _MSC_VER +#include +#include +#define stat64 __stat64 +#endif + namespace Athena { namespace utility @@ -63,13 +69,13 @@ atUint64 swapU64(atUint64 val) atInt64 swap64(atInt64 val) { return (val = ((atInt64)((((atInt64)(val) & 0xFF00000000000000ULL) >> 56) | - (((atInt64)(val) & 0x00FF000000000000ULL) >> 40) | - (((atInt64)(val) & 0x0000FF0000000000ULL) >> 24) | - (((atInt64)(val) & 0x000000FF00000000ULL) >> 8) | - (((atInt64)(val) & 0x00000000FF000000ULL) << 8) | - (((atInt64)(val) & 0x0000000000FF0000ULL) << 24) | - (((atInt64)(val) & 0x000000000000FF00ULL) << 40) | - (((atInt64)(val) & 0x00000000000000FFULL) << 56)))); + (((atInt64)(val) & 0x00FF000000000000ULL) >> 40) | + (((atInt64)(val) & 0x0000FF0000000000ULL) >> 24) | + (((atInt64)(val) & 0x000000FF00000000ULL) >> 8) | + (((atInt64)(val) & 0x00000000FF000000ULL) << 8) | + (((atInt64)(val) & 0x0000000000FF0000ULL) << 24) | + (((atInt64)(val) & 0x000000000000FF00ULL) << 40) | + (((atInt64)(val) & 0x00000000000000FFULL) << 56)))); } bool isSystemBigEndian() @@ -294,13 +300,13 @@ std::string vsprintf(const char* fmt, va_list list) int size = 512; char* buffer = 0; buffer = new char[size]; - int nsize = vsnprintf(buffer, size, fmt, list); + int nsize = ::vsnprintf(buffer, size, fmt, list); while(size<=nsize) { //fail delete buffer and try again delete[] buffer; buffer = 0; buffer = new char[nsize+1]; //+1 for /0 - nsize = vsnprintf(buffer, size, fmt, list); + nsize = ::vsnprintf(buffer, size, fmt, list); } std::string ret(buffer); delete[] buffer; @@ -373,21 +379,29 @@ atUint64 fileSize(const std::string& filename) return st.st_size; } -std::string& ltrim(std::string& s) +// trim from both ends +std::string &trim(std::string &s) { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); - return s; -} + // Find first non whitespace char in StrToTrim + std::string::size_type first = s.find_first_not_of( ' ' ); + // Check whether something went wrong? + if( first == std::string::npos ) + { + first = 0; + } -std::string& rtrim(std::string& s) -{ - s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); - return s; -} + // Find last non whitespace char from StrToTrim + std::string::size_type last = s.find_last_not_of( ' ' ); + // If something didn't go wrong, Last will be recomputed to get real length of substring + if( last != std::string::npos ) + { + last = ( last + 1 ) - first; + } -std::string& trim(std::string& s) -{ - return ltrim(rtrim(s)); + // Copy such a string to TrimmedString + s = s.substr( first, last ); + + return s; } } // utility diff --git a/src/Athena/WiiFile.cpp b/src/Athena/WiiFile.cpp index 39b0791..4e74261 100644 --- a/src/Athena/WiiFile.cpp +++ b/src/Athena/WiiFile.cpp @@ -157,7 +157,7 @@ void WiiFile::addChild(WiiFile *file) { // add them from the beginning of the path up tmpName = tmpName.substr(0, tmpName.find('/')); - for (int i = 0; i < m_children.size(); i++) + for (atUint32 i = 0; i < m_children.size(); i++) { if (!m_children[i]->filename().compare(tmpName)) { @@ -226,7 +226,7 @@ void WiiFile::setParent(WiiFile* parent) atUint32 WiiFile::fileCount() { - int ret = m_children.size(); + size_t ret = m_children.size(); for (WiiFile* f : m_children) { @@ -236,7 +236,7 @@ atUint32 WiiFile::fileCount() ret += f->fileCount(); } - return ret; + return (atUint32)ret; } std::vector WiiFile::allChildren() diff --git a/src/Athena/WiiSaveWriter.cpp b/src/Athena/WiiSaveWriter.cpp index b1935c0..03dd969 100644 --- a/src/Athena/WiiSaveWriter.cpp +++ b/src/Athena/WiiSaveWriter.cpp @@ -78,7 +78,7 @@ bool WiiSaveWriter::writeSave(WiiSave *save, atUint8 *macAddress, atUint32 ngId, { totalSize += writeFile(file); } - int pos = base::position(); + atUint64 pos = base::position(); // Write size data base::seek(0xF0C0 + 0x10, SeekOrigin::Begin); base::writeUint32(totalSize); @@ -97,7 +97,7 @@ void WiiSaveWriter::writeBanner(WiiBanner *banner) { base::setEndian(Endian::BigEndian); base::writeInt64(banner->gameID()); - base::writeInt32((0x60a0+0x1200)*banner->icons().size()); + base::writeInt32((0x60a0+0x1200)*(atUint32)banner->icons().size()); base::writeByte((atInt8)banner->permissions()); base::seek(1); base::writeBytes((atInt8*)MD5_BLANKER, 16); diff --git a/src/LZ77/LZBase.cpp b/src/LZ77/LZBase.cpp index b3d96b8..adcf48f 100644 --- a/src/LZ77/LZBase.cpp +++ b/src/LZ77/LZBase.cpp @@ -112,8 +112,8 @@ Normally a search for one byte is matched, then two, then three, all the way up */ LZLengthOffset LZBase::windowSearch(atUint8* beginSearchPtr, atUint8* searchPosPtr, atUint8* endLABufferPtr, atUint8* startLBPtr) { - atInt32 size=endLABufferPtr-beginSearchPtr;//Size of the entire sliding window - atInt32 n=endLABufferPtr-searchPosPtr; + atInt32 size=(atUint32)(endLABufferPtr-beginSearchPtr);//Size of the entire sliding window + atInt32 n=(atUint32)(endLABufferPtr-searchPosPtr); LZLengthOffset result={0,0}; atInt32 temp=0; if(n > size)//If the string that is being looked for is bigger than the string that is being searched diff --git a/src/LZ77/LZLookupTable.cpp b/src/LZ77/LZLookupTable.cpp index 286adc9..076033d 100644 --- a/src/LZ77/LZLookupTable.cpp +++ b/src/LZ77/LZLookupTable.cpp @@ -1,5 +1,5 @@ #include "LZ77/LZLookupTable.hpp" - +#include LZLookupTable::LZLookupTable() { diff --git a/src/LZ77/LZType10.cpp b/src/LZ77/LZType10.cpp index 5845f49..c42493b 100644 --- a/src/LZ77/LZType10.cpp +++ b/src/LZ77/LZType10.cpp @@ -67,7 +67,7 @@ atUint32 LZType10::compress(const atUint8* src, atUint8** dstBuf, atUint32 srcLe *dstBuf = outbuf.data(); outbuf.save(); - return outbuf.length(); + return (atUint32)outbuf.length(); } atUint32 LZType10::decompress(const atUint8* src, atUint8** dst, atUint32 srcLength) diff --git a/src/LZ77/LZType11.cpp b/src/LZ77/LZType11.cpp index bba5106..2e0a214 100644 --- a/src/LZ77/LZType11.cpp +++ b/src/LZ77/LZType11.cpp @@ -114,7 +114,7 @@ atUint32 LZType11::compress(const atUint8* src, atUint8** dst, atUint32 srcLengt outbuff.writeByte(0); *dst = outbuff.data(); - return outbuff.length(); + return (atUint32)outbuff.length(); } atUint32 LZType11::decompress(const atUint8* src, atUint8** dst, atUint32 srcLength) diff --git a/src/lzo.c b/src/lzo.c index 0a90196..b4f6d37 100644 --- a/src/lzo.c +++ b/src/lzo.c @@ -67,11 +67,11 @@ static void copy(LZOContext *c, int cnt) { register uint8_t *src = c->in; register uint8_t *dst = c->out; if (src + cnt > c->in_end) { - cnt = c->in_end - src; + cnt = (int)(c->in_end - src); c->error |= LZO_INPUT_DEPLETED; } if (dst + cnt > c->out_end) { - cnt = c->out_end - dst; + cnt = (int)(c->out_end - dst); c->error |= LZO_OUTPUT_FULL; } @@ -111,7 +111,7 @@ static void copy_backptr(LZOContext *c, int back, int cnt) { return; } if (dst + cnt > c->out_end) { - cnt = c->out_end - dst; + cnt = (int)(c->out_end - dst); c->error |= LZO_OUTPUT_FULL; } if (back == 1) { @@ -166,7 +166,7 @@ static void copy_backptr(LZOContext *c, int back, int cnt) { * make sure all buffers are appropriately padded, in must provide * LZO_INPUT_PADDING, out must provide LZO_OUTPUT_PADDING additional bytes */ -int lzo1x_decode(atUint8 *out, atInt32 *outlen, const atUint8 *in, atInt32 *inlen) { +int lzo1x_decode(atUint8 *out, atInt32 *outlen, atUint8 *in, atInt32 *inlen) { enum {COPY, BACKPTR} state = COPY; atInt32 x; LZOContext c; @@ -225,7 +225,7 @@ int lzo1x_decode(atUint8 *out, atInt32 *outlen, const atUint8 *in, atInt32 *inle copy(&c, cnt); x = get_byte(&c); } - *inlen = c.in_end - c.in; - *outlen = c.out_end - c.out; + *inlen = (atInt32)(c.in_end - c.in); + *outlen = (atInt32)(c.out_end - c.out); return c.error; } diff --git a/src/md5.cpp b/src/md5.cpp index f4a3344..056e0e4 100644 --- a/src/md5.cpp +++ b/src/md5.cpp @@ -84,6 +84,10 @@ #include #include +#ifdef _MSC_VER +#pragma warning(disable : 4996) +#endif + #include "md5.h" namespace MD5Hash @@ -560,7 +564,7 @@ unsigned char * MD5fromFile(unsigned char *dst, const char *src) do { - read = fread(buffer, 1, blksize, file); + read = (int)fread(buffer, 1, blksize, file); (void) auth_md5SumCtx(ctx, buffer, read); /* Pass only one block. */ } while (read > 0); diff --git a/src/win32_largefilewrapper.c b/src/win32_largefilewrapper.c index 75da284..7acdec7 100644 --- a/src/win32_largefilewrapper.c +++ b/src/win32_largefilewrapper.c @@ -1,7 +1,7 @@ #include "win32_largefilewrapper.h" #include -#if defined(_WIN32) && defined(_MSC_VER) +#if defined(_MSC_VER) int fseeko64(FILE* fp, off64_t offset, int whence) { return _fseeki64(fp, offset, whence);