mirror of
https://github.com/fedddddd/iw5-gsc-utils.git
synced 2025-04-20 04:55:43 +00:00
Fix for pluto update
This commit is contained in:
parent
3a492f51d9
commit
a7576ea765
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -8,3 +8,9 @@
|
||||
path = deps/json
|
||||
url = https://github.com/nlohmann/json.git
|
||||
branch = develop
|
||||
[submodule "deps/gsc-tool"]
|
||||
path = deps/gsc-tool
|
||||
url = https://github.com/xensik/gsc-tool.git
|
||||
[submodule "deps/zlib"]
|
||||
path = deps/zlib
|
||||
url = https://github.com/madler/zlib.git
|
||||
|
1
deps/gsc-tool
vendored
Submodule
1
deps/gsc-tool
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit a8a62c2667ca1c2643798a6c88e39a9e5a30df86
|
62
deps/premake/gsc-tool.lua
vendored
Normal file
62
deps/premake/gsc-tool.lua
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
gsc_tool = {
|
||||
source = path.join(dependencies.basePath, "gsc-tool"),
|
||||
}
|
||||
|
||||
function gsc_tool.import()
|
||||
links { "xsk-gsc-iw5-pc", "xsk-gsc-utils" }
|
||||
gsc_tool.includes()
|
||||
end
|
||||
|
||||
function gsc_tool.includes()
|
||||
includedirs {
|
||||
path.join(gsc_tool.source, "include"),
|
||||
}
|
||||
end
|
||||
|
||||
function gsc_tool.project()
|
||||
project "xsk-gsc-utils"
|
||||
kind "StaticLib"
|
||||
language "C++"
|
||||
|
||||
files {
|
||||
path.join(gsc_tool.source, "include/xsk/utils/*.hpp"),
|
||||
path.join(gsc_tool.source, "src/utils/*.cpp"),
|
||||
}
|
||||
|
||||
includedirs {
|
||||
path.join(gsc_tool.source, "include"),
|
||||
}
|
||||
|
||||
zlib.includes()
|
||||
|
||||
project "xsk-gsc-iw5-pc"
|
||||
kind "StaticLib"
|
||||
language "C++"
|
||||
|
||||
filter "action:vs*"
|
||||
buildoptions "/Zc:__cplusplus"
|
||||
filter {}
|
||||
|
||||
files {
|
||||
path.join(gsc_tool.source, "include/xsk/stdinc.hpp"),
|
||||
|
||||
path.join(gsc_tool.source, "include/xsk/gsc/engine/iw5_pc.hpp"),
|
||||
path.join(gsc_tool.source, "src/gsc/engine/iw5_pc.cpp"),
|
||||
|
||||
path.join(gsc_tool.source, "src/gsc/engine/iw5_pc_code.cpp"),
|
||||
path.join(gsc_tool.source, "src/gsc/engine/iw5_pc_func.cpp"),
|
||||
path.join(gsc_tool.source, "src/gsc/engine/iw5_pc_meth.cpp"),
|
||||
path.join(gsc_tool.source, "src/gsc/engine/iw5_pc_token.cpp"),
|
||||
|
||||
path.join(gsc_tool.source, "src/gsc/*.cpp"),
|
||||
|
||||
path.join(gsc_tool.source, "src/gsc/common/*.cpp"),
|
||||
path.join(gsc_tool.source, "include/xsk/gsc/common/*.hpp"),
|
||||
}
|
||||
|
||||
includedirs {
|
||||
path.join(gsc_tool.source, "include"),
|
||||
}
|
||||
end
|
||||
|
||||
table.insert(dependencies, gsc_tool)
|
39
deps/premake/zlib.lua
vendored
Normal file
39
deps/premake/zlib.lua
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
zlib = {
|
||||
source = path.join(dependencies.basePath, "zlib"),
|
||||
}
|
||||
|
||||
function zlib.import()
|
||||
links { "zlib" }
|
||||
zlib.includes()
|
||||
end
|
||||
|
||||
function zlib.includes()
|
||||
includedirs {
|
||||
zlib.source
|
||||
}
|
||||
|
||||
defines {
|
||||
"ZLIB_CONST",
|
||||
}
|
||||
end
|
||||
|
||||
function zlib.project()
|
||||
project "zlib"
|
||||
language "C"
|
||||
|
||||
zlib.includes()
|
||||
|
||||
files {
|
||||
path.join(zlib.source, "*.h"),
|
||||
path.join(zlib.source, "*.c"),
|
||||
}
|
||||
|
||||
defines {
|
||||
"_CRT_SECURE_NO_DEPRECATE",
|
||||
}
|
||||
|
||||
warnings "Off"
|
||||
kind "StaticLib"
|
||||
end
|
||||
|
||||
table.insert(dependencies, zlib)
|
1
deps/zlib
vendored
Submodule
1
deps/zlib
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 04f42ceca40f73e2978b50e93806c2a18c1281fc
|
@ -1,3 +1,4 @@
|
||||
@echo off
|
||||
call git submodule update --init --recursive
|
||||
tools\windows\premake5.exe vs2022
|
||||
pause
|
@ -21,7 +21,7 @@ namespace gsc
|
||||
{
|
||||
std::string method_name(unsigned int id)
|
||||
{
|
||||
const auto& map = *game::plutonium::method_map_rev;
|
||||
const auto& map = (*game::plutonium::gsc_ctx)->meth_map();
|
||||
|
||||
for (const auto& function : map)
|
||||
{
|
||||
@ -36,7 +36,7 @@ namespace gsc
|
||||
|
||||
std::string function_name(unsigned int id)
|
||||
{
|
||||
const auto& map = *game::plutonium::function_map_rev;
|
||||
const auto& map = (*game::plutonium::gsc_ctx)->func_map();
|
||||
|
||||
for (const auto& function : map)
|
||||
{
|
||||
@ -247,24 +247,34 @@ namespace gsc
|
||||
namespace function
|
||||
{
|
||||
void add(const std::string& name, const script_function& func)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto index = function_map_start++;
|
||||
|
||||
functions[index] = func;
|
||||
const auto name_view = utils::memory::get_allocator()->duplicate_string(name);
|
||||
(*game::plutonium::function_map_rev)[name_view] = index;
|
||||
(*game::plutonium::gsc_ctx)->func_add(name, index);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
printf("[iw5-gsc-utils] failed to add function \"%s\": %s\n", name.data(), e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace method
|
||||
{
|
||||
void add(const std::string& name, const script_method& func)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto index = method_map_start++;
|
||||
|
||||
methods[index] = func;
|
||||
const auto name_view = utils::memory::get_allocator()->duplicate_string(name);
|
||||
(*game::plutonium::method_map_rev)[name_view] = index;
|
||||
(*game::plutonium::gsc_ctx)->meth_add(name, index);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
printf("[iw5-gsc-utils] failed to add method \"%s\": %s\n", name.data(), e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,25 +284,13 @@ namespace gsc
|
||||
const std::function<scripting::script_value(unsigned int entnum)>& getter,
|
||||
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter)
|
||||
{
|
||||
uint16_t token_id{};
|
||||
auto& token_map = *game::plutonium::token_map_rev;
|
||||
if (token_map.find(name) != token_map.end())
|
||||
{
|
||||
token_id = token_map.at(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
token_id = token_map_start++;
|
||||
token_map.insert(std::make_pair(name, token_id));
|
||||
}
|
||||
|
||||
const auto offset = field_offset_start++;
|
||||
custom_fields[classnum][offset] = {name, getter, setter};
|
||||
|
||||
post_load_callbacks.push_back([classnum, name, token_id, offset]()
|
||||
post_load_callbacks.push_back([=]()
|
||||
{
|
||||
const auto name_str = game::SL_GetString(name.data(), 0);
|
||||
game::Scr_AddClassField(classnum, name_str, token_id, offset);
|
||||
game::Scr_AddClassField(classnum, name_str, game::SL_GetCanonicalString(name.data()), offset);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -61,18 +61,16 @@ namespace signatures
|
||||
return find_string_ptr({bytes, 4});
|
||||
}
|
||||
|
||||
bool process_maps()
|
||||
bool process_gsc_ctx()
|
||||
{
|
||||
const auto string_ref = find_string_ref("couldn't resolve builtin function id for name '%s'!");
|
||||
const auto string_ref = find_string_ref("in call to builtin %s");
|
||||
if (!string_ref)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto map_ptr = *reinterpret_cast<size_t*>(string_ref - 0x2B);
|
||||
game::plutonium::function_map_rev.set(map_ptr);
|
||||
game::plutonium::method_map_rev.set(map_ptr + 0x20);
|
||||
game::plutonium::token_map_rev.set(map_ptr + 0xBC);
|
||||
const auto gsc_ctx_ptr = *reinterpret_cast<size_t*>(string_ref - 0x8C);
|
||||
game::plutonium::gsc_ctx.set(gsc_ctx_ptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -93,6 +91,6 @@ namespace signatures
|
||||
bool process()
|
||||
{
|
||||
load_function_tables();
|
||||
return process_printf() && process_maps();
|
||||
return process_printf() && process_gsc_ctx();
|
||||
}
|
||||
}
|
||||
|
@ -7,51 +7,20 @@ namespace scripting
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::unordered_map<std::string, uint16_t> lowercase_map(
|
||||
const std::unordered_map<std::string_view, uint16_t>& old_map)
|
||||
{
|
||||
std::unordered_map<std::string, uint16_t> new_map{};
|
||||
for (auto& entry : old_map)
|
||||
{
|
||||
new_map[utils::string::to_lower(entry.first.data())] = entry.second;
|
||||
}
|
||||
|
||||
return new_map;
|
||||
}
|
||||
|
||||
const std::unordered_map<std::string, uint16_t>& get_methods()
|
||||
{
|
||||
static auto methods = lowercase_map(*game::plutonium::method_map_rev);
|
||||
return methods;
|
||||
}
|
||||
|
||||
const std::unordered_map<std::string, uint16_t>& get_functions()
|
||||
{
|
||||
static auto function = lowercase_map(*game::plutonium::function_map_rev);
|
||||
return function;
|
||||
}
|
||||
|
||||
int find_function_index(const std::string& name, const bool prefer_global)
|
||||
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 = (*game::plutonium::gsc_ctx)->func_map();
|
||||
auto const& second = (*game::plutonium::gsc_ctx)->meth_map();
|
||||
|
||||
const auto& primary_map = prefer_global
|
||||
? get_functions()
|
||||
: get_methods();
|
||||
const auto& secondary_map = !prefer_global
|
||||
? get_functions()
|
||||
: get_methods();
|
||||
|
||||
auto function_entry = primary_map.find(target);
|
||||
if (function_entry != primary_map.end())
|
||||
if (const auto itr = first.find(name); itr != first.end())
|
||||
{
|
||||
return function_entry->second;
|
||||
return static_cast<int>(itr->second);
|
||||
}
|
||||
|
||||
function_entry = secondary_map.find(target);
|
||||
if (function_entry != secondary_map.end())
|
||||
if (const auto itr = second.find(name); itr != second.end())
|
||||
{
|
||||
return function_entry->second;
|
||||
return static_cast<int>(itr->second);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -73,16 +42,7 @@ namespace scripting
|
||||
|
||||
std::string find_token(unsigned int id)
|
||||
{
|
||||
const auto& token_map = *game::plutonium::token_map_rev;
|
||||
for (const auto& token : token_map)
|
||||
{
|
||||
if (token.second == id)
|
||||
{
|
||||
return token.first;
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
return (*game::plutonium::gsc_ctx)->token_name(id);
|
||||
}
|
||||
|
||||
std::string find_file(unsigned int id)
|
||||
@ -92,21 +52,16 @@ namespace scripting
|
||||
|
||||
int find_token_id(const std::string& name)
|
||||
{
|
||||
const auto& token_map = *game::plutonium::token_map_rev;
|
||||
const auto result = token_map.find(name);
|
||||
|
||||
if (result != token_map.end())
|
||||
{
|
||||
return result->second;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return (*game::plutonium::gsc_ctx)->token_id(name);
|
||||
}
|
||||
|
||||
script_function find_function(const std::string& name, const bool prefer_global)
|
||||
{
|
||||
const auto index = find_function_index(name, prefer_global);
|
||||
if (index < 0) return nullptr;
|
||||
if (index < 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return get_function_by_index(index);
|
||||
}
|
||||
|
@ -86,9 +86,7 @@ namespace game
|
||||
|
||||
namespace plutonium
|
||||
{
|
||||
WEAK symbol<std::unordered_map<std::string_view, std::uint16_t>> function_map_rev{0};
|
||||
WEAK symbol<std::unordered_map<std::string_view, std::uint16_t>> method_map_rev{0};
|
||||
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> token_map_rev{0};
|
||||
WEAK symbol<std::unique_ptr<xsk::gsc::iw5_pc::context>> gsc_ctx{0};
|
||||
WEAK symbol<int(const char* fmt, ...)> printf{0};
|
||||
WEAK symbol<void*> function_table{0};
|
||||
WEAK symbol<void*> method_table{0};
|
||||
|
@ -8,6 +8,8 @@
|
||||
#pragma warning(disable: 4996)
|
||||
#pragma warning(disable: 26812)
|
||||
|
||||
#include <xsk/gsc/engine/iw5_pc.hpp>
|
||||
|
||||
#define DLL_EXPORT extern "C" __declspec(dllexport)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
@ -37,6 +39,7 @@ using namespace std::literals;
|
||||
#include <gsl/gsl>
|
||||
#include <MinHook.h>
|
||||
|
||||
|
||||
#include "utils/memory.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/hook.hpp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user