Compare commits
No commits in common. "eeb69fe0dfce87bf10223f19fcd14a049c07d1f1" and "582b2a1933e0c87935479688256a79aa42343aeb" have entirely different histories.
eeb69fe0df
...
582b2a1933
|
@ -1,6 +1,3 @@
|
||||||
# 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
|
||||||
|
@ -23,6 +20,9 @@ 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
7
LICENSE
|
@ -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.
|
|
21
README.md
21
README.md
|
@ -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.
|
|
53
bolt.hexpat
53
bolt.hexpat
|
@ -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] @ $;
|
|
|
@ -1,6 +1,3 @@
|
||||||
# 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.
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
# 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})
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
# Copyright 2023 The LightningBolt Authors
|
|
||||||
# SPDX-License-Identifier: MIT
|
|
||||||
add_library(lb_base
|
add_library(lb_base
|
||||||
MmapFile.cpp
|
MmapFile.cpp
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
// Copyright 2023 The LightningBolt Authors
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
// Copyright 2023 The LightningBolt Authors
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
#include <base/MmapFile.hpp>
|
#include <base/MmapFile.hpp>
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
// 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>
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
// 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>
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
// 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>
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
// Copyright 2023 The LightningBolt Authors
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
//! Core types and includes
|
//! Core types and includes
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
// 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>
|
||||||
|
|
118
src/main.cpp
118
src/main.cpp
|
@ -1,6 +1,3 @@
|
||||||
// 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>
|
||||||
|
@ -8,51 +5,48 @@
|
||||||
#include <structs/BoltStructs.hpp>
|
#include <structs/BoltStructs.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <fstream>
|
std::vector<u8> BoltDecompress(std::span<u8> data) {
|
||||||
|
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;
|
||||||
|
|
||||||
res.resize(decompressedSize);
|
i32 iVar3;
|
||||||
|
i32 iVar6;
|
||||||
|
u32 uVar5;
|
||||||
|
u32 pbVar4; // outrun
|
||||||
|
|
||||||
u8* pOut = res.data();
|
for(u32 i = 0; i < data.size(); ++i) {
|
||||||
u8* pEnd = res.data() + decompressedSize;
|
auto uVar7 = inptr[i];
|
||||||
|
|
||||||
i32 iVar3 = 0;
|
if(uVar7 < 128) {
|
||||||
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 = pOut + -(iVar6 * 0x10 + (uVar7 & 0xf) + 1);
|
pbVar4 = -(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(bVar1);
|
} while(iVar6 != 0);
|
||||||
}
|
}
|
||||||
iVar6 = 0;
|
iVar6 = 0;
|
||||||
iVar3 = 0;
|
iVar3 = 0;
|
||||||
uVar5 = 0;
|
uVar5 = 0;
|
||||||
} else if(uVar7 < 144) { // literal copy from stream
|
} else if(uVar7 < 144) {
|
||||||
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 = *inptr++;
|
//*pOut = *pbRam00590aa8;
|
||||||
pOut = pOut + 1;
|
// pOut = pOut + 1;
|
||||||
|
// pbRam00590aa8 = pbRam00590aa8 + 1;
|
||||||
|
// iRam00590ab0 = iRam00590ab0 + -1;
|
||||||
|
// if(iRam00590ab0 == 0) {
|
||||||
|
// NextBlock();
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
iVar3 = 0;
|
iVar3 = 0;
|
||||||
uVar5 = 0;
|
uVar5 = 0;
|
||||||
|
@ -78,26 +72,12 @@ struct BoltReader {
|
||||||
u16 index;
|
u16 index;
|
||||||
u16 gid;
|
u16 gid;
|
||||||
|
|
||||||
bool compressed;
|
std::span<u8> uncompressedData;
|
||||||
|
|
||||||
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 fs::path& path) {
|
ErrorOr<void> OpenBolt(const lightningbolt::fs::path& path) {
|
||||||
auto p = path;
|
auto p = path;
|
||||||
p.replace_filename("SLUS_201.14");
|
p.replace_filename("SLUS_201.14");
|
||||||
|
|
||||||
|
@ -130,6 +110,7 @@ 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++;
|
||||||
|
@ -141,16 +122,13 @@ 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 == nullptr) {
|
if(file.uncompressedData.empty()) {
|
||||||
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.compressed = !(entries[file.index & 0x00ff].unk & 0x8);
|
file.uncompressedData = { std::bit_cast<u8*>(boltFile.GetMapping() + offset), size };
|
||||||
|
|
||||||
file.uncompressedData = std::bit_cast<u8*>(boltFile.GetMapping() + offset);
|
|
||||||
file.uncompressedSize = size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!f(file))
|
if(!f(file))
|
||||||
|
@ -168,41 +146,13 @@ struct BoltReader {
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
BoltReader reader;
|
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();
|
std::cout << "Error opening Bolt file: " << error.Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.ForEachFile([](BoltReader::ParsedTableEntry& ent) {
|
reader.ForEachFile([](BoltReader::ParsedTableEntry& ent) {
|
||||||
std::cout << std::format("File: {}", ent.filename);
|
std::cout << std::format("File: {} magic: ", ent.filename) << ent.uncompressedData[0] << ent.uncompressedData[1] << ent.uncompressedData[2]
|
||||||
|
<< 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;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue