138 Commits
v1.0.0 ... main

Author SHA1 Message Date
fed
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
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](f1a494cfd2...b39e7e4b09)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-27 14:30:40 +00:00
fed
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
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](e342bb3dae...5c42a230b7)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-12 14:10:29 +00:00
fed
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
fed
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
fed
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
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](643e17b749...e342bb3dae)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-07 14:11:12 +00:00
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](e64c97fc2c...f1a494cfd2)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-30 15:02:59 +00:00
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](3780b41dd0...0457de21cf)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-30 15:02:56 +00:00
fed
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
fed
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
fed
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
fed
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
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](da92c0e3e7...3780b41dd0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-07 14:58:09 +00:00
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](0f25a2449b...f5485b8454)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-27 15:05:13 +00:00
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](79a0e447a0...643e17b749)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-15 14:14:08 +00:00
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](52212c2d76...e64c97fc2c)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-19 14:37:17 +00:00
fed
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
fed
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
fed
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
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](4300304ef2...52212c2d76)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-12 14:12:10 +00:00
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](5d2754306d...da92c0e3e7)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-11 14:56:53 +00:00
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](04f42ceca4...79a0e447a0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-21 14:47:09 +00:00
fed
dd8c1ff71e Update signatures.cpp 2023-08-10 01:55:12 +02:00
fed
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
fed
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
fed
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
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](f0264876df...d7365e471a)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-28 14:35:53 +00:00
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](303d964a24...4300304ef2)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-27 14:35:38 +00:00
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](c71ecde505...5d2754306d)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-14 15:06:14 +00:00
fed
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
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](a0c1318830...c71ecde505)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-12 14:14:45 +00:00
fed
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
fed
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
fed
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
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](afaaa71bce...303d964a24)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-23 15:04:36 +00:00
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](6af826d0bd...a0c1318830)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-22 15:10:24 +00:00
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](a8a62c2667...f0264876df)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-19 15:04:33 +00:00
fed
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
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](98b74f1fc1...0f25a2449b)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-15 15:08:38 +00:00
1b2d4dbc46 Merge pull request #20 from fedddddd/dependabot/submodules/deps/json-6af826d 2023-05-13 18:05:49 +00:00
7dfb35233e Merge pull request #22 from fedddddd/dependabot/submodules/deps/minhook-98b74f1 2023-05-13 18:04:33 +00:00
d842022056 Merge pull request #21 from fedddddd/dependabot/submodules/deps/GSL-afaaa71 2023-05-13 18:03:36 +00:00
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](e4643d1f1b...6af826d0bd)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-13 17:58:53 +00:00
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](c31a9ad5e8...afaaa71bce)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-13 17:58:43 +00:00
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](423d1e45af...98b74f1fc1)

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

Signed-off-by: dependabot[bot] <support@github.com>
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
fed
1d94fdd88d Small fix 2022-12-28 01:07:53 +01:00
0af6b1cb13 Fix for update 2022-07-12 22:12:53 +02:00
d72c6f7057 Fix #16 2022-03-27 23:42:47 +02:00
39b9e7e352 Small change 2022-03-26 20:03:42 +01:00
36fefa6bb5 Remove this 2022-03-26 20:01:21 +01:00
4ffdb331b4 Use signature utils 2022-03-26 19:51:51 +01:00
7b995b3348 Add some string functions 2022-03-26 00:05:02 +01:00
14d0f401fb vs2022 build 2022-03-18 01:17:28 +01:00
df23604b1e Update pointers 2022-03-17 19:23:52 +01:00
fed
e2960bc895 Merge pull request #14 from diamante0018/main
Update Premake5, fix git modules.
2022-02-26 12:13:25 +01:00
db90d361a9 tabs 2022-02-26 11:12:55 +00:00
6ec0c5e23c .git 2022-02-26 11:00:11 +00:00
c84d681a3a Re add unfricked json 2022-02-26 10:58:51 +00:00
62d1c8671b Re add unfricked json 2022-02-26 10:58:41 +00:00
877adfa4b6 Fix json 2022-02-26 10:54:43 +00:00
12fd44d0da New gsc func + premake5 update 2022-02-26 10:51:20 +00:00
fed
12562eb8fd Merge pull request #13 from diamante0018/main
Clean up gsc functions with additional checks
2022-02-25 12:04:16 +01:00
286481cbcd Clean up gsc functions with additional checks 2022-02-24 19:25:58 +00:00
e9a877bd74 Update dllmain.cpp 2022-02-11 19:35:46 +01:00
3060df1f05 Update pointers 2022-02-07 02:00:15 +01:00
fed
aa1ae8c574 Merge pull request #12 from diamante0018/main 2022-02-02 15:25:52 +01:00
ccd8176c25 Remove assert 2022-02-02 15:24:20 +01:00
c230a1d916 Remove incorrect offset comments 2022-02-02 12:47:46 +01:00
2785a60dc0 Add function drop all bots 2022-02-02 12:45:07 +01:00
1b65bda323 Update pointers 2022-01-29 16:37:04 +01:00
9ca07aca55 Update pointers 2022-01-23 22:09:40 +01:00
fed
10b45027d0 Merge pull request #10 from diamante0018/main
Add isBot function
2022-01-06 22:08:45 +01:00
d5c0063fee Add isBot function 2022-01-06 22:04:19 +01:00
31920b0692 Some fixes 2021-12-27 21:03:29 +01:00
fed
89e4edc00b Fix 2021-12-14 10:03:59 +01:00
fed
379a21ff7e Small fix 2021-12-13 08:06:24 +01:00
0ac5225114 #5 2021-12-13 03:05:22 +01:00
e918bdf28f Update dllmain.cpp 2021-12-02 00:42:58 +01:00
fed
50b83787e7 Update pointers 2021-12-02 00:38:28 +01:00
e6ca925562 Fix setjmp 2021-11-15 22:06:44 +01:00
0f92a7ce25 Fixes for pluto update 2021-11-09 23:55:25 +01:00
d4d91de80f Small change 2021-11-09 22:48:15 +01:00
a508a7e3a4 Also function 2021-11-08 01:42:55 +01:00
640fb032ea Print errors 2021-11-08 01:36:48 +01:00
eee68760e4 Add custom entity field support 2021-11-07 23:42:56 +01:00
7526de9b76 Fix struct 2021-11-07 18:57:55 +01:00
705ad50d65 Fixes for pluto update 2021-11-07 02:33:16 +01:00
e8cad54293 Merge branch 'main' of https://github.com/fedddddd/iw5-gsc-utils 2021-11-07 02:06:05 +01:00
a548e9d04b Update dllmain.cpp 2021-11-07 02:06:03 +01:00
fed
d4c8a7ce2c Merge pull request #3 from diamante0018/main
Add unlimited sprint toggle via gsc
2021-11-07 01:22:05 +01:00
Edo
ba290e0f7c [GSC] VS Delete this space 2021-11-07 00:19:03 +00:00
234f510e98 [GSC] Add infinite sprint 2021-11-07 00:04:31 +00:00
8224ca3b57 Update pointers 2021-11-06 02:16:11 +01:00
a19c2761c8 Update pointers 2021-10-21 18:55:01 +02:00
739ea2a7f0 Update pointers 2021-10-01 03:04:08 +02:00
6c99991429 Typo 2021-08-31 21:06:18 +02:00
c9543dfbe4 Verify plutonium version 2021-08-31 20:58:15 +02:00
76842b4bce Update pointers 2021-08-31 20:23:36 +02:00
7139e8d3c4 Update pointers 2021-07-21 14:10:16 +02:00
6f53ed5d87 And this 2021-07-11 17:17:22 +02:00
063caa51f9 This too 2021-07-11 17:12:24 +02:00
9ed8626067 Fix array class 2021-07-11 17:11:15 +02:00
fed
cb0725bad1 Fix 2021-07-11 04:26:57 +02:00
44886c8f9f Small change 2021-06-26 00:42:00 +02:00
bdfd37de35 Update gsc.cpp 2021-06-24 20:22:21 +02:00
c49ca5a8cd Remove this 2021-06-20 21:21:29 +02:00
b1a29ded7d Add httpGet function 2021-06-20 20:04:36 +02:00
fed
e5083cd228 Update README.md 2021-06-20 16:24:16 +02:00
288fa38dac Fix exceptions 2021-06-20 00:47:44 +02:00
dbc0a928b9 Add jsonPrint function 2021-06-20 00:36:07 +02:00
9ead1676b0 Add functions to change player clantags/name 2021-06-20 00:31:56 +02:00
97371d8f44 Use function class 2021-06-19 22:17:41 +02:00
fed
7ac6443b2c Update README.md 2021-06-19 03:41:47 +02:00
50eb58dfd9 Refactoring + update some stuff 2021-06-19 03:40:28 +02:00
833271b7a1 Add some array methods 2021-06-19 00:30:51 +02:00
517cad33f4 Use FindVariable 2021-06-19 00:17:21 +02:00
fed
d96e28cdcb Update README.md 2021-06-18 23:42:14 +02:00
3d59fd7aa7 More fixes 2021-06-18 23:29:48 +02:00
8e0c68ddf9 Add more IO functions 2021-06-18 23:18:14 +02:00
2a0789692f Catch insufficient arguments 2021-06-18 23:18:04 +02:00
376e7f11ec Small fix 2021-06-18 23:01:15 +02:00
c8063eb0b0 Use array class 2021-06-18 22:42:12 +02:00
7170f863f3 Cleanup 2021-06-18 22:26:30 +02:00
ec9a2ad7fa Also notify say_team 2021-06-18 22:26:18 +02:00
e84cfe54a6 Correct json array indexes 2021-06-18 22:23:37 +02:00
57 changed files with 2312 additions and 7882 deletions

7
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: gitsubmodule
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10

45
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,45 @@
name: Build
on:
push:
branches:
- "*"
pull_request:
branches:
- "*"
types: [opened, synchronize, reopened]
jobs:
build:
name: Build binaries
runs-on: windows-2022
strategy:
matrix:
configuration:
- Debug
- Release
steps:
- name: Check out files
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
lfs: false
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1.3
- 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@v3.1.0
with:
name: ${{matrix.configuration}} binaries
path: |
build/bin/${{matrix.configuration}}/iw5-gsc-utils.dll

13
.gitmodules vendored
View File

@ -4,12 +4,13 @@
[submodule "deps/GSL"]
path = deps/GSL
url = https://github.com/microsoft/GSL.git
[submodule "deps/sol2"]
path = deps/sol2
url = https://github.com/ThePhD/sol2.git
[submodule "deps/lua"]
path = deps/lua
url = https://github.com/lua/lua.git
[submodule "deps/json"]
path = deps/json
url = https://github.com/nlohmann/json.git
branch = develop
[submodule "deps/gsc-tool"]
path = deps/gsc-tool
url = https://github.com/xensik/gsc-tool.git
[submodule "deps/zlib"]
path = deps/zlib
url = https://github.com/madler/zlib.git

View File

