iw5 console interface

This commit is contained in:
xensik 2022-08-23 14:07:32 +02:00
parent 3b53157c6d
commit b04434a3cb

View File

@ -5,6 +5,7 @@
#include "stdafx.hpp" #include "stdafx.hpp"
#include "utils/xsk/utils.hpp" #include "utils/xsk/utils.hpp"
#include "experimental/iw5c/xsk/iw5c.hpp"
#include "iw5/xsk/iw5.hpp" #include "iw5/xsk/iw5.hpp"
#include "iw6/xsk/iw6.hpp" #include "iw6/xsk/iw6.hpp"
#include "iw7/xsk/iw7.hpp" #include "iw7/xsk/iw7.hpp"
@ -19,46 +20,47 @@
namespace xsk namespace xsk
{ {
enum class encd { __, SOURCE, ASSEMBLY, BINARY }; enum class encd { _, source, assembly, binary };
enum class mode { __, ASM, DISASM, COMP, DECOMP }; enum class mode { _, assemble, disassemble, compile, decompile };
enum class game { __, IW5, IW6, IW7, IW8, S1, S2, S4, H1, H2, T6 }; enum class game { _, iw5c, iw5, iw6, iw7, iw8, s1, s2, s4, h1, h2, t6 };
const std::map<std::string, encd> exts = const std::map<std::string, encd> exts =
{ {
{ ".gsc", encd::SOURCE }, { ".gsc", encd::source },
{ ".cgsc", encd::BINARY }, { ".cgsc", encd::binary },
{ ".gscbin", encd::BINARY }, { ".gscbin", encd::binary },
{ ".gscasm", encd::ASSEMBLY }, { ".gscasm", encd::assembly },
}; };
const std::map<std::string, mode> modes = const std::map<std::string, mode> modes =
{ {
{ "asm", mode::ASM }, { "asm", mode::assemble },
{ "disasm", mode::DISASM }, { "disasm", mode::disassemble },
{ "comp", mode::COMP }, { "comp", mode::compile },
{ "decomp", mode::DECOMP }, { "decomp", mode::decompile },
}; };
const std::map<std::string, game> games = const std::map<std::string, game> games =
{ {
{ "iw5", game::IW5 }, { "iw5c", game::iw5c },
{ "iw6", game::IW6 }, { "iw5", game::iw5 },
{ "iw7", game::IW7 }, { "iw6", game::iw6 },
{ "iw8", game::IW8 }, { "iw7", game::iw7 },
{ "s1", game::S1 }, { "iw8", game::iw8 },
{ "s2", game::S2 }, { "s1", game::s1 },
{ "s4", game::S4 }, { "s2", game::s2 },
{ "h1", game::H1 }, { "s4", game::s4 },
{ "h2", game::H2 }, { "h1", game::h1 },
{ "t6", game::T6 }, { "h2", game::h2 },
{ "t6", game::t6 },
}; };
const std::map<mode, encd> encds = const std::map<mode, encd> encds =
{ {
{ mode::ASM , encd::ASSEMBLY }, { mode::assemble , encd::assembly },
{ mode::DISASM, encd::BINARY }, { mode::disassemble, encd::binary },
{ mode::COMP, encd::SOURCE }, { mode::compile, encd::source },
{ mode::DECOMP, encd::BINARY }, { mode::decompile, encd::binary },
}; };
auto overwrite_prompt(const std::string& file) -> bool auto overwrite_prompt(const std::string& file) -> bool
@ -98,23 +100,25 @@ auto choose_resolver_file_name(uint32_t id, game& game) -> std::string
{ {
switch (game) switch (game)
{ {
case game::IW5: case game::iw5c:
return iw5c::resolver::token_name(static_cast<std::uint16_t>(id));
case game::iw5:
return iw5::resolver::token_name(static_cast<std::uint16_t>(id)); return iw5::resolver::token_name(static_cast<std::uint16_t>(id));
case game::IW6: case game::iw6:
return iw6::resolver::file_name(static_cast<std::uint16_t>(id)); return iw6::resolver::file_name(static_cast<std::uint16_t>(id));
case game::IW7: case game::iw7:
return iw7::resolver::file_name(id); return iw7::resolver::file_name(id);
case game::IW8: case game::iw8:
return iw8::resolver::file_name(id); return iw8::resolver::file_name(id);
case game::S1: case game::s1:
return s1::resolver::file_name(static_cast<std::uint16_t>(id)); return s1::resolver::file_name(static_cast<std::uint16_t>(id));
case game::S2: case game::s2:
return s2::resolver::file_name(static_cast<std::uint16_t>(id)); return s2::resolver::file_name(static_cast<std::uint16_t>(id));
case game::S4: case game::s4:
return s4::resolver::file_name(id); return s4::resolver::file_name(id);
case game::H1: case game::h1:
return h1::resolver::token_name(static_cast<std::uint16_t>(id)); return h1::resolver::token_name(static_cast<std::uint16_t>(id));
case game::H2: case game::h2:
return h2::resolver::token_name(static_cast<std::uint16_t>(id)); return h2::resolver::token_name(static_cast<std::uint16_t>(id));
default: default:
return ""; return "";
@ -377,7 +381,7 @@ void decompile_file(game game, std::string file)
} }
else else
{ {
auto filename = choose_resolver_file_name(std::atoi(scriptid.data()), game); auto filename = choose_resolver_file_name(std::atoi(scriptid.data()), game);/*xsk::utils::string::va("%s_%04X", scriptid.data(), std::atoi(scriptid.data()));*/
auto count = file.find(scriptid); auto count = file.find(scriptid);
if (count != std::string::npos) if (count != std::string::npos)
@ -400,29 +404,31 @@ void decompile_file(game game, std::string file)
void init() void init()
{ {
contexts[game::IW5] = std::make_unique<iw5::context>(); contexts[game::iw5c] = std::make_unique<iw5c::context>();
contexts[game::IW5]->init(build::prod, utils::file::read); contexts[game::iw5c]->init(build::prod, utils::file::read);
contexts[game::IW6] = std::make_unique<iw6::context>(); contexts[game::iw5] = std::make_unique<iw5::context>();
contexts[game::IW6]->init(build::prod, utils::file::read); contexts[game::iw5]->init(build::prod, utils::file::read);
contexts[game::IW7] = std::make_unique<iw7::context>(); contexts[game::iw6] = std::make_unique<iw6::context>();
contexts[game::IW7]->init(build::prod, utils::file::read); contexts[game::iw6]->init(build::prod, utils::file::read);
contexts[game::IW8] = std::make_unique<iw8::context>(); contexts[game::iw7] = std::make_unique<iw7::context>();
contexts[game::IW8]->init(build::prod, utils::file::read); contexts[game::iw7]->init(build::prod, utils::file::read);
contexts[game::S1] = std::make_unique<s1::context>(); contexts[game::iw8] = std::make_unique<iw8::context>();
contexts[game::S1]->init(build::prod, utils::file::read); contexts[game::iw8]->init(build::prod, utils::file::read);
contexts[game::S2] = std::make_unique<s2::context>(); contexts[game::s1] = std::make_unique<s1::context>();
contexts[game::S2]->init(build::prod, utils::file::read); contexts[game::s1]->init(build::prod, utils::file::read);
contexts[game::S4] = std::make_unique<s4::context>(); contexts[game::s2] = std::make_unique<s2::context>();
contexts[game::S4]->init(build::prod, utils::file::read); contexts[game::s2]->init(build::prod, utils::file::read);
contexts[game::H1] = std::make_unique<h1::context>(); contexts[game::s4] = std::make_unique<s4::context>();
contexts[game::H1]->init(build::prod, utils::file::read); contexts[game::s4]->init(build::prod, utils::file::read);
contexts[game::H2] = std::make_unique<h2::context>(); contexts[game::h1] = std::make_unique<h1::context>();
contexts[game::H2]->init(build::prod, utils::file::read); contexts[game::h1]->init(build::prod, utils::file::read);
contexts[game::h2] = std::make_unique<h2::context>();
contexts[game::h2]->init(build::prod, utils::file::read);
funcs[mode::ASM] = assemble_file; funcs[mode::assemble] = assemble_file;
funcs[mode::DISASM] = disassemble_file; funcs[mode::disassemble] = disassemble_file;
funcs[mode::COMP] = compile_file; funcs[mode::compile] = compile_file;
funcs[mode::DECOMP] = decompile_file; funcs[mode::decompile] = decompile_file;
} }
} // namespace xsk::gsc } // namespace xsk::gsc
@ -527,13 +533,13 @@ void decompile_file(game game, const std::filesystem::path& file)
void init() void init()
{ {
contexts[game::T6] = std::make_unique<t6::context>(); contexts[game::t6] = std::make_unique<t6::context>();
contexts[game::T6]->init(build::prod, utils::file::read); contexts[game::t6]->init(build::prod, utils::file::read);
funcs[mode::ASM] = assemble_file; funcs[mode::assemble] = assemble_file;
funcs[mode::DISASM] = disassemble_file; funcs[mode::disassemble] = disassemble_file;
funcs[mode::COMP] = compile_file; funcs[mode::compile] = compile_file;
funcs[mode::DECOMP] = decompile_file; funcs[mode::decompile] = decompile_file;
} }
} // namespace xsk::arc } // namespace xsk::arc
@ -546,7 +552,7 @@ void execute(mode mode, game game, const std::string& path)
{ {
if (entry.is_regular_file()) if (entry.is_regular_file())
{ {
if (game < game::T6) if (game < game::t6)
gsc::funcs[mode](game, entry.path().generic_string()); gsc::funcs[mode](game, entry.path().generic_string());
else else
arc::funcs[mode](game, std::filesystem::path(entry.path().generic_string(), std::filesystem::path::format::generic_format)); arc::funcs[mode](game, std::filesystem::path(entry.path().generic_string(), std::filesystem::path::format::generic_format));
@ -555,7 +561,7 @@ void execute(mode mode, game game, const std::string& path)
} }
else if (std::filesystem::is_regular_file(path)) else if (std::filesystem::is_regular_file(path))
{ {
if (game < game::T6) if (game < game::t6)
gsc::funcs[mode](game, path); gsc::funcs[mode](game, path);
else else
arc::funcs[mode](game, std::filesystem::path(path, std::filesystem::path::format::generic_format)); arc::funcs[mode](game, std::filesystem::path(path, std::filesystem::path::format::generic_format));
@ -609,7 +615,7 @@ void print_usage()
{ {
std::cout << "usage: gsc-tool.exe <mode> <game> <path>\n"; std::cout << "usage: gsc-tool.exe <mode> <game> <path>\n";
std::cout << "\t* modes: asm, disasm, comp, decomp\n"; std::cout << "\t* modes: asm, disasm, comp, decomp\n";
std::cout << "\t* games: iw5, iw6, iw7, iw8, s1, s2, s4, h1, h2, t6\n"; std::cout << "\t* games: iw5c, iw5, iw6, iw7, iw8, s1, s2, s4, h1, h2, t6\n";
std::cout << "\t* paths: file or directory (recursive)\n"; std::cout << "\t* paths: file or directory (recursive)\n";
} }
/* /*
@ -708,8 +714,8 @@ void shell()
void main(std::uint32_t argc, char** argv) void main(std::uint32_t argc, char** argv)
{ {
auto path = ""s; auto path = ""s;
mode mode = mode::__; mode mode = mode::_;
game game = game::__; game game = game::_;
gsc::init(); gsc::init();
arc::init(); arc::init();