Compare commits

..

No commits in common. "eeb69fe0dfce87bf10223f19fcd14a049c07d1f1" and "582b2a1933e0c87935479688256a79aa42343aeb" have entirely different histories.

16 changed files with 37 additions and 198 deletions

View File

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

View File

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

View File

@ -1,7 +0,0 @@
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.

View File

@ -1,21 +0,0 @@
# 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.

View File

@ -1,53 +0,0 @@
// 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,6 +1,3 @@
# Copyright 2023 The LightningBolt Authors
# SPDX-License-Identifier: MIT
# CMake policy configuration
# Macro to enable new CMake policy.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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