@ -10,7 +10,7 @@ This plugin adds some useful functions/methods to IW5's GSC VM
```c
init()
{
replaceFunc(maps\mp\gametypes\_damage::Callback_PlayerDamage, ::callbackPlayerDamage);
replaceFunc(maps\mp\gametypes\_damage::Callback_PlayerDamage, ::callbackPlayerDamage);
}
callbackPlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, timeOffset)
@ -43,7 +43,19 @@ This plugin adds some useful functions/methods to IW5's GSC VM
}
}
```
# Player
* `say(message)`: Prints a message to all players' chat.
* `self tell(message)`: Prints a message to the player's chat.
* `self setName(name)`: Sets a player's name.
* `self resetName(name)`: Resets a player's name to its original.
* `self setClantag(name)`: Sets a player's clantag.
* `self resetClantag(name)`: Resets a player's clantag to its original.
* `self removeClantag(name)`: Removes a player's clantag.
# IO
The basepath for all IO functions is `Plutonium/storage/iw5`
* `fopen(path, mode)`: Opens a file of given name with given mode, returns a file stream.
* `fwrite(stream, text)`: Writes a string to a stream.
* `fread(stream)`: Reads entire file.
@ -64,6 +76,15 @@ This plugin adds some useful functions/methods to IW5's GSC VM
fclose(file);
}
```
* `fileExists(path)`: Returns true if the file exists.
* `writeFile(path, data[, append])`: Creates a file if it doesn't exist and writes/appends text to it.
* `readFile(path)`: Reads a file.
* `fileSize(path)`: Returns file size in bytes.
* `createDirectory(path)`: Creates a directory.
* `directoryExists(path)`: Returns true if the directory exists.
* `directoryIsEmpty(path)`: Returns true if the directory is empty.
* `listFiles(path)`: Returns the list of files in the directory as an array.
* `copyFolder(source, target)`: Copies a folder.
# JSON
@ -205,6 +226,6 @@ This plugin adds some useful functions/methods to IW5's GSC VM
*/
}
```
* `jsonPrint(...)`: Prints values as json.
# Credits
* [xensik](https://github.com/xensik)

2
deps/GSL vendored

Submodule deps/GSL updated: c1cbb41b42...b39e7e4b09

1
deps/gsc-tool vendored Submodule

Submodule deps/gsc-tool added at 0e6238a6ab

2
deps/json vendored

Submodule deps/json updated: e10a3fac8a...0457de21cf

2
deps/minhook vendored

62
deps/premake/gsc-tool.lua vendored Normal file
View File

@ -0,0 +1,62 @@
gsc_tool = {
source = path.join(dependencies.basePath, "gsc-tool"),
}
function gsc_tool.import()
links { "xsk-gsc-iw5-pc", "xsk-gsc-utils" }
gsc_tool.includes()
end
function gsc_tool.includes()
includedirs {
path.join(gsc_tool.source, "include"),
}
end
function gsc_tool.project()
project "xsk-gsc-utils"
kind "StaticLib"
language "C++"
files {
path.join(gsc_tool.source, "include/xsk/utils/*.hpp"),
path.join(gsc_tool.source, "src/utils/*.cpp"),
}
includedirs {
path.join(gsc_tool.source, "include"),
}
zlib.includes()
project "xsk-gsc-iw5-pc"
kind "StaticLib"
language "C++"
filter "action:vs*"
buildoptions "/Zc:__cplusplus"
filter {}
files {
path.join(gsc_tool.source, "include/xsk/stdinc.hpp"),
path.join(gsc_tool.source, "include/xsk/gsc/engine/iw5_pc.hpp"),
path.join(gsc_tool.source, "src/gsc/engine/iw5_pc.cpp"),
path.join(gsc_tool.source, "src/gsc/engine/iw5_pc_code.cpp"),
path.join(gsc_tool.source, "src/gsc/engine/iw5_pc_func.cpp"),
path.join(gsc_tool.source, "src/gsc/engine/iw5_pc_meth.cpp"),
path.join(gsc_tool.source, "src/gsc/engine/iw5_pc_token.cpp"),
path.join(gsc_tool.source, "src/gsc/*.cpp"),
path.join(gsc_tool.source, "src/gsc/common/*.cpp"),
path.join(gsc_tool.source, "include/xsk/gsc/common/*.hpp"),
}
includedirs {
path.join(gsc_tool.source, "include"),
}
end
table.insert(dependencies, gsc_tool)

39
deps/premake/zlib.lua vendored Normal file
View File

@ -0,0 +1,39 @@
zlib = {
source = path.join(dependencies.basePath, "zlib"),
}
function zlib.import()
links { "zlib" }
zlib.includes()
end
function zlib.includes()
includedirs {
zlib.source
}
defines {
"ZLIB_CONST",
}
end
function zlib.project()
project "zlib"
language "C"
zlib.includes()
files {
path.join(zlib.source, "*.h"),
path.join(zlib.source, "*.c"),
}
defines {
"_CRT_SECURE_NO_DEPRECATE",
}
warnings "Off"
kind "StaticLib"
end
table.insert(dependencies, zlib)

1
deps/zlib vendored Submodule

Submodule deps/zlib added at 5c42a230b7

View File

@ -1,2 +1,3 @@
@echo off
tools\windows\premake5.exe vs2019
call git submodule update --init --recursive
tools\premake5.exe vs2022

View File

@ -36,12 +36,19 @@ workspace "iw5-gsc-utils"
targetdir "%{wks.location}/bin/%{cfg.buildcfg}"
targetname "%{prj.name}"
configurations { "Debug", "Release", }
language "C++"
cppdialect "C++20"
architecture "x86"
buildoptions "/std:c++latest"
systemversion "latest"
symbols "On"
staticruntime "On"
editandcontinue "Off"
warnings "Extra"
characterset "ASCII"
flags
{
@ -49,19 +56,15 @@ workspace "iw5-gsc-utils"
"MultiProcessorCompile",
}
configurations { "Debug", "Release", }
symbols "On"
configuration "Release"
filter "configurations:Release"
optimize "Full"
defines { "NDEBUG" }
configuration{}
filter {}
configuration "Debug"
filter "configurations:Debug"
optimize "Debug"
defines { "DEBUG", "_DEBUG" }
configuration {}
filter {}
startproject "iw5-gsc-utils"

View File

@ -49,6 +49,7 @@ namespace command
if (i > index) result.append(" ");
result.append(this->get(i));
}
return result;
}
@ -96,7 +97,6 @@ namespace command
public:
void post_unpack() override
{
}
};
}

View File

