@amxts/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +162 -0
  3. package/README.ru.md +162 -0
  4. package/amxmodx/base/include/amxconst.inc +594 -0
  5. package/amxmodx/base/include/amxmisc.inc +902 -0
  6. package/amxmodx/base/include/amxmodx.inc +3447 -0
  7. package/amxmodx/base/include/amxmodx_version.inc +20 -0
  8. package/amxmodx/base/include/cellarray.inc +525 -0
  9. package/amxmodx/base/include/cellstack.inc +166 -0
  10. package/amxmodx/base/include/celltrie.inc +412 -0
  11. package/amxmodx/base/include/core.inc +202 -0
  12. package/amxmodx/base/include/csstats.inc +298 -0
  13. package/amxmodx/base/include/csstats_const.inc +29 -0
  14. package/amxmodx/base/include/cstrike.inc +1287 -0
  15. package/amxmodx/base/include/cstrike_const.inc +521 -0
  16. package/amxmodx/base/include/csx.inc +259 -0
  17. package/amxmodx/base/include/cvars.inc +547 -0
  18. package/amxmodx/base/include/datapack.inc +161 -0
  19. package/amxmodx/base/include/dbi.inc +154 -0
  20. package/amxmodx/base/include/dodconst.inc +152 -0
  21. package/amxmodx/base/include/dodfun.inc +152 -0
  22. package/amxmodx/base/include/dodstats.inc +69 -0
  23. package/amxmodx/base/include/dodx.inc +161 -0
  24. package/amxmodx/base/include/engine.inc +1343 -0
  25. package/amxmodx/base/include/engine_const.inc +310 -0
  26. package/amxmodx/base/include/engine_stocks.inc +248 -0
  27. package/amxmodx/base/include/esf.inc +70 -0
  28. package/amxmodx/base/include/esf_const.inc +74 -0
  29. package/amxmodx/base/include/fakemeta.inc +1127 -0
  30. package/amxmodx/base/include/fakemeta_const.inc +793 -0
  31. package/amxmodx/base/include/fakemeta_stocks.inc +395 -0
  32. package/amxmodx/base/include/fakemeta_util.inc +882 -0
  33. package/amxmodx/base/include/file.inc +666 -0
  34. package/amxmodx/base/include/float.inc +422 -0
  35. package/amxmodx/base/include/fun.inc +333 -0
  36. package/amxmodx/base/include/gameconfig.inc +93 -0
  37. package/amxmodx/base/include/geoip.inc +264 -0
  38. package/amxmodx/base/include/ham_const.inc +4352 -0
  39. package/amxmodx/base/include/hamsandwich.inc +439 -0
  40. package/amxmodx/base/include/hlsdk_const.inc +808 -0
  41. package/amxmodx/base/include/json.inc +777 -0
  42. package/amxmodx/base/include/lang.inc +119 -0
  43. package/amxmodx/base/include/message_const.inc +1130 -0
  44. package/amxmodx/base/include/message_stocks.inc +161 -0
  45. package/amxmodx/base/include/messages.inc +604 -0
  46. package/amxmodx/base/include/newmenus.inc +387 -0
  47. package/amxmodx/base/include/ns.inc +754 -0
  48. package/amxmodx/base/include/ns_const.inc +196 -0
  49. package/amxmodx/base/include/nvault.inc +154 -0
  50. package/amxmodx/base/include/regex.inc +348 -0
  51. package/amxmodx/base/include/sockets.inc +183 -0
  52. package/amxmodx/base/include/sorting.inc +107 -0
  53. package/amxmodx/base/include/sqlx.inc +582 -0
  54. package/amxmodx/base/include/string.inc +786 -0
  55. package/amxmodx/base/include/string_const.inc +156 -0
  56. package/amxmodx/base/include/string_stocks.inc +325 -0
  57. package/amxmodx/base/include/textparse_ini.inc +214 -0
  58. package/amxmodx/base/include/textparse_smc.inc +261 -0
  59. package/amxmodx/base/include/tfcconst.inc +84 -0
  60. package/amxmodx/base/include/tfcstats.inc +62 -0
  61. package/amxmodx/base/include/tfcx.inc +148 -0
  62. package/amxmodx/base/include/time.inc +118 -0
  63. package/amxmodx/base/include/tsconst.inc +154 -0
  64. package/amxmodx/base/include/tsfun.inc +198 -0
  65. package/amxmodx/base/include/tsstats.inc +65 -0
  66. package/amxmodx/base/include/tsx.inc +88 -0
  67. package/amxmodx/base/include/vault.inc +60 -0
  68. package/amxmodx/base/include/vector.inc +131 -0
  69. package/amxmodx/base/include/xs.inc +1570 -0
  70. package/as/amxts.d.ts +153 -0
  71. package/as/constants.ts +4730 -0
  72. package/as/effects.ts +1449 -0
  73. package/as/entities.ts +5482 -0
  74. package/as/events.ts +3054 -0
  75. package/as/facade.ts +4639 -0
  76. package/as/flags.ts +299 -0
  77. package/as/fs.ts +287 -0
  78. package/as/hooks.ts +18536 -0
  79. package/as/kit.ts +25 -0
  80. package/as/lib/check.ts +86 -0
  81. package/as/modules/http.ts +184 -0
  82. package/as/natives.ts +11845 -0
  83. package/as/os.ts +30 -0
  84. package/as/promise.ts +1392 -0
  85. package/as/promise.types.d.ts +82 -0
  86. package/as/remote.ts +288 -0
  87. package/as/tsconfig.json +22 -0
  88. package/as/vector.ts +65 -0
  89. package/bin/amxts.mjs +10 -0
  90. package/includes/menu_core.inc +355 -0
  91. package/includes/order.txt +54 -0
  92. package/includes/sources.json +27 -0
  93. package/includes/universal_config.inc +355 -0
  94. package/lint/oxlint-plugin.mjs +77 -0
  95. package/node_modules/assemblyscript/LICENSE +201 -0
  96. package/node_modules/assemblyscript/NOTICE +93 -0
  97. package/node_modules/assemblyscript/package.json +63 -0
  98. package/node_modules/assemblyscript/std/README.md +6 -0
  99. package/node_modules/assemblyscript/std/assembly/array.ts +526 -0
  100. package/node_modules/assemblyscript/std/assembly/arraybuffer.ts +77 -0
  101. package/node_modules/assemblyscript/std/assembly/atomics.ts +127 -0
  102. package/node_modules/assemblyscript/std/assembly/bindings/asyncify.ts +16 -0
  103. package/node_modules/assemblyscript/std/assembly/bindings/dom.ts +291 -0
  104. package/node_modules/assemblyscript/std/assembly/bindings/node.ts +6 -0
  105. package/node_modules/assemblyscript/std/assembly/builtins.ts +2631 -0
  106. package/node_modules/assemblyscript/std/assembly/compat.ts +2 -0
  107. package/node_modules/assemblyscript/std/assembly/console.ts +42 -0
  108. package/node_modules/assemblyscript/std/assembly/crypto.ts +9 -0
  109. package/node_modules/assemblyscript/std/assembly/dataview.ts +181 -0
  110. package/node_modules/assemblyscript/std/assembly/date.ts +373 -0
  111. package/node_modules/assemblyscript/std/assembly/diagnostics.ts +11 -0
  112. package/node_modules/assemblyscript/std/assembly/error.ts +44 -0
  113. package/node_modules/assemblyscript/std/assembly/function.ts +38 -0
  114. package/node_modules/assemblyscript/std/assembly/index.d.ts +2822 -0
  115. package/node_modules/assemblyscript/std/assembly/iterator.ts +35 -0
  116. package/node_modules/assemblyscript/std/assembly/map.ts +260 -0
  117. package/node_modules/assemblyscript/std/assembly/math.ts +3289 -0
  118. package/node_modules/assemblyscript/std/assembly/memory.ts +123 -0
  119. package/node_modules/assemblyscript/std/assembly/number.ts +388 -0
  120. package/node_modules/assemblyscript/std/assembly/object.ts +36 -0
  121. package/node_modules/assemblyscript/std/assembly/performance.ts +9 -0
  122. package/node_modules/assemblyscript/std/assembly/polyfills.ts +27 -0
  123. package/node_modules/assemblyscript/std/assembly/process.ts +50 -0
  124. package/node_modules/assemblyscript/std/assembly/reference.ts +48 -0
  125. package/node_modules/assemblyscript/std/assembly/regexp.ts +12 -0
  126. package/node_modules/assemblyscript/std/assembly/rt/README.md +83 -0
  127. package/node_modules/assemblyscript/std/assembly/rt/common.ts +81 -0
  128. package/node_modules/assemblyscript/std/assembly/rt/index-incremental.ts +2 -0
  129. package/node_modules/assemblyscript/std/assembly/rt/index-minimal.ts +2 -0
  130. package/node_modules/assemblyscript/std/assembly/rt/index-stub.ts +1 -0
  131. package/node_modules/assemblyscript/std/assembly/rt/index.d.ts +37 -0
  132. package/node_modules/assemblyscript/std/assembly/rt/itcms.ts +419 -0
  133. package/node_modules/assemblyscript/std/assembly/rt/rtrace.ts +15 -0
  134. package/node_modules/assemblyscript/std/assembly/rt/stub.ts +133 -0
  135. package/node_modules/assemblyscript/std/assembly/rt/tcms.ts +254 -0
  136. package/node_modules/assemblyscript/std/assembly/rt/tlsf.ts +592 -0
  137. package/node_modules/assemblyscript/std/assembly/rt.ts +87 -0
  138. package/node_modules/assemblyscript/std/assembly/set.ts +220 -0
  139. package/node_modules/assemblyscript/std/assembly/shared/feature.ts +65 -0
  140. package/node_modules/assemblyscript/std/assembly/shared/runtime.ts +11 -0
  141. package/node_modules/assemblyscript/std/assembly/shared/target.ts +11 -0
  142. package/node_modules/assemblyscript/std/assembly/shared/tsconfig.json +11 -0
  143. package/node_modules/assemblyscript/std/assembly/shared/typeinfo.ts +72 -0
  144. package/node_modules/assemblyscript/std/assembly/staticarray.ts +401 -0
  145. package/node_modules/assemblyscript/std/assembly/string.ts +847 -0
  146. package/node_modules/assemblyscript/std/assembly/symbol.ts +114 -0
  147. package/node_modules/assemblyscript/std/assembly/table.ts +16 -0
  148. package/node_modules/assemblyscript/std/assembly/tsconfig.json +6 -0
  149. package/node_modules/assemblyscript/std/assembly/typedarray.ts +1945 -0
  150. package/node_modules/assemblyscript/std/assembly/uri.ts +17 -0
  151. package/node_modules/assemblyscript/std/assembly/util/bytes.ts +107 -0
  152. package/node_modules/assemblyscript/std/assembly/util/casemap.ts +497 -0
  153. package/node_modules/assemblyscript/std/assembly/util/error.ts +54 -0
  154. package/node_modules/assemblyscript/std/assembly/util/hash.ts +117 -0
  155. package/node_modules/assemblyscript/std/assembly/util/math.ts +1922 -0
  156. package/node_modules/assemblyscript/std/assembly/util/memory.ts +290 -0
  157. package/node_modules/assemblyscript/std/assembly/util/number.ts +873 -0
  158. package/node_modules/assemblyscript/std/assembly/util/sort.ts +313 -0
  159. package/node_modules/assemblyscript/std/assembly/util/string.ts +1202 -0
  160. package/node_modules/assemblyscript/std/assembly/util/uri.ts +275 -0
  161. package/node_modules/assemblyscript/std/assembly/vector.ts +4 -0
  162. package/node_modules/assemblyscript/std/assembly.json +16 -0
  163. package/node_modules/assemblyscript/std/portable/index.d.ts +462 -0
  164. package/node_modules/assemblyscript/std/portable/index.js +416 -0
  165. package/node_modules/assemblyscript/std/portable.json +11 -0
  166. package/node_modules/assemblyscript/std/types/assembly/index.d.ts +1 -0
  167. package/node_modules/assemblyscript/std/types/assembly/package.json +3 -0
  168. package/node_modules/assemblyscript/std/types/portable/index.d.ts +1 -0
  169. package/node_modules/assemblyscript/std/types/portable/package.json +3 -0
  170. package/node_modules/assemblyscript/tsconfig-base.json +13 -0
  171. package/package.json +112 -0
  172. package/runtime/deps/assemblyscript/LICENSE +201 -0
  173. package/runtime/deps/assemblyscript/NOTICE +93 -0
  174. package/runtime/deps/assemblyscript/bin/asc.js +35 -0
  175. package/runtime/deps/assemblyscript/dist/asc.js +25035 -0
  176. package/runtime/deps/assemblyscript/dist/assemblyscript.js +337 -0
  177. package/runtime/deps/assemblyscript/node_modules/binaryen/LICENSE +201 -0
  178. package/runtime/deps/assemblyscript/node_modules/binaryen/index.js +28905 -0
  179. package/runtime/deps/assemblyscript/node_modules/binaryen/package.json +50 -0
  180. package/runtime/deps/assemblyscript/node_modules/long/LICENSE +202 -0
  181. package/runtime/deps/assemblyscript/node_modules/long/index.js +1581 -0
  182. package/runtime/deps/assemblyscript/node_modules/long/package.json +58 -0
  183. package/runtime/deps/assemblyscript/package.json +114 -0
  184. package/runtime/host/amxts.inc +85 -0
  185. package/runtime/licenses/AMXX-LICENSE.txt +34 -0
  186. package/runtime/licenses/AssemblyScript-LICENSE +201 -0
  187. package/runtime/licenses/AssemblyScript-NOTICE +93 -0
  188. package/runtime/licenses/Binaryen-LICENSE +201 -0
  189. package/runtime/licenses/Bun-LICENSE.md +84 -0
  190. package/runtime/licenses/GPL-3.0.txt +674 -0
  191. package/runtime/licenses/LLVM-LICENSE.TXT +279 -0
  192. package/runtime/licenses/README.md +25 -0
  193. package/runtime/licenses/WAMR-LICENSE +219 -0
  194. package/runtime/natives.txt +1095 -0
  195. package/runtime/patches/README.md +59 -0
  196. package/runtime/patches/assemblyscript-0.28.20-amxts.patch +14174 -0
  197. package/runtime/patches/wamr-2.4.5-amxts.patch +364 -0
  198. package/scripts/apply-docs.ts +508 -0
  199. package/scripts/asc.ts +27 -0
  200. package/scripts/auto-imports.ts +258 -0
  201. package/scripts/build-wasm.ts +595 -0
  202. package/scripts/check.ts +93 -0
  203. package/scripts/compile-cache.ts +179 -0
  204. package/scripts/compile.ts +401 -0
  205. package/scripts/docker-server.ts +73 -0
  206. package/scripts/docs/as/amxts.ts +210 -0
  207. package/scripts/docs/as/effects.ts +1684 -0
  208. package/scripts/docs/as/facade.ts +3302 -0
  209. package/scripts/docs/as/fs.ts +173 -0
  210. package/scripts/docs/as/lib/check.ts +68 -0
  211. package/scripts/docs/as/modules/http.ts +66 -0
  212. package/scripts/docs/as/os.ts +16 -0
  213. package/scripts/docs/as/promise.ts +132 -0
  214. package/scripts/docs/as/promise.types.ts +63 -0
  215. package/scripts/docs/as/vector.ts +48 -0
  216. package/scripts/docs/entities.ts +2338 -0
  217. package/scripts/docs/events.ts +245 -0
  218. package/scripts/docs/game.ts +497 -0
  219. package/scripts/docs/messages.ts +148 -0
  220. package/scripts/file-contents.ts +74 -0
  221. package/scripts/includes.ts +134 -0
  222. package/scripts/player-fields.ts +866 -0
  223. package/scripts/plugin-cache.ts +92 -0
  224. package/scripts/plugin-natives.ts +1157 -0
  225. package/scripts/prebuilt.ts +268 -0
  226. package/scripts/prepare.ts +134 -0
  227. package/scripts/project.ts +973 -0
  228. package/scripts/run.ts +28 -0
  229. package/scripts/shared-modules.ts +906 -0
  230. package/scripts/system.ts +33 -0
  231. package/scripts/tracked-fs.ts +115 -0
  232. package/scripts/typed-configs.ts +788 -0
  233. package/scripts/ui.ts +77 -0
  234. package/src/cli-api.mjs +175 -0
  235. package/src/parser/include-parser.ts +506 -0
  236. package/src/system.mjs +155 -0
  237. package/src/testing/compile-cache.ts +31 -0
  238. package/src/testing/compile.ts +222 -0
  239. package/src/testing/coroutines.ts +191 -0
  240. package/src/testing/index.ts +39 -0
  241. package/src/testing/kits.ts +55 -0
  242. package/src/testing/memory.ts +125 -0
  243. package/src/testing/natives.ts +925 -0
  244. package/src/testing/server.ts +1874 -0
  245. package/src/testing/setup.ts +63 -0
  246. package/src/testing/tables.ts +139 -0
  247. package/src/types.ts +51 -0
