Use gsc-tool tokens
This commit is contained in:
parent
c72cfe510d
commit
34e3a57b57
2
deps/gsc-tool-h2
vendored
2
deps/gsc-tool-h2
vendored
@ -1 +1 @@
|
|||||||
Subproject commit b18d79c1da68c8bd97bbba91b72321a1302e651f
|
Subproject commit 77170a40a6558bb6f54c6d796f1574ba2de497a3
|
@ -428,15 +428,15 @@ namespace gsc
|
|||||||
auto function_id_start = 0x320;
|
auto function_id_start = 0x320;
|
||||||
void add_function(const std::string& name, scripting::script_function function)
|
void add_function(const std::string& name, scripting::script_function function)
|
||||||
{
|
{
|
||||||
if (scripting::function_map.find(name) != scripting::function_map.end())
|
if (xsk::gsc::h2::resolver::find_function(name))
|
||||||
{
|
{
|
||||||
const auto id = scripting::function_map[name];
|
const auto id = xsk::gsc::h2::resolver::function_id(name);
|
||||||
functions[function] = id;
|
functions[function] = id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto id = ++function_id_start;
|
const auto id = ++function_id_start;
|
||||||
scripting::function_map[name] = id;
|
xsk::gsc::h2::resolver::add_function(name, static_cast<std::uint16_t>(id));
|
||||||
functions[function] = id;
|
functions[function] = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -512,25 +512,6 @@ namespace gsc
|
|||||||
{
|
{
|
||||||
developer_script = dvars::register_bool("developer_script", false, 0, "Print GSC errors");
|
developer_script = dvars::register_bool("developer_script", false, 0, "Print GSC errors");
|
||||||
|
|
||||||
// wait for other tokens to be added
|
|
||||||
scheduler::once([]()
|
|
||||||
{
|
|
||||||
for (const auto& function : scripting::function_map)
|
|
||||||
{
|
|
||||||
xsk::gsc::h2::resolver::add_function(function.first, static_cast<std::uint16_t>(function.second));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& method : scripting::method_map)
|
|
||||||
{
|
|
||||||
xsk::gsc::h2::resolver::add_method(method.first, static_cast<std::uint16_t>(method.second));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& token : scripting::token_map)
|
|
||||||
{
|
|
||||||
xsk::gsc::h2::resolver::add_token(token.first, static_cast<std::uint16_t>(token.second));
|
|
||||||
}
|
|
||||||
}, scheduler::pipeline::main);
|
|
||||||
|
|
||||||
utils::hook::call(0x1405C6177, find_script);
|
utils::hook::call(0x1405C6177, find_script);
|
||||||
utils::hook::call(0x1405C6187, db_is_xasset_default);
|
utils::hook::call(0x1405C6187, db_is_xasset_default);
|
||||||
|
|
||||||
|
@ -11,6 +11,10 @@
|
|||||||
#include "command.hpp"
|
#include "command.hpp"
|
||||||
#include "game/scripting/functions.hpp"
|
#include "game/scripting/functions.hpp"
|
||||||
|
|
||||||
|
#include <xsk/gsc/types.hpp>
|
||||||
|
#include <xsk/resolver.hpp>
|
||||||
|
#include <xsk/utils/compression.hpp>
|
||||||
|
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
#include <utils/concurrency.hpp>
|
#include <utils/concurrency.hpp>
|
||||||
#include <utils/string.hpp>
|
#include <utils/string.hpp>
|
||||||
@ -169,13 +173,14 @@ namespace mapents
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto key_ = key.substr(1, key.size() - 2);
|
const auto key_ = key.substr(1, key.size() - 2);
|
||||||
if (scripting::token_map.find(key_) == scripting::token_map.end())
|
const auto id = xsk::gsc::h2::resolver::token_id(key_);
|
||||||
|
if (id == 0)
|
||||||
{
|
{
|
||||||
console::warn("[addon_map_ents parser] Key '%s' not found, on line %i", key_.data(), line_index);
|
console::warn("[addon_map_ents parser] Key '%s' not found, on line %i", key_.data(), line_index);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_buffer.append(utils::string::va("%i \"%s\"\n", scripting::token_map[key_], value.data()));
|
out_buffer.append(utils::string::va("%i \"%s\"\n", id, value.data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return out_buffer;
|
return out_buffer;
|
||||||
@ -288,13 +293,13 @@ namespace mapents
|
|||||||
{
|
{
|
||||||
const auto id = token_id_start++;
|
const auto id = token_id_start++;
|
||||||
custom_fields[id] = type;
|
custom_fields[id] = type;
|
||||||
scripting::token_map[name] = id;
|
xsk::gsc::h2::resolver::add_token(name, static_cast<std::uint16_t>(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_field(const std::string& name, game::scriptType_e type, unsigned int id)
|
void add_field(const std::string& name, game::scriptType_e type, unsigned int id)
|
||||||
{
|
{
|
||||||
custom_fields[id] = type;
|
custom_fields[id] = type;
|
||||||
scripting::token_map[name] = id;
|
xsk::gsc::h2::resolver::add_token(name, static_cast<std::uint16_t>(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
utils::hook::detour scr_find_field_hook;
|
utils::hook::detour scr_find_field_hook;
|
||||||
@ -334,15 +339,8 @@ namespace mapents
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto id = static_cast<unsigned int>(std::atoi(line.substr(0, first_space).data()));
|
const auto id = static_cast<unsigned int>(std::atoi(line.substr(0, first_space).data()));
|
||||||
std::string key = std::to_string(id);
|
const auto token = xsk::gsc::h2::resolver::token_name(static_cast<std::uint16_t>(id));
|
||||||
for (const auto& [token, value] : scripting::token_map)
|
const auto key = "\"" + token + "\"";
|
||||||
{
|
|
||||||
if (value == id)
|
|
||||||
{
|
|
||||||
key = "\"" + token + "\"";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto new_line = key + line.substr(first_space);
|
const auto new_line = key + line.substr(first_space);
|
||||||
buffer.append(new_line);
|
buffer.append(new_line);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -3,57 +3,36 @@
|
|||||||
|
|
||||||
#include "../../component/gsc.hpp"
|
#include "../../component/gsc.hpp"
|
||||||
|
|
||||||
|
#include <xsk/gsc/types.hpp>
|
||||||
|
#include <xsk/resolver.hpp>
|
||||||
|
#include <xsk/utils/compression.hpp>
|
||||||
|
|
||||||
#include <utils/string.hpp>
|
#include <utils/string.hpp>
|
||||||
|
|
||||||
namespace scripting
|
namespace scripting
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::unordered_map<std::string, unsigned> lowercase_map(
|
|
||||||
const std::unordered_map<std::string, unsigned>& old_map)
|
|
||||||
{
|
|
||||||
std::unordered_map<std::string, unsigned> new_map{};
|
|
||||||
for (auto& entry : old_map)
|
|
||||||
{
|
|
||||||
new_map[utils::string::to_lower(entry.first)] = entry.second;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new_map;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::unordered_map<std::string, unsigned>& get_methods()
|
|
||||||
{
|
|
||||||
static auto methods = lowercase_map(method_map);
|
|
||||||
return methods;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::unordered_map<std::string, unsigned>& get_functions()
|
|
||||||
{
|
|
||||||
static auto function = lowercase_map(function_map);
|
|
||||||
return function;
|
|
||||||
}
|
|
||||||
|
|
||||||
int find_function_index(const std::string& name, const bool prefer_global)
|
int find_function_index(const std::string& name, const bool prefer_global)
|
||||||
{
|
{
|
||||||
const auto target = utils::string::to_lower(name);
|
const auto target = utils::string::to_lower(name);
|
||||||
|
auto first = xsk::gsc::h2::resolver::function_id;
|
||||||
const auto& primary_map = prefer_global
|
auto second = xsk::gsc::h2::resolver::method_id;
|
||||||
? get_functions()
|
if (!prefer_global)
|
||||||
: 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())
|
|
||||||
{
|
{
|
||||||
return function_entry->second;
|
std::swap(first, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
function_entry = secondary_map.find(target);
|
const auto first_res = first(target);
|
||||||
if (function_entry != secondary_map.end())
|
if (first_res)
|
||||||
{
|
{
|
||||||
return function_entry->second;
|
return first_res;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto second_res = second(target);
|
||||||
|
if (second_res)
|
||||||
|
{
|
||||||
|
return second_res;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -79,11 +58,6 @@ namespace scripting
|
|||||||
return static_cast<unsigned int>(std::strtol(name.substr(3).data(), nullptr, 10));
|
return static_cast<unsigned int>(std::strtol(name.substr(3).data(), nullptr, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name.starts_with("_id_"))
|
|
||||||
{
|
|
||||||
return static_cast<unsigned int>(std::strtol(name.substr(4).data(), nullptr, 16));
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,43 +66,24 @@ namespace scripting
|
|||||||
{
|
{
|
||||||
std::vector<std::string> results;
|
std::vector<std::string> results;
|
||||||
|
|
||||||
results.push_back(utils::string::va("_id_%X", id));
|
|
||||||
results.push_back(utils::string::va("_ID%i", id));
|
results.push_back(utils::string::va("_ID%i", id));
|
||||||
|
results.push_back(utils::string::va("_id_%04X", id));
|
||||||
for (const auto& token : token_map)
|
results.push_back(xsk::gsc::h2::resolver::token_name(static_cast<std::uint16_t>(id)));
|
||||||
{
|
|
||||||
if (token.second == id)
|
|
||||||
{
|
|
||||||
results.push_back(token.first);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string find_token_single(unsigned int id)
|
std::string find_token_single(unsigned int id)
|
||||||
{
|
{
|
||||||
std::vector<std::string> results;
|
return xsk::gsc::h2::resolver::token_name(static_cast<std::uint16_t>(id));
|
||||||
|
|
||||||
for (const auto& token : token_map)
|
|
||||||
{
|
|
||||||
if (token.second == id)
|
|
||||||
{
|
|
||||||
return token.first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return utils::string::va("_id_%X", id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int find_token_id(const std::string& name)
|
unsigned int find_token_id(const std::string& name)
|
||||||
{
|
{
|
||||||
const auto result = token_map.find(name);
|
const auto id = xsk::gsc::h2::resolver::token_id(name);
|
||||||
|
if (id != 0)
|
||||||
if (result != token_map.end())
|
|
||||||
{
|
{
|
||||||
return result->second;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto parsed_id = parse_token_id(name);
|
const auto parsed_id = parse_token_id(name);
|
||||||
@ -143,7 +98,10 @@ namespace scripting
|
|||||||
script_function find_function(const std::string& name, const bool prefer_global)
|
script_function find_function(const std::string& name, const bool prefer_global)
|
||||||
{
|
{
|
||||||
const auto index = find_function_index(name, 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);
|
return get_function_by_index(index);
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,6 @@
|
|||||||
|
|
||||||
namespace scripting
|
namespace scripting
|
||||||
{
|
{
|
||||||
extern std::unordered_map<std::string, unsigned> method_map;
|
|
||||||
extern std::unordered_map<std::string, unsigned> function_map;
|
|
||||||
extern std::unordered_map<std::string, unsigned> token_map;
|
|
||||||
extern std::unordered_map<unsigned, std::string> file_list;
|
|
||||||
|
|
||||||
using script_function = void(*)(game::scr_entref_t);
|
using script_function = void(*)(game::scr_entref_t);
|
||||||
|
|
||||||
std::vector<std::string> find_token(unsigned int id);
|
std::vector<std::string> find_token(unsigned int id);
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
|
|
||||||
#include "game/ui_scripting/execution.hpp"
|
#include "game/ui_scripting/execution.hpp"
|
||||||
|
|
||||||
|
#include <xsk/gsc/types.hpp>
|
||||||
|
#include <xsk/resolver.hpp>
|
||||||
|
#include <xsk/utils/compression.hpp>
|
||||||
|
|
||||||
#include <utils/string.hpp>
|
#include <utils/string.hpp>
|
||||||
#include <utils/io.hpp>
|
#include <utils/io.hpp>
|
||||||
#include <utils/nt.hpp>
|
#include <utils/nt.hpp>
|
||||||
@ -336,9 +340,10 @@ namespace scripting::lua
|
|||||||
|
|
||||||
auto entity_type = state.new_usertype<entity>("entity");
|
auto entity_type = state.new_usertype<entity>("entity");
|
||||||
|
|
||||||
for (const auto& func : method_map)
|
for (const auto& func : xsk::gsc::h2::resolver::get_methods())
|
||||||
{
|
{
|
||||||
const auto name = utils::string::to_lower(func.first);
|
const auto func_name = std::string(func.first);
|
||||||
|
const auto name = utils::string::to_lower(func_name);
|
||||||
entity_type[name.data()] = [name](const entity& entity, const sol::this_state s, sol::variadic_args va)
|
entity_type[name.data()] = [name](const entity& entity, const sol::this_state s, sol::variadic_args va)
|
||||||
{
|
{
|
||||||
std::vector<script_value> arguments{};
|
std::vector<script_value> arguments{};
|
||||||
@ -469,9 +474,10 @@ namespace scripting::lua
|
|||||||
auto game_type = state.new_usertype<game>("game_");
|
auto game_type = state.new_usertype<game>("game_");
|
||||||
state["game"] = game();
|
state["game"] = game();
|
||||||
|
|
||||||
for (const auto& func : function_map)
|
for (const auto& func : xsk::gsc::h2::resolver::get_functions())
|
||||||
{
|
{
|
||||||
const auto name = utils::string::to_lower(func.first);
|
const auto func_name = std::string(func.first);
|
||||||
|
const auto name = utils::string::to_lower(func_name);
|
||||||
game_type[name] = [name](const game&, const sol::this_state s, sol::variadic_args va)
|
game_type[name] = [name](const game&, const sol::this_state s, sol::variadic_args va)
|
||||||
{
|
{
|
||||||
std::vector<script_value> arguments{};
|
std::vector<script_value> arguments{};
|
||||||
|
Loading…
Reference in New Issue
Block a user