@ -7,6 +7,8 @@
#include "game/scripting/event.hpp"
#include "game/scripting/execution.hpp"
#include "game/scripting/functions.hpp"
#include "game/scripting/array.hpp"
#include "game/scripting/function.hpp"
#include "gsc.hpp"
@ -19,13 +21,13 @@ namespace gsc
{
std::string method_name(unsigned int id)
{
const auto map = *game::plutonium::method_map_rev;
const auto& map = (*game::plutonium::gsc_ctx)->meth_map();
for (const auto& function : map)
{
if (function.second == id)
{
return function.first;
return function.first.data();
}
}
@ -34,13 +36,13 @@ namespace gsc
std::string function_name(unsigned int id)
{
const auto map = *game::plutonium::function_map_rev;
const auto& map = (*game::plutonium::gsc_ctx)->func_map();
for (const auto& function : map)
{
if (function.second == id)
{
return function.first;
return function.first.data();
}
}
@ -49,9 +51,7 @@ namespace gsc
function_args get_arguments()
{
function_args args;
const auto top = game::scr_VmPub->top;
std::vector<scripting::script_value> args;
for (auto i = 0; i < game::scr_VmPub->outparamcount; i++)
{
@ -74,12 +74,24 @@ namespace gsc
auto function_map_start = 0x200;
auto method_map_start = 0x8400;
auto token_map_start = 0x8000;
auto field_offset_start = 0xA000;
struct entity_field
{
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*>(0x1D6EB34)[id]();
return reinterpret_cast<builtin_function*>(game::plutonium::function_table.get())[id]();
}
try
@ -92,11 +104,11 @@ namespace gsc
return_value(result);
}
}
catch (std::exception e)
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("Error executing function %s:\n", function_name(id).data());
printf(" %s\n", e.what());
printf("****************************************************\n");
}
}
@ -105,7 +117,7 @@ namespace gsc
{
if (id < 0x8400)
{
return reinterpret_cast<builtin_method*>(0x1D4F258)[id](ent);
return reinterpret_cast<builtin_method*>(game::plutonium::method_table.get())[id - 0x8000](ent);
}
try
@ -118,11 +130,11 @@ namespace gsc
return_value(result);
}
}
catch (std::exception e)
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("Error executing method %s:\n", method_name(id).data());
printf(" %s\n", e.what());
printf("****************************************************\n");
}
}
@ -172,60 +184,63 @@ namespace gsc
}
}
unsigned int replaced_pos = 0;
void get_replaced_pos(unsigned int pos)
utils::hook::detour scr_get_object_field_hook;
void scr_get_object_field_stub(unsigned int classnum, int entnum, unsigned int offset)
{
if (scripting::replaced_functions.find(pos) != scripting::replaced_functions.end())
if (custom_fields[classnum].find(offset) == custom_fields[classnum].end())
{
replaced_pos = scripting::replaced_functions[pos];
return scr_get_object_field_hook.invoke<void>(classnum, entnum, offset);
}
const auto& field = custom_fields[classnum][offset];
try
{
const auto result = field.getter(entnum);
return_value(result);
}
catch (const std::exception& e)
{
printf("************** Script execution error **************\n");
printf("Error getting field %s:\n", field.name.data());
printf(" %s\n", e.what());
printf("****************************************************\n");
}
}
__declspec(naked) void vm_execute_stub()
utils::hook::detour scr_set_object_field_hook;
void scr_set_object_field_stub(unsigned int classnum, int entnum, unsigned int offset)
{
__asm
if (custom_fields[classnum].find(offset) == custom_fields[classnum].end())
{
pushad
push esi
call get_replaced_pos
pop esi
popad
cmp replaced_pos, 0
jne set_pos
movzx eax, byte ptr[esi]
inc esi
jmp loc_1
loc_1:
mov [ebp - 0x18], eax
mov [ebp - 0x8], esi
push ecx
mov ecx, 0x20B8E28
mov [ecx], eax
mov ecx, 0x20B4A5C
mov[ecx], esi
pop ecx
cmp eax, 0x98
push 0x56B740
retn
set_pos:
mov esi, replaced_pos
mov replaced_pos, 0
movzx eax, byte ptr[esi]
inc esi
jmp loc_1
return scr_set_object_field_hook.invoke<void>(classnum, entnum, offset);
}
const auto args = get_arguments();
const auto& field = custom_fields[classnum][offset];
try
{
field.setter(entnum, args[0]);
}
catch (const std::exception& e)
{
printf("************** Script execution error **************\n");
printf("Error setting field %s:\n", field.name.data());
printf(" %s\n", e.what());
printf("****************************************************\n");
}
}
utils::hook::detour scr_post_load_scripts_hook;
void scr_post_load_scripts_stub()
{
for (const auto& callback : post_load_callbacks)
{
callback();
}
return scr_post_load_scripts_hook.invoke<void>();
}
}
@ -233,10 +248,21 @@ namespace gsc
{
void add(const std::string& name, const script_function& func)
{
const auto index = function_map_start++;
auto index = 0u;
auto& ctx = (*game::plutonium::gsc_ctx);
functions[index] = func;
(*game::plutonium::function_map_rev)[name] = index;
if (ctx->func_exists(name))
{
printf("[iw5-gsc-utils] Warning: function '%s' already defined\n", name.data());
index = ctx->func_id(name);
}
else
{
index = function_map_start++;
ctx->func_add(name, index);
}
functions.insert(std::make_pair(index, func));
}
}
@ -244,38 +270,64 @@ namespace gsc
{
void add(const std::string& name, const script_method& func)
{
const auto index = method_map_start++;
auto index = 0u;
auto& ctx = (*game::plutonium::gsc_ctx);
methods[index] = func;
(*game::plutonium::method_map_rev)[name] = index;
if (ctx->meth_exists(name))
{
printf("[iw5-gsc-utils] Warning: method '%s' already defined\n", name.data());
index = ctx->meth_id(name);
}
else
{
index = method_map_start++;
ctx->meth_add(name, index);
}
methods.insert(std::make_pair(index, func));
}
}
unsigned int make_array()
namespace field
{
unsigned int index = 0;
const auto variable = game::AllocVariable(&index);
variable->w.type = game::SCRIPT_ARRAY;
variable->u.f.prev = 0;
variable->u.f.next = 0;
void add(const classid classnum, const std::string& name,
const std::function<scripting::script_value(unsigned int entnum)>& getter,
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter)
{
const auto offset = field_offset_start++;
custom_fields[classnum][offset] = {name, getter, setter};
return index;
post_load_callbacks.push_back([=]()
{
const auto name_str = game::SL_GetString(name.data(), 0);
game::Scr_AddClassField(classnum, name_str, game::SL_GetCanonicalString(name.data()), offset);
});
}
}
void add_array_key_value(unsigned int parent_id, const std::string& _key, const scripting::script_value& value)
function_args::function_args(std::vector<scripting::script_value> values)
: values_(values)
{
const auto key = game::SL_GetString(_key.data(), 0);
scripting::push_value(scripting::entity(parent_id));
scripting::push_value(value);
game::Scr_AddArrayStringIndexed(key);
}
void add_array_value(unsigned int parent_id, const scripting::script_value& value)
unsigned int function_args::size() const
{
scripting::push_value(scripting::entity(parent_id));
scripting::push_value(value);
game::Scr_AddArray();
return this->values_.size();
}
std::vector<scripting::script_value> function_args::get_raw() const
{
return this->values_;
}
scripting::value_wrap function_args::get(const int index) const
{
if (index >= this->values_.size())
{
throw std::runtime_error(utils::string::va("parameter %d does not exist", index));
}
return {this->values_[index], index};
}
class component final : public component_interface
@ -283,54 +335,61 @@ namespace gsc
public:
void post_unpack() override
{
function::add("executecommand", [](function_args args) -> scripting::script_value
scr_get_object_field_hook.create(0x52BDB0, scr_get_object_field_stub);
scr_set_object_field_hook.create(0x52BCC0, scr_set_object_field_stub);
scr_post_load_scripts_hook.create(0x628B50, scr_post_load_scripts_stub);
field::add(classid::entity, "entityflags",
[](unsigned int entnum) -> scripting::script_value
{
const auto entity = &game::g_entities[entnum];
return entity->flags;
},
[](unsigned int entnum, const scripting::script_value& value)
{
const auto entity = &game::g_entities[entnum];
entity->flags = value.as<int>();
}
);
field::add(classid::entity, "clientflags",
[](unsigned int entnum) -> scripting::script_value
{
const auto entity = &game::g_entities[entnum];
return entity->client->flags;
},
[](unsigned int entnum, const scripting::script_value& value)
{
const auto entity = &game::g_entities[entnum];
entity->client->flags = value.as<int>();
}
);
function::add("executecommand", [](const function_args& args) -> scripting::script_value
{
game::Cbuf_AddText(0, args[0].as<const char*>());
return {};
});
function::add("replacefunc", [](function_args args) -> scripting::script_value
{
const auto what = args[0].get_raw();
const auto with = args[1].get_raw();
if (what.type != game::SCRIPT_FUNCTION || with.type != game::SCRIPT_FUNCTION)
{
throw std::runtime_error("Invalid type");
}
scripting::replaced_functions[what.u.uintValue] = with.u.uintValue;
return {};
});
function::add("addcommand", [](function_args args) -> scripting::script_value
function::add("addcommand", [](const function_args& args) -> scripting::script_value
{
const auto name = args[0].as<std::string>();
const auto function = args[1].get_raw();
if (function.type != game::SCRIPT_FUNCTION)
const auto function = args[1].as<scripting::function>();
command::add_script_command(name, [function](const command::params& params)
{
throw std::runtime_error("Invalid type");
}
const auto pos = function.u.codePosValue;
command::add_script_command(name, [pos](const command::params& params)
{
const auto array = make_array();
scripting::array array;
for (auto i = 0; i < params.size(); i++)
{
add_array_value(array, params[i]);
array.push(params[i]);
}
const auto entity = scripting::entity(array);
scripting::exec_ent_thread(*game::levelEntityId, pos, {entity});
function({array.get_raw()});
});
return {};
});
function::add("say", [](function_args args) -> scripting::script_value
function::add("say", [](const function_args& args) -> scripting::script_value
{
const auto message = args[0].as<std::string>();
game::SV_GameSendServerCommand(-1, 0, utils::string::va("%c \"%s\"", 84, message.data()));
@ -338,24 +397,103 @@ namespace gsc
return {};
});
method::add("tell", [](game::scr_entref_t ent, function_args args) -> scripting::script_value
function::add("dropallbots", [](const function_args&) -> scripting::script_value
{
for (auto i = 0; i < *game::svs_clientCount; i++)
{
if (game::svs_clients[i].header.state != game::CS_FREE
&& game::svs_clients[i].header.netchan.remoteAddress.type == game::NA_BOT)
{
game::SV_GameDropClient(i, "GAME_GET_TO_COVER");
}
}
return {};
});
method::add("tell", [](const game::scr_entref_t ent, const function_args& args) -> scripting::script_value
{
if (ent.classnum != 0)
{
throw std::runtime_error("Invalid type");
throw std::runtime_error("Invalid entity");
}
const auto client = ent.entnum;
const auto message = args[0].as<std::string>();
if (game::g_entities[client].client == nullptr)
{
throw std::runtime_error("Not a player entity");
}
const auto message = args[0].as<std::string>();
game::SV_GameSendServerCommand(client, 0, utils::string::va("%c \"%s\"", 84, message.data()));
return {};
});
utils::hook::jump(0x56C8EB, call_builtin_stub);
utils::hook::jump(0x56CBDC, call_builtin_method_stub);
utils::hook::jump(0x56B726, vm_execute_stub);
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>();
auto flags = game::g_entities[client].client->ps.perks[0];
game::g_entities[client].client->ps.perks[0] = toggle
? flags | 0x4000u : flags & ~0x4000u;
return {};
});
method::add("isbot", [](const game::scr_entref_t ent, const function_args&) -> scripting::script_value
{
if (ent.classnum != 0)
{
throw std::runtime_error("Invalid entity");
}
const auto client = ent.entnum;
if (game::g_entities[client].client == nullptr)
{
throw std::runtime_error("Not a player entity");
}
return game::svs_clients[client].bIsTestClient;
});
method::add("arecontrolsfrozen", [](const game::scr_entref_t ent, const function_args&) -> scripting::script_value
{
if (ent.classnum != 0)
{
throw std::runtime_error("Invalid entity");
}
const auto client = ent.entnum;
if (game::g_entities[client].client == nullptr)
{
throw std::runtime_error("Not a player entity");
}
return {(game::g_entities[client].client->flags & 4) != 0};
});
// 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);
});
}
};
}

View File

@ -1,14 +1,40 @@
#pragma once
#include "game/scripting/array.hpp"
#include "game/scripting/execution.hpp"
namespace gsc
{
using function_args = std::vector<scripting::script_value>;
enum classid
{
entity,
hudelem,
pathnode,
node,
count
};
class function_args
{
public:
function_args(std::vector<scripting::script_value>);
unsigned int size() const;
std::vector<scripting::script_value> get_raw() const;
scripting::value_wrap get(const int index) const;
scripting::value_wrap operator[](const int index) const
{
return this->get(index);
}
private:
std::vector<scripting::script_value> values_;
};
using builtin_function = void(*)();
using builtin_method = void(*)(game::scr_entref_t);
using script_function = std::function<scripting::script_value(function_args)>;
using script_method = std::function<scripting::script_value(game::scr_entref_t, 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&)>;
namespace function
{
@ -20,7 +46,10 @@ namespace gsc
void add(const std::string& name, const script_method& func);
}
unsigned int make_array();
void add_array_key_value(unsigned int parent_id, const std::string& _key, const scripting::script_value& value);
void add_array_value(unsigned int parent_id, const scripting::script_value& value);
namespace field
{
void add(const classid classnum, const std::string& name,
const std::function<scripting::script_value(unsigned int entnum)>& getter,
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter);
}
}

View File

@ -2,12 +2,8 @@
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
#include "game/scripting/event.hpp"
#include "game/scripting/execution.hpp"
#include "game/scripting/functions.hpp"
#include "gsc.hpp"
#include "json.hpp"
namespace io
{
@ -19,13 +15,27 @@ namespace io
const auto path = game::Dvar_FindVar("fs_basegame")->current.string;
std::filesystem::current_path(path);
gsc::function::add("fremove", [](gsc::function_args args)
gsc::function::add("jsonprint", [](const gsc::function_args& args) -> scripting::script_value
{
std::string buffer;
for (const auto arg : args.get_raw())
{
buffer.append(json::gsc_to_string(arg));
buffer.append("\t");
}
printf("%s\n", buffer.data());
return {};
});
gsc::function::add("fremove", [](const gsc::function_args& args)
{
const auto path = args[0].as<const char*>();
return std::remove(path);
});
gsc::function::add("fopen", [](gsc::function_args args)
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*>();
@ -40,13 +50,13 @@ namespace io
return handle;
});
gsc::function::add("fclose", [](gsc::function_args args)
gsc::function::add("fclose", [](const gsc::function_args& args)
{
const auto handle = args[0].as_ptr<FILE>();
return fclose(handle);
});
gsc::function::add("fwrite", [](gsc::function_args args)
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*>();
@ -54,7 +64,7 @@ namespace io
return fprintf(handle, text);
});
gsc::function::add("fread", [](gsc::function_args args)
gsc::function::add("fread", [](const gsc::function_args& args)
{
const auto handle = args[0].as_ptr<FILE>();
@ -72,6 +82,99 @@ namespace io
return result;
});
gsc::function::add("fileexists", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
return utils::io::file_exists(path);
});
gsc::function::add("writefile", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
const auto data = args[1].as<std::string>();
auto append = false;
if (args.size() > 2)
{
append = args[2].as<bool>();
}
return utils::io::write_file(path, data, append);
});
gsc::function::add("readfile", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
return utils::io::read_file(path);
});
gsc::function::add("filesize", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
return utils::io::file_size(path);
});
gsc::function::add("createdirectory", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
return utils::io::create_directory(path);
});
gsc::function::add("directoryexists", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
return utils::io::directory_exists(path);
});
gsc::function::add("directoryisempty", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
return utils::io::directory_is_empty(path);
});
gsc::function::add("listfiles", [](const gsc::function_args& args)
{
const auto path = args[0].as<std::string>();
const auto files = utils::io::list_files(path);
scripting::array array;
for (const auto& file : files)
{
array.push(file);
}
return array;
});
gsc::function::add("copyfolder", [](const gsc::function_args& args)
{
const auto source = args[0].as<std::string>();
const auto target = args[1].as<std::string>();
utils::io::copy_folder(source, target);
return scripting::script_value{};
});
gsc::function::add("httpget", [](const gsc::function_args& args) -> scripting::script_value
{
const auto url = args[0].as<std::string>();
const auto object = scripting::entity(scripting::make_object());
scheduler::once([object, url]()
{
const auto result = utils::http::get_data(url.data());
scheduler::once([object, result]()
{
const auto value = result.has_value()
? result.value().substr(0, 0x5000)
: "";
scripting::notify(object, "done", {value});
});
}, scheduler::pipeline::async);
return object;
});
}
};
}

