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 | ||
|
|
bf1d649bc1 | ||
|
|
71727a5197 | ||
|
|
530cd10466 | ||
|
|
978e251df8 | ||
|
|
cb96052638 | ||
|
|
9b217b20e3 | ||
|
|
136a723187 | ||
|
|
ad27dcb098 | ||
|
|
96acf0718e | ||
|
|
72f936e82a | ||
|
|
9a11ac82b3 | ||
|
|
8f36c271fd | ||
|
|
e952b8a0f7 | ||
|
|
f6d78fd815 | ||
|
|
cadcca22f9 | ||
|
|
c04a0a0d8c | ||
|
|
61706336ce | ||
|
|
eb08109392 | ||
|
|
b23cb2014b | ||
|
|
4d979bf659 | ||
|
|
206d06dc7d | ||
|
|
4d8af4bd45 | ||
|
|
46ab288488 | ||
|
|
dd8c1ff71e | ||
|
|
ed1ac62153 | ||
|
|
7f7fd016cf | ||
|
|
6c093888b5 | ||
|
|
1440760aa5 | ||
|
|
105c11a8b2 | ||
|
|
795f8ac162 | ||
|
|
6dd4d2651a | ||
|
|
b2f030f349 | ||
|
|
2690eeeece | ||
|
|
098bd21008 | ||
|
|
2f474e979f | ||
|
|
2ab4da0ad9 | ||
|
|
28c5594094 | ||
|
|
6525bbb8bf | ||
|
|
1a9e3dfb15 | ||
|
|
c62f1995e7 | ||
|
|
883e38ae58 | ||
|
|
1b2d4dbc46 | ||
|
|
7dfb35233e | ||
|
|
d842022056 | ||
|
|
0a8ebc3058 | ||
|
|
8ccae5ddec | ||
|
|
cfb143f0fd | ||
|
|
0281b5bef6 | ||
|
|
70a91b271d | ||
|
|
a7576ea765 | ||
|
|
3a492f51d9 | ||
|
|
d4ba37cde5 | ||
|
|
2ded4c6a2a | ||
|
|
24b3a9369e | ||
|
|
1d94fdd88d | ||
|
|
0af6b1cb13 | ||
|
|
d72c6f7057 | ||
|
|
39b9e7e352 | ||
|
|
36fefa6bb5 | ||
|
|
4ffdb331b4 | ||
|
|
7b995b3348 | ||
|
|
14d0f401fb | ||
|
|
df23604b1e | ||
|
|
e2960bc895 | ||
|
|
db90d361a9 | ||
|
|
6ec0c5e23c | ||
|
|
c84d681a3a | ||
|
|
62d1c8671b | ||
|
|
877adfa4b6 | ||
|
|
12fd44d0da | ||
|
|
12562eb8fd | ||
|
|
286481cbcd | ||
|
|
e9a877bd74 | ||
|
|
3060df1f05 | ||
|
|
aa1ae8c574 | ||
|
|
ccd8176c25
|
||
|
|
c230a1d916
|
||
|
|
2785a60dc0
|
||
|
|
1b65bda323 | ||
|
|
9ca07aca55 | ||
|
|
10b45027d0 | ||
|
|
d5c0063fee
|
||
|
|
31920b0692 | ||
|
|
89e4edc00b | ||
|
|
379a21ff7e | ||
|
|
0ac5225114 | ||
|
|
e918bdf28f | ||
|
|
50b83787e7 | ||
|
|
e6ca925562 | ||
|
|
0f92a7ce25 | ||
|
|
d4d91de80f | ||
|
|
a508a7e3a4 | ||
|
|
640fb032ea | ||
|
|
eee68760e4 | ||
|
|
7526de9b76 | ||
|
|
705ad50d65 | ||
|
|
e8cad54293 | ||
|
|
a548e9d04b | ||
|
|
d4c8a7ce2c | ||
|
|
ba290e0f7c | ||
|
|
234f510e98 | ||
|
|
8224ca3b57 | ||
|
|
a19c2761c8 | ||
|
|
739ea2a7f0 | ||
|
|
6c99991429 | ||
|
|
c9543dfbe4 | ||
|
|
76842b4bce | ||
|
|
7139e8d3c4 | ||
|
|
6f53ed5d87 | ||
|
|
063caa51f9 | ||
|
|
9ed8626067 | ||
|
|
cb0725bad1 | ||
|
|
44886c8f9f | ||
|
|
bdfd37de35 | ||
|
|
c49ca5a8cd | ||
|
|
b1a29ded7d | ||
|
|
e5083cd228 | ||
|
|
288fa38dac | ||
|
|
dbc0a928b9 | ||
|
|
9ead1676b0 | ||
|
|
97371d8f44 | ||
|
|
7ac6443b2c | ||
|
|
50eb58dfd9 | ||
|
|
833271b7a1 | ||
|
|
517cad33f4 | ||
|
|
d96e28cdcb |
@@ -0,0 +1,7 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: gitsubmodule
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
|
open-pull-requests-limit: 10
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "*"
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "*"
|
||||||
|
types: [opened, synchronize, reopened]
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.ref }}
|
||||||
|
cancel-in-progress: false
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build binaries
|
||||||
|
runs-on: windows-2022
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
configuration:
|
||||||
|
- Debug
|
||||||
|
- Release
|
||||||
|
steps:
|
||||||
|
- name: Check out files
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
fetch-depth: 0
|
||||||
|
lfs: false
|
||||||
|
|
||||||
|
- name: Add msbuild to PATH
|
||||||
|
uses: microsoft/setup-msbuild@v2
|
||||||
|
|
||||||
|
- name: Generate project files
|
||||||
|
run: tools/premake5 vs2022
|
||||||
|
|
||||||
|
- name: Set up problem matching
|
||||||
|
uses: ammaraskar/msvc-problem-matcher@master
|
||||||
|
|
||||||
|
- name: Build ${{matrix.configuration}} binaries
|
||||||
|
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@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 }}
|
||||||
+10
-6
@@ -4,12 +4,16 @@
|
|||||||
[submodule "deps/GSL"]
|
[submodule "deps/GSL"]
|
||||||
path = deps/GSL
|
path = deps/GSL
|
||||||
url = https://github.com/microsoft/GSL.git
|
url = https://github.com/microsoft/GSL.git
|
||||||
[submodule "deps/sol2"]
|
|
||||||
path = deps/sol2
|
|
||||||
url = https://github.com/ThePhD/sol2.git
|
|
||||||
[submodule "deps/lua"]
|
|
||||||
path = deps/lua
|
|
||||||
url = https://github.com/lua/lua.git
|
|
||||||
[submodule "deps/json"]
|
[submodule "deps/json"]
|
||||||
path = deps/json
|
path = deps/json
|
||||||
url = https://github.com/nlohmann/json.git
|
url = https://github.com/nlohmann/json.git
|
||||||
|
branch = develop
|
||||||
|
[submodule "deps/gsc-tool"]
|
||||||
|
path = deps/gsc-tool
|
||||||
|
url = https://github.com/xensik/gsc-tool.git
|
||||||
|
[submodule "deps/zlib"]
|
||||||
|
path = deps/zlib
|
||||||
|
url = https://github.com/madler/zlib.git
|
||||||
|
[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
|
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
|
# Misc
|
||||||
|
|
||||||
* `executeCommand(command)`: Executes a console command.
|
* `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):
|
* `addCommand(name, callback)`: Adds a console command (gets removed after a map restart):
|
||||||
|
|
||||||
```c
|
```c
|
||||||
@@ -43,27 +34,37 @@ This plugin adds some useful functions/methods to IW5's GSC VM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
# Player
|
||||||
|
* `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.
|
||||||
|
* `self resetClantag(name)`: Resets a player's clantag to its original.
|
||||||
|
* `self removeClantag(name)`: Removes a player's clantag.
|
||||||
# IO
|
# IO
|
||||||
* `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
|
The basepath for all IO functions is `Plutonium/storage/iw5`.
|
||||||
init()
|
* `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.
|
||||||
basePath = getDvar("fs_basegame") + "/";
|
* `readFile(path)`: Reads a file.
|
||||||
|
* `fileSize(path)`: Returns file size in bytes.
|
||||||
file = fopen(basePath + "test.txt", "w");
|
* `createDirectory(path)`: Creates a directory.
|
||||||
fwrite(file, "test");
|
* `directoryExists(path)`: Returns true if the directory exists.
|
||||||
fclose(file);
|
* `directoryIsEmpty(path)`: Returns true if the directory is empty.
|
||||||
|
* `listFiles(path)`: Returns the list of files in the directory as an array.
|
||||||
|
* `copyFolder(source, target)`: Copies a folder.
|
||||||
|
|
||||||
file = fopen(basePath + "test.txt", "r");
|
# HTTP
|
||||||
print(fread(file));
|
|
||||||
fclose(file);
|
* `httpGet(url)`: creates an HTTP request.
|
||||||
}
|
|
||||||
```
|
```c
|
||||||
|
init()
|
||||||
|
{
|
||||||
|
req = httpget("http://example.com");
|
||||||
|
req waittill("done", data);
|
||||||
|
print(data);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
# JSON
|
# JSON
|
||||||
|
|
||||||
@@ -205,6 +206,6 @@ This plugin adds some useful functions/methods to IW5's GSC VM
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
* `jsonPrint(...)`: Prints values as json.
|
||||||
# Credits
|
# Credits
|
||||||
* [xensik](https://github.com/xensik)
|
* [xensik](https://github.com/xensik)
|
||||||
|
|||||||
Vendored
+1
-1
Submodule deps/GSL updated: c1cbb41b42...b39e7e4b09
Vendored
+1
-1
Submodule deps/json updated: e10a3fac8a...d0d29039da
Vendored
+1
-1
Submodule deps/minhook updated: 423d1e45af...d94c64d32e
+1
Submodule deps/plutonium-sdk added at 17e9a0a4d5
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)
|
||||||
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
@echo off
|
@echo off
|
||||||
tools\windows\premake5.exe vs2019
|
call git submodule update --init --recursive
|
||||||
|
tools\premake5.exe vs2022
|
||||||
|
|||||||
+12
-9
@@ -36,32 +36,35 @@ workspace "iw5-gsc-utils"
|
|||||||
targetdir "%{wks.location}/bin/%{cfg.buildcfg}"
|
targetdir "%{wks.location}/bin/%{cfg.buildcfg}"
|
||||||
targetname "%{prj.name}"
|
targetname "%{prj.name}"
|
||||||
|
|
||||||
|
configurations { "Debug", "Release", }
|
||||||
|
|
||||||
language "C++"
|
language "C++"
|
||||||
|
cppdialect "C++20"
|
||||||
|
|
||||||
architecture "x86"
|
architecture "x86"
|
||||||
|
|
||||||
buildoptions "/std:c++latest"
|
|
||||||
systemversion "latest"
|
systemversion "latest"
|
||||||
|
symbols "On"
|
||||||
|
staticruntime "On"
|
||||||
|
editandcontinue "Off"
|
||||||
|
warnings "Extra"
|
||||||
|
characterset "ASCII"
|
||||||
|
|
||||||
flags
|
flags
|
||||||
{
|
{
|
||||||
"NoIncrementalLink",
|
"NoIncrementalLink",
|
||||||
"MultiProcessorCompile",
|
"MultiProcessorCompile",
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations { "Debug", "Release", }
|
|
||||||
|
|
||||||
symbols "On"
|
|
||||||
|
|
||||||
configuration "Release"
|
filter "configurations:Release"
|
||||||
optimize "Full"
|
optimize "Full"
|
||||||
defines { "NDEBUG" }
|
defines { "NDEBUG" }
|
||||||
configuration{}
|
filter {}
|
||||||
|
|
||||||
configuration "Debug"
|
filter "configurations:Debug"
|
||||||
optimize "Debug"
|
optimize "Debug"
|
||||||
defines { "DEBUG", "_DEBUG" }
|
defines { "DEBUG", "_DEBUG" }
|
||||||
configuration {}
|
filter {}
|
||||||
|
|
||||||
startproject "iw5-gsc-utils"
|
startproject "iw5-gsc-utils"
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
namespace command
|
namespace command
|
||||||
{
|
{
|
||||||
std::unordered_map<std::string, std::function<void(params&)>> handlers;
|
std::unordered_map<std::string, std::function<void(params&)>> handlers;
|
||||||
|
std::vector<std::string> script_commands;
|
||||||
|
utils::memory::allocator allocator;
|
||||||
|
|
||||||
void main_handler()
|
void main_handler()
|
||||||
{
|
{
|
||||||
@@ -46,9 +48,14 @@ namespace command
|
|||||||
|
|
||||||
for (auto i = index; i < this->size(); i++)
|
for (auto i = index; i < this->size(); i++)
|
||||||
{
|
{
|
||||||
if (i > index) result.append(" ");
|
if (i > index)
|
||||||
|
{
|
||||||
|
result.append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
result.append(this->get(i));
|
result.append(this->get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,14 +76,11 @@ namespace command
|
|||||||
handlers[command] = callback;
|
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)
|
void add_script_command(const std::string& name, const std::function<void(const params&)>& callback)
|
||||||
{
|
{
|
||||||
script_commands.push_back(name);
|
script_commands.push_back(name);
|
||||||
const auto _name = allocator.duplicate_string(name);
|
const auto name_str = allocator.duplicate_string(name);
|
||||||
add(_name, callback);
|
add(name_str, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_script_commands()
|
void clear_script_commands()
|
||||||
@@ -94,9 +98,8 @@ namespace command
|
|||||||
class component final : public component_interface
|
class component final : public component_interface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void post_unpack() override
|
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,4 @@ namespace command
|
|||||||
|
|
||||||
void add_script_command(const std::string& name, const std::function<void(const params&)>& callback);
|
void add_script_command(const std::string& name, const std::function<void(const params&)>& callback);
|
||||||
void clear_script_commands();
|
void clear_script_commands();
|
||||||
}
|
}
|
||||||
|
|||||||
+234
-217
@@ -8,78 +8,18 @@
|
|||||||
#include "game/scripting/execution.hpp"
|
#include "game/scripting/execution.hpp"
|
||||||
#include "game/scripting/functions.hpp"
|
#include "game/scripting/functions.hpp"
|
||||||
#include "game/scripting/array.hpp"
|
#include "game/scripting/array.hpp"
|
||||||
|
#include "game/scripting/function.hpp"
|
||||||
|
|
||||||
#include "gsc.hpp"
|
#include "gsc.hpp"
|
||||||
|
|
||||||
namespace gsc
|
namespace gsc
|
||||||
{
|
{
|
||||||
function_args::function_args(std::vector<scripting::script_value> values)
|
|
||||||
: values_(values)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int function_args::size() const
|
|
||||||
{
|
|
||||||
return this->values_.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<scripting::script_value> function_args::get_raw() const
|
|
||||||
{
|
|
||||||
return this->values_;
|
|
||||||
}
|
|
||||||
|
|
||||||
scripting::script_value function_args::get(const int index) const
|
|
||||||
{
|
|
||||||
if (index >= this->values_.size())
|
|
||||||
{
|
|
||||||
throw std::runtime_error(utils::string::va("Insufficient arguments, got %i expected %i",
|
|
||||||
this->values_.size(), index + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
return this->values_[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unordered_map<unsigned, script_function> functions;
|
|
||||||
std::unordered_map<unsigned, script_method> methods;
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::string method_name(unsigned int id)
|
|
||||||
{
|
|
||||||
const auto map = *game::plutonium::method_map_rev;
|
|
||||||
|
|
||||||
for (const auto& function : map)
|
|
||||||
{
|
|
||||||
if (function.second == id)
|
|
||||||
{
|
|
||||||
return function.first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string function_name(unsigned int id)
|
|
||||||
{
|
|
||||||
const auto map = *game::plutonium::function_map_rev;
|
|
||||||
|
|
||||||
for (const auto& function : map)
|
|
||||||
{
|
|
||||||
if (function.second == id)
|
|
||||||
{
|
|
||||||
return function.first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
function_args get_arguments()
|
function_args get_arguments()
|
||||||
{
|
{
|
||||||
std::vector<scripting::script_value> args;
|
std::vector<scripting::script_value> args;
|
||||||
|
|
||||||
const auto top = game::scr_VmPub->top;
|
|
||||||
|
|
||||||
for (auto i = 0; i < game::scr_VmPub->outparamcount; i++)
|
for (auto i = 0; i < game::scr_VmPub->outparamcount; i++)
|
||||||
{
|
{
|
||||||
const auto value = game::scr_VmPub->top[-i];
|
const auto value = game::scr_VmPub->top[-i];
|
||||||
@@ -99,19 +39,23 @@ namespace gsc
|
|||||||
scripting::push_value(value);
|
scripting::push_value(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto function_map_start = 0x200;
|
auto field_offset_start = 0xA000;
|
||||||
auto method_map_start = 0x8400;
|
|
||||||
|
|
||||||
void call_function(unsigned int id)
|
struct entity_field
|
||||||
{
|
{
|
||||||
if (id < 0x200)
|
std::string name;
|
||||||
{
|
std::function<scripting::script_value(unsigned int entnum)> getter;
|
||||||
return reinterpret_cast<builtin_function*>(0x1D6EB34)[id]();
|
std::function<void(unsigned int entnum, scripting::script_value)> setter;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
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(const script_function* function, const char* name)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const auto result = functions[id](get_arguments());
|
const auto result = function->operator()(get_arguments());
|
||||||
const auto type = result.get_raw().type;
|
const auto type = result.get_raw().type;
|
||||||
|
|
||||||
if (type)
|
if (type)
|
||||||
@@ -119,25 +63,20 @@ namespace gsc
|
|||||||
return_value(result);
|
return_value(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
printf("************** Script execution error **************\n");
|
printf("************** Script execution error **************");
|
||||||
printf("Error executing function %s\n", function_name(id).data());
|
printf("Error executing function %s:", name);
|
||||||
printf("%s\n", e.what());
|
printf(" %s", e.what());
|
||||||
printf("****************************************************\n");
|
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*>(0x1D4F258)[id](ent);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const auto result = methods[id](ent, get_arguments());
|
const auto result = method->operator()(ent, get_arguments());
|
||||||
const auto type = result.get_raw().type;
|
const auto type = result.get_raw().type;
|
||||||
|
|
||||||
if (type)
|
if (type)
|
||||||
@@ -145,177 +84,210 @@ namespace gsc
|
|||||||
return_value(result);
|
return_value(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
printf("************** Script execution error **************\n");
|
printf("************** Script execution error **************");
|
||||||
printf("Error executing method %s\n", method_name(id).data());
|
printf("Error executing method %s:", name);
|
||||||
printf("%s\n", e.what());
|
printf(" %s", e.what());
|
||||||
printf("****************************************************\n");
|
printf("****************************************************");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__declspec(naked) void call_builtin_stub()
|
utils::hook::detour scr_get_object_field_hook;
|
||||||
|
void scr_get_object_field_stub(unsigned int classnum, int entnum, unsigned int offset)
|
||||||
{
|
{
|
||||||
__asm
|
if (custom_fields[classnum].find(offset) == custom_fields[classnum].end())
|
||||||
{
|
{
|
||||||
push eax
|
return scr_get_object_field_hook.invoke<void>(classnum, entnum, offset);
|
||||||
|
}
|
||||||
|
|
||||||
mov eax, 0x20B4A5C
|
const auto& field = custom_fields[classnum][offset];
|
||||||
mov [eax], esi
|
|
||||||
|
|
||||||
mov eax, 0x20B4A90
|
try
|
||||||
mov [eax], edx
|
{
|
||||||
|
const auto result = field.getter(entnum);
|
||||||
pop eax
|
return_value(result);
|
||||||
|
}
|
||||||
pushad
|
catch (const std::exception& e)
|
||||||
push eax
|
{
|
||||||
call call_function
|
printf("************** Script execution error **************");
|
||||||
pop eax
|
printf("Error getting field %s:", field.name.data());
|
||||||
popad
|
printf(" %s", e.what());
|
||||||
|
printf("****************************************************");
|
||||||
push 0x56C900
|
|
||||||
retn
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__declspec(naked) void call_builtin_method_stub()
|
utils::hook::detour scr_set_object_field_hook;
|
||||||
|
void scr_set_object_field_stub(unsigned int classnum, int entnum, unsigned int offset)
|
||||||
{
|
{
|
||||||
__asm
|
if (custom_fields[classnum].find(offset) == custom_fields[classnum].end())
|
||||||
{
|
{
|
||||||
pushad
|
return scr_set_object_field_hook.invoke<void>(classnum, entnum, offset);
|
||||||
push ecx
|
}
|
||||||
push ebx
|
|
||||||
call call_method
|
|
||||||
pop ebx
|
|
||||||
pop ecx
|
|
||||||
popad
|
|
||||||
|
|
||||||
push ebx
|
const auto args = get_arguments();
|
||||||
add esp, 0xC
|
const auto& field = custom_fields[classnum][offset];
|
||||||
|
|
||||||
push 0x56CBE9
|
try
|
||||||
retn
|
{
|
||||||
|
field.setter(entnum, args[0]);
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
printf("************** Script execution error **************");
|
||||||
|
printf("Error setting field %s:", field.name.data());
|
||||||
|
printf(" %s", e.what());
|
||||||
|
printf("****************************************************");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int replaced_pos = 0;
|
utils::hook::detour scr_post_load_scripts_hook;
|
||||||
|
void scr_post_load_scripts_stub()
|
||||||
void get_replaced_pos(unsigned int pos)
|
|
||||||
{
|
{
|
||||||
if (scripting::replaced_functions.find(pos) != scripting::replaced_functions.end())
|
for (const auto& callback : post_load_callbacks)
|
||||||
{
|
{
|
||||||
replaced_pos = scripting::replaced_functions[pos];
|
callback();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
__declspec(naked) void vm_execute_stub()
|
return scr_post_load_scripts_hook.invoke<void>();
|
||||||
{
|
|
||||||
__asm
|
|
||||||
{
|
|
||||||
pushad
|
|
||||||
push esi
|
|
||||||
call get_replaced_pos
|
|
||||||
pop esi
|
|
||||||
popad
|
|
||||||
|
|
||||||
cmp replaced_pos, 0
|
|
||||||
jne set_pos
|
|
||||||
|
|
||||||
movzx eax, byte ptr[esi]
|
|
||||||
inc esi
|
|
||||||
|
|
||||||
jmp loc_1
|
|
||||||
loc_1:
|
|
||||||
mov [ebp - 0x18], eax
|
|
||||||
mov [ebp - 0x8], esi
|
|
||||||
|
|
||||||
push ecx
|
|
||||||
|
|
||||||
mov ecx, 0x20B8E28
|
|
||||||
mov [ecx], eax
|
|
||||||
|
|
||||||
mov ecx, 0x20B4A5C
|
|
||||||
mov[ecx], esi
|
|
||||||
|
|
||||||
pop ecx
|
|
||||||
|
|
||||||
cmp eax, 0x98
|
|
||||||
|
|
||||||
push 0x56B740
|
|
||||||
retn
|
|
||||||
set_pos:
|
|
||||||
mov esi, replaced_pos
|
|
||||||
mov replaced_pos, 0
|
|
||||||
|
|
||||||
movzx eax, byte ptr[esi]
|
|
||||||
inc esi
|
|
||||||
|
|
||||||
jmp loc_1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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[] =
|
||||||
{
|
{
|
||||||
const auto index = function_map_start++;
|
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
|
||||||
|
};
|
||||||
|
|
||||||
functions[index] = func;
|
const auto stub = utils::memory::allocate_array<std::uint8_t>(sizeof(bytes));
|
||||||
(*game::plutonium::function_map_rev)[name] = index;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
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 + 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
|
||||||
|
{
|
||||||
|
void add(const classid classnum, const std::string& name,
|
||||||
|
const std::function<scripting::script_value(unsigned int entnum)>& getter,
|
||||||
|
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter)
|
||||||
|
{
|
||||||
|
const auto offset = field_offset_start++;
|
||||||
|
custom_fields[classnum][offset] = {name, getter, setter};
|
||||||
|
|
||||||
|
post_load_callbacks.push_back([=]()
|
||||||
|
{
|
||||||
|
const auto name_str = game::SL_GetString(name.data(), 0);
|
||||||
|
game::Scr_AddClassField(classnum, name_str, game::SL_GetCanonicalString(name.data()), offset);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace method
|
function_args::function_args(std::vector<scripting::script_value> values)
|
||||||
|
: values_(values)
|
||||||
{
|
{
|
||||||
void add(const std::string& name, const script_method& func)
|
}
|
||||||
{
|
|
||||||
const auto index = method_map_start++;
|
|
||||||
|
|
||||||
methods[index] = func;
|
unsigned int function_args::size() const
|
||||||
(*game::plutonium::method_map_rev)[name] = index;
|
{
|
||||||
|
return this->values_.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<scripting::script_value> function_args::get_raw() const
|
||||||
|
{
|
||||||
|
return this->values_;
|
||||||
|
}
|
||||||
|
|
||||||
|
scripting::value_wrap function_args::get(const int index) const
|
||||||
|
{
|
||||||
|
if (index >= this->values_.size())
|
||||||
|
{
|
||||||
|
throw std::runtime_error(utils::string::va("parameter %d does not exist", index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {this->values_[index], index};
|
||||||
}
|
}
|
||||||
|
|
||||||
class component final : public component_interface
|
class component final : public component_interface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void post_unpack() override
|
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||||
{
|
{
|
||||||
function::add("executecommand", [](function_args args) -> scripting::script_value
|
scr_get_object_field_hook.create(0x52BDB0, scr_get_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);
|
||||||
|
|
||||||
|
field::add(classid::entity, "entityflags",
|
||||||
|
[](unsigned int entnum) -> scripting::script_value
|
||||||
|
{
|
||||||
|
const auto entity = &game::g_entities[entnum];
|
||||||
|
return entity->flags;
|
||||||
|
},
|
||||||
|
[](unsigned int entnum, const scripting::script_value& value)
|
||||||
|
{
|
||||||
|
const auto entity = &game::g_entities[entnum];
|
||||||
|
entity->flags = value.as<int>();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
field::add(classid::entity, "clientflags",
|
||||||
|
[](unsigned int entnum) -> scripting::script_value
|
||||||
|
{
|
||||||
|
const auto entity = &game::g_entities[entnum];
|
||||||
|
return entity->client->flags;
|
||||||
|
},
|
||||||
|
[](unsigned int entnum, const scripting::script_value& value)
|
||||||
|
{
|
||||||
|
const auto entity = &game::g_entities[entnum];
|
||||||
|
entity->client->flags = value.as<int>();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
function::add("executecommand", [](const function_args& args) -> scripting::script_value
|
||||||
{
|
{
|
||||||
game::Cbuf_AddText(0, args[0].as<const char*>());
|
game::Cbuf_AddText(0, args[0].as<const char*>());
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
function::add("replacefunc", [](function_args args) -> scripting::script_value
|
function::add("addcommand", [](const function_args& args) -> scripting::script_value
|
||||||
{
|
|
||||||
const auto what = args[0].get_raw();
|
|
||||||
const auto with = args[1].get_raw();
|
|
||||||
|
|
||||||
if (what.type != game::SCRIPT_FUNCTION || with.type != game::SCRIPT_FUNCTION)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid type");
|
|
||||||
}
|
|
||||||
|
|
||||||
scripting::replaced_functions[what.u.uintValue] = with.u.uintValue;
|
|
||||||
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
|
|
||||||
function::add("addcommand", [](function_args args) -> scripting::script_value
|
|
||||||
{
|
{
|
||||||
const auto name = args[0].as<std::string>();
|
const auto name = args[0].as<std::string>();
|
||||||
const auto function = args[1].get_raw();
|
const auto function = args[1].as<scripting::function>();
|
||||||
|
command::add_script_command(name, [function](const command::params& params)
|
||||||
if (function.type != game::SCRIPT_FUNCTION)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid type");
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto pos = function.u.codePosValue;
|
|
||||||
command::add_script_command(name, [pos](const command::params& params)
|
|
||||||
{
|
{
|
||||||
scripting::array array;
|
scripting::array array;
|
||||||
for (auto i = 0; i < params.size(); i++)
|
for (auto i = 0; i < params.size(); i++)
|
||||||
@@ -323,40 +295,85 @@ namespace gsc
|
|||||||
array.push(params[i]);
|
array.push(params[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
scripting::exec_ent_thread(*game::levelEntityId, pos, {array.get_raw()});
|
function({array.get_raw()});
|
||||||
});
|
});
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
function::add("say", [](function_args args) -> scripting::script_value
|
function::add("dropallbots", [](const function_args&) -> scripting::script_value
|
||||||
{
|
{
|
||||||
const auto message = args[0].as<std::string>();
|
for (auto i = 0; i < *game::svs_clientCount; i++)
|
||||||
game::SV_GameSendServerCommand(-1, 0, utils::string::va("%c \"%s\"", 84, message.data()));
|
{
|
||||||
|
if (game::svs_clients[i].header.state != game::CS_FREE
|
||||||
|
&& game::svs_clients[i].header.netchan.remoteAddress.type == game::NA_BOT)
|
||||||
|
{
|
||||||
|
game::SV_GameDropClient(i, "GAME_GET_TO_COVER");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
method::add("tell", [](game::scr_entref_t ent, function_args args) -> scripting::script_value
|
method::add("specialtymarathon", [](const game::scr_entref_t ent, const function_args& args) -> scripting::script_value
|
||||||
{
|
{
|
||||||
if (ent.classnum != 0)
|
if (ent.classnum != 0)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid type");
|
throw std::runtime_error("invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto client = ent.entnum;
|
const auto client = ent.entnum;
|
||||||
const auto message = args[0].as<std::string>();
|
|
||||||
|
|
||||||
game::SV_GameSendServerCommand(client, 0, utils::string::va("%c \"%s\"", 84, message.data()));
|
if (game::g_entities[client].client == nullptr)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
utils::hook::jump(0x56C8EB, call_builtin_stub);
|
method::add("isbot", [](const game::scr_entref_t ent, const function_args&) -> scripting::script_value
|
||||||
utils::hook::jump(0x56CBDC, call_builtin_method_stub);
|
{
|
||||||
utils::hook::jump(0x56B726, vm_execute_stub);
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
return game::svs_clients[client].bIsTestClient;
|
||||||
|
});
|
||||||
|
|
||||||
|
method::add("arecontrolsfrozen", [](const game::scr_entref_t ent, const function_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");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {(game::g_entities[client].client->flags & 4) != 0};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_COMPONENT(gsc::component)
|
REGISTER_COMPONENT(gsc::component)
|
||||||
|
|||||||
+45
-8
@@ -1,17 +1,28 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "game/scripting/array.hpp"
|
||||||
|
#include "game/scripting/execution.hpp"
|
||||||
|
|
||||||
namespace gsc
|
namespace gsc
|
||||||
{
|
{
|
||||||
|
enum classid
|
||||||
|
{
|
||||||
|
entity,
|
||||||
|
hudelem,
|
||||||
|
pathnode,
|
||||||
|
node,
|
||||||
|
count
|
||||||
|
};
|
||||||
|
|
||||||
class function_args
|
class function_args
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
function_args(std::vector<scripting::script_value>);
|
function_args(std::vector<scripting::script_value>);
|
||||||
|
|
||||||
unsigned int function_args::size() const;
|
unsigned int size() const;
|
||||||
std::vector<scripting::script_value> function_args::get_raw() const;
|
std::vector<scripting::script_value> get_raw() const;
|
||||||
scripting::script_value get(const int index) const;
|
scripting::value_wrap get(const int index) const;
|
||||||
|
|
||||||
scripting::script_value operator[](const int index) const
|
scripting::value_wrap operator[](const int index) const
|
||||||
{
|
{
|
||||||
return this->get(index);
|
return this->get(index);
|
||||||
}
|
}
|
||||||
@@ -22,16 +33,42 @@ namespace gsc
|
|||||||
using builtin_function = void(*)();
|
using builtin_function = void(*)();
|
||||||
using builtin_method = void(*)(game::scr_entref_t);
|
using builtin_method = void(*)(game::scr_entref_t);
|
||||||
|
|
||||||
using script_function = std::function<scripting::script_value(function_args)>;
|
using script_function = std::function<scripting::script_value(const function_args&)>;
|
||||||
using script_method = std::function<scripting::script_value(game::scr_entref_t, 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
|
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
|
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
|
||||||
|
{
|
||||||
|
void add(const classid classnum, const std::string& name,
|
||||||
|
const std::function<scripting::script_value(unsigned int entnum)>& getter,
|
||||||
|
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+117
-65
@@ -2,85 +2,127 @@
|
|||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
|
|
||||||
#include "game/scripting/event.hpp"
|
|
||||||
#include "game/scripting/execution.hpp"
|
|
||||||
#include "game/scripting/functions.hpp"
|
|
||||||
#include "game/scripting/array.hpp"
|
|
||||||
|
|
||||||
#include "gsc.hpp"
|
#include "gsc.hpp"
|
||||||
|
#include "json.hpp"
|
||||||
|
#include "scripting.hpp"
|
||||||
|
|
||||||
namespace io
|
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
|
class component final : public component_interface
|
||||||
{
|
{
|
||||||
public:
|
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;
|
const auto fs_basegame = game::Dvar_FindVar("fs_basegame");
|
||||||
std::filesystem::current_path(path);
|
if (fs_basegame == nullptr)
|
||||||
|
|
||||||
gsc::function::add("fremove", [](gsc::function_args args)
|
|
||||||
{
|
{
|
||||||
const auto path = args[0].as<const char*>();
|
return;
|
||||||
return std::remove(path);
|
}
|
||||||
|
|
||||||
|
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("fopen", [](gsc::function_args args)
|
gsc::function::add("jsonprint", [](const gsc::function_args& args) -> scripting::script_value
|
||||||
{
|
{
|
||||||
const auto* path = args[0].as<const char*>();
|
std::string buffer;
|
||||||
const auto* mode = args[1].as<const char*>();
|
|
||||||
|
|
||||||
const auto handle = fopen(path, mode);
|
for (const auto& arg : args.get_raw())
|
||||||
|
|
||||||
if (!handle)
|
|
||||||
{
|
{
|
||||||
printf("fopen: Invalid path\n");
|
buffer.append(json::gsc_to_string(arg));
|
||||||
|
buffer.append("\t");
|
||||||
}
|
}
|
||||||
|
|
||||||
return handle;
|
printf("%s", buffer.data());
|
||||||
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("fclose", [](gsc::function_args args)
|
gsc::function::add("fileexists", [](const gsc::function_args& args)
|
||||||
{
|
|
||||||
const auto handle = args[0].as_ptr<FILE>();
|
|
||||||
return fclose(handle);
|
|
||||||
});
|
|
||||||
|
|
||||||
gsc::function::add("fwrite", [](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", [](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", [](gsc::function_args args)
|
|
||||||
{
|
{
|
||||||
const auto path = args[0].as<std::string>();
|
const auto path = args[0].as<std::string>();
|
||||||
return utils::io::file_exists(path);
|
return utils::io::file_exists(path);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("writefile", [](gsc::function_args args)
|
gsc::function::add("writefile", [](const gsc::function_args& args)
|
||||||
{
|
{
|
||||||
const auto path = args[0].as<std::string>();
|
const auto path = args[0].as<std::string>();
|
||||||
const auto data = args[1].as<std::string>();
|
const auto data = args[1].as<std::string>();
|
||||||
@@ -94,37 +136,37 @@ namespace io
|
|||||||
return utils::io::write_file(path, data, append);
|
return utils::io::write_file(path, data, append);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("readfile", [](gsc::function_args args)
|
gsc::function::add("readfile", [](const gsc::function_args& args)
|
||||||
{
|
{
|
||||||
const auto path = args[0].as<std::string>();
|
const auto path = args[0].as<std::string>();
|
||||||
return utils::io::read_file(path);
|
return utils::io::read_file(path);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("filesize", [](gsc::function_args args)
|
gsc::function::add("filesize", [](const gsc::function_args& args)
|
||||||
{
|
{
|
||||||
const auto path = args[0].as<std::string>();
|
const auto path = args[0].as<std::string>();
|
||||||
return utils::io::file_size(path);
|
return utils::io::file_size(path);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("createdirectory", [](gsc::function_args args)
|
gsc::function::add("createdirectory", [](const gsc::function_args& args)
|
||||||
{
|
{
|
||||||
const auto path = args[0].as<std::string>();
|
const auto path = args[0].as<std::string>();
|
||||||
return utils::io::create_directory(path);
|
return utils::io::create_directory(path);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("directoryexists", [](gsc::function_args args)
|
gsc::function::add("directoryexists", [](const gsc::function_args& args)
|
||||||
{
|
{
|
||||||
const auto path = args[0].as<std::string>();
|
const auto path = args[0].as<std::string>();
|
||||||
return utils::io::directory_exists(path);
|
return utils::io::directory_exists(path);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("directoryisempty", [](gsc::function_args args)
|
gsc::function::add("directoryisempty", [](const gsc::function_args& args)
|
||||||
{
|
{
|
||||||
const auto path = args[0].as<std::string>();
|
const auto path = args[0].as<std::string>();
|
||||||
return utils::io::directory_is_empty(path);
|
return utils::io::directory_is_empty(path);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("listfiles", [](gsc::function_args args)
|
gsc::function::add("listfiles", [](const gsc::function_args& args)
|
||||||
{
|
{
|
||||||
const auto path = args[0].as<std::string>();
|
const auto path = args[0].as<std::string>();
|
||||||
const auto files = utils::io::list_files(path);
|
const auto files = utils::io::list_files(path);
|
||||||
@@ -135,10 +177,10 @@ namespace io
|
|||||||
array.push(file);
|
array.push(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array.get_raw();
|
return array;
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("copyfolder", [](gsc::function_args args)
|
gsc::function::add("copyfolder", [](const gsc::function_args& args)
|
||||||
{
|
{
|
||||||
const auto source = args[0].as<std::string>();
|
const auto source = args[0].as<std::string>();
|
||||||
const auto target = args[1].as<std::string>();
|
const auto target = args[1].as<std::string>();
|
||||||
@@ -146,8 +188,18 @@ namespace io
|
|||||||
|
|
||||||
return scripting::script_value{};
|
return scripting::script_value{};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
gsc::function::add("httpget", [](const gsc::function_args& args) -> scripting::script_value
|
||||||
|
{
|
||||||
|
const auto url = args[0].as<std::string>();
|
||||||
|
const auto object = scripting::entity(scripting::make_object());
|
||||||
|
|
||||||
|
add_request(url, object);
|
||||||
|
|
||||||
|
return object;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_COMPONENT(io::component)
|
REGISTER_COMPONENT(io::component)
|
||||||
|
|||||||
+23
-18
@@ -2,13 +2,8 @@
|
|||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
|
|
||||||
#include "game/scripting/event.hpp"
|
|
||||||
#include "game/scripting/execution.hpp"
|
|
||||||
#include "game/scripting/functions.hpp"
|
|
||||||
#include "game/scripting/array.hpp"
|
|
||||||
|
|
||||||
#include "gsc.hpp"
|
#include "gsc.hpp"
|
||||||
|
#include "json.hpp"
|
||||||
|
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
|
|
||||||
@@ -27,18 +22,23 @@ namespace json
|
|||||||
const auto keys = array.get_keys();
|
const auto keys = array.get_keys();
|
||||||
for (auto i = 0; i < keys.size(); i++)
|
for (auto i = 0; i < keys.size(); i++)
|
||||||
{
|
{
|
||||||
|
const auto is_int = keys[i].is<int>();
|
||||||
|
const auto is_string = keys[i].is<std::string>();
|
||||||
|
|
||||||
if (string_indexed == -1)
|
if (string_indexed == -1)
|
||||||
{
|
{
|
||||||
string_indexed = keys[i].is_string;
|
string_indexed = is_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string_indexed && keys[i].is_integer)
|
if (!string_indexed && is_int)
|
||||||
{
|
{
|
||||||
obj[keys[i].index] = gsc_to_json(array[keys[i].index]);
|
const auto index = keys[i].as<int>();
|
||||||
|
obj[index] = gsc_to_json(array[index]);
|
||||||
}
|
}
|
||||||
else if (string_indexed && keys[i].is_string)
|
else if (string_indexed && is_string)
|
||||||
{
|
{
|
||||||
obj.emplace(keys[i].key, gsc_to_json(array[keys[i].key]));
|
const auto key = keys[i].as<std::string>();
|
||||||
|
obj.emplace(key, gsc_to_json(array[key]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,18 +136,23 @@ namespace json
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string gsc_to_string(const scripting::script_value& value)
|
||||||
|
{
|
||||||
|
return gsc_to_json(value).dump();
|
||||||
|
}
|
||||||
|
|
||||||
class component final : public component_interface
|
class component final : public component_interface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void post_unpack() override
|
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||||
{
|
{
|
||||||
gsc::function::add("array", [](gsc::function_args args)
|
gsc::function::add("array", [](const gsc::function_args& args)
|
||||||
{
|
{
|
||||||
scripting::array array(args.get_raw());
|
scripting::array array(args.get_raw());
|
||||||
return array.get_raw();
|
return array.get_raw();
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("map", [](gsc::function_args args)
|
gsc::function::add("map", [](const gsc::function_args& args)
|
||||||
{
|
{
|
||||||
scripting::array array;
|
scripting::array array;
|
||||||
|
|
||||||
@@ -162,10 +167,10 @@ namespace json
|
|||||||
array[key] = args[i + 1];
|
array[key] = args[i + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return array.get_raw();
|
return array;
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("jsonparse", [](gsc::function_args args)
|
gsc::function::add("jsonparse", [](const gsc::function_args& args)
|
||||||
{
|
{
|
||||||
const auto json = args[0].as<std::string>();
|
const auto json = args[0].as<std::string>();
|
||||||
const auto obj = nlohmann::json::parse(json);
|
const auto obj = nlohmann::json::parse(json);
|
||||||
@@ -173,7 +178,7 @@ namespace json
|
|||||||
return json_to_gsc(obj);
|
return json_to_gsc(obj);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("jsonserialize", [](gsc::function_args args)
|
gsc::function::add("jsonserialize", [](const gsc::function_args& args)
|
||||||
{
|
{
|
||||||
const auto value = args[0];
|
const auto value = args[0];
|
||||||
auto indent = -1;
|
auto indent = -1;
|
||||||
@@ -189,4 +194,4 @@ namespace json
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_COMPONENT(json::component)
|
REGISTER_COMPONENT(json::component)
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace json
|
||||||
|
{
|
||||||
|
std::string gsc_to_string(const scripting::script_value& _value);
|
||||||
|
}
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#include <stdinc.hpp>
|
|
||||||
#include "loader/component_loader.hpp"
|
|
||||||
#include "scheduler.hpp"
|
|
||||||
|
|
||||||
#include "game/scripting/entity.hpp"
|
|
||||||
#include "game/scripting/execution.hpp"
|
|
||||||
|
|
||||||
namespace notifies
|
|
||||||
{
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
utils::hook::detour client_command_hook;
|
|
||||||
|
|
||||||
void client_command_stub(int clientNum)
|
|
||||||
{
|
|
||||||
char cmd[1024] = { 0 };
|
|
||||||
|
|
||||||
game::SV_Cmd_ArgvBuffer(0, cmd, 1024);
|
|
||||||
|
|
||||||
if (cmd == "say"s || cmd == "say_team"s)
|
|
||||||
{
|
|
||||||
std::string message = game::ConcatArgs(1);
|
|
||||||
message.erase(0, 1);
|
|
||||||
|
|
||||||
const scripting::entity level{*game::levelEntityId};
|
|
||||||
const auto player = scripting::call("getEntByNum", {clientNum}).as<scripting::entity>();
|
|
||||||
|
|
||||||
scripting::notify(level, cmd, {player, message});
|
|
||||||
scripting::notify(player, cmd, {message});
|
|
||||||
}
|
|
||||||
|
|
||||||
return 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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
REGISTER_COMPONENT(notifies::component)
|
|
||||||
+105
-30
@@ -1,83 +1,158 @@
|
|||||||
#include <stdinc.hpp>
|
#include <stdinc.hpp>
|
||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
|
#include "scheduler.hpp"
|
||||||
|
#include "game/game.hpp"
|
||||||
|
|
||||||
namespace scheduler
|
namespace scheduler
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::queue<std::function<void()>> tasks;
|
|
||||||
|
|
||||||
struct task
|
struct task
|
||||||
{
|
{
|
||||||
std::function<bool()> handler;
|
std::function<bool()> handler{};
|
||||||
std::chrono::milliseconds interval{};
|
std::chrono::milliseconds interval{};
|
||||||
std::chrono::high_resolution_clock::time_point last_call{};
|
std::chrono::high_resolution_clock::time_point last_call{};
|
||||||
};
|
};
|
||||||
|
|
||||||
utils::concurrent_list<task> callbacks;
|
using task_list = std::vector<task>;
|
||||||
|
|
||||||
void execute()
|
class task_pipeline
|
||||||
{
|
{
|
||||||
for (auto callback : callbacks)
|
public:
|
||||||
|
void add(task&& task)
|
||||||
{
|
{
|
||||||
const auto now = std::chrono::high_resolution_clock::now();
|
new_callbacks_.access([&task](task_list& tasks)
|
||||||
const auto diff = now - callback->last_call;
|
|
||||||
|
|
||||||
if (diff < callback->interval) continue;
|
|
||||||
|
|
||||||
callback->last_call = now;
|
|
||||||
|
|
||||||
const auto res = callback->handler();
|
|
||||||
if (res)
|
|
||||||
{
|
{
|
||||||
callbacks.remove(callback);
|
tasks.emplace_back(std::move(task));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void execute()
|
||||||
|
{
|
||||||
|
callbacks_.access([&](task_list& tasks)
|
||||||
|
{
|
||||||
|
this->merge_callbacks();
|
||||||
|
|
||||||
|
for (auto i = tasks.begin(); i != tasks.end();)
|
||||||
|
{
|
||||||
|
const auto now = std::chrono::high_resolution_clock::now();
|
||||||
|
const auto diff = now - i->last_call;
|
||||||
|
|
||||||
|
if (diff < i->interval)
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
i->last_call = now;
|
||||||
|
|
||||||
|
const auto res = i->handler();
|
||||||
|
if (res == cond_end)
|
||||||
|
{
|
||||||
|
i = tasks.erase(i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
utils::concurrency::container<task_list> new_callbacks_;
|
||||||
|
utils::concurrency::container<task_list, std::recursive_mutex> callbacks_;
|
||||||
|
|
||||||
|
void merge_callbacks()
|
||||||
|
{
|
||||||
|
callbacks_.access([&](task_list& tasks)
|
||||||
|
{
|
||||||
|
new_callbacks_.access([&](task_list& new_tasks)
|
||||||
|
{
|
||||||
|
tasks.insert(tasks.end(), std::move_iterator<task_list::iterator>(new_tasks.begin()), std::move_iterator<task_list::iterator>(new_tasks.end()));
|
||||||
|
new_tasks = {};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::thread thread;
|
||||||
|
std::atomic_bool killed;
|
||||||
|
task_pipeline pipelines[pipeline::count];
|
||||||
|
|
||||||
|
void execute(const pipeline type)
|
||||||
|
{
|
||||||
|
assert(type >= 0 && type < pipeline::count);
|
||||||
|
pipelines[type].execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void server_frame()
|
void server_frame_stub()
|
||||||
{
|
{
|
||||||
execute();
|
|
||||||
reinterpret_cast<void (*)()>(0x50C1E0)();
|
reinterpret_cast<void (*)()>(0x50C1E0)();
|
||||||
|
execute(pipeline::server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void schedule(const std::function<bool()>& callback, const std::chrono::milliseconds delay)
|
void schedule(const std::function<bool()>& callback, const pipeline type,
|
||||||
|
const std::chrono::milliseconds delay)
|
||||||
{
|
{
|
||||||
|
assert(type >= 0 && type < pipeline::count);
|
||||||
|
|
||||||
task task;
|
task task;
|
||||||
task.handler = callback;
|
task.handler = callback;
|
||||||
task.interval = delay;
|
task.interval = delay;
|
||||||
task.last_call = std::chrono::high_resolution_clock::now();
|
task.last_call = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
callbacks.add(task);
|
pipelines[type].add(std::move(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(const std::function<void()>& callback, const std::chrono::milliseconds delay)
|
void loop(const std::function<void()>& callback, const pipeline type,
|
||||||
|
const std::chrono::milliseconds delay)
|
||||||
{
|
{
|
||||||
schedule([callback]()
|
schedule([callback]()
|
||||||
{
|
{
|
||||||
callback();
|
callback();
|
||||||
return false;
|
return cond_continue;
|
||||||
}, delay);
|
}, type, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
void once(const std::function<void()>& callback, const std::chrono::milliseconds delay)
|
void once(const std::function<void()>& callback, const pipeline type,
|
||||||
|
const std::chrono::milliseconds delay)
|
||||||
{
|
{
|
||||||
schedule([callback]()
|
schedule([callback]()
|
||||||
{
|
{
|
||||||
callback();
|
callback();
|
||||||
return true;
|
return cond_end;
|
||||||
}, delay);
|
}, type, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
class component final : public component_interface
|
class component final : public component_interface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void post_unpack() override
|
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||||
{
|
{
|
||||||
utils::hook::call(0x50CEDC, server_frame);
|
thread = std::thread([]()
|
||||||
|
{
|
||||||
|
while (!killed)
|
||||||
|
{
|
||||||
|
execute(pipeline::async);
|
||||||
|
std::this_thread::sleep_for(10ms);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
utils::hook::call(0x50CEDC, server_frame_stub);
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_shutdown([[maybe_unused]] plugin::plugin* plugin) override
|
||||||
|
{
|
||||||
|
killed = true;
|
||||||
|
|
||||||
|
if (thread.joinable())
|
||||||
|
{
|
||||||
|
thread.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_COMPONENT(scheduler::component)
|
REGISTER_COMPONENT(scheduler::component)
|
||||||
|
|||||||
@@ -2,9 +2,20 @@
|
|||||||
|
|
||||||
namespace scheduler
|
namespace scheduler
|
||||||
{
|
{
|
||||||
void schedule(const std::function<bool()>& callback, std::chrono::milliseconds delay = 0ms);
|
enum pipeline
|
||||||
void loop(const std::function<void()>& callback, std::chrono::milliseconds delay = 0ms);
|
{
|
||||||
void once(const std::function<void()>& callback, std::chrono::milliseconds delay = 0ms);
|
server,
|
||||||
|
async,
|
||||||
|
count,
|
||||||
|
};
|
||||||
|
|
||||||
void init();
|
static const bool cond_continue = false;
|
||||||
|
static const bool cond_end = true;
|
||||||
|
|
||||||
|
void schedule(const std::function<bool()>& callback, pipeline type = pipeline::server,
|
||||||
|
std::chrono::milliseconds delay = 0ms);
|
||||||
|
void loop(const std::function<void()>& callback, pipeline type = pipeline::server,
|
||||||
|
std::chrono::milliseconds delay = 0ms);
|
||||||
|
void once(const std::function<void()>& callback, pipeline type = pipeline::server,
|
||||||
|
std::chrono::milliseconds delay = 0ms);
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-107
@@ -3,139 +3,49 @@
|
|||||||
|
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
#include "command.hpp"
|
#include "command.hpp"
|
||||||
|
#include "userinfo.hpp"
|
||||||
|
|
||||||
#include "game/scripting/event.hpp"
|
#include "game/scripting/event.hpp"
|
||||||
#include "game/scripting/execution.hpp"
|
#include "game/scripting/execution.hpp"
|
||||||
#include "game/scripting/functions.hpp"
|
#include "game/scripting/functions.hpp"
|
||||||
|
|
||||||
|
#include "gsc.hpp"
|
||||||
|
|
||||||
namespace scripting
|
namespace scripting
|
||||||
{
|
{
|
||||||
std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
|
|
||||||
std::unordered_map<std::string, std::unordered_map<std::string, char*>> script_function_table;
|
|
||||||
|
|
||||||
std::unordered_map<unsigned, unsigned> replaced_functions;
|
|
||||||
|
|
||||||
namespace
|
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 g_shutdown_game_hook;
|
||||||
|
|
||||||
utils::hook::detour scr_emit_function_hook;
|
std::vector<std::function<void()>> shutdown_callbacks;
|
||||||
utils::hook::detour scr_end_load_scripts_hook;
|
|
||||||
|
|
||||||
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")
|
|
||||||
{
|
|
||||||
scripting::clear_entity_fields(e.entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
void g_shutdown_game_stub(const int free_scripts)
|
||||||
{
|
{
|
||||||
|
userinfo::clear_overrides();
|
||||||
command::clear_script_commands();
|
command::clear_script_commands();
|
||||||
replaced_functions.clear();
|
|
||||||
|
for (const auto& callback : shutdown_callbacks)
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
g_shutdown_game_hook.invoke<void>(free_scripts);
|
g_shutdown_game_hook.invoke<void>(free_scripts);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char* function_pos(unsigned int filename, unsigned int name)
|
void on_shutdown(const std::function<void()>& callback)
|
||||||
{
|
{
|
||||||
const auto scripts_pos = *reinterpret_cast<int*>(0x1D6EB14);
|
shutdown_callbacks.push_back(callback);
|
||||||
|
|
||||||
const auto v2 = game::FindVariable(scripts_pos, filename);
|
|
||||||
|
|
||||||
const auto v3 = game::FindObject(scripts_pos, v2);
|
|
||||||
const auto v4 = game::FindVariable(v3, name);
|
|
||||||
|
|
||||||
if (!v2 || !v3 || !v4)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return utils::hook::invoke<char*>(0x5659C0, v3, v4);
|
|
||||||
}
|
|
||||||
|
|
||||||
void scr_emit_function_stub(unsigned int filename, unsigned int threadName, char* codePos)
|
|
||||||
{
|
|
||||||
const auto* name = game::SL_ConvertToString(filename);
|
|
||||||
const auto filename_id = atoi(name);
|
|
||||||
|
|
||||||
for (const auto& entry : scripting::file_list)
|
|
||||||
{
|
|
||||||
if (entry.first == filename_id)
|
|
||||||
{
|
|
||||||
if (script_function_table.find(entry.second) == script_function_table.end())
|
|
||||||
{
|
|
||||||
script_function_table[entry.second] = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& token : scripting::token_map)
|
|
||||||
{
|
|
||||||
if (token.second == threadName)
|
|
||||||
{
|
|
||||||
const auto pos = function_pos(filename, threadName);
|
|
||||||
|
|
||||||
if (pos)
|
|
||||||
{
|
|
||||||
script_function_table[entry.second][token.first] = pos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scr_emit_function_hook.invoke<void>(filename, threadName, codePos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class component final : public component_interface
|
class component final : public component_interface
|
||||||
{
|
{
|
||||||
public:
|
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);
|
g_shutdown_game_hook.create(0x50C100, g_shutdown_game_stub);
|
||||||
|
|
||||||
scr_add_class_field_hook.create(0x567CD0, scr_add_class_field_stub);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_COMPONENT(scripting::component)
|
REGISTER_COMPONENT(scripting::component)
|
||||||
|
|||||||
@@ -2,8 +2,5 @@
|
|||||||
|
|
||||||
namespace scripting
|
namespace scripting
|
||||||
{
|
{
|
||||||
extern std::unordered_map<unsigned, unsigned> replaced_functions;
|
void on_shutdown(const std::function<void()>& callback);
|
||||||
|
|
||||||
extern std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
|
|
||||||
extern std::unordered_map<std::string, std::unordered_map<std::string, char*>> script_function_table;
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#include <stdinc.hpp>
|
||||||
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
|
#include "gsc.hpp"
|
||||||
|
|
||||||
|
#include <utils/string.hpp>
|
||||||
|
|
||||||
|
namespace string
|
||||||
|
{
|
||||||
|
class component final : public component_interface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
|
||||||
|
{
|
||||||
|
gsc::function::add("getchar", [](const gsc::function_args& args)
|
||||||
|
{
|
||||||
|
auto index = 0;
|
||||||
|
if (args.size() > 1)
|
||||||
|
{
|
||||||
|
index = args[1].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto string = args[0].as<std::string>();
|
||||||
|
if (index >= static_cast<int>(string.size()))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("char index out of bounds");
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<int>(string[index]);
|
||||||
|
});
|
||||||
|
|
||||||
|
gsc::function::add("chartostring", [](const gsc::function_args& args)
|
||||||
|
{
|
||||||
|
const auto char_ = static_cast<char>(args[0].as<int>());
|
||||||
|
return std::string(1, char_);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
REGISTER_COMPONENT(string::component)
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
#include <stdinc.hpp>
|
||||||
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
|
#include "scheduler.hpp"
|
||||||
|
#include "gsc.hpp"
|
||||||
|
|
||||||
|
namespace userinfo
|
||||||
|
{
|
||||||
|
using userinfo_map = std::unordered_map<std::string, std::string>;
|
||||||
|
std::unordered_map<int, userinfo_map> userinfo_overrides;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
utils::hook::detour sv_getuserinfo_hook;
|
||||||
|
|
||||||
|
userinfo_map userinfo_to_map(std::string userinfo)
|
||||||
|
{
|
||||||
|
userinfo_map map{};
|
||||||
|
|
||||||
|
if (userinfo[0] == '\\')
|
||||||
|
{
|
||||||
|
userinfo = userinfo.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto args = utils::string::split(userinfo, '\\');
|
||||||
|
for (size_t i = 0; !args.empty() && i < (args.size() - 1); i += 2)
|
||||||
|
{
|
||||||
|
map[args[i]] = args[i + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string map_to_userinfo(const userinfo_map& map)
|
||||||
|
{
|
||||||
|
std::string buffer{};
|
||||||
|
|
||||||
|
for (const auto& value : map)
|
||||||
|
{
|
||||||
|
buffer.append("\\");
|
||||||
|
buffer.append(value.first);
|
||||||
|
buffer.append("\\");
|
||||||
|
buffer.append(value.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sv_getuserinfo_stub(int index, char* buffer, int bufferSize)
|
||||||
|
{
|
||||||
|
sv_getuserinfo_hook.invoke<void>(index, buffer, bufferSize);
|
||||||
|
auto map = userinfo_to_map(buffer);
|
||||||
|
|
||||||
|
if (userinfo_overrides.find(index) == userinfo_overrides.end())
|
||||||
|
{
|
||||||
|
userinfo_overrides[index] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& values : userinfo_overrides[index])
|
||||||
|
{
|
||||||
|
if (values.second.empty())
|
||||||
|
{
|
||||||
|
map.erase(values.first);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
map[values.first] = values.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto userinfo = map_to_userinfo(map);
|
||||||
|
strcpy_s(buffer, 1024, userinfo.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_client_overrides(unsigned int client)
|
||||||
|
{
|
||||||
|
userinfo_overrides[client].clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_overrides()
|
||||||
|
{
|
||||||
|
userinfo_overrides.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
class component final : public component_interface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto name = args[0].as<std::string>();
|
||||||
|
|
||||||
|
userinfo_overrides[ent.entnum]["name"] = name;
|
||||||
|
game::ClientUserinfoChanged(ent.entnum);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
|
gsc::method::add("resetname", [](const game::scr_entref_t ent, const gsc::function_args&) -> scripting::script_value
|
||||||
|
{
|
||||||
|
if (ent.classnum != 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("invalid entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
userinfo_overrides[ent.entnum].erase("name");
|
||||||
|
game::ClientUserinfoChanged(ent.entnum);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
|
gsc::method::add("setclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
||||||
|
{
|
||||||
|
if (ent.classnum != 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("invalid entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto name = args[0].as<std::string>();
|
||||||
|
|
||||||
|
userinfo_overrides[ent.entnum]["clantag"] = name;
|
||||||
|
userinfo_overrides[ent.entnum]["ec_TagText"] = name;
|
||||||
|
userinfo_overrides[ent.entnum]["ec_usingTag"] = "1";
|
||||||
|
game::ClientUserinfoChanged(ent.entnum);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
|
gsc::method::add("resetclantag", [](const game::scr_entref_t ent, const gsc::function_args&) -> scripting::script_value
|
||||||
|
{
|
||||||
|
if (ent.classnum != 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("invalid entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
userinfo_overrides[ent.entnum].erase("clantag");
|
||||||
|
userinfo_overrides[ent.entnum].erase("ec_TagText");
|
||||||
|
userinfo_overrides[ent.entnum].erase("ec_usingTag");
|
||||||
|
game::ClientUserinfoChanged(ent.entnum);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
|
gsc::method::add("removeclantag", [](const game::scr_entref_t ent, const gsc::function_args&) -> scripting::script_value
|
||||||
|
{
|
||||||
|
if (ent.classnum != 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("invalid entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
userinfo_overrides[ent.entnum]["clantag"] = "";
|
||||||
|
userinfo_overrides[ent.entnum]["ec_TagText"] = "";
|
||||||
|
userinfo_overrides[ent.entnum]["ec_usingTag"] = "0";
|
||||||
|
game::ClientUserinfoChanged(ent.entnum);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
REGISTER_COMPONENT(userinfo::component)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace userinfo
|
||||||
|
{
|
||||||
|
void clear_client_overrides(int client);
|
||||||
|
void clear_overrides();
|
||||||
|
}
|
||||||
+16
-4
@@ -1,12 +1,24 @@
|
|||||||
#include <stdinc.hpp>
|
#include <stdinc.hpp>
|
||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
#include "plugin.hpp"
|
||||||
|
|
||||||
|
PLUTONIUM_API plutonium::sdk::plugin* PLUTONIUM_CALLBACK on_initialize()
|
||||||
{
|
{
|
||||||
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
|
return plugin::get();
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL APIENTRY DllMain(HMODULE /*module*/, DWORD reason, LPVOID /*reserved*/)
|
||||||
|
{
|
||||||
|
if (reason == DLL_PROCESS_ATTACH)
|
||||||
{
|
{
|
||||||
component_loader::post_unpack();
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reason == DLL_PROCESS_DETACH)
|
||||||
|
{
|
||||||
|
component_loader::on_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -2,5 +2,11 @@
|
|||||||
|
|
||||||
namespace game
|
namespace game
|
||||||
{
|
{
|
||||||
|
void SV_GameDropClient(int clientNum, const char* reason)
|
||||||
|
{
|
||||||
|
if (clientNum >= 0 && clientNum < sv_maxclients->current.integer)
|
||||||
|
{
|
||||||
|
SV_DropClient(&svs_clients[clientNum], reason, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ namespace game
|
|||||||
return dedi_;
|
return dedi_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set(const size_t dedi)
|
||||||
|
{
|
||||||
|
this->dedi_ = reinterpret_cast<T*>(dedi);
|
||||||
|
}
|
||||||
|
|
||||||
operator T* () const
|
operator T* () const
|
||||||
{
|
{
|
||||||
return this->get();
|
return this->get();
|
||||||
@@ -29,6 +34,8 @@ namespace game
|
|||||||
private:
|
private:
|
||||||
T* dedi_;
|
T* dedi_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void SV_GameDropClient(int clientNum, const char* reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "symbols.hpp"
|
#include "symbols.hpp"
|
||||||
+144
-40
@@ -1,5 +1,6 @@
|
|||||||
#include <stdinc.hpp>
|
#include <stdinc.hpp>
|
||||||
#include "array.hpp"
|
#include "array.hpp"
|
||||||
|
#include "script_value.hpp"
|
||||||
#include "execution.hpp"
|
#include "execution.hpp"
|
||||||
|
|
||||||
namespace scripting
|
namespace scripting
|
||||||
@@ -40,9 +41,20 @@ namespace scripting
|
|||||||
this->value_ = value;
|
this->value_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
array::array(unsigned int id)
|
array::array(const unsigned int id)
|
||||||
: id_(id)
|
: id_(id)
|
||||||
{
|
{
|
||||||
|
this->add();
|
||||||
|
}
|
||||||
|
|
||||||
|
array::array(const array& other) : array(other.id_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
array::array(array&& other) noexcept
|
||||||
|
{
|
||||||
|
this->id_ = other.id_;
|
||||||
|
other.id_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
array::array()
|
array::array()
|
||||||
@@ -70,9 +82,54 @@ namespace scripting
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<array_key> array::get_keys() const
|
array::~array()
|
||||||
{
|
{
|
||||||
std::vector<array_key> result;
|
this->release();
|
||||||
|
}
|
||||||
|
|
||||||
|
array& array::operator=(const array& other)
|
||||||
|
{
|
||||||
|
if (&other != this)
|
||||||
|
{
|
||||||
|
this->release();
|
||||||
|
this->id_ = other.id_;
|
||||||
|
this->add();
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
array& array::operator=(array&& other) noexcept
|
||||||
|
{
|
||||||
|
if (&other != this)
|
||||||
|
{
|
||||||
|
this->release();
|
||||||
|
this->id_ = other.id_;
|
||||||
|
other.id_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void array::add() const
|
||||||
|
{
|
||||||
|
if (this->id_)
|
||||||
|
{
|
||||||
|
game::AddRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->id_)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void array::release() const
|
||||||
|
{
|
||||||
|
if (this->id_)
|
||||||
|
{
|
||||||
|
game::RemoveRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->id_)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<script_value> array::get_keys() const
|
||||||
|
{
|
||||||
|
std::vector<script_value> result;
|
||||||
|
|
||||||
const auto offset = 0xC800 * (this->id_ & 1);
|
const auto offset = 0xC800 * (this->id_ & 1);
|
||||||
auto current = game::scr_VarGlob->objectVariableChildren[this->id_].firstChild;
|
auto current = game::scr_VarGlob->objectVariableChildren[this->id_].firstChild;
|
||||||
@@ -90,16 +147,14 @@ namespace scripting
|
|||||||
const auto string_value = (unsigned int)((unsigned __int8)var.name_lo + (var.k.keys.name_hi << 8));
|
const auto string_value = (unsigned int)((unsigned __int8)var.name_lo + (var.k.keys.name_hi << 8));
|
||||||
const auto* str = game::SL_ConvertToString(string_value);
|
const auto* str = game::SL_ConvertToString(string_value);
|
||||||
|
|
||||||
array_key key;
|
script_value key;
|
||||||
if (string_value < 0x40000 && str)
|
if (string_value < 0x40000 && str)
|
||||||
{
|
{
|
||||||
key.is_string = true;
|
key = str;
|
||||||
key.key = str;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
key.is_integer = true;
|
key = (string_value - 0x800000) & 0xFFFFFF;
|
||||||
key.index = (string_value - 0x800000) & 0xFFFFFF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result.push_back(key);
|
result.push_back(key);
|
||||||
@@ -110,20 +165,59 @@ namespace scripting
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int array::size() const
|
unsigned int array::size() const
|
||||||
{
|
{
|
||||||
return game::Scr_GetSelf(this->id_);
|
return game::Scr_GetSelf(this->id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void array::push(script_value value) const
|
unsigned int array::push(script_value value) const
|
||||||
{
|
{
|
||||||
this->set(this->size(), value);
|
this->set(this->size(), value);
|
||||||
|
return this->size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void array::erase(const unsigned int index) const
|
||||||
|
{
|
||||||
|
const auto variable_id = game::FindVariable(this->id_, (index - 0x800000) & 0xFFFFFF);
|
||||||
|
if (variable_id)
|
||||||
|
{
|
||||||
|
game::RemoveVariableValue(this->id_, variable_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void array::erase(const std::string& key) const
|
||||||
|
{
|
||||||
|
const auto string_value = game::SL_GetString(key.data(), 0);
|
||||||
|
const auto variable_id = game::FindVariable(this->id_, string_value);
|
||||||
|
if (variable_id)
|
||||||
|
{
|
||||||
|
game::RemoveVariableValue(this->id_, variable_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
script_value array::pop() const
|
||||||
|
{
|
||||||
|
const auto value = this->get(this->size() - 1);
|
||||||
|
this->erase(this->size() - 1);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
script_value array::get(const script_value& key) const
|
||||||
|
{
|
||||||
|
if (key.is<int>())
|
||||||
|
{
|
||||||
|
return this->get(key.as<int>());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this->get(key.as<std::string>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
script_value array::get(const std::string& key) const
|
script_value array::get(const std::string& key) const
|
||||||
{
|
{
|
||||||
const auto string_value = game::SL_GetString(key.data(), 0);
|
const auto string_value = game::SL_GetString(key.data(), 0);
|
||||||
const auto variable_id = game::GetVariable(this->id_, string_value);
|
const auto variable_id = game::FindVariable(this->id_, string_value);
|
||||||
|
|
||||||
if (!variable_id)
|
if (!variable_id)
|
||||||
{
|
{
|
||||||
@@ -140,7 +234,7 @@ namespace scripting
|
|||||||
|
|
||||||
script_value array::get(const unsigned int index) const
|
script_value array::get(const unsigned int index) const
|
||||||
{
|
{
|
||||||
const auto variable_id = game::GetVariable(this->id_, (index - 0x800000) & 0xFFFFFF);
|
const auto variable_id = game::FindVariable(this->id_, (index - 0x800000) & 0xFFFFFF);
|
||||||
|
|
||||||
if (!variable_id)
|
if (!variable_id)
|
||||||
{
|
{
|
||||||
@@ -155,40 +249,21 @@ namespace scripting
|
|||||||
return variable;
|
return variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int array::get_entity_id() const
|
void array::set(const script_value& key, const script_value& value) const
|
||||||
{
|
{
|
||||||
return this->id_;
|
if (key.is<int>())
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int array::get_value_id(const std::string& key) const
|
|
||||||
{
|
|
||||||
const auto string_value = game::SL_GetString(key.data(), 0);
|
|
||||||
const auto variable_id = game::GetVariable(this->id_, string_value);
|
|
||||||
|
|
||||||
if (!variable_id)
|
|
||||||
{
|
{
|
||||||
return game::GetNewVariable(this->id_, string_value);
|
this->set(key.as<int>(), value);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return variable_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int array::get_value_id(const unsigned int index) const
|
|
||||||
{
|
|
||||||
const auto variable_id = game::GetVariable(this->id_, (index - 0x800000) & 0xFFFFFF);
|
|
||||||
if (!variable_id)
|
|
||||||
{
|
{
|
||||||
return game::GetNewArrayVariable(this->id_, index);
|
this->set(key.as<std::string>(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return variable_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void array::set(const std::string& key, const script_value& _value) const
|
void array::set(const std::string& key, const script_value& value_) const
|
||||||
{
|
{
|
||||||
const auto value = _value.get_raw();
|
const auto value = value_.get_raw();
|
||||||
|
|
||||||
const auto string_value = game::SL_GetString(key.data(), 0);
|
|
||||||
const auto variable_id = this->get_value_id(key);
|
const auto variable_id = this->get_value_id(key);
|
||||||
|
|
||||||
if (!variable_id)
|
if (!variable_id)
|
||||||
@@ -205,9 +280,9 @@ namespace scripting
|
|||||||
variable->u.u = value.u;
|
variable->u.u = value.u;
|
||||||
}
|
}
|
||||||
|
|
||||||
void array::set(const unsigned int index, const script_value& _value) const
|
void array::set(const unsigned int index, const script_value& value_) const
|
||||||
{
|
{
|
||||||
const auto value = _value.get_raw();
|
const auto value = value_.get_raw();
|
||||||
const auto variable_id = this->get_value_id(index);
|
const auto variable_id = this->get_value_id(index);
|
||||||
|
|
||||||
if (!variable_id)
|
if (!variable_id)
|
||||||
@@ -224,6 +299,35 @@ namespace scripting
|
|||||||
variable->u.u = value.u;
|
variable->u.u = value.u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int array::get_entity_id() const
|
||||||
|
{
|
||||||
|
return this->id_;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int array::get_value_id(const std::string& key) const
|
||||||
|
{
|
||||||
|
const auto string_value = game::SL_GetString(key.data(), 0);
|
||||||
|
const auto variable_id = game::FindVariable(this->id_, string_value);
|
||||||
|
|
||||||
|
if (!variable_id)
|
||||||
|
{
|
||||||
|
return game::GetNewVariable(this->id_, string_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return variable_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int array::get_value_id(const unsigned int index) const
|
||||||
|
{
|
||||||
|
const auto variable_id = game::FindVariable(this->id_, (index - 0x800000) & 0xFFFFFF);
|
||||||
|
if (!variable_id)
|
||||||
|
{
|
||||||
|
return game::GetNewArrayVariable(this->id_, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return variable_id;
|
||||||
|
}
|
||||||
|
|
||||||
entity array::get_raw() const
|
entity array::get_raw() const
|
||||||
{
|
{
|
||||||
return entity(this->id_);
|
return entity(this->id_);
|
||||||
|
|||||||
@@ -1,21 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "game/game.hpp"
|
||||||
#include "script_value.hpp"
|
#include "script_value.hpp"
|
||||||
|
|
||||||
namespace scripting
|
namespace scripting
|
||||||
{
|
{
|
||||||
struct array_key
|
|
||||||
{
|
|
||||||
bool is_string = false;
|
|
||||||
bool is_integer = false;
|
|
||||||
int index{};
|
|
||||||
std::string key{};
|
|
||||||
};
|
|
||||||
|
|
||||||
class array_value : public script_value
|
class array_value : public script_value
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
array_value(unsigned int parent_id, unsigned int id);
|
array_value(unsigned int, unsigned int);
|
||||||
void array_value::operator=(const script_value& value);
|
void operator=(const script_value&);
|
||||||
private:
|
private:
|
||||||
unsigned int id_;
|
unsigned int id_;
|
||||||
unsigned int parent_id_;
|
unsigned int parent_id_;
|
||||||
@@ -25,38 +18,70 @@ namespace scripting
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
array();
|
array();
|
||||||
array(unsigned int);
|
array(const unsigned int);
|
||||||
|
|
||||||
array(std::vector<script_value>);
|
array(std::vector<script_value>);
|
||||||
array(std::unordered_map<std::string, script_value>);
|
array(std::unordered_map<std::string, script_value>);
|
||||||
|
|
||||||
std::vector<array_key> get_keys() const;
|
array(const array& other);
|
||||||
|
array(array&& other) noexcept;
|
||||||
|
|
||||||
int size() const;
|
~array();
|
||||||
void push(script_value) const;
|
|
||||||
|
|
||||||
|
array& operator=(const array& other);
|
||||||
|
array& operator=(array&& other) noexcept;
|
||||||
|
|
||||||
|
std::vector<script_value> get_keys() const;
|
||||||
|
unsigned int size() const;
|
||||||
|
|
||||||
|
unsigned int push(script_value) const;
|
||||||
|
void erase(const unsigned int) const;
|
||||||
|
void erase(const std::string&) const;
|
||||||
|
script_value pop() const;
|
||||||
|
|
||||||
|
script_value get(const script_value&) const;
|
||||||
script_value get(const std::string&) const;
|
script_value get(const std::string&) const;
|
||||||
script_value get(const unsigned int) const;
|
script_value get(const unsigned int) const;
|
||||||
|
|
||||||
|
void set(const script_value&, const script_value&) const;
|
||||||
|
void set(const std::string&, const script_value&) const;
|
||||||
|
void set(const unsigned int, const script_value&) const;
|
||||||
|
|
||||||
unsigned int get_entity_id() const;
|
unsigned int get_entity_id() const;
|
||||||
|
|
||||||
unsigned int get_value_id(const std::string&) const;
|
unsigned int get_value_id(const std::string&) const;
|
||||||
unsigned int get_value_id(const unsigned int) const;
|
unsigned int get_value_id(const unsigned int) const;
|
||||||
|
|
||||||
void set(const std::string&, const script_value&) const;
|
|
||||||
void set(const unsigned int, const script_value&) const;
|
|
||||||
|
|
||||||
entity get_raw() const;
|
entity get_raw() const;
|
||||||
|
|
||||||
array_value array::operator[](const int index) const
|
array_value operator[](const int index) const
|
||||||
{
|
{
|
||||||
return {this->id_, this->get_value_id(index)};
|
return {this->id_, this->get_value_id(index)};
|
||||||
}
|
}
|
||||||
|
|
||||||
array_value array::operator[](const std::string& key) const
|
array_value operator[](const std::string& key) const
|
||||||
{
|
{
|
||||||
return {this->id_, this->get_value_id(key)};
|
return {this->id_, this->get_value_id(key)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename I = int, typename S = std::string>
|
||||||
|
array_value operator[](const script_value& key) const
|
||||||
|
{
|
||||||
|
if (key.is<I>())
|
||||||
|
{
|
||||||
|
return { this->id_, this->get_value_id(key.as<I>()) };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key.is<S>())
|
||||||
|
{
|
||||||
|
return { this->id_, this->get_value_id(key.as<S>()) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void add() const;
|
||||||
|
void release() const;
|
||||||
|
|
||||||
unsigned int id_;
|
unsigned int id_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,20 +96,4 @@ namespace scripting
|
|||||||
game::RemoveRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->entity_id_)});
|
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=(const entity& other);
|
||||||
entity& operator=(entity&& other) noexcept;
|
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;
|
unsigned int get_entity_id() const;
|
||||||
game::scr_entref_t get_entity_reference() const;
|
game::scr_entref_t get_entity_reference() const;
|
||||||
|
|
||||||
@@ -37,13 +30,4 @@ namespace scripting
|
|||||||
void add() const;
|
void add() const;
|
||||||
void release() 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 <stdinc.hpp>
|
||||||
#include "execution.hpp"
|
#include "execution.hpp"
|
||||||
#include "safe_execution.hpp"
|
|
||||||
#include "stack_isolation.hpp"
|
#include "stack_isolation.hpp"
|
||||||
#include "event.hpp"
|
#include "event.hpp"
|
||||||
|
|
||||||
@@ -32,16 +31,6 @@ namespace scripting
|
|||||||
return script_value(game::scr_VmPub->top[1 - game::scr_VmPub->outparamcount]);
|
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)
|
void scr_notify_id(int id, unsigned int stringValue, unsigned int paramcount)
|
||||||
{
|
{
|
||||||
if (game::scr_VmPub->outparamcount)
|
if (game::scr_VmPub->outparamcount)
|
||||||
@@ -95,47 +84,6 @@ namespace scripting
|
|||||||
scr_notify_id(entity.get_entity_id(), event_id, game::scr_VmPub->inparamcount);
|
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)
|
script_value exec_ent_thread(const entity& entity, const char* pos, const std::vector<script_value>& arguments)
|
||||||
{
|
{
|
||||||
const auto id = entity.get_entity_id();
|
const auto id = entity.get_entity_id();
|
||||||
@@ -155,121 +103,6 @@ namespace scripting
|
|||||||
return get_return_value();
|
return get_return_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
script_value call_script_function(const entity& entity, const std::string& filename,
|
|
||||||
const std::string& function, const std::vector<script_value>& arguments)
|
|
||||||
{
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto pos = functions.at(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int make_array()
|
unsigned int make_array()
|
||||||
{
|
{
|
||||||
unsigned int index = 0;
|
unsigned int index = 0;
|
||||||
@@ -280,4 +113,14 @@ namespace scripting
|
|||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int make_object()
|
||||||
|
{
|
||||||
|
unsigned int index = 0;
|
||||||
|
const auto variable = game::AllocVariable(&index);
|
||||||
|
variable->w.type = game::SCRIPT_STRUCT;
|
||||||
|
variable->u.f.prev = 0;
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "game/game.hpp"
|
#include "game/game.hpp"
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
|
#include "array.hpp"
|
||||||
|
#include "function.hpp"
|
||||||
#include "script_value.hpp"
|
#include "script_value.hpp"
|
||||||
|
|
||||||
namespace scripting
|
namespace scripting
|
||||||
{
|
{
|
||||||
void push_value(const script_value& value);
|
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>
|
template <typename T = script_value>
|
||||||
T call(const std::string& name, const std::vector<script_value>& arguments = {});
|
T call(const std::string& name, const std::vector<script_value>& arguments = {});
|
||||||
|
|
||||||
@@ -24,16 +22,9 @@ namespace scripting
|
|||||||
}
|
}
|
||||||
|
|
||||||
script_value exec_ent_thread(const entity& entity, const char* pos, const std::vector<script_value>& arguments);
|
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);
|
void notify(const entity& entity, const std::string& event, const std::vector<script_value>& arguments);
|
||||||
|
|
||||||
unsigned int make_array();
|
unsigned int make_array();
|
||||||
|
unsigned int make_object();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#include <stdinc.hpp>
|
||||||
|
#include "function.hpp"
|
||||||
|
#include "execution.hpp"
|
||||||
|
|
||||||
|
namespace scripting
|
||||||
|
{
|
||||||
|
function::function(const char* pos)
|
||||||
|
: pos_(pos)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
script_value function::get_raw() const
|
||||||
|
{
|
||||||
|
game::VariableValue value;
|
||||||
|
value.type = game::SCRIPT_FUNCTION;
|
||||||
|
value.u.codePosValue = this->pos_;
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* function::get_pos() const
|
||||||
|
{
|
||||||
|
return this->pos_;
|
||||||
|
}
|
||||||
|
|
||||||
|
script_value function::call(const entity& self, std::vector<script_value> arguments) const
|
||||||
|
{
|
||||||
|
return exec_ent_thread(self, this->pos_, arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "entity.hpp"
|
||||||
|
#include "script_value.hpp"
|
||||||
|
|
||||||
|
namespace scripting
|
||||||
|
{
|
||||||
|
class function
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
function(const char*);
|
||||||
|
|
||||||
|
script_value get_raw() const;
|
||||||
|
const char* get_pos() const;
|
||||||
|
|
||||||
|
script_value call(const entity& self, std::vector<script_value> arguments) const;
|
||||||
|
|
||||||
|
script_value operator()(const entity& self, std::vector<script_value> arguments) const
|
||||||
|
{
|
||||||
|
return this->call(self, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
script_value operator()(std::vector<script_value> arguments) const
|
||||||
|
{
|
||||||
|
return this->call(*game::levelEntityId, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
script_value operator()() const
|
||||||
|
{
|
||||||
|
return this->call(*game::levelEntityId, {});
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
const char* pos_;
|
||||||
|
};
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -5,89 +5,5 @@
|
|||||||
|
|
||||||
namespace scripting
|
namespace scripting
|
||||||
{
|
{
|
||||||
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)
|
|
||||||
{
|
|
||||||
const auto target = utils::string::to_lower(name);
|
|
||||||
|
|
||||||
const auto& primary_map = prefer_global
|
|
||||||
? get_functions()
|
|
||||||
: get_methods();
|
|
||||||
const auto& secondary_map = !prefer_global
|
|
||||||
? get_functions()
|
|
||||||
: get_methods();
|
|
||||||
|
|
||||||
auto function_entry = primary_map.find(target);
|
|
||||||
if (function_entry != primary_map.end())
|
|
||||||
{
|
|
||||||
return function_entry->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
function_entry = secondary_map.find(target);
|
|
||||||
if (function_entry != secondary_map.end())
|
|
||||||
{
|
|
||||||
return function_entry->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
script_function get_function_by_index(const unsigned index)
|
|
||||||
{
|
|
||||||
static const auto function_table = 0x1D6EB34;
|
|
||||||
static const auto method_table = 0x1D4F258;
|
|
||||||
|
|
||||||
if (index < 0x1C7)
|
|
||||||
{
|
|
||||||
return reinterpret_cast<script_function*>(function_table)[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
return reinterpret_cast<script_function*>(method_table)[index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int find_token_id(const std::string& name)
|
|
||||||
{
|
|
||||||
const auto result = token_map.find(name);
|
|
||||||
|
|
||||||
if (result != token_map.end())
|
|
||||||
{
|
|
||||||
return result->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,5 @@
|
|||||||
|
|
||||||
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);
|
||||||
|
|
||||||
script_function find_function(const std::string& name, const bool prefer_global);
|
|
||||||
int find_token_id(const std::string& name);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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]))
|
|
||||||
{
|
|
||||||
*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]))
|
|
||||||
{
|
|
||||||
*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]))
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "script_value.hpp"
|
#include "script_value.hpp"
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
#include "array.hpp"
|
#include "array.hpp"
|
||||||
|
#include "function.hpp"
|
||||||
|
|
||||||
namespace scripting
|
namespace scripting
|
||||||
{
|
{
|
||||||
@@ -14,6 +15,11 @@ namespace scripting
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
script_value::script_value(const value_wrap& value)
|
||||||
|
: value_(value.get_raw())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
script_value::script_value(void* value)
|
script_value::script_value(void* value)
|
||||||
{
|
{
|
||||||
game::VariableValue variable{};
|
game::VariableValue variable{};
|
||||||
@@ -102,6 +108,24 @@ namespace scripting
|
|||||||
this->value_ = variable;
|
this->value_ = variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
script_value::script_value(const array& value)
|
||||||
|
{
|
||||||
|
game::VariableValue variable{};
|
||||||
|
variable.type = game::SCRIPT_OBJECT;
|
||||||
|
variable.u.pointerValue = value.get_entity_id();
|
||||||
|
|
||||||
|
this->value_ = variable;
|
||||||
|
}
|
||||||
|
|
||||||
|
script_value::script_value(const function& value)
|
||||||
|
{
|
||||||
|
game::VariableValue variable{};
|
||||||
|
variable.type = game::SCRIPT_OBJECT;
|
||||||
|
variable.u.codePosValue = value.get_pos();
|
||||||
|
|
||||||
|
this->value_ = variable;
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* Integer
|
* Integer
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
@@ -261,11 +285,17 @@ namespace scripting
|
|||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
bool script_value::is<std::function<void()>>() const
|
bool script_value::is<function>() const
|
||||||
{
|
{
|
||||||
return this->get_raw().type == game::SCRIPT_FUNCTION;
|
return this->get_raw().type == game::SCRIPT_FUNCTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
function script_value::get() const
|
||||||
|
{
|
||||||
|
return function(this->get_raw().u.codePosValue);
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* Vector
|
* Vector
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
@@ -290,4 +320,10 @@ namespace scripting
|
|||||||
{
|
{
|
||||||
return this->value_.get();
|
return this->value_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value_wrap::value_wrap(const scripting::script_value& value, int argument_index)
|
||||||
|
: value_(value)
|
||||||
|
, argument_index_(argument_index)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,102 @@
|
|||||||
namespace scripting
|
namespace scripting
|
||||||
{
|
{
|
||||||
class entity;
|
class entity;
|
||||||
|
class array;
|
||||||
|
class function;
|
||||||
|
class value_wrap;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::unordered_map<int, std::string> typenames =
|
||||||
|
{
|
||||||
|
{0, "undefined"},
|
||||||
|
{1, "object"},
|
||||||
|
{2, "string"},
|
||||||
|
{3, "localized string"},
|
||||||
|
{4, "vector"},
|
||||||
|
{5, "float"},
|
||||||
|
{6, "integer"},
|
||||||
|
{7, "codepos"},
|
||||||
|
{8, "precodepos"},
|
||||||
|
{9, "function"},
|
||||||
|
{10, "builtin function"},
|
||||||
|
{11, "builtin method"},
|
||||||
|
{12, "stack"},
|
||||||
|
{13, "animation"},
|
||||||
|
{14, "pre animation"},
|
||||||
|
{15, "thread"},
|
||||||
|
{16, "thread"},
|
||||||
|
{17, "thread"},
|
||||||
|
{18, "thread"},
|
||||||
|
{19, "struct"},
|
||||||
|
{20, "removed entity"},
|
||||||
|
{21, "entity"},
|
||||||
|
{22, "array"},
|
||||||
|
{23, "removed thread"},
|
||||||
|
{24, "count"},
|
||||||
|
{25, "<free>"},
|
||||||
|
{26, "thread list"},
|
||||||
|
{27, "endon list"},
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string get_typename(const game::VariableValue& value)
|
||||||
|
{
|
||||||
|
if (value.type == game::SCRIPT_OBJECT)
|
||||||
|
{
|
||||||
|
const auto type = game::scr_VarGlob->objectVariableValue[value.u.uintValue].w.type;
|
||||||
|
return typenames[type];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return typenames[value.type];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename A = array>
|
||||||
|
std::string get_c_typename()
|
||||||
|
{
|
||||||
|
auto& info = typeid(T);
|
||||||
|
|
||||||
|
if (info == typeid(std::string))
|
||||||
|
{
|
||||||
|
return "string";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info == typeid(const char*))
|
||||||
|
{
|
||||||
|
return "string";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info == typeid(entity))
|
||||||
|
{
|
||||||
|
return "entity";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info == typeid(array))
|
||||||
|
{
|
||||||
|
return "array";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info == typeid(function))
|
||||||
|
{
|
||||||
|
return "function";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info == typeid(vector))
|
||||||
|
{
|
||||||
|
return "vector";
|
||||||
|
}
|
||||||
|
|
||||||
|
return info.name();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class script_value
|
class script_value
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
script_value() = default;
|
script_value() = default;
|
||||||
script_value(const game::VariableValue& value);
|
script_value(const game::VariableValue& value);
|
||||||
|
script_value(const value_wrap& value);
|
||||||
|
|
||||||
script_value(void* value);
|
script_value(void* value);
|
||||||
|
|
||||||
@@ -29,6 +119,10 @@ namespace scripting
|
|||||||
|
|
||||||
script_value(const vector& value);
|
script_value(const vector& value);
|
||||||
|
|
||||||
|
script_value(const array& value);
|
||||||
|
|
||||||
|
script_value(const function& value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool is() const;
|
bool is() const;
|
||||||
|
|
||||||
@@ -37,25 +131,23 @@ namespace scripting
|
|||||||
{
|
{
|
||||||
if (!this->is<T>())
|
if (!this->is<T>())
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid type");
|
const auto type = get_typename(this->get_raw());
|
||||||
|
const auto c_type = get_c_typename<T>();
|
||||||
|
throw std::runtime_error(std::string("has type '" + type + "' but should be '" + c_type + "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return get<T>();
|
return get<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename I = int>
|
||||||
T* as_ptr()
|
T* as_ptr()
|
||||||
{
|
{
|
||||||
if (!this->is<int>())
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid type");
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto value = this->get<int>();
|
const auto value = this->as<I>();
|
||||||
|
|
||||||
if (!value)
|
if (!value)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Null pointer");
|
throw std::runtime_error("is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
return reinterpret_cast<T*>(value);
|
return reinterpret_cast<T*>(value);
|
||||||
@@ -68,4 +160,50 @@ namespace scripting
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
T get() const;
|
T get() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class value_wrap
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
value_wrap(const scripting::script_value& value, int argument_index);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T as() const
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return this->value_.as<T>();
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(utils::string::va("parameter %d %s", this->argument_index_, e.what()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename I = int>
|
||||||
|
T* as_ptr()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return this->value_.as_ptr<T>();
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(utils::string::va("parameter %d %s", this->argument_index_, e.what()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T is() const
|
||||||
|
{
|
||||||
|
return this->value_.is<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
const game::VariableValue& get_raw() const
|
||||||
|
{
|
||||||
|
return this->value_.get_raw();
|
||||||
|
}
|
||||||
|
|
||||||
|
int argument_index_{};
|
||||||
|
scripting::script_value value_;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+121
-2
@@ -26,20 +26,35 @@ namespace game
|
|||||||
const char** argv[8];
|
const char** argv[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum netsrc_t
|
||||||
|
{
|
||||||
|
NS_CLIENT1 = 0x0,
|
||||||
|
NS_CLIENT2 = 0x1,
|
||||||
|
NS_CLIENT3 = 0x2,
|
||||||
|
NS_CLIENT4 = 0x3,
|
||||||
|
NS_MAXCLIENTS = 0x4,
|
||||||
|
NS_SERVER = 0x4,
|
||||||
|
NS_PACKET = 0x5,
|
||||||
|
NS_INVALID_NETSRC = 0x6
|
||||||
|
};
|
||||||
|
|
||||||
struct msg_t
|
struct msg_t
|
||||||
{
|
{
|
||||||
int overflowed;
|
int overflowed;
|
||||||
int readOnly;
|
int readOnly;
|
||||||
char* data;
|
unsigned char* data;
|
||||||
char* splitData;
|
unsigned char* splitData;
|
||||||
int maxsize;
|
int maxsize;
|
||||||
int cursize;
|
int cursize;
|
||||||
int splitSize;
|
int splitSize;
|
||||||
int readcount;
|
int readcount;
|
||||||
int bit;
|
int bit;
|
||||||
int lastEntityRef;
|
int lastEntityRef;
|
||||||
|
netsrc_t targetLocalNetID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(msg_t) == 0x2C);
|
||||||
|
|
||||||
struct XZoneInfo
|
struct XZoneInfo
|
||||||
{
|
{
|
||||||
const char* name;
|
const char* name;
|
||||||
@@ -303,8 +318,112 @@ namespace game
|
|||||||
dvar_t* hashNext;
|
dvar_t* hashNext;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct playerState_s
|
||||||
|
{
|
||||||
|
char __pad0[0x4EC];
|
||||||
|
unsigned int perks[0x2];
|
||||||
|
unsigned int perkSlots[0x9];
|
||||||
|
char __pad1[0x2DE8];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gclient_s
|
||||||
|
{
|
||||||
|
playerState_s ps;
|
||||||
|
char __pad0[0x2CC];
|
||||||
|
int flags;
|
||||||
|
};
|
||||||
|
|
||||||
struct gentity_s
|
struct gentity_s
|
||||||
{
|
{
|
||||||
int entnum;
|
int entnum;
|
||||||
|
char __pad0[0x154];
|
||||||
|
gclient_s* client;
|
||||||
|
char __pad1[0x28];
|
||||||
|
int flags;
|
||||||
|
char __pad2[0xEC];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum netadrtype_t
|
||||||
|
{
|
||||||
|
NA_BOT = 0x0,
|
||||||
|
NA_BAD = 0x1,
|
||||||
|
NA_LOOPBACK = 0x2,
|
||||||
|
NA_BROADCAST = 0x3,
|
||||||
|
NA_IP = 0x4
|
||||||
|
};
|
||||||
|
|
||||||
|
struct netadr_s
|
||||||
|
{
|
||||||
|
netadrtype_t type;
|
||||||
|
unsigned char ip[4];
|
||||||
|
unsigned __int16 port;
|
||||||
|
unsigned char ipx[10];
|
||||||
|
unsigned int addrHandleIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(netadr_s) == 24);
|
||||||
|
|
||||||
|
struct netchan_t
|
||||||
|
{
|
||||||
|
int outgoingSequence;
|
||||||
|
netsrc_t sock;
|
||||||
|
int dropped;
|
||||||
|
int incomingSequence;
|
||||||
|
netadr_s remoteAddress;
|
||||||
|
int qport;
|
||||||
|
int fragmentSequence;
|
||||||
|
int fragmentLength;
|
||||||
|
unsigned char* fragmentBuffer;
|
||||||
|
int fragmentBufferSize;
|
||||||
|
int unsentFragments;
|
||||||
|
int unsentFragmentStart;
|
||||||
|
int unsentLength;
|
||||||
|
unsigned char* unsentBuffer;
|
||||||
|
int unsentBufferSize;
|
||||||
|
unsigned char __pad0[0x5E0];
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(netchan_t) == 0x630);
|
||||||
|
|
||||||
|
enum clientState_t
|
||||||
|
{
|
||||||
|
CS_FREE = 0,
|
||||||
|
CS_ZOMBIE = 1,
|
||||||
|
CS_RECONNECTING = 2,
|
||||||
|
CS_CONNECTED = 3,
|
||||||
|
CS_CLIENTLOADING = 4,
|
||||||
|
CS_ACTIVE = 5
|
||||||
|
};
|
||||||
|
|
||||||
|
struct clientHeader_t
|
||||||
|
{
|
||||||
|
clientState_t state; // 0
|
||||||
|
int sendAsActive; // 4
|
||||||
|
int deltaMessage; // 8
|
||||||
|
int rateDealyed; // 12
|
||||||
|
int hasAckedBaselineData; // 16
|
||||||
|
int hugeSnapshotSent; // 20
|
||||||
|
netchan_t netchan; // 24
|
||||||
|
vec3_t predictedOrigin;
|
||||||
|
int predictedOriginServerTime;
|
||||||
|
int migrationState;
|
||||||
|
vec3_t predictedVehicleOrigin;
|
||||||
|
int predictedVehicleServerTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(clientHeader_t) == 0x66C);
|
||||||
|
|
||||||
|
struct client_s
|
||||||
|
{
|
||||||
|
clientHeader_t header;
|
||||||
|
const char* dropReason;
|
||||||
|
char userinfo[1024];
|
||||||
|
char __pad0[0x41242];
|
||||||
|
unsigned __int16 scriptId; // 269490
|
||||||
|
int bIsTestClient; // 269492
|
||||||
|
int serverId; // 269496
|
||||||
|
char __pad1[0x369DC];
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(client_s) == 0x78698);
|
||||||
}
|
}
|
||||||
+11
-11
@@ -16,6 +16,7 @@ namespace game
|
|||||||
|
|
||||||
WEAK symbol<void(unsigned int weapon, bool isAlternate, char* output, unsigned int maxStringLen)> BG_GetWeaponNameComplete{0x42F760};
|
WEAK symbol<void(unsigned int weapon, bool isAlternate, char* output, unsigned int maxStringLen)> BG_GetWeaponNameComplete{0x42F760};
|
||||||
|
|
||||||
|
WEAK symbol<void(int client)> ClientUserinfoChanged{0x4FADB0};
|
||||||
WEAK symbol<const char*(int index)> ConcatArgs{0x502150};
|
WEAK symbol<const char*(int index)> ConcatArgs{0x502150};
|
||||||
WEAK symbol<void(int localClientNum, const char* text)> Cbuf_AddText{0x545680};
|
WEAK symbol<void(int localClientNum, const char* text)> Cbuf_AddText{0x545680};
|
||||||
WEAK symbol<void(const char* cmdName, void(), cmd_function_t* allocedCmd)> Cmd_AddCommandInternal{0x545DF0};
|
WEAK symbol<void(const char* cmdName, void(), cmd_function_t* allocedCmd)> Cmd_AddCommandInternal{0x545DF0};
|
||||||
@@ -24,8 +25,6 @@ namespace game
|
|||||||
|
|
||||||
WEAK symbol<const dvar_t*(const char*)> Dvar_FindVar{0x5BDCC0};
|
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<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)> FindVariable{0x5651F0};
|
||||||
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> FindObject{0x565BD0};
|
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> FindObject{0x565BD0};
|
||||||
@@ -33,6 +32,7 @@ namespace game
|
|||||||
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> GetNewVariable{0x566390};
|
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> GetNewVariable{0x566390};
|
||||||
WEAK symbol<unsigned int(unsigned int parentId, unsigned int unsignedValue)> GetNewArrayVariable{0x5668C0};
|
WEAK symbol<unsigned int(unsigned int parentId, unsigned int unsignedValue)> GetNewArrayVariable{0x5668C0};
|
||||||
WEAK symbol<void(unsigned int parentId, unsigned int id, VariableValue* value)> SetNewVariableValue{0x5658D0};
|
WEAK symbol<void(unsigned int parentId, unsigned int id, VariableValue* value)> SetNewVariableValue{0x5658D0};
|
||||||
|
WEAK symbol<void(unsigned int parentId, unsigned int index)> RemoveVariableValue{0x566500};
|
||||||
|
|
||||||
WEAK symbol<const float* (const float* v)> Scr_AllocVector{0x565680};
|
WEAK symbol<const float* (const float* v)> Scr_AllocVector{0x565680};
|
||||||
WEAK symbol<void()> Scr_ClearOutParams{0x569010};
|
WEAK symbol<void()> Scr_ClearOutParams{0x569010};
|
||||||
@@ -47,18 +47,21 @@ namespace game
|
|||||||
WEAK symbol<unsigned int(unsigned int threadId)> Scr_GetSelf{0x5655E0};
|
WEAK symbol<unsigned int(unsigned int threadId)> Scr_GetSelf{0x5655E0};
|
||||||
WEAK symbol<void()> Scr_MakeArray{0x56ADE0};
|
WEAK symbol<void()> Scr_MakeArray{0x56ADE0};
|
||||||
WEAK symbol<void(unsigned int stringValue)> Scr_AddArrayStringIndexed{0x56AE70};
|
WEAK symbol<void(unsigned int stringValue)> Scr_AddArrayStringIndexed{0x56AE70};
|
||||||
|
WEAK symbol<void(unsigned int classnum, unsigned int name, unsigned int canonicalString, unsigned int offset)> Scr_AddClassField{0x567CD0};
|
||||||
|
|
||||||
WEAK symbol<unsigned int(const char* str, unsigned int user)> SL_GetString{0x5649E0};
|
WEAK symbol<unsigned int(const char* str, unsigned int user)> SL_GetString{0x5649E0};
|
||||||
|
WEAK symbol<unsigned int(const char* str)> SL_GetCanonicalString{0x5619A0};
|
||||||
WEAK symbol<const char*(unsigned int stringValue)> SL_ConvertToString{0x564270};
|
WEAK symbol<const char*(unsigned int stringValue)> SL_ConvertToString{0x564270};
|
||||||
|
|
||||||
WEAK symbol<void(int clientNum, int type, const char* command)> SV_GameSendServerCommand{0x573220};
|
WEAK symbol<void(int clientNum, int type, const char* command)> SV_GameSendServerCommand{0x573220};
|
||||||
WEAK symbol<void(int arg, char* buffer, int bufferLength)> SV_Cmd_ArgvBuffer{0x5459F0};
|
WEAK symbol<void(int arg, char* buffer, int bufferLength)> SV_Cmd_ArgvBuffer{0x5459F0};
|
||||||
|
WEAK symbol<void(client_s* drop, const char* reason, bool tellThem)> SV_DropClient{0x570980};
|
||||||
|
|
||||||
WEAK symbol<void(unsigned int notifyListOwnerId, unsigned int stringValue, VariableValue* top)> VM_Notify{0x569720};
|
WEAK symbol<void(unsigned int notifyListOwnerId, unsigned int stringValue, VariableValue* top)> VM_Notify{0x569720};
|
||||||
WEAK symbol<unsigned int(unsigned int localId, const char* pos, unsigned int paramcount)> VM_Execute{0x56DFE0};
|
WEAK symbol<unsigned int(unsigned int localId, const char* pos, unsigned int paramcount)> VM_Execute{0x56DFE0};
|
||||||
|
|
||||||
WEAK symbol<void* (jmp_buf* Buf, int Value)> longjmp{0x7363BC};
|
WEAK symbol<void* (jmp_buf* Buf, int Value)> longjmp{0x7363BC};
|
||||||
WEAK symbol<int(jmp_buf* Buf)> _setjmp{0x734CF8};
|
WEAK symbol<int(jmp_buf* Buf, int a2, int a3, int a4)> _setjmp{0x734CF8};
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
|
||||||
@@ -72,13 +75,10 @@ namespace game
|
|||||||
|
|
||||||
WEAK symbol<scr_classStruct_t*> g_classMap{0x8B4300};
|
WEAK symbol<scr_classStruct_t*> g_classMap{0x8B4300};
|
||||||
|
|
||||||
WEAK symbol<gentity_s> g_entities{0x0};
|
WEAK symbol<gentity_s> g_entities{0x1A66E28};
|
||||||
WEAK symbol<unsigned int> levelEntityId{0x208E1A4};
|
WEAK symbol<unsigned int> levelEntityId{0x208E1A4};
|
||||||
|
|
||||||
namespace plutonium
|
WEAK symbol<dvar_t> sv_maxclients{0x1BA0E4C};
|
||||||
{
|
WEAK symbol<int> svs_clientCount{0x4B5CF8C};
|
||||||
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> function_map_rev{0x20589F68};
|
WEAK symbol<client_s> svs_clients{0x4B5CF90};
|
||||||
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> method_map_rev{0x20589F88};
|
}
|
||||||
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> token_map_rev{0x20589FC8};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "../plugin.hpp"
|
||||||
|
|
||||||
class component_interface
|
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()
|
virtual bool is_supported()
|
||||||
|
|||||||
@@ -1,87 +1,48 @@
|
|||||||
#include <stdinc.hpp>
|
#include <stdinc.hpp>
|
||||||
#include "component_loader.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()
|
#define ON_CALLBACK(__name__) \
|
||||||
{
|
void component_loader::__name__() \
|
||||||
static auto handled = false;
|
{ \
|
||||||
if (handled) return true;
|
static auto handled = false; \
|
||||||
handled = true;
|
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
|
ON_CALLBACK(on_startup);
|
||||||
{
|
ON_CALLBACK(on_dvar_init);
|
||||||
for (const auto& component_ : get_components())
|
ON_CALLBACK(on_after_dvar_init);
|
||||||
{
|
ON_CALLBACK(on_shutdown);
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void component_loader::clean()
|
void component_loader::clean()
|
||||||
{
|
{
|
||||||
auto& components = get_components();
|
auto& components = get_components();
|
||||||
for (auto i = components.begin(); i != components.end();)
|
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);
|
i = components.erase(i);
|
||||||
}
|
}
|
||||||
else
|
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()
|
void component_loader::trigger_premature_shutdown()
|
||||||
{
|
{
|
||||||
throw premature_shutdown_trigger();
|
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*)>>;
|
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)
|
static component_vector_container components(new component_vector, [](component_vector* component_vector)
|
||||||
{
|
{
|
||||||
pre_destroy();
|
on_shutdown();
|
||||||
delete component_vector;
|
delete component_vector;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ public:
|
|||||||
static_assert(std::is_base_of<component_interface, T>::value, "component has invalid base class");
|
static_assert(std::is_base_of<component_interface, T>::value, "component has invalid base class");
|
||||||
|
|
||||||
public:
|
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;
|
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 void on_startup();
|
||||||
static bool post_load();
|
static void on_dvar_init();
|
||||||
static void post_unpack();
|
static void on_after_dvar_init();
|
||||||
static void pre_destroy();
|
static void on_shutdown();
|
||||||
static void clean();
|
static void clean();
|
||||||
|
|
||||||
static void* load_import(const std::string& library, const std::string& function);
|
static void* load_import(const std::string& library, const std::string& function);
|
||||||
@@ -51,11 +51,11 @@ public:
|
|||||||
static void trigger_premature_shutdown();
|
static void trigger_premature_shutdown();
|
||||||
|
|
||||||
private:
|
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) \
|
#define REGISTER_COMPONENT(name) \
|
||||||
namespace \
|
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();
|
||||||
|
}
|
||||||
+11
-2
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
#pragma warning(disable: 4018)
|
#pragma warning(disable: 4018)
|
||||||
#pragma warning(disable: 4146)
|
#pragma warning(disable: 4146)
|
||||||
|
#pragma warning(disable: 4129)
|
||||||
#pragma warning(disable: 4244)
|
#pragma warning(disable: 4244)
|
||||||
#pragma warning(disable: 4267)
|
#pragma warning(disable: 4267)
|
||||||
|
#pragma warning(disable: 4996)
|
||||||
#pragma warning(disable: 26812)
|
#pragma warning(disable: 26812)
|
||||||
|
|
||||||
#define DLL_EXPORT extern "C" __declspec(dllexport)
|
#define DLL_EXPORT extern "C" __declspec(dllexport)
|
||||||
@@ -25,17 +27,24 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <csetjmp>
|
#include <csetjmp>
|
||||||
|
#include <atlcomcli.h>
|
||||||
|
#include <Psapi.h>
|
||||||
|
|
||||||
|
#pragma comment(lib, "urlmon.lib")
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
|
#define __has_warning(...) 0
|
||||||
|
|
||||||
#include <gsl/gsl>
|
#include <gsl/gsl>
|
||||||
#include <MinHook.h>
|
#include <MinHook.h>
|
||||||
|
|
||||||
#include "utils/memory.hpp"
|
#include "utils/memory.hpp"
|
||||||
#include "utils/string.hpp"
|
#include "utils/string.hpp"
|
||||||
#include "utils/hook.hpp"
|
#include "utils/hook.hpp"
|
||||||
#include "utils/concurrent_list.hpp"
|
|
||||||
#include "utils/io.hpp"
|
#include "utils/io.hpp"
|
||||||
|
#include "utils/concurrency.hpp"
|
||||||
|
#include "utils/http.hpp"
|
||||||
|
|
||||||
#include "game/structs.hpp"
|
#include "game/structs.hpp"
|
||||||
#include "game/game.hpp"
|
#include "game/game.hpp"
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
namespace utils::concurrency
|
||||||
|
{
|
||||||
|
template <typename T, typename MutexType = std::mutex>
|
||||||
|
class container
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <typename R = void, typename F>
|
||||||
|
R access(F&& accessor) const
|
||||||
|
{
|
||||||
|
std::lock_guard<MutexType> _{mutex_};
|
||||||
|
return accessor(object_);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename R = void, typename F>
|
||||||
|
R access(F&& accessor)
|
||||||
|
{
|
||||||
|
std::lock_guard<MutexType> _{mutex_};
|
||||||
|
return accessor(object_);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename R = void, typename F>
|
||||||
|
R access_with_lock(F&& accessor) const
|
||||||
|
{
|
||||||
|
std::unique_lock<MutexType> lock{mutex_};
|
||||||
|
return accessor(object_, lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename R = void, typename F>
|
||||||
|
R access_with_lock(F&& accessor)
|
||||||
|
{
|
||||||
|
std::unique_lock<MutexType> lock{mutex_};
|
||||||
|
return accessor(object_, lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
T& get_raw() { return object_; }
|
||||||
|
const T& get_raw() const { return object_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable MutexType mutex_{};
|
||||||
|
T object_{};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -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_;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -177,4 +177,17 @@ namespace utils::hook
|
|||||||
|
|
||||||
delete[] bytes;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -113,4 +113,7 @@ namespace utils::hook
|
|||||||
{
|
{
|
||||||
return static_cast<T(*)(Args ...)>(func)(args...);
|
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);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#include <stdinc.hpp>
|
||||||
|
#include "http.hpp"
|
||||||
|
|
||||||
|
namespace utils::http
|
||||||
|
{
|
||||||
|
std::optional<std::string> get_data(const std::string& url)
|
||||||
|
{
|
||||||
|
CComPtr<IStream> stream;
|
||||||
|
|
||||||
|
if (FAILED(URLOpenBlockingStreamA(nullptr, url.data(), &stream, 0, nullptr)))
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
char buffer[0x1000];
|
||||||
|
std::string result;
|
||||||
|
|
||||||
|
HRESULT status{};
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
DWORD bytes_read = 0;
|
||||||
|
status = stream->Read(buffer, sizeof(buffer), &bytes_read);
|
||||||
|
|
||||||
|
if (bytes_read > 0)
|
||||||
|
{
|
||||||
|
result.append(buffer, bytes_read);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (SUCCEEDED(status) && status != S_FALSE);
|
||||||
|
|
||||||
|
if (FAILED(status))
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {result};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::future<std::optional<std::string>> get_data_async(const std::string& url)
|
||||||
|
{
|
||||||
|
return std::async(std::launch::async, [url]()
|
||||||
|
{
|
||||||
|
return get_data(url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
|
#include <future>
|
||||||
|
|
||||||
|
namespace utils::http
|
||||||
|
{
|
||||||
|
std::optional<std::string> get_data(const std::string& url);
|
||||||
|
std::future<std::optional<std::string>> get_data_async(const std::string& url);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user