diff --git a/.gitmodules b/.gitmodules index e91c1b5..b1dc161 100644 --- a/.gitmodules +++ b/.gitmodules @@ -37,6 +37,3 @@ path = deps/gsc-tool url = https://github.com/xensik/gsc-tool.git branch = dev -[submodule "deps/fmt"] - path = deps/fmt - url = https://github.com/fmtlib/fmt.git diff --git a/deps/extra/gsc-tool/gsc_interface.cpp b/deps/extra/gsc-tool/gsc_interface.cpp deleted file mode 100644 index ecfe7a2..0000000 --- a/deps/extra/gsc-tool/gsc_interface.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "gsc_interface.hpp" - -namespace gsc -{ - std::unique_ptr cxt; -} diff --git a/deps/extra/gsc-tool/gsc_interface.hpp b/deps/extra/gsc-tool/gsc_interface.hpp deleted file mode 100644 index 7074ab4..0000000 --- a/deps/extra/gsc-tool/gsc_interface.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#undef ERROR -#undef IN -#undef TRUE -#undef FALSE - -#undef far - -#include -#include - -namespace gsc -{ - extern std::unique_ptr cxt; -} diff --git a/deps/fmt b/deps/fmt deleted file mode 160000 index 9869971..0000000 --- a/deps/fmt +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 98699719f85445e0ab4a962c0b1a2a0218289814 diff --git a/deps/gsc-tool b/deps/gsc-tool index 9318c6e..b44a51d 160000 --- a/deps/gsc-tool +++ b/deps/gsc-tool @@ -1 +1 @@ -Subproject commit 9318c6e0ae15b69fd02d192ff3148dd187352d5d +Subproject commit b44a51d8ac9aa69eee360f96d619c460373bbbc2 diff --git a/deps/premake/fmt.lua b/deps/premake/fmt.lua deleted file mode 100644 index 905bbf7..0000000 --- a/deps/premake/fmt.lua +++ /dev/null @@ -1,34 +0,0 @@ -fmt = { - source = path.join(dependencies.basePath, "fmt"), -} - -function fmt.import() - links { "fmt" } - - fmt.includes() -end - -function fmt.includes() - includedirs { - path.join(fmt.source, "include"), - } -end - -function fmt.project() - project "fmt" - kind "StaticLib" - language "C++" - - fmt.includes() - - files { - path.join(fmt.source, "include/fmt/*.h"), - path.join(fmt.source, "src/*.cc") - } - - removefiles { - path.join(fmt.source, "src/fmt.cc") - } -end - -table.insert(dependencies, fmt) diff --git a/deps/premake/gsc-tool.lua b/deps/premake/gsc-tool.lua index be50dfd..8678836 100644 --- a/deps/premake/gsc-tool.lua +++ b/deps/premake/gsc-tool.lua @@ -9,12 +9,11 @@ end function gsc_tool.includes() includedirs { + gsc_tool.source, path.join(gsc_tool.source, "iw5"), path.join(gsc_tool.source, "utils"), path.join(gsc_tool.source, "gsc"), - gsc_tool.source, - - path.join(dependencies.basePath, "extra/gsc-tool"), + path.join(dependencies.basePath, "gsc-tool/include"), } end @@ -29,12 +28,11 @@ function gsc_tool.project() } includedirs { - path.join(gsc_tool.source, "utils"), gsc_tool.source, + path.join(gsc_tool.source, "utils"), } zlib.includes() - fmt.includes() project "xsk-gsc-iw5" kind "StaticLib" @@ -45,6 +43,9 @@ function gsc_tool.project() filter {} files { + path.join(gsc_tool.source, "stdinc.hpp"), + path.join(gsc_tool.source, "stdinc.cpp"), + path.join(gsc_tool.source, "iw5/iw5_pc.hpp"), path.join(gsc_tool.source, "iw5/iw5_pc.cpp"), path.join(gsc_tool.source, "iw5/iw5_pc_code.cpp"), @@ -56,17 +57,12 @@ function gsc_tool.project() path.join(gsc_tool.source, "gsc/misc/*.cpp"), path.join(gsc_tool.source, "gsc/*.hpp"), path.join(gsc_tool.source, "gsc/*.cpp"), - - path.join(dependencies.basePath, "extra/gsc-tool/gsc_interface.cpp"), } includedirs { - path.join(gsc_tool.source, "iw5"), gsc_tool.source, - path.join(dependencies.basePath, "extra/gsc-tool"), + path.join(gsc_tool.source, "iw5"), } - - fmt.includes() end table.insert(dependencies, gsc_tool) diff --git a/src/game/scripting/functions.cpp b/src/game/scripting/functions.cpp deleted file mode 100644 index 7180d32..0000000 --- a/src/game/scripting/functions.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include "game/game.hpp" - -#include "module/gsc/script_extension.hpp" - -#include "functions.hpp" - -#include - -#include - -namespace scripting -{ - int find_function_index(const std::string& name, [[maybe_unused]] const bool prefer_global) - { - const auto target = utils::string::to_lower(name); - auto const& first = gsc::cxt->func_map(); - auto const& second = gsc::cxt->meth_map(); - - if (const auto itr = first.find(name); itr != first.end()) - { - return static_cast(itr->second); - } - - if (const auto itr = second.find(name); itr != second.end()) - { - return static_cast(itr->second); - } - - return -1; - } - - std::uint32_t parse_token_id(const std::string& name) - { - if (name.starts_with("_ID")) - { - return static_cast(std::strtol(name.substr(3).data(), nullptr, 10)); - } - - return 0; - } - - std::string find_token(std::uint32_t id) - { - return gsc::cxt->token_name(id); - } - - std::string find_token_single(std::uint32_t id) - { - return gsc::cxt->token_name(id); - } - - unsigned int find_token_id(const std::string& name) - { - const auto id = gsc::cxt->token_id(name); - if (id) - { - return id; - } - - const auto parsed_id = parse_token_id(name); - if (parsed_id) - { - return parsed_id; - } - - return game::native::SL_GetCanonicalString(name.data()); - } - - game::native::BuiltinFunction get_function_by_index(const std::uint32_t index) - { - auto** function_table = gsc::func_table; - auto** method_table = gsc::meth_table; - - if (index < gsc::scr_func_max_id) - { - return reinterpret_cast(function_table)[index - 1]; - } - - return reinterpret_cast(method_table)[index]; - } - - game::native::BuiltinFunction find_function(const std::string& name, const bool prefer_global) - { - const auto index = find_function_index(name, prefer_global); - if (index < 0) return nullptr; - - return get_function_by_index(index); - } -} diff --git a/src/game/scripting/functions.hpp b/src/game/scripting/functions.hpp deleted file mode 100644 index b73230b..0000000 --- a/src/game/scripting/functions.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -namespace scripting -{ - std::string find_token(std::uint32_t id); - std::string find_token_single(std::uint32_t id); - unsigned int find_token_id(const std::string& name); - - int find_function_index(const std::string& name, bool prefer_global); -} diff --git a/src/module/gsc/script_error.cpp b/src/module/gsc/script_error.cpp index e64ed1a..6001e60 100644 --- a/src/module/gsc/script_error.cpp +++ b/src/module/gsc/script_error.cpp @@ -4,6 +4,7 @@ #include "script_error.hpp" #include "script_loading.hpp" +#include "script_extension.hpp" #include "module/console.hpp" #include "module/scripting.hpp" @@ -11,8 +12,6 @@ #include #include -#include - using namespace utils::string; namespace gsc @@ -124,8 +123,8 @@ namespace gsc { try { - const auto index = gsc::cxt->opcode_enum(opcode); - return {gsc::cxt->opcode_name(index)}; + const auto index = gsc_ctx->opcode_enum(opcode); + return {gsc_ctx->opcode_name(index)}; } catch (...) { @@ -140,11 +139,11 @@ namespace gsc if (function_id > (scr_func_max_id - 1)) { - console::error("in call to builtin method \"%s\"%s\n", gsc::cxt->meth_name(function_id).data(), error.data()); + console::error("in call to builtin method \"%s\"%s\n", gsc_ctx->meth_name(function_id).data(), error.data()); } else { - console::error("in call to builtin function \"%s\"%s\n", gsc::cxt->func_name(function_id).data(), error.data()); + console::error("in call to builtin function \"%s\"%s\n", gsc_ctx->func_name(function_id).data(), error.data()); } } diff --git a/src/module/gsc/script_extension.cpp b/src/module/gsc/script_extension.cpp index b45b918..5dbdfc3 100644 --- a/src/module/gsc/script_extension.cpp +++ b/src/module/gsc/script_extension.cpp @@ -4,6 +4,7 @@ #include "script_extension.hpp" #include "script_error.hpp" +#include "script_loading.hpp" #include "module/console.hpp" #include "module/scripting.hpp" @@ -11,8 +12,6 @@ #include #include -#include - namespace gsc { std::uint16_t scr_func_max_id = 0x1C7; @@ -173,7 +172,7 @@ namespace gsc ++scr_func_max_id; custom_functions.push_back({ lowered_name, scr_func_max_id, func }); - cxt->func_add(lowered_name, scr_func_max_id); + gsc_ctx->func_add(lowered_name, scr_func_max_id); } void register_method(const std::string& name, const game::native::BuiltinMethod& meth) @@ -193,7 +192,7 @@ namespace gsc ++scr_meth_max_id; custom_methods.push_back({ lowered_name, scr_meth_max_id, meth }); - cxt->meth_add(lowered_name, scr_meth_max_id); + gsc_ctx->meth_add(lowered_name, scr_meth_max_id); } const char* get_code_pos(int index) diff --git a/src/module/gsc/script_loading.cpp b/src/module/gsc/script_loading.cpp index 589bd07..b10755b 100644 --- a/src/module/gsc/script_loading.cpp +++ b/src/module/gsc/script_loading.cpp @@ -12,10 +12,10 @@ #include #include -#include - namespace gsc { + std::unique_ptr gsc_ctx; + namespace { utils::memory::allocator script_file_allocator; @@ -80,8 +80,8 @@ namespace gsc try { - auto& compiler = gsc::cxt->compiler(); - auto& assembler = gsc::cxt->assembler(); + auto& compiler = gsc_ctx->compiler(); + auto& assembler = gsc_ctx->assembler(); std::string source_buffer; if (!read_raw_script_file(real_name + ".gsc", &source_buffer)) @@ -128,7 +128,7 @@ namespace gsc std::string get_script_file_name(const std::string& name) { - const auto id = gsc::cxt->token_id(name); + const auto id = gsc_ctx->token_id(name); if (!id) { return name; @@ -190,14 +190,14 @@ namespace gsc console::info("Script %s.gsc loaded successfully\n", path); - const auto main_handle = game::native::Scr_GetFunctionHandle(path, static_cast(gsc::cxt->token_id("main"))); + const auto main_handle = game::native::Scr_GetFunctionHandle(path, static_cast(gsc_ctx->token_id("main"))); if (main_handle) { console::info("Loaded '%s::main'\n", path); main_handles[path] = main_handle; } - const auto init_handle = game::native::Scr_GetFunctionHandle(path, static_cast(gsc::cxt->token_id("init"))); + const auto init_handle = game::native::Scr_GetFunctionHandle(path, static_cast(gsc_ctx->token_id("init"))); if (init_handle) { console::info("Loaded '%s::init'\n", path); @@ -265,7 +265,7 @@ namespace gsc xsk::gsc::build::dev : xsk::gsc::build::prod; - gsc::cxt->init(comp_mode, [](const std::string& include_name) -> std::pair> + gsc_ctx->init(comp_mode, [](const std::string& include_name) -> std::pair> { const auto real_name = get_raw_script_file_name(include_name); @@ -293,7 +293,7 @@ namespace gsc void scr_end_load_scripts_stub() { // Cleanup the compiler - gsc::cxt->cleanup(); + gsc_ctx->cleanup(); utils::hook::invoke(SELECT_VALUE(0x5DF010, 0x561D00)); } @@ -305,7 +305,7 @@ namespace gsc const auto id = static_cast(std::strtol(name, nullptr, 10)); if (id) { - real_name = gsc::cxt->token_name(id); + real_name = gsc_ctx->token_name(id); } auto* script = load_custom_script(name, real_name); @@ -322,7 +322,7 @@ namespace gsc public: void post_start() override { - gsc::cxt = std::make_unique(); + gsc_ctx = std::make_unique(); } void post_load() override diff --git a/src/module/gsc/script_loading.hpp b/src/module/gsc/script_loading.hpp index 471288c..0c2eca9 100644 --- a/src/module/gsc/script_loading.hpp +++ b/src/module/gsc/script_loading.hpp @@ -1,8 +1,10 @@ #pragma once +#define XSK_GSC_IW5_PC +#include namespace gsc { - extern std::uint16_t scr_func_max_id; + extern std::unique_ptr gsc_ctx; game::native::ScriptFile* find_script(game::native::XAssetType type, const char* name, int allow_create_default); } diff --git a/src/module/scripting.cpp b/src/module/scripting.cpp index 30af425..cd209b6 100644 --- a/src/module/scripting.cpp +++ b/src/module/scripting.cpp @@ -2,9 +2,9 @@ #include #include "game/game.hpp" -#include +#include "scripting.hpp" -#include "game/scripting/functions.hpp" +#include #include "gsc/script_loading.hpp" @@ -23,11 +23,6 @@ namespace scripting std::vector> shutdown_callbacks; - std::string get_token(unsigned int id) - { - return find_token(id); - } - void add_function_sort(unsigned int id, const char* pos) { std::string filename = current_file; @@ -111,6 +106,11 @@ namespace scripting } } + std::string find_token(std::uint32_t id) + { + return gsc::gsc_ctx->token_name(id); + } + std::string get_token(unsigned int id) { return find_token(id); diff --git a/src/module/scripting.hpp b/src/module/scripting.hpp index 5a1dd29..4b58898 100644 --- a/src/module/scripting.hpp +++ b/src/module/scripting.hpp @@ -8,6 +8,7 @@ namespace scripting extern std::string current_file; + std::string find_token(std::uint32_t id); std::string get_token(unsigned int id); void on_shutdown(const std::function& callback);