View File

@ -2,12 +2,8 @@
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
#include "game/scripting/event.hpp"
#include "game/scripting/execution.hpp"
#include "game/scripting/functions.hpp"
#include "gsc.hpp"
#include "json.hpp"
#include <json.hpp>
@ -19,44 +15,31 @@ namespace json
nlohmann::json entity_to_array(unsigned int id)
{
scripting::array array(id);
nlohmann::json obj;
auto string_indexed = -1;
const auto offset = 0xC800 * (id & 1);
auto current = game::scr_VarGlob->objectVariableChildren[id].firstChild;
for (auto i = offset + current; current; i = offset + current)
const auto keys = array.get_keys();
for (auto i = 0; i < keys.size(); i++)
{
const auto var = game::scr_VarGlob->childVariableValue[i];
if (var.type == game::SCRIPT_NONE)
{
current = var.nextSibling;
continue;
}
const auto string_value = (unsigned int)((unsigned __int8)var.name_lo + (var.k.keys.name_hi << 8));
const auto* str = game::SL_ConvertToString(string_value);
const auto is_int = keys[i].is<int>();
const auto is_string = keys[i].is<std::string>();
if (string_indexed == -1)
{
string_indexed = string_value < 0x40000 && str;
string_indexed = is_string;
}
game::VariableValue variable{};
variable.type = (game::scriptType_e)var.type;
variable.u = var.u.u;
if (!string_indexed)
if (!string_indexed && is_int)
{
obj.emplace_back(gsc_to_json(variable));
const auto index = keys[i].as<int>();
obj[index] = gsc_to_json(array[index]);
}
else
else if (string_indexed && is_string)
{
obj.emplace(str, gsc_to_json(variable));
const auto key = keys[i].as<std::string>();
obj.emplace(key, gsc_to_json(array[key]));
}
current = var.nextSibling;
}
return obj;
@ -127,25 +110,25 @@ namespace json
return obj.get<std::string>();
case (nlohmann::detail::value_t::array):
{
const auto arr = gsc::make_array();
scripting::array array;
for (const auto& [key, value] : obj.items())
{
gsc::add_array_value(arr, json_to_gsc(value));
array.push(json_to_gsc(value));
}
return scripting::entity(arr);
return array.get_raw();
}
case (nlohmann::detail::value_t::object):
{
const auto arr = gsc::make_array();
scripting::array array;
for (const auto& [key, value] : obj.items())
{
gsc::add_array_key_value(arr, key, json_to_gsc(value));
array[key] = json_to_gsc(value);
}
return scripting::entity(arr);
return array.get_raw();
}
}
@ -153,26 +136,25 @@ namespace json
}
}
std::string gsc_to_string(const scripting::script_value& value)
{
return gsc_to_json(value).dump();
}
class component final : public component_interface
{
public:
void post_unpack() override
{
gsc::function::add("array", [](gsc::function_args args)
gsc::function::add("array", [](const gsc::function_args& args)
{
const auto array = gsc::make_array();
for (auto i = 0; i < args.size(); i++)
{
gsc::add_array_value(array, args[i]);
}
return scripting::entity(array);
scripting::array array(args.get_raw());
return array.get_raw();
});
gsc::function::add("map", [](gsc::function_args args)
gsc::function::add("map", [](const gsc::function_args& args)
{
const auto array = gsc::make_array();
scripting::array array;
for (auto i = 0; i < args.size(); i += 2)
{
@ -182,13 +164,13 @@ namespace json
}
const auto key = args[i].as<std::string>();
gsc::add_array_key_value(array, key, args[i + 1]);
array[key] = args[i + 1];
}
return scripting::entity(array);
return array;
});
gsc::function::add("jsonparse", [](gsc::function_args args)
gsc::function::add("jsonparse", [](const gsc::function_args& args)
{
const auto json = args[0].as<std::string>();
const auto obj = nlohmann::json::parse(json);
@ -196,7 +178,7 @@ namespace json
return json_to_gsc(obj);
});
gsc::function::add("jsonserialize", [](gsc::function_args args)
gsc::function::add("jsonserialize", [](const gsc::function_args& args)
{
const auto value = args[0];
auto indent = -1;

6
src/component/json.hpp Normal file
View File

@ -0,0 +1,6 @@
#pragma once
namespace json
{
std::string gsc_to_string(const scripting::script_value& _value);
}

View File

@ -1,39 +1,51 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
#include "game/scripting/entity.hpp"
#include "game/scripting/execution.hpp"
#include "notifies.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;
utils::hook::detour scr_player_killed_hook;
utils::hook::detour scr_player_damage_hook;
void client_command_stub(int clientNum)
{
char cmd[1024] = { 0 };
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);
if (cmd == "say"s)
auto hidden = false;
if (cmd == "say"s || cmd == "say_team"s)
{
std::string message = game::ConcatArgs(1);
message.erase(0, 1);
const scripting::entity level{*game::levelEntityId};
const auto player = scripting::call("getEntByNum", {clientNum}).as<scripting::entity>();
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});
scripting::notify(level, "say", {player, message});
scripting::notify(player, "say", {message});
if (result.is<int>() && !hidden)
{
hidden = result.as<int>() == 0;
}
}
}
return client_command_hook.invoke<void>(clientNum);
if (!hidden)
{
client_command_hook.invoke<void>(clientNum);
}
}
}
@ -43,6 +55,18 @@ namespace notifies
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 {};
});
}
};
}

View File

@ -1,5 +0,0 @@
#pragma once
namespace notifies
{
}

View File

@ -1,73 +1,128 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
#include "game/game.hpp"
namespace scheduler
{
namespace
{
std::queue<std::function<void()>> tasks;
struct task
{
std::function<bool()> handler;
std::function<bool()> handler{};
std::chrono::milliseconds interval{};
std::chrono::high_resolution_clock::time_point last_call{};
};
utils::concurrent_list<task> callbacks;
using task_list = std::vector<task>;
void execute()
class task_pipeline
{
for (auto callback : callbacks)
public:
void add(task&& task)
{
const auto now = std::chrono::high_resolution_clock::now();
const auto diff = now - callback->last_call;
if (diff < callback->interval) continue;
callback->last_call = now;
const auto res = callback->handler();
if (res)
new_callbacks_.access([&task](task_list& tasks)
{
callbacks.remove(callback);
}
tasks.emplace_back(std::move(task));
});
}
void execute()
{
callbacks_.access([&](task_list& tasks)
{
this->merge_callbacks();
for (auto i = tasks.begin(); i != tasks.end();)
{
const auto now = std::chrono::high_resolution_clock::now();
const auto diff = now - i->last_call;
if (diff < i->interval)
{
++i;
continue;
}
i->last_call = now;
const auto res = i->handler();
if (res == cond_end)
{
i = tasks.erase(i);
}
else
{
++i;
}
}
});
}
private:
utils::concurrency::container<task_list> new_callbacks_;
utils::concurrency::container<task_list, std::recursive_mutex> callbacks_;
void merge_callbacks()
{
callbacks_.access([&](task_list& tasks)
{
new_callbacks_.access([&](task_list& new_tasks)
{
tasks.insert(tasks.end(), std::move_iterator<task_list::iterator>(new_tasks.begin()), std::move_iterator<task_list::iterator>(new_tasks.end()));
new_tasks = {};
});
});
}
};
std::thread thread;
task_pipeline pipelines[pipeline::count];
void execute(const pipeline type)
{
assert(type >= 0 && type < pipeline::count);
pipelines[type].execute();
}
void server_frame()
void server_frame_stub()
{
execute();
reinterpret_cast<void (*)()>(0x50C1E0)();
execute(pipeline::server);
}
}
void schedule(const std::function<bool()>& callback, const std::chrono::milliseconds delay)
void schedule(const std::function<bool()>& callback, const pipeline type,
const std::chrono::milliseconds delay)
{
assert(type >= 0 && type < pipeline::count);
task task;
task.handler = callback;
task.interval = delay;
task.last_call = std::chrono::high_resolution_clock::now();
callbacks.add(task);
pipelines[type].add(std::move(task));
}
void loop(const std::function<void()>& callback, const std::chrono::milliseconds delay)
void loop(const std::function<void()>& callback, const pipeline type,
const std::chrono::milliseconds delay)
{
schedule([callback]()
{
callback();
return false;
}, delay);
return cond_continue;
}, type, delay);
}
void once(const std::function<void()>& callback, const std::chrono::milliseconds delay)
void once(const std::function<void()>& callback, const pipeline type,
const std::chrono::milliseconds delay)
{
schedule([callback]()
{
callback();
return true;
}, delay);
return cond_end;
}, type, delay);
}
class component final : public component_interface
@ -75,7 +130,16 @@ namespace scheduler
public:
void post_unpack() override
{
utils::hook::call(0x50CEDC, server_frame);
thread = std::thread([]()
{
while (true)
{
execute(pipeline::async);
std::this_thread::sleep_for(10ms);
}
});
utils::hook::call(0x50CEDC, server_frame_stub);
}
};
}

View File

@ -2,9 +2,20 @@
namespace scheduler
{
void schedule(const std::function<bool()>& callback, std::chrono::milliseconds delay = 0ms);
void loop(const std::function<void()>& callback, std::chrono::milliseconds delay = 0ms);
void once(const std::function<void()>& callback, std::chrono::milliseconds delay = 0ms);
enum pipeline
{
server,
async,
count,
};
void init();
static const bool cond_continue = false;
static const bool cond_end = true;
void schedule(const std::function<bool()>& callback, pipeline type = pipeline::server,
std::chrono::milliseconds delay = 0ms);
void loop(const std::function<void()>& callback, pipeline type = pipeline::server,
std::chrono::milliseconds delay = 0ms);
void once(const std::function<void()>& callback, pipeline type = pipeline::server,
std::chrono::milliseconds delay = 0ms);
}

View File

