diff --git a/LEGO1/LegoOmni.def b/LEGO1/LegoOmni.def index 2807bea9..238bb6f2 100644 --- a/LEGO1/LegoOmni.def +++ b/LEGO1/LegoOmni.def @@ -98,7 +98,6 @@ EXPORTS ?RemoveAll@ViewManager@@QAEXPAVViewROI@@@Z ?RemoveWorld@LegoOmni@@QAEXABVMxAtomId@@J@Z ?Save@LegoGameState@@QAEJK@Z -?Seek@MxDSFile@@UAEJJH@Z ?SerializePlayersInfo@LegoGameState@@QAEXF@Z ?SerializeScoreHistory@LegoGameState@@QAEXF@Z ?SetCD@MxOmni@@SAXPBD@Z diff --git a/LEGO1/LegoOmni.mingw.def b/LEGO1/LegoOmni.mingw.def index 2d19d114..dbd07f3e 100644 --- a/LEGO1/LegoOmni.mingw.def +++ b/LEGO1/LegoOmni.mingw.def @@ -146,7 +146,6 @@ _ZN8MxDSFile13GetBufferSizeEv _ZN8MxDSFile19GetStreamBuffersNumEv _ZN8MxDSFile4OpenEj _ZN8MxDSFile4ReadEPhj -_ZN8MxDSFile4SeekEii _ZN8MxDSFile5CloseEv _ZN8MxDSFileC1EPKcj _ZN8MxDSFileC2EPKcj diff --git a/LEGO1/lego/legoomni/include/legoworldpresenter.h b/LEGO1/lego/legoomni/include/legoworldpresenter.h index 629aa381..f0657f7c 100644 --- a/LEGO1/lego/legoomni/include/legoworldpresenter.h +++ b/LEGO1/lego/legoomni/include/legoworldpresenter.h @@ -3,7 +3,7 @@ #include "legoentitypresenter.h" -#include +#include class LegoWorld; struct ModelDbPart; @@ -50,8 +50,8 @@ class LegoWorldPresenter : public LegoEntityPresenter { // LegoWorldPresenter::`scalar deleting destructor' private: - MxResult FUN_10067360(ModelDbPart& p_part, FILE* p_wdbFile); - MxResult FUN_100674b0(ModelDbModel& p_model, FILE* p_wdbFile, LegoWorld* p_world); + MxResult FUN_10067360(ModelDbPart& p_part, SDL_IOStream* p_wdbFile); + MxResult FUN_100674b0(ModelDbModel& p_model, SDL_IOStream* p_wdbFile, LegoWorld* p_world); undefined4 m_unk0x50; }; diff --git a/LEGO1/lego/legoomni/src/actors/act3actors.cpp b/LEGO1/lego/legoomni/src/actors/act3actors.cpp index 83fe23ab..1b82be72 100644 --- a/LEGO1/lego/legoomni/src/actors/act3actors.cpp +++ b/LEGO1/lego/legoomni/src/actors/act3actors.cpp @@ -16,6 +16,7 @@ #include "roi/legoroi.h" #include +#include DECOMP_SIZE_ASSERT(Act3Actor, 0x178) DECOMP_SIZE_ASSERT(Act3Cop, 0x188) diff --git a/LEGO1/lego/legoomni/src/actors/ambulance.cpp b/LEGO1/lego/legoomni/src/actors/ambulance.cpp index f89610b8..c2bf41b1 100644 --- a/LEGO1/lego/legoomni/src/actors/ambulance.cpp +++ b/LEGO1/lego/legoomni/src/actors/ambulance.cpp @@ -23,6 +23,8 @@ #include "mxvariabletable.h" #include "scripts.h" +#include + DECOMP_SIZE_ASSERT(Ambulance, 0x184) DECOMP_SIZE_ASSERT(AmbulanceMissionState, 0x24) diff --git a/LEGO1/lego/legoomni/src/actors/dunebuggy.cpp b/LEGO1/lego/legoomni/src/actors/dunebuggy.cpp index 59890fed..43332d0d 100644 --- a/LEGO1/lego/legoomni/src/actors/dunebuggy.cpp +++ b/LEGO1/lego/legoomni/src/actors/dunebuggy.cpp @@ -18,6 +18,8 @@ #include "mxtransitionmanager.h" #include "mxvariabletable.h" +#include + DECOMP_SIZE_ASSERT(DuneBuggy, 0x16c) // GLOBAL: LEGO1 0x100f7660 diff --git a/LEGO1/lego/legoomni/src/actors/jetski.cpp b/LEGO1/lego/legoomni/src/actors/jetski.cpp index 4db9d119..7c145d45 100644 --- a/LEGO1/lego/legoomni/src/actors/jetski.cpp +++ b/LEGO1/lego/legoomni/src/actors/jetski.cpp @@ -16,6 +16,8 @@ #include "mxvariabletable.h" #include "scripts.h" +#include + DECOMP_SIZE_ASSERT(Jetski, 0x164) // GLOBAL: LEGO1 0x100f7ab8 diff --git a/LEGO1/lego/legoomni/src/actors/motorcycle.cpp b/LEGO1/lego/legoomni/src/actors/motorcycle.cpp index 1c8c73db..63407ce0 100644 --- a/LEGO1/lego/legoomni/src/actors/motorcycle.cpp +++ b/LEGO1/lego/legoomni/src/actors/motorcycle.cpp @@ -16,6 +16,8 @@ #include "mxtransitionmanager.h" #include "mxvariabletable.h" +#include + DECOMP_SIZE_ASSERT(Motocycle, 0x16c) // FUNCTION: LEGO1 0x100357b0 diff --git a/LEGO1/lego/legoomni/src/actors/towtrack.cpp b/LEGO1/lego/legoomni/src/actors/towtrack.cpp index 08da9727..7dba4ee7 100644 --- a/LEGO1/lego/legoomni/src/actors/towtrack.cpp +++ b/LEGO1/lego/legoomni/src/actors/towtrack.cpp @@ -20,6 +20,8 @@ #include "mxtransitionmanager.h" #include "mxvariabletable.h" +#include + DECOMP_SIZE_ASSERT(TowTrack, 0x180) DECOMP_SIZE_ASSERT(TowTrackMissionState, 0x28) diff --git a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp index e8ac3d7d..a75f382c 100644 --- a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp +++ b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp @@ -31,6 +31,7 @@ #include "scripts.h" #include +#include #include // Names and values verified by BETA10 0x1006d742. diff --git a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp index 4b74fdf1..c360b1a6 100644 --- a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp @@ -29,6 +29,7 @@ #include "viewmanager/viewmanager.h" #include +#include #include DECOMP_SIZE_ASSERT(LegoAnimationManager, 0x500) diff --git a/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp b/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp index 57c4aa42..2ac46fd2 100644 --- a/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp @@ -16,6 +16,7 @@ #include "roi/legolod.h" #include "viewmanager/viewmanager.h" +#include #include DECOMP_SIZE_ASSERT(LegoCharacter, 0x08) diff --git a/LEGO1/lego/legoomni/src/common/legoutils.cpp b/LEGO1/lego/legoomni/src/common/legoutils.cpp index 8037b901..4f9deefc 100644 --- a/LEGO1/lego/legoomni/src/common/legoutils.cpp +++ b/LEGO1/lego/legoomni/src/common/legoutils.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include diff --git a/LEGO1/lego/legoomni/src/entity/legoentity.cpp b/LEGO1/lego/legoomni/src/entity/legoentity.cpp index 731fa70c..f6c4a200 100644 --- a/LEGO1/lego/legoomni/src/entity/legoentity.cpp +++ b/LEGO1/lego/legoomni/src/entity/legoentity.cpp @@ -18,6 +18,8 @@ #include "mxutilities.h" #include "realtime/realtime.h" +#include + DECOMP_SIZE_ASSERT(LegoEntity, 0x68) // FUNCTION: LEGO1 0x100105f0 diff --git a/LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp b/LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp index c4b8c52e..fa2c183b 100644 --- a/LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp +++ b/LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp @@ -27,7 +27,7 @@ #include "mxstl/stlcompat.h" #include "mxutilities.h" -#include +#include DECOMP_SIZE_ASSERT(LegoWorldPresenter, 0x54) @@ -35,7 +35,7 @@ DECOMP_SIZE_ASSERT(LegoWorldPresenter, 0x54) MxS32 g_legoWorldPresenterQuality = 1; // GLOBAL: LEGO1 0x100f75d8 -MxLong g_wdbOffset = 0; +Sint64 g_wdbOffset = 0; // FUNCTION: LEGO1 0x100665b0 void LegoWorldPresenter::configureLegoWorldPresenter(MxS32 p_legoWorldPresenterQuality) @@ -166,22 +166,26 @@ MxResult LegoWorldPresenter::LoadWorld(char* p_worldName, LegoWorld* p_world) char wdbPath[512]; sprintf(wdbPath, "%s", MxOmni::GetHD()); - if (wdbPath[strlen(wdbPath) - 1] != '\\') { + if (wdbPath[strlen(wdbPath) - 1] != '\\' && wdbPath[strlen(wdbPath) - 1] != '/') { strcat(wdbPath, "\\"); } strcat(wdbPath, "lego\\data\\world.wdb"); + MxString::NormalizePath(wdbPath); - if (access(wdbPath, 4) != 0) { + SDL_IOStream* wdbFile; + + if ((wdbFile = SDL_IOFromFile(wdbPath, "rb")) == NULL) { sprintf(wdbPath, "%s", MxOmni::GetCD()); - if (wdbPath[strlen(wdbPath) - 1] != '\\') { + if (wdbPath[strlen(wdbPath) - 1] != '\\' && wdbPath[strlen(wdbPath) - 1] != '/') { strcat(wdbPath, "\\"); } strcat(wdbPath, "lego\\data\\world.wdb"); + MxString::NormalizePath(wdbPath); - if (access(wdbPath, 4) != 0) { + if ((wdbFile = SDL_IOFromFile(wdbPath, "rb")) == NULL) { return FAILURE; } } @@ -190,11 +194,6 @@ MxResult LegoWorldPresenter::LoadWorld(char* p_worldName, LegoWorld* p_world) MxS32 numWorlds, i, j; MxU32 size; MxU8* buff; - FILE* wdbFile = fopen(wdbPath, "rb"); - - if (wdbFile == NULL) { - return FAILURE; - } ReadModelDbWorlds(wdbFile, worlds, numWorlds); @@ -209,12 +208,12 @@ MxResult LegoWorldPresenter::LoadWorld(char* p_worldName, LegoWorld* p_world) } if (g_wdbOffset == 0) { - if (fread(&size, sizeof(size), 1, wdbFile) != 1) { + if (SDL_ReadIO(wdbFile, &size, sizeof(size)) != sizeof(size)) { return FAILURE; } buff = new MxU8[size]; - if (fread(buff, size, 1, wdbFile) != 1) { + if (SDL_ReadIO(wdbFile, buff, size) != size) { return FAILURE; } @@ -229,12 +228,12 @@ MxResult LegoWorldPresenter::LoadWorld(char* p_worldName, LegoWorld* p_world) delete[] buff; - if (fread(&size, sizeof(size), 1, wdbFile) != 1) { + if (SDL_ReadIO(wdbFile, &size, sizeof(size)) != sizeof(size)) { return FAILURE; } buff = new MxU8[size]; - if (fread(buff, size, 1, wdbFile) != 1) { + if (SDL_ReadIO(wdbFile, buff, size) != size) { return FAILURE; } @@ -248,10 +247,10 @@ MxResult LegoWorldPresenter::LoadWorld(char* p_worldName, LegoWorld* p_world) delete[] buff; - g_wdbOffset = ftell(wdbFile); + g_wdbOffset = SDL_TellIO(wdbFile); } else { - if (fseek(wdbFile, g_wdbOffset, SEEK_SET) != 0) { + if (SDL_SeekIO(wdbFile, g_wdbOffset, SDL_IO_SEEK_SET) != g_wdbOffset) { return FAILURE; } } @@ -309,18 +308,18 @@ MxResult LegoWorldPresenter::LoadWorld(char* p_worldName, LegoWorld* p_world) } FreeModelDbWorlds(worlds, numWorlds); - fclose(wdbFile); + SDL_CloseIO(wdbFile); return SUCCESS; } // FUNCTION: LEGO1 0x10067360 -MxResult LegoWorldPresenter::FUN_10067360(ModelDbPart& p_part, FILE* p_wdbFile) +MxResult LegoWorldPresenter::FUN_10067360(ModelDbPart& p_part, SDL_IOStream* p_wdbFile) { MxResult result; MxU8* buff = new MxU8[p_part.m_partDataLength]; - fseek(p_wdbFile, p_part.m_partDataOffset, SEEK_SET); - if (fread(buff, p_part.m_partDataLength, 1, p_wdbFile) != 1) { + SDL_SeekIO(p_wdbFile, p_part.m_partDataOffset, SDL_IO_SEEK_SET); + if (SDL_ReadIO(p_wdbFile, buff, p_part.m_partDataLength) != p_part.m_partDataLength) { return FAILURE; } @@ -340,12 +339,12 @@ MxResult LegoWorldPresenter::FUN_10067360(ModelDbPart& p_part, FILE* p_wdbFile) } // FUNCTION: LEGO1 0x100674b0 -MxResult LegoWorldPresenter::FUN_100674b0(ModelDbModel& p_model, FILE* p_wdbFile, LegoWorld* p_world) +MxResult LegoWorldPresenter::FUN_100674b0(ModelDbModel& p_model, SDL_IOStream* p_wdbFile, LegoWorld* p_world) { MxU8* buff = new MxU8[p_model.m_unk0x04]; - fseek(p_wdbFile, p_model.m_unk0x08, SEEK_SET); - if (fread(buff, p_model.m_unk0x04, 1, p_wdbFile) != 1) { + SDL_SeekIO(p_wdbFile, p_model.m_unk0x08, SDL_IO_SEEK_SET); + if (SDL_ReadIO(p_wdbFile, buff, p_model.m_unk0x04) != p_model.m_unk0x04) { return FAILURE; } diff --git a/LEGO1/lego/legoomni/src/race/carrace.cpp b/LEGO1/lego/legoomni/src/race/carrace.cpp index c979db0b..e3f38cb8 100644 --- a/LEGO1/lego/legoomni/src/race/carrace.cpp +++ b/LEGO1/lego/legoomni/src/race/carrace.cpp @@ -23,6 +23,8 @@ #include "mxvariabletable.h" #include "scripts.h" +#include + DECOMP_SIZE_ASSERT(CarRace, 0x154) // GLOBAL: LEGO1 0x100d5d10 diff --git a/LEGO1/lego/legoomni/src/race/jetskirace.cpp b/LEGO1/lego/legoomni/src/race/jetskirace.cpp index d8f9323d..2bdcd095 100644 --- a/LEGO1/lego/legoomni/src/race/jetskirace.cpp +++ b/LEGO1/lego/legoomni/src/race/jetskirace.cpp @@ -22,6 +22,8 @@ #include "mxvariabletable.h" #include "scripts.h" +#include + // Defined in legopathstruct.cpp extern MxBool g_unk0x100f119c; diff --git a/LEGO1/lego/legoomni/src/race/legoracers.cpp b/LEGO1/lego/legoomni/src/race/legoracers.cpp index 15d6e66e..0d0fbb0f 100644 --- a/LEGO1/lego/legoomni/src/race/legoracers.cpp +++ b/LEGO1/lego/legoomni/src/race/legoracers.cpp @@ -19,6 +19,8 @@ #include "mxvariabletable.h" #include "raceskel.h" +#include + DECOMP_SIZE_ASSERT(EdgeReference, 0x08) DECOMP_SIZE_ASSERT(SkeletonKickPhase, 0x10) DECOMP_SIZE_ASSERT(LegoRaceCar, 0x200) diff --git a/LEGO1/lego/legoomni/src/video/legoanimpresenter.cpp b/LEGO1/lego/legoomni/src/video/legoanimpresenter.cpp index c827043f..39df4a50 100644 --- a/LEGO1/lego/legoomni/src/video/legoanimpresenter.cpp +++ b/LEGO1/lego/legoomni/src/video/legoanimpresenter.cpp @@ -26,6 +26,8 @@ #include "realtime/realtime.h" #include "viewmanager/viewmanager.h" +#include + DECOMP_SIZE_ASSERT(LegoAnimPresenter, 0xbc) // FUNCTION: LEGO1 0x10068420 diff --git a/LEGO1/lego/legoomni/src/worlds/act3.cpp b/LEGO1/lego/legoomni/src/worlds/act3.cpp index 170343fd..80b635b0 100644 --- a/LEGO1/lego/legoomni/src/worlds/act3.cpp +++ b/LEGO1/lego/legoomni/src/worlds/act3.cpp @@ -23,6 +23,7 @@ #include "mxtransitionmanager.h" #include "scripts.h" +#include #include DECOMP_SIZE_ASSERT(Act3, 0x4274) diff --git a/LEGO1/lego/sources/misc/legostorage.cpp b/LEGO1/lego/sources/misc/legostorage.cpp index 7da93569..af4ecb8e 100644 --- a/LEGO1/lego/sources/misc/legostorage.cpp +++ b/LEGO1/lego/sources/misc/legostorage.cpp @@ -42,7 +42,7 @@ LegoFile::LegoFile() LegoFile::~LegoFile() { if (m_file) { - fclose(m_file); + SDL_CloseIO(m_file); } } @@ -52,7 +52,7 @@ LegoResult LegoFile::Read(void* p_buffer, LegoU32 p_size) if (!m_file) { return FAILURE; } - if (fread(p_buffer, 1, p_size, m_file) != p_size) { + if (SDL_ReadIO(m_file, p_buffer, p_size) != p_size) { return FAILURE; } return SUCCESS; @@ -64,7 +64,7 @@ LegoResult LegoFile::Write(const void* p_buffer, LegoU32 p_size) if (!m_file) { return FAILURE; } - if (fwrite(p_buffer, 1, p_size, m_file) != p_size) { + if (SDL_WriteIO(m_file, p_buffer, p_size) != p_size) { return FAILURE; } return SUCCESS; @@ -76,7 +76,7 @@ LegoResult LegoFile::GetPosition(LegoU32& p_position) if (!m_file) { return FAILURE; } - LegoU32 position = ftell(m_file); + Sint64 position = SDL_TellIO(m_file); if (position == -1) { return FAILURE; } @@ -90,7 +90,7 @@ LegoResult LegoFile::SetPosition(LegoU32 p_position) if (!m_file) { return FAILURE; } - if (fseek(m_file, p_position, SEEK_SET) != 0) { + if (SDL_SeekIO(m_file, p_position, SDL_IO_SEEK_SET) != p_position) { return FAILURE; } return SUCCESS; @@ -100,7 +100,7 @@ LegoResult LegoFile::SetPosition(LegoU32 p_position) LegoResult LegoFile::Open(const char* p_name, LegoU32 p_mode) { if (m_file) { - fclose(m_file); + SDL_CloseIO(m_file); } char mode[4]; mode[0] = '\0'; @@ -115,13 +115,15 @@ LegoResult LegoFile::Open(const char* p_name, LegoU32 p_mode) strcat(mode, "w"); } if ((p_mode & c_text) != 0) { - strcat(mode, "t"); } else { strcat(mode, "b"); } - if (!(m_file = fopen(p_name, mode))) { + MxString path(p_name); + path.NormalizePath(); + + if (!(m_file = SDL_IOFromFile(path.GetData(), mode))) { return FAILURE; } return SUCCESS; diff --git a/LEGO1/lego/sources/misc/legostorage.h b/LEGO1/lego/sources/misc/legostorage.h index 5de72303..16cc976c 100644 --- a/LEGO1/lego/sources/misc/legostorage.h +++ b/LEGO1/lego/sources/misc/legostorage.h @@ -5,7 +5,7 @@ #include "mxgeometry/mxgeometry3d.h" #include "mxstring.h" -#include +#include // VTABLE: LEGO1 0x100d7d80 // SIZE 0x08 @@ -149,7 +149,7 @@ class LegoFile : public LegoStorage { // LegoFile::`scalar deleting destructor' protected: - FILE* m_file; // 0x08 + SDL_IOStream* m_file; // 0x08 }; #endif // __LEGOSTORAGE_H diff --git a/LEGO1/modeldb/modeldb.cpp b/LEGO1/modeldb/modeldb.cpp index c56e62b7..62fb2ca5 100644 --- a/LEGO1/modeldb/modeldb.cpp +++ b/LEGO1/modeldb/modeldb.cpp @@ -15,44 +15,44 @@ void ModelDbModel::Free() } // FUNCTION: LEGO1 0x100276b0 -MxResult ModelDbModel::Read(FILE* p_file) +MxResult ModelDbModel::Read(SDL_IOStream* p_file) { MxU32 len; - if (fread(&len, sizeof(len), 1, p_file) != 1) { + if (SDL_ReadIO(p_file, &len, sizeof(len)) != sizeof(len)) { return FAILURE; } m_modelName = new char[len]; - if (fread(m_modelName, len, 1, p_file) != 1) { + if (SDL_ReadIO(p_file, m_modelName, len) != len) { return FAILURE; } - if (fread(&m_unk0x04, sizeof(m_unk0x04), 1, p_file) != 1) { + if (SDL_ReadIO(p_file, &m_unk0x04, sizeof(m_unk0x04)) != sizeof(m_unk0x04)) { return FAILURE; } - if (fread(&m_unk0x08, sizeof(m_unk0x08), 1, p_file) != 1) { + if (SDL_ReadIO(p_file, &m_unk0x08, sizeof(m_unk0x08)) != sizeof(m_unk0x08)) { return FAILURE; } - if (fread(&len, sizeof(len), 1, p_file) != 1) { + if (SDL_ReadIO(p_file, &len, sizeof(len)) != sizeof(len)) { return FAILURE; } m_presenterName = new char[len]; - if (fread(m_presenterName, len, 1, p_file) != 1) { + if (SDL_ReadIO(p_file, m_presenterName, len) != len) { return FAILURE; } - if (fread(&m_location, sizeof(*m_location), 3, p_file) != 3) { + if (SDL_ReadIO(p_file, m_location, sizeof(m_location)) != sizeof(m_location)) { return FAILURE; } - if (fread(&m_direction, sizeof(*m_direction), 3, p_file) != 3) { + if (SDL_ReadIO(p_file, m_direction, sizeof(m_direction)) != sizeof(m_direction)) { return FAILURE; } - if (fread(&m_up, sizeof(*m_up), 3, p_file) != 3) { + if (SDL_ReadIO(p_file, m_up, sizeof(m_up)) != sizeof(m_up)) { return FAILURE; } - if (fread(&m_unk0x34, sizeof(m_unk0x34), 1, p_file) != 1) { + if (SDL_ReadIO(p_file, &m_unk0x34, sizeof(m_unk0x34)) != sizeof(m_unk0x34)) { return FAILURE; } @@ -60,26 +60,27 @@ MxResult ModelDbModel::Read(FILE* p_file) } // FUNCTION: LEGO1 0x10027850 -MxResult ModelDbPart::Read(FILE* p_file) +MxResult ModelDbPart::Read(SDL_IOStream* p_file) { MxU32 len; - char buff[128]; - if (fread(&len, sizeof(len), 1, p_file) != 1) { + if (SDL_ReadIO(p_file, &len, sizeof(len)) != sizeof(len)) { return FAILURE; } - // (modernization) critical bug: buffer overrun - if (fread(buff, len, 1, p_file) != 1) { + char* buff = new char[len]; + + if (SDL_ReadIO(p_file, buff, len) != len) { return FAILURE; } m_roiName = buff; + delete[] buff; - if (fread(&m_partDataLength, sizeof(m_partDataLength), 1, p_file) != 1) { + if (SDL_ReadIO(p_file, &m_partDataLength, sizeof(m_partDataLength)) != sizeof(m_partDataLength)) { return FAILURE; } - if (fread(&m_partDataOffset, sizeof(m_partDataOffset), 1, p_file) != 1) { + if (SDL_ReadIO(p_file, &m_partDataOffset, sizeof(m_partDataOffset)) != sizeof(m_partDataOffset)) { return FAILURE; } @@ -87,13 +88,13 @@ MxResult ModelDbPart::Read(FILE* p_file) } // FUNCTION: LEGO1 0x10027910 -MxResult ReadModelDbWorlds(FILE* p_file, ModelDbWorld*& p_worlds, MxS32& p_numWorlds) +MxResult ReadModelDbWorlds(SDL_IOStream* p_file, ModelDbWorld*& p_worlds, MxS32& p_numWorlds) { p_worlds = NULL; p_numWorlds = 0; MxS32 numWorlds; - if (fread(&numWorlds, sizeof(numWorlds), 1, p_file) != 1) { + if (SDL_ReadIO(p_file, &numWorlds, sizeof(numWorlds)) != sizeof(numWorlds)) { return FAILURE; } @@ -101,16 +102,16 @@ MxResult ReadModelDbWorlds(FILE* p_file, ModelDbWorld*& p_worlds, MxS32& p_numWo MxS32 worldNameLen, numParts, i, j; for (i = 0; i < numWorlds; i++) { - if (fread(&worldNameLen, sizeof(worldNameLen), 1, p_file) != 1) { + if (SDL_ReadIO(p_file, &worldNameLen, sizeof(worldNameLen)) != sizeof(worldNameLen)) { return FAILURE; } worlds[i].m_worldName = new char[worldNameLen]; - if (fread(worlds[i].m_worldName, worldNameLen, 1, p_file) != 1) { + if (SDL_ReadIO(p_file, worlds[i].m_worldName, worldNameLen) != worldNameLen) { return FAILURE; } - if (fread(&numParts, sizeof(numParts), 1, p_file) != 1) { + if (SDL_ReadIO(p_file, &numParts, sizeof(numParts)) != sizeof(numParts)) { return FAILURE; } @@ -126,7 +127,8 @@ MxResult ReadModelDbWorlds(FILE* p_file, ModelDbWorld*& p_worlds, MxS32& p_numWo worlds[i].m_partList->Append(part); } - if (fread(&worlds[i].m_numModels, sizeof(worlds[i].m_numModels), 1, p_file) != 1) { + if (SDL_ReadIO(p_file, &worlds[i].m_numModels, sizeof(worlds[i].m_numModels)) != + sizeof(worlds[i].m_numModels)) { return FAILURE; } diff --git a/LEGO1/modeldb/modeldb.h b/LEGO1/modeldb/modeldb.h index 911832e5..979a5249 100644 --- a/LEGO1/modeldb/modeldb.h +++ b/LEGO1/modeldb/modeldb.h @@ -6,11 +6,11 @@ #include "mxstring.h" #include "mxtypes.h" -#include +#include // SIZE 0x18 struct ModelDbPart { - MxResult Read(FILE* p_file); + MxResult Read(SDL_IOStream* p_file); MxString m_roiName; // 0x00 undefined4 m_partDataLength; // 0x10 @@ -92,7 +92,7 @@ class ModelDbPartListCursor : public MxListCursor { // SIZE 0x38 struct ModelDbModel { void Free(); - MxResult Read(FILE* p_file); + MxResult Read(SDL_IOStream* p_file); char* m_modelName; // 0x00 undefined4 m_unk0x04; // 0x04 @@ -113,7 +113,7 @@ struct ModelDbWorld { undefined m_unk0x10[0x08]; // 0x10 }; -MxResult ReadModelDbWorlds(FILE* p_file, ModelDbWorld*& p_worlds, MxS32& p_numWorlds); +MxResult ReadModelDbWorlds(SDL_IOStream* p_file, ModelDbWorld*& p_worlds, MxS32& p_numWorlds); void FreeModelDbWorlds(ModelDbWorld*& p_worlds, MxS32 p_numWorlds); #endif // MODELDB_H diff --git a/LEGO1/omni/include/mxdsfile.h b/LEGO1/omni/include/mxdsfile.h index f15139f9..4ddfaf3c 100644 --- a/LEGO1/omni/include/mxdsfile.h +++ b/LEGO1/omni/include/mxdsfile.h @@ -6,8 +6,6 @@ #include "mxstring.h" #include "mxtypes.h" -#include - // VTABLE: LEGO1 0x100dc890 // VTABLE: BETA10 0x101c2418 // SIZE 0x7c @@ -43,14 +41,14 @@ class MxDSFile : public MxDSSource { MxResult Open(MxULong) override; // vtable+0x14 MxResult Close() override; // vtable+0x18 MxResult Read(unsigned char*, MxULong) override; // vtable+0x20 - MxResult Seek(MxLong, MxS32) override; // vtable+0x24 + MxResult Seek(MxLong, SDL_IOWhence) override; // vtable+0x24 MxULong GetBufferSize() override; // vtable+0x28 MxULong GetStreamBuffersNum() override; // vtable+0x2c // FUNCTION: BETA10 0x1015e110 void SetFileName(const char* p_filename) { m_filename = p_filename; } - MxS32 CalcFileSize() { return GetFileSize(m_io.m_info.hmmio, NULL); } + MxS32 CalcFileSize() { return SDL_GetIOSize(m_io.m_file); } // SYNTHETIC: LEGO1 0x100c01e0 // SYNTHETIC: BETA10 0x10148e40 @@ -63,7 +61,7 @@ class MxDSFile : public MxDSSource { MxS16 m_majorVersion; // 0x00 MxS16 m_minorVersion; // 0x02 - MxULong m_bufferSize; // 0x04 + MxU32 m_bufferSize; // 0x04 MxS16 m_streamBuffersNum; // 0x08 MxS16 m_reserved; // 0x0a }; diff --git a/LEGO1/omni/include/mxdssource.h b/LEGO1/omni/include/mxdssource.h index 06f5e556..6dd03a83 100644 --- a/LEGO1/omni/include/mxdssource.h +++ b/LEGO1/omni/include/mxdssource.h @@ -3,6 +3,8 @@ #include "mxcore.h" +#include + class MxDSBuffer; // VTABLE: LEGO1 0x100dc8c8 @@ -31,7 +33,7 @@ class MxDSSource : public MxCore { virtual MxLong Close() = 0; // vtable+0x18 virtual MxResult ReadToBuffer(MxDSBuffer* p_buffer); // vtable+0x1c virtual MxResult Read(unsigned char*, MxULong) = 0; // vtable+0x20 - virtual MxLong Seek(MxLong, MxS32) = 0; // vtable+0x24 + virtual MxLong Seek(MxLong, SDL_IOWhence) = 0; // vtable+0x24 virtual MxULong GetBufferSize() = 0; // vtable+0x28 virtual MxULong GetStreamBuffersNum() = 0; // vtable+0x2c virtual MxLong GetLengthInDWords(); // vtable+0x30 diff --git a/LEGO1/omni/include/mxio.h b/LEGO1/omni/include/mxio.h index 64461d6a..4a549ecd 100644 --- a/LEGO1/omni/include/mxio.h +++ b/LEGO1/omni/include/mxio.h @@ -3,15 +3,70 @@ #include "mxtypes.h" -// mmsystem.h requires inclusion of windows.h before -// clang-format off -#include -#include -// clang-format on +#include -#if defined(_M_IX86) || defined(__i386__) -#define MXIO_MINFO_MFILE -#endif +// [library:filesystem] +// We define the bare minimum constants and structures to be compatible with the code in mxio.cpp +// This is mostly copy-pasted from the MMSYSTEM.H Windows header. + +/* MMIO error return values */ +#define MMIOERR_BASE 256 +#define MMIOERR_OUTOFMEMORY (MMIOERR_BASE + 2) /* out of memory */ +#define MMIOERR_CANNOTOPEN (MMIOERR_BASE + 3) /* cannot open */ +#define MMIOERR_CANNOTREAD (MMIOERR_BASE + 5) /* cannot read */ +#define MMIOERR_CANNOTWRITE (MMIOERR_BASE + 6) /* cannot write */ +#define MMIOERR_CANNOTSEEK (MMIOERR_BASE + 7) /* cannot seek */ +#define MMIOERR_CHUNKNOTFOUND (MMIOERR_BASE + 9) /* chunk not found */ +#define MMIOERR_UNBUFFERED (MMIOERR_BASE + 10) /* */ + +/* bit field masks */ +#define MMIO_RWMODE 0x00000003 /* open file for reading/writing/both */ + +/* constants for dwFlags field of MMIOINFO */ +#define MMIO_ALLOCBUF 0x00010000 /* mmioOpen() should allocate a buffer */ +#define MMIO_DIRTY 0x10000000 /* I/O buffer is dirty */ + +/* read/write mode numbers (bit field MMIO_RWMODE) */ +#define MMIO_READ 0x00000000 /* open file for reading only */ +#define MMIO_WRITE 0x00000001 /* open file for writing only */ +#define MMIO_READWRITE 0x00000002 /* open file for reading and writing */ + +/* MMIO macros */ +#define mmioFOURCC(ch0, ch1, ch2, ch3) FOURCC(ch0, ch1, ch2, ch3) + +/* standard four character codes */ +#define FOURCC_RIFF mmioFOURCC('R', 'I', 'F', 'F') +#define FOURCC_LIST mmioFOURCC('L', 'I', 'S', 'T') + +/* various MMIO flags */ +#define MMIO_FINDRIFF 0x0020 /* mmioDescend: find a LIST chunk */ +#define MMIO_FINDLIST 0x0040 /* mmioDescend: find a RIFF chunk */ + +/* general MMIO information data structure */ +typedef struct _ISLE_MMIOINFO { + /* general fields */ + MxU32 dwFlags; /* general status flags */ + + /* fields maintained by MMIO functions during buffered I/O */ + Sint64 cchBuffer; /* size of I/O buffer (or 0L) */ + char* pchBuffer; /* start of I/O buffer (or NULL) */ + char* pchNext; /* pointer to next byte to read/write */ + char* pchEndRead; /* pointer to last valid byte to read */ + char* pchEndWrite; /* pointer to last byte to write */ + Sint64 lBufOffset; /* disk offset of start of buffer */ + + /* fields maintained by I/O procedure */ + Sint64 lDiskOffset; /* disk offset of next read or write */ +} ISLE_MMIOINFO; + +/* RIFF chunk information data structure */ +typedef struct _ISLE_MMCKINFO { + MxU32 ckid; /* chunk ID */ + MxU32 cksize; /* chunk size */ + MxU32 fccType; /* form type or list type */ + MxU32 dwDataOffset; /* offset of data portion of chunk */ + MxU32 dwFlags; /* flags used by MMIO functions */ +} ISLE_MMCKINFO; // SIZE 0x48 class MXIOINFO { @@ -23,19 +78,18 @@ class MXIOINFO { MxU16 Close(MxLong); MxLong Read(void*, MxLong); MxLong Write(void*, MxLong); - MxLong Seek(MxLong, MxLong); + MxLong Seek(MxLong, SDL_IOWhence); MxU16 SetBuffer(char*, MxLong, MxLong); MxU16 Flush(MxU16); MxU16 Advance(MxU16); - MxU16 Descend(MMCKINFO*, const MMCKINFO*, MxU16); - MxU16 Ascend(MMCKINFO*, MxU16); + MxU16 Descend(ISLE_MMCKINFO*, const ISLE_MMCKINFO*, MxU16); + MxU16 Ascend(ISLE_MMCKINFO*, MxU16); // NOTE: In MXIOINFO, the `hmmio` member of MMIOINFO is used like // an HFILE (int) instead of an HMMIO (WORD). - MMIOINFO m_info; -#ifndef MXIO_MINFO_MFILE - HFILE m_file; -#endif + ISLE_MMIOINFO m_info; + // [library:filesystem] This handle is always used instead of the `hmmio` member in m_info. + SDL_IOStream* m_file; }; #endif // MXIO_H diff --git a/LEGO1/omni/include/mxomni.h b/LEGO1/omni/include/mxomni.h index 4ac59916..6b2a7537 100644 --- a/LEGO1/omni/include/mxomni.h +++ b/LEGO1/omni/include/mxomni.h @@ -36,6 +36,7 @@ class MxOmni : public MxCore { static void SetCD(const char* p_cd); static void SetHD(const char* p_hd); static void SetSound3D(MxBool p_use3dSound); + static void NormalizePath(char* p_path); MxOmni(); ~MxOmni() override; diff --git a/LEGO1/omni/include/mxstring.h b/LEGO1/omni/include/mxstring.h index 477c821c..ccaafbed 100644 --- a/LEGO1/omni/include/mxstring.h +++ b/LEGO1/omni/include/mxstring.h @@ -17,6 +17,7 @@ class MxString : public MxCore { void Reverse(); void ToUpperCase(); void ToLowerCase(); + void NormalizePath() { NormalizePath(m_data); } MxString& operator=(const MxString& p_str); const MxString& operator=(const char* p_str); @@ -25,6 +26,7 @@ class MxString : public MxCore { MxString& operator+=(const char* p_str); static void CharSwap(char* p_a, char* p_b); + static void NormalizePath(char* p_path); // FUNCTION: BETA10 0x10017c50 char* GetData() const { return m_data; } diff --git a/LEGO1/omni/src/common/mxstring.cpp b/LEGO1/omni/src/common/mxstring.cpp index b33a7f10..d7f8093c 100644 --- a/LEGO1/omni/src/common/mxstring.cpp +++ b/LEGO1/omni/src/common/mxstring.cpp @@ -2,6 +2,7 @@ #include "decomp.h" +#include #include #include @@ -185,3 +186,22 @@ void MxString::CharSwap(char* p_a, char* p_b) *p_a = *p_b; *p_b = t; } + +void MxString::NormalizePath(char* p_path) +{ + // [library:filesystem] + // This function is used to build a consistent path that will eventually be used to read a file. + // The input may come with Windows path separators, i.e. \lego\scripts\infocntr\infomain + // We have to replace the backslashes with forward slashes to be able to access the files + // on non-Windows systems +#if !defined(SDL_PLATFORM_WINDOWS) + char* path = p_path; + while (*path) { + if (*path == '\\') { + *path = '/'; + } + + path++; + } +#endif +} diff --git a/LEGO1/omni/src/common/mxutilities.cpp b/LEGO1/omni/src/common/mxutilities.cpp index c943bde5..22c82c65 100644 --- a/LEGO1/omni/src/common/mxutilities.cpp +++ b/LEGO1/omni/src/common/mxutilities.cpp @@ -164,9 +164,9 @@ void FUN_100b7220(MxDSAction* p_action, MxU32 p_newFlags, MxBool p_setFlags) MxDSObject* CreateStreamObject(MxDSFile* p_file, MxS16 p_ofs) { MxU8* buf; - _MMCKINFO tmpChunk; + ISLE_MMCKINFO tmpChunk; - if (p_file->Seek(((MxLong*) p_file->GetBuffer())[p_ofs], SEEK_SET)) { + if (p_file->Seek(((MxLong*) p_file->GetBuffer())[p_ofs], SDL_IO_SEEK_SET)) { return NULL; } diff --git a/LEGO1/omni/src/stream/mxdiskstreamprovider.cpp b/LEGO1/omni/src/stream/mxdiskstreamprovider.cpp index 80f93c51..2c4cdaf0 100644 --- a/LEGO1/omni/src/stream/mxdiskstreamprovider.cpp +++ b/LEGO1/omni/src/stream/mxdiskstreamprovider.cpp @@ -245,7 +245,7 @@ void MxDiskStreamProvider::PerformWork() buffer = streamingAction->GetUnknowna0(); if (m_pFile->GetPosition() == streamingAction->GetBufferOffset() || - m_pFile->Seek(streamingAction->GetBufferOffset(), SEEK_SET) == 0) { + m_pFile->Seek(streamingAction->GetBufferOffset(), SDL_IO_SEEK_SET) == 0) { buffer->SetUnknown14(m_pFile->GetPosition()); if (m_pFile->ReadToBuffer(buffer) == SUCCESS) { diff --git a/LEGO1/omni/src/stream/mxdsfile.cpp b/LEGO1/omni/src/stream/mxdsfile.cpp index 54195f92..2c5b5247 100644 --- a/LEGO1/omni/src/stream/mxdsfile.cpp +++ b/LEGO1/omni/src/stream/mxdsfile.cpp @@ -3,6 +3,7 @@ #include "decomp.h" #include "mxdebug.h" +#include #include #define SI_MAJOR_VERSION 2 @@ -41,7 +42,7 @@ MxResult MxDSFile::Open(MxULong p_uStyle) Close(); } else { - Seek(0, SEEK_SET); + Seek(0, SDL_IO_SEEK_SET); } return result; @@ -51,8 +52,8 @@ MxResult MxDSFile::Open(MxULong p_uStyle) // FUNCTION: BETA10 0x1015dd18 MxResult MxDSFile::ReadChunks() { - _MMCKINFO topChunk; - _MMCKINFO childChunk; + ISLE_MMCKINFO topChunk; + ISLE_MMCKINFO childChunk; char tempBuffer[80]; topChunk.fccType = FOURCC('O', 'M', 'N', 'I'); @@ -70,7 +71,7 @@ MxResult MxDSFile::ReadChunks() m_io.Read(&m_header, 0x0c); if ((m_header.m_majorVersion != SI_MAJOR_VERSION) || (m_header.m_minorVersion != SI_MINOR_VERSION)) { sprintf(tempBuffer, "Wrong SI file version. %d.%d expected.", SI_MAJOR_VERSION, SI_MINOR_VERSION); - MessageBoxA(NULL, tempBuffer, NULL, MB_ICONERROR); + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "LEGO® Island Error", tempBuffer, NULL); return FAILURE; } @@ -116,7 +117,7 @@ MxResult MxDSFile::Read(unsigned char* p_buf, MxULong p_nbytes) // FUNCTION: LEGO1 0x100cc7b0 // FUNCTION: BETA10 0x1015dfee -MxResult MxDSFile::Seek(MxLong p_lOffset, MxS32 p_iOrigin) +MxResult MxDSFile::Seek(MxLong p_lOffset, SDL_IOWhence p_iOrigin) { m_position = m_io.Seek(p_lOffset, p_iOrigin); if (m_position == -1) { diff --git a/LEGO1/omni/src/stream/mxio.cpp b/LEGO1/omni/src/stream/mxio.cpp index 3b7c9b6d..49d55ad2 100644 --- a/LEGO1/omni/src/stream/mxio.cpp +++ b/LEGO1/omni/src/stream/mxio.cpp @@ -1,23 +1,19 @@ #include "mxio.h" #include "decomp.h" +#include "mxstring.h" #include +#include // This class should be 72 bytes in size, same as the MMIOINFO struct. // The current implementation has MMIOINFO as the only member of the class, // but this assert will enforce the size if we decide to change that. DECOMP_SIZE_ASSERT(MXIOINFO, sizeof(MMIOINFO)); -#ifdef MXIO_MINFO_MFILE -#define ASSIGN_M_FILE(X) m_info.hmmio = (HMMIO) (X) -#define M_FILE (HFILE)(m_info.hmmio) -#define RAW_M_FILE m_info.hmmio -#else #define ASSIGN_M_FILE(X) m_file = (X) #define M_FILE (m_file) #define RAW_M_FILE m_file -#endif // FUNCTION: LEGO1 0x100cc800 // FUNCTION: BETA10 0x1015e140 @@ -37,21 +33,23 @@ MXIOINFO::~MXIOINFO() // FUNCTION: BETA10 0x1015e189 MxU16 MXIOINFO::Open(const char* p_filename, MxULong p_flags) { - OFSTRUCT unused; + // [library:filesystem] p_flags is always 0 (OF_READ) + assert(p_flags == 0); + MxU16 result = 0; m_info.lDiskOffset = m_info.lBufOffset = 0; - // DECOMP: Cast of p_flags to u16 forces the `movzx` instruction - // original: m_info.hmmio = OpenFile(p_filename, &unused, (MxU16) p_flags); - ASSIGN_M_FILE(OpenFile(p_filename, &unused, (MxU16) p_flags)); + MxString path(p_filename); + path.NormalizePath(); + ASSIGN_M_FILE(SDL_IOFromFile(path.GetData(), "rb")); - if (M_FILE != HFILE_ERROR) { + if (M_FILE != NULL) { m_info.dwFlags = p_flags; if (m_info.dwFlags & MMIO_ALLOCBUF) { // Default buffer length of 8k if none specified - MxLong len = m_info.cchBuffer; + Sint64 len = m_info.cchBuffer; if (len == 0) { len = 8192; } @@ -66,7 +64,7 @@ MxU16 MXIOINFO::Open(const char* p_filename, MxULong p_flags) } else { m_info.cchBuffer = len; - m_info.pchBuffer = (HPSTR) buf; + m_info.pchBuffer = buf; } m_info.pchNext = m_info.pchEndRead = m_info.pchBuffer; @@ -88,7 +86,7 @@ MxU16 MXIOINFO::Close(MxLong p_unused) if (RAW_M_FILE) { result = Flush(0); - _lclose(M_FILE); + SDL_CloseIO(M_FILE); ASSIGN_M_FILE(0); if (m_info.dwFlags & MMIO_ALLOCBUF) { @@ -106,11 +104,11 @@ MxU16 MXIOINFO::Close(MxLong p_unused) // FUNCTION: BETA10 0x1015e3b2 MxLong MXIOINFO::Read(void* p_buf, MxLong p_len) { - MxLong bytesRead = 0; + Sint64 bytesRead = 0; if (m_info.pchBuffer) { - MxLong bytesLeft = m_info.pchEndRead - m_info.pchNext; + Sint64 bytesLeft = m_info.pchEndRead - m_info.pchNext; while (p_len > 0) { if (bytesLeft > 0) { @@ -139,11 +137,11 @@ MxLong MXIOINFO::Read(void* p_buf, MxLong p_len) } } else if (RAW_M_FILE && p_len > 0) { - bytesRead = _hread(M_FILE, p_buf, p_len); + bytesRead = SDL_ReadIO(M_FILE, p_buf, p_len); - if (bytesRead == -1) { + if (SDL_GetIOStatus(M_FILE) == SDL_IO_STATUS_ERROR) { bytesRead = 0; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { m_info.lDiskOffset += bytesRead; @@ -156,11 +154,11 @@ MxLong MXIOINFO::Read(void* p_buf, MxLong p_len) // FUNCTION: BETA10 0x1015e4fc MxLong MXIOINFO::Write(void* p_buf, MxLong p_len) { - MxLong bytesWritten = 0; + Sint64 bytesWritten = 0; if (m_info.pchBuffer) { - MxLong bytesLeft = m_info.pchEndWrite - m_info.pchNext; + Sint64 bytesLeft = m_info.pchEndWrite - m_info.pchNext; while (p_len > 0) { if (bytesLeft > 0) { @@ -192,11 +190,11 @@ MxLong MXIOINFO::Write(void* p_buf, MxLong p_len) } } else if (RAW_M_FILE && p_len > 0) { - bytesWritten = _hwrite(M_FILE, (const char*) p_buf, p_len); + bytesWritten = SDL_WriteIO(M_FILE, p_buf, p_len); - if (bytesWritten == -1) { + if (SDL_GetIOStatus(M_FILE) == SDL_IO_STATUS_ERROR) { bytesWritten = 0; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { m_info.lDiskOffset += bytesWritten; @@ -212,30 +210,30 @@ MxLong MXIOINFO::Write(void* p_buf, MxLong p_len) // FUNCTION: LEGO1 0x100cca00 // FUNCTION: BETA10 0x1015e6c4 -MxLong MXIOINFO::Seek(MxLong p_offset, MxLong p_origin) +MxLong MXIOINFO::Seek(MxLong p_offset, SDL_IOWhence p_origin) { MxLong result = -1; - MxLong bytesRead; + Sint64 bytesRead; // If buffered I/O if (m_info.pchBuffer) { - if (p_origin == SEEK_CUR) { + if (p_origin == SDL_IO_SEEK_CUR) { if (!p_offset) { // don't seek at all and just return where we are. return m_info.lBufOffset + (m_info.pchNext - m_info.pchBuffer); } - // With SEEK_CUR, p_offset is a relative offset. - // Get the absolute position instead and use SEEK_SET. + // With SDL_IO_SEEK_CUR, p_offset is a relative offset. + // Get the absolute position instead and use SDL_IO_SEEK_SET. p_offset += m_info.lBufOffset + (m_info.pchNext - m_info.pchBuffer); - p_origin = SEEK_SET; + p_origin = SDL_IO_SEEK_SET; } - else if (p_origin == SEEK_END) { + else if (p_origin == SDL_IO_SEEK_END) { // not possible with buffered I/O return -1; } - // else p_origin == SEEK_SET. + // else p_origin == SDL_IO_SEEK_SET. // is p_offset between the start and end of the buffer? // i.e. can we do the seek without reading more from disk? @@ -246,10 +244,10 @@ MxLong MXIOINFO::Seek(MxLong p_offset, MxLong p_origin) else { // we have to read another chunk from disk. if (RAW_M_FILE && !Flush(0)) { - m_info.lDiskOffset = _llseek(M_FILE, p_offset, p_origin); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, p_offset, p_origin); if (m_info.lDiskOffset == -1) { - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { @@ -259,10 +257,10 @@ MxLong MXIOINFO::Seek(MxLong p_offset, MxLong p_origin) // do we need to seek again? // (i.e. are we already aligned to buffer size?) if (p_offset != m_info.lBufOffset) { - m_info.lDiskOffset = _llseek(M_FILE, m_info.lBufOffset, SEEK_SET); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, m_info.lBufOffset, SDL_IO_SEEK_SET); if (m_info.lDiskOffset == -1) { - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } } @@ -270,10 +268,10 @@ MxLong MXIOINFO::Seek(MxLong p_offset, MxLong p_origin) // is the file open for writing only? if ((m_info.dwFlags & MMIO_RWMODE) == 0 || (m_info.dwFlags & MMIO_RWMODE) == MMIO_READWRITE) { // We can read from the file. Fill the buffer. - bytesRead = _hread(M_FILE, m_info.pchBuffer, m_info.cchBuffer); + bytesRead = SDL_ReadIO(M_FILE, m_info.pchBuffer, m_info.cchBuffer); - if (bytesRead == -1) { - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + if (SDL_GetIOStatus(M_FILE) == SDL_IO_STATUS_ERROR) { + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { m_info.lDiskOffset += bytesRead; @@ -297,16 +295,16 @@ MxLong MXIOINFO::Seek(MxLong p_offset, MxLong p_origin) else if (RAW_M_FILE) { // No buffer so just seek the file directly (if we have a valid handle) // i.e. if we just want to get the current file position - if (p_origin == SEEK_CUR && p_offset == 0) { + if (p_origin == SDL_IO_SEEK_CUR && p_offset == 0) { return m_info.lDiskOffset; } - m_info.lDiskOffset = _llseek(M_FILE, p_offset, p_origin); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, p_offset, p_origin); result = m_info.lDiskOffset; if (result == -1) { - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } } @@ -338,7 +336,7 @@ MxU16 MXIOINFO::SetBuffer(char* p_buf, MxLong p_len, MxLong p_unused) MxU16 MXIOINFO::Flush(MxU16 p_unused) { MxU16 result = 0; - MxLong bytesWritten; + Sint64 bytesWritten; // if buffer is dirty if (m_info.dwFlags & MMIO_DIRTY) { @@ -350,20 +348,20 @@ MxU16 MXIOINFO::Flush(MxU16 p_unused) MxLong cchBuffer = m_info.cchBuffer; if (cchBuffer > 0) { if (m_info.lBufOffset != m_info.lDiskOffset) { - m_info.lDiskOffset = _llseek(M_FILE, m_info.lBufOffset, SEEK_SET); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, m_info.lBufOffset, SDL_IO_SEEK_SET); } // Was the previous seek (if required) successful? if (m_info.lBufOffset != m_info.lDiskOffset) { result = MMIOERR_CANNOTSEEK; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { - bytesWritten = _hwrite(M_FILE, m_info.pchBuffer, cchBuffer); + bytesWritten = SDL_WriteIO(M_FILE, m_info.pchBuffer, cchBuffer); - if (bytesWritten == -1 || bytesWritten != cchBuffer) { + if (SDL_GetIOStatus(M_FILE) == SDL_IO_STATUS_ERROR || bytesWritten != cchBuffer) { result = MMIOERR_CANNOTWRITE; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { m_info.lDiskOffset += bytesWritten; @@ -393,8 +391,8 @@ MxU16 MXIOINFO::Advance(MxU16 p_option) MxULong rwmode = m_info.dwFlags & MMIO_RWMODE; if (m_info.pchBuffer) { - MxLong cch = m_info.cchBuffer; - MxLong bytesCounter; + Sint64 cch = m_info.cchBuffer; + Sint64 bytesCounter; // If we can and should write to the file, // if we are being asked to write to the file, @@ -403,19 +401,19 @@ MxU16 MXIOINFO::Advance(MxU16 p_option) ((p_option & MMIO_WRITE) || (rwmode == MMIO_READWRITE)) && cch > 0) { if (m_info.lBufOffset != m_info.lDiskOffset) { - m_info.lDiskOffset = _llseek(M_FILE, m_info.lBufOffset, SEEK_SET); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, m_info.lBufOffset, SDL_IO_SEEK_SET); } if (m_info.lBufOffset != m_info.lDiskOffset) { result = MMIOERR_CANNOTSEEK; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { - bytesCounter = _hwrite(M_FILE, m_info.pchBuffer, cch); + bytesCounter = SDL_WriteIO(M_FILE, m_info.pchBuffer, cch); - if (bytesCounter == -1 || bytesCounter != cch) { + if (SDL_GetIOStatus(M_FILE) == SDL_IO_STATUS_ERROR || bytesCounter != cch) { result = MMIOERR_CANNOTWRITE; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { m_info.lDiskOffset += bytesCounter; @@ -429,20 +427,20 @@ MxU16 MXIOINFO::Advance(MxU16 p_option) m_info.lBufOffset += cch; if ((!rwmode || rwmode == MMIO_READWRITE) && cch > 0) { if (m_info.lBufOffset != m_info.lDiskOffset) { - m_info.lDiskOffset = _llseek(M_FILE, m_info.lBufOffset, SEEK_SET); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, m_info.lBufOffset, SDL_IO_SEEK_SET); } // if previous seek failed if (m_info.lBufOffset != m_info.lDiskOffset) { result = MMIOERR_CANNOTSEEK; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { - bytesCounter = _hread(M_FILE, m_info.pchBuffer, cch); + bytesCounter = SDL_ReadIO(M_FILE, m_info.pchBuffer, cch); - if (bytesCounter == -1) { + if (SDL_GetIOStatus(M_FILE) == SDL_IO_STATUS_ERROR) { result = MMIOERR_CANNOTREAD; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { m_info.lDiskOffset += bytesCounter; @@ -461,11 +459,11 @@ MxU16 MXIOINFO::Advance(MxU16 p_option) // FUNCTION: LEGO1 0x100cce60 // FUNCTION: BETA10 0x1015edef -MxU16 MXIOINFO::Descend(MMCKINFO* p_chunkInfo, const MMCKINFO* p_parentInfo, MxU16 p_descend) +MxU16 MXIOINFO::Descend(ISLE_MMCKINFO* p_chunkInfo, const ISLE_MMCKINFO* p_parentInfo, MxU16 p_descend) { MxU16 result = 0; MxULong ofs; - BOOL readOk; + MxU32 readOk; if (!p_chunkInfo) { return MMIOERR_BASE; // ? @@ -491,15 +489,15 @@ MxU16 MXIOINFO::Descend(MMCKINFO* p_chunkInfo, const MMCKINFO* p_parentInfo, MxU } } else { - ofs = MAXLONG; + ofs = LONG_MAX; if (p_parentInfo) { ofs = p_parentInfo->cksize + p_parentInfo->dwDataOffset; } - BOOL running = TRUE; + MxU32 running = TRUE; readOk = FALSE; - MMCKINFO tmp; + ISLE_MMCKINFO tmp; tmp.dwFlags = 0; while (running) { @@ -533,7 +531,7 @@ MxU16 MXIOINFO::Descend(MMCKINFO* p_chunkInfo, const MMCKINFO* p_parentInfo, MxU else if (p_chunkInfo->ckid == tmp.ckid) { running = FALSE; } - else if (Seek((tmp.cksize & 1) + tmp.cksize, SEEK_CUR) == -1) { + else if (Seek((tmp.cksize & 1) + tmp.cksize, SDL_IO_SEEK_CUR) == -1) { result = MMIOERR_CANNOTSEEK; running = FALSE; } @@ -550,7 +548,7 @@ MxU16 MXIOINFO::Descend(MMCKINFO* p_chunkInfo, const MMCKINFO* p_parentInfo, MxU } // FUNCTION: BETA10 0x1015f08b -MxU16 MXIOINFO::Ascend(MMCKINFO* p_chunkInfo, MxU16 p_ascend) +MxU16 MXIOINFO::Ascend(ISLE_MMCKINFO* p_chunkInfo, MxU16 p_ascend) { MxLong ofs; MxULong size; @@ -585,11 +583,11 @@ MxU16 MXIOINFO::Ascend(MMCKINFO* p_chunkInfo, MxU16 p_ascend) m_info.dwFlags |= MMIO_DIRTY; } else { - m_info.lDiskOffset = _llseek(M_FILE, ofs, SEEK_SET); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, ofs, SDL_IO_SEEK_SET); if (m_info.lDiskOffset == ofs) { - if (_lwrite(M_FILE, (char*) &size, 4) != 4) { - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + if (SDL_WriteIO(M_FILE, (char*) &size, 4) != 4) { + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); result = MMIOERR_CANNOTWRITE; } else { @@ -597,7 +595,7 @@ MxU16 MXIOINFO::Ascend(MMCKINFO* p_chunkInfo, MxU16 p_ascend) } } else { - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); result = MMIOERR_CANNOTSEEK; } } @@ -606,7 +604,7 @@ MxU16 MXIOINFO::Ascend(MMCKINFO* p_chunkInfo, MxU16 p_ascend) // Seek past the end of the chunk (plus optional pad byte if size is odd) if (result == 0 && - Seek((p_chunkInfo->cksize & 1) + p_chunkInfo->cksize + p_chunkInfo->dwDataOffset, SEEK_SET) == -1) { + Seek((p_chunkInfo->cksize & 1) + p_chunkInfo->cksize + p_chunkInfo->dwDataOffset, SDL_IO_SEEK_SET) == -1) { result = MMIOERR_CANNOTSEEK; } diff --git a/README.md b/README.md index 4c4874fd..0293a4a3 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ To achieve our goal of platform independence, we need to replace any Windows-onl | - | - | - | - | | Window, Events | [SDL3](https://www.libsdl.org/) | WIP | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Awindow%5D%22&type=code) | | Windows Registry (Configuration) | [libiniparser](https://github.com/ndevilla/iniparser) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aconfig%5D%22&type=code) | -| Filesystem | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Afilesystem%5D%22&type=code) | +| Filesystem | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Afilesystem%5D%22&type=code) | | Threads, Mutexes (Synchronization) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Asynchronization%5D%22&type=code) | | Keyboard/Mouse, DirectInput (Input) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%5D%22&type=code) | | Joystick/Gamepad, DirectInput (Input) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%5D%22&type=code) | diff --git a/tools/ncc/skip.yml b/tools/ncc/skip.yml index 4f39ddc8..e988db5e 100644 --- a/tools/ncc/skip.yml +++ b/tools/ncc/skip.yml @@ -53,3 +53,21 @@ m_Decals_Ctl5: "Allow original naming from beta" m_Decals_Ctl6: "Allow original naming from beta" m_Decals_Ctl7: "Allow original naming from beta" p_scorehist: "Allow original naming from beta" + +ISLE_MMIOINFO: "Re-defined Windows name" +_ISLE_MMIOINFO: "Re-defined Windows name" +dwFlags: "Re-defined Windows name" +cchBuffer: "Re-defined Windows name" +pchBuffer: "Re-defined Windows name" +pchNext: "Re-defined Windows name" +pchEndRead: "Re-defined Windows name" +pchEndWrite: "Re-defined Windows name" +lBufOffset: "Re-defined Windows name" +lDiskOffset: "Re-defined Windows name" +ISLE_MMCKINFO: "Re-defined Windows name" +_ISLE_MMCKINFO: "Re-defined Windows name" +ckid: "Re-defined Windows name" +cksize: "Re-defined Windows name" +fccType: "Re-defined Windows name" +dwDataOffset: "Re-defined Windows name" +fccType: "Re-defined Windows name" \ No newline at end of file