diff --git a/src/common/mmap.h b/src/common/mmap.h new file mode 100644 index 0000000..9e076b5 --- /dev/null +++ b/src/common/mmap.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +struct stream { + primitives::templates2::mmap_file &m; + uint8_t *p{m.p}; + + template + operator T &() { + auto &r = *(T *)p; + p += sizeof(T); + return r; + } + template + auto span(size_t len) { + auto s = std::span((T *)p, len); + p += sizeof(T) * len; + return s; + } +}; diff --git a/src/script2txt/script.h b/src/script2txt/script.h index 4195437..85c7e26 100644 --- a/src/script2txt/script.h +++ b/src/script2txt/script.h @@ -45,7 +45,7 @@ inline bool replace_all(std::string &str, const std::string &from, const std::st struct script { uint32_t file_size; - uint32_t unk0; + uint32_t unk0; // stack size? always 16000? section bits? magic? max size? uint32_t raw_text_size; uint32_t unk1; std::vector raw_text; diff --git a/src/script2txt2/script2txt2.cpp b/src/script2txt2/script2txt2.cpp new file mode 100644 index 0000000..429bbbd --- /dev/null +++ b/src/script2txt2/script2txt2.cpp @@ -0,0 +1,92 @@ +/* + * AIM script2txt2 (simpler version) + * Copyright (C) 2024 lzwdgc + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include +#include +#include + +#pragma pack(push, 1) +struct script { + uint32_t file_size; + uint32_t unk0; // stack size? always 16000? // section bits? + uint32_t raw_text_size; + uint32_t nlines; +}; +#pragma pack(pop) + +int main(int argc, char *argv[]) { + cl::opt p(cl::Positional, cl::desc(""), cl::Required); + + cl::ParseCommandLineOptions(argc, argv); + + auto func = [](auto &&fn) { + primitives::templates2::mmap_file f{fn}; + stream s{f}; + script scr = s; + auto text = s.span(scr.raw_text_size); + uint32_t max_nlines = s; + auto rest = s.span(max_nlines); + std::vector lines; + lines.reserve(scr.nlines); + for (int i = 0; i < scr.nlines; ++i) { + lines.emplace_back((const char *)f.p + sizeof(script) + rest[i]); + } + int a = 5; + a++; + + // write script + /*{ + filename += ".txt"; + std::ofstream ofile(filename); + if (ofile) + ofile << ctx.getText(); + } + + // write function calls + { + std::ofstream functions("functions.txt", std::ios::app); + if (functions) + { + for (auto &f : driver.functions) + { + std::string f2(f.size(), 0); + std::transform(f.begin(), f.end(), f2.begin(), tolower); + functions << f2 << "\n"; + } + } + }*/ + }; + + if (fs::is_regular_file(p)) { + func(p.string()); + } else if (fs::is_directory(p)) { + auto files = enumerate_files_like(p, ".*\\.scr", false); + auto files2 = enumerate_files_like(p, ".*\\.QST", false); + files.insert(files2.begin(), files2.end()); + for (auto &f : files) { + std::cout << "processing: " << f << "\n"; + func(f.string()); + } + } else { + throw std::runtime_error("Bad fs object"); + } + + return 0; +} diff --git a/src/unpaker2/unpaker2.cpp b/src/unpaker2/unpaker2.cpp index 91e6820..aca5832 100644 --- a/src/unpaker2/unpaker2.cpp +++ b/src/unpaker2/unpaker2.cpp @@ -17,12 +17,12 @@ */ #include +#include #include #include #include #include -#include #include #include @@ -56,31 +56,16 @@ struct segment { none = 0x0, lzo = 0x1, lzma = 0x2, - rlew = 0x4, + rlew = 0x4, // https://moddingwiki.shikadi.net/wiki/Id_Software_RLEW_compression }; - uint32_t unk1; // some file offset? trash? + // some file offset? trash? crc? m1 has zlib crc table (png)? + uint32_t unk1; decode_algorithm algorithm; uint32_t offset; }; #pragma pack(pop) -struct stream { - primitives::templates2::mmap_file &m; - uint8_t *p{m.p}; - - template operator T&() { - auto &r = *(T*)p; - p += sizeof(T); - return r; - } - template auto span(size_t len) { - auto s = std::span((T*)p, len); - p += sizeof(T) * len; - return s; - } -}; - void unpack_file(path fn) { primitives::templates2::mmap_file f{fn}; stream s{f}; diff --git a/sw.cpp b/sw.cpp index 9f8768f..a8c854f 100644 --- a/sw.cpp +++ b/sw.cpp @@ -48,6 +48,7 @@ void build(Solution &s) add_exe_with_data_manager("mmo_extractor"); add_exe_with_common("mmp_extractor") += "org.sw.demo.intel.opencv.highgui"_dep; add_exe_with_common("mpj_loader"); + add_exe_with_common("script2txt2"); add_exe_with_common("tm_converter"); add_exe("name_generator"); add_exe_with_common("save_loader");