@ -3,17 +3,18 @@
#include "scheduler.hpp"
#include "command.hpp"
#include "userinfo.hpp"
#include "game/scripting/event.hpp"
#include "game/scripting/execution.hpp"
#include "game/scripting/functions.hpp"
#include "gsc.hpp"
namespace scripting
{
std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
std::unordered_map<std::string, std::unordered_map<std::string, char*>> script_function_table;
std::unordered_map<unsigned, unsigned> replaced_functions;
std::unordered_map<std::string, std::unordered_map<std::string, const char*>> script_function_table;
namespace
{
@ -23,8 +24,12 @@ namespace scripting
utils::hook::detour scr_load_level_hook;
utils::hook::detour g_shutdown_game_hook;
utils::hook::detour scr_emit_function_hook;
utils::hook::detour scr_end_load_scripts_hook;
utils::hook::detour scr_set_thread_position_hook;
utils::hook::detour process_script_hook;
std::string current_file;
std::vector<std::function<void()>> shutdown_callbacks;
void vm_notify_stub(const unsigned int notify_list_owner_id, const unsigned int string_value,
game::VariableValue* top)
@ -44,7 +49,9 @@ namespace scripting
if (e.name == "connected")
{
scripting::clear_entity_fields(e.entity);
const auto player = e.arguments[0].as<scripting::entity>();
const auto client = player.call("getentitynumber").as<int>();
userinfo::clear_client_overrides(client);
}
}
@ -70,61 +77,48 @@ namespace scripting
void g_shutdown_game_stub(const int free_scripts)
{
userinfo::clear_overrides();
command::clear_script_commands();
replaced_functions.clear();
for (const auto& callback : shutdown_callbacks)
{
callback();
}
g_shutdown_game_hook.invoke<void>(free_scripts);
}
char* function_pos(unsigned int filename, unsigned int name)
void process_script_stub(const char* filename)
{
const auto scripts_pos = *reinterpret_cast<int*>(0x1D6EB14);
current_file = filename;
const auto v2 = game::FindVariable(scripts_pos, filename);
const auto v3 = game::FindObject(scripts_pos, v2);
const auto v4 = game::FindVariable(v3, name);
if (!v2 || !v3 || !v4)
const auto file_id = atoi(filename);
if (file_id)
{
return 0;
current_file = scripting::find_file(file_id);
}
return utils::hook::invoke<char*>(0x5659C0, v3, v4);
process_script_hook.invoke<void>(filename);
}
void scr_emit_function_stub(unsigned int filename, unsigned int threadName, char* codePos)
void scr_set_thread_position_stub(unsigned int threadName, const char* codePos)
{
const auto* name = game::SL_ConvertToString(filename);
const auto filename_id = atoi(name);
const auto function_name = scripting::find_token(threadName);
for (const auto& entry : scripting::file_list)
if (!function_name.empty())
{
if (entry.first == filename_id)
{
if (script_function_table.find(entry.second) == script_function_table.end())
{
script_function_table[entry.second] = {};
}
for (const auto& token : scripting::token_map)
{
if (token.second == threadName)
{
const auto pos = function_pos(filename, threadName);
if (pos)
{
script_function_table[entry.second][token.first] = pos;
}
}
}
}
script_function_table[current_file][function_name] = codePos;
}
scr_emit_function_hook.invoke<void>(filename, threadName, codePos);
scr_set_thread_position_hook.invoke<void>(threadName, codePos);
}
}
void on_shutdown(const std::function<void()>& callback)
{
shutdown_callbacks.push_back(callback);
}
class component final : public component_interface
{
public:
@ -134,6 +128,10 @@ namespace scripting
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);
}
};
}

View File

@ -2,8 +2,8 @@
namespace scripting
{
extern std::unordered_map<unsigned, unsigned> replaced_functions;
extern std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
extern std::unordered_map<std::string, std::unordered_map<std::string, char*>> script_function_table;
extern std::unordered_map<std::string, std::unordered_map<std::string, const char*>> script_function_table;
void on_shutdown(const std::function<void()>& callback);
}

View File

@ -0,0 +1,106 @@
#include <stdinc.hpp>
#include "signatures.hpp"
#include <utils/hook.hpp>
namespace signatures
{
size_t load_image_size()
{
MODULEINFO info{};
GetModuleInformation(GetCurrentProcess(),
GetModuleHandle("plutonium-bootstrapper-win32.exe"), &info, sizeof(MODULEINFO));
return info.SizeOfImage;
}
size_t get_image_size()
{
static const auto image_size = load_image_size();
return image_size;
}
void load_function_tables()
{
static const auto ptr = *reinterpret_cast<size_t*>(0x56CBDC + 0x1) + 0x56CBDC + 0x5;
static const auto function_table = *reinterpret_cast<size_t*>(0x56C8EB + 0x3);
static const auto method_table = *reinterpret_cast<size_t*>(ptr + 0xA);
game::plutonium::function_table.set(function_table);
game::plutonium::method_table.set(method_table);
}
size_t find_string_ptr(const std::string& string)
{
const char* string_ptr = nullptr;
std::string mask(string.size(), 'x');
const auto base = reinterpret_cast<size_t>(GetModuleHandle("plutonium-bootstrapper-win32.exe"));
utils::hook::signature signature(base, get_image_size() - base);
auto found = false;
signature.add({
string,
mask,
[&](char* address)
{
if (found)
{
return;
}
found = true;
string_ptr = address;
}
});
signature.process();
return reinterpret_cast<size_t>(string_ptr);
}
size_t find_string_ref(const std::string& string)
{
char bytes[4] = {0};
const auto string_ptr = find_string_ptr(string);
if (!string_ptr)
{
return 0;
}
std::memcpy(bytes, &string_ptr, sizeof(bytes));
return find_string_ptr({bytes, 4});
}
bool process_gsc_ctx()
{
const auto string_ref = find_string_ref("in call to builtin %s \"%s\"");
if (!string_ref)
{
return false;
}
const auto gsc_ctx_ptr = *reinterpret_cast<size_t*>(string_ref - 0xAD);
OutputDebugString(utils::string::va("gsc_ctx_ptr: %p\n", gsc_ctx_ptr));
game::plutonium::gsc_ctx.set(gsc_ctx_ptr);
return true;
}
bool process_printf()
{
const auto string_ref = find_string_ref("A critical exception occured!\n");
if (!string_ref)
{
return false;
}
const auto offset = *reinterpret_cast<size_t*>(string_ref + 5);
const auto printf_ptr = string_ref + 4 + 5 + offset;
OutputDebugString(utils::string::va("printf_ptr: %p\n", printf_ptr));
game::plutonium::printf.set(printf_ptr);
return true;
}
bool process()
{
load_function_tables();
return process_printf() && process_gsc_ctx();
}
}

View File

@ -0,0 +1,6 @@
#pragma once
namespace signatures
{
bool process();
}

46
src/component/string.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "gsc.hpp"
#include <utils/string.hpp>
namespace string
{
class component final : public component_interface
{
public:
void post_unpack() override
{
gsc::function::add("toupper", [](const gsc::function_args& args)
{
return utils::string::to_upper(args[0].as<std::string>());
});
gsc::function::add("getchar", [](const gsc::function_args& args)
{
auto index = 0;
if (args.size() > 1)
{
index = args[1].as<int>();
}
const auto string = args[0].as<std::string>();
if (index >= static_cast<int>(string.size()))
{
throw std::runtime_error("Char index out of bounds");
}
return static_cast<int>(string[index]);
});
gsc::function::add("chartostring", [](const gsc::function_args& args)
{
const auto char_ = static_cast<char>(args[0].as<int>());
return std::string(1, char_);
});
}
};
}
REGISTER_COMPONENT(string::component)

196
src/component/userinfo.cpp Normal file
View File

@ -0,0 +1,196 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
#include "gsc.hpp"
namespace userinfo
{
using userinfo_map = std::unordered_map<std::string, std::string>;
std::unordered_map<int, userinfo_map> userinfo_overrides;
namespace
{
utils::hook::detour sv_getuserinfo_hook;
userinfo_map userinfo_to_map(std::string userinfo)
{
userinfo_map map{};
if (userinfo[0] == '\\')
{
userinfo = userinfo.substr(1);
}
const auto args = utils::string::split(userinfo, '\\');
for (size_t i = 0; !args.empty() && i < (args.size() - 1); i += 2)
{
map[args[i]] = args[i + 1];
}
return map;
}
std::string map_to_userinfo(const userinfo_map& map)
{
std::string buffer{};
for (const auto& value : map)
{
buffer.append("\\");
buffer.append(value.first);
buffer.append("\\");
buffer.append(value.second);
}
return buffer;
}
void sv_getuserinfo_stub(int index, char* buffer, int bufferSize)
{
sv_getuserinfo_hook.invoke<void>(index, buffer, bufferSize);
auto map = userinfo_to_map(buffer);
if (userinfo_overrides.find(index) == userinfo_overrides.end())
{
userinfo_overrides[index] = {};
}
for (const auto& values : userinfo_overrides[index])
{
if (values.second.empty())
{
map.erase(values.first);
}
else
{
map[values.first] = values.second;
}
}
const auto userinfo = map_to_userinfo(map);
strcpy_s(buffer, 1024, userinfo.data());
}
}
void clear_client_overrides(int client)
{
userinfo_overrides[client].clear();
}
void clear_overrides()
{
userinfo_overrides.clear();
}
class component final : public component_interface
{
public:
void post_unpack() override
{
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
{
if (ent.classnum != 0)
{
throw std::runtime_error("Invalid entity");
}
if (game::g_entities[ent.entnum].client == nullptr)
{
throw std::runtime_error("Not a player entity");
}
const auto name = args[0].as<std::string>();
userinfo_overrides[ent.entnum]["name"] = name;
game::ClientUserinfoChanged(ent.entnum);
return {};
});
gsc::method::add("resetname", [](const game::scr_entref_t ent, const gsc::function_args&) -> scripting::script_value
{
if (ent.classnum != 0)
{
throw std::runtime_error("Invalid entity");
}
if (game::g_entities[ent.entnum].client == nullptr)
{
throw std::runtime_error("Not a player entity");
}
userinfo_overrides[ent.entnum].erase("name");
game::ClientUserinfoChanged(ent.entnum);
return {};
});
gsc::method::add("setclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
{
if (ent.classnum != 0)
{
throw std::runtime_error("Invalid entity");
}
if (game::g_entities[ent.entnum].client == nullptr)
{
throw std::runtime_error("Not a player entity");
}
const auto name = args[0].as<std::string>();
userinfo_overrides[ent.entnum]["clantag"] = name;
userinfo_overrides[ent.entnum]["ec_TagText"] = name;
userinfo_overrides[ent.entnum]["ec_usingTag"] = "1";
game::ClientUserinfoChanged(ent.entnum);
return {};
});
gsc::method::add("resetclantag", [](const game::scr_entref_t ent, const gsc::function_args&) -> scripting::script_value
{
if (ent.classnum != 0)
{
throw std::runtime_error("Invalid entity");
}
if (game::g_entities[ent.entnum].client == nullptr)
{
throw std::runtime_error("Not a player entity");
}
userinfo_overrides[ent.entnum].erase("clantag");
userinfo_overrides[ent.entnum].erase("ec_TagText");
userinfo_overrides[ent.entnum].erase("ec_usingTag");
game::ClientUserinfoChanged(ent.entnum);
return {};
});
gsc::method::add("removeclantag", [](const game::scr_entref_t ent, const gsc::function_args&) -> scripting::script_value
{
if (ent.classnum != 0)
{
throw std::runtime_error("Invalid entity");
}
if (game::g_entities[ent.entnum].client == nullptr)
{
throw std::runtime_error("Not a player entity");
}
userinfo_overrides[ent.entnum]["clantag"] = "";
userinfo_overrides[ent.entnum]["ec_TagText"] = "";
userinfo_overrides[ent.entnum]["ec_usingTag"] = "0";
game::ClientUserinfoChanged(ent.entnum);
return {};
});
}
};
}
REGISTER_COMPONENT(userinfo::component)

