From d639369f0869eb534cb9d2536377afa766afeef9 Mon Sep 17 00:00:00 2001 From: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com> Date: Wed, 17 Feb 2021 15:04:20 +0100 Subject: [PATCH] wiiu: some fixes after merge --- src/audio/oal/stream.cpp | 39 ++++++++++++++++++++++++++------------- src/control/Script6.cpp | 4 ++-- src/control/Script7.cpp | 8 ++++---- src/core/FileLoader.cpp | 12 ++++++++++-- src/rw/TexRead.cpp | 2 +- src/text/Text.cpp | 6 ++++++ 6 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/audio/oal/stream.cpp b/src/audio/oal/stream.cpp index c07ae093..be0c7ccc 100644 --- a/src/audio/oal/stream.cpp +++ b/src/audio/oal/stream.cpp @@ -419,14 +419,12 @@ static sf_count_t sndfile_vio_read(void* ptr, sf_count_t count, void* user_data) return fread(ptr, 1, count, (FILE*)user_data); } -static sf_count_t -sndfile_vio_write(const void* ptr, sf_count_t count, void* user_data) +static sf_count_t sndfile_vio_write(const void* ptr, sf_count_t count, void* user_data) { return fwrite(ptr, 1, count, (FILE*)user_data); } -static sf_count_t -sndfile_vio_tell(void* user_data) +static sf_count_t sndfile_vio_tell(void* user_data) { return ftell((FILE*)user_data); } @@ -653,7 +651,8 @@ static ssize_t mpg123_read_replacement(void* handle, void* data, size_t size) static off_t mpg123_seek_replacement(void* handle, off_t offset, int whence) { - return fseek((FILE*)handle, offset, whence); + fseek((FILE*)handle, (uint32) offset, whence); + return ftell((FILE*)handle); } class CMP3File : public IDecoder @@ -670,7 +669,9 @@ protected: m_pMH(nil), m_bOpened(false), m_nRate(0), - m_nChannels(0) {} + m_nChannels(0), + m_fileHandle(NULL), + m_buffer(NULL) {} public: CMP3File(const char *path) : m_pMH(nil), @@ -726,6 +727,8 @@ public: } free(m_buffer); + m_fileHandle = nil; + m_buffer = nil; m_pMH = nil; } } @@ -799,10 +802,6 @@ class CADFFile : public CMP3File fseek((FILE*)fh, pos, seekType); return ftell((FILE*)fh); } - static void r_close(void* fh) - { - fclose((FILE*)fh); - } public: CADFFile(const char* path) { @@ -816,10 +815,18 @@ public: int channels = 0; int encoding = 0; - FILE* f = fopen(path, "rb"); + m_buffer = (char*) memalign(0x40, IO_BUFFER_SIZE); - m_bOpened = mpg123_replace_reader_handle(m_pMH, r_read, r_seek, r_close) == MPG123_OK - && mpg123_open_handle(m_pMH, f) == MPG123_OK && mpg123_getformat(m_pMH, &rate, &channels, &encoding) == MPG123_OK; + FILE* m_fileHandle = fopen(path, "rb"); + if (!m_fileHandle) { + m_bOpened = false; + return; + } + + setvbuf(m_fileHandle, m_buffer, _IOFBF, IO_BUFFER_SIZE); + + m_bOpened = mpg123_replace_reader_handle(m_pMH, r_read, r_seek, NULL) == MPG123_OK + && mpg123_open_handle(m_pMH, m_fileHandle) == MPG123_OK && mpg123_getformat(m_pMH, &rate, &channels, &encoding) == MPG123_OK; m_nRate = rate; m_nChannels = channels; @@ -905,6 +912,7 @@ public: class CVbFile : public IDecoder { FILE *m_pFile; + char *m_buffer; CVagDecoder *m_pVagDecoders; size_t m_FileSize; @@ -934,9 +942,13 @@ public: CVbFile(const char* path, uint32 nSampleRate = 32000, uint8 nChannels = 2) : m_nSampleRate(nSampleRate), m_nChannels(nChannels), m_pVagDecoders(nil), m_ppVagBuffers(nil), m_ppPcmBuffers(nil), m_FileSize(0), m_nNumberOfBlocks(0), m_bBlockRead(false), m_LineInBlock(0), m_CurrentBlock(0) { + m_buffer = (char*) memalign(0x40, IO_BUFFER_SIZE); + m_pFile = fopen(path, "rb"); if (!m_pFile) return; + setvbuf(m_pFile, m_buffer, _IOFBF, IO_BUFFER_SIZE); + fseek(m_pFile, 0, SEEK_END); m_FileSize = ftell(m_pFile); fseek(m_pFile, 0, SEEK_SET); @@ -954,6 +966,7 @@ public: if (m_pFile) { fclose(m_pFile); + free(m_buffer); delete[] m_pVagDecoders; for (int i = 0; i < m_nChannels; i++) diff --git a/src/control/Script6.cpp b/src/control/Script6.cpp index 4d7121f2..210bc540 100644 --- a/src/control/Script6.cpp +++ b/src/control/Script6.cpp @@ -1696,7 +1696,7 @@ int8 CRunningScript::ProcessCommands1100To1199(int32 command) { int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); CollectParameters(&m_nIp, 1); - UpdateCompareFlag(*ptr == ScriptParams[0]); + UpdateCompareFlag(BSWAP32(*ptr) == ScriptParams[0]); return 0; } case COMMAND_IS_INT_LVAR_EQUAL_TO_CONSTANT: @@ -1786,7 +1786,7 @@ int8 CRunningScript::ProcessCommands1100To1199(int32 command) { int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); CollectParameters(&m_nIp, 1); - *ptr = ScriptParams[0]; + *ptr = BSWAP32(ScriptParams[0]); return 0; } case COMMAND_SET_LVAR_INT_TO_CONSTANT: diff --git a/src/control/Script7.cpp b/src/control/Script7.cpp index 34a364a7..5f8cc01e 100644 --- a/src/control/Script7.cpp +++ b/src/control/Script7.cpp @@ -38,7 +38,7 @@ int8 CRunningScript::ProcessCommands1200To1299(int32 command) { int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); CollectParameters(&m_nIp, 1); - UpdateCompareFlag(*ptr > ScriptParams[0]); + UpdateCompareFlag(BSWAP32(*ptr) > ScriptParams[0]); return 0; } case COMMAND_IS_INT_LVAR_GREATER_THAN_CONSTANT: @@ -52,7 +52,7 @@ int8 CRunningScript::ProcessCommands1200To1299(int32 command) { CollectParameters(&m_nIp, 1); int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); - UpdateCompareFlag(ScriptParams[0] > *ptr); + UpdateCompareFlag(ScriptParams[0] > BSWAP32(*ptr)); return 0; } case COMMAND_IS_CONSTANT_GREATER_THAN_INT_LVAR: @@ -66,7 +66,7 @@ int8 CRunningScript::ProcessCommands1200To1299(int32 command) { int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); CollectParameters(&m_nIp, 1); - UpdateCompareFlag(*ptr >= ScriptParams[0]); + UpdateCompareFlag(BSWAP32(*ptr) >= ScriptParams[0]); return 0; } case COMMAND_IS_INT_LVAR_GREATER_OR_EQUAL_TO_CONSTANT: @@ -80,7 +80,7 @@ int8 CRunningScript::ProcessCommands1200To1299(int32 command) { CollectParameters(&m_nIp, 1); int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL); - UpdateCompareFlag(ScriptParams[0] >= *ptr); + UpdateCompareFlag(ScriptParams[0] >= BSWAP32(*ptr)); return 0; } case COMMAND_IS_CONSTANT_GREATER_OR_EQUAL_TO_INT_LVAR: diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp index eaf844ec..79f05640 100644 --- a/src/core/FileLoader.cpp +++ b/src/core/FileLoader.cpp @@ -230,8 +230,12 @@ CFileLoader::LoadCollisionFileFirstTime(uint8 *buffer, uint32 size, uint8 colSlo while(size > 8){ header = (ColHeader*)buffer; - modelsize = header->size; + modelsize = BSWAP32(header->size); +#ifdef BIGENDIAN + if(header->ident != 'COLL') +#else if(header->ident != 'LLOC') +#endif return size-8 < CDSTREAM_SECTOR_SIZE; memcpy(modelname, buffer+8, 24); memcpy(work_buff, buffer+32, modelsize-24); @@ -264,8 +268,12 @@ CFileLoader::LoadCollisionFile(uint8 *buffer, uint32 size, uint8 colSlot) while(size > 8){ header = (ColHeader*)buffer; - modelsize = header->size; + modelsize = BSWAP32(header->size); +#ifdef BIGENDIAN + if(header->ident != 'COLL') +#else if(header->ident != 'LLOC') +#endif return size-8 < CDSTREAM_SECTOR_SIZE; memcpy(modelname, buffer+8, 24); memcpy(work_buff, buffer+32, modelsize-24); diff --git a/src/rw/TexRead.cpp b/src/rw/TexRead.cpp index 77fefa8f..1078cfbf 100644 --- a/src/rw/TexRead.cpp +++ b/src/rw/TexRead.cpp @@ -305,7 +305,7 @@ CanVideoCardDoDXT(void) { #ifdef LIBRW // TODO -#ifdef RW_OPENGL +#if defined(RW_OPENGL) || defined(__WIIU__) return false; #else return true; diff --git a/src/text/Text.cpp b/src/text/Text.cpp index 0b551d30..240a94c2 100644 --- a/src/text/Text.cpp +++ b/src/text/Text.cpp @@ -214,6 +214,7 @@ CText::ReadChunkHeader(ChunkHeader *buf, int32 file, size_t *offset) CFileMgr::Read(file, (char*)buf, sizeof(ChunkHeader)); *offset += sizeof(ChunkHeader); #endif + memLittle32(&buf->size); } void @@ -464,6 +465,11 @@ CMissionTextOffsets::Load(size_t table_size, int file, size_t *offset, int) CFileMgr::Read(file, (char*)data, sizeof(CMissionTextOffsets::Entry) * size); *offset += sizeof(CMissionTextOffsets::Entry) * size; #endif +#ifdef BIGENDIAN + for (uint16 i = 0; i < size; i++) { + memLittle32(&data[i].offset); + } +#endif } char*