package/as/flags.ts ADDED
@@ -0,0 +1,299 @@
1
+ // GENERATED by scripts/generate-flags.ts — do not edit
2
+ // Source: as/constants.ts
3
+ //
4
+ // Flag families as string literal types, and FlagList - the array a plugin
5
+ // sees where Pawn has a bit mask.
6
+ import { get_entvar, set_entvar, get_member, set_member } from "./natives";
7
+
8
+
9
+ // ---------------------------------------------------------------- the list
10
+
11
+ /** A family's names and the bit each stands for, in the same order. */
12
+ export class FlagFamily {
13
+ constructor(public names: string[], public bits: i32[]) {}
14
+
15
+ bitOf(name: string): i32 {
16
+ const at = this.names.indexOf(name);
17
+ return at < 0 ? 0 : unchecked(this.bits[at]);
18
+ }
19
+
20
+ /** The names set in a mask. */
21
+ namesOf(mask: i32): string[] {
22
+ const list: string[] = [];
23
+ for (let i = 0; i < this.bits.length; i++) {
24
+ if ((mask & unchecked(this.bits[i])) != 0) list.push(unchecked(this.names[i]));
25
+ }
26
+ return list;
27
+ }
28
+
29
+ /** Every bit the family names, as one mask. */
30
+ get all(): i32 {
31
+ let mask = 0;
32
+ for (let i = 0; i < this.bits.length; i++) mask |= unchecked(this.bits[i]);
33
+ return mask;
34
+ }
35
+
36
+ /** A list of names as the mask Pawn wants. */
37
+ maskOf<T>(names: T[]): i32 {
38
+ let mask = 0;
39
+ for (let i = 0; i < names.length; i++) mask |= this.bitOf(<string>unchecked(names[i]));
40
+ return mask;
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Where a mask lives: an entvar, a member, a hookchain argument.
46
+ *
47
+ * A FlagList holds the entity and field it came from as one of these, and
48
+ * `push` goes back through it.
49
+ */
50
+ export abstract class FlagStore {
51
+ abstract read(): i32;
52
+ abstract write(mask: i32): void;
53
+ }
54
+
55
+ /** A mask in an entvar - var_flags, var_effects, var_button. */
56
+ export class EntvarFlags extends FlagStore {
57
+ constructor(private entity: i32, private field: i32) { super(); }
58
+ read(): i32 { return get_entvar(this.entity, this.field); }
59
+ write(mask: i32): void { set_entvar(this.entity, this.field, mask); }
60
+ }
61
+
62
+ /** A mask in a game member - m_iHideHUD. */
63
+ export class MemberFlags extends FlagStore {
64
+ constructor(private entity: i32, private field: i32) { super(); }
65
+ read(): i32 { return get_member(this.entity, this.field); }
66
+ write(mask: i32): void { set_member(this.entity, this.field, mask); }
67
+ }
68
+
69
+ /**
70
+ * The flags a mask holds, as an array of names.
71
+ *
72
+ * `push` sets the bit where the mask lives as well, so
73
+ * `player.hideHud.push("Money")` hides the money. Everything else is a plain
74
+ * array: `includes`, `filter`, `length`, a for loop. To take flags away,
75
+ * assign the array back - `player.hideHud = player.hideHud.filter(...)`.
76
+ */
77
+ export class FlagList<T> extends Array<T> {
78
+ store: FlagStore | null = null;
79
+ family: FlagFamily | null = null;
80
+
81
+ push(value: T): i32 {
82
+ const store = this.store;
83
+ const family = this.family;
84
+ if (store && family) store.write(store.read() | family.bitOf(<string>value));
85
+ return super.push(value);
86
+ }
87
+ }
88
+
89
+ /** The names set in the mask `store` holds now, as a list that writes back. */
90
+ export function flagList<T>(store: FlagStore, family: FlagFamily): FlagList<T> {
91
+ const list = new FlagList<T>();
92
+ const names = family.namesOf(store.read());
93
+ for (let i = 0; i < names.length; i++) list.push(<T>unchecked(names[i]));
94
+ // Only now: building the list must not write the bits it just read.
95
+ list.store = store;
96
+ list.family = family;
97
+ return list;
98
+ }
99
+
100
+ /** Parts of the HUD a player does not see - m_iHideHUD. */
101
+ export type HideHud =
102
+ | "Weapons"
103
+ | "Flashlight"
104
+ | "All"
105
+ | "Health"
106
+ | "Timer"
107
+ | "Money"
108
+ | "Crosshair"
109
+ | "ObserverCrosshair";
110
+
111
+ /** The HideHud names and their bits, for the hood. */
112
+ export const HIDE_HUD = new FlagFamily(
113
+ ["Weapons", "Flashlight", "All", "Health", "Timer", "Money", "Crosshair", "ObserverCrosshair"],
114
+ [1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7]
115
+ );
116
+
117
+ /** Buttons a player holds - var_button, var_oldbuttons. */
118
+ export type Button =
119
+ | "Attack"
120
+ | "Jump"
121
+ | "Duck"
122
+ | "Forward"
123
+ | "Back"
124
+ | "Use"
125
+ | "Cancel"
126
+ | "Left"
127
+ | "Right"
128
+ | "MoveLeft"
129
+ | "MoveRight"
130
+ | "Attack2"
131
+ | "Run"
132
+ | "Reload"
133
+ | "Alt1"
134
+ | "Score";
135
+
136
+ /** The Button names and their bits, for the hood. */
137
+ export const BUTTON = new FlagFamily(
138
+ ["Attack", "Jump", "Duck", "Forward", "Back", "Use", "Cancel", "Left", "Right", "MoveLeft", "MoveRight", "Attack2", "Run", "Reload", "Alt1", "Score"],
139
+ [1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7, 1 << 8, 1 << 9, 1 << 10, 1 << 11, 1 << 12, 1 << 13, 1 << 14, 1 << 15]
140
+ );
141
+
142
+ /** Visual effects on an entity - var_effects. */
143
+ export type Effect =
144
+ | "BrightField"
145
+ | "MuzzleFlash"
146
+ | "BrightLight"
147
+ | "DimLight"
148
+ | "InvLight"
149
+ | "NoInterp"
150
+ | "Light"
151
+ | "NoDraw"
152
+ | "ForceVisibility"
153
+ | "OwnerVisibility"
154
+ | "OwnerNoVisibility"
155
+ | "NoSlerp"
156
+ | "FollowKeepRender";
157
+
158
+ /** The Effect names and their bits, for the hood. */
159
+ export const EFFECT = new FlagFamily(
160
+ ["BrightField", "MuzzleFlash", "BrightLight", "DimLight", "InvLight", "NoInterp", "Light", "NoDraw", "ForceVisibility", "OwnerVisibility", "OwnerNoVisibility", "NoSlerp", "FollowKeepRender"],
161
+ [1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7, 1 << 11, 1 << 12, 1 << 13, 1 << 14, 1 << 15]
162
+ );
163
+
164
+ /** Engine flags of an entity - var_flags. */
165
+ export type EntityFlag =
166
+ | "Fly"
167
+ | "Swim"
168
+ | "Conveyor"
169
+ | "Client"
170
+ | "InWater"
171
+ | "Monster"
172
+ | "GodMode"
173
+ | "NoTarget"
174
+ | "SkipLocalHost"
175
+ | "OnGround"
176
+ | "PartialGround"
177
+ | "WaterJump"
178
+ | "Frozen"
179
+ | "FakeClient"
180
+ | "Ducking"
181
+ | "Float"
182
+ | "Graphed"
183
+ | "ImmuneWater"
184
+ | "ImmuneSlime"
185
+ | "ImmuneLava"
186
+ | "Proxy"
187
+ | "AlwaysThink"
188
+ | "BaseVelocity"
189
+ | "MonsterClip"
190
+ | "OnTrain"
191
+ | "WorldBrush"
192
+ | "Spectator"
193
+ | "CustomEntity"
194
+ | "KillMe"
195
+ | "Dormant";
196
+
197
+ /** The EntityFlag names and their bits, for the hood. */
198
+ export const ENTITY_FLAG = new FlagFamily(
199
+ ["Fly", "Swim", "Conveyor", "Client", "InWater", "Monster", "GodMode", "NoTarget", "SkipLocalHost", "OnGround", "PartialGround", "WaterJump", "Frozen", "FakeClient", "Ducking", "Float", "Graphed", "ImmuneWater", "ImmuneSlime", "ImmuneLava", "Proxy", "AlwaysThink", "BaseVelocity", "MonsterClip", "OnTrain", "WorldBrush", "Spectator", "CustomEntity", "KillMe", "Dormant"],
200
+ [1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7, 1 << 8, 1 << 9, 1 << 10, 1 << 11, 1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16, 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 21, 1 << 22, 1 << 23, 1 << 24, 1 << 25, 1 << 26, 1 << 29, 1 << 30, 1 << 31]
201
+ );
202
+
203
+ /** Kinds of damage - the damage type a hook receives. */
204
+ export type Damage =
205
+ | "Crush"
206
+ | "Bullet"
207
+ | "Slash"
208
+ | "Burn"
209
+ | "Freeze"
210
+ | "Fall"
211
+ | "Blast"
212
+ | "Club"
213
+ | "Shock"
214
+ | "Sonic"
215
+ | "EnergyBeam"
216
+ | "NeverGib"
217
+ | "AlwaysGib"
218
+ | "Drown"
219
+ | "Paralyze"
220
+ | "NerveGas"
221
+ | "Poison"
222
+ | "Radiation"
223
+ | "DrownRecover"
224
+ | "Acid"
225
+ | "SlowBurn"
226
+ | "SlowFreeze"
227
+ | "Mortar"
228
+ | "Grenade";
229
+ // Not single bits, so not names: DMG_GENERIC = 0, DMG_GIB_CORPSE = 737, DMG_SHOWNHUD = 7815448.
230
+
231
+ /** The Damage names and their bits, for the hood. */
232
+ export const DAMAGE = new FlagFamily(
233
+ ["Crush", "Bullet", "Slash", "Burn", "Freeze", "Fall", "Blast", "Club", "Shock", "Sonic", "EnergyBeam", "NeverGib", "AlwaysGib", "Drown", "Paralyze", "NerveGas", "Poison", "Radiation", "DrownRecover", "Acid", "SlowBurn", "SlowFreeze", "Mortar", "Grenade"],
234
+ [1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7, 1 << 8, 1 << 9, 1 << 10, 1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16, 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 21, 1 << 22, 1 << 23, 1 << 24]
235
+ );
236
+
237
+ /** What an admin may do - get_user_flags, users.ini letters. */
238
+ export type Access =
239
+ | "Immunity"
240
+ | "Reservation"
241
+ | "Kick"
242
+ | "Ban"
243
+ | "Slay"
244
+ | "Map"
245
+ | "Cvar"
246
+ | "Cfg"
247
+ | "Chat"
248
+ | "Vote"
249
+ | "Password"
250
+ | "Rcon"
251
+ | "LevelA"
252
+ | "LevelB"
253
+ | "LevelC"
254
+ | "LevelD"
255
+ | "LevelE"
256
+ | "LevelF"
257
+ | "LevelG"
258
+ | "LevelH"
259
+ | "Menu"
260
+ | "BanTemp"
261
+ | "Admin"
262
+ | "User";
263
+ // Not single bits, so not names: ADMIN_ALL = 0.
264
+
265
+ /** The Access names and their bits, for the hood. */
266
+ export const ACCESS = new FlagFamily(
267
+ ["Immunity", "Reservation", "Kick", "Ban", "Slay", "Map", "Cvar", "Cfg", "Chat", "Vote", "Password", "Rcon", "LevelA", "LevelB", "LevelC", "LevelD", "LevelE", "LevelF", "LevelG", "LevelH", "Menu", "BanTemp", "Admin", "User"],
268
+ [1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7, 1 << 8, 1 << 9, 1 << 10, 1 << 11, 1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16, 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 21, 1 << 24, 1 << 25]
269
+ );
270
+
271
+ /** Modes a weapon is in - m_iWeaponState: a silencer on, burst fire, the shield drawn. */
272
+ export type WeaponState =
273
+ | "UspSilenced"
274
+ | "Glock18Burst"
275
+ | "M4a1Silenced"
276
+ | "EliteLeft"
277
+ | "FamasBurst"
278
+ | "ShieldDrawn";
279
+
280
+ /** The WeaponState names and their bits, for the hood. */
281
+ export const WEAPON_STATE = new FlagFamily(
282
+ ["UspSilenced", "Glock18Burst", "M4a1Silenced", "EliteLeft", "FamasBurst", "ShieldDrawn"],
283
+ [1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5]
284
+ );
285
+
286
+ /** The physics state of a player - m_afPhysicsFlags: on a ladder, on a train, ducking. */
287
+ export type PhysicsFlag =
288
+ | "OnLadder"
289
+ | "OnTrain"
290
+ | "OnBarnacle"
291
+ | "Ducking"
292
+ | "Using"
293
+ | "Observer";
294
+
295
+ /** The PhysicsFlag names and their bits, for the hood. */
296
+ export const PHYSICS_FLAG = new FlagFamily(
297
+ ["OnLadder", "OnTrain", "OnBarnacle", "Ducking", "Using", "Observer"],
298
+ [1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5]
299
+ );
package/as/fs.ts ADDED
@@ -0,0 +1,287 @@
1
+ // Files, the way Node's fs reads and writes them:
2
+ //
3
+ // import * as fs from "~/fs";
4
+ //
5
+ // const text = fs.readFileSync("addons/amxmodx/configs/myplugin.ini");
6
+ // fs.writeFileSync("addons/amxmodx/data/last.txt", "de_dust2");
7
+ // const later = await fs.readFile("addons/amxmodx/configs/myplugin.ini");
8
+ //
9
+ // Underneath are AMX Mod X's own file natives - fopen, fread_blocks, fputs,
10
+ // open_dir - so a path means what it means to a Pawn plugin: relative to the
11
+ // game folder (cstrike/), `addons/amxmodx/configs/...` for configs.
12
+ //
13
+ // Text is UTF-8 both ways. A file is read whole, whatever its size: 128 bytes
14
+ // a native call (the thunk's buffer for an array it does not know the size
15
+ // of), never through a 255-character line buffer.
16
+ //
17
+ // There are no exceptions in AssemblyScript, so the synchronous functions say
18
+ // they failed by their result - null, false - and the promise ones reject
19
+ // with an Error, as Node's do.
20
+ //
21
+ // Written with explicit integer types: outside the facade a bare literal is
22
+ // a JavaScript number, and every count here is a cell.
23
+
24
+ // Promise, for the promise versions, whether or not the plugin imports the facade.
25
+ import "./promise";
26
+
27
+ // @ts-ignore: decorator
28
+ @external("env", "fopen") declare function _fopen(name: usize, mode: usize, valve: i32, pathId: usize): i32;
29
+ // @ts-ignore: decorator
30
+ @external("env", "fclose") declare function _fclose(file: i32): i32;
31
+ // @ts-ignore: decorator
32
+ @external("env", "fread_blocks") declare function _freadBlocks(file: i32, data: usize, blocks: i32, mode: i32): i32;
33
+ // @ts-ignore: decorator
34
+ @external("env", "fputs") declare function _fputs(file: i32, text: usize, nullTerm: i32): i32;
35
+ // @ts-ignore: decorator
36
+ @external("env", "file_exists") declare function _fileExists(name: usize, valve: i32): i32;
37
+ // @ts-ignore: decorator
38
+ @external("env", "dir_exists") declare function _dirExists(name: usize, valve: i32): i32;
39
+ // @ts-ignore: decorator
40
+ @external("env", "open_dir") declare function _openDir(dir: usize, first: usize, length: i32, type: usize, valve: i32, pathId: usize): i32;
41
+ // @ts-ignore: decorator
42
+ @external("env", "next_file") declare function _nextFile(handle: i32, name: usize, length: i32, type: usize): i32;
43
+ // @ts-ignore: decorator
44
+ @external("env", "close_dir") declare function _closeDir(handle: i32): i32;
45
+ // @ts-ignore: decorator
46
+ @external("env", "mkdir") declare function _mkdir(name: usize, mode: i32, valve: i32, pathId: usize): i32;
47
+
48
+ // fread_blocks' mode for one byte per cell.
49
+ const BLOCK_CHAR: i32 = 1;
50
+ // What one fread_blocks call reads: the module's thunk copies exactly this
51
+ // many cells of an array whose size it cannot know.
52
+ const READ_CELLS: i32 = 128;
53
+ // What one fputs call writes: the thunk copies a string up to 511 cells.
54
+ const WRITE_BYTES: i32 = 500;
55
+ // A name from open_dir / next_file.
56
+ const NAME_CELLS: i32 = 256;
57
+ // mkdir's FPERM_DIR_DEFAULT: rwxrwxr-x, where the system has permissions.
58
+ const DIR_MODE: i32 = 0o775;
59
+
60
+ /** Text as a Pawn string: its UTF-8 bytes, a byte a cell, and a zero cell. */
61
+ function cells(text: string): StaticArray<i32> {
62
+ const bytes = Uint8Array.wrap(String.UTF8.encode(text));
63
+ const out = new StaticArray<i32>(bytes.length + 1);
64
+ for (let i: i32 = 0; i < bytes.length; i++) unchecked(out[i] = <i32>unchecked(bytes[i]));
65
+ return out;
66
+ }
67
+
68
+ /** A Pawn string of UTF-8 bytes back as text. */
69
+ function textOf(from: StaticArray<i32>): string {
70
+ const bytes = new Array<u8>();
71
+ for (let i: i32 = 0; i < from.length; i++) {
72
+ const c = unchecked(from[i]);
73
+ if (c == 0) break;
74
+ bytes.push(<u8>c);
75
+ }
76
+ return String.UTF8.decodeUnsafe(bytes.dataStart, <usize>bytes.length);
77
+ }
78
+
79
+ function open(path: string, mode: string): i32 {
80
+ return _fopen(changetype<usize>(cells(path)), changetype<usize>(cells(mode)), 0, 0);
81
+ }
82
+
83
+ function write(path: string, data: string, mode: string): bool {
84
+ const file = open(path, mode);
85
+ if (file == 0) return false;
86
+
87
+ const bytes = Uint8Array.wrap(String.UTF8.encode(data));
88
+ const chunk = new StaticArray<i32>(WRITE_BYTES + 1);
89
+
90
+ for (let at: i32 = 0; at < bytes.length; at += WRITE_BYTES) {
91
+ const count = min(WRITE_BYTES, bytes.length - at);
92
+ for (let i: i32 = 0; i < count; i++) unchecked(chunk[i] = <i32>unchecked(bytes[at + i]));
93
+ unchecked(chunk[count] = 0);
94
+ _fputs(file, changetype<usize>(chunk), 0);
95
+ }
96
+
97
+ _fclose(file);
98
+ return true;
99
+ }
100
+
101
+ function missing(path: string, call: string): Error {
102
+ return new Error(`ENOENT: no such file or directory, ${call} '${path}'`);
103
+ }
104
+
105
+ /**
106
+ * Reads a whole file as text; `null` when it cannot be opened.
107
+ *
108
+ * ```ts
109
+ * const text = fs.readFileSync("addons/amxmodx/configs/myplugin.ini");
110
+ * if (text == null) return;
111
+ * ```
112
+ *
113
+ * The path is relative to the game folder (`cstrike/`), as for any AMX Mod X
114
+ * plugin. The file is UTF-8; it is read whole, whatever its size.
115
+ *
116
+ * Pawn: `fopen`, `fread_blocks`
117
+ */
118
+ export function readFileSync(path: string): string | null {
119
+ const file = open(path, "rb");
120
+ if (file == 0) return null;
121
+
122
+ const bytes = new Array<u8>();
123
+ const chunk = new StaticArray<i32>(READ_CELLS);
124
+
125
+ for (;;) {
126
+ const read = _freadBlocks(file, changetype<usize>(chunk), READ_CELLS, BLOCK_CHAR);
127
+ for (let i: i32 = 0; i < read; i++) bytes.push(<u8>(unchecked(chunk[i]) & 0xFF));
128
+ if (read < READ_CELLS) break;
129
+ }
130
+
131
+ _fclose(file);
132
+ return String.UTF8.decodeUnsafe(bytes.dataStart, <usize>bytes.length);
133
+ }
134
+
135
+ /**
136
+ * Writes text to a file, replacing what was there; `false` when it cannot be
137
+ * opened (a folder that does not exist, for one).
138
+ *
139
+ * ```ts
140
+ * fs.writeFileSync("addons/amxmodx/data/last-map.txt", server.map);
141
+ * ```
142
+ *
143
+ * Pawn: `fopen`, `fputs`
144
+ */
145
+ export function writeFileSync(path: string, data: string): boolean {
146
+ return write(path, data, "wb");
147
+ }
148
+
149
+ /**
150
+ * Adds text to the end of a file, making it if there is none; `false` when it cannot be opened.
151
+ *
152
+ * Pawn: `fopen(path, "a")`, `fputs`
153
+ */
154
+ export function appendFileSync(path: string, data: string): boolean {
155
+ return write(path, data, "ab");
156
+ }
157
+
158
+ /**
159
+ * `true` when the file or folder exists.
160
+ *
161
+ * Pawn: `file_exists`, `dir_exists`
162
+ */
163
+ export function existsSync(path: string): boolean {
164
+ const name = changetype<usize>(cells(path));
165
+ return _fileExists(name, 0) != 0 || _dirExists(name, 0) != 0;
166
+ }
167
+
168
+ /**
169
+ * Lists the names in a folder, without `.` and `..`; `null` when there is no
170
+ * such folder.
171
+ *
172
+ * ```ts
173
+ * const maps = fs.readdirSync("maps");
174
+ * ```
175
+ *
176
+ * Pawn: `open_dir`, `next_file`
177
+ */
178
+ export function readdirSync(path: string): string[] | null {
179
+ const name = new StaticArray<i32>(NAME_CELLS);
180
+ const type = new StaticArray<i32>(1);
181
+ const handle = _openDir(changetype<usize>(cells(path)), changetype<usize>(name), NAME_CELLS - 1, changetype<usize>(type), 0, 0);
182
+ if (handle == 0) return null;
183
+
184
+ const names: string[] = [];
185
+ for (;;) {
186
+ const entry = textOf(name);
187
+ if (entry != "." && entry != "..") names.push(entry);
188
+ if (_nextFile(handle, changetype<usize>(name), NAME_CELLS - 1, changetype<usize>(type)) == 0) break;
189
+ }
190
+
191
+ _closeDir(handle);
192
+ return names;
193
+ }
194
+
195
+ /** The options of `mkdirSync`: `{ recursive: true }` makes the missing folders above too. */
196
+ export class MakeDirectoryOptions {
197
+ /** `true` to make every missing folder on the way too; `false` by default. */
198
+ recursive: boolean = false;
199
+ }
200
+
201
+ /**
202
+ * Makes a folder; `false` when it cannot be made, or - without `recursive` -
203
+ * when it is there already or its parent is not.
204
+ *
205
+ * ```ts
206
+ * fs.mkdirSync("addons/amxmodx/data/stats", { recursive: true });
207
+ * ```
208
+ *
209
+ * With `{ recursive: true }` every missing folder on the way is made, and a
210
+ * folder that is already there is fine, as in Node.
211
+ *
212
+ * Pawn: `mkdir`
213
+ */
214
+ export function mkdirSync(path: string, options: MakeDirectoryOptions = new MakeDirectoryOptions()): boolean {
215
+ if (!options.recursive) return makeOne(path);
216
+
217
+ const parts = path.replaceAll("\\", "/").split("/");
218
+ let at = "";
219
+ for (let i = 0; i < parts.length; i++) {
220
+ const part = parts[i];
221
+ at = at.length > 0 ? `${at}/${part}` : part;
222
+ // "a//b" and a Windows drive ("C:") are not folders to make.
223
+ if (part.length == 0 || (i == 0 && part.endsWith(":"))) continue;
224
+ if (isFolder(at)) continue;
225
+ if (!makeOne(at)) return false;
226
+ }
227
+ return true;
228
+ }
229
+
230
+ function isFolder(path: string): bool {
231
+ return _dirExists(changetype<usize>(cells(path)), 0) != 0;
232
+ }
233
+
234
+ function makeOne(path: string): bool {
235
+ return _mkdir(changetype<usize>(cells(path)), DIR_MODE, 0, changetype<usize>(cells("GAMECONFIG"))) == 0;
236
+ }
237
+
238
+ /** `mkdirSync` as a promise, rejected when the folder cannot be made. */
239
+ export function mkdir(path: string, options: MakeDirectoryOptions = new MakeDirectoryOptions()): Promise<void> {
240
+ const promise = __co_promise<void>();
241
+ if (mkdirSync(path, options)) promise.__fulfillVoid();
242
+ else promise.__reject(new Error(`EEXIST or ENOENT: cannot make the folder, mkdir '${path}'`));
243
+ return promise;
244
+ }
245
+
246
+ /**
247
+ * `readFileSync` as a promise: it rejects with an `ENOENT` error when the file
248
+ * cannot be opened, like Node's `fs.promises.readFile`.
249
+ *
250
+ * ```ts
251
+ * const text = await fs.readFile("addons/amxmodx/configs/myplugin.ini");
252
+ * ```
253
+ */
254
+ export function readFile(path: string): Promise<string> {
255
+ const text = readFileSync(path);
256
+ if (text == null) return Promise.reject<string>(missing(path, "open"));
257
+ return Promise.resolve<string>(text);
258
+ }
259
+
260
+ /** `writeFileSync` as a promise, rejected when the file cannot be opened. */
261
+ export function writeFile(path: string, data: string): Promise<void> {
262
+ return settled(writeFileSync(path, data), path);
263
+ }
264
+
265
+ /** `appendFileSync` as a promise, rejected when the file cannot be opened. */
266
+ export function appendFile(path: string, data: string): Promise<void> {
267
+ return settled(appendFileSync(path, data), path);
268
+ }
269
+
270
+ /** `existsSync` as a promise. */
271
+ export function exists(path: string): Promise<boolean> {
272
+ return Promise.resolve<boolean>(existsSync(path));
273
+ }
274
+
275
+ /** `readdirSync` as a promise, rejected when there is no such folder. */
276
+ export function readdir(path: string): Promise<string[]> {
277
+ const names = readdirSync(path);
278
+ if (names == null) return Promise.reject<string[]>(missing(path, "scandir"));
279
+ return Promise.resolve<string[]>(names);
280
+ }
281
+
282
+ function settled(ok: bool, path: string): Promise<void> {
283
+ const promise = __co_promise<void>();
284
+ if (ok) promise.__fulfillVoid();
285
+ else promise.__reject(missing(path, "open"));
286
+ return promise;
287
+ }