View File

@ -0,0 +1,7 @@
#pragma once
namespace userinfo
{
void clear_client_overrides(int client);
void clear_overrides();
}

View File

@ -1,10 +1,27 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
#include "component/signatures.hpp"
BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
if (!signatures::process())
{
MessageBoxA(NULL,
"This version of iw5-gsc-utils is outdated.\n" \
"Download the latest dll from here: https://github.com/fedddddd/iw5-gsc-utils/releases",
"ERROR", MB_ICONERROR);
return FALSE;
}
if (game::plutonium::printf.get() != nullptr)
{
utils::hook::jump(reinterpret_cast<uintptr_t>(&printf), game::plutonium::printf);
}
component_loader::post_unpack();
}

View File

@ -2,5 +2,11 @@
namespace game
{
void SV_GameDropClient(int clientNum, const char* reason)
{
if (clientNum >= 0 && clientNum < sv_maxclients->current.integer)
{
SV_DropClient(&svs_clients[clientNum], reason, true);
}
}
}

View File

@ -16,6 +16,11 @@ namespace game
return dedi_;
}
void set(const size_t dedi)
{
this->dedi_ = reinterpret_cast<T*>(dedi);
}
operator T* () const
{
return this->get();
@ -29,6 +34,8 @@ namespace game
private:
T* dedi_;
};
void SV_GameDropClient(int clientNum, const char* reason);
}
#include "symbols.hpp"

View File

@ -0,0 +1,337 @@
#include <stdinc.hpp>
#include "array.hpp"
#include "script_value.hpp"
#include "execution.hpp"
namespace scripting
{
array_value::array_value(unsigned int parent_id, unsigned int id)
: id_(id)
, parent_id_(parent_id)
{
if (!this->id_)
{
return;
}
const auto value = game::scr_VarGlob->childVariableValue[this->id_ + 0xC800 * (this->parent_id_ & 1)];
game::VariableValue variable;
variable.u = value.u.u;
variable.type = (game::scriptType_e)value.type;
this->value_ = variable;
}
void array_value::operator=(const script_value& _value)
{
if (!this->id_)
{
return;
}
const auto value = _value.get_raw();
const auto variable = &game::scr_VarGlob->childVariableValue[this->id_ + 0xC800 * (this->parent_id_ & 1)];
game::AddRefToValue(value.type, value.u);
game::RemoveRefToValue(variable->type, variable->u.u);
variable->type = value.type;
variable->u.u = value.u;
this->value_ = value;
}
array::array(const unsigned int id)
: id_(id)
{
this->add();
}
array::array(const array& other) : array(other.id_)
{
}
array::array(array&& other) noexcept
{
this->id_ = other.id_;
other.id_ = 0;
}
array::array()
{
this->id_ = make_array();
}
array::array(std::vector<script_value> values)
{
this->id_ = make_array();
for (const auto& value : values)
{
this->push(value);
}
}
array::array(std::unordered_map<std::string, script_value> values)
{
this->id_ = make_array();
for (const auto& value : values)
{
this->set(value.first, value.second);
}
}
array::~array()
{
this->release();
}
array& array::operator=(const array& other)
{
if (&other != this)
{
this->release();
this->id_ = other.id_;
this->add();
}
return *this;
}
array& array::operator=(array&& other) noexcept
{
if (&other != this)
{
this->release();
this->id_ = other.id_;
other.id_ = 0;
}
return *this;
}
void array::add() const
{
if (this->id_)
{
game::AddRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->id_)});
}
}
void array::release() const
{
if (this->id_)
{
game::RemoveRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->id_)});
}
}
std::vector<script_value> array::get_keys() const
{
std::vector<script_value> result;
const auto offset = 0xC800 * (this->id_ & 1);
auto current = game::scr_VarGlob->objectVariableChildren[this->id_].firstChild;
for (auto i = offset + current; current; i = offset + current)
{
const auto var = game::scr_VarGlob->childVariableValue[i];
if (var.type == game::SCRIPT_NONE)
{
current = var.nextSibling;
continue;
}
const auto string_value = (unsigned int)((unsigned __int8)var.name_lo + (var.k.keys.name_hi << 8));
const auto* str = game::SL_ConvertToString(string_value);
script_value key;
if (string_value < 0x40000 && str)
{
key = str;
}
else
{
key = (string_value - 0x800000) & 0xFFFFFF;
}
result.push_back(key);
current = var.nextSibling;
}
return result;
}
unsigned int array::size() const
{
return game::Scr_GetSelf(this->id_);
}
unsigned int array::push(script_value value) const
{
this->set(this->size(), value);
return this->size();
}
void array::erase(const unsigned int index) const
{
const auto variable_id = game::FindVariable(this->id_, (index - 0x800000) & 0xFFFFFF);
if (variable_id)
{
game::RemoveVariableValue(this->id_, variable_id);
}
}
void array::erase(const std::string& key) const
{
const auto string_value = game::SL_GetString(key.data(), 0);
const auto variable_id = game::FindVariable(this->id_, string_value);
if (variable_id)
{
game::RemoveVariableValue(this->id_, variable_id);
}
}
script_value array::pop() const
{
const auto value = this->get(this->size() - 1);
this->erase(this->size() - 1);
return value;
}
script_value array::get(const script_value& key) const
{
if (key.is<int>())
{
return this->get(key.as<int>());
}
else
{
return this->get(key.as<std::string>());
}
return {};
}
script_value array::get(const std::string& key) const
{
const auto string_value = game::SL_GetString(key.data(), 0);
const auto variable_id = game::FindVariable(this->id_, string_value);
if (!variable_id)
{
return {};
}
const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)];
game::VariableValue variable;
variable.u = value.u.u;
variable.type = (game::scriptType_e)value.type;
return variable;
}
script_value array::get(const unsigned int index) const
{
const auto variable_id = game::FindVariable(this->id_, (index - 0x800000) & 0xFFFFFF);
if (!variable_id)
{
return {};
}
const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)];
game::VariableValue variable;
variable.u = value.u.u;
variable.type = (game::scriptType_e)value.type;
return variable;
}
void array::set(const script_value& key, const script_value& value) const
{
if (key.is<int>())
{
this->set(key.as<int>(), value);
}
else
{
this->set(key.as<std::string>(), value);
}
}
void array::set(const std::string& key, const script_value& value_) const
{
const auto value = value_.get_raw();
const auto variable_id = this->get_value_id(key);
if (!variable_id)
{
return;
}
const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)];
game::AddRefToValue(value.type, value.u);
game::RemoveRefToValue(variable->type, variable->u.u);
variable->type = value.type;
variable->u.u = value.u;
}
void array::set(const unsigned int index, const script_value& value_) const
{
const auto value = value_.get_raw();
const auto variable_id = this->get_value_id(index);
if (!variable_id)
{
return;
}
const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)];
game::AddRefToValue(value.type, value.u);
game::RemoveRefToValue(variable->type, variable->u.u);
variable->type = value.type;
variable->u.u = value.u;
}
unsigned int array::get_entity_id() const
{
return this->id_;
}
unsigned int array::get_value_id(const std::string& key) const
{
const auto string_value = game::SL_GetString(key.data(), 0);
const auto variable_id = game::FindVariable(this->id_, string_value);
if (!variable_id)
{
return game::GetNewVariable(this->id_, string_value);
}
return variable_id;
}
unsigned int array::get_value_id(const unsigned int index) const
{
const auto variable_id = game::FindVariable(this->id_, (index - 0x800000) & 0xFFFFFF);
if (!variable_id)
{
return game::GetNewArrayVariable(this->id_, index);
}
return variable_id;
}
entity array::get_raw() const
{
return entity(this->id_);
}
}

View File

@ -0,0 +1,87 @@
#pragma once
#include "game/game.hpp"
#include "script_value.hpp"
namespace scripting
{
class array_value : public script_value
{
public:
array_value(unsigned int, unsigned int);
void operator=(const script_value&);
private:
unsigned int id_;
unsigned int parent_id_;
};
class array final
{
public:
array();
array(const unsigned int);
array(std::vector<script_value>);
array(std::unordered_map<std::string, script_value>);
array(const array& other);
array(array&& other) noexcept;
~array();
array& operator=(const array& other);
array& operator=(array&& other) noexcept;
std::vector<script_value> get_keys() const;
unsigned int size() const;
unsigned int push(script_value) const;
void erase(const unsigned int) const;
void erase(const std::string&) const;
script_value pop() const;
script_value get(const script_value&) const;
script_value get(const std::string&) const;
script_value get(const unsigned int) const;
void set(const script_value&, const script_value&) const;
void set(const std::string&, const script_value&) const;
void set(const unsigned int, const script_value&) const;
unsigned int get_entity_id() const;
unsigned int get_value_id(const std::string&) const;
unsigned int get_value_id(const unsigned int) const;
entity get_raw() const;
array_value operator[](const int index) const
{
return {this->id_, this->get_value_id(index)};
}
array_value operator[](const std::string& key) const
{
return {this->id_, this->get_value_id(key)};
}
template <typename I = int, typename S = std::string>
array_value operator[](const script_value& key) const
{
if (key.is<I>())
{
return { this->id_, this->get_value_id(key.as<I>()) };
}
if (key.is<S>())
{
return { this->id_, this->get_value_id(key.as<S>()) };
}
}
private:
void add() const;
void release() const;
unsigned int id_;
};
}

View File

@ -155,8 +155,7 @@ namespace scripting
return get_return_value();
}
script_value call_script_function(const entity& entity, const std::string& filename,
const std::string& function, const std::vector<script_value>& arguments)
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())
{
@ -164,14 +163,18 @@ namespace scripting
};
const auto functions = scripting::script_function_table[filename];
if (functions.find(function) == functions.end())
{
throw std::runtime_error("Function '" + function + "' in file '" + filename + "' not found");
}
const auto pos = functions.at(function);
return 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);
}
@ -266,7 +269,26 @@ namespace scripting
{
return get_custom_field(entity, field);
}
}
return {};
unsigned int make_array()
{
unsigned int index = 0;
const auto variable = game::AllocVariable(&index);
variable->w.type = game::SCRIPT_ARRAY;
variable->u.f.prev = 0;
variable->u.f.next = 0;
return index;
}
unsigned int make_object()
{
unsigned int index = 0;
const auto variable = game::AllocVariable(&index);
variable->w.type = game::SCRIPT_STRUCT;
variable->u.f.prev = 0;
return index;
}
}

View File

@ -1,6 +1,8 @@
#pragma once
#include "game/game.hpp"
#include "entity.hpp"
#include "array.hpp"
#include "function.hpp"
#include "script_value.hpp"
namespace scripting
@ -34,4 +36,7 @@ namespace scripting
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);
unsigned int make_array();
unsigned int make_object();
}

