71 Commits
Author SHA1 Message Date
alice befebc4b6e cleanup 2026-07-27 03:57:20 +02:00
alice 933192724a changes + cleanup 2026-07-27 03:32:32 +02:00
alice 64c1ab0120 update readme [skip ci] 2026-07-26 02:41:07 +02:00
alice ad466e020b update deps 2026-07-26 02:34:41 +02:00
alice 5b4b06cb03 Update build.yml 2026-07-26 02:33:28 +02:00
alice 04871f2a3d update readme [skip ci] 2026-07-26 02:26:05 +02:00
alice 0fedd81e1f httpget fix 2026-07-26 02:22:26 +02:00
alice a1d52b9472 Delete gsc-tool 2026-07-26 02:09:23 +02:00
alice 50438cef27 fixes 2026-07-26 02:06:25 +02:00
alice b2bd1e0835 Update build.yml 2025-12-03 05:49:19 +01:00
alice e2a5d96e10 update 2 2025-12-03 05:47:55 +01:00
alice 8d4fa65e3b update 2025-12-03 05:45:25 +01:00
alice 54226a0e56 Update gsc-tool 2025-12-03 04:26:17 +01:00
fedandGitHub 1061c08829 Merge pull request #92 from fedddddd/dependabot/submodules/deps/GSL-b39e7e4
Bump deps/GSL from `f1a494c` to `b39e7e4`
2024-03-07 21:40:03 +01:00
dependabot[bot]andGitHub c75cf561f7 Bump deps/GSL from f1a494c to b39e7e4
Bumps [deps/GSL](https://github.com/microsoft/GSL) from `f1a494c` to `b39e7e4`.
- [Release notes](https://github.com/microsoft/GSL/releases)
- [Commits](https://github.com/microsoft/GSL/compare/f1a494cfd2ce55fe88b5134eab985f5852667b8d...b39e7e4b0987859f5b19ff7686b149c916588658)

---
updated-dependencies:
- dependency-name: deps/GSL
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-02-27 14:30:40 +00:00
fedandGitHub 3ea6050498 Merge pull request #89 from fedddddd/dependabot/submodules/deps/zlib-5c42a23
Bump deps/zlib from `e342bb3` to `5c42a23`
2024-02-12 17:19:02 +01:00
dependabot[bot]andGitHub 1551d7f1fd Bump deps/zlib from e342bb3 to 5c42a23
Bumps [deps/zlib](https://github.com/madler/zlib) from `e342bb3` to `5c42a23`.
- [Release notes](https://github.com/madler/zlib/releases)
- [Commits](https://github.com/madler/zlib/compare/e342bb3daef3f6d89dd1d39a3059355db5a64c49...5c42a230b7b468dff011f444161c0145b5efae59)

---
updated-dependencies:
- dependency-name: deps/zlib
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-02-12 14:10:29 +00:00
fedandGitHub bf1d649bc1 Merge pull request #83 from fedddddd/dependabot/submodules/deps/GSL-f1a494c
Bump deps/GSL from `e64c97f` to `f1a494c`
2024-02-07 18:55:06 +01:00
fedandGitHub 71727a5197 Merge pull request #82 from fedddddd/dependabot/submodules/deps/json-0457de2
Bump deps/json from `3780b41` to `0457de2`
2024-02-07 18:54:58 +01:00
fedandGitHub 530cd10466 Merge pull request #85 from fedddddd/dependabot/submodules/deps/zlib-e342bb3
Bump deps/zlib from `643e17b` to `e342bb3`
2024-02-07 18:54:52 +01:00
fed 978e251df8 Fixes for update 2024-02-07 18:52:23 +01:00
dependabot[bot]andGitHub cb96052638 Bump deps/zlib from 643e17b to e342bb3
Bumps [deps/zlib](https://github.com/madler/zlib) from `643e17b` to `e342bb3`.
- [Release notes](https://github.com/madler/zlib/releases)
- [Commits](https://github.com/madler/zlib/compare/643e17b7498d12ab8d15565662880579692f769d...e342bb3daef3f6d89dd1d39a3059355db5a64c49)

---
updated-dependencies:
- dependency-name: deps/zlib
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-02-07 14:11:12 +00:00
dependabot[bot]andGitHub 9b217b20e3 Bump deps/GSL from e64c97f to f1a494c
Bumps [deps/GSL](https://github.com/microsoft/GSL) from `e64c97f` to `f1a494c`.
- [Release notes](https://github.com/microsoft/GSL/releases)
- [Commits](https://github.com/microsoft/GSL/compare/e64c97fc2cfc11992098bb38eda932de275e3f4d...f1a494cfd2ce55fe88b5134eab985f5852667b8d)

---
updated-dependencies:
- dependency-name: deps/GSL
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-01-30 15:02:59 +00:00
dependabot[bot]andGitHub 136a723187 Bump deps/json from 3780b41 to 0457de2
Bumps [deps/json](https://github.com/nlohmann/json) from `3780b41` to `0457de2`.
- [Release notes](https://github.com/nlohmann/json/releases)
- [Commits](https://github.com/nlohmann/json/compare/3780b41dd070436f3f55327b0a88f27a52e2dfa8...0457de21cffb298c22b629e538036bfeb96130b7)

---
updated-dependencies:
- dependency-name: deps/json
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-01-30 15:02:56 +00:00
fedandGitHub ad27dcb098 Merge pull request #73 from fedddddd/dependabot/submodules/deps/zlib-643e17b
Bump deps/zlib from `79a0e44` to `643e17b`
2024-01-29 19:33:48 +01:00
fedandGitHub 96acf0718e Merge pull request #79 from fedddddd/dependabot/submodules/deps/json-3780b41
Bump deps/json from `da92c0e` to `3780b41`
2024-01-29 19:33:42 +01:00
fedandGitHub 72f936e82a Merge pull request #74 from fedddddd/dependabot/submodules/deps/minhook-f5485b8
Bump deps/minhook from `0f25a24` to `f5485b8`
2024-01-29 19:33:35 +01:00
fedandGitHub 9a11ac82b3 Merge pull request #67 from fedddddd/dependabot/submodules/deps/GSL-e64c97f
Bump deps/GSL from `52212c2` to `e64c97f`
2024-01-29 19:33:30 +01:00
fed 8f36c271fd Fix for update 2024-01-29 19:33:03 +01:00
dependabot[bot]andGitHub e952b8a0f7 Bump deps/json from da92c0e to 3780b41
Bumps [deps/json](https://github.com/nlohmann/json) from `da92c0e` to `3780b41`.
- [Release notes](https://github.com/nlohmann/json/releases)
- [Commits](https://github.com/nlohmann/json/compare/da92c0e3e72d6a42106b5d829f5ff2d57fb16f77...3780b41dd070436f3f55327b0a88f27a52e2dfa8)

---
updated-dependencies:
- dependency-name: deps/json
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-12-07 14:58:09 +00:00
dependabot[bot]andGitHub f6d78fd815 Bump deps/minhook from 0f25a24 to f5485b8
Bumps [deps/minhook](https://github.com/TsudaKageyu/minhook) from `0f25a24` to `f5485b8`.
- [Release notes](https://github.com/TsudaKageyu/minhook/releases)
- [Commits](https://github.com/TsudaKageyu/minhook/compare/0f25a2449b3cf878bcbdbf91b693c38149ecf029...f5485b8454544c2f034c78f8f127c1d03dea3636)

---
updated-dependencies:
- dependency-name: deps/minhook
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-11-27 15:05:13 +00:00
dependabot[bot]andGitHub cadcca22f9 Bump deps/zlib from 79a0e44 to 643e17b
Bumps [deps/zlib](https://github.com/madler/zlib) from `79a0e44` to `643e17b`.
- [Release notes](https://github.com/madler/zlib/releases)
- [Commits](https://github.com/madler/zlib/compare/79a0e447a0dfa32979420cb21cfb96d684b2c9d5...643e17b7498d12ab8d15565662880579692f769d)

---
updated-dependencies:
- dependency-name: deps/zlib
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-11-15 14:14:08 +00:00
dependabot[bot]andGitHub c04a0a0d8c Bump deps/GSL from 52212c2 to e64c97f
Bumps [deps/GSL](https://github.com/microsoft/GSL) from `52212c2` to `e64c97f`.
- [Release notes](https://github.com/microsoft/GSL/releases)
- [Commits](https://github.com/microsoft/GSL/compare/52212c2d7600c816ec9b0438d3fbd2a95c190c2f...e64c97fc2cfc11992098bb38eda932de275e3f4d)

---
updated-dependencies:
- dependency-name: deps/GSL
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-10-19 14:37:17 +00:00
fedandGitHub 61706336ce Merge pull request #50 from fedddddd/dependabot/submodules/deps/zlib-79a0e44
Bump deps/zlib from `04f42ce` to `79a0e44`
2023-09-13 17:44:09 +02:00
fedandGitHub eb08109392 Merge pull request #57 from fedddddd/dependabot/submodules/deps/json-da92c0e
Bump deps/json from `5d27543` to `da92c0e`
2023-09-13 17:43:49 +02:00
fedandGitHub b23cb2014b Merge pull request #58 from fedddddd/dependabot/submodules/deps/GSL-52212c2
Bump deps/GSL from `4300304` to `52212c2`
2023-09-13 17:43:40 +02:00
fed 4d979bf659 Fix for update 2023-09-13 17:43:18 +02:00
dependabot[bot]andGitHub 206d06dc7d Bump deps/GSL from 4300304 to 52212c2
Bumps [deps/GSL](https://github.com/microsoft/GSL) from `4300304` to `52212c2`.
- [Release notes](https://github.com/microsoft/GSL/releases)
- [Commits](https://github.com/microsoft/GSL/compare/4300304ef24c247b3db0255763f46b9f95c3a83d...52212c2d7600c816ec9b0438d3fbd2a95c190c2f)

---
updated-dependencies:
- dependency-name: deps/GSL
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-09-12 14:12:10 +00:00
dependabot[bot]andGitHub 4d8af4bd45 Bump deps/json from 5d27543 to da92c0e
Bumps [deps/json](https://github.com/nlohmann/json) from `5d27543` to `da92c0e`.
- [Release notes](https://github.com/nlohmann/json/releases)
- [Commits](https://github.com/nlohmann/json/compare/5d2754306d67d1e654a1a34e1d2e74439a9d53b3...da92c0e3e72d6a42106b5d829f5ff2d57fb16f77)

---
updated-dependencies:
- dependency-name: deps/json
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-09-11 14:56:53 +00:00
dependabot[bot]andGitHub 46ab288488 Bump deps/zlib from 04f42ce to 79a0e44
Bumps [deps/zlib](https://github.com/madler/zlib) from `04f42ce` to `79a0e44`.
- [Release notes](https://github.com/madler/zlib/releases)
- [Commits](https://github.com/madler/zlib/compare/04f42ceca40f73e2978b50e93806c2a18c1281fc...79a0e447a0dfa32979420cb21cfb96d684b2c9d5)

---
updated-dependencies:
- dependency-name: deps/zlib
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-08-21 14:47:09 +00:00
fed dd8c1ff71e Update signatures.cpp 2023-08-10 01:55:12 +02:00
fedandGitHub ed1ac62153 Merge pull request #36 from fedddddd/dependabot/submodules/deps/json-5d27543
Bump deps/json from `c71ecde` to `5d27543`
2023-08-08 16:23:45 +02:00
fedandGitHub 7f7fd016cf Merge pull request #44 from fedddddd/dependabot/submodules/deps/GSL-4300304
Bump deps/GSL from `303d964` to `4300304`
2023-08-08 16:23:38 +02:00
fedandGitHub 6c093888b5 Merge pull request #45 from fedddddd/dependabot/submodules/deps/gsc-tool-d7365e4
Bump deps/gsc-tool from `f026487` to `d7365e4`
2023-08-08 16:23:31 +02:00
dependabot[bot]andGitHub 1440760aa5 Bump deps/gsc-tool from f026487 to d7365e4
Bumps [deps/gsc-tool](https://github.com/xensik/gsc-tool) from `f026487` to `d7365e4`.
- [Release notes](https://github.com/xensik/gsc-tool/releases)
- [Commits](https://github.com/xensik/gsc-tool/compare/f0264876dffeef28a3fc98f9612c53554df35724...d7365e471a05a7a6ac5b60b48f6a11a5947f10f1)

---
updated-dependencies:
- dependency-name: deps/gsc-tool
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-07-28 14:35:53 +00:00
dependabot[bot]andGitHub 105c11a8b2 Bump deps/GSL from 303d964 to 4300304
Bumps [deps/GSL](https://github.com/microsoft/GSL) from `303d964` to `4300304`.
- [Release notes](https://github.com/microsoft/GSL/releases)
- [Commits](https://github.com/microsoft/GSL/compare/303d964a241cb2f2a058fe0baa14013eb9afa116...4300304ef24c247b3db0255763f46b9f95c3a83d)

---
updated-dependencies:
- dependency-name: deps/GSL
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-07-27 14:35:38 +00:00
dependabot[bot]andGitHub 795f8ac162 Bump deps/json from c71ecde to 5d27543
Bumps [deps/json](https://github.com/nlohmann/json) from `c71ecde` to `5d27543`.
- [Release notes](https://github.com/nlohmann/json/releases)
- [Commits](https://github.com/nlohmann/json/compare/c71ecde505ebf236048a731c81ae8ecaf2b260a8...5d2754306d67d1e654a1a34e1d2e74439a9d53b3)

---
updated-dependencies:
- dependency-name: deps/json
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-06-14 15:06:14 +00:00
fedandGitHub 6dd4d2651a Merge pull request #34 from fedddddd/dependabot/submodules/deps/json-c71ecde
Bump deps/json from `a0c1318` to `c71ecde`
2023-06-13 04:33:01 +02:00
dependabot[bot]andGitHub b2f030f349 Bump deps/json from a0c1318 to c71ecde
Bumps [deps/json](https://github.com/nlohmann/json) from `a0c1318` to `c71ecde`.
- [Release notes](https://github.com/nlohmann/json/releases)
- [Commits](https://github.com/nlohmann/json/compare/a0c1318830519eac027a31edec1a99ce1ae5670e...c71ecde505ebf236048a731c81ae8ecaf2b260a8)

---
updated-dependencies:
- dependency-name: deps/json
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-06-12 14:14:45 +00:00
fedandGitHub 2690eeeece Merge pull request #28 from fedddddd/dependabot/submodules/deps/gsc-tool-f026487
Bump deps/gsc-tool from `a8a62c2` to `f026487`
2023-05-24 00:28:18 +02:00
fedandGitHub 098bd21008 Merge pull request #29 from fedddddd/dependabot/submodules/deps/json-a0c1318
Bump deps/json from `6af826d` to `a0c1318`
2023-05-24 00:28:11 +02:00
fedandGitHub 2f474e979f Merge pull request #30 from fedddddd/dependabot/submodules/deps/GSL-303d964
Bump deps/GSL from `afaaa71` to `303d964`
2023-05-24 00:28:05 +02:00
dependabot[bot]andGitHub 2ab4da0ad9 Bump deps/GSL from afaaa71 to 303d964
Bumps [deps/GSL](https://github.com/microsoft/GSL) from `afaaa71` to `303d964`.
- [Release notes](https://github.com/microsoft/GSL/releases)
- [Commits](https://github.com/microsoft/GSL/compare/afaaa71bcee45d9c90c21f8bd3ba2b12902242e9...303d964a241cb2f2a058fe0baa14013eb9afa116)

---
updated-dependencies:
- dependency-name: deps/GSL
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-05-23 15:04:36 +00:00
dependabot[bot]andGitHub 28c5594094 Bump deps/json from 6af826d to a0c1318
Bumps [deps/json](https://github.com/nlohmann/json) from `6af826d` to `a0c1318`.
- [Release notes](https://github.com/nlohmann/json/releases)
- [Commits](https://github.com/nlohmann/json/compare/6af826d0bdb55e4b69e3ad817576745335f243ca...a0c1318830519eac027a31edec1a99ce1ae5670e)

---
updated-dependencies:
- dependency-name: deps/json
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-05-22 15:10:24 +00:00
dependabot[bot]andGitHub 6525bbb8bf Bump deps/gsc-tool from a8a62c2 to f026487
Bumps [deps/gsc-tool](https://github.com/xensik/gsc-tool) from `a8a62c2` to `f026487`.
- [Release notes](https://github.com/xensik/gsc-tool/releases)
- [Commits](https://github.com/xensik/gsc-tool/compare/a8a62c2667ca1c2643798a6c88e39a9e5a30df86...f0264876dffeef28a3fc98f9612c53554df35724)

---
updated-dependencies:
- dependency-name: deps/gsc-tool
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-05-19 15:04:33 +00:00
fedandGitHub 1a9e3dfb15 Merge pull request #24 from fedddddd/dependabot/submodules/deps/minhook-0f25a24
Bump deps/minhook from `98b74f1` to `0f25a24`
2023-05-19 11:00:56 +02:00
fed c62f1995e7 Update generate.bat 2023-05-19 10:49:37 +02:00
dependabot[bot]andGitHub 883e38ae58 Bump deps/minhook from 98b74f1 to 0f25a24
Bumps [deps/minhook](https://github.com/TsudaKageyu/minhook) from `98b74f1` to `0f25a24`.
- [Release notes](https://github.com/TsudaKageyu/minhook/releases)
- [Commits](https://github.com/TsudaKageyu/minhook/compare/98b74f1fc12d00313d91f10450e5b3e0036175e3...0f25a2449b3cf878bcbdbf91b693c38149ecf029)

---
updated-dependencies:
- dependency-name: deps/minhook
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-05-15 15:08:38 +00:00
dependabot[bot]andGitHub 1b2d4dbc46 Merge pull request #20 from fedddddd/dependabot/submodules/deps/json-6af826d 2023-05-13 18:05:49 +00:00
dependabot[bot]andGitHub 7dfb35233e Merge pull request #22 from fedddddd/dependabot/submodules/deps/minhook-98b74f1 2023-05-13 18:04:33 +00:00
dependabot[bot]andGitHub d842022056 Merge pull request #21 from fedddddd/dependabot/submodules/deps/GSL-afaaa71 2023-05-13 18:03:36 +00:00
dependabot[bot]andGitHub 0a8ebc3058 Bump deps/json from e4643d1 to 6af826d
Bumps [deps/json](https://github.com/nlohmann/json) from `e4643d1` to `6af826d`.
- [Release notes](https://github.com/nlohmann/json/releases)
- [Commits](https://github.com/nlohmann/json/compare/e4643d1f1b03fc7a1d7b65f17e012ca93680cad8...6af826d0bdb55e4b69e3ad817576745335f243ca)

---
updated-dependencies:
- dependency-name: deps/json
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-05-13 17:58:53 +00:00
dependabot[bot]andGitHub 8ccae5ddec Bump deps/GSL from c31a9ad to afaaa71
Bumps [deps/GSL](https://github.com/microsoft/GSL) from `c31a9ad` to `afaaa71`.
- [Release notes](https://github.com/microsoft/GSL/releases)
- [Commits](https://github.com/microsoft/GSL/compare/c31a9ad5e8e99da8567237a7ba51a7d8f419e5bf...afaaa71bcee45d9c90c21f8bd3ba2b12902242e9)

---
updated-dependencies:
- dependency-name: deps/GSL
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-05-13 17:58:43 +00:00
dependabot[bot]andGitHub cfb143f0fd Bump deps/minhook from 423d1e4 to 98b74f1
Bumps [deps/minhook](https://github.com/TsudaKageyu/minhook) from `423d1e4` to `98b74f1`.
- [Release notes](https://github.com/TsudaKageyu/minhook/releases)
- [Commits](https://github.com/TsudaKageyu/minhook/compare/423d1e45af2ed2719a5c31e990e935ef301ed9c3...98b74f1fc12d00313d91f10450e5b3e0036175e3)

---
updated-dependencies:
- dependency-name: deps/minhook
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
2023-05-13 17:58:38 +00:00
fed 0281b5bef6 Update premake5 2023-05-13 19:53:55 +02:00
fed 70a91b271d Add workflows 2023-05-13 19:51:36 +02:00
fed a7576ea765 Fix for pluto update 2023-05-13 19:50:00 +02:00
fed 3a492f51d9 Update functions.cpp 2023-02-27 01:24:02 +01:00
fed d4ba37cde5 Remove this 2023-02-27 01:20:58 +01:00
fed 2ded4c6a2a Small fix 2023-02-27 01:20:08 +01:00
fed 24b3a9369e Fixes for pluto update 2023-02-27 01:18:50 +01:00
55 changed files with 726 additions and 1538 deletions
+7
View File
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: gitsubmodule
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
+80
View File
@@ -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 }}
+9
View File
@@ -8,3 +8,12 @@
path = deps/json path = deps/json
url = https://github.com/nlohmann/json.git url = https://github.com/nlohmann/json.git
branch = develop 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
+18 -38
View File
@@ -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
@@ -44,9 +35,6 @@ This plugin adds some useful functions/methods to IW5's GSC VM
} }
``` ```
# Player # Player
* `say(message)`: Prints a message to all players' chat.
* `self tell(message)`: Prints a message to the player's chat.
* `self setName(name)`: Sets a player's name. * `self setName(name)`: Sets a player's name.
* `self resetName(name)`: Resets a player's name to its original. * `self resetName(name)`: Resets a player's name to its original.
* `self setClantag(name)`: Sets a player's clantag. * `self setClantag(name)`: Sets a player's clantag.
@@ -54,28 +42,7 @@ This plugin adds some useful functions/methods to IW5's GSC VM
* `self removeClantag(name)`: Removes a player's clantag. * `self removeClantag(name)`: Removes a player's clantag.
# IO # IO
The basepath for all IO functions is `Plutonium/storage/iw5` The basepath for all IO functions is `Plutonium/storage/iw5`.
* `fopen(path, mode)`: Opens a file of given name with given mode, returns a file stream.
* `fwrite(stream, text)`: Writes a string to a stream.
* `fread(stream)`: Reads entire file.
* `fclose(stream)`: Closes a file stream.
* `fremove(path)`: Deletes a file.
```c
init()
{
basePath = getDvar("fs_basegame") + "/";
file = fopen(basePath + "test.txt", "w");
fwrite(file, "test");
fclose(file);
file = fopen(basePath + "test.txt", "r");
print(fread(file));
fclose(file);
}
```
* `fileExists(path)`: Returns true if the file exists. * `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. * `writeFile(path, data[, append])`: Creates a file if it doesn't exist and writes/appends text to it.
* `readFile(path)`: Reads a file. * `readFile(path)`: Reads a file.
@@ -86,6 +53,19 @@ The basepath for all IO functions is `Plutonium/storage/iw5`
* `listFiles(path)`: Returns the list of files in the directory as an array. * `listFiles(path)`: Returns the list of files in the directory as an array.
* `copyFolder(source, target)`: Copies a folder. * `copyFolder(source, target)`: Copies a folder.
# HTTP
* `httpGet(url)`: creates an HTTP request.
```c
init()
{
req = httpget("http://example.com");
req waittill("done", data);
print(data);
}
```
# JSON # JSON
* `jsonSerialize(variable[, indent])`: Converts GSC variables (such as arrays) into JSON: * `jsonSerialize(variable[, indent])`: Converts GSC variables (such as arrays) into JSON:
Vendored
+1 -1
Submodule deps/GSL updated: c31a9ad5e8...b39e7e4b09
Vendored
+1 -1
Submodule deps/json updated: e4643d1f1b...d0d29039da
+1 -1
Vendored Submodule
+1
Submodule deps/plutonium-sdk added at 17e9a0a4d5
+18
View File
@@ -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)
+1 -1
View File
@@ -1,3 +1,3 @@
@echo off @echo off
call git submodule update --init --recursive call git submodule update --init --recursive
tools\windows\premake5.exe vs2022 tools\premake5.exe vs2022
+10 -7
View File
@@ -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,7 +48,11 @@ 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));
} }
@@ -70,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()
@@ -95,7 +98,7 @@ 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
{ {
} }
}; };
+1 -1
View File
@@ -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();
} }
+126 -264
View File
@@ -6,7 +6,6 @@
#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/array.hpp" #include "game/scripting/array.hpp"
#include "game/scripting/function.hpp" #include "game/scripting/function.hpp"
@@ -14,54 +13,8 @@
namespace gsc namespace gsc
{ {
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()
{
std::vector<scripting::script_value> args;
for (auto i = 0; i < game::scr_VmPub->outparamcount; i++)
{
const auto value = game::scr_VmPub->top[-i];
args.push_back(value);
}
return args;
}
void return_value(const scripting::script_value& value) void return_value(const scripting::script_value& value)
{ {
if (game::scr_VmPub->outparamcount) if (game::scr_VmPub->outparamcount)
@@ -72,245 +25,182 @@ namespace gsc
scripting::push_value(value); scripting::push_value(value);
} }
auto function_map_start = 0x200; auto field_offset_start = 0xA000u;
auto method_map_start = 0x8400;
auto token_map_start = 0x8000;
auto field_offset_start = 0xA000;
struct entity_field std::unordered_map<unsigned int, entity_field_t> custom_fields[class_id_t::class_count];
{
std::string name;
std::function<scripting::script_value(unsigned int entnum)> getter;
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(unsigned int id)
{
if (id < 0x200)
{
return reinterpret_cast<builtin_function*>(game::plutonium::function_table.get())[id]();
}
try
{
const auto result = functions[id](get_arguments());
const auto type = result.get_raw().type;
if (type)
{
return_value(result);
}
}
catch (const std::exception& e)
{
printf("************** Script execution error **************\n");
printf("Error executing function %s:\n", function_name(id).data());
printf(" %s\n", e.what());
printf("****************************************************\n");
}
}
void call_method(game::scr_entref_t ent, unsigned int id)
{
if (id < 0x8400)
{
return reinterpret_cast<builtin_method*>(game::plutonium::method_table.get())[id - 0x8000](ent);
}
try
{
const auto result = methods[id](ent, get_arguments());
const auto type = result.get_raw().type;
if (type)
{
return_value(result);
}
}
catch (const std::exception& e)
{
printf("************** Script execution error **************\n");
printf("Error executing method %s:\n", method_name(id).data());
printf(" %s\n", e.what());
printf("****************************************************\n");
}
}
__declspec(naked) void call_builtin_stub()
{
__asm
{
push eax
mov eax, 0x20B4A5C
mov [eax], esi
mov eax, 0x20B4A90
mov [eax], edx
pop eax
pushad
push eax
call call_function
pop eax
popad
push 0x56C900
retn
}
}
__declspec(naked) void call_builtin_method_stub()
{
__asm
{
pushad
push ecx
push ebx
call call_method
pop ebx
pop ecx
popad
push ebx
add esp, 0xC
push 0x56CBE9
retn
}
}
utils::hook::detour scr_get_object_field_hook; utils::hook::detour scr_get_object_field_hook;
utils::hook::detour scr_set_object_field_hook;
utils::hook::detour scr_post_load_scripts_hook;
const char* get_script_loc()
{
return "unknown location";
}
void print_error(const char* fmt, ...)
{
static char buffer[0x1000];
va_list ap;
va_start(ap, fmt);
_vsnprintf_s(buffer, sizeof(buffer), sizeof(buffer), fmt, ap);
va_end(ap);
printf("\n"
"******* script runtime error *******\n"
"%s\n"
"\tat %s\n"
"************************************",
buffer, get_script_loc());
}
const gsc::entity_field_t* find_field(unsigned int classnum, unsigned int offset)
{
const auto& class_map = custom_fields[classnum];
const auto field_iter = class_map.find(offset);
if (field_iter == class_map.end())
{
return nullptr;
}
return &field_iter->second;
}
void scr_get_object_field_stub(unsigned int classnum, int entnum, unsigned int offset) void scr_get_object_field_stub(unsigned int classnum, int entnum, unsigned int offset)
{ {
if (custom_fields[classnum].find(offset) == custom_fields[classnum].end()) const auto field = find_field(classnum, offset);
if (field == nullptr)
{ {
return scr_get_object_field_hook.invoke<void>(classnum, entnum, offset); return scr_get_object_field_hook.invoke<void>(classnum, entnum, offset);
} }
const auto& field = custom_fields[classnum][offset];
try try
{ {
const auto result = field.getter(entnum); const auto result = field->getter(entnum);
return_value(result); return_value(result);
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
printf("************** Script execution error **************\n"); print_error("while getting builtin field \"%s\"\n%s", field->name.data(), e.what());
printf("Error getting field %s:\n", field.name.data());
printf(" %s\n", e.what());
printf("****************************************************\n");
} }
} }
utils::hook::detour scr_set_object_field_hook;
void scr_set_object_field_stub(unsigned int classnum, int entnum, unsigned int offset) void scr_set_object_field_stub(unsigned int classnum, int entnum, unsigned int offset)
{ {
if (custom_fields[classnum].find(offset) == custom_fields[classnum].end()) const auto field = find_field(classnum, offset);
if (field == nullptr)
{ {
return scr_set_object_field_hook.invoke<void>(classnum, entnum, offset); return scr_set_object_field_hook.invoke<void>(classnum, entnum, offset);
} }
const auto args = get_arguments(); function_args args;
const auto& field = custom_fields[classnum][offset];
try try
{ {
field.setter(entnum, args[0]); field->setter(entnum, args[0]);
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
printf("************** Script execution error **************\n"); print_error("while setting builtin field \"%s\"\n%s", field->name.data(), e.what());
printf("Error setting field %s:\n", field.name.data());
printf(" %s\n", e.what());
printf("****************************************************\n");
} }
} }
utils::hook::detour scr_post_load_scripts_hook;
void scr_post_load_scripts_stub() void scr_post_load_scripts_stub()
{ {
for (const auto& callback : post_load_callbacks) for (auto i = 0; i < class_id_t::class_count; i++)
{ {
callback(); const auto& class_map = custom_fields[i];
for (const auto& [offset, field] : class_map)
{
const auto str_id = game::SL_GetString(field.name.data(), 0);
const auto canon_str = game::SL_GetCanonicalString(field.name.data());
game::Scr_AddClassField(i, str_id, canon_str, offset);
}
} }
return scr_post_load_scripts_hook.invoke<void>(); return scr_post_load_scripts_hook.invoke<void>();
} }
} }
namespace function void call_function(const script_function& function, const std::string& name)
{ {
void add(const std::string& name, const script_function& func) try
{ {
const auto index = function_map_start++; function_args args;
const auto result = function.operator()(args);
const auto type = result.get_raw().type;
functions[index] = func; if (type)
(*game::plutonium::function_map_rev)[name] = index; {
return_value(result);
}
}
catch (const std::exception& e)
{
print_error("in call to builtin function \"%s\"\n%s", name.data(), e.what());
} }
} }
namespace method void call_method(const script_method& method, const std::string& name, game::scr_entref_t ent)
{ {
void add(const std::string& name, const script_method& func) try
{ {
const auto index = method_map_start++; function_args args;
const auto result = method.operator()(ent, args);
const auto type = result.get_raw().type;
methods[index] = func; if (type)
(*game::plutonium::method_map_rev)[name] = index; {
return_value(result);
}
}
catch (const std::exception& e)
{
print_error("in call to builtin method \"%s\"\n%s", name.data(), e.what());
} }
} }
namespace field namespace field
{ {
void add(const classid classnum, const std::string& name, void add(const class_id_t classnum, const std::string& name, const field_getter_t getter, const field_setter_t& setter)
const std::function<scripting::script_value(unsigned int entnum)>& getter,
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter)
{ {
uint16_t token_id{};
auto& token_map = *game::plutonium::token_map_rev;
if (token_map.find(name) != token_map.end())
{
token_id = token_map.at(name);
}
else
{
token_id = token_map_start++;
token_map.insert(std::make_pair(name, token_id));
}
const auto offset = field_offset_start++; const auto offset = field_offset_start++;
custom_fields[classnum][offset] = {name, getter, setter}; auto& class_map = custom_fields[classnum];
post_load_callbacks.push_back([classnum, name, token_id, offset]() entity_field_t field{};
{ field.name = name;
const auto name_str = game::SL_GetString(name.data(), 0); field.getter = getter;
game::Scr_AddClassField(classnum, name_str, token_id, offset); field.setter = setter;
}); class_map.insert(std::make_pair(offset, field));
} }
} }
function_args::function_args(std::vector<scripting::script_value> values) function_args::function_args()
{
for (auto i = 0u; i < game::scr_VmPub->outparamcount; i++)
{
const auto value = game::scr_VmPub->top[-i];
this->values_.emplace_back(value);
}
}
function_args::function_args(const std::vector<scripting::script_value>& values)
: values_(values) : values_(values)
{ {
} }
unsigned int function_args::size() const std::uint32_t function_args::size() const
{ {
return this->values_.size(); return this->values_.size();
} }
std::vector<scripting::script_value> function_args::get_raw() const const std::vector<scripting::script_value>& function_args::get_raw() const
{ {
return this->values_; return this->values_;
} }
scripting::value_wrap function_args::get(const int index) const scripting::value_wrap function_args::get(const std::uint32_t index) const
{ {
if (index >= this->values_.size()) if (index >= this->values_.size())
{ {
@@ -323,13 +213,13 @@ namespace gsc
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_get_object_field_hook.create(0x52BDB0, scr_get_object_field_stub); 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_set_object_field_hook.create(0x52BCC0, scr_set_object_field_stub);
scr_post_load_scripts_hook.create(0x628B50, scr_post_load_scripts_stub); scr_post_load_scripts_hook.create(0x628B50, scr_post_load_scripts_stub);
field::add(classid::entity, "entityflags", field::add(class_id_t::class_entity, "entityflags",
[](unsigned int entnum) -> scripting::script_value [](unsigned int entnum) -> scripting::script_value
{ {
const auto entity = &game::g_entities[entnum]; const auto entity = &game::g_entities[entnum];
@@ -342,7 +232,7 @@ namespace gsc
} }
); );
field::add(classid::entity, "clientflags", field::add(class_id_t::class_entity, "clientflags",
[](unsigned int entnum) -> scripting::script_value [](unsigned int entnum) -> scripting::script_value
{ {
const auto entity = &game::g_entities[entnum]; const auto entity = &game::g_entities[entnum];
@@ -355,13 +245,15 @@ namespace gsc
} }
); );
function::add("executecommand", [](const function_args& args) -> scripting::script_value 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("addcommand", [](const function_args& args) -> scripting::script_value function::add("addcommand", [](const 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].as<scripting::function>(); const auto function = args[1].as<scripting::function>();
@@ -379,15 +271,8 @@ namespace gsc
return {}; return {};
}); });
function::add("say", [](const function_args& args) -> scripting::script_value function::add("dropallbots", [](const function_args&)
{ -> scripting::script_value
const auto message = args[0].as<std::string>();
game::SV_GameSendServerCommand(-1, 0, utils::string::va("%c \"%s\"", 84, message.data()));
return {};
});
function::add("dropallbots", [](const function_args&) -> scripting::script_value
{ {
for (auto i = 0; i < *game::svs_clientCount; i++) for (auto i = 0; i < *game::svs_clientCount; i++)
{ {
@@ -401,88 +286,65 @@ namespace gsc
return {}; return {};
}); });
method::add("tell", [](const game::scr_entref_t ent, const 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 entity"); throw std::runtime_error("invalid entity");
} }
const auto client = ent.entnum; const auto client = ent.entnum;
if (game::g_entities[client].client == nullptr) if (game::g_entities[client].client == nullptr)
{ {
throw std::runtime_error("Not a player entity"); throw std::runtime_error("not a player entity");
}
const auto message = args[0].as<std::string>();
game::SV_GameSendServerCommand(client, 0, utils::string::va("%c \"%s\"", 84, message.data()));
return {};
});
method::add("specialtymarathon", [](const game::scr_entref_t ent, const function_args& args) -> scripting::script_value
{
if (ent.classnum != 0)
{
throw std::runtime_error("Invalid entity");
}
const auto client = ent.entnum;
if (game::g_entities[client].client == nullptr)
{
throw std::runtime_error("Not a player entity");
} }
const auto toggle = args[0].as<int>(); const auto toggle = args[0].as<int>();
auto flags = game::g_entities[client].client->ps.perks[0]; auto flags = game::g_entities[client].client->ps.perks[0];
game::g_entities[client].client->ps.perks[0] = toggle game::g_entities[client].client->ps.perks[0] = toggle
? flags | 0x4000u : flags & ~0x4000u; ? flags | 0x4000u
: flags & ~0x4000u;
return {}; return {};
}); });
method::add("isbot", [](const game::scr_entref_t ent, const function_args&) -> scripting::script_value method::add("isbot", [](const game::scr_entref_t ent, const function_args&)
-> scripting::script_value
{ {
if (ent.classnum != 0) if (ent.classnum != 0)
{ {
throw std::runtime_error("Invalid entity"); throw std::runtime_error("invalid entity");
} }
const auto client = ent.entnum; const auto client = ent.entnum;
if (game::g_entities[client].client == nullptr) if (game::g_entities[client].client == nullptr)
{ {
throw std::runtime_error("Not a player entity"); throw std::runtime_error("not a player entity");
} }
return game::svs_clients[client].bIsTestClient; return game::svs_clients[client].bIsTestClient;
}); });
method::add("arecontrolsfrozen", [](const game::scr_entref_t ent, const function_args&) -> scripting::script_value method::add("arecontrolsfrozen", [](const game::scr_entref_t ent, const function_args&)
-> scripting::script_value
{ {
if (ent.classnum != 0) if (ent.classnum != 0)
{ {
throw std::runtime_error("Invalid entity"); throw std::runtime_error("invalid entity");
} }
const auto client = ent.entnum; const auto client = ent.entnum;
if (game::g_entities[client].client == nullptr) if (game::g_entities[client].client == nullptr)
{ {
throw std::runtime_error("Not a player entity"); throw std::runtime_error("not a player entity");
} }
return {(game::g_entities[client].client->flags & 4) != 0}; return (game::g_entities[client].client->flags & 4) != 0;
});
// let other plugins read the pointers
post_load_callbacks.push_back([]()
{
utils::hook::jump(0x56C8EB, call_builtin_stub);
utils::hook::jump(0x56CBDC, call_builtin_method_stub);
}); });
} }
}; };
+63 -17
View File
@@ -4,25 +4,36 @@
namespace gsc namespace gsc
{ {
enum classid enum class_id_t
{ {
entity, class_entity,
hudelem, class_hudelem,
pathnode, class_pathnode,
node, class_node,
count class_count
};
using field_getter_t = std::function<scripting::script_value(unsigned int entnum)>;
using field_setter_t = std::function<void(unsigned int entnum, const scripting::script_value&)>;
struct entity_field_t
{
std::string name;
field_getter_t getter;
field_setter_t setter;
}; };
class function_args class function_args
{ {
public: public:
function_args(std::vector<scripting::script_value>); function_args();
function_args(const std::vector<scripting::script_value>&);
unsigned int size() const; std::uint32_t size() const;
std::vector<scripting::script_value> get_raw() const; const std::vector<scripting::script_value>& get_raw() const;
scripting::value_wrap get(const int index) const; scripting::value_wrap get(const std::uint32_t index) const;
scripting::value_wrap operator[](const int index) const scripting::value_wrap operator[](const std::uint32_t index) const
{ {
return this->get(index); return this->get(index);
} }
@@ -36,20 +47,55 @@ namespace gsc
using script_function = std::function<scripting::script_value(const function_args&)>; using script_function = std::function<scripting::script_value(const function_args&)>;
using script_method = std::function<scripting::script_value(const game::scr_entref_t, const function_args&)>; using script_method = std::function<scripting::script_value(const game::scr_entref_t, const function_args&)>;
void call_function(const script_function& function, const std::string& name);
void call_method(const script_method& method, const std::string& name, game::scr_entref_t ent);
namespace function namespace function
{ {
void add(const std::string& name, const script_function& func); template <typename F>
void add(const std::string& n, F&& f)
{
static auto done = false;
assert(!done);
done = true;
static struct
{
std::string name;
script_function function;
} ctx{n, f};
plugin::get()->get_interface()->gsc()->register_function(n, []()
{
call_function(ctx.function, ctx.name);
});
}
} }
namespace method namespace method
{ {
void add(const std::string& name, const script_method& func); template <typename F>
void add(const std::string& n, F&& f)
{
static auto done = false;
assert(!done);
done = true;
static struct
{
std::string name;
script_method function;
} ctx{n, f};
plugin::get()->get_interface()->gsc()->register_method(n, [](plutonium::sdk::types::entref entref)
{
call_method(ctx.function, ctx.name, *reinterpret_cast<game::scr_entref_t*>(&entref));
});
}
} }
namespace field namespace field
{ {
void add(const classid classnum, const std::string& name, void add(const class_id_t classnum, const std::string& name, const field_getter_t getter, const field_setter_t& setter);
const std::function<scripting::script_value(unsigned int entnum)>& getter,
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter);
} }
} }
+98 -73
View File
@@ -4,85 +4,119 @@
#include "scheduler.hpp" #include "scheduler.hpp"
#include "gsc.hpp" #include "gsc.hpp"
#include "json.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)
{
return;
}
gsc::function::add("jsonprint", [](const gsc::function_args& args) -> scripting::script_value printf("working directory: %s", fs_basegame->current.string);
std::filesystem::current_path(fs_basegame->current.string);
}
void on_startup([[maybe_unused]] plugin::plugin* plugin) override
{
scheduler::loop(run_requests, scheduler::async);
scheduler::loop(check_requests, scheduler::server);
scripting::on_shutdown([]()
{
requests.access([&](std::vector<http_request_t>& r)
{
r.clear();
});
});
gsc::function::add("jsonprint", [](const gsc::function_args& args)
-> scripting::script_value
{ {
std::string buffer; std::string buffer;
for (const auto arg : args.get_raw()) for (const auto& arg : args.get_raw())
{ {
buffer.append(json::gsc_to_string(arg)); buffer.append(json::gsc_to_string(arg));
buffer.append("\t"); buffer.append("\t");
} }
printf("%s\n", buffer.data()); printf("%s", buffer.data());
return {}; return {};
}); });
gsc::function::add("fremove", [](const gsc::function_args& args)
{
const auto path = args[0].as<const char*>();
return std::remove(path);
});
gsc::function::add("fopen", [](const gsc::function_args& args)
{
const auto* path = args[0].as<const char*>();
const auto* mode = args[1].as<const char*>();
const auto handle = fopen(path, mode);
if (!handle)
{
printf("fopen: Invalid path\n");
}
return handle;
});
gsc::function::add("fclose", [](const gsc::function_args& args)
{
const auto handle = args[0].as_ptr<FILE>();
return fclose(handle);
});
gsc::function::add("fwrite", [](const gsc::function_args& args)
{
const auto handle = args[0].as_ptr<FILE>();
const auto text = args[1].as<const char*>();
return fprintf(handle, text);
});
gsc::function::add("fread", [](const gsc::function_args& args)
{
const auto handle = args[0].as_ptr<FILE>();
fseek(handle, 0, SEEK_END);
const auto length = ftell(handle);
fseek(handle, 0, SEEK_SET);
char* buffer = (char*)calloc(length, sizeof(char));
fread(buffer, sizeof(char), length, handle);
const std::string result = buffer;
free(buffer);
return result;
});
gsc::function::add("fileexists", [](const gsc::function_args& args) gsc::function::add("fileexists", [](const gsc::function_args& args)
{ {
const auto path = args[0].as<std::string>(); const auto path = args[0].as<std::string>();
@@ -156,22 +190,13 @@ namespace io
return scripting::script_value{}; return scripting::script_value{};
}); });
gsc::function::add("httpget", [](const gsc::function_args& args) -> 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 url = args[0].as<std::string>();
const auto object = scripting::entity(scripting::make_object()); const auto object = scripting::entity(scripting::make_object());
scheduler::once([object, url]() add_request(url, object);
{
const auto result = utils::http::get_data(url.data());
scheduler::once([object, result]()
{
const auto value = result.has_value()
? result.value().substr(0, 0x5000)
: "";
scripting::notify(object, "done", {value});
});
}, scheduler::pipeline::async);
return object; return object;
}); });
@@ -179,4 +204,4 @@ namespace io
}; };
} }
REGISTER_COMPONENT(io::component) REGISTER_COMPONENT(io::component)
+4 -3
View File
@@ -20,7 +20,8 @@ namespace json
auto string_indexed = -1; auto string_indexed = -1;
const auto keys = array.get_keys(); const auto keys = array.get_keys();
for (auto i = 0; i < keys.size(); i++)
for (auto i = 0u; i < keys.size(); i++)
{ {
const auto is_int = keys[i].is<int>(); const auto is_int = keys[i].is<int>();
const auto is_string = keys[i].is<std::string>(); const auto is_string = keys[i].is<std::string>();
@@ -144,7 +145,7 @@ namespace json
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", [](const gsc::function_args& args) gsc::function::add("array", [](const gsc::function_args& args)
{ {
@@ -194,4 +195,4 @@ namespace json
}; };
} }
REGISTER_COMPONENT(json::component) REGISTER_COMPONENT(json::component)
-74
View File
@@ -1,74 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
#include "gsc.hpp"
#include "scripting.hpp"
namespace notifies
{
namespace
{
std::vector<scripting::function> say_callbacks;
utils::hook::detour client_command_hook;
void client_command_stub(int clientNum)
{
char cmd[1024] = {0};
const auto* entity = &game::g_entities[clientNum];
if (entity->client == nullptr)
{
return; // Client is not fully in game yet
}
game::SV_Cmd_ArgvBuffer(0, cmd, 1024);
auto hidden = false;
if (cmd == "say"s || cmd == "say_team"s)
{
std::string message = game::ConcatArgs(1);
message.erase(0, 1);
for (const auto& callback : say_callbacks)
{
const auto entity_id = game::Scr_GetEntityId(clientNum, 0);
const auto result = callback(entity_id, {message, cmd == "say_team"s});
if (result.is<int>() && !hidden)
{
hidden = result.as<int>() == 0;
}
}
}
if (!hidden)
{
client_command_hook.invoke<void>(clientNum);
}
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
client_command_hook.create(0x502CB0, client_command_stub);
scripting::on_shutdown([]()
{
say_callbacks.clear();
});
gsc::function::add("onplayersay", [](const gsc::function_args& args) -> scripting::script_value
{
const auto function = args[0].as<scripting::function>();
say_callbacks.push_back(function);
return {};
});
}
};
}
REGISTER_COMPONENT(notifies::component)
+13 -2
View File
@@ -77,6 +77,7 @@ namespace scheduler
}; };
std::thread thread; std::thread thread;
std::atomic_bool killed;
task_pipeline pipelines[pipeline::count]; task_pipeline pipelines[pipeline::count];
void execute(const pipeline type) void execute(const pipeline type)
@@ -128,11 +129,11 @@ namespace scheduler
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
{ {
thread = std::thread([]() thread = std::thread([]()
{ {
while (true) while (!killed)
{ {
execute(pipeline::async); execute(pipeline::async);
std::this_thread::sleep_for(10ms); std::this_thread::sleep_for(10ms);
@@ -141,6 +142,16 @@ namespace scheduler
utils::hook::call(0x50CEDC, server_frame_stub); utils::hook::call(0x50CEDC, server_frame_stub);
} }
void on_shutdown([[maybe_unused]] plugin::plugin* plugin) override
{
killed = true;
if (thread.joinable())
{
thread.join();
}
}
}; };
} }
+2 -91
View File
@@ -7,74 +7,17 @@
#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 "gsc.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, const char*>> script_function_table;
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_set_thread_position_hook;
utils::hook::detour process_script_hook;
std::string current_file;
std::vector<std::function<void()>> shutdown_callbacks; std::vector<std::function<void()>> shutdown_callbacks;
void vm_notify_stub(const unsigned int notify_list_owner_id, const unsigned int string_value,
game::VariableValue* top)
{
const auto* name = game::SL_ConvertToString(string_value);
if (name)
{
event e;
e.name = name;
e.entity = notify_list_owner_id;
for (auto* value = top; value->type != game::SCRIPT_END; --value)
{
e.arguments.emplace_back(*value);
}
if (e.name == "connected")
{
const auto player = e.arguments[0].as<scripting::entity>();
const auto client = player.call("getentitynumber").as<int>();
userinfo::clear_client_overrides(client);
}
}
vm_notify_hook.invoke<void>(notify_list_owner_id, string_value, top);
}
void scr_add_class_field_stub(unsigned int classnum, unsigned int _name, unsigned int canonicalString, unsigned int offset)
{
const auto name = game::SL_ConvertToString(_name);
if (fields_table[classnum].find(name) == fields_table[classnum].end())
{
fields_table[classnum][name] = offset;
}
scr_add_class_field_hook.invoke<void>(classnum, _name, canonicalString, offset);
}
void scr_load_level_stub()
{
scr_load_level_hook.invoke<void>();
}
void g_shutdown_game_stub(const int free_scripts) void g_shutdown_game_stub(const int free_scripts)
{ {
userinfo::clear_overrides(); userinfo::clear_overrides();
@@ -87,31 +30,6 @@ namespace scripting
g_shutdown_game_hook.invoke<void>(free_scripts); g_shutdown_game_hook.invoke<void>(free_scripts);
} }
void process_script_stub(const char* filename)
{
current_file = filename;
const auto file_id = atoi(filename);
if (file_id)
{
current_file = scripting::find_file(file_id);
}
process_script_hook.invoke<void>(filename);
}
void scr_set_thread_position_stub(unsigned int threadName, const char* codePos)
{
const auto function_name = scripting::find_token(threadName);
if (!function_name.empty())
{
script_function_table[current_file][function_name] = codePos;
}
scr_set_thread_position_hook.invoke<void>(threadName, codePos);
}
} }
void on_shutdown(const std::function<void()>& callback) void on_shutdown(const std::function<void()>& callback)
@@ -122,18 +40,11 @@ namespace scripting
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);
vm_notify_hook.create(0x569720, vm_notify_stub);
scr_set_thread_position_hook.create(0x5616D0, scr_set_thread_position_stub);
process_script_hook.create(0x56B130, process_script_stub);
} }
}; };
} }
REGISTER_COMPONENT(scripting::component) REGISTER_COMPONENT(scripting::component)
+1 -4
View File
@@ -2,8 +2,5 @@
namespace scripting namespace scripting
{ {
extern std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
extern std::unordered_map<std::string, std::unordered_map<std::string, const char*>> script_function_table;
void on_shutdown(const std::function<void()>& callback); void on_shutdown(const std::function<void()>& callback);
} }
-93
View File
@@ -1,93 +0,0 @@
#include <stdinc.hpp>
#include "signatures.hpp"
#include <utils/hook.hpp>
namespace signatures
{
size_t load_image_size()
{
MODULEINFO info{};
GetModuleInformation(GetCurrentProcess(),
GetModuleHandle("plutonium-bootstrapper-win32.exe"), &info, sizeof(MODULEINFO));
return info.SizeOfImage;
}
size_t get_image_size()
{
static const auto image_size = load_image_size();
return image_size;
}
void load_function_tables()
{
static const auto ptr = *reinterpret_cast<size_t*>(0x56CBDC + 0x1) + 0x56CBDC + 0x5;
static const auto function_table = *reinterpret_cast<size_t*>(0x56C8EB + 0x3);
static const auto method_table = *reinterpret_cast<size_t*>(ptr + 0xA);
game::plutonium::function_table.set(function_table);
game::plutonium::method_table.set(method_table);
}
size_t find_string_ptr(const std::string& string)
{
const char* string_ptr = nullptr;
std::string mask(string.size(), 'x');
const auto base = reinterpret_cast<size_t>(GetModuleHandle("plutonium-bootstrapper-win32.exe"));
utils::hook::signature signature(base, get_image_size() - base);
signature.add({
string,
mask,
[&](char* address)
{
string_ptr = address;
}
});
signature.process();
return reinterpret_cast<size_t>(string_ptr);
}
size_t find_string_ref(const std::string& string)
{
char bytes[4] = {0};
const auto string_ptr = find_string_ptr(string);
memcpy(bytes, &string_ptr, sizeof(bytes));
return find_string_ptr({bytes, 4});
}
bool process_maps()
{
const auto string_ref = find_string_ref("Couldn't resolve builtin function id for name '%s'!");
if (!string_ref)
{
return false;
}
const auto map_ptr = *reinterpret_cast<size_t*>(string_ref - 0x3A);
game::plutonium::function_map_rev.set(map_ptr);
game::plutonium::method_map_rev.set(map_ptr + 0x20);
game::plutonium::file_map_rev.set(map_ptr + 0x40);
game::plutonium::token_map_rev.set(map_ptr + 0x60);
return true;
}
bool process_printf()
{
const auto string_ref = find_string_ref("A critical exception occured!\n");
if (!string_ref)
{
return false;
}
const auto offset = *reinterpret_cast<size_t*>(string_ref + 5);
game::plutonium::printf.set(string_ref + 4 + 5 + offset);
return true;
}
bool process()
{
load_function_tables();
return process_printf() && process_maps();
}
}
-6
View File
@@ -1,6 +0,0 @@
#pragma once
namespace signatures
{
bool process();
}
+2 -7
View File
@@ -10,13 +10,8 @@ namespace string
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("toupper", [](const gsc::function_args& args)
{
return utils::string::to_upper(args[0].as<std::string>());
});
gsc::function::add("getchar", [](const gsc::function_args& args) gsc::function::add("getchar", [](const gsc::function_args& args)
{ {
auto index = 0; auto index = 0;
@@ -28,7 +23,7 @@ namespace string
const auto string = args[0].as<std::string>(); const auto string = args[0].as<std::string>();
if (index >= static_cast<int>(string.size())) if (index >= static_cast<int>(string.size()))
{ {
throw std::runtime_error("Char index out of bounds"); throw std::runtime_error("char index out of bounds");
} }
return static_cast<int>(string[index]); return static_cast<int>(string[index]);
+38 -31
View File
@@ -7,23 +7,23 @@
namespace userinfo namespace userinfo
{ {
using userinfo_map = std::unordered_map<std::string, std::string>; using userinfo_map = std::unordered_map<std::string, std::string>;
std::unordered_map<int, userinfo_map> userinfo_overrides; std::array<userinfo_map, 18> userinfo_overrides;
namespace namespace
{ {
utils::hook::detour sv_getuserinfo_hook; utils::hook::detour sv_getuserinfo_hook;
userinfo_map userinfo_to_map(std::string userinfo) userinfo_map userinfo_to_map(const char* userinfo)
{ {
userinfo_map map{}; userinfo_map map{};
if (userinfo[0] == '\\') if (userinfo[0] == '\\')
{ {
userinfo = userinfo.substr(1); ++userinfo;
} }
const auto args = utils::string::split(userinfo, '\\'); const auto args = utils::string::split(userinfo, '\\');
for (size_t i = 0; !args.empty() && i < (args.size() - 1); i += 2) for (auto i = 0u; !args.empty() && i < (args.size() - 1); i += 2)
{ {
map[args[i]] = args[i + 1]; map[args[i]] = args[i + 1];
} }
@@ -49,12 +49,8 @@ namespace userinfo
void sv_getuserinfo_stub(int index, char* buffer, int bufferSize) void sv_getuserinfo_stub(int index, char* buffer, int bufferSize)
{ {
sv_getuserinfo_hook.invoke<void>(index, buffer, bufferSize); sv_getuserinfo_hook.invoke<void>(index, buffer, bufferSize);
auto map = userinfo_to_map(buffer);
if (userinfo_overrides.find(index) == userinfo_overrides.end()) auto map = userinfo_to_map(buffer);
{
userinfo_overrides[index] = {};
}
for (const auto& values : userinfo_overrides[index]) for (const auto& values : userinfo_overrides[index])
{ {
@@ -71,35 +67,42 @@ namespace userinfo
const auto userinfo = map_to_userinfo(map); const auto userinfo = map_to_userinfo(map);
strcpy_s(buffer, 1024, userinfo.data()); strcpy_s(buffer, 1024, userinfo.data());
} }
}
void clear_client_overrides(int client) void clear_client_overrides(unsigned int client)
{ {
userinfo_overrides[client].clear(); userinfo_overrides[client].clear();
}
} }
void clear_overrides() void clear_overrides()
{ {
userinfo_overrides.clear(); for (auto& entry : userinfo_overrides)
{
entry.clear();
}
} }
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
{ {
sv_getuserinfo_hook.create(0x573E00, sv_getuserinfo_stub); sv_getuserinfo_hook.create(0x573E00, sv_getuserinfo_stub);
gsc::method::add("setname", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value 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) if (ent.classnum != 0)
{ {
throw std::runtime_error("Invalid entity"); throw std::runtime_error("invalid entity");
} }
if (game::g_entities[ent.entnum].client == nullptr) if (game::g_entities[ent.entnum].client == nullptr)
{ {
throw std::runtime_error("Not a player entity"); throw std::runtime_error("not a player entity");
} }
const auto name = args[0].as<std::string>(); const auto name = args[0].as<std::string>();
@@ -110,16 +113,17 @@ namespace userinfo
return {}; return {};
}); });
gsc::method::add("resetname", [](const game::scr_entref_t ent, const gsc::function_args&) -> scripting::script_value gsc::method::add("resetname", [](const game::scr_entref_t ent, const gsc::function_args&)
-> scripting::script_value
{ {
if (ent.classnum != 0) if (ent.classnum != 0)
{ {
throw std::runtime_error("Invalid entity"); throw std::runtime_error("invalid entity");
} }
if (game::g_entities[ent.entnum].client == nullptr) if (game::g_entities[ent.entnum].client == nullptr)
{ {
throw std::runtime_error("Not a player entity"); throw std::runtime_error("not a player entity");
} }
userinfo_overrides[ent.entnum].erase("name"); userinfo_overrides[ent.entnum].erase("name");
@@ -128,16 +132,17 @@ namespace userinfo
return {}; return {};
}); });
gsc::method::add("setclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value gsc::method::add("setclantag", [](const game::scr_entref_t ent, const gsc::function_args& args)
-> scripting::script_value
{ {
if (ent.classnum != 0) if (ent.classnum != 0)
{ {
throw std::runtime_error("Invalid entity"); throw std::runtime_error("invalid entity");
} }
if (game::g_entities[ent.entnum].client == nullptr) if (game::g_entities[ent.entnum].client == nullptr)
{ {
throw std::runtime_error("Not a player entity"); throw std::runtime_error("not a player entity");
} }
const auto name = args[0].as<std::string>(); const auto name = args[0].as<std::string>();
@@ -150,16 +155,17 @@ namespace userinfo
return {}; return {};
}); });
gsc::method::add("resetclantag", [](const game::scr_entref_t ent, const gsc::function_args&) -> scripting::script_value gsc::method::add("resetclantag", [](const game::scr_entref_t ent, const gsc::function_args&)
-> scripting::script_value
{ {
if (ent.classnum != 0) if (ent.classnum != 0)
{ {
throw std::runtime_error("Invalid entity"); throw std::runtime_error("invalid entity");
} }
if (game::g_entities[ent.entnum].client == nullptr) if (game::g_entities[ent.entnum].client == nullptr)
{ {
throw std::runtime_error("Not a player entity"); throw std::runtime_error("not a player entity");
} }
userinfo_overrides[ent.entnum].erase("clantag"); userinfo_overrides[ent.entnum].erase("clantag");
@@ -170,16 +176,17 @@ namespace userinfo
return {}; return {};
}); });
gsc::method::add("removeclantag", [](const game::scr_entref_t ent, const gsc::function_args&) -> scripting::script_value gsc::method::add("removeclantag", [](const game::scr_entref_t ent, const gsc::function_args&)
-> scripting::script_value
{ {
if (ent.classnum != 0) if (ent.classnum != 0)
{ {
throw std::runtime_error("Invalid entity"); throw std::runtime_error("invalid entity");
} }
if (game::g_entities[ent.entnum].client == nullptr) if (game::g_entities[ent.entnum].client == nullptr)
{ {
throw std::runtime_error("Not a player entity"); throw std::runtime_error("not a player entity");
} }
userinfo_overrides[ent.entnum]["clantag"] = ""; userinfo_overrides[ent.entnum]["clantag"] = "";
@@ -193,4 +200,4 @@ namespace userinfo
}; };
} }
REGISTER_COMPONENT(userinfo::component) REGISTER_COMPONENT(userinfo::component)
+1 -2
View File
@@ -2,6 +2,5 @@
namespace userinfo namespace userinfo
{ {
void clear_client_overrides(int client);
void clear_overrides(); void clear_overrides();
} }
+13 -18
View File
@@ -1,29 +1,24 @@
#include <stdinc.hpp> #include <stdinc.hpp>
#include "loader/component_loader.hpp" #include "loader/component_loader.hpp"
#include "component/signatures.hpp" #include "plugin.hpp"
BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/) PLUTONIUM_API plutonium::sdk::plugin* PLUTONIUM_CALLBACK on_initialize()
{ {
if (ul_reason_for_call == DLL_PROCESS_ATTACH) return plugin::get();
}
BOOL APIENTRY DllMain(HMODULE /*module*/, DWORD reason, LPVOID /*reserved*/)
{
if (reason == DLL_PROCESS_ATTACH)
{ {
if (!signatures::process())
{
MessageBoxA(NULL,
"This version of iw5-gsc-utils is outdated.\n" \
"Download the latest dll from here: https://github.com/fedddddd/iw5-gsc-utils/releases",
"ERROR", MB_ICONERROR);
return FALSE; }
}
if (game::plutonium::printf.get() != nullptr) if (reason == DLL_PROCESS_DETACH)
{ {
utils::hook::jump(reinterpret_cast<uintptr_t>(&printf), game::plutonium::printf); component_loader::on_shutdown();
}
component_loader::post_unpack();
} }
return TRUE; return TRUE;
} }
+21 -22
View File
@@ -15,30 +15,30 @@ namespace scripting
} }
const auto value = game::scr_VarGlob->childVariableValue[this->id_ + 0xC800 * (this->parent_id_ & 1)]; const auto value = game::scr_VarGlob->childVariableValue[this->id_ + 0xC800 * (this->parent_id_ & 1)];
game::VariableValue variable; game::VariableValue variable{};
variable.u = value.u.u; variable.u = value.u.u;
variable.type = (game::scriptType_e)value.type; variable.type = (game::scriptType_e)value.type;
this->value_ = variable; this->value_ = variable;
} }
void array_value::operator=(const script_value& _value) void array_value::operator=(const script_value& value)
{ {
if (!this->id_) if (!this->id_)
{ {
return; return;
} }
const auto value = _value.get_raw(); const auto& value_raw = value.get_raw();
const auto variable = &game::scr_VarGlob->childVariableValue[this->id_ + 0xC800 * (this->parent_id_ & 1)]; const auto variable = &game::scr_VarGlob->childVariableValue[this->id_ + 0xC800 * (this->parent_id_ & 1)];
game::AddRefToValue(value.type, value.u); game::AddRefToValue(value_raw.type, value_raw.u);
game::RemoveRefToValue(variable->type, variable->u.u); game::RemoveRefToValue(variable->type, variable->u.u);
variable->type = value.type; variable->type = value_raw.type;
variable->u.u = value.u; variable->u.u = value_raw.u;
this->value_ = value; this->value_ = value_raw;
} }
array::array(const unsigned int id) array::array(const unsigned int id)
@@ -170,7 +170,7 @@ namespace scripting
return game::Scr_GetSelf(this->id_); return game::Scr_GetSelf(this->id_);
} }
unsigned int array::push(script_value value) const unsigned int array::push(const script_value& value) const
{ {
this->set(this->size(), value); this->set(this->size(), value);
return this->size(); return this->size();
@@ -212,8 +212,6 @@ namespace scripting
{ {
return this->get(key.as<std::string>()); return this->get(key.as<std::string>());
} }
return {};
} }
script_value array::get(const std::string& key) const script_value array::get(const std::string& key) const
@@ -227,7 +225,7 @@ namespace scripting
} }
const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)]; const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)];
game::VariableValue variable; game::VariableValue variable{};
variable.u = value.u.u; variable.u = value.u.u;
variable.type = (game::scriptType_e)value.type; variable.type = (game::scriptType_e)value.type;
@@ -244,7 +242,7 @@ namespace scripting
} }
const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)]; const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)];
game::VariableValue variable; game::VariableValue variable{};
variable.u = value.u.u; variable.u = value.u.u;
variable.type = (game::scriptType_e)value.type; variable.type = (game::scriptType_e)value.type;
@@ -263,9 +261,9 @@ namespace scripting
} }
} }
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_raw = value.get_raw();
const auto variable_id = this->get_value_id(key); const auto variable_id = this->get_value_id(key);
if (!variable_id) if (!variable_id)
@@ -275,16 +273,16 @@ namespace scripting
const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)]; const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)];
game::AddRefToValue(value.type, value.u); game::AddRefToValue(value_raw.type, value_raw.u);
game::RemoveRefToValue(variable->type, variable->u.u); game::RemoveRefToValue(variable->type, variable->u.u);
variable->type = value.type; variable->type = value_raw.type;
variable->u.u = value.u; variable->u.u = value_raw.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_raw = 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)
@@ -294,11 +292,11 @@ namespace scripting
const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)]; const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)];
game::AddRefToValue(value.type, value.u); game::AddRefToValue(value_raw.type, value_raw.u);
game::RemoveRefToValue(variable->type, variable->u.u); game::RemoveRefToValue(variable->type, variable->u.u);
variable->type = value.type; variable->type = value_raw.type;
variable->u.u = value.u; variable->u.u = value_raw.u;
} }
unsigned int array::get_entity_id() const unsigned int array::get_entity_id() const
@@ -322,6 +320,7 @@ namespace scripting
unsigned int array::get_value_id(const unsigned int index) const unsigned int array::get_value_id(const unsigned int index) const
{ {
const auto variable_id = game::FindVariable(this->id_, (index - 0x800000) & 0xFFFFFF); const auto variable_id = game::FindVariable(this->id_, (index - 0x800000) & 0xFFFFFF);
if (!variable_id) if (!variable_id)
{ {
return game::GetNewArrayVariable(this->id_, index); return game::GetNewArrayVariable(this->id_, index);
+3 -3
View File
@@ -34,7 +34,7 @@ namespace scripting
std::vector<script_value> get_keys() const; std::vector<script_value> get_keys() const;
unsigned int size() const; unsigned int size() const;
unsigned int push(script_value) const; unsigned int push(const script_value&) const;
void erase(const unsigned int) const; void erase(const unsigned int) const;
void erase(const std::string&) const; void erase(const std::string&) const;
script_value pop() const; script_value pop() const;
@@ -69,12 +69,12 @@ namespace scripting
{ {
if (key.is<I>()) if (key.is<I>())
{ {
return { this->id_, this->get_value_id(key.as<I>()) }; return {this->id_, this->get_value_id(key.as<I>())};
} }
if (key.is<S>()) if (key.is<S>())
{ {
return { this->id_, this->get_value_id(key.as<S>()) }; return {this->id_, this->get_value_id(key.as<S>())};
} }
} }
-16
View File
@@ -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);
}
} }
-16
View File
@@ -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>();
}
} }
-168
View File
@@ -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,122 +103,6 @@ namespace scripting
return get_return_value(); return get_return_value();
} }
const char* get_function_pos(const std::string& filename, const std::string& function)
{
if (scripting::script_function_table.find(filename) == scripting::script_function_table.end())
{
throw std::runtime_error("File '" + filename + "' not found");
};
const auto functions = scripting::script_function_table[filename];
if (functions.find(function) == functions.end())
{
throw std::runtime_error("Function '" + function + "' in file '" + filename + "' not found");
}
return functions.at(function);
}
script_value call_script_function(const entity& entity, const std::string& filename,
const std::string& function, const std::vector<script_value>& arguments)
{
const auto pos = get_function_pos(filename, function);
return exec_ent_thread(entity, pos, arguments);
}
static std::unordered_map<unsigned int, std::unordered_map<std::string, script_value>> custom_fields;
script_value get_custom_field(const entity& entity, const std::string& field)
{
auto fields = custom_fields[entity.get_entity_id()];
const auto _field = fields.find(field);
if (_field != fields.end())
{
return _field->second;
}
return {};
}
void set_custom_field(const entity& entity, const std::string& field, const script_value& value)
{
const auto id = entity.get_entity_id();
if (custom_fields[id].find(field) != custom_fields[id].end())
{
custom_fields[id][field] = value;
return;
}
custom_fields[id].insert(std::make_pair(field, value));
}
void clear_entity_fields(const entity& entity)
{
const auto id = entity.get_entity_id();
if (custom_fields.find(id) != custom_fields.end())
{
custom_fields[id].clear();
}
}
void clear_custom_fields()
{
custom_fields.clear();
}
void set_entity_field(const entity& entity, const std::string& field, const script_value& value)
{
const auto entref = entity.get_entity_reference();
const int id = get_field_id(entref.classnum, field);
if (id != -1)
{
stack_isolation _;
push_value(value);
game::scr_VmPub->outparamcount = game::scr_VmPub->inparamcount;
game::scr_VmPub->inparamcount = 0;
if (!safe_execution::set_entity_field(entref, id))
{
throw std::runtime_error("Failed to set value for field '" + field + "'");
}
}
else
{
set_custom_field(entity, field, value);
}
}
script_value get_entity_field(const entity& entity, const std::string& field)
{
const auto entref = entity.get_entity_reference();
const auto id = get_field_id(entref.classnum, field);
if (id != -1)
{
stack_isolation _;
game::VariableValue value{};
if (!safe_execution::get_entity_field(entref, id, &value))
{
throw std::runtime_error("Failed to get value for field '" + field + "'");
}
const auto __ = gsl::finally([value]()
{
game::RemoveRefToValue(value.type, value.u);
});
return value;
}
else
{
return get_custom_field(entity, field);
}
}
unsigned int make_array() unsigned int make_array()
{ {
unsigned int index = 0; unsigned int index = 0;
-12
View File
@@ -9,10 +9,6 @@ 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 = {});
@@ -26,14 +22,6 @@ namespace scripting
} }
script_value exec_ent_thread(const entity& entity, const char* pos, const std::vector<script_value>& arguments); script_value 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);
+2 -3
View File
@@ -11,10 +11,9 @@ namespace scripting
script_value function::get_raw() const script_value function::get_raw() const
{ {
game::VariableValue value; game::VariableValue value{};
value.type = game::SCRIPT_FUNCTION; value.type = game::SCRIPT_FUNCTION;
value.u.codePosValue = this->pos_; value.u.codePosValue = this->pos_;
return value; return value;
} }
@@ -23,7 +22,7 @@ namespace scripting
return this->pos_; return this->pos_;
} }
script_value function::call(const entity& self, std::vector<script_value> arguments) const script_value function::call(const entity& self, const std::vector<script_value>& arguments) const
{ {
return exec_ent_thread(self, this->pos_, arguments); return exec_ent_thread(self, this->pos_, arguments);
} }
+5 -3
View File
@@ -12,14 +12,14 @@ namespace scripting
script_value get_raw() const; script_value get_raw() const;
const char* get_pos() const; const char* get_pos() const;
script_value call(const entity& self, std::vector<script_value> arguments) const; script_value call(const entity& self, const std::vector<script_value>& arguments) const;
script_value operator()(const entity& self, std::vector<script_value> arguments) const script_value operator()(const entity& self, const std::vector<script_value>& arguments) const
{ {
return this->call(self, arguments); return this->call(self, arguments);
} }
script_value operator()(std::vector<script_value> arguments) const script_value operator()(const std::vector<script_value>& arguments) const
{ {
return this->call(*game::levelEntityId, arguments); return this->call(*game::levelEntityId, arguments);
} }
@@ -28,7 +28,9 @@ namespace scripting
{ {
return this->call(*game::levelEntityId, {}); return this->call(*game::levelEntityId, {});
} }
private: private:
const char* pos_; const char* pos_;
}; };
} }
-122
View File
@@ -1,122 +0,0 @@
#include <stdinc.hpp>
#include "functions.hpp"
#include <utils/string.hpp>
namespace scripting
{
namespace
{
std::unordered_map<std::string, uint16_t> lowercase_map(
const std::unordered_map<std::string, uint16_t>& old_map)
{
std::unordered_map<std::string, uint16_t> new_map{};
for (auto& entry : old_map)
{
new_map[utils::string::to_lower(entry.first)] = entry.second;
}
return new_map;
}
const std::unordered_map<std::string, uint16_t>& get_methods()
{
static auto methods = lowercase_map(*game::plutonium::method_map_rev);
return methods;
}
const std::unordered_map<std::string, uint16_t>& get_functions()
{
static auto function = lowercase_map(*game::plutonium::function_map_rev);
return function;
}
int find_function_index(const std::string& name, const bool prefer_global)
{
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 = game::plutonium::function_table.get();
static const auto method_table = game::plutonium::method_table.get();
if (index < 0x1C7)
{
return reinterpret_cast<script_function*>(function_table)[index];
}
return reinterpret_cast<script_function*>(method_table)[index - 0x8000];
}
}
std::string find_file(unsigned int id)
{
const auto& file_map = *game::plutonium::file_map_rev;
for (const auto& file : file_map)
{
if (file.second == id)
{
return file.first;
}
}
return {};
}
std::string find_token(unsigned int id)
{
const auto& token_map = *game::plutonium::token_map_rev;
for (const auto& token : token_map)
{
if (token.second == id)
{
return token.first;
}
}
return {};
}
int find_token_id(const std::string& name)
{
const auto& token_map = *game::plutonium::token_map_rev;
const auto result = token_map.find(name);
if (result != token_map.end())
{
return result->second;
}
return -1;
}
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);
}
}
-12
View File
@@ -1,12 +0,0 @@
#pragma once
#include "game/game.hpp"
namespace scripting
{
using script_function = void(*)(game::scr_entref_t);
script_function find_function(const std::string& name, const bool prefer_global);
int find_token_id(const std::string& name);
std::string find_token(unsigned int id);
std::string find_file(unsigned int id);
}
-74
View File
@@ -1,74 +0,0 @@
#include <stdinc.hpp>
#include "safe_execution.hpp"
#pragma warning(push)
#pragma warning(disable: 4611)
namespace scripting::safe_execution
{
namespace
{
bool execute_with_seh(const script_function function, const game::scr_entref_t& entref)
{
__try
{
function(entref);
return true;
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return false;
}
}
}
bool call(const script_function function, const game::scr_entref_t& entref)
{
*game::g_script_error_level += 1;
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level], 0, 0, 0))
{
*game::g_script_error_level -= 1;
return false;
}
const auto result = execute_with_seh(function, entref);
*game::g_script_error_level -= 1;
return result;
}
bool set_entity_field(const game::scr_entref_t& entref, const int offset)
{
*game::g_script_error_level += 1;
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level], 0, 0, 0))
{
*game::g_script_error_level -= 1;
return false;
}
game::Scr_SetObjectField(entref.classnum, entref.entnum, offset);
*game::g_script_error_level -= 1;
return true;
}
bool get_entity_field(const game::scr_entref_t& entref, const int offset, game::VariableValue* value)
{
*game::g_script_error_level += 1;
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level], 0, 0, 0))
{
value->type = game::SCRIPT_NONE;
value->u.intValue = 0;
*game::g_script_error_level -= 1;
return false;
}
const auto _value = game::GetEntityFieldValue(entref.classnum, entref.entnum, offset);
value->type = _value.type;
value->u = _value.u;
*game::g_script_error_level -= 1;
return true;
}
}
#pragma warning(pop)
-10
View File
@@ -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);
}
+1 -1
View File
@@ -321,7 +321,7 @@ namespace scripting
return this->value_.get(); return this->value_.get();
} }
value_wrap::value_wrap(const scripting::script_value& value, int argument_index) value_wrap::value_wrap(const scripting::script_value& value, const std::uint32_t argument_index)
: value_(value) : value_(value)
, argument_index_(argument_index) , argument_index_(argument_index)
{ {
+3 -3
View File
@@ -164,7 +164,7 @@ namespace scripting
class value_wrap class value_wrap
{ {
public: public:
value_wrap(const scripting::script_value& value, int argument_index); value_wrap(const scripting::script_value& value, const std::uint32_t);
template <typename T> template <typename T>
T as() const T as() const
@@ -179,7 +179,7 @@ namespace scripting
} }
} }
template <typename T, typename I = int> template <typename T>
T* as_ptr() T* as_ptr()
{ {
try try
@@ -203,7 +203,7 @@ namespace scripting
return this->value_.get_raw(); return this->value_.get_raw();
} }
int argument_index_{}; std::uint32_t argument_index_{};
scripting::script_value value_; scripting::script_value value_;
}; };
} }
+1 -1
View File
@@ -26,6 +26,6 @@ namespace scripting
void set_z(float value); void set_z(float value);
private: private:
game::vec3_t value_{ 0 }; game::vec3_t value_{};
}; };
} }
+1 -13
View File
@@ -25,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};
@@ -50,6 +48,7 @@ namespace game
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<void(unsigned int classnum, unsigned int name, unsigned int canonicalString, unsigned int offset)> Scr_AddClassField{0x567CD0};
WEAK symbol<void()> Scr_ErrorInternal{0x568FD0};
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<unsigned int(const char* str)> SL_GetCanonicalString{0x5619A0};
@@ -83,15 +82,4 @@ namespace game
WEAK symbol<dvar_t> sv_maxclients{0x1BA0E4C}; WEAK symbol<dvar_t> sv_maxclients{0x1BA0E4C};
WEAK symbol<int> svs_clientCount{0x4B5CF8C}; WEAK symbol<int> svs_clientCount{0x4B5CF8C};
WEAK symbol<client_s> svs_clients{0x4B5CF90}; WEAK symbol<client_s> svs_clients{0x4B5CF90};
namespace plutonium
{
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> function_map_rev{0};
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> method_map_rev{0};
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> file_map_rev{0};
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> token_map_rev{0};
WEAK symbol<int(const char* fmt, ...)> printf{0};
WEAK symbol<void*> function_table{0};
WEAK symbol<void*> method_table{0};
}
} }
+6 -6
View File
@@ -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()
+34 -89
View File
@@ -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;
}); });
+10 -10
View File
@@ -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); \
} }
+74
View File
@@ -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;
}
}
+30
View File
@@ -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();
}
+3 -2
View File
@@ -34,16 +34,17 @@
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/concurrency.hpp"
#include "utils/http.hpp" #include "utils/http.hpp"
#include "game/structs.hpp" #include "game/structs.hpp"
#include "game/game.hpp" #include "game/game.hpp"
-144
View File
@@ -1,144 +0,0 @@
#pragma once
#include <mutex>
#include <memory>
// This class is trash. Need to get rid of it.
namespace utils
{
template <typename T>
class concurrent_list final
{
public:
class element final
{
public:
explicit element(std::recursive_mutex* mutex, std::shared_ptr<T> entry = {},
std::shared_ptr<element> next = {}) :
mutex_(mutex),
entry_(std::move(entry)),
next_(std::move(next))
{
}
void remove(const std::shared_ptr<T>& element)
{
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
if (!this->next_) return;
if (this->next_->entry_.get() == element.get())
{
this->next_ = this->next_->next_;
}
else
{
this->next_->remove(element);
}
}
[[nodiscard]] std::shared_ptr<element> get_next() const
{
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
return this->next_;
}
std::shared_ptr<T> operator*() const
{
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
return this->entry_;
}
element& operator++()
{
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
*this = this->next_ ? *this->next_ : element(this->mutex_);
return *this;
}
element operator++(int)
{
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
auto result = *this;
this->operator++();
return result;
}
bool operator==(const element& other)
{
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
return this->entry_.get() == other.entry_.get();
}
bool operator!=(const element& other)
{
std::lock_guard<std::recursive_mutex> _(*this->mutex_);
return !(*this == other);
}
private:
std::recursive_mutex* mutex_;
std::shared_ptr<T> entry_;
std::shared_ptr<element> next_;
};
element begin()
{
std::lock_guard<std::recursive_mutex> _(this->mutex_);
return this->entry_ ? *this->entry_ : this->end();
}
element end()
{
std::lock_guard<std::recursive_mutex> _(this->mutex_);
return element(&this->mutex_);
}
void remove(const element& entry)
{
std::lock_guard<std::recursive_mutex> _(this->mutex_);
this->remove(*entry);
}
void remove(const std::shared_ptr<T>& element)
{
std::lock_guard<std::recursive_mutex> _(this->mutex_);
if (!this->entry_) return;
if ((**this->entry_).get() == element.get())
{
this->entry_ = this->entry_->get_next();
}
else
{
this->entry_->remove(element);
}
}
void add(const T& object)
{
std::lock_guard<std::recursive_mutex> _(this->mutex_);
const auto object_ptr = std::make_shared<T>(object);
this->entry_ = std::make_shared<element>(&this->mutex_, object_ptr, this->entry_);
}
void add(T&& object)
{
std::lock_guard<std::recursive_mutex> _(this->mutex_);
const auto object_ptr = std::make_shared<T>(std::move(object));
this->entry_ = std::make_shared<element>(&this->mutex_, object_ptr, this->entry_);
}
void clear()
{
std::lock_guard<std::recursive_mutex> _(this->mutex_);
this->entry_ = {};
}
private:
std::recursive_mutex mutex_;
std::shared_ptr<element> entry_;
};
}
+13 -42
View File
@@ -4,48 +4,6 @@
namespace utils::hook namespace utils::hook
{ {
// open-iw5
void signature::process()
{
if (this->signatures_.empty()) return;
const auto start = static_cast<char*>(this->start_);
const unsigned int sig_count = this->signatures_.size();
const auto containers = this->signatures_.data();
for (size_t i = 0; i < this->length_; ++i)
{
const auto address = start + i;
for (unsigned int k = 0; k < sig_count; ++k)
{
const auto container = &containers[k];
unsigned int j;
for (j = 0; j < static_cast<unsigned int>(container->mask.size()); ++j)
{
if (container->mask[j] != '?' && container->signature[j] != address[j])
{
break;
}
}
if (j == container->mask.size())
{
container->callback(address);
}
}
}
}
void signature::add(const container& container)
{
signatures_.push_back(container);
}
namespace namespace
{ {
[[maybe_unused]] class _ [[maybe_unused]] class _
@@ -219,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);
}
} }
+3 -31
View File
@@ -4,37 +4,6 @@
namespace utils::hook namespace utils::hook
{ {
class signature final
{
public:
struct container final
{
std::string signature;
std::string mask;
std::function<void(char*)> callback;
};
signature(void* start, const size_t length) : start_(start), length_(length)
{
}
signature(const DWORD start, const size_t length) : signature(reinterpret_cast<void*>(start), length)
{
}
signature() : signature(0x400000, 0x800000)
{
}
void process();
void add(const container& container);
private:
void* start_;
size_t length_;
std::vector<container> signatures_;
};
class detour class detour
{ {
public: public:
@@ -144,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);
} }
+6
View File
@@ -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();
+1
View File
@@ -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.