Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
build
build.ninja
compile_commands.json

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify where these files are coming from? I'm not sure if these need to be added to the .gitignore. Even if they should be added, I think this doesn't pertain to the scope of this PR

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zed forces clangd down your throat and this is the only way to prevent it :P if .vscode is gitignored then so should these really.

.cache/**
__pycache__
out
.vs
.vscode
.zed
*.szs
statusTestCases.json
.env
25 changes: 23 additions & 2 deletions source/game/system/GhostFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,29 @@ bool RawGhostFile::decompress(const u8 *rkg) {

/// @addr{0x8051C120}
/// @todo Check for valid controller type?
/// @todo Check lap times sum to race time?
bool RawGhostFile::isValid(const u8 *rkg) const {
if (strncmp(reinterpret_cast<const char *>(rkg), "RKGD", 4) != 0) {
PANIC("RKG header malformed");
return false;
}

u32 finalTime = RawGhostFile::readRKGTime(reinterpret_cast<const u8 *>(rkg + 0x4));
Comment thread
FallBackITA27 marked this conversation as resolved.
Outdated
u32 lapSum = 0;
for (u8 i = 0; i < 8; i++) {
Comment thread
FallBackITA27 marked this conversation as resolved.
Outdated
lapSum += RawGhostFile::readRKGTime(reinterpret_cast<const u8 *>(rkg + 0x11 + (i*3)));
Comment thread
FallBackITA27 marked this conversation as resolved.
Outdated
}

if (finalTime != lapSum) {
return false;
}

u32 ids = parse<u32>(*reinterpret_cast<const u32 *>(rkg + 0x8));
Vehicle vehicle = static_cast<Vehicle>(ids >> 0x1a);
Character character = static_cast<Character>((ids >> 0x14) & 0x3f);
u8 year = (ids >> 0xd) & 0x7f;
u8 day = (ids >> 0x4) & 0x1f;
u8 month = (ids >> 0x9) & 0xf;
u8 day = (ids >> 0x4) & 0x1f;
u8 controllerType = ids & 0b1111;
Comment thread
FallBackITA27 marked this conversation as resolved.
Outdated

if (vehicle >= Vehicle::Max || character >= Character::Max) {
return false;
Expand All @@ -163,6 +173,10 @@ bool RawGhostFile::isValid(const u8 *rkg) const {
if (year >= 100 || day >= 32 || month > 12) {
return false;
}

if (controllerType > 3) {
return false;
}

// Validate weight class match
WeightClass charWeight = CharacterToWeight(character);
Expand All @@ -181,6 +195,13 @@ bool RawGhostFile::isValid(const u8 *rkg) const {
return true;
}

u32 RawGhostFile::readRKGTime(const u8 *timeBytes) const {
u32 minutes = *timeBytes; // The minutes are doubled here
Comment thread
FallBackITA27 marked this conversation as resolved.
Outdated
u32 seconds = (*reinterpret_cast<const u8 *>(timeBytes + 1)) >> 2;
u32 milliseconds = parse<u16>(*reinterpret_cast<const u16 *>(timeBytes + 1)) & 0b1111111111;
return (minutes * 30000) + (seconds * 1000) + milliseconds;
}

const u8 *RawGhostFile::buffer() const {
return m_buffer;
}
Expand Down
1 change: 1 addition & 0 deletions source/game/system/GhostFile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public:

private:
[[nodiscard]] bool compressed(const u8 *rkg) const;
[[nodiscard]] u32 readRKGTime(const u8 *rkg) const;

u8 m_buffer[RKG_UNCOMPRESSED_FILE_SIZE];
};
Expand Down