mirror of
https://github.com/fedddddd/iw5-gsc-utils.git
synced 2025-07-03 09:41:51 +00:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
3a492f51d9 | |||
d4ba37cde5 | |||
2ded4c6a2a | |||
24b3a9369e | |||
1d94fdd88d | |||
0af6b1cb13 | |||
d72c6f7057 | |||
39b9e7e352 | |||
36fefa6bb5 |
@ -21,13 +21,13 @@ namespace gsc
|
|||||||
{
|
{
|
||||||
std::string method_name(unsigned int id)
|
std::string method_name(unsigned int id)
|
||||||
{
|
{
|
||||||
const auto map = *game::plutonium::method_map_rev;
|
const auto& map = *game::plutonium::method_map_rev;
|
||||||
|
|
||||||
for (const auto& function : map)
|
for (const auto& function : map)
|
||||||
{
|
{
|
||||||
if (function.second == id)
|
if (function.second == id)
|
||||||
{
|
{
|
||||||
return function.first;
|
return function.first.data();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,13 +36,13 @@ namespace gsc
|
|||||||
|
|
||||||
std::string function_name(unsigned int id)
|
std::string function_name(unsigned int id)
|
||||||
{
|
{
|
||||||
const auto map = *game::plutonium::function_map_rev;
|
const auto& map = *game::plutonium::function_map_rev;
|
||||||
|
|
||||||
for (const auto& function : map)
|
for (const auto& function : map)
|
||||||
{
|
{
|
||||||
if (function.second == id)
|
if (function.second == id)
|
||||||
{
|
{
|
||||||
return function.first;
|
return function.first.data();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ namespace gsc
|
|||||||
return scr_get_object_field_hook.invoke<void>(classnum, entnum, offset);
|
return scr_get_object_field_hook.invoke<void>(classnum, entnum, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto field = custom_fields[classnum][offset];
|
const auto& field = custom_fields[classnum][offset];
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -217,7 +217,7 @@ namespace gsc
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto args = get_arguments();
|
const auto args = get_arguments();
|
||||||
const auto field = custom_fields[classnum][offset];
|
const auto& field = custom_fields[classnum][offset];
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -251,7 +251,8 @@ namespace gsc
|
|||||||
const auto index = function_map_start++;
|
const auto index = function_map_start++;
|
||||||
|
|
||||||
functions[index] = func;
|
functions[index] = func;
|
||||||
(*game::plutonium::function_map_rev)[name] = index;
|
const auto name_view = utils::memory::get_allocator()->duplicate_string(name);
|
||||||
|
(*game::plutonium::function_map_rev)[name_view] = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +263,8 @@ namespace gsc
|
|||||||
const auto index = method_map_start++;
|
const auto index = method_map_start++;
|
||||||
|
|
||||||
methods[index] = func;
|
methods[index] = func;
|
||||||
(*game::plutonium::method_map_rev)[name] = index;
|
const auto name_view = utils::memory::get_allocator()->duplicate_string(name);
|
||||||
|
(*game::plutonium::method_map_rev)[name_view] = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,11 +274,20 @@ namespace gsc
|
|||||||
const std::function<scripting::script_value(unsigned int entnum)>& getter,
|
const std::function<scripting::script_value(unsigned int entnum)>& getter,
|
||||||
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter)
|
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter)
|
||||||
{
|
{
|
||||||
const auto token_id = token_map_start++;
|
uint16_t token_id{};
|
||||||
const auto offset = field_offset_start++;
|
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};
|
custom_fields[classnum][offset] = {name, getter, setter};
|
||||||
(*game::plutonium::token_map_rev)[name] = token_id;
|
|
||||||
|
|
||||||
post_load_callbacks.push_back([classnum, name, token_id, offset]()
|
post_load_callbacks.push_back([classnum, name, token_id, offset]()
|
||||||
{
|
{
|
||||||
@ -320,7 +331,7 @@ namespace gsc
|
|||||||
scr_set_object_field_hook.create(0x52BCC0, scr_set_object_field_stub);
|
scr_set_object_field_hook.create(0x52BCC0, scr_set_object_field_stub);
|
||||||
scr_post_load_scripts_hook.create(0x628B50, scr_post_load_scripts_stub);
|
scr_post_load_scripts_hook.create(0x628B50, scr_post_load_scripts_stub);
|
||||||
|
|
||||||
field::add(classid::entity, "flags",
|
field::add(classid::entity, "entityflags",
|
||||||
[](unsigned int entnum) -> scripting::script_value
|
[](unsigned int entnum) -> scripting::script_value
|
||||||
{
|
{
|
||||||
const auto entity = &game::g_entities[entnum];
|
const auto entity = &game::g_entities[entnum];
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
#include "signatures.hpp"
|
#include "signatures.hpp"
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
|
|
||||||
#define PAYLOAD_SIZE 0x20000000
|
|
||||||
|
|
||||||
namespace signatures
|
namespace signatures
|
||||||
{
|
{
|
||||||
size_t load_image_size()
|
size_t load_image_size()
|
||||||
@ -34,7 +32,8 @@ namespace signatures
|
|||||||
{
|
{
|
||||||
const char* string_ptr = nullptr;
|
const char* string_ptr = nullptr;
|
||||||
std::string mask(string.size(), 'x');
|
std::string mask(string.size(), 'x');
|
||||||
utils::hook::signature signature(PAYLOAD_SIZE, get_image_size() - PAYLOAD_SIZE);
|
const auto base = reinterpret_cast<size_t>(GetModuleHandle("plutonium-bootstrapper-win32.exe"));
|
||||||
|
utils::hook::signature signature(base, get_image_size() - base);
|
||||||
|
|
||||||
signature.add({
|
signature.add({
|
||||||
string,
|
string,
|
||||||
@ -53,36 +52,27 @@ namespace signatures
|
|||||||
{
|
{
|
||||||
char bytes[4] = {0};
|
char bytes[4] = {0};
|
||||||
const auto string_ptr = find_string_ptr(string);
|
const auto string_ptr = find_string_ptr(string);
|
||||||
memcpy(bytes, &string_ptr, sizeof(size_t));
|
if (!string_ptr)
|
||||||
return find_string_ptr(bytes);
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::memcpy(bytes, &string_ptr, sizeof(bytes));
|
||||||
|
return find_string_ptr({bytes, 4});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool process_maps()
|
bool process_maps()
|
||||||
{
|
{
|
||||||
const auto string_ref = find_string_ref("Couldn't resolve builtin function id for name '%s'!");
|
const auto string_ref = find_string_ref("couldn't resolve builtin function id for name '%s'!");
|
||||||
if (!string_ref)
|
if (!string_ref)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto map_ptr = *reinterpret_cast<size_t*>(string_ref - 0x3A);
|
const auto map_ptr = *reinterpret_cast<size_t*>(string_ref - 0x2B);
|
||||||
game::plutonium::function_map_rev.set(map_ptr);
|
game::plutonium::function_map_rev.set(map_ptr);
|
||||||
game::plutonium::method_map_rev.set(map_ptr + 0x20);
|
game::plutonium::method_map_rev.set(map_ptr + 0x20);
|
||||||
game::plutonium::file_map_rev.set(map_ptr + 0x40);
|
game::plutonium::token_map_rev.set(map_ptr + 0xBC);
|
||||||
game::plutonium::token_map_rev.set(map_ptr + 0x60);
|
|
||||||
|
|
||||||
for (const auto& function : *game::plutonium::function_map_rev)
|
|
||||||
{
|
|
||||||
utils::io::write_file("functions.txt", function.first, true);
|
|
||||||
utils::io::write_file("functions.txt", "\n", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& function : *game::plutonium::method_map_rev)
|
|
||||||
{
|
|
||||||
utils::io::write_file("methods.txt", function.first, true);
|
|
||||||
utils::io::write_file("methods.txt", "\n", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,13 +86,13 @@ namespace signatures
|
|||||||
|
|
||||||
const auto offset = *reinterpret_cast<size_t*>(string_ref + 5);
|
const auto offset = *reinterpret_cast<size_t*>(string_ref + 5);
|
||||||
game::plutonium::printf.set(string_ref + 4 + 5 + offset);
|
game::plutonium::printf.set(string_ref + 4 + 5 + offset);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool process()
|
bool process()
|
||||||
{
|
{
|
||||||
load_function_tables();
|
load_function_tables();
|
||||||
process_printf();
|
return process_printf() && process_maps();
|
||||||
return process_maps();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,12 @@ namespace scripting
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::unordered_map<std::string, uint16_t> lowercase_map(
|
std::unordered_map<std::string, uint16_t> lowercase_map(
|
||||||
const std::unordered_map<std::string, uint16_t>& old_map)
|
const std::unordered_map<std::string_view, uint16_t>& old_map)
|
||||||
{
|
{
|
||||||
std::unordered_map<std::string, uint16_t> new_map{};
|
std::unordered_map<std::string, uint16_t> new_map{};
|
||||||
for (auto& entry : old_map)
|
for (auto& entry : old_map)
|
||||||
{
|
{
|
||||||
new_map[utils::string::to_lower(entry.first)] = entry.second;
|
new_map[utils::string::to_lower(entry.first.data())] = entry.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new_map;
|
return new_map;
|
||||||
@ -71,20 +71,6 @@ namespace scripting
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string find_file(unsigned int id)
|
|
||||||
{
|
|
||||||
const auto& file_map = *game::plutonium::file_map_rev;
|
|
||||||
for (const auto& file : file_map)
|
|
||||||
{
|
|
||||||
if (file.second == id)
|
|
||||||
{
|
|
||||||
return file.first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string find_token(unsigned int id)
|
std::string find_token(unsigned int id)
|
||||||
{
|
{
|
||||||
const auto& token_map = *game::plutonium::token_map_rev;
|
const auto& token_map = *game::plutonium::token_map_rev;
|
||||||
@ -99,6 +85,11 @@ namespace scripting
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string find_file(unsigned int id)
|
||||||
|
{
|
||||||
|
return find_token(id);
|
||||||
|
}
|
||||||
|
|
||||||
int find_token_id(const std::string& name)
|
int find_token_id(const std::string& name)
|
||||||
{
|
{
|
||||||
const auto& token_map = *game::plutonium::token_map_rev;
|
const auto& token_map = *game::plutonium::token_map_rev;
|
||||||
|
@ -86,9 +86,8 @@ namespace game
|
|||||||
|
|
||||||
namespace plutonium
|
namespace plutonium
|
||||||
{
|
{
|
||||||
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> function_map_rev{0};
|
WEAK symbol<std::unordered_map<std::string_view, std::uint16_t>> function_map_rev{0};
|
||||||
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> method_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>> file_map_rev{0};
|
|
||||||
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> token_map_rev{0};
|
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> token_map_rev{0};
|
||||||
WEAK symbol<int(const char* fmt, ...)> printf{0};
|
WEAK symbol<int(const char* fmt, ...)> printf{0};
|
||||||
WEAK symbol<void*> function_table{0};
|
WEAK symbol<void*> function_table{0};
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
#include <stdinc.hpp>
|
#include <stdinc.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include "io.hpp"
|
||||||
|
|
||||||
namespace utils::io
|
namespace utils::io
|
||||||
{
|
{
|
||||||
|
bool remove_file(const std::string& file)
|
||||||
|
{
|
||||||
|
return DeleteFileA(file.data()) == TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
bool file_exists(const std::string& file)
|
bool file_exists(const std::string& file)
|
||||||
{
|
{
|
||||||
return std::ifstream(file).good();
|
return std::ifstream(file).good();
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
namespace utils::io
|
namespace utils::io
|
||||||
{
|
{
|
||||||
|
bool remove_file(const std::string& file);
|
||||||
bool file_exists(const std::string& file);
|
bool file_exists(const std::string& file);
|
||||||
bool write_file(const std::string& file, const std::string& data, bool append = false);
|
bool write_file(const std::string& file, const std::string& data, bool append = false);
|
||||||
bool read_file(const std::string& file, std::string* data);
|
bool read_file(const std::string& file, std::string* data);
|
||||||
|
Reference in New Issue
Block a user