Compare commits

...

2 Commits

Author SHA1 Message Date
Lily Tsuru eeb69fe0df License project as open-source under the MIT license
This commit also adds a README with build and usage instructions.
2023-11-19 20:21:56 -05:00
Lily Tsuru 35cabf05da working decompression and extraction 2023-11-19 20:14:08 -05:00
16 changed files with 198 additions and 37 deletions

1
AUTHORS Normal file
View File

@ -0,0 +1 @@
Lily Tsuru <lily@crustywindo.ws>

View File

@ -1,3 +1,6 @@
# Copyright 2023 The LightningBolt Authors
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project(lightningbolt project(lightningbolt
@ -20,9 +23,6 @@ lb_set_alternate_linker()
add_subdirectory(lib/base) add_subdirectory(lib/base)
# third party vendor dependencies
#add_subdirectory(third_party)
add_executable(lightningbolt add_executable(lightningbolt
src/main.cpp src/main.cpp
) )

7
LICENSE Normal file
View File

@ -0,0 +1,7 @@
Copyright 2023 The LightningBolt Developers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# LightningBolt
A (only semi-WIP) extractor for The Simpsons Skateboarding BOLT archive files.
Currently only works with US copies.
# Building
You need:
- CMake
- A C++20 compiler (clang/gcc, MSVC won't work on Windows, you need clang-cl)
```bash
$ cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release
$ cmake --build build
```
# Using
Run `lightningbolt` where both the game executable and ASSETS.BLT reside.

53
bolt.hexpat Normal file
View File

@ -0,0 +1,53 @@
// Copyright 2023 The LightningBolt Authors
// SPDX-License-Identifier: MIT
struct BoltHdr {
char magic[6]; // BOLT\r\n
// have no idea what these are yet
u8 unk2;
u8 unk3;
// or these, they don't seem to be
// directly referenced by bolt stuff
u8 unk5;
u8 unk6;
u8 unk7;
u8 groupCount;
// in bytes
u32 libSize;
};
struct BoltGroupEnt {
u32 unk;
u32 fileSize;
u32 fileOffset;
u32 unk3;
u8 fileData[4] @ fileOffset;
};
struct BoltGroupDesc {
// flags?
u8 unk;
u8 unk2;
u8 unk3;
u8 groupEntCount;
// in bytes
u32 groupSize;
u32 groupOffset;
// ptr padding for ps2 code
u32 resolvedptr;
if(groupEntCount == 0)
BoltGroupEnt groupEntries[0x100] @ groupOffset;
else
BoltGroupEnt groupEntries[groupEntCount] @ groupOffset;
};
BoltHdr hdr @0;
BoltGroupDesc groupDescs[hdr.groupCount] @ $;

View File

@ -1,3 +1,6 @@
# Copyright 2023 The LightningBolt Authors
# SPDX-License-Identifier: MIT
# CMake policy configuration # CMake policy configuration
# Macro to enable new CMake policy. # Macro to enable new CMake policy.

View File

@ -1,3 +1,6 @@
# Copyright 2023 The LightningBolt Authors
# SPDX-License-Identifier: MIT
function(lb_target target) function(lb_target target)
target_compile_definitions(${target} PRIVATE "$<$<CONFIG:DEBUG>:LIGHTNINGBOLT_DEBUG>") target_compile_definitions(${target} PRIVATE "$<$<CONFIG:DEBUG>:LIGHTNINGBOLT_DEBUG>")
#target_include_directories(${target} PRIVATE ${PROJECT_SOURCE_DIR}) #target_include_directories(${target} PRIVATE ${PROJECT_SOURCE_DIR})

View File

@ -1,3 +1,5 @@
# Copyright 2023 The LightningBolt Authors
# SPDX-License-Identifier: MIT
add_library(lb_base add_library(lb_base
MmapFile.cpp MmapFile.cpp
) )

View File

@ -1,3 +1,6 @@
// Copyright 2023 The LightningBolt Authors
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <optional> #include <optional>
#include <system_error> #include <system_error>

View File

@ -1,3 +1,6 @@
// Copyright 2023 The LightningBolt Authors
// SPDX-License-Identifier: MIT
#include <base/MmapFile.hpp> #include <base/MmapFile.hpp>
#ifdef __linux__ #ifdef __linux__

View File

@ -1,3 +1,6 @@
// Copyright 2023 The LightningBolt Authors
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <base/Types.hpp> #include <base/Types.hpp>
#include <base/ErrorOr.hpp> #include <base/ErrorOr.hpp>

View File

@ -1,3 +1,6 @@
// Copyright 2023 The LightningBolt Authors
// SPDX-License-Identifier: MIT
#include "MmapFile.hpp" #include "MmapFile.hpp"
#include <fcntl.h> #include <fcntl.h>
#include <sys/file.h> #include <sys/file.h>

View File

@ -1,3 +1,6 @@
// Copyright 2023 The LightningBolt Authors
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <bit> #include <bit>
#include <base/Types.hpp> #include <base/Types.hpp>

View File

@ -1,3 +1,6 @@
// Copyright 2023 The LightningBolt Authors
// SPDX-License-Identifier: MIT
//! Core types and includes //! Core types and includes
#pragma once #pragma once

View File

@ -1,3 +1,6 @@
// Copyright 2023 The LightningBolt Authors
// SPDX-License-Identifier: MIT
#include <base/Types.hpp> #include <base/Types.hpp>
#include <cstring> #include <cstring>
#include <span> #include <span>

View File

@ -1,3 +1,6 @@
// Copyright 2023 The LightningBolt Authors
// SPDX-License-Identifier: MIT
#include <base/MmapFile.hpp> #include <base/MmapFile.hpp>
#include <filesystem> #include <filesystem>
#include <format> #include <format>
@ -5,48 +8,51 @@
#include <structs/BoltStructs.hpp> #include <structs/BoltStructs.hpp>
#include <vector> #include <vector>
std::vector<u8> BoltDecompress(std::span<u8> data) { #include <fstream>
u8* inptr = data.data();
namespace fs = std::filesystem;
std::vector<u8> BoltDecompress(u8* input, usize decompressedSize) {
u8* inptr = input;
std::vector<u8> res; std::vector<u8> res;
i32 iVar3; res.resize(decompressedSize);
i32 iVar6;
u32 uVar5;
u32 pbVar4; // outrun
for(u32 i = 0; i < data.size(); ++i) { u8* pOut = res.data();
auto uVar7 = inptr[i]; u8* pEnd = res.data() + decompressedSize;
if(uVar7 < 128) { i32 iVar3 = 0;
i32 iVar6 = 0;
u32 uVar5 = 0;
u8* pbVar4 = nullptr; // outrun
bool bVar1;
while(pOut < pEnd) {
auto uVar7 = *inptr++;
if(uVar7 < 128) { // lookback/run?
iVar3 = iVar3 + uVar5 * 8 + ((int)(uVar7 & 0x70) >> 4); iVar3 = iVar3 + uVar5 * 8 + ((int)(uVar7 & 0x70) >> 4);
pbVar4 = -(iVar6 * 0x10 + (uVar7 & 0xf) + 1); pbVar4 = pOut + -(iVar6 * 0x10 + (uVar7 & 0xf) + 1);
iVar6 = iVar3 + 1; iVar6 = iVar3 + 1;
if(iVar3 != -2) { if(iVar3 != -2) {
do { do {
//*pOut = *pbVar4; *pOut = *pbVar4;
pbVar4 = pbVar4 + 1; pbVar4 = pbVar4 + 1;
//bVar1 = iVar6 != 0; bVar1 = iVar6 != 0;
// pOut = pOut + 1; pOut = pOut + 1;
iVar6 = iVar6 + -1; iVar6 = iVar6 + -1;
} while(iVar6 != 0); } while(bVar1);
} }
iVar6 = 0; iVar6 = 0;
iVar3 = 0; iVar3 = 0;
uVar5 = 0; uVar5 = 0;
} else if(uVar7 < 144) { } else if(uVar7 < 144) { // literal copy from stream
iVar3 = uVar5 * 0x10 + (uVar7 & 0xf) + 1; iVar3 = uVar5 * 0x10 + (uVar7 & 0xf) + 1;
while(iVar3 != 0) { while(iVar3 != 0) {
iVar3 = iVar3 + -1; iVar3 = iVar3 + -1;
//*pOut = *pbRam00590aa8; *pOut = *inptr++;
// pOut = pOut + 1; pOut = pOut + 1;
// pbRam00590aa8 = pbRam00590aa8 + 1;
// iRam00590ab0 = iRam00590ab0 + -1;
// if(iRam00590ab0 == 0) {
// NextBlock();
//}
} }
iVar3 = 0; iVar3 = 0;
uVar5 = 0; uVar5 = 0;
@ -72,12 +78,26 @@ struct BoltReader {
u16 index; u16 index;
u16 gid; u16 gid;
std::span<u8> uncompressedData; bool compressed;
u8* uncompressedData { nullptr };
usize uncompressedSize;
fs::path pathify() {
// Create a mutable copy of the filename
std::string s = { filename.data(), filename.size() };
for(auto& c : s)
if(c == '\\')
c = '/';
return fs::current_path() / "ASSETS" / fs::path(s);
}
}; };
BoltReader() {} BoltReader() {}
ErrorOr<void> OpenBolt(const lightningbolt::fs::path& path) { ErrorOr<void> OpenBolt(const fs::path& path) {
auto p = path; auto p = path;
p.replace_filename("SLUS_201.14"); p.replace_filename("SLUS_201.14");
@ -110,7 +130,6 @@ struct BoltReader {
if(te.filename == "") if(te.filename == "")
break; break;
// std::cout << std::format("te: {} {:04x} {:04x}\n", te.filename, te.index, te.gid);
entryTable.emplace_back(te); entryTable.emplace_back(te);
table++; table++;
@ -122,13 +141,16 @@ struct BoltReader {
template <class F> template <class F>
void ForEachFile(F f) { void ForEachFile(F f) {
for(auto& file : entryTable) { for(auto& file : entryTable) {
if(file.uncompressedData.empty()) { if(file.uncompressedData == nullptr) {
auto gid = (file.gid >> 8); auto gid = (file.gid >> 8);
auto entries = lib->GroupDescriptors()[gid].Entries(boltFile.GetMapping()); auto entries = lib->GroupDescriptors()[gid].Entries(boltFile.GetMapping());
auto size = entries[file.index & 0x00ff].fileSize; auto size = entries[file.index & 0x00ff].fileSize;
auto offset = entries[file.index & 0x00ff].fileOffset; auto offset = entries[file.index & 0x00ff].fileOffset;
file.uncompressedData = { std::bit_cast<u8*>(boltFile.GetMapping() + offset), size }; file.compressed = !(entries[file.index & 0x00ff].unk & 0x8);
file.uncompressedData = std::bit_cast<u8*>(boltFile.GetMapping() + offset);
file.uncompressedSize = size;
} }
if(!f(file)) if(!f(file))
@ -146,13 +168,41 @@ struct BoltReader {
int main() { int main() {
BoltReader reader; BoltReader reader;
if(auto error = reader.OpenBolt(lightningbolt::fs::current_path() / "ASSETS.BLT"); error.HasError()) { if(auto error = reader.OpenBolt(fs::current_path() / "ASSETS.BLT"); error.HasError()) {
std::cout << "Error opening Bolt file: " << error.Error(); std::cout << "Error opening Bolt file: " << error.Error();
} }
reader.ForEachFile([](BoltReader::ParsedTableEntry& ent) { reader.ForEachFile([](BoltReader::ParsedTableEntry& ent) {
std::cout << std::format("File: {} magic: ", ent.filename) << ent.uncompressedData[0] << ent.uncompressedData[1] << ent.uncompressedData[2] std::cout << std::format("File: {}", ent.filename);
<< ent.uncompressedData[3] << '\n';
auto p = ent.pathify();
auto pathonly = p;
pathonly.remove_filename();
if(!fs::exists(pathonly))
fs::create_directories(pathonly);
std::ofstream ofs(p.string(), std::ofstream::binary);
if(!ofs) {
std::cout << "... : Could not open " << p.string() << " for writing\n";
return false;
}
if(ent.compressed) {
std::cout << std::format(", compressed ({} bytes uncompressed)", ent.uncompressedSize);
auto decompressed = BoltDecompress(ent.uncompressedData, ent.uncompressedSize);
ofs.write((char*)decompressed.data(), ent.uncompressedSize);
std::cout << std::format(", written to \"{}\"\n", p.string());
} else {
std::cout << std::format(", uncompressed ({} bytes)", ent.uncompressedSize);
ofs.write((char*)ent.uncompressedData, ent.uncompressedSize);
std::cout << std::format(", written to \"{}\"\n", p.string());
}
return true; return true;
}); });