View File

@ -0,0 +1,30 @@
#include <stdinc.hpp>
#include "function.hpp"
#include "execution.hpp"
namespace scripting
{
function::function(const char* pos)
: pos_(pos)
{
}
script_value function::get_raw() const
{
game::VariableValue value;
value.type = game::SCRIPT_FUNCTION;
value.u.codePosValue = this->pos_;
return value;
}
const char* function::get_pos() const
{
return this->pos_;
}
script_value function::call(const entity& self, std::vector<script_value> arguments) const
{
return exec_ent_thread(self, this->pos_, arguments);
}
}

View File

@ -0,0 +1,34 @@
#pragma once
#include "entity.hpp"
#include "script_value.hpp"
namespace scripting
{
class function
{
public:
function(const char*);
script_value get_raw() const;
const char* get_pos() const;
script_value call(const entity& self, std::vector<script_value> arguments) const;
script_value operator()(const entity& self, std::vector<script_value> arguments) const
{
return this->call(self, arguments);
}
script_value operator()(std::vector<script_value> arguments) const
{
return this->call(*game::levelEntityId, arguments);
}
script_value operator()() const
{
return this->call(*game::levelEntityId, {});
}
private:
const char* pos_;
};
}

File diff suppressed because it is too large Load Diff

View File

@ -7,51 +7,20 @@ namespace scripting
{
namespace
{
std::unordered_map<std::string, unsigned> lowercase_map(
const std::unordered_map<std::string, unsigned>& old_map)
{
std::unordered_map<std::string, unsigned> new_map{};
for (auto& entry : old_map)
{
new_map[utils::string::to_lower(entry.first)] = entry.second;
}
return new_map;
}
const std::unordered_map<std::string, unsigned>& get_methods()
{
static auto methods = lowercase_map(method_map);
return methods;
}
const std::unordered_map<std::string, unsigned>& get_functions()
{
static auto function = lowercase_map(function_map);
return function;
}
int find_function_index(const std::string& name, const bool prefer_global)
int find_function_index(const std::string& name, [[maybe_unused]] const bool prefer_global)
{
const auto target = utils::string::to_lower(name);
auto const& first = (*game::plutonium::gsc_ctx)->func_map();
auto const& second = (*game::plutonium::gsc_ctx)->meth_map();
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())
if (const auto itr = first.find(name); itr != first.end())
{
return function_entry->second;
return static_cast<int>(itr->second);
}
function_entry = secondary_map.find(target);
if (function_entry != secondary_map.end())
if (const auto itr = second.find(name); itr != second.end())
{
return function_entry->second;
return static_cast<int>(itr->second);
}
return -1;
@ -59,34 +28,40 @@ namespace scripting
script_function get_function_by_index(const unsigned index)
{
static const auto function_table = 0x1D6EB34;
static const auto method_table = 0x1D4F258;
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];
return reinterpret_cast<script_function*>(method_table)[index - 0x8000];
}
}
std::string find_token(unsigned int id)
{
return (*game::plutonium::gsc_ctx)->token_name(id);
}
std::string find_file(unsigned int id)
{
return find_token(id);
}
int find_token_id(const std::string& name)
{
const auto result = token_map.find(name);
if (result != token_map.end())
{
return result->second;
}
return -1;
return (*game::plutonium::gsc_ctx)->token_id(name);
}
script_function find_function(const std::string& name, const bool prefer_global)
{
const auto index = find_function_index(name, prefer_global);
if (index < 0) return nullptr;
if (index < 0)
{
return nullptr;
}
return get_function_by_index(index);
}

View File

@ -3,13 +3,10 @@
namespace scripting
{
extern std::unordered_map<std::string, unsigned> method_map;
extern std::unordered_map<std::string, unsigned> function_map;
extern std::unordered_map<std::string, unsigned> token_map;
extern std::unordered_map<unsigned, std::string> file_list;
using script_function = void(*)(game::scr_entref_t);
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);
}

View File

@ -25,7 +25,7 @@ namespace scripting::safe_execution
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]))
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level], 0, 0, 0))
{
*game::g_script_error_level -= 1;
return false;
@ -39,7 +39,7 @@ namespace scripting::safe_execution
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]))
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level], 0, 0, 0))
{
*game::g_script_error_level -= 1;
return false;
@ -54,7 +54,7 @@ namespace scripting::safe_execution
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]))
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level], 0, 0, 0))
{
value->type = game::SCRIPT_NONE;
value->u.intValue = 0;

View File

@ -1,7 +1,8 @@
#include <stdinc.hpp>
#include "script_value.hpp"
#include "entity.hpp"
#include "array.hpp"
#include "function.hpp"
namespace scripting
{
@ -14,6 +15,11 @@ namespace scripting
{
}
script_value::script_value(const value_wrap& value)
: value_(value.get_raw())
{
}
script_value::script_value(void* value)
{
game::VariableValue variable{};
@ -102,6 +108,24 @@ namespace scripting
this->value_ = variable;
}
script_value::script_value(const array& value)
{
game::VariableValue variable{};
variable.type = game::SCRIPT_OBJECT;
variable.u.pointerValue = value.get_entity_id();
this->value_ = variable;
}
script_value::script_value(const function& value)
{
game::VariableValue variable{};
variable.type = game::SCRIPT_OBJECT;
variable.u.codePosValue = value.get_pos();
this->value_ = variable;
}
/***************************************************************
* Integer
**************************************************************/
@ -219,7 +243,7 @@ namespace scripting
**************************************************************/
template <>
bool script_value::is<std::vector<script_value>>() const
bool script_value::is<array>() const
{
if (this->get_raw().type != game::SCRIPT_OBJECT)
{
@ -232,6 +256,12 @@ namespace scripting
return type == game::SCRIPT_ARRAY;
}
template <>
array script_value::get() const
{
return array(this->get_raw().u.uintValue);
}
/***************************************************************
* Struct
**************************************************************/
@ -255,11 +285,17 @@ namespace scripting
**************************************************************/
template <>
bool script_value::is<std::function<void()>>() const
bool script_value::is<function>() const
{
return this->get_raw().type == game::SCRIPT_FUNCTION;
}
template <>
function script_value::get() const
{
return function(this->get_raw().u.codePosValue);
}
/***************************************************************
* Vector
**************************************************************/
@ -284,4 +320,10 @@ namespace scripting
{
return this->value_.get();
}
value_wrap::value_wrap(const scripting::script_value& value, int argument_index)
: value_(value)
, argument_index_(argument_index)
{
}
}

View File

@ -6,12 +6,102 @@
namespace scripting
{
class entity;
class array;
class function;
class value_wrap;
namespace
{
std::unordered_map<int, std::string> typenames =
{
{0, "undefined"},
{1, "object"},
{2, "string"},
{3, "localized string"},
{4, "vector"},
{5, "float"},
{6, "integer"},
{7, "codepos"},
{8, "precodepos"},
{9, "function"},
{10, "builtin function"},
{11, "builtin method"},
{12, "stack"},
{13, "animation"},
{14, "pre animation"},
{15, "thread"},
{16, "thread"},
{17, "thread"},
{18, "thread"},
{19, "struct"},
{20, "removed entity"},
{21, "entity"},
{22, "array"},
{23, "removed thread"},
{24, "count"},
{25, "<free>"},
{26, "thread list"},
{27, "endon list"},
};
std::string get_typename(const game::VariableValue& value)
{
if (value.type == game::SCRIPT_OBJECT)
{
const auto type = game::scr_VarGlob->objectVariableValue[value.u.uintValue].w.type;
return typenames[type];
}
else
{
return typenames[value.type];
}
}
template <typename T, typename A = array>
std::string get_c_typename()
{
auto& info = typeid(T);
if (info == typeid(std::string))
{
return "string";
}
if (info == typeid(const char*))
{
return "string";
}
if (info == typeid(entity))
{
return "entity";
}
if (info == typeid(array))
{
return "array";
}
if (info == typeid(function))
{
return "function";
}
if (info == typeid(vector))
{
return "vector";
}
return info.name();
}
}
class script_value
{
public:
script_value() = default;
script_value(const game::VariableValue& value);
script_value(const value_wrap& value);
script_value(void* value);
@ -29,6 +119,10 @@ namespace scripting
script_value(const vector& value);
script_value(const array& value);
script_value(const function& value);
template <typename T>
bool is() const;
@ -37,25 +131,23 @@ namespace scripting
{
if (!this->is<T>())
{
throw std::runtime_error("Invalid type");
const auto type = get_typename(this->get_raw());
const auto c_type = get_c_typename<T>();
throw std::runtime_error(std::string("has type '" + type + "' but should be '" + c_type + "'"));
}
return get<T>();
}
template <typename T>
template <typename T, typename I = int>
T* as_ptr()
{
if (!this->is<int>())
{
throw std::runtime_error("Invalid type");
}
const auto value = this->get<int>();
const auto value = this->as<I>();
if (!value)
{
throw std::runtime_error("Null pointer");
throw std::runtime_error("is null");
}
return reinterpret_cast<T*>(value);
@ -63,10 +155,55 @@ namespace scripting
const game::VariableValue& get_raw() const;
variable_value value_{};
private:
template <typename T>
T get() const;
};
variable_value value_{};
class value_wrap
{
public:
value_wrap(const scripting::script_value& value, int argument_index);
template <typename T>
T as() const
{
try
{
return this->value_.as<T>();
}
catch (const std::exception& e)
{
throw std::runtime_error(utils::string::va("parameter %d %s", this->argument_index_, e.what()));
}
}
template <typename T, typename I = int>
T* as_ptr()
{
try
{
return this->value_.as_ptr<T>();
}
catch (const std::exception& e)
{
throw std::runtime_error(utils::string::va("parameter %d %s", this->argument_index_, e.what()));
}
}
template <typename T>
T is() const
{
return this->value_.is<T>();
}
const game::VariableValue& get_raw() const
{
return this->value_.get_raw();
}
int argument_index_{};
scripting::script_value value_;
};
}

View File

@ -26,20 +26,35 @@ namespace game
const char** argv[8];
};
enum netsrc_t
{
NS_CLIENT1 = 0x0,
NS_CLIENT2 = 0x1,
NS_CLIENT3 = 0x2,
NS_CLIENT4 = 0x3,
NS_MAXCLIENTS = 0x4,
NS_SERVER = 0x4,
NS_PACKET = 0x5,
NS_INVALID_NETSRC = 0x6
};
struct msg_t
{
int overflowed;
int readOnly;
char* data;
char* splitData;
unsigned char* data;
unsigned char* splitData;
int maxsize;
int cursize;
int splitSize;
int readcount;
int bit;
int lastEntityRef;
netsrc_t targetLocalNetID;
};
static_assert(sizeof(msg_t) == 0x2C);
struct XZoneInfo
{
const char* name;
@ -303,8 +318,112 @@ namespace game
dvar_t* hashNext;
};
struct playerState_s
{
char __pad0[0x4EC];
unsigned int perks[0x2];
unsigned int perkSlots[0x9];
char __pad1[0x2DE8];
};
struct gclient_s
{
playerState_s ps;
char __pad0[0x2CC];
int flags;
};
struct gentity_s
{
int entnum;
char __pad0[0x154];
gclient_s* client;
char __pad1[0x28];
int flags;
char __pad2[0xEC];
};
enum netadrtype_t
{
NA_BOT = 0x0,
NA_BAD = 0x1,
NA_LOOPBACK = 0x2,
NA_BROADCAST = 0x3,
NA_IP = 0x4
};
struct netadr_s
{
netadrtype_t type;
unsigned char ip[4];
unsigned __int16 port;
unsigned char ipx[10];
unsigned int addrHandleIndex;
};
static_assert(sizeof(netadr_s) == 24);
struct netchan_t
{
int outgoingSequence;
netsrc_t sock;
int dropped;
int incomingSequence;
netadr_s remoteAddress;
int qport;
int fragmentSequence;
int fragmentLength;
unsigned char* fragmentBuffer;
int fragmentBufferSize;
int unsentFragments;
int unsentFragmentStart;
int unsentLength;
unsigned char* unsentBuffer;
int unsentBufferSize;
unsigned char __pad0[0x5E0];
};
static_assert(sizeof(netchan_t) == 0x630);
enum clientState_t
{
CS_FREE = 0,
CS_ZOMBIE = 1,
CS_RECONNECTING = 2,
CS_CONNECTED = 3,
CS_CLIENTLOADING = 4,
CS_ACTIVE = 5
};
struct clientHeader_t
{
clientState_t state; // 0
int sendAsActive; // 4
int deltaMessage; // 8
int rateDealyed; // 12
int hasAckedBaselineData; // 16
int hugeSnapshotSent; // 20
netchan_t netchan; // 24
vec3_t predictedOrigin;
int predictedOriginServerTime;
int migrationState;
vec3_t predictedVehicleOrigin;
int predictedVehicleServerTime;
};
static_assert(sizeof(clientHeader_t) == 0x66C);
struct client_s
{
clientHeader_t header;
const char* dropReason;
char userinfo[1024];
char __pad0[0x41242];
unsigned __int16 scriptId; // 269490
int bIsTestClient; // 269492
int serverId; // 269496
char __pad1[0x369DC];
};
static_assert(sizeof(client_s) == 0x78698);
}

View File

@ -16,6 +16,7 @@ namespace game
WEAK symbol<void(unsigned int weapon, bool isAlternate, char* output, unsigned int maxStringLen)> BG_GetWeaponNameComplete{0x42F760};
WEAK symbol<void(int client)> ClientUserinfoChanged{0x4FADB0};
WEAK symbol<const char*(int index)> ConcatArgs{0x502150};
WEAK symbol<void(int localClientNum, const char* text)> Cbuf_AddText{0x545680};
WEAK symbol<void(const char* cmdName, void(), cmd_function_t* allocedCmd)> Cmd_AddCommandInternal{0x545DF0};
@ -31,7 +32,9 @@ namespace game
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> FindObject{0x565BD0};
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> GetVariable{0x5663E0};
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> GetNewVariable{0x566390};
WEAK symbol<unsigned int(unsigned int parentId, unsigned int unsignedValue)> GetNewArrayVariable{0x5668C0};
WEAK symbol<void(unsigned int parentId, unsigned int id, VariableValue* value)> SetNewVariableValue{0x5658D0};
WEAK symbol<void(unsigned int parentId, unsigned int index)> RemoveVariableValue{0x566500};
WEAK symbol<const float* (const float* v)> Scr_AllocVector{0x565680};
WEAK symbol<void()> Scr_ClearOutParams{0x569010};
@ -46,18 +49,21 @@ namespace game
WEAK symbol<unsigned int(unsigned int threadId)> Scr_GetSelf{0x5655E0};
WEAK symbol<void()> Scr_MakeArray{0x56ADE0};
WEAK symbol<void(unsigned int stringValue)> Scr_AddArrayStringIndexed{0x56AE70};
WEAK symbol<void(unsigned int classnum, unsigned int name, unsigned int canonicalString, unsigned int offset)> Scr_AddClassField{0x567CD0};
WEAK symbol<unsigned int(const char* str, unsigned int user)> SL_GetString{0x5649E0};
WEAK symbol<unsigned int(const char* str)> SL_GetCanonicalString{0x5619A0};
WEAK symbol<const char*(unsigned int stringValue)> SL_ConvertToString{0x564270};
WEAK symbol<void(int clientNum, int type, const char* command)> SV_GameSendServerCommand{0x573220};
WEAK symbol<void(int arg, char* buffer, int bufferLength)> SV_Cmd_ArgvBuffer{0x5459F0};
WEAK symbol<void(client_s* drop, const char* reason, bool tellThem)> SV_DropClient{0x570980};
WEAK symbol<void(unsigned int notifyListOwnerId, unsigned int stringValue, VariableValue* top)> VM_Notify{0x569720};
WEAK symbol<unsigned int(unsigned int localId, const char* pos, unsigned int paramcount)> VM_Execute{0x56DFE0};
WEAK symbol<void* (jmp_buf* Buf, int Value)> longjmp{0x7363BC};
WEAK symbol<int(jmp_buf* Buf)> _setjmp{0x734CF8};
WEAK symbol<int(jmp_buf* Buf, int a2, int a3, int a4)> _setjmp{0x734CF8};
// Variables
@ -71,13 +77,18 @@ namespace game
WEAK symbol<scr_classStruct_t*> g_classMap{0x8B4300};
WEAK symbol<gentity_s> g_entities{0x0};
WEAK symbol<gentity_s> g_entities{0x1A66E28};
WEAK symbol<unsigned int> levelEntityId{0x208E1A4};
WEAK symbol<dvar_t> sv_maxclients{0x1BA0E4C};
WEAK symbol<int> svs_clientCount{0x4B5CF8C};
WEAK symbol<client_s> svs_clients{0x4B5CF90};
namespace plutonium
{
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> function_map_rev{0x20589F68};
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> method_map_rev{0x20589F88};
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> token_map_rev{0x20589FC8};
WEAK symbol<std::unique_ptr<xsk::gsc::iw5_pc::context>> gsc_ctx{0};
WEAK symbol<int(const char* fmt, ...)> printf{0};
WEAK symbol<void*> function_table{0};
WEAK symbol<void*> method_table{0};
}
}

