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

View File

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

View File

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