Created
February 14, 2025 21:29
-
-
Save LemonHaze420/0b0c5e009f299c19f6d73686bfcfa57b to your computer and use it in GitHub Desktop.
da_ghost_ridaaa.cpp for Ghost Rider 2002 (arc files)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LemonHaze - 2025 | |
#include <iostream> | |
#include <ostream> | |
#include <fstream> | |
#include <vector> | |
#include <zlib.h> | |
struct arc { | |
struct entry { | |
int a, b, c, size; | |
}; | |
struct header { | |
int a; | |
int num_entries; | |
int data_tbl_start; | |
int name_tbl_start; | |
} header; | |
std::vector<entry> entries; | |
std::vector<std::vector<uint8_t>> entry_data; | |
}; | |
std::vector<uint8_t> decompressZlib(const std::vector<uint8_t>& compressedData) { | |
size_t estimatedSize = compressedData.size() * 8; | |
std::vector<uint8_t> decompressedData(estimatedSize); | |
uLongf decompressedSize = decompressedData.size(); | |
int result = uncompress(decompressedData.data(), &decompressedSize, | |
compressedData.data(), compressedData.size()); | |
if (result == Z_OK) { | |
decompressedData.resize(decompressedSize); | |
return decompressedData; | |
} | |
else { | |
std::cerr << "Decompression failed! Error code: " << result << std::endl; | |
return {}; | |
} | |
} | |
int main(int argc, char ** argp) | |
{ | |
arc file; | |
std::ifstream in(argp[1], std::ios::binary); | |
size_t data_offs = 0, name_offs = 0; | |
if (in.good()) { | |
in.read(reinterpret_cast<char*>(&file.header), sizeof(arc::header)); | |
data_offs = file.header.data_tbl_start; | |
for (int entry = 0; entry < file.header.num_entries; ++entry) { | |
arc::entry tmp_entry; | |
in.read(reinterpret_cast<char*>(&tmp_entry), sizeof(arc::entry)); | |
size_t last_pos = in.tellg(); | |
in.seekg(file.header.name_tbl_start + name_offs, std::ios::beg); | |
std::string name; | |
while (in.peek() != 0) name.push_back(in.get()); | |
name_offs += name.size()+1; | |
in.seekg(data_offs, std::ios::beg); | |
std::vector<uint8_t> data(tmp_entry.size); | |
data.resize(tmp_entry.size); | |
data.reserve(tmp_entry.size); | |
in.read((char*) &data.data()[0], tmp_entry.size); | |
printf("[0x%X] %s\n", data_offs, name.c_str()); | |
if (data.data()[0] == 0x78 && data.data()[1] == 0xDA) { | |
auto decompressed = decompressZlib(data); | |
if (decompressed.size()) | |
data = decompressed; | |
} | |
while (in.peek() != 0x78) in.get(); | |
data_offs = in.tellg(); | |
std::ofstream output(name, std::ios::binary); | |
if (output.good()) { | |
output.write(reinterpret_cast<char*>(&data.data()[0]), data.size()); | |
output.close(); | |
} | |
file.entries.push_back(tmp_entry); | |
file.entry_data.push_back(data); | |
in.seekg(last_pos); | |
} | |
in.close(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment