bolt: Table lookup only done with Simpsons Skateboarding

This commit is contained in:
Lily Tsuru 2023-11-21 20:33:26 -05:00
parent c92a61d633
commit 0bce5917f3
3 changed files with 36 additions and 27 deletions

View File

@ -2,12 +2,12 @@
#include <base/MmapFile.hpp>
#include <bolt/Reader.hpp>
#include <structs/BoltStructs.hpp>
namespace lightningbolt {
struct BoltReader::Impl {
Impl(Game game) : game(game) {}
ErrorOr<void> OpenBolt(const fs::path& path) {
// Load the BOLT file
@ -19,36 +19,40 @@ namespace lightningbolt {
if(!lib->Validate())
return std::make_error_code(BoltErrc::InvalidMagic);
auto p = path;
p.replace_filename("SLUS_201.14");
if(game == Game::SimpsonsSkateboarding) {
auto p = path;
p.replace_filename("SLUS_201.14");
if(auto error = elfFile.Open(p); error.HasError())
return error;
if(auto error = elfFile.Open(p); error.HasError())
return error;
// Load table entries.
GetTableEntries();
// Load table entries.
GetTableEntries();
}
return {};
}
const std::vector<BoltReader::File>& GetTableEntries() {
if(entryTable.empty()) {
auto* base = elfFile.GetMapping();
auto* table = std::bit_cast<elf::BoltTableEntry*>(base + elf::BoltTableOffsets.usTable);
while(table->filenamePtr != 0x0) {
auto string_offset = elf::AddressToElfFileOffset(table->filenamePtr);
if(game == Game::SimpsonsSkateboarding) {
if(entryTable.empty()) {
auto* base = elfFile.GetMapping();
auto* table = std::bit_cast<elf::BoltTableEntry*>(base + elf::BoltTableOffsets.usTable);
while(table->filenamePtr != 0x0) {
auto string_offset = elf::AddressToElfFileOffset(table->filenamePtr);
BoltReader::File te;
te.filename = { std::bit_cast<char*>(base + string_offset) };
te.index = table->entryId;
te.gid = table->groupId;
BoltReader::File te;
te.filename = { std::bit_cast<char*>(base + string_offset) };
te.index = table->entryId;
te.gid = table->groupId;
if(te.filename == "")
break;
if(te.filename == "")
break;
entryTable.emplace_back(te);
entryTable.emplace_back(te);
table++;
table++;
}
}
}
return entryTable;
@ -75,6 +79,7 @@ namespace lightningbolt {
}
private:
Game game;
std::vector<BoltReader::File> entryTable;
MmapFile elfFile;
MmapFile boltFile;
@ -82,8 +87,8 @@ namespace lightningbolt {
BoltLibraryHeader* lib;
};
BoltReader::BoltReader():
impl(std::make_unique<Impl>()) {}
BoltReader::BoltReader(Game game) : impl(std::make_unique<Impl>(game)) {
}
BoltReader::~BoltReader() = default;
@ -92,9 +97,7 @@ namespace lightningbolt {
}
void BoltReader::ForEachFile(std::function<bool(File&)> f) {
impl->ForEachFile([&f](auto& file) {
return f(file);
});
impl->ForEachFile([&f](auto& file) { return f(file); });
}
} // namespace lightningbolt

View File

@ -6,6 +6,12 @@
namespace lightningbolt {
struct BoltReader {
enum class Game {
LooseBolt, ///< Use this for games with no bolt entry
SimpsonsSkateboarding,
NamcoMuseumGCN = LooseBolt
};
struct File {
std::string_view filename;
u16 index;
@ -15,10 +21,9 @@ namespace lightningbolt {
u8* uncompressedData { nullptr };
usize uncompressedSize;
};
BoltReader();
BoltReader(Game game = Game::SimpsonsSkateboarding);
~BoltReader();
ErrorOr<void> OpenBolt(const fs::path& path);

View File

@ -7,6 +7,7 @@
namespace lightningbolt {
/// Elf structures, only applicable to Simpsons Skateboarding
namespace elf {
/// Table entry in the ELF. We use this to create file names.