mirror of
https://github.com/fedddddd/iw5-gsc-utils.git
synced 2026-08-01 12:50:33 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64c1ab0120 | ||
|
|
ad466e020b | ||
|
|
5b4b06cb03 | ||
|
|
04871f2a3d | ||
|
|
0fedd81e1f | ||
|
|
a1d52b9472 | ||
|
|
50438cef27 | ||
|
|
b2bd1e0835 | ||
|
|
e2a5d96e10 | ||
|
|
8d4fa65e3b | ||
|
|
54226a0e56 | ||
|
|
1061c08829 | ||
|
|
c75cf561f7 | ||
|
|
3ea6050498 | ||
|
|
1551d7f1fd |
@@ -8,6 +8,9 @@ on:
|
||||
branches:
|
||||
- "*"
|
||||
types: [opened, synchronize, reopened]
|
||||
concurrency:
|
||||
group: ${{ github.ref }}
|
||||
cancel-in-progress: false
|
||||
jobs:
|
||||
build:
|
||||
name: Build binaries
|
||||
@@ -19,14 +22,14 @@ jobs:
|
||||
- Release
|
||||
steps:
|
||||
- name: Check out files
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
fetch-depth: 0
|
||||
lfs: false
|
||||
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1.3
|
||||
uses: microsoft/setup-msbuild@v2
|
||||
|
||||
- name: Generate project files
|
||||
run: tools/premake5 vs2022
|
||||
@@ -38,8 +41,40 @@ jobs:
|
||||
run: msbuild /m /v:minimal /p:Configuration=${{matrix.configuration}} /p:PlatformTarget=x86 build/iw5-gsc-utils.sln
|
||||
|
||||
- name: Upload ${{matrix.configuration}} binaries
|
||||
uses: actions/upload-artifact@v3.1.0
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{matrix.configuration}} binaries
|
||||
path: |
|
||||
build/bin/${{matrix.configuration}}/iw5-gsc-utils.dll
|
||||
deploy:
|
||||
name: Deploy artifacts
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'push' && (github.ref == 'refs/heads/main')
|
||||
steps:
|
||||
- name: Setup main environment
|
||||
if: github.ref == 'refs/heads/main'
|
||||
run: echo "ALICE_MASTER_PATH=${{ secrets.ALICE_MASTER_SSH_PATH }}" >> $GITHUB_ENV
|
||||
|
||||
- name: Download Release binaries
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: Release binaries
|
||||
|
||||
- name: Install SSH key
|
||||
uses: shimataro/[email protected]
|
||||
with:
|
||||
key: ${{ secrets.ALICE_MASTER_SSH_PRIVATE_KEY }}
|
||||
known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
|
||||
|
||||
- name: Add known hosts
|
||||
run: ssh-keyscan -H ${{ secrets.ALICE_MASTER_SSH_ADDRESS }} >> ~/.ssh/known_hosts
|
||||
|
||||
- name: Remove old data files
|
||||
run: ssh ${{ secrets.ALICE_MASTER_SSH_USER }}@${{ secrets.ALICE_MASTER_SSH_ADDRESS }} rm -rf ${{ env.ALICE_MASTER_PATH }}/iw5-gsc-utils/*
|
||||
|
||||
- name: Upload binary
|
||||
run: rsync -avz iw5-gsc-utils.dll ${{ secrets.ALICE_MASTER_SSH_USER }}@${{ secrets.ALICE_MASTER_SSH_ADDRESS }}:${{ env.ALICE_MASTER_PATH }}/iw5-gsc-utils/
|
||||
|
||||
- name: Publish changes
|
||||
run: ssh ${{ secrets.ALICE_MASTER_SSH_USER }}@${{ secrets.ALICE_MASTER_SSH_ADDRESS }} ${{ secrets.ALICE_MASTER_SSH_CHANGE_PUBLISH_COMMAND }}
|
||||
|
||||
@@ -14,3 +14,6 @@
|
||||
[submodule "deps/zlib"]
|
||||
path = deps/zlib
|
||||
url = https://github.com/madler/zlib.git
|
||||
[submodule "deps/plutonium-sdk"]
|
||||
path = deps/plutonium-sdk
|
||||
url = https://github.com/plutoniummod/plutonium-sdk.git
|
||||
|
||||
@@ -2,22 +2,13 @@
|
||||
|
||||
This plugin adds some useful functions/methods to IW5's GSC VM
|
||||
|
||||
# Installation
|
||||
* Download the latest version [iw5-gsc-utils.dll](https://github.alicent.cat/iw5-gsc-utils/iw5-gsc-utils.dll)
|
||||
* Copy it to `Plutonium/plugins/`
|
||||
|
||||
# Misc
|
||||
|
||||
* `executeCommand(command)`: Executes a console command.
|
||||
* `replaceFunc(what, with)`: Replaces a function with another:
|
||||
|
||||
```c
|
||||
init()
|
||||
{
|
||||
replaceFunc(maps\mp\gametypes\_damage::Callback_PlayerDamage, ::callbackPlayerDamage);
|
||||
}
|
||||
|
||||
callbackPlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, timeOffset)
|
||||
{
|
||||
|
||||
}
|
||||
```
|
||||
* `addCommand(name, callback)`: Adds a console command (gets removed after a map restart):
|
||||
|
||||
```c
|
||||
@@ -44,9 +35,6 @@ This plugin adds some useful functions/methods to IW5's GSC VM
|
||||
}
|
||||
```
|
||||
# Player
|
||||
* `say(message)`: Prints a message to all players' chat.
|
||||
|
||||
* `self tell(message)`: Prints a message to the player's chat.
|
||||
* `self setName(name)`: Sets a player's name.
|
||||
* `self resetName(name)`: Resets a player's name to its original.
|
||||
* `self setClantag(name)`: Sets a player's clantag.
|
||||
@@ -54,28 +42,7 @@ This plugin adds some useful functions/methods to IW5's GSC VM
|
||||
* `self removeClantag(name)`: Removes a player's clantag.
|
||||
# IO
|
||||
|
||||
The basepath for all IO functions is `Plutonium/storage/iw5`
|
||||
|
||||
* `fopen(path, mode)`: Opens a file of given name with given mode, returns a file stream.
|
||||
* `fwrite(stream, text)`: Writes a string to a stream.
|
||||
* `fread(stream)`: Reads entire file.
|
||||
* `fclose(stream)`: Closes a file stream.
|
||||
* `fremove(path)`: Deletes a file.
|
||||
|
||||
```c
|
||||
init()
|
||||
{
|
||||
basePath = getDvar("fs_basegame") + "/";
|
||||
|
||||
file = fopen(basePath + "test.txt", "w");
|
||||
fwrite(file, "test");
|
||||
fclose(file);
|
||||
|
||||
file = fopen(basePath + "test.txt", "r");
|
||||
print(fread(file));
|
||||
fclose(file);
|
||||
}
|
||||
```
|
||||
The basepath for all IO functions is `Plutonium/storage/iw5`.
|
||||
* `fileExists(path)`: Returns true if the file exists.
|
||||
* `writeFile(path, data[, append])`: Creates a file if it doesn't exist and writes/appends text to it.
|
||||
* `readFile(path)`: Reads a file.
|
||||
@@ -86,6 +53,19 @@ The basepath for all IO functions is `Plutonium/storage/iw5`
|
||||
* `listFiles(path)`: Returns the list of files in the directory as an array.
|
||||
* `copyFolder(source, target)`: Copies a folder.
|
||||
|
||||
# HTTP
|
||||
|
||||
* `httpGet(url)`: creates an HTTP request.
|
||||
|
||||
```c
|
||||
init()
|
||||
{
|
||||
req = httpget("http://example.com");
|
||||
req waittill("done", data);
|
||||
print(data);
|
||||
}
|
||||
```
|
||||
|
||||
# JSON
|
||||
|
||||
* `jsonSerialize(variable[, indent])`: Converts GSC variables (such as arrays) into JSON:
|
||||
|
||||
Vendored
+1
-1
Submodule deps/GSL updated: f1a494cfd2...b39e7e4b09
Vendored
-1
Submodule deps/gsc-tool deleted from 0e6238a6ab
Vendored
+1
-1
Submodule deps/json updated: 0457de21cf...d0d29039da
Vendored
+1
-1
Submodule deps/minhook updated: f5485b8454...d94c64d32e
+1
Submodule deps/plutonium-sdk added at 17e9a0a4d5
Vendored
-62
@@ -1,62 +0,0 @@
|
||||
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)
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
plutonium_sdk = {
|
||||
source = path.join(dependencies.basePath, "plutonium-sdk"),
|
||||
}
|
||||
|
||||
function plutonium_sdk.import()
|
||||
plutonium_sdk.includes()
|
||||
end
|
||||
|
||||
function plutonium_sdk.includes()
|
||||
includedirs {
|
||||
plutonium_sdk.source,
|
||||
}
|
||||
end
|
||||
|
||||
function plutonium_sdk.project()
|
||||
end
|
||||
|
||||
table.insert(dependencies, plutonium_sdk)
|
||||
Vendored
-39
@@ -1,39 +0,0 @@
|
||||
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)
|
||||
Vendored
-1
Submodule deps/zlib deleted from e342bb3dae
@@ -8,6 +8,8 @@
|
||||
namespace command
|
||||
{
|
||||
std::unordered_map<std::string, std::function<void(params&)>> handlers;
|
||||
std::vector<std::string> script_commands;
|
||||
utils::memory::allocator allocator;
|
||||
|
||||
void main_handler()
|
||||
{
|
||||
@@ -46,7 +48,11 @@ namespace command
|
||||
|
||||
for (auto i = index; i < this->size(); i++)
|
||||
{
|
||||
if (i > index) result.append(" ");
|
||||
if (i > index)
|
||||
{
|
||||
result.append(" ");
|
||||
}
|
||||
|
||||
result.append(this->get(i));
|
||||
}
|
||||
|
||||
@@ -70,14 +76,11 @@ namespace command
|
||||
handlers[command] = callback;
|
||||
}
|
||||
|
||||
std::vector<std::string> script_commands;
|
||||
utils::memory::allocator allocator;
|
||||
|
||||
void add_script_command(const std::string& name, const std::function<void(const params&)>& callback)
|
||||
{
|
||||
script_commands.push_back(name);
|
||||
const auto _name = allocator.duplicate_string(name);
|
||||
add(_name, callback);
|
||||
const auto name_str = allocator.duplicate_string(name);
|
||||
add(name_str, callback);
|
||||
}
|
||||
|
||||
void clear_script_commands()
|
||||
@@ -95,7 +98,7 @@ namespace command
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
+66
-188
@@ -14,41 +14,8 @@
|
||||
|
||||
namespace gsc
|
||||
{
|
||||
std::unordered_map<unsigned, script_function> functions;
|
||||
std::unordered_map<unsigned, script_method> methods;
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string method_name(unsigned int id)
|
||||
{
|
||||
const auto& map = (*game::plutonium::gsc_ctx)->meth_map();
|
||||
|
||||
for (const auto& function : map)
|
||||
{
|
||||
if (function.second == id)
|
||||
{
|
||||
return function.first.data();
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string function_name(unsigned int id)
|
||||
{
|
||||
const auto& map = (*game::plutonium::gsc_ctx)->func_map();
|
||||
|
||||
for (const auto& function : map)
|
||||
{
|
||||
if (function.second == id)
|
||||
{
|
||||
return function.first.data();
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
function_args get_arguments()
|
||||
{
|
||||
std::vector<scripting::script_value> args;
|
||||
@@ -72,9 +39,6 @@ namespace gsc
|
||||
scripting::push_value(value);
|
||||
}
|
||||
|
||||
auto function_map_start = 0x200;
|
||||
auto method_map_start = 0x8400;
|
||||
auto token_map_start = 0x8000;
|
||||
auto field_offset_start = 0xA000;
|
||||
|
||||
struct entity_field
|
||||
@@ -87,16 +51,11 @@ namespace gsc
|
||||
std::vector<std::function<void()>> post_load_callbacks;
|
||||
std::unordered_map<unsigned int, std::unordered_map<unsigned int, entity_field>> custom_fields;
|
||||
|
||||
void call_function(unsigned int id)
|
||||
void call_function(const script_function* function, const char* name)
|
||||
{
|
||||
if (id < 0x200)
|
||||
{
|
||||
return reinterpret_cast<builtin_function*>(game::plutonium::function_table.get())[id]();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const auto result = functions[id](get_arguments());
|
||||
const auto result = function->operator()(get_arguments());
|
||||
const auto type = result.get_raw().type;
|
||||
|
||||
if (type)
|
||||
@@ -106,23 +65,18 @@ namespace gsc
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
printf("************** Script execution error **************\n");
|
||||
printf("Error executing function %s:\n", function_name(id).data());
|
||||
printf(" %s\n", e.what());
|
||||
printf("****************************************************\n");
|
||||
printf("************** Script execution error **************");
|
||||
printf("Error executing function %s:", name);
|
||||
printf(" %s", e.what());
|
||||
printf("****************************************************");
|
||||
}
|
||||
}
|
||||
|
||||
void call_method(game::scr_entref_t ent, unsigned int id)
|
||||
void call_method(const script_method* method, const char* name, game::scr_entref_t ent)
|
||||
{
|
||||
if (id < 0x8400)
|
||||
{
|
||||
return reinterpret_cast<builtin_method*>(game::plutonium::method_table.get())[id - 0x8000](ent);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
const auto result = methods[id](ent, get_arguments());
|
||||
const auto result = method->operator()(ent, get_arguments());
|
||||
const auto type = result.get_raw().type;
|
||||
|
||||
if (type)
|
||||
@@ -132,55 +86,10 @@ namespace gsc
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
printf("************** Script execution error **************\n");
|
||||
printf("Error executing method %s:\n", method_name(id).data());
|
||||
printf(" %s\n", e.what());
|
||||
printf("****************************************************\n");
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(naked) void call_builtin_stub()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push eax
|
||||
|
||||
mov eax, 0x20B4A5C
|
||||
mov [eax], esi
|
||||
|
||||
mov eax, 0x20B4A90
|
||||
mov [eax], edx
|
||||
|
||||
pop eax
|
||||
|
||||
pushad
|
||||
push eax
|
||||
call call_function
|
||||
pop eax
|
||||
popad
|
||||
|
||||
push 0x56C900
|
||||
retn
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(naked) void call_builtin_method_stub()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
pushad
|
||||
push ecx
|
||||
push ebx
|
||||
call call_method
|
||||
pop ebx
|
||||
pop ecx
|
||||
popad
|
||||
|
||||
push ebx
|
||||
add esp, 0xC
|
||||
|
||||
push 0x56CBE9
|
||||
retn
|
||||
printf("************** Script execution error **************");
|
||||
printf("Error executing method %s:", name);
|
||||
printf(" %s", e.what());
|
||||
printf("****************************************************");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,10 +110,10 @@ namespace gsc
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
printf("************** Script execution error **************\n");
|
||||
printf("Error getting field %s:\n", field.name.data());
|
||||
printf(" %s\n", e.what());
|
||||
printf("****************************************************\n");
|
||||
printf("************** Script execution error **************");
|
||||
printf("Error getting field %s:", field.name.data());
|
||||
printf(" %s", e.what());
|
||||
printf("****************************************************");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,10 +134,10 @@ namespace gsc
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
printf("************** Script execution error **************\n");
|
||||
printf("Error setting field %s:\n", field.name.data());
|
||||
printf(" %s\n", e.what());
|
||||
printf("****************************************************\n");
|
||||
printf("************** Script execution error **************");
|
||||
printf("Error setting field %s:", field.name.data());
|
||||
printf(" %s", e.what());
|
||||
printf("****************************************************");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,48 +153,51 @@ namespace gsc
|
||||
}
|
||||
}
|
||||
|
||||
namespace function
|
||||
void* make_function_thunk(const char* name, const script_function* func)
|
||||
{
|
||||
void add(const std::string& name, const script_function& func)
|
||||
static std::uint8_t bytes[] =
|
||||
{
|
||||
auto index = 0u;
|
||||
auto& ctx = (*game::plutonium::gsc_ctx);
|
||||
0x68, 0x44, 0x33, 0x22, 0x11, // push
|
||||
0x68, 0x44, 0x33, 0x22, 0x11, // push
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, // call
|
||||
0x83, 0xC4, 0x08, // add esp, 8
|
||||
0xC3 // ret
|
||||
};
|
||||
|
||||
if (ctx->func_exists(name))
|
||||
{
|
||||
printf("[iw5-gsc-utils] Warning: function '%s' already defined\n", name.data());
|
||||
index = ctx->func_id(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
index = function_map_start++;
|
||||
ctx->func_add(name, index);
|
||||
const auto stub = utils::memory::allocate_array<std::uint8_t>(sizeof(bytes));
|
||||
std::memcpy(stub, bytes, sizeof(bytes));
|
||||
|
||||
utils::hook::unprotect(stub, sizeof(bytes));
|
||||
|
||||
*reinterpret_cast<std::size_t*>(stub + 1) = reinterpret_cast<size_t>(name);
|
||||
*reinterpret_cast<std::size_t*>(stub + 6) = reinterpret_cast<size_t>(func);
|
||||
utils::hook::call(stub + 10, call_function);
|
||||
|
||||
return stub;
|
||||
}
|
||||
|
||||
functions.insert(std::make_pair(index, func));
|
||||
}
|
||||
}
|
||||
void* make_method_thunk(const char* name, const script_method* func)
|
||||
{
|
||||
static std::uint8_t bytes[] =
|
||||
{
|
||||
0xFF, 0x74, 0x24, 0x04, // push [esp+4]
|
||||
0x68, 0x44, 0x33, 0x22, 0x11, // push
|
||||
0x68, 0x44, 0x33, 0x22, 0x11, // push
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, // call
|
||||
0x83, 0xC4, 0x0C, // add esp, 8
|
||||
0xC3 // ret
|
||||
};
|
||||
|
||||
namespace method
|
||||
{
|
||||
void add(const std::string& name, const script_method& func)
|
||||
{
|
||||
auto index = 0u;
|
||||
auto& ctx = (*game::plutonium::gsc_ctx);
|
||||
const auto stub = utils::memory::allocate_array<std::uint8_t>(sizeof(bytes));
|
||||
std::memcpy(stub, bytes, sizeof(bytes));
|
||||
|
||||
if (ctx->meth_exists(name))
|
||||
{
|
||||
printf("[iw5-gsc-utils] Warning: method '%s' already defined\n", name.data());
|
||||
index = ctx->meth_id(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
index = method_map_start++;
|
||||
ctx->meth_add(name, index);
|
||||
}
|
||||
utils::hook::unprotect(stub, sizeof(bytes));
|
||||
|
||||
methods.insert(std::make_pair(index, func));
|
||||
}
|
||||
*reinterpret_cast<std::size_t*>(stub + 5) = reinterpret_cast<size_t>(name);
|
||||
*reinterpret_cast<std::size_t*>(stub + 10) = reinterpret_cast<size_t>(func);
|
||||
utils::hook::call(stub + 14, call_method);
|
||||
|
||||
return stub;
|
||||
}
|
||||
|
||||
namespace field
|
||||
@@ -333,7 +245,7 @@ namespace gsc
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||
{
|
||||
scr_get_object_field_hook.create(0x52BDB0, scr_get_object_field_stub);
|
||||
scr_set_object_field_hook.create(0x52BCC0, scr_set_object_field_stub);
|
||||
@@ -389,14 +301,6 @@ namespace gsc
|
||||
return {};
|
||||
});
|
||||
|
||||
function::add("say", [](const function_args& args) -> scripting::script_value
|
||||
{
|
||||
const auto message = args[0].as<std::string>();
|
||||
game::SV_GameSendServerCommand(-1, 0, utils::string::va("%c \"%s\"", 84, message.data()));
|
||||
|
||||
return {};
|
||||
});
|
||||
|
||||
function::add("dropallbots", [](const function_args&) -> scripting::script_value
|
||||
{
|
||||
for (auto i = 0; i < *game::svs_clientCount; i++)
|
||||
@@ -411,45 +315,26 @@ namespace gsc
|
||||
return {};
|
||||
});
|
||||
|
||||
method::add("tell", [](const game::scr_entref_t ent, const function_args& args) -> scripting::script_value
|
||||
{
|
||||
if (ent.classnum != 0)
|
||||
{
|
||||
throw std::runtime_error("Invalid entity");
|
||||
}
|
||||
|
||||
const auto client = ent.entnum;
|
||||
|
||||
if (game::g_entities[client].client == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Not a player entity");
|
||||
}
|
||||
|
||||
const auto message = args[0].as<std::string>();
|
||||
game::SV_GameSendServerCommand(client, 0, utils::string::va("%c \"%s\"", 84, message.data()));
|
||||
|
||||
return {};
|
||||
});
|
||||
|
||||
method::add("specialtymarathon", [](const game::scr_entref_t ent, const function_args& args) -> scripting::script_value
|
||||
{
|
||||
if (ent.classnum != 0)
|
||||
{
|
||||
throw std::runtime_error("Invalid entity");
|
||||
throw std::runtime_error("invalid entity");
|
||||
}
|
||||
|
||||
const auto client = ent.entnum;
|
||||
|
||||
if (game::g_entities[client].client == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Not a player entity");
|
||||
throw std::runtime_error("not a player entity");
|
||||
}
|
||||
|
||||
const auto toggle = args[0].as<int>();
|
||||
auto flags = game::g_entities[client].client->ps.perks[0];
|
||||
|
||||
game::g_entities[client].client->ps.perks[0] = toggle
|
||||
? flags | 0x4000u : flags & ~0x4000u;
|
||||
? flags | 0x4000u
|
||||
: flags & ~0x4000u;
|
||||
|
||||
return {};
|
||||
});
|
||||
@@ -458,14 +343,14 @@ namespace gsc
|
||||
{
|
||||
if (ent.classnum != 0)
|
||||
{
|
||||
throw std::runtime_error("Invalid entity");
|
||||
throw std::runtime_error("invalid entity");
|
||||
}
|
||||
|
||||
const auto client = ent.entnum;
|
||||
|
||||
if (game::g_entities[client].client == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Not a player entity");
|
||||
throw std::runtime_error("not a player entity");
|
||||
}
|
||||
|
||||
return game::svs_clients[client].bIsTestClient;
|
||||
@@ -475,25 +360,18 @@ namespace gsc
|
||||
{
|
||||
if (ent.classnum != 0)
|
||||
{
|
||||
throw std::runtime_error("Invalid entity");
|
||||
throw std::runtime_error("invalid entity");
|
||||
}
|
||||
|
||||
const auto client = ent.entnum;
|
||||
|
||||
if (game::g_entities[client].client == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Not a player entity");
|
||||
throw std::runtime_error("not a player entity");
|
||||
}
|
||||
|
||||
return {(game::g_entities[client].client->flags & 4) != 0};
|
||||
});
|
||||
|
||||
// let other plugins read the pointers
|
||||
post_load_callbacks.push_back([]()
|
||||
{
|
||||
utils::hook::jump(0x56C8EB, call_builtin_stub);
|
||||
utils::hook::jump(0x56CBDC, call_builtin_method_stub);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+21
-2
@@ -36,14 +36,33 @@ namespace gsc
|
||||
using script_function = std::function<scripting::script_value(const function_args&)>;
|
||||
using script_method = std::function<scripting::script_value(const game::scr_entref_t, const function_args&)>;
|
||||
|
||||
void* make_function_thunk(const char* name, const script_function* func);
|
||||
void* make_method_thunk(const char* name, const script_method* meth);
|
||||
|
||||
namespace function
|
||||
{
|
||||
void add(const std::string& name, const script_function& func);
|
||||
template <typename F>
|
||||
void add(const std::string& name, F&& f)
|
||||
{
|
||||
const auto name_str = utils::memory::duplicate_string(name);
|
||||
const auto func = new script_function(std::forward<F>(f));
|
||||
const auto thunk = reinterpret_cast<
|
||||
plutonium::sdk::interfaces::gsc::function_callback>(make_function_thunk(name_str, func));
|
||||
plugin::get()->get_interface()->gsc()->register_function(name, thunk);
|
||||
}
|
||||
}
|
||||
|
||||
namespace method
|
||||
{
|
||||
void add(const std::string& name, const script_method& func);
|
||||
template <typename F>
|
||||
void add(const std::string& name, F&& f)
|
||||
{
|
||||
const auto name_str = utils::memory::duplicate_string(name);
|
||||
const auto func = new script_method(std::forward<F>(f));
|
||||
const auto thunk = reinterpret_cast<
|
||||
plutonium::sdk::interfaces::gsc::method_callback>(make_method_thunk(name_str, func));
|
||||
plugin::get()->get_interface()->gsc()->register_method(name, thunk);
|
||||
}
|
||||
}
|
||||
|
||||
namespace field
|
||||
|
||||
+93
-70
@@ -4,85 +4,118 @@
|
||||
#include "scheduler.hpp"
|
||||
#include "gsc.hpp"
|
||||
#include "json.hpp"
|
||||
#include "scripting.hpp"
|
||||
|
||||
namespace io
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct http_request_t
|
||||
{
|
||||
std::string url;
|
||||
bool completed;
|
||||
std::string result;
|
||||
scripting::entity handle;
|
||||
};
|
||||
|
||||
utils::concurrency::container<std::vector<http_request_t>> requests;
|
||||
|
||||
void run_requests()
|
||||
{
|
||||
requests.access([&](std::vector<http_request_t>& r)
|
||||
{
|
||||
for (auto& request : r)
|
||||
{
|
||||
const auto data = utils::http::get_data(request.url.data());
|
||||
if (data.has_value())
|
||||
{
|
||||
request.result = data->substr(0, 0x5000);
|
||||
}
|
||||
else
|
||||
{
|
||||
request.result = "";
|
||||
}
|
||||
|
||||
request.completed = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void check_requests()
|
||||
{
|
||||
requests.access([&](std::vector<http_request_t>& r)
|
||||
{
|
||||
for (auto i = r.begin(); i != r.end(); )
|
||||
{
|
||||
if (!i->completed)
|
||||
{
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
scripting::notify(i->handle, "done", {i->result});
|
||||
i = r.erase(i);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void add_request(const std::string& url, const scripting::entity& handle)
|
||||
{
|
||||
requests.access([&](std::vector<http_request_t>& r)
|
||||
{
|
||||
http_request_t request{};
|
||||
request.handle = handle;
|
||||
request.url = url;
|
||||
request.completed = false;
|
||||
r.emplace_back(request);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
void on_after_dvar_init([[maybe_unused]] plugin::plugin* plugin) override
|
||||
{
|
||||
const auto path = game::Dvar_FindVar("fs_basegame")->current.string;
|
||||
std::filesystem::current_path(path);
|
||||
const auto fs_basegame = game::Dvar_FindVar("fs_basegame");
|
||||
if (fs_basegame == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
printf("working directory: %s", fs_basegame->current.string);
|
||||
std::filesystem::current_path(fs_basegame->current.string);
|
||||
}
|
||||
|
||||
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||
{
|
||||
scheduler::loop(run_requests, scheduler::async);
|
||||
scheduler::loop(check_requests, scheduler::server);
|
||||
|
||||
scripting::on_shutdown([]()
|
||||
{
|
||||
requests.access([&](std::vector<http_request_t>& r)
|
||||
{
|
||||
r.clear();
|
||||
});
|
||||
});
|
||||
|
||||
gsc::function::add("jsonprint", [](const gsc::function_args& args) -> scripting::script_value
|
||||
{
|
||||
std::string buffer;
|
||||
|
||||
for (const auto arg : args.get_raw())
|
||||
for (const auto& arg : args.get_raw())
|
||||
{
|
||||
buffer.append(json::gsc_to_string(arg));
|
||||
buffer.append("\t");
|
||||
}
|
||||
|
||||
printf("%s\n", buffer.data());
|
||||
printf("%s", buffer.data());
|
||||
return {};
|
||||
});
|
||||
|
||||
gsc::function::add("fremove", [](const gsc::function_args& args)
|
||||
{
|
||||
const auto path = args[0].as<const char*>();
|
||||
return std::remove(path);
|
||||
});
|
||||
|
||||
gsc::function::add("fopen", [](const gsc::function_args& args)
|
||||
{
|
||||
const auto* path = args[0].as<const char*>();
|
||||
const auto* mode = args[1].as<const char*>();
|
||||
|
||||
const auto handle = fopen(path, mode);
|
||||
|
||||
if (!handle)
|
||||
{
|
||||
printf("fopen: Invalid path\n");
|
||||
}
|
||||
|
||||
return handle;
|
||||
});
|
||||
|
||||
gsc::function::add("fclose", [](const gsc::function_args& args)
|
||||
{
|
||||
const auto handle = args[0].as_ptr<FILE>();
|
||||
return fclose(handle);
|
||||
});
|
||||
|
||||
gsc::function::add("fwrite", [](const gsc::function_args& args)
|
||||
{
|
||||
const auto handle = args[0].as_ptr<FILE>();
|
||||
const auto text = args[1].as<const char*>();
|
||||
|
||||
return fprintf(handle, text);
|
||||
});
|
||||
|
||||
gsc::function::add("fread", [](const gsc::function_args& args)
|
||||
{
|
||||
const auto handle = args[0].as_ptr<FILE>();
|
||||
|
||||
fseek(handle, 0, SEEK_END);
|
||||
const auto length = ftell(handle);
|
||||
|
||||
fseek(handle, 0, SEEK_SET);
|
||||
char* buffer = (char*)calloc(length, sizeof(char));
|
||||
|
||||
fread(buffer, sizeof(char), length, handle);
|
||||
|
||||
const std::string result = buffer;
|
||||
|
||||
free(buffer);
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
gsc::function::add("fileexists", [](const gsc::function_args& args)
|
||||
{
|
||||
const auto path = args[0].as<std::string>();
|
||||
@@ -161,17 +194,7 @@ namespace io
|
||||
const auto url = args[0].as<std::string>();
|
||||
const auto object = scripting::entity(scripting::make_object());
|
||||
|
||||
scheduler::once([object, url]()
|
||||
{
|
||||
const auto result = utils::http::get_data(url.data());
|
||||
scheduler::once([object, result]()
|
||||
{
|
||||
const auto value = result.has_value()
|
||||
? result.value().substr(0, 0x5000)
|
||||
: "";
|
||||
scripting::notify(object, "done", {value});
|
||||
});
|
||||
}, scheduler::pipeline::async);
|
||||
add_request(url, object);
|
||||
|
||||
return object;
|
||||
});
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace json
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||
{
|
||||
gsc::function::add("array", [](const gsc::function_args& args)
|
||||
{
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
#include <stdinc.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "gsc.hpp"
|
||||
#include "scripting.hpp"
|
||||
|
||||
namespace notifies
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::vector<scripting::function> say_callbacks;
|
||||
utils::hook::detour client_command_hook;
|
||||
|
||||
void client_command_stub(int clientNum)
|
||||
{
|
||||
char cmd[1024] = {0};
|
||||
const auto* entity = &game::g_entities[clientNum];
|
||||
|
||||
if (entity->client == nullptr)
|
||||
{
|
||||
return; // Client is not fully in game yet
|
||||
}
|
||||
|
||||
game::SV_Cmd_ArgvBuffer(0, cmd, 1024);
|
||||
|
||||
auto hidden = false;
|
||||
if (cmd == "say"s || cmd == "say_team"s)
|
||||
{
|
||||
std::string message = game::ConcatArgs(1);
|
||||
message.erase(0, 1);
|
||||
|
||||
for (const auto& callback : say_callbacks)
|
||||
{
|
||||
const auto entity_id = game::Scr_GetEntityId(clientNum, 0);
|
||||
const auto result = callback(entity_id, {message, cmd == "say_team"s});
|
||||
|
||||
if (result.is<int>() && !hidden)
|
||||
{
|
||||
hidden = result.as<int>() == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hidden)
|
||||
{
|
||||
client_command_hook.invoke<void>(clientNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
client_command_hook.create(0x502CB0, client_command_stub);
|
||||
|
||||
scripting::on_shutdown([]()
|
||||
{
|
||||
say_callbacks.clear();
|
||||
});
|
||||
|
||||
gsc::function::add("onplayersay", [](const gsc::function_args& args) -> scripting::script_value
|
||||
{
|
||||
const auto function = args[0].as<scripting::function>();
|
||||
say_callbacks.push_back(function);
|
||||
return {};
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(notifies::component)
|
||||
@@ -77,6 +77,7 @@ namespace scheduler
|
||||
};
|
||||
|
||||
std::thread thread;
|
||||
std::atomic_bool killed;
|
||||
task_pipeline pipelines[pipeline::count];
|
||||
|
||||
void execute(const pipeline type)
|
||||
@@ -128,11 +129,11 @@ namespace scheduler
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||
{
|
||||
thread = std::thread([]()
|
||||
{
|
||||
while (true)
|
||||
while (!killed)
|
||||
{
|
||||
execute(pipeline::async);
|
||||
std::this_thread::sleep_for(10ms);
|
||||
@@ -141,6 +142,16 @@ namespace scheduler
|
||||
|
||||
utils::hook::call(0x50CEDC, server_frame_stub);
|
||||
}
|
||||
|
||||
void on_shutdown([[maybe_unused]] plugin::plugin* plugin) override
|
||||
{
|
||||
killed = true;
|
||||
|
||||
if (thread.joinable())
|
||||
{
|
||||
thread.join();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,68 +13,12 @@
|
||||
|
||||
namespace scripting
|
||||
{
|
||||
std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
|
||||
std::unordered_map<std::string, std::unordered_map<std::string, const char*>> script_function_table;
|
||||
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour vm_notify_hook;
|
||||
utils::hook::detour scr_add_class_field_hook;
|
||||
|
||||
utils::hook::detour scr_load_level_hook;
|
||||
utils::hook::detour g_shutdown_game_hook;
|
||||
|
||||
utils::hook::detour scr_set_thread_position_hook;
|
||||
utils::hook::detour process_script_hook;
|
||||
|
||||
std::string current_file;
|
||||
|
||||
std::vector<std::function<void()>> shutdown_callbacks;
|
||||
|
||||
void vm_notify_stub(const unsigned int notify_list_owner_id, const unsigned int string_value,
|
||||
game::VariableValue* top)
|
||||
{
|
||||
const auto* name = game::SL_ConvertToString(string_value);
|
||||
|
||||
if (name)
|
||||
{
|
||||
event e;
|
||||
e.name = name;
|
||||
e.entity = notify_list_owner_id;
|
||||
|
||||
for (auto* value = top; value->type != game::SCRIPT_END; --value)
|
||||
{
|
||||
e.arguments.emplace_back(*value);
|
||||
}
|
||||
|
||||
if (e.name == "connected")
|
||||
{
|
||||
const auto player = e.arguments[0].as<scripting::entity>();
|
||||
const auto client = player.call("getentitynumber").as<int>();
|
||||
userinfo::clear_client_overrides(client);
|
||||
}
|
||||
}
|
||||
|
||||
vm_notify_hook.invoke<void>(notify_list_owner_id, string_value, top);
|
||||
}
|
||||
|
||||
void scr_add_class_field_stub(unsigned int classnum, unsigned int _name, unsigned int canonicalString, unsigned int offset)
|
||||
{
|
||||
const auto name = game::SL_ConvertToString(_name);
|
||||
|
||||
if (fields_table[classnum].find(name) == fields_table[classnum].end())
|
||||
{
|
||||
fields_table[classnum][name] = offset;
|
||||
}
|
||||
|
||||
scr_add_class_field_hook.invoke<void>(classnum, _name, canonicalString, offset);
|
||||
}
|
||||
|
||||
void scr_load_level_stub()
|
||||
{
|
||||
scr_load_level_hook.invoke<void>();
|
||||
}
|
||||
|
||||
void g_shutdown_game_stub(const int free_scripts)
|
||||
{
|
||||
userinfo::clear_overrides();
|
||||
@@ -87,31 +31,6 @@ namespace scripting
|
||||
|
||||
g_shutdown_game_hook.invoke<void>(free_scripts);
|
||||
}
|
||||
|
||||
void process_script_stub(const char* filename)
|
||||
{
|
||||
current_file = filename;
|
||||
|
||||
const auto file_id = atoi(filename);
|
||||
if (file_id)
|
||||
{
|
||||
current_file = scripting::find_file(file_id);
|
||||
}
|
||||
|
||||
process_script_hook.invoke<void>(filename);
|
||||
}
|
||||
|
||||
void scr_set_thread_position_stub(unsigned int threadName, const char* codePos)
|
||||
{
|
||||
const auto function_name = scripting::find_token(threadName);
|
||||
|
||||
if (!function_name.empty())
|
||||
{
|
||||
script_function_table[current_file][function_name] = codePos;
|
||||
}
|
||||
|
||||
scr_set_thread_position_hook.invoke<void>(threadName, codePos);
|
||||
}
|
||||
}
|
||||
|
||||
void on_shutdown(const std::function<void()>& callback)
|
||||
@@ -122,16 +41,9 @@ namespace scripting
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||
{
|
||||
scr_load_level_hook.create(0x527AF0, scr_load_level_stub);
|
||||
g_shutdown_game_hook.create(0x50C100, g_shutdown_game_stub);
|
||||
|
||||
scr_add_class_field_hook.create(0x567CD0, scr_add_class_field_stub);
|
||||
vm_notify_hook.create(0x569720, vm_notify_stub);
|
||||
|
||||
scr_set_thread_position_hook.create(0x5616D0, scr_set_thread_position_stub);
|
||||
process_script_hook.create(0x56B130, process_script_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,8 +2,5 @@
|
||||
|
||||
namespace scripting
|
||||
{
|
||||
extern std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
|
||||
extern std::unordered_map<std::string, std::unordered_map<std::string, const char*>> script_function_table;
|
||||
|
||||
void on_shutdown(const std::function<void()>& callback);
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
#include <stdinc.hpp>
|
||||
#include "signatures.hpp"
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
namespace signatures
|
||||
{
|
||||
size_t load_image_size()
|
||||
{
|
||||
MODULEINFO info{};
|
||||
GetModuleInformation(GetCurrentProcess(),
|
||||
GetModuleHandle("plutonium-bootstrapper-win32.exe"), &info, sizeof(MODULEINFO));
|
||||
return info.SizeOfImage;
|
||||
}
|
||||
|
||||
size_t get_image_size()
|
||||
{
|
||||
static const auto image_size = load_image_size();
|
||||
return image_size;
|
||||
}
|
||||
|
||||
void load_function_tables()
|
||||
{
|
||||
static const auto ptr = *reinterpret_cast<size_t*>(0x56CBDC + 0x1) + 0x56CBDC + 0x5;
|
||||
static const auto function_table = *reinterpret_cast<size_t*>(0x56C8EB + 0x3);
|
||||
static const auto method_table = *reinterpret_cast<size_t*>(ptr + 0xA);
|
||||
|
||||
game::plutonium::function_table.set(function_table);
|
||||
game::plutonium::method_table.set(method_table);
|
||||
}
|
||||
|
||||
size_t find_string_ptr(const std::string& string)
|
||||
{
|
||||
const char* string_ptr = nullptr;
|
||||
std::string mask(string.size(), 'x');
|
||||
const auto base = reinterpret_cast<size_t>(GetModuleHandle("plutonium-bootstrapper-win32.exe"));
|
||||
utils::hook::signature signature(base, get_image_size() - base);
|
||||
|
||||
auto found = false;
|
||||
signature.add({
|
||||
string,
|
||||
mask,
|
||||
[&](char* address)
|
||||
{
|
||||
if (found)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
found = true;
|
||||
string_ptr = address;
|
||||
}
|
||||
});
|
||||
|
||||
signature.process();
|
||||
return reinterpret_cast<size_t>(string_ptr);
|
||||
}
|
||||
|
||||
size_t find_string_ref(const std::string& string)
|
||||
{
|
||||
char bytes[4] = {0};
|
||||
const auto string_ptr = find_string_ptr(string);
|
||||
if (!string_ptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::memcpy(bytes, &string_ptr, sizeof(bytes));
|
||||
return find_string_ptr({bytes, 4});
|
||||
}
|
||||
|
||||
bool process_gsc_ctx()
|
||||
{
|
||||
const auto string_ref = find_string_ref("in call to builtin %s \"%s\"");
|
||||
if (!string_ref)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto gsc_ctx_ptr = *reinterpret_cast<size_t*>(string_ref - 0xAD);
|
||||
OutputDebugString(utils::string::va("gsc_ctx_ptr: %p\n", gsc_ctx_ptr));
|
||||
game::plutonium::gsc_ctx.set(gsc_ctx_ptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool process_printf()
|
||||
{
|
||||
const auto string_ref = find_string_ref("A critical exception occured!\n");
|
||||
if (!string_ref)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto offset = *reinterpret_cast<size_t*>(string_ref + 5);
|
||||
const auto printf_ptr = string_ref + 4 + 5 + offset;
|
||||
OutputDebugString(utils::string::va("printf_ptr: %p\n", printf_ptr));
|
||||
game::plutonium::printf.set(printf_ptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool process()
|
||||
{
|
||||
load_function_tables();
|
||||
return process_printf() && process_gsc_ctx();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace signatures
|
||||
{
|
||||
bool process();
|
||||
}
|
||||
@@ -10,13 +10,8 @@ namespace string
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||
{
|
||||
gsc::function::add("toupper", [](const gsc::function_args& args)
|
||||
{
|
||||
return utils::string::to_upper(args[0].as<std::string>());
|
||||
});
|
||||
|
||||
gsc::function::add("getchar", [](const gsc::function_args& args)
|
||||
{
|
||||
auto index = 0;
|
||||
@@ -28,7 +23,7 @@ namespace string
|
||||
const auto string = args[0].as<std::string>();
|
||||
if (index >= static_cast<int>(string.size()))
|
||||
{
|
||||
throw std::runtime_error("Char index out of bounds");
|
||||
throw std::runtime_error("char index out of bounds");
|
||||
}
|
||||
|
||||
return static_cast<int>(string[index]);
|
||||
|
||||
+16
-13
@@ -71,12 +71,12 @@ namespace userinfo
|
||||
const auto userinfo = map_to_userinfo(map);
|
||||
strcpy_s(buffer, 1024, userinfo.data());
|
||||
}
|
||||
}
|
||||
|
||||
void clear_client_overrides(int client)
|
||||
void clear_client_overrides(unsigned int client)
|
||||
{
|
||||
userinfo_overrides[client].clear();
|
||||
}
|
||||
}
|
||||
|
||||
void clear_overrides()
|
||||
{
|
||||
@@ -86,20 +86,23 @@ namespace userinfo
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||
{
|
||||
sv_getuserinfo_hook.create(0x573E00, sv_getuserinfo_stub);
|
||||
|
||||
plugin->get_interface()->callbacks()->on_player_connect(clear_client_overrides);
|
||||
plugin->get_interface()->callbacks()->on_player_disconnect(clear_client_overrides);
|
||||
|
||||
gsc::method::add("setname", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
||||
{
|
||||
if (ent.classnum != 0)
|
||||
{
|
||||
throw std::runtime_error("Invalid entity");
|
||||
throw std::runtime_error("invalid entity");
|
||||
}
|
||||
|
||||
if (game::g_entities[ent.entnum].client == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Not a player entity");
|
||||
throw std::runtime_error("not a player entity");
|
||||
}
|
||||
|
||||
const auto name = args[0].as<std::string>();
|
||||
@@ -114,12 +117,12 @@ namespace userinfo
|
||||
{
|
||||
if (ent.classnum != 0)
|
||||
{
|
||||
throw std::runtime_error("Invalid entity");
|
||||
throw std::runtime_error("invalid entity");
|
||||
}
|
||||
|
||||
if (game::g_entities[ent.entnum].client == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Not a player entity");
|
||||
throw std::runtime_error("not a player entity");
|
||||
}
|
||||
|
||||
userinfo_overrides[ent.entnum].erase("name");
|
||||
@@ -132,12 +135,12 @@ namespace userinfo
|
||||
{
|
||||
if (ent.classnum != 0)
|
||||
{
|
||||
throw std::runtime_error("Invalid entity");
|
||||
throw std::runtime_error("invalid entity");
|
||||
}
|
||||
|
||||
if (game::g_entities[ent.entnum].client == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Not a player entity");
|
||||
throw std::runtime_error("not a player entity");
|
||||
}
|
||||
|
||||
const auto name = args[0].as<std::string>();
|
||||
@@ -154,12 +157,12 @@ namespace userinfo
|
||||
{
|
||||
if (ent.classnum != 0)
|
||||
{
|
||||
throw std::runtime_error("Invalid entity");
|
||||
throw std::runtime_error("invalid entity");
|
||||
}
|
||||
|
||||
if (game::g_entities[ent.entnum].client == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Not a player entity");
|
||||
throw std::runtime_error("not a player entity");
|
||||
}
|
||||
|
||||
userinfo_overrides[ent.entnum].erase("clantag");
|
||||
@@ -174,12 +177,12 @@ namespace userinfo
|
||||
{
|
||||
if (ent.classnum != 0)
|
||||
{
|
||||
throw std::runtime_error("Invalid entity");
|
||||
throw std::runtime_error("invalid entity");
|
||||
}
|
||||
|
||||
if (game::g_entities[ent.entnum].client == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Not a player entity");
|
||||
throw std::runtime_error("not a player entity");
|
||||
}
|
||||
|
||||
userinfo_overrides[ent.entnum]["clantag"] = "";
|
||||
|
||||
+11
-16
@@ -1,28 +1,23 @@
|
||||
#include <stdinc.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "component/signatures.hpp"
|
||||
#include "plugin.hpp"
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/)
|
||||
PLUTONIUM_API plutonium::sdk::plugin* PLUTONIUM_CALLBACK on_initialize()
|
||||
{
|
||||
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
if (!signatures::process())
|
||||
{
|
||||
MessageBoxA(NULL,
|
||||
"This version of iw5-gsc-utils is outdated.\n" \
|
||||
"Download the latest dll from here: https://github.com/fedddddd/iw5-gsc-utils/releases",
|
||||
"ERROR", MB_ICONERROR);
|
||||
return plugin::get();
|
||||
}
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE /*module*/, DWORD reason, LPVOID /*reserved*/)
|
||||
{
|
||||
if (reason == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (game::plutonium::printf.get() != nullptr)
|
||||
if (reason == DLL_PROCESS_DETACH)
|
||||
{
|
||||
utils::hook::jump(reinterpret_cast<uintptr_t>(&printf), game::plutonium::printf);
|
||||
}
|
||||
|
||||
component_loader::post_unpack();
|
||||
component_loader::on_shutdown();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
@@ -212,8 +212,6 @@ namespace scripting
|
||||
{
|
||||
return this->get(key.as<std::string>());
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
script_value array::get(const std::string& key) const
|
||||
|
||||
@@ -96,20 +96,4 @@ namespace scripting
|
||||
game::RemoveRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->entity_id_)});
|
||||
}
|
||||
}
|
||||
|
||||
void entity::set(const std::string& field, const script_value& value) const
|
||||
{
|
||||
set_entity_field(*this, field, value);
|
||||
}
|
||||
|
||||
template <>
|
||||
script_value entity::get<script_value>(const std::string& field) const
|
||||
{
|
||||
return get_entity_field(*this, field);
|
||||
}
|
||||
|
||||
script_value entity::call(const std::string& name, const std::vector<script_value>& arguments) const
|
||||
{
|
||||
return call_function(name, *this, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,6 @@ namespace scripting
|
||||
entity& operator=(const entity& other);
|
||||
entity& operator=(entity&& other) noexcept;
|
||||
|
||||
void set(const std::string& field, const script_value& value) const;
|
||||
|
||||
template <typename T = script_value>
|
||||
T get(const std::string& field) const;
|
||||
|
||||
script_value call(const std::string& name, const std::vector<script_value>& arguments = {}) const;
|
||||
|
||||
unsigned int get_entity_id() const;
|
||||
game::scr_entref_t get_entity_reference() const;
|
||||
|
||||
@@ -37,13 +30,4 @@ namespace scripting
|
||||
void add() const;
|
||||
void release() const;
|
||||
};
|
||||
|
||||
template <>
|
||||
script_value entity::get(const std::string& field) const;
|
||||
|
||||
template <typename T>
|
||||
T entity::get(const std::string& field) const
|
||||
{
|
||||
return this->get<script_value>(field).as<T>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <stdinc.hpp>
|
||||
#include "execution.hpp"
|
||||
#include "safe_execution.hpp"
|
||||
#include "stack_isolation.hpp"
|
||||
#include "event.hpp"
|
||||
|
||||
@@ -32,16 +31,6 @@ namespace scripting
|
||||
return script_value(game::scr_VmPub->top[1 - game::scr_VmPub->outparamcount]);
|
||||
}
|
||||
|
||||
int get_field_id(const int classnum, const std::string& field)
|
||||
{
|
||||
if (scripting::fields_table[classnum].find(field) != scripting::fields_table[classnum].end())
|
||||
{
|
||||
return scripting::fields_table[classnum][field];
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void scr_notify_id(int id, unsigned int stringValue, unsigned int paramcount)
|
||||
{
|
||||
if (game::scr_VmPub->outparamcount)
|
||||
@@ -95,47 +84,6 @@ namespace scripting
|
||||
scr_notify_id(entity.get_entity_id(), event_id, game::scr_VmPub->inparamcount);
|
||||
}
|
||||
|
||||
script_value call_function(const std::string& name, const entity& entity,
|
||||
const std::vector<script_value>& arguments)
|
||||
{
|
||||
const auto entref = entity.get_entity_reference();
|
||||
|
||||
const auto is_method_call = *reinterpret_cast<const int*>(&entref) != -1;
|
||||
const auto function = find_function(name, !is_method_call);
|
||||
if (!function)
|
||||
{
|
||||
throw std::runtime_error("Unknown function '" + name + "'");
|
||||
}
|
||||
|
||||
stack_isolation _;
|
||||
|
||||
for (auto i = arguments.rbegin(); i != arguments.rend(); ++i)
|
||||
{
|
||||
push_value(*i);
|
||||
}
|
||||
|
||||
game::scr_VmPub->outparamcount = game::scr_VmPub->inparamcount;
|
||||
game::scr_VmPub->inparamcount = 0;
|
||||
|
||||
if (!safe_execution::call(function, entref))
|
||||
{
|
||||
throw std::runtime_error("Error executing function '" + name + "'");
|
||||
}
|
||||
|
||||
return get_return_value();
|
||||
}
|
||||
|
||||
script_value call_function(const std::string& name, const std::vector<script_value>& arguments)
|
||||
{
|
||||
return call_function(name, entity(), arguments);
|
||||
}
|
||||
|
||||
template <>
|
||||
script_value call(const std::string& name, const std::vector<script_value>& arguments)
|
||||
{
|
||||
return call_function(name, arguments);
|
||||
}
|
||||
|
||||
script_value exec_ent_thread(const entity& entity, const char* pos, const std::vector<script_value>& arguments)
|
||||
{
|
||||
const auto id = entity.get_entity_id();
|
||||
@@ -155,122 +103,6 @@ namespace scripting
|
||||
return get_return_value();
|
||||
}
|
||||
|
||||
const char* get_function_pos(const std::string& filename, const std::string& function)
|
||||
{
|
||||
if (scripting::script_function_table.find(filename) == scripting::script_function_table.end())
|
||||
{
|
||||
throw std::runtime_error("File '" + filename + "' not found");
|
||||
};
|
||||
|
||||
const auto functions = scripting::script_function_table[filename];
|
||||
if (functions.find(function) == functions.end())
|
||||
{
|
||||
throw std::runtime_error("Function '" + function + "' in file '" + filename + "' not found");
|
||||
}
|
||||
|
||||
return functions.at(function);
|
||||
}
|
||||
|
||||
script_value call_script_function(const entity& entity, const std::string& filename,
|
||||
const std::string& function, const std::vector<script_value>& arguments)
|
||||
{
|
||||
const auto pos = get_function_pos(filename, function);
|
||||
return exec_ent_thread(entity, pos, arguments);
|
||||
}
|
||||
|
||||
static std::unordered_map<unsigned int, std::unordered_map<std::string, script_value>> custom_fields;
|
||||
|
||||
script_value get_custom_field(const entity& entity, const std::string& field)
|
||||
{
|
||||
auto fields = custom_fields[entity.get_entity_id()];
|
||||
const auto _field = fields.find(field);
|
||||
if (_field != fields.end())
|
||||
{
|
||||
return _field->second;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void set_custom_field(const entity& entity, const std::string& field, const script_value& value)
|
||||
{
|
||||
const auto id = entity.get_entity_id();
|
||||
|
||||
if (custom_fields[id].find(field) != custom_fields[id].end())
|
||||
{
|
||||
custom_fields[id][field] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
custom_fields[id].insert(std::make_pair(field, value));
|
||||
}
|
||||
|
||||
void clear_entity_fields(const entity& entity)
|
||||
{
|
||||
const auto id = entity.get_entity_id();
|
||||
|
||||
if (custom_fields.find(id) != custom_fields.end())
|
||||
{
|
||||
custom_fields[id].clear();
|
||||
}
|
||||
}
|
||||
|
||||
void clear_custom_fields()
|
||||
{
|
||||
custom_fields.clear();
|
||||
}
|
||||
|
||||
void set_entity_field(const entity& entity, const std::string& field, const script_value& value)
|
||||
{
|
||||
const auto entref = entity.get_entity_reference();
|
||||
const int id = get_field_id(entref.classnum, field);
|
||||
|
||||
if (id != -1)
|
||||
{
|
||||
stack_isolation _;
|
||||
push_value(value);
|
||||
|
||||
game::scr_VmPub->outparamcount = game::scr_VmPub->inparamcount;
|
||||
game::scr_VmPub->inparamcount = 0;
|
||||
|
||||
if (!safe_execution::set_entity_field(entref, id))
|
||||
{
|
||||
throw std::runtime_error("Failed to set value for field '" + field + "'");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
set_custom_field(entity, field, value);
|
||||
}
|
||||
}
|
||||
|
||||
script_value get_entity_field(const entity& entity, const std::string& field)
|
||||
{
|
||||
const auto entref = entity.get_entity_reference();
|
||||
const auto id = get_field_id(entref.classnum, field);
|
||||
|
||||
if (id != -1)
|
||||
{
|
||||
stack_isolation _;
|
||||
|
||||
game::VariableValue value{};
|
||||
if (!safe_execution::get_entity_field(entref, id, &value))
|
||||
{
|
||||
throw std::runtime_error("Failed to get value for field '" + field + "'");
|
||||
}
|
||||
|
||||
const auto __ = gsl::finally([value]()
|
||||
{
|
||||
game::RemoveRefToValue(value.type, value.u);
|
||||
});
|
||||
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return get_custom_field(entity, field);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int make_array()
|
||||
{
|
||||
unsigned int index = 0;
|
||||
|
||||
@@ -9,10 +9,6 @@ namespace scripting
|
||||
{
|
||||
void push_value(const script_value& value);
|
||||
|
||||
script_value call_function(const std::string& name, const std::vector<script_value>& arguments);
|
||||
script_value call_function(const std::string& name, const entity& entity,
|
||||
const std::vector<script_value>& arguments);
|
||||
|
||||
template <typename T = script_value>
|
||||
T call(const std::string& name, const std::vector<script_value>& arguments = {});
|
||||
|
||||
@@ -26,14 +22,6 @@ namespace scripting
|
||||
}
|
||||
|
||||
script_value exec_ent_thread(const entity& entity, const char* pos, const std::vector<script_value>& arguments);
|
||||
script_value call_script_function(const entity& entity, const std::string& filename,
|
||||
const std::string& function, const std::vector<script_value>& arguments);
|
||||
|
||||
void clear_entity_fields(const entity& entity);
|
||||
void clear_custom_fields();
|
||||
|
||||
void set_entity_field(const entity& entity, const std::string& field, const script_value& value);
|
||||
script_value get_entity_field(const entity& entity, const std::string& field);
|
||||
|
||||
void notify(const entity& entity, const std::string& event, const std::vector<script_value>& arguments);
|
||||
|
||||
|
||||
@@ -5,64 +5,5 @@
|
||||
|
||||
namespace scripting
|
||||
{
|
||||
namespace
|
||||
{
|
||||
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();
|
||||
|
||||
if (const auto itr = first.find(name); itr != first.end())
|
||||
{
|
||||
return static_cast<int>(itr->second);
|
||||
}
|
||||
|
||||
if (const auto itr = second.find(name); itr != second.end())
|
||||
{
|
||||
return static_cast<int>(itr->second);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
script_function get_function_by_index(const unsigned index)
|
||||
{
|
||||
static const auto function_table = game::plutonium::function_table.get();
|
||||
static const auto method_table = game::plutonium::method_table.get();
|
||||
|
||||
if (index < 0x1C7)
|
||||
{
|
||||
return reinterpret_cast<script_function*>(function_table)[index];
|
||||
}
|
||||
|
||||
return reinterpret_cast<script_function*>(method_table)[index - 0x8000];
|
||||
}
|
||||
}
|
||||
|
||||
std::string find_token(unsigned int id)
|
||||
{
|
||||
return (*game::plutonium::gsc_ctx)->token_name(id);
|
||||
}
|
||||
|
||||
std::string find_file(unsigned int id)
|
||||
{
|
||||
return find_token(id);
|
||||
}
|
||||
|
||||
int find_token_id(const std::string& name)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
return get_function_by_index(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,4 @@
|
||||
namespace scripting
|
||||
{
|
||||
using script_function = void(*)(game::scr_entref_t);
|
||||
|
||||
script_function find_function(const std::string& name, const bool prefer_global);
|
||||
int find_token_id(const std::string& name);
|
||||
std::string find_token(unsigned int id);
|
||||
std::string find_file(unsigned int id);
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
#include <stdinc.hpp>
|
||||
#include "safe_execution.hpp"
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4611)
|
||||
|
||||
namespace scripting::safe_execution
|
||||
{
|
||||
namespace
|
||||
{
|
||||
bool execute_with_seh(const script_function function, const game::scr_entref_t& entref)
|
||||
{
|
||||
__try
|
||||
{
|
||||
function(entref);
|
||||
return true;
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool call(const script_function function, const game::scr_entref_t& entref)
|
||||
{
|
||||
*game::g_script_error_level += 1;
|
||||
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level], 0, 0, 0))
|
||||
{
|
||||
*game::g_script_error_level -= 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto result = execute_with_seh(function, entref);
|
||||
*game::g_script_error_level -= 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool set_entity_field(const game::scr_entref_t& entref, const int offset)
|
||||
{
|
||||
*game::g_script_error_level += 1;
|
||||
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level], 0, 0, 0))
|
||||
{
|
||||
*game::g_script_error_level -= 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
game::Scr_SetObjectField(entref.classnum, entref.entnum, offset);
|
||||
|
||||
*game::g_script_error_level -= 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get_entity_field(const game::scr_entref_t& entref, const int offset, game::VariableValue* value)
|
||||
{
|
||||
*game::g_script_error_level += 1;
|
||||
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level], 0, 0, 0))
|
||||
{
|
||||
value->type = game::SCRIPT_NONE;
|
||||
value->u.intValue = 0;
|
||||
*game::g_script_error_level -= 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto _value = game::GetEntityFieldValue(entref.classnum, entref.entnum, offset);
|
||||
value->type = _value.type;
|
||||
value->u = _value.u;
|
||||
|
||||
*game::g_script_error_level -= 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning(pop)
|
||||
@@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
#include "functions.hpp"
|
||||
|
||||
namespace scripting::safe_execution
|
||||
{
|
||||
bool call(script_function function, const game::scr_entref_t& entref);
|
||||
|
||||
bool set_entity_field(const game::scr_entref_t& entref, int offset);
|
||||
bool get_entity_field(const game::scr_entref_t& entref, int offset, game::VariableValue* value);
|
||||
}
|
||||
@@ -25,8 +25,6 @@ namespace game
|
||||
|
||||
WEAK symbol<const dvar_t*(const char*)> Dvar_FindVar{0x5BDCC0};
|
||||
|
||||
WEAK symbol<char*(const char*)> I_CleanStr{0x0};
|
||||
|
||||
WEAK symbol<VariableValue(unsigned int classnum, int entnum, int offset)> GetEntityFieldValue{0x56AF20};
|
||||
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> FindVariable{0x5651F0};
|
||||
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> FindObject{0x565BD0};
|
||||
@@ -83,12 +81,4 @@ namespace game
|
||||
WEAK symbol<dvar_t> sv_maxclients{0x1BA0E4C};
|
||||
WEAK symbol<int> svs_clientCount{0x4B5CF8C};
|
||||
WEAK symbol<client_s> svs_clients{0x4B5CF90};
|
||||
|
||||
namespace plutonium
|
||||
{
|
||||
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};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "../plugin.hpp"
|
||||
|
||||
class component_interface
|
||||
{
|
||||
@@ -7,25 +8,24 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual void post_start()
|
||||
virtual void on_startup([[maybe_unused]] plugin::plugin* plugin)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void post_load()
|
||||
virtual void on_dvar_init([[maybe_unused]] plugin::plugin* plugin)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void pre_destroy()
|
||||
virtual void on_after_dvar_init([[maybe_unused]] plugin::plugin* plugin)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void post_unpack()
|
||||
virtual void on_game_init([[maybe_unused]] plugin::plugin* plugin)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void* load_import([[maybe_unused]] const std::string& library, [[maybe_unused]] const std::string& function)
|
||||
virtual void on_shutdown([[maybe_unused]] plugin::plugin* plugin)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual bool is_supported()
|
||||
|
||||
@@ -1,87 +1,48 @@
|
||||
#include <stdinc.hpp>
|
||||
#include "component_loader.hpp"
|
||||
|
||||
void component_loader::register_component(std::unique_ptr<component_interface>&& component_)
|
||||
void component_loader::register_component(const std::string& name, std::unique_ptr<component_interface>&& component_)
|
||||
{
|
||||
get_components().push_back(std::move(component_));
|
||||
get_components().push_back(std::make_pair(name, std::move(component_)));
|
||||
}
|
||||
|
||||
bool component_loader::post_start()
|
||||
{
|
||||
static auto handled = false;
|
||||
if (handled) return true;
|
||||
handled = true;
|
||||
#define ON_CALLBACK(__name__) \
|
||||
void component_loader::__name__() \
|
||||
{ \
|
||||
static auto handled = false; \
|
||||
if (handled) \
|
||||
{ \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
handled = true; \
|
||||
\
|
||||
for (const auto& component_ : get_components()) \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
component_.second->__name__(plugin::get()); \
|
||||
} \
|
||||
catch (const std::exception& e) \
|
||||
{ \
|
||||
printf("error executing component \"%s\" callback \"%s\": %s\n", component_.first.data(), #__name__, e.what()); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
|
||||
try
|
||||
{
|
||||
for (const auto& component_ : get_components())
|
||||
{
|
||||
component_->post_start();
|
||||
}
|
||||
}
|
||||
catch (premature_shutdown_trigger&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool component_loader::post_load()
|
||||
{
|
||||
static auto handled = false;
|
||||
if (handled) return true;
|
||||
handled = true;
|
||||
|
||||
clean();
|
||||
|
||||
try
|
||||
{
|
||||
for (const auto& component_ : get_components())
|
||||
{
|
||||
component_->post_load();
|
||||
}
|
||||
}
|
||||
catch (premature_shutdown_trigger&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void component_loader::post_unpack()
|
||||
{
|
||||
static auto handled = false;
|
||||
if (handled) return;
|
||||
handled = true;
|
||||
|
||||
for (const auto& component_ : get_components())
|
||||
{
|
||||
component_->post_unpack();
|
||||
}
|
||||
}
|
||||
|
||||
void component_loader::pre_destroy()
|
||||
{
|
||||
static auto handled = false;
|
||||
if (handled) return;
|
||||
handled = true;
|
||||
|
||||
for (const auto& component_ : get_components())
|
||||
{
|
||||
component_->pre_destroy();
|
||||
}
|
||||
}
|
||||
ON_CALLBACK(on_startup);
|
||||
ON_CALLBACK(on_dvar_init);
|
||||
ON_CALLBACK(on_after_dvar_init);
|
||||
ON_CALLBACK(on_shutdown);
|
||||
|
||||
void component_loader::clean()
|
||||
{
|
||||
auto& components = get_components();
|
||||
for (auto i = components.begin(); i != components.end();)
|
||||
{
|
||||
if (!(*i)->is_supported())
|
||||
if (!(*i).second->is_supported())
|
||||
{
|
||||
(*i)->pre_destroy();
|
||||
(*i).second->on_shutdown(plugin::get());
|
||||
i = components.erase(i);
|
||||
}
|
||||
else
|
||||
@@ -91,35 +52,19 @@ void component_loader::clean()
|
||||
}
|
||||
}
|
||||
|
||||
void* component_loader::load_import(const std::string& library, const std::string& function)
|
||||
{
|
||||
void* function_ptr = nullptr;
|
||||
|
||||
for (const auto& component_ : get_components())
|
||||
{
|
||||
auto* const component_function_ptr = component_->load_import(library, function);
|
||||
if (component_function_ptr)
|
||||
{
|
||||
function_ptr = component_function_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return function_ptr;
|
||||
}
|
||||
|
||||
void component_loader::trigger_premature_shutdown()
|
||||
{
|
||||
throw premature_shutdown_trigger();
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<component_interface>>& component_loader::get_components()
|
||||
std::vector<std::pair<std::string, std::unique_ptr<component_interface>>>& component_loader::get_components()
|
||||
{
|
||||
using component_vector = std::vector<std::unique_ptr<component_interface>>;
|
||||
using component_vector = std::vector<std::pair<std::string, std::unique_ptr<component_interface>>>;
|
||||
using component_vector_container = std::unique_ptr<component_vector, std::function<void(component_vector*)>>;
|
||||
|
||||
static component_vector_container components(new component_vector, [](component_vector* component_vector)
|
||||
{
|
||||
pre_destroy();
|
||||
on_shutdown();
|
||||
delete component_vector;
|
||||
});
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@ public:
|
||||
static_assert(std::is_base_of<component_interface, T>::value, "component has invalid base class");
|
||||
|
||||
public:
|
||||
installer()
|
||||
installer(const std::string& name)
|
||||
{
|
||||
register_component(std::make_unique<T>());
|
||||
register_component(name, std::make_unique<T>());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -38,12 +38,12 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void register_component(std::unique_ptr<component_interface>&& component);
|
||||
static void register_component(const std::string& name, std::unique_ptr<component_interface>&& component);
|
||||
|
||||
static bool post_start();
|
||||
static bool post_load();
|
||||
static void post_unpack();
|
||||
static void pre_destroy();
|
||||
static void on_startup();
|
||||
static void on_dvar_init();
|
||||
static void on_after_dvar_init();
|
||||
static void on_shutdown();
|
||||
static void clean();
|
||||
|
||||
static void* load_import(const std::string& library, const std::string& function);
|
||||
@@ -51,11 +51,11 @@ public:
|
||||
static void trigger_premature_shutdown();
|
||||
|
||||
private:
|
||||
static std::vector<std::unique_ptr<component_interface>>& get_components();
|
||||
static std::vector<std::pair<std::string, std::unique_ptr<component_interface>>>& get_components();
|
||||
};
|
||||
|
||||
#define REGISTER_COMPONENT(name) \
|
||||
namespace \
|
||||
{ \
|
||||
static component_loader::installer<name> __component; \
|
||||
static component_loader::installer<name> __component(#name); \
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#include <stdinc.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "plugin.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/string.hpp>
|
||||
|
||||
namespace plugin
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void printf_stub(const char* fmt, ...)
|
||||
{
|
||||
char buffer[0x2000] = {};
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, fmt, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
get()->get_interface()->logging()->info(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
std::uint32_t plugin::plugin_version()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* plugin::plugin_name()
|
||||
{
|
||||
return "iw5-gsc-utils";
|
||||
}
|
||||
|
||||
bool plugin::is_game_supported([[maybe_unused]] plutonium::sdk::game game)
|
||||
{
|
||||
return game == plutonium::sdk::game::iw5;
|
||||
}
|
||||
|
||||
void plugin::on_startup(plutonium::sdk::iinterface* interface_ptr, plutonium::sdk::game game)
|
||||
{
|
||||
this->interface_ = interface_ptr;
|
||||
this->game_ = game;
|
||||
utils::hook::jump(reinterpret_cast<uintptr_t>(&printf), printf_stub);
|
||||
component_loader::on_startup();
|
||||
|
||||
interface_ptr->callbacks()->on_dvar_init(component_loader::on_dvar_init);
|
||||
interface_ptr->callbacks()->on_after_dvar_init(component_loader::on_after_dvar_init);
|
||||
}
|
||||
|
||||
void plugin::on_shutdown()
|
||||
{
|
||||
component_loader::on_shutdown();
|
||||
}
|
||||
|
||||
plutonium::sdk::iinterface* plugin::get_interface()
|
||||
{
|
||||
return this->interface_;
|
||||
}
|
||||
|
||||
plutonium::sdk::game plugin::get_game()
|
||||
{
|
||||
return this->game_;
|
||||
}
|
||||
|
||||
plugin* get()
|
||||
{
|
||||
static plugin instance;
|
||||
return &instance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <plutonium_sdk.hpp>
|
||||
|
||||
namespace plugin
|
||||
{
|
||||
class plugin : public plutonium::sdk::plugin
|
||||
{
|
||||
public:
|
||||
~plugin() = default;
|
||||
|
||||
std::uint32_t plugin_version() override;
|
||||
const char* plugin_name() override;
|
||||
|
||||
bool is_game_supported([[maybe_unused]] plutonium::sdk::game game) override;
|
||||
|
||||
void on_startup(plutonium::sdk::iinterface* interface_ptr, plutonium::sdk::game game) override;
|
||||
void on_shutdown() override;
|
||||
|
||||
plutonium::sdk::iinterface* get_interface();
|
||||
plutonium::sdk::game get_game();
|
||||
|
||||
private:
|
||||
plutonium::sdk::iinterface* interface_{};
|
||||
plutonium::sdk::game game_{};
|
||||
|
||||
};
|
||||
|
||||
plugin* get();
|
||||
}
|
||||
+2
-4
@@ -8,8 +8,6 @@
|
||||
#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>
|
||||
@@ -36,14 +34,14 @@
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
#define __has_warning(...) 0
|
||||
|
||||
#include <gsl/gsl>
|
||||
#include <MinHook.h>
|
||||
|
||||
|
||||
#include "utils/memory.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/hook.hpp"
|
||||
#include "utils/concurrent_list.hpp"
|
||||
#include "utils/io.hpp"
|
||||
#include "utils/concurrency.hpp"
|
||||
#include "utils/http.hpp"
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
|
||||
// This class is trash. Need to get rid of it.
|
||||
|
||||
namespace utils
|
||||
{
|
||||
template <typename T>
|
||||
class concurrent_list final
|
||||
{
|
||||
public:
|
||||
class element final
|
||||
{
|
||||
public:
|
||||
explicit element(std::recursive_mutex* mutex, std::shared_ptr<T> entry = {},
|
||||
std::shared_ptr<element> next = {}) :
|
||||
mutex_(mutex),
|
||||
entry_(std::move(entry)),
|
||||
next_(std::move(next))
|
||||
{
|
||||
}
|
||||
|
||||
void remove(const std::shared_ptr<T>& element)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
|
||||
if (!this->next_) return;
|
||||
|
||||
if (this->next_->entry_.get() == element.get())
|
||||
{
|
||||
this->next_ = this->next_->next_;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->next_->remove(element);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] std::shared_ptr<element> get_next() const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
|
||||
return this->next_;
|
||||
}
|
||||
|
||||
std::shared_ptr<T> operator*() const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
|
||||
return this->entry_;
|
||||
}
|
||||
|
||||
element& operator++()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
|
||||
*this = this->next_ ? *this->next_ : element(this->mutex_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
element operator++(int)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
|
||||
auto result = *this;
|
||||
this->operator++();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool operator==(const element& other)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
|
||||
return this->entry_.get() == other.entry_.get();
|
||||
}
|
||||
|
||||
bool operator!=(const element& other)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
private:
|
||||
std::recursive_mutex* mutex_;
|
||||
std::shared_ptr<T> entry_;
|
||||
std::shared_ptr<element> next_;
|
||||
};
|
||||
|
||||
element begin()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(this->mutex_);
|
||||
return this->entry_ ? *this->entry_ : this->end();
|
||||
}
|
||||
|
||||
element end()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(this->mutex_);
|
||||
return element(&this->mutex_);
|
||||
}
|
||||
|
||||
void remove(const element& entry)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(this->mutex_);
|
||||
this->remove(*entry);
|
||||
}
|
||||
|
||||
void remove(const std::shared_ptr<T>& element)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(this->mutex_);
|
||||
if (!this->entry_) return;
|
||||
|
||||
if ((**this->entry_).get() == element.get())
|
||||
{
|
||||
this->entry_ = this->entry_->get_next();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->entry_->remove(element);
|
||||
}
|
||||
}
|
||||
|
||||
void add(const T& object)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(this->mutex_);
|
||||
|
||||
const auto object_ptr = std::make_shared<T>(object);
|
||||
this->entry_ = std::make_shared<element>(&this->mutex_, object_ptr, this->entry_);
|
||||
}
|
||||
|
||||
void add(T&& object)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(this->mutex_);
|
||||
|
||||
const auto object_ptr = std::make_shared<T>(std::move(object));
|
||||
this->entry_ = std::make_shared<element>(&this->mutex_, object_ptr, this->entry_);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _(this->mutex_);
|
||||
this->entry_ = {};
|
||||
}
|
||||
|
||||
private:
|
||||
std::recursive_mutex mutex_;
|
||||
std::shared_ptr<element> entry_;
|
||||
};
|
||||
}
|
||||
+13
-42
@@ -4,48 +4,6 @@
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
// open-iw5
|
||||
|
||||
void signature::process()
|
||||
{
|
||||
if (this->signatures_.empty()) return;
|
||||
|
||||
const auto start = static_cast<char*>(this->start_);
|
||||
|
||||
const unsigned int sig_count = this->signatures_.size();
|
||||
const auto containers = this->signatures_.data();
|
||||
|
||||
for (size_t i = 0; i < this->length_; ++i)
|
||||
{
|
||||
const auto address = start + i;
|
||||
|
||||
for (unsigned int k = 0; k < sig_count; ++k)
|
||||
{
|
||||
const auto container = &containers[k];
|
||||
|
||||
unsigned int j;
|
||||
for (j = 0; j < static_cast<unsigned int>(container->mask.size()); ++j)
|
||||
{
|
||||
if (container->mask[j] != '?' && container->signature[j] != address[j])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j == container->mask.size())
|
||||
{
|
||||
container->callback(address);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void signature::add(const container& container)
|
||||
{
|
||||
signatures_.push_back(container);
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
[[maybe_unused]] class _
|
||||
@@ -219,4 +177,17 @@ namespace utils::hook
|
||||
|
||||
delete[] bytes;
|
||||
}
|
||||
|
||||
DWORD unprotect(void* place, const size_t size)
|
||||
{
|
||||
DWORD old_protect{};
|
||||
VirtualProtect(place, size, PAGE_EXECUTE_READWRITE, &old_protect);
|
||||
return old_protect;
|
||||
}
|
||||
|
||||
void protect(void* place, const size_t size, DWORD old_protect)
|
||||
{
|
||||
VirtualProtect(place, size, old_protect, &old_protect);
|
||||
FlushInstructionCache(GetCurrentProcess(), place, size);
|
||||
}
|
||||
}
|
||||
+3
-31
@@ -4,37 +4,6 @@
|
||||
|
||||
namespace utils::hook
|
||||
{
|
||||
class signature final
|
||||
{
|
||||
public:
|
||||
struct container final
|
||||
{
|
||||
std::string signature;
|
||||
std::string mask;
|
||||
std::function<void(char*)> callback;
|
||||
};
|
||||
|
||||
signature(void* start, const size_t length) : start_(start), length_(length)
|
||||
{
|
||||
}
|
||||
|
||||
signature(const DWORD start, const size_t length) : signature(reinterpret_cast<void*>(start), length)
|
||||
{
|
||||
}
|
||||
|
||||
signature() : signature(0x400000, 0x800000)
|
||||
{
|
||||
}
|
||||
|
||||
void process();
|
||||
void add(const container& container);
|
||||
|
||||
private:
|
||||
void* start_;
|
||||
size_t length_;
|
||||
std::vector<container> signatures_;
|
||||
};
|
||||
|
||||
class detour
|
||||
{
|
||||
public:
|
||||
@@ -144,4 +113,7 @@ namespace utils::hook
|
||||
{
|
||||
return static_cast<T(*)(Args ...)>(func)(args...);
|
||||
}
|
||||
|
||||
DWORD unprotect(void* place, const size_t size);
|
||||
void protect(void* place, const size_t size, DWORD old_protect);
|
||||
}
|
||||
Reference in New Issue
Block a user