diff --git a/.gitmodules b/.gitmodules index 03c64ab..a5ff954 100644 --- a/.gitmodules +++ b/.gitmodules @@ -48,6 +48,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 b4579fe..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 9723f04..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..30efba5 160000 --- a/deps/gsc-tool +++ b/deps/gsc-tool @@ -1 +1 @@ -Subproject commit 9318c6e0ae15b69fd02d192ff3148dd187352d5d +Subproject commit 30efba5424e89adc2133caf671c5c4e73208c3dd 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 50530e2..6f650f4 100644 --- a/deps/premake/gsc-tool.lua +++ b/deps/premake/gsc-tool.lua @@ -9,12 +9,7 @@ end function gsc_tool.includes() includedirs { - path.join(gsc_tool.source, "s1"), - path.join(gsc_tool.source, "utils"), - path.join(gsc_tool.source, "gsc"), gsc_tool.source, - - path.join(dependencies.basePath, "extra/gsc-tool"), } end @@ -34,7 +29,6 @@ function gsc_tool.project() } zlib.includes() - fmt.includes() project "xsk-gsc-s1" kind "StaticLib" @@ -45,6 +39,8 @@ function gsc_tool.project() filter {} files { + path.join(gsc_tool.source, "stdinc.hpp"), + path.join(gsc_tool.source, "s1/s1_pc.hpp"), path.join(gsc_tool.source, "s1/s1_pc.cpp"), path.join(gsc_tool.source, "s1/s1_pc_code.cpp"), @@ -56,17 +52,11 @@ 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, "s1"), gsc_tool.source, - path.join(dependencies.basePath, "extra/gsc-tool"), } - - fmt.includes() end table.insert(dependencies, gsc_tool) diff --git a/src/client/component/gsc/script_extension.cpp b/src/client/component/gsc/script_extension.cpp index b20dd35..5b0e3a2 100644 --- a/src/client/component/gsc/script_extension.cpp +++ b/src/client/component/gsc/script_extension.cpp @@ -10,11 +10,10 @@ #include "script_error.hpp" #include "script_extension.hpp" +#include "script_loading.hpp" #include -#include - namespace gsc { std::uint16_t function_id_start = 0x2DF; @@ -95,11 +94,11 @@ namespace gsc if (function_id > 0x1000) { - console::warn("in call to builtin method \"%s\"%s", gsc::cxt->meth_name(function_id).data(), error.data()); + console::warn("in call to builtin method \"%s\"%s", gsc_ctx->meth_name(function_id).data(), error.data()); } else { - console::warn("in call to builtin function \"%s\"%s", gsc::cxt->func_name(function_id).data(), error.data()); + console::warn("in call to builtin function \"%s\"%s", gsc_ctx->func_name(function_id).data(), error.data()); } } @@ -107,8 +106,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 (...) { @@ -232,7 +231,7 @@ namespace gsc void override_function(const std::string& name, game::BuiltinFunction func) { - const auto id = gsc::cxt->func_id(name); + const auto id = gsc_ctx->func_id(name); builtin_funcs_overrides.emplace(id, func); } @@ -240,7 +239,7 @@ namespace gsc { ++function_id_start; functions[function_id_start] = function; - gsc::cxt->func_add(name, function_id_start); + gsc_ctx->func_add(name, function_id_start); } class extension final : public component_interface diff --git a/src/client/component/gsc/script_loading.cpp b/src/client/component/gsc/script_loading.cpp index 60be599..e425fbf 100644 --- a/src/client/component/gsc/script_loading.cpp +++ b/src/client/component/gsc/script_loading.cpp @@ -14,10 +14,10 @@ #include "script_loading.hpp" -#include - namespace gsc { + std::unique_ptr gsc_ctx; + namespace { std::unordered_map main_handles; @@ -82,8 +82,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)) @@ -140,7 +140,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; @@ -177,8 +177,8 @@ namespace gsc return; } - const auto main_handle = game::Scr_GetFunctionHandle(name.data(), gsc::cxt->token_id("main")); - const auto init_handle = game::Scr_GetFunctionHandle(name.data(), gsc::cxt->token_id("init")); + const auto main_handle = game::Scr_GetFunctionHandle(name.data(), gsc_ctx->token_id("main")); + const auto init_handle = game::Scr_GetFunctionHandle(name.data(), gsc_ctx->token_id("init")); if (main_handle) { @@ -306,7 +306,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); @@ -334,7 +334,7 @@ namespace gsc void scr_end_load_scripts_stub() { // Cleanup the compiler - gsc::cxt->cleanup(); + gsc_ctx->cleanup(); utils::hook::invoke(SELECT_VALUE(0x140243780, 0x1403EDF90)); } @@ -346,7 +346,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); @@ -363,7 +363,7 @@ namespace gsc public: void post_load() override { - gsc::cxt = std::make_unique(); + gsc_ctx = std::make_unique(); } void post_unpack() override diff --git a/src/client/component/gsc/script_loading.hpp b/src/client/component/gsc/script_loading.hpp index 2a07774..5d4ce6f 100644 --- a/src/client/component/gsc/script_loading.hpp +++ b/src/client/component/gsc/script_loading.hpp @@ -1,6 +1,9 @@ #pragma once +#include namespace gsc { + extern std::unique_ptr gsc_ctx; + game::ScriptFile* find_script(game::XAssetType type, const char* name, int allow_create_default); } diff --git a/src/client/game/scripting/functions.cpp b/src/client/game/scripting/functions.cpp index 1dd958f..f52240d 100644 --- a/src/client/game/scripting/functions.cpp +++ b/src/client/game/scripting/functions.cpp @@ -4,8 +4,7 @@ #include #include "component/gsc/script_extension.hpp" - -#include +#include "component/gsc/script_loading.hpp" namespace scripting { @@ -14,8 +13,8 @@ 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(); + auto const& first = gsc::gsc_ctx->func_map(); + auto const& second = gsc::gsc_ctx->meth_map(); if (const auto itr = first.find(name); itr != first.end()) { @@ -43,17 +42,17 @@ namespace scripting std::string find_token(std::uint32_t id) { - return gsc::cxt->token_name(id); + return gsc::gsc_ctx->token_name(id); } std::string find_token_single(std::uint32_t id) { - return gsc::cxt->token_name(id); + return gsc::gsc_ctx->token_name(id); } unsigned int find_token_id(const std::string& name) { - const auto id = gsc::cxt->token_id(name); + const auto id = gsc::gsc_ctx->token_id(name); if (id) { return id; diff --git a/src/client/game/scripting/lua/context.cpp b/src/client/game/scripting/lua/context.cpp index e1135e6..b017919 100644 --- a/src/client/game/scripting/lua/context.cpp +++ b/src/client/game/scripting/lua/context.cpp @@ -5,14 +5,14 @@ #include "game/scripting/execution.hpp" +#include "component/gsc/script_loading.hpp" + #include "component/command.hpp" #include "component/notifies.hpp" #include "component/scripting.hpp" #include -#include - namespace scripting::lua { namespace @@ -245,7 +245,7 @@ namespace scripting::lua auto entity_type = state.new_usertype("entity"); - for (auto const& func : gsc::cxt->meth_map()) + for (auto const& func : gsc::gsc_ctx->meth_map()) { const auto name = std::string(func.first); entity_type[name] = [name](const entity& entity, const sol::this_state s, sol::variadic_args va) @@ -377,7 +377,7 @@ namespace scripting::lua auto game_type = state.new_usertype("game_"); state["game"] = game(); - for (auto const& func : gsc::cxt->func_map()) + for (auto const& func : gsc::gsc_ctx->func_map()) { const auto name = std::string(func.first); game_type[name] = [name](const game&, const sol::this_state s, sol::variadic_args va)