Skip to content

Commit

Permalink
Use macros for Seek modes (#1235)
Browse files Browse the repository at this point in the history
* Use macros for `Seek` modes

* Fix syntax

* Use `OF_READ`

* Add names to skip.yml

* Revert "Add names to skip.yml"

This reverts commit 28b6f57.
  • Loading branch information
foxtacles authored Dec 16, 2024
1 parent 615c3a5 commit cfa3769
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ MxResult LegoWorldPresenter::FUN_10067360(ModelDbPart& p_part, FILE* p_wdbFile)
MxResult result;
MxU8* buff = new MxU8[p_part.m_partDataLength];

fseek(p_wdbFile, p_part.m_partDataOffset, 0);
fseek(p_wdbFile, p_part.m_partDataOffset, SEEK_SET);
if (fread(buff, p_part.m_partDataLength, 1, p_wdbFile) != 1) {
return FAILURE;
}
Expand All @@ -344,7 +344,7 @@ MxResult LegoWorldPresenter::FUN_100674b0(ModelDbModel& p_model, FILE* p_wdbFile
{
MxU8* buff = new MxU8[p_model.m_unk0x04];

fseek(p_wdbFile, p_model.m_unk0x08, 0);
fseek(p_wdbFile, p_model.m_unk0x08, SEEK_SET);
if (fread(buff, p_model.m_unk0x04, 1, p_wdbFile) != 1) {
return FAILURE;
}
Expand Down
10 changes: 8 additions & 2 deletions LEGO1/modeldb/modeldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ MxResult ModelDbModel::Read(FILE* p_file)
if (fread(&m_up, sizeof(*m_up), 3, p_file) != 3) {
return FAILURE;
}
if (fread(&m_unk0x34, sizeof(m_unk0x34), 1, p_file) != 1) {
return FAILURE;
}

return fread(&m_unk0x34, sizeof(m_unk0x34), 1, p_file) == 1 ? SUCCESS : FAILURE;
return SUCCESS;
}

// FUNCTION: LEGO1 0x10027850
Expand All @@ -76,8 +79,11 @@ MxResult ModelDbPart::Read(FILE* p_file)
if (fread(&m_partDataLength, sizeof(m_partDataLength), 1, p_file) != 1) {
return FAILURE;
}
if (fread(&m_partDataOffset, sizeof(m_partDataOffset), 1, p_file) != 1) {
return FAILURE;
}

return fread(&m_partDataOffset, sizeof(m_partDataOffset), 1, p_file) == 1 ? SUCCESS : FAILURE;
return SUCCESS;
}

// FUNCTION: LEGO1 0x10027910
Expand Down
2 changes: 1 addition & 1 deletion LEGO1/omni/include/mxdsfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ 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, int) override; // vtable+0x24
MxResult Seek(MxLong, MxS32) override; // vtable+0x24
MxULong GetBufferSize() override; // vtable+0x28
MxULong GetStreamBuffersNum() override; // vtable+0x2c

Expand Down
2 changes: 1 addition & 1 deletion LEGO1/omni/include/mxdssource.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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, int) = 0; // vtable+0x24
virtual MxLong Seek(MxLong, MxS32) = 0; // vtable+0x24
virtual MxULong GetBufferSize() = 0; // vtable+0x28
virtual MxULong GetStreamBuffersNum() = 0; // vtable+0x2c
virtual MxLong GetLengthInDWords(); // vtable+0x30
Expand Down
4 changes: 2 additions & 2 deletions LEGO1/omni/src/common/mxutilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <assert.h>

// GLOBAL: LEGO1 0x101020e8
void (*g_omniUserMessage)(const char*, int) = NULL;
void (*g_omniUserMessage)(const char*, MxS32) = NULL;

// FUNCTION: LEGO1 0x100b6e10
MxBool GetRectIntersection(
Expand Down Expand Up @@ -166,7 +166,7 @@ MxDSObject* CreateStreamObject(MxDSFile* p_file, MxS16 p_ofs)
MxU8* buf;
_MMCKINFO tmpChunk;

if (p_file->Seek(((MxLong*) p_file->GetBuffer())[p_ofs], 0)) {
if (p_file->Seek(((MxLong*) p_file->GetBuffer())[p_ofs], SEEK_SET)) {
return NULL;
}

Expand Down
6 changes: 3 additions & 3 deletions LEGO1/omni/src/stream/mxdiskstreamprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ MxResult MxDiskStreamProvider::SetResourceToGet(MxStreamController* p_resource)

m_pFile = new MxDSFile(path.GetData(), 0);
if (m_pFile != NULL) {
if (m_pFile->Open(0) != 0) {
if (m_pFile->Open(OF_READ) != 0) {
path = MxString(MxOmni::GetCD()) + p_resource->GetAtom().GetInternal() + ".si";
m_pFile->SetFileName(path.GetData());

if (m_pFile->Open(0) != 0) {
if (m_pFile->Open(OF_READ) != 0) {
goto done;
}
}
Expand Down Expand Up @@ -245,7 +245,7 @@ void MxDiskStreamProvider::PerformWork()
buffer = streamingAction->GetUnknowna0();

if (m_pFile->GetPosition() == streamingAction->GetBufferOffset() ||
m_pFile->Seek(streamingAction->GetBufferOffset(), 0) == 0) {
m_pFile->Seek(streamingAction->GetBufferOffset(), SEEK_SET) == 0) {
buffer->SetUnknown14(m_pFile->GetPosition());

if (m_pFile->ReadToBuffer(buffer) == SUCCESS) {
Expand Down
2 changes: 1 addition & 1 deletion LEGO1/omni/src/stream/mxdsfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ MxResult MxDSFile::Open(MxULong p_uStyle)
Close();
}
else {
Seek(0, 0);
Seek(0, SEEK_SET);
}

return result;
Expand Down
4 changes: 2 additions & 2 deletions LEGO1/omni/src/stream/mxramstreamprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ MxResult MxRAMStreamProvider::SetResourceToGet(MxStreamController* p_resource)

m_pFile = new MxDSFile(path.GetData(), 0);
if (m_pFile != NULL) {
if (m_pFile->Open(0) != 0) {
if (m_pFile->Open(OF_READ) != 0) {
path = MxString(MxOmni::GetCD()) + p_resource->GetAtom().GetInternal() + ".si";
m_pFile->SetFileName(path.GetData());

if (m_pFile->Open(0) != 0) {
if (m_pFile->Open(OF_READ) != 0) {
goto done;
}
}
Expand Down

0 comments on commit cfa3769

Please sign in to comment.