-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from roblabla/pbg3-fixes
Pbg3 fixes
- Loading branch information
Showing
13 changed files
with
371 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[submodule "3rdparty/munit"] | ||
path = 3rdparty/munit | ||
url = https://github.com/roblabla/munit | ||
branch = msvc2002 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from pathlib import Path | ||
|
||
from build import BuildType, build | ||
from winhelpers import run_windows_program | ||
|
||
SCRIPTS_DIR = Path(__file__).parent | ||
|
||
|
||
def main(): | ||
# Run the build for tests | ||
build(BuildType.TESTS) | ||
|
||
# Then, run the tests | ||
run_windows_program( | ||
[SCRIPTS_DIR.parent / "build" / "th06e-tests.exe"], | ||
cwd=str(SCRIPTS_DIR.parent), | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include "IPbg3Parser.hpp" | ||
|
||
void IPbg3Parser::Reset() | ||
{ | ||
this->bitIdxInCurByte = 128; | ||
this->offsetInFile = 0; | ||
this->fileSize = 0; | ||
this->curByte = 0; | ||
this->crc = 0; | ||
} | ||
|
||
u32 IPbg3Parser::ReadVarInt() | ||
{ | ||
u32 res = 0; | ||
i32 varintHdr = 0; | ||
|
||
if (this->ReadBit()) | ||
{ | ||
varintHdr = 2; | ||
} | ||
if (this->ReadBit()) | ||
{ | ||
varintHdr |= 1; | ||
} | ||
|
||
u32 intLen; | ||
switch (varintHdr) | ||
{ | ||
case 0: | ||
intLen = 0x80; | ||
break; | ||
case 1: | ||
intLen = 0x8000; | ||
break; | ||
case 2: | ||
intLen = 0x800000; | ||
break; | ||
case 3: | ||
intLen = 0x80000000; | ||
break; | ||
default: | ||
// TODO: There's probably a way to match without goto, but | ||
// I can't figure it out... a simple `return 0;` won't share | ||
// the function epilogue with the other return res. | ||
goto end; | ||
} | ||
|
||
do | ||
{ | ||
if (this->ReadBit()) | ||
{ | ||
res |= intLen; | ||
} | ||
intLen >>= 1; | ||
} while (intLen != 0); | ||
end: | ||
return res; | ||
} | ||
|
||
u32 IPbg3Parser::ReadMagic() | ||
{ | ||
u32 b0 = this->ReadInt(8); | ||
u32 b1 = b0 + (this->ReadInt(8) << 8); | ||
u32 b2 = b1 + (this->ReadInt(8) << 16); | ||
u32 b3 = b2 + (this->ReadInt(8) << 24); | ||
|
||
return b3; | ||
} | ||
|
||
u32 IPbg3Parser::ReadString(char *out, u32 maxSize) | ||
{ | ||
if (out == NULL) | ||
return FALSE; | ||
|
||
for (u32 idx = 0; idx < maxSize; idx++) | ||
{ | ||
out[idx] = this->ReadInt(8); | ||
if (out[idx] == '\0') | ||
{ | ||
return TRUE; | ||
} | ||
} | ||
|
||
return FALSE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include "inttypes.hpp" | ||
#include <Windows.h> | ||
|
||
class IPbg3Parser | ||
{ | ||
public: | ||
IPbg3Parser() | ||
{ | ||
this->Reset(); | ||
} | ||
void Reset(); | ||
u32 ReadVarInt(); | ||
u32 ReadMagic(); | ||
u32 ReadString(char *out, u32 maxSize); | ||
virtual i32 ReadBit() = 0; | ||
virtual u32 ReadInt(u32 numBitsAsPowersOf2) = 0; | ||
virtual u8 ReadByteAssumeAligned() = 0; | ||
virtual i32 SeekToOffset(u32 fileOffset) = 0; | ||
virtual i32 SeekToNextByte() = 0; | ||
virtual i32 ReadByteAlignedData(u8 *data, u32 bytesToRead) = 0; | ||
virtual i32 GetLastWriteTime(LPFILETIME lastWriteTime) = 0; | ||
virtual ~IPbg3Parser() | ||
{ | ||
} | ||
|
||
protected: | ||
u32 offsetInFile; | ||
u32 fileSize; | ||
u32 curByte; | ||
u8 bitIdxInCurByte; | ||
u32 crc; | ||
}; |
Oops, something went wrong.