View File

@ -2,10 +2,14 @@
#pragma warning(disable: 4018)
#pragma warning(disable: 4146)
#pragma warning(disable: 4129)
#pragma warning(disable: 4244)
#pragma warning(disable: 4267)
#pragma warning(disable: 4996)
#pragma warning(disable: 26812)
#include <xsk/gsc/engine/iw5_pc.hpp>
#define DLL_EXPORT extern "C" __declspec(dllexport)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@ -25,17 +29,24 @@
#include <filesystem>
#include <map>
#include <csetjmp>
#include <atlcomcli.h>
#include <Psapi.h>
#pragma comment(lib, "urlmon.lib")
using namespace std::literals;
#include <gsl/gsl>
#include <MinHook.h>
#include "utils/memory.hpp"
#include "utils/string.hpp"
#include "utils/hook.hpp"
#include "utils/concurrent_list.hpp"
#include "utils/io.hpp"
#include "utils/concurrency.hpp"
#include "utils/http.hpp"
#include "game/structs.hpp"
#include "game/game.hpp"

46
src/utils/concurrency.hpp Normal file
View File

@ -0,0 +1,46 @@
#pragma once
#include <mutex>
namespace utils::concurrency
{
template <typename T, typename MutexType = std::mutex>
class container
{
public:
template <typename R = void, typename F>
R access(F&& accessor) const
{
std::lock_guard<MutexType> _{mutex_};
return accessor(object_);
}
template <typename R = void, typename F>
R access(F&& accessor)
{
std::lock_guard<MutexType> _{mutex_};
return accessor(object_);
}
template <typename R = void, typename F>
R access_with_lock(F&& accessor) const
{
std::unique_lock<MutexType> lock{mutex_};
return accessor(object_, lock);
}
template <typename R = void, typename F>
R access_with_lock(F&& accessor)
{
std::unique_lock<MutexType> lock{mutex_};
return accessor(object_, lock);
}
T& get_raw() { return object_; }
const T& get_raw() const { return object_; }
private:
mutable MutexType mutex_{};
T object_{};
};
}

View File

@ -4,6 +4,48 @@
namespace utils::hook
{
// open-iw5
void signature::process()
{
if (this->signatures_.empty()) return;
const auto start = static_cast<char*>(this->start_);
const unsigned int sig_count = this->signatures_.size();
const auto containers = this->signatures_.data();
for (size_t i = 0; i < this->length_; ++i)
{
const auto address = start + i;
for (unsigned int k = 0; k < sig_count; ++k)
{
const auto container = &containers[k];
unsigned int j;
for (j = 0; j < static_cast<unsigned int>(container->mask.size()); ++j)
{
if (container->mask[j] != '?' && container->signature[j] != address[j])
{
break;
}
}
if (j == container->mask.size())
{
container->callback(address);
}
}
}
}
void signature::add(const container& container)
{
signatures_.push_back(container);
}
namespace
{
[[maybe_unused]] class _

View File

@ -4,6 +4,37 @@
namespace utils::hook
{
class signature final
{
public:
struct container final
{
std::string signature;
std::string mask;
std::function<void(char*)> callback;
};
signature(void* start, const size_t length) : start_(start), length_(length)
{
}
signature(const DWORD start, const size_t length) : signature(reinterpret_cast<void*>(start), length)
{
}
signature() : signature(0x400000, 0x800000)
{
}
void process();
void add(const container& container);
private:
void* start_;
size_t length_;
std::vector<container> signatures_;
};
class detour
{
public:

47
src/utils/http.cpp Normal file
View File

@ -0,0 +1,47 @@
#include <stdinc.hpp>
#include "http.hpp"
namespace utils::http
{
std::optional<std::string> get_data(const std::string& url)
{
CComPtr<IStream> stream;
if (FAILED(URLOpenBlockingStreamA(nullptr, url.data(), &stream, 0, nullptr)))
{
return {};
}
char buffer[0x1000];
std::string result;
HRESULT status{};
do
{
DWORD bytes_read = 0;
status = stream->Read(buffer, sizeof(buffer), &bytes_read);
if (bytes_read > 0)
{
result.append(buffer, bytes_read);
}
}
while (SUCCEEDED(status) && status != S_FALSE);
if (FAILED(status))
{
return {};
}
return {result};
}
std::future<std::optional<std::string>> get_data_async(const std::string& url)
{
return std::async(std::launch::async, [url]()
{
return get_data(url);
});
}
}

11
src/utils/http.hpp Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include <string>
#include <optional>
#include <future>
namespace utils::http
{
std::optional<std::string> get_data(const std::string& url);
std::future<std::optional<std::string>> get_data_async(const std::string& url);
}

View File

@ -1,8 +1,14 @@
#include <stdinc.hpp>
#include <fstream>
#include "io.hpp"
namespace utils::io
{
bool remove_file(const std::string& file)
{
return DeleteFileA(file.data()) == TRUE;
}
bool file_exists(const std::string& file)
{
return std::ifstream(file).good();

View File

@ -6,6 +6,7 @@
namespace utils::io
{
bool remove_file(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 read_file(const std::string& file, std::string* data);

BIN
tools/premake5.exe Normal file

Binary file not shown.

Binary file not shown.