@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.
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/README.ru.md +162 -0
- package/amxmodx/base/include/amxconst.inc +594 -0
- package/amxmodx/base/include/amxmisc.inc +902 -0
- package/amxmodx/base/include/amxmodx.inc +3447 -0
- package/amxmodx/base/include/amxmodx_version.inc +20 -0
- package/amxmodx/base/include/cellarray.inc +525 -0
- package/amxmodx/base/include/cellstack.inc +166 -0
- package/amxmodx/base/include/celltrie.inc +412 -0
- package/amxmodx/base/include/core.inc +202 -0
- package/amxmodx/base/include/csstats.inc +298 -0
- package/amxmodx/base/include/csstats_const.inc +29 -0
- package/amxmodx/base/include/cstrike.inc +1287 -0
- package/amxmodx/base/include/cstrike_const.inc +521 -0
- package/amxmodx/base/include/csx.inc +259 -0
- package/amxmodx/base/include/cvars.inc +547 -0
- package/amxmodx/base/include/datapack.inc +161 -0
- package/amxmodx/base/include/dbi.inc +154 -0
- package/amxmodx/base/include/dodconst.inc +152 -0
- package/amxmodx/base/include/dodfun.inc +152 -0
- package/amxmodx/base/include/dodstats.inc +69 -0
- package/amxmodx/base/include/dodx.inc +161 -0
- package/amxmodx/base/include/engine.inc +1343 -0
- package/amxmodx/base/include/engine_const.inc +310 -0
- package/amxmodx/base/include/engine_stocks.inc +248 -0
- package/amxmodx/base/include/esf.inc +70 -0
- package/amxmodx/base/include/esf_const.inc +74 -0
- package/amxmodx/base/include/fakemeta.inc +1127 -0
- package/amxmodx/base/include/fakemeta_const.inc +793 -0
- package/amxmodx/base/include/fakemeta_stocks.inc +395 -0
- package/amxmodx/base/include/fakemeta_util.inc +882 -0
- package/amxmodx/base/include/file.inc +666 -0
- package/amxmodx/base/include/float.inc +422 -0
- package/amxmodx/base/include/fun.inc +333 -0
- package/amxmodx/base/include/gameconfig.inc +93 -0
- package/amxmodx/base/include/geoip.inc +264 -0
- package/amxmodx/base/include/ham_const.inc +4352 -0
- package/amxmodx/base/include/hamsandwich.inc +439 -0
- package/amxmodx/base/include/hlsdk_const.inc +808 -0
- package/amxmodx/base/include/json.inc +777 -0
- package/amxmodx/base/include/lang.inc +119 -0
- package/amxmodx/base/include/message_const.inc +1130 -0
- package/amxmodx/base/include/message_stocks.inc +161 -0
- package/amxmodx/base/include/messages.inc +604 -0
- package/amxmodx/base/include/newmenus.inc +387 -0
- package/amxmodx/base/include/ns.inc +754 -0
- package/amxmodx/base/include/ns_const.inc +196 -0
- package/amxmodx/base/include/nvault.inc +154 -0
- package/amxmodx/base/include/regex.inc +348 -0
- package/amxmodx/base/include/sockets.inc +183 -0
- package/amxmodx/base/include/sorting.inc +107 -0
- package/amxmodx/base/include/sqlx.inc +582 -0
- package/amxmodx/base/include/string.inc +786 -0
- package/amxmodx/base/include/string_const.inc +156 -0
- package/amxmodx/base/include/string_stocks.inc +325 -0
- package/amxmodx/base/include/textparse_ini.inc +214 -0
- package/amxmodx/base/include/textparse_smc.inc +261 -0
- package/amxmodx/base/include/tfcconst.inc +84 -0
- package/amxmodx/base/include/tfcstats.inc +62 -0
- package/amxmodx/base/include/tfcx.inc +148 -0
- package/amxmodx/base/include/time.inc +118 -0
- package/amxmodx/base/include/tsconst.inc +154 -0
- package/amxmodx/base/include/tsfun.inc +198 -0
- package/amxmodx/base/include/tsstats.inc +65 -0
- package/amxmodx/base/include/tsx.inc +88 -0
- package/amxmodx/base/include/vault.inc +60 -0
- package/amxmodx/base/include/vector.inc +131 -0
- package/amxmodx/base/include/xs.inc +1570 -0
- package/as/amxts.d.ts +153 -0
- package/as/constants.ts +4730 -0
- package/as/effects.ts +1449 -0
- package/as/entities.ts +5482 -0
- package/as/events.ts +3054 -0
- package/as/facade.ts +4639 -0
- package/as/flags.ts +299 -0
- package/as/fs.ts +287 -0
- package/as/hooks.ts +18536 -0
- package/as/kit.ts +25 -0
- package/as/lib/check.ts +86 -0
- package/as/modules/http.ts +184 -0
- package/as/natives.ts +11845 -0
- package/as/os.ts +30 -0
- package/as/promise.ts +1392 -0
- package/as/promise.types.d.ts +82 -0
- package/as/remote.ts +288 -0
- package/as/tsconfig.json +22 -0
- package/as/vector.ts +65 -0
- package/bin/amxts.mjs +10 -0
- package/includes/menu_core.inc +355 -0
- package/includes/order.txt +54 -0
- package/includes/sources.json +27 -0
- package/includes/universal_config.inc +355 -0
- package/lint/oxlint-plugin.mjs +77 -0
- package/node_modules/assemblyscript/LICENSE +201 -0
- package/node_modules/assemblyscript/NOTICE +93 -0
- package/node_modules/assemblyscript/package.json +63 -0
- package/node_modules/assemblyscript/std/README.md +6 -0
- package/node_modules/assemblyscript/std/assembly/array.ts +526 -0
- package/node_modules/assemblyscript/std/assembly/arraybuffer.ts +77 -0
- package/node_modules/assemblyscript/std/assembly/atomics.ts +127 -0
- package/node_modules/assemblyscript/std/assembly/bindings/asyncify.ts +16 -0
- package/node_modules/assemblyscript/std/assembly/bindings/dom.ts +291 -0
- package/node_modules/assemblyscript/std/assembly/bindings/node.ts +6 -0
- package/node_modules/assemblyscript/std/assembly/builtins.ts +2631 -0
- package/node_modules/assemblyscript/std/assembly/compat.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/console.ts +42 -0
- package/node_modules/assemblyscript/std/assembly/crypto.ts +9 -0
- package/node_modules/assemblyscript/std/assembly/dataview.ts +181 -0
- package/node_modules/assemblyscript/std/assembly/date.ts +373 -0
- package/node_modules/assemblyscript/std/assembly/diagnostics.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/error.ts +44 -0
- package/node_modules/assemblyscript/std/assembly/function.ts +38 -0
- package/node_modules/assemblyscript/std/assembly/index.d.ts +2822 -0
- package/node_modules/assemblyscript/std/assembly/iterator.ts +35 -0
- package/node_modules/assemblyscript/std/assembly/map.ts +260 -0
- package/node_modules/assemblyscript/std/assembly/math.ts +3289 -0
- package/node_modules/assemblyscript/std/assembly/memory.ts +123 -0
- package/node_modules/assemblyscript/std/assembly/number.ts +388 -0
- package/node_modules/assemblyscript/std/assembly/object.ts +36 -0
- package/node_modules/assemblyscript/std/assembly/performance.ts +9 -0
- package/node_modules/assemblyscript/std/assembly/polyfills.ts +27 -0
- package/node_modules/assemblyscript/std/assembly/process.ts +50 -0
- package/node_modules/assemblyscript/std/assembly/reference.ts +48 -0
- package/node_modules/assemblyscript/std/assembly/regexp.ts +12 -0
- package/node_modules/assemblyscript/std/assembly/rt/README.md +83 -0
- package/node_modules/assemblyscript/std/assembly/rt/common.ts +81 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-incremental.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-minimal.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-stub.ts +1 -0
- package/node_modules/assemblyscript/std/assembly/rt/index.d.ts +37 -0
- package/node_modules/assemblyscript/std/assembly/rt/itcms.ts +419 -0
- package/node_modules/assemblyscript/std/assembly/rt/rtrace.ts +15 -0
- package/node_modules/assemblyscript/std/assembly/rt/stub.ts +133 -0
- package/node_modules/assemblyscript/std/assembly/rt/tcms.ts +254 -0
- package/node_modules/assemblyscript/std/assembly/rt/tlsf.ts +592 -0
- package/node_modules/assemblyscript/std/assembly/rt.ts +87 -0
- package/node_modules/assemblyscript/std/assembly/set.ts +220 -0
- package/node_modules/assemblyscript/std/assembly/shared/feature.ts +65 -0
- package/node_modules/assemblyscript/std/assembly/shared/runtime.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/target.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/tsconfig.json +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/typeinfo.ts +72 -0
- package/node_modules/assemblyscript/std/assembly/staticarray.ts +401 -0
- package/node_modules/assemblyscript/std/assembly/string.ts +847 -0
- package/node_modules/assemblyscript/std/assembly/symbol.ts +114 -0
- package/node_modules/assemblyscript/std/assembly/table.ts +16 -0
- package/node_modules/assemblyscript/std/assembly/tsconfig.json +6 -0
- package/node_modules/assemblyscript/std/assembly/typedarray.ts +1945 -0
- package/node_modules/assemblyscript/std/assembly/uri.ts +17 -0
- package/node_modules/assemblyscript/std/assembly/util/bytes.ts +107 -0
- package/node_modules/assemblyscript/std/assembly/util/casemap.ts +497 -0
- package/node_modules/assemblyscript/std/assembly/util/error.ts +54 -0
- package/node_modules/assemblyscript/std/assembly/util/hash.ts +117 -0
- package/node_modules/assemblyscript/std/assembly/util/math.ts +1922 -0
- package/node_modules/assemblyscript/std/assembly/util/memory.ts +290 -0
- package/node_modules/assemblyscript/std/assembly/util/number.ts +873 -0
- package/node_modules/assemblyscript/std/assembly/util/sort.ts +313 -0
- package/node_modules/assemblyscript/std/assembly/util/string.ts +1202 -0
- package/node_modules/assemblyscript/std/assembly/util/uri.ts +275 -0
- package/node_modules/assemblyscript/std/assembly/vector.ts +4 -0
- package/node_modules/assemblyscript/std/assembly.json +16 -0
- package/node_modules/assemblyscript/std/portable/index.d.ts +462 -0
- package/node_modules/assemblyscript/std/portable/index.js +416 -0
- package/node_modules/assemblyscript/std/portable.json +11 -0
- package/node_modules/assemblyscript/std/types/assembly/index.d.ts +1 -0
- package/node_modules/assemblyscript/std/types/assembly/package.json +3 -0
- package/node_modules/assemblyscript/std/types/portable/index.d.ts +1 -0
- package/node_modules/assemblyscript/std/types/portable/package.json +3 -0
- package/node_modules/assemblyscript/tsconfig-base.json +13 -0
- package/package.json +112 -0
- package/runtime/deps/assemblyscript/LICENSE +201 -0
- package/runtime/deps/assemblyscript/NOTICE +93 -0
- package/runtime/deps/assemblyscript/bin/asc.js +35 -0
- package/runtime/deps/assemblyscript/dist/asc.js +25035 -0
- package/runtime/deps/assemblyscript/dist/assemblyscript.js +337 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/LICENSE +201 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/index.js +28905 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/package.json +50 -0
- package/runtime/deps/assemblyscript/node_modules/long/LICENSE +202 -0
- package/runtime/deps/assemblyscript/node_modules/long/index.js +1581 -0
- package/runtime/deps/assemblyscript/node_modules/long/package.json +58 -0
- package/runtime/deps/assemblyscript/package.json +114 -0
- package/runtime/host/amxts.inc +85 -0
- package/runtime/licenses/AMXX-LICENSE.txt +34 -0
- package/runtime/licenses/AssemblyScript-LICENSE +201 -0
- package/runtime/licenses/AssemblyScript-NOTICE +93 -0
- package/runtime/licenses/Binaryen-LICENSE +201 -0
- package/runtime/licenses/Bun-LICENSE.md +84 -0
- package/runtime/licenses/GPL-3.0.txt +674 -0
- package/runtime/licenses/LLVM-LICENSE.TXT +279 -0
- package/runtime/licenses/README.md +25 -0
- package/runtime/licenses/WAMR-LICENSE +219 -0
- package/runtime/natives.txt +1095 -0
- package/runtime/patches/README.md +59 -0
- package/runtime/patches/assemblyscript-0.28.20-amxts.patch +14174 -0
- package/runtime/patches/wamr-2.4.5-amxts.patch +364 -0
- package/scripts/apply-docs.ts +508 -0
- package/scripts/asc.ts +27 -0
- package/scripts/auto-imports.ts +258 -0
- package/scripts/build-wasm.ts +595 -0
- package/scripts/check.ts +93 -0
- package/scripts/compile-cache.ts +179 -0
- package/scripts/compile.ts +401 -0
- package/scripts/docker-server.ts +73 -0
- package/scripts/docs/as/amxts.ts +210 -0
- package/scripts/docs/as/effects.ts +1684 -0
- package/scripts/docs/as/facade.ts +3302 -0
- package/scripts/docs/as/fs.ts +173 -0
- package/scripts/docs/as/lib/check.ts +68 -0
- package/scripts/docs/as/modules/http.ts +66 -0
- package/scripts/docs/as/os.ts +16 -0
- package/scripts/docs/as/promise.ts +132 -0
- package/scripts/docs/as/promise.types.ts +63 -0
- package/scripts/docs/as/vector.ts +48 -0
- package/scripts/docs/entities.ts +2338 -0
- package/scripts/docs/events.ts +245 -0
- package/scripts/docs/game.ts +497 -0
- package/scripts/docs/messages.ts +148 -0
- package/scripts/file-contents.ts +74 -0
- package/scripts/includes.ts +134 -0
- package/scripts/player-fields.ts +866 -0
- package/scripts/plugin-cache.ts +92 -0
- package/scripts/plugin-natives.ts +1157 -0
- package/scripts/prebuilt.ts +268 -0
- package/scripts/prepare.ts +134 -0
- package/scripts/project.ts +973 -0
- package/scripts/run.ts +28 -0
- package/scripts/shared-modules.ts +906 -0
- package/scripts/system.ts +33 -0
- package/scripts/tracked-fs.ts +115 -0
- package/scripts/typed-configs.ts +788 -0
- package/scripts/ui.ts +77 -0
- package/src/cli-api.mjs +175 -0
- package/src/parser/include-parser.ts +506 -0
- package/src/system.mjs +155 -0
- package/src/testing/compile-cache.ts +31 -0
- package/src/testing/compile.ts +222 -0
- package/src/testing/coroutines.ts +191 -0
- package/src/testing/index.ts +39 -0
- package/src/testing/kits.ts +55 -0
- package/src/testing/memory.ts +125 -0
- package/src/testing/natives.ts +925 -0
- package/src/testing/server.ts +1874 -0
- package/src/testing/setup.ts +63 -0
- package/src/testing/tables.ts +139 -0
- package/src/types.ts +51 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// The Promise globals as the editor reads them, and what it knows of
|
|
2
|
+
// Promise.all, allSettled, race and any.
|
|
3
|
+
//
|
|
4
|
+
// as/promise.ts is where the classes are; the compiler makes them global
|
|
5
|
+
// through `@global`. The editor treats every file with an import or an export
|
|
6
|
+
// as a module - a project's plugin without an import line too - so here they
|
|
7
|
+
// are made global for it: `Promise`, `AbortController`, `AbortSignal`,
|
|
8
|
+
// `Event`, and what the hood's other files call.
|
|
9
|
+
//
|
|
10
|
+
// The four statics are TypeScript's own lib signatures, which type a list
|
|
11
|
+
// written in place as a tuple - `Promise.all([fetch(url), sleep(1000)])` is a
|
|
12
|
+
// `Promise<[Response, void]>`. AssemblyScript has no tuple types and no
|
|
13
|
+
// mapped types to declare these with, so as/promise.ts leaves the four out of
|
|
14
|
+
// its Promise class and the compiler lowers each call to a hidden function
|
|
15
|
+
// there (Resolver.lowerPromiseCall in the compiler patch). A namespace of the
|
|
16
|
+
// same name merges them into the class, as statics.
|
|
17
|
+
//
|
|
18
|
+
// Only the editor reads this file.
|
|
19
|
+
import * as impl from "./promise";
|
|
20
|
+
|
|
21
|
+
declare global {
|
|
22
|
+
/** The value a promise gives, or the value itself. */
|
|
23
|
+
type __PromiseValue<T> = T extends impl.Promise<infer U> ? U : T;
|
|
24
|
+
|
|
25
|
+
/** The value `await` gives of a promise or of a plain value - TypeScript's own name for it, which `await 5` and `for await` look up. */
|
|
26
|
+
type Awaited<T> = __PromiseValue<T>;
|
|
27
|
+
|
|
28
|
+
/** The statics that take a list of promises: `all`, `allSettled`, `race` and `any`. */
|
|
29
|
+
// oxlint-disable-next-line no-redeclare -- merged into the class below, as statics
|
|
30
|
+
namespace Promise {
|
|
31
|
+
/**
|
|
32
|
+
* Waits for every promise and gives their values in order; rejects with the
|
|
33
|
+
* first rejection. Promises of different types give a tuple:
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const [response, count] = await Promise.all([fetch(url), countAsync()]);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function all<T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: __PromiseValue<T[P]> }>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Waits for every promise to settle, either way, and tells how each did:
|
|
43
|
+
* `status` is `"fulfilled"` with `value`, or `"rejected"` with `reason`.
|
|
44
|
+
*/
|
|
45
|
+
function allSettled<T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: PromiseSettledResult<__PromiseValue<T[P]>> }>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Settles like the first promise to settle. Promises of different types
|
|
49
|
+
* need a common base class; a Promise<void> among them makes the value
|
|
50
|
+
* nullable.
|
|
51
|
+
*/
|
|
52
|
+
function race<T extends readonly unknown[] | []>(values: T): Promise<__PromiseValue<T[number]>>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Gives the first value to arrive; once all promises are rejected, rejects
|
|
56
|
+
* with an AggregateError whose `errors` hold every reason.
|
|
57
|
+
*/
|
|
58
|
+
function any<T extends readonly unknown[] | []>(values: T): Promise<__PromiseValue<T[number]>>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The class the namespace above merges its statics into.
|
|
62
|
+
class Promise<T> extends impl.Promise<T> {}
|
|
63
|
+
export import PromiseLike = impl.PromiseLike;
|
|
64
|
+
export import PromiseBase = impl.PromiseBase;
|
|
65
|
+
export import PromiseSettledResult = impl.PromiseSettledResult;
|
|
66
|
+
export import AggregateError = impl.AggregateError;
|
|
67
|
+
export import Event = impl.Event;
|
|
68
|
+
export import AbortSignal = impl.AbortSignal;
|
|
69
|
+
export import AbortController = impl.AbortController;
|
|
70
|
+
|
|
71
|
+
// The hood's: what the facade and the libraries beside it call.
|
|
72
|
+
export import __AbortWatch = impl.__AbortWatch;
|
|
73
|
+
export import __AbortGuard = impl.__AbortGuard;
|
|
74
|
+
export import __co_promise = impl.__co_promise;
|
|
75
|
+
export import __co_resolve = impl.__co_resolve;
|
|
76
|
+
export import __co_reject = impl.__co_reject;
|
|
77
|
+
export import __co_bindEnv = impl.__co_bindEnv;
|
|
78
|
+
export import __co_sleep = impl.__co_sleep;
|
|
79
|
+
export import __co_player_signal = impl.__co_player_signal;
|
|
80
|
+
/** @hidden The player whose command or event is being handled. */
|
|
81
|
+
let __co_ambient_player: i32;
|
|
82
|
+
}
|
package/as/remote.ts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// Calls between plugins, for the modules one plugin runs for the whole server.
|
|
2
|
+
//
|
|
3
|
+
// A module at ~/modules/<name> that the plugin ~/<name>.ts owns (see
|
|
4
|
+
// scripts/shared-modules.ts) has one instance on the server:
|
|
5
|
+
// the owner's. Every other plugin that imports it is given a proxy instead,
|
|
6
|
+
// generated by scripts/shared-modules.ts - the same exported functions, each
|
|
7
|
+
// of which writes its arguments here, has the module (runtime/src/module.cpp)
|
|
8
|
+
// run the owner's copy, and reads the answer back. A function passed across -
|
|
9
|
+
// a condition, an action - stays where it was written; the other side gets a
|
|
10
|
+
// stand-in that calls back the same way.
|
|
11
|
+
//
|
|
12
|
+
// This file is the part both sides share: the byte buffers the arguments
|
|
13
|
+
// travel in, the plugin's table of functions others may call back, and the
|
|
14
|
+
// one export the module calls, __amxts_rpc. It is hood: plugins never import it.
|
|
15
|
+
// __co_bindEnv, which makes a stand-in, is as/promise.ts's; __env, where the
|
|
16
|
+
// stand-in finds its place, the compiler library's.
|
|
17
|
+
import "~/promise";
|
|
18
|
+
|
|
19
|
+
// @ts-ignore: decorator
|
|
20
|
+
@external("env", "amxts_serve") declare function _serve(name: string, hash: i32): void;
|
|
21
|
+
// @ts-ignore: decorator
|
|
22
|
+
@external("env", "amxts_owner") declare function _owner(name: string, hash: i32): i32;
|
|
23
|
+
// @ts-ignore: decorator
|
|
24
|
+
@external("env", "amxts_rpc") declare function _rpc(service: i32, plugin: i32, data: usize, length: i32): i32;
|
|
25
|
+
// @ts-ignore: decorator
|
|
26
|
+
@external("env", "amxts_rpc_take") declare function _take(to: usize): void;
|
|
27
|
+
// @ts-ignore: decorator
|
|
28
|
+
@external("env", "amxts_rpc_reply") declare function _reply(data: usize, length: i32): void;
|
|
29
|
+
// @ts-ignore: decorator
|
|
30
|
+
@external("env", "amxts_rpc_result") declare function _result(to: usize): void;
|
|
31
|
+
|
|
32
|
+
const KIND_MODULE: i32 = 0;
|
|
33
|
+
const KIND_CALLBACK: i32 = 1;
|
|
34
|
+
|
|
35
|
+
/** What a call carries: its arguments, or its answer, as bytes. */
|
|
36
|
+
export class Writer {
|
|
37
|
+
data: ArrayBuffer = new ArrayBuffer(64);
|
|
38
|
+
length: i32 = 0;
|
|
39
|
+
|
|
40
|
+
private room(bytes: i32): usize {
|
|
41
|
+
if (this.length + bytes > this.data.byteLength) {
|
|
42
|
+
let size = this.data.byteLength * 2;
|
|
43
|
+
while (size < this.length + bytes) size *= 2;
|
|
44
|
+
const grown = new ArrayBuffer(size);
|
|
45
|
+
memory.copy(changetype<usize>(grown), changetype<usize>(this.data), <usize>this.length);
|
|
46
|
+
this.data = grown;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const at = changetype<usize>(this.data) + <usize>this.length;
|
|
50
|
+
this.length += bytes;
|
|
51
|
+
return at;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
i32(value: i32): void {
|
|
55
|
+
store<i32>(this.room(4), value);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
f64(value: f64): void {
|
|
59
|
+
store<f64>(this.room(8), value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
bool(value: bool): void {
|
|
63
|
+
store<u8>(this.room(1), value ? 1 : 0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
str(value: string): void {
|
|
67
|
+
const bytes = String.UTF8.encode(value);
|
|
68
|
+
const size = bytes.byteLength;
|
|
69
|
+
this.i32(size);
|
|
70
|
+
memory.copy(this.room(size), changetype<usize>(bytes), <usize>size);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The other end of a Writer. Past the end every read is zero - what a failed call reads as. */
|
|
75
|
+
export class Reader {
|
|
76
|
+
at: i32 = 0;
|
|
77
|
+
|
|
78
|
+
/** `from`: the plugin that wrote it - where a function it carries lives. */
|
|
79
|
+
constructor(public data: ArrayBuffer, public from: i32) {}
|
|
80
|
+
|
|
81
|
+
private take(bytes: i32): usize {
|
|
82
|
+
if (this.at + bytes > this.data.byteLength) {
|
|
83
|
+
this.at = this.data.byteLength;
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const at = changetype<usize>(this.data) + <usize>this.at;
|
|
88
|
+
this.at += bytes;
|
|
89
|
+
return at;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
i32(): i32 {
|
|
93
|
+
const at = this.take(4);
|
|
94
|
+
return at != 0 ? load<i32>(at) : 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
f64(): f64 {
|
|
98
|
+
const at = this.take(8);
|
|
99
|
+
return at != 0 ? load<f64>(at) : 0.0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
bool(): bool {
|
|
103
|
+
const at = this.take(1);
|
|
104
|
+
return at != 0 ? load<u8>(at) != 0 : false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
str(): string {
|
|
108
|
+
const size = this.i32();
|
|
109
|
+
if (size <= 0) return "";
|
|
110
|
+
const at = this.take(size);
|
|
111
|
+
return at != 0 ? String.UTF8.decodeUnsafe(at, <usize>size) : "";
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** A module another plugin owns, as a proxy knows it. */
|
|
116
|
+
export class Service {
|
|
117
|
+
private id: i32 = -1;
|
|
118
|
+
private failed: bool = false;
|
|
119
|
+
|
|
120
|
+
constructor(public name: string, public hash: i32) {}
|
|
121
|
+
|
|
122
|
+
/** A call of the module's `op`-th function (or field). */
|
|
123
|
+
begin(op: i32): Writer {
|
|
124
|
+
const w = new Writer();
|
|
125
|
+
w.i32(KIND_MODULE);
|
|
126
|
+
w.i32(op);
|
|
127
|
+
return w;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Runs it in the owner and returns the answer; an empty one, and an error in the log, when it cannot. */
|
|
131
|
+
call(w: Writer): Reader {
|
|
132
|
+
if (this.id < 0) {
|
|
133
|
+
const id = _owner(this.name, this.hash);
|
|
134
|
+
if (id < 0) return this.fail(id == -2
|
|
135
|
+
? `~/modules/${this.name}: ${this.name}.aot was built from another version of it - build both again`
|
|
136
|
+
: `~/modules/${this.name}: no plugin runs it - is ${this.name}.aot in plugins.ini?`);
|
|
137
|
+
this.id = id;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const answer = send(this.id, -1, w);
|
|
141
|
+
if (answer == null) return this.fail(`~/modules/${this.name}: the call failed in ${this.name}`);
|
|
142
|
+
this.failed = false;
|
|
143
|
+
return answer!;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private fail(message: string): Reader {
|
|
147
|
+
if (!this.failed) console.error(message);
|
|
148
|
+
this.failed = true;
|
|
149
|
+
return new Reader(new ArrayBuffer(0), -1);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The answer from `service`, or from `plugin` when service is -1; null when there is none. */
|
|
154
|
+
function send(service: i32, plugin: i32, w: Writer): Reader | null {
|
|
155
|
+
const length = _rpc(service, plugin, changetype<usize>(w.data), w.length);
|
|
156
|
+
if (length < 4) return null;
|
|
157
|
+
const data = new ArrayBuffer(length);
|
|
158
|
+
_result(changetype<usize>(data));
|
|
159
|
+
const r = new Reader(data, 0);
|
|
160
|
+
r.from = r.i32();
|
|
161
|
+
return r;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ---------------------------------------------------------------- functions passed across
|
|
165
|
+
|
|
166
|
+
/** Calls `fn`, a function of signature `sig`, with the arguments in `r`; its answer goes to `w`. */
|
|
167
|
+
export type Invoke = (fn: usize, sig: i32, r: Reader, w: Writer) => void;
|
|
168
|
+
|
|
169
|
+
class Callback {
|
|
170
|
+
constructor(public fn: Object, public sig: i32, public invoke: Invoke) {}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const callbacks: Callback[] = [];
|
|
174
|
+
const callbackIds = new Map<usize, i32>();
|
|
175
|
+
|
|
176
|
+
/** The number another plugin calls `fn` back by; 0 for null. The same function keeps its number. */
|
|
177
|
+
export function sendFunction(fn: usize, sig: i32, invoke: Invoke): i32 {
|
|
178
|
+
if (fn == 0) return 0;
|
|
179
|
+
|
|
180
|
+
if (callbackIds.has(fn)) {
|
|
181
|
+
const id = callbackIds.get(fn);
|
|
182
|
+
if (callbacks[id - 1].sig == sig) return id;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
callbacks.push(new Callback(changetype<Object>(fn), sig, invoke));
|
|
186
|
+
const id = callbacks.length;
|
|
187
|
+
callbackIds.set(fn, id);
|
|
188
|
+
return id;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Where a stand-in calls: the plugin a function lives in, and its number there. */
|
|
192
|
+
class Remote {
|
|
193
|
+
constructor(public plugin: i32, public id: i32) {}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const standIns = new Map<string, usize>();
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* A stand-in for function `id` of the plugin that wrote `r`: a copy of
|
|
200
|
+
* `stub` - a function of the same signature that calls back - with the place
|
|
201
|
+
* in its `_env`, where the stub finds it (__env, the compiler's). The same
|
|
202
|
+
* function is the same stand-in, so it can be compared and removed.
|
|
203
|
+
*/
|
|
204
|
+
export function receiveFunction(r: Reader, stub: usize): usize {
|
|
205
|
+
const id = r.i32();
|
|
206
|
+
if (id == 0) return 0;
|
|
207
|
+
const key = `${r.from}:${id}`;
|
|
208
|
+
if (standIns.has(key)) return standIns.get(key);
|
|
209
|
+
// @ts-ignore: as/promise.ts's, global to the compiler and unknown to the editor
|
|
210
|
+
const bound: usize = __co_bindEnv(stub, new Remote(r.from, id));
|
|
211
|
+
standIns.set(key, bound);
|
|
212
|
+
// Held here: the stand-in is only ever reached through what it was given to.
|
|
213
|
+
kept.push(changetype<Object>(bound));
|
|
214
|
+
return bound;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const kept: Object[] = [];
|
|
218
|
+
|
|
219
|
+
/** The first thing a stub does: where it calls. Before any other call, which would change __env. */
|
|
220
|
+
export function remoteTarget(): Remote {
|
|
221
|
+
// @ts-ignore: the compiler library's, unknown to the editor
|
|
222
|
+
return changetype<Remote>(__env);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** A call of the function a stand-in stands for. */
|
|
226
|
+
export function beginCallback(target: Remote): Writer {
|
|
227
|
+
const w = new Writer();
|
|
228
|
+
w.i32(KIND_CALLBACK);
|
|
229
|
+
w.i32(target.id);
|
|
230
|
+
return w;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function callBack(target: Remote, w: Writer): Reader {
|
|
234
|
+
const answer = send(-1, target.plugin, w);
|
|
235
|
+
return answer ?? new Reader(new ArrayBuffer(0), -1);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ---------------------------------------------------------------- the owner's side
|
|
239
|
+
|
|
240
|
+
/** Runs op `op` of the served module with the arguments in `r`; the answer goes to `w`. */
|
|
241
|
+
export type Dispatch = (op: i32, r: Reader, w: Writer) => void;
|
|
242
|
+
|
|
243
|
+
let served: Dispatch | null = null;
|
|
244
|
+
|
|
245
|
+
/** The module this plugin runs for the others; one a plugin. */
|
|
246
|
+
export function serve(name: string, hash: i32, dispatch: Dispatch): void {
|
|
247
|
+
served = dispatch;
|
|
248
|
+
_serve(name, hash);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Objects the owner hands out and takes back by number: a menu, a config, a section. */
|
|
252
|
+
export class Handles {
|
|
253
|
+
objects: Object[] = [];
|
|
254
|
+
ids: Map<usize, i32> = new Map<usize, i32>();
|
|
255
|
+
|
|
256
|
+
id(object: usize): i32 {
|
|
257
|
+
if (object == 0) return 0;
|
|
258
|
+
if (this.ids.has(object)) return this.ids.get(object);
|
|
259
|
+
this.objects.push(changetype<Object>(object));
|
|
260
|
+
const id = this.objects.length;
|
|
261
|
+
this.ids.set(object, id);
|
|
262
|
+
return id;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
at(id: i32): usize {
|
|
266
|
+
return id > 0 && id <= this.objects.length ? changetype<usize>(this.objects[id - 1]) : 0;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** @hidden What the module calls: a request of `length` bytes from plugin `from`. */
|
|
271
|
+
export function __amxts_rpc(length: i32, from: i32): void {
|
|
272
|
+
const data = new ArrayBuffer(length);
|
|
273
|
+
_take(changetype<usize>(data));
|
|
274
|
+
const r = new Reader(data, from);
|
|
275
|
+
const kind = r.i32();
|
|
276
|
+
const id = r.i32();
|
|
277
|
+
const w = new Writer();
|
|
278
|
+
|
|
279
|
+
if (kind == KIND_MODULE) {
|
|
280
|
+
const dispatch = served;
|
|
281
|
+
if (dispatch != null) dispatch(id, r, w);
|
|
282
|
+
} else if (kind == KIND_CALLBACK && id > 0 && id <= callbacks.length) {
|
|
283
|
+
const callback = callbacks[id - 1];
|
|
284
|
+
callback.invoke(changetype<usize>(callback.fn), callback.sig, r, w);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
_reply(changetype<usize>(w.data), w.length);
|
|
288
|
+
}
|
package/as/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "assemblyscript/std/assembly.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es2015",
|
|
5
|
+
"moduleDetection": "force",
|
|
6
|
+
"module": "esnext",
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
"paths": {
|
|
9
|
+
"~/*": ["./*"],
|
|
10
|
+
"@amxts/core": ["./facade.ts"],
|
|
11
|
+
"@amxts/core/*": ["./*"],
|
|
12
|
+
"@amxts/menu-core": ["../../amxts-modules/menu-core/src/index.ts"],
|
|
13
|
+
"@amxts/config-core": ["../../amxts-modules/config-core/src/index.ts"]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"include": [
|
|
17
|
+
"./**/*.ts",
|
|
18
|
+
"../amxts.config.ts",
|
|
19
|
+
"../../amxts-modules/menu-core/src/index.ts",
|
|
20
|
+
"../../amxts-modules/config-core/src/index.ts"
|
|
21
|
+
]
|
|
22
|
+
}
|
package/as/vector.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// A point or a direction in the game world: an origin, a velocity, angles.
|
|
2
|
+
//
|
|
3
|
+
// It is an array of three numbers underneath, so `origin[0]`, a native that
|
|
4
|
+
// takes a vector (get_distance_f, message_begin) and a literal written as
|
|
5
|
+
// `[0.0, 0.0, 100.0]` all keep working next to `origin.x` and `origin.add(...)`.
|
|
6
|
+
// Being an array is also why its size is `magnitude()`: `length` is already
|
|
7
|
+
// the array's 3.
|
|
8
|
+
|
|
9
|
+
/** Three numbers, x y z, with the math a plugin needs on them. */
|
|
10
|
+
export class Vector extends Array<number> {
|
|
11
|
+
constructor(x: number = 0.0, y: number = 0.0, z: number = 0.0) {
|
|
12
|
+
super(3);
|
|
13
|
+
this[0] = x;
|
|
14
|
+
this[1] = y;
|
|
15
|
+
this[2] = z;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The x coordinate, `vector[0]`. */
|
|
19
|
+
get x() { return this[0]; }
|
|
20
|
+
set x(value: number) { this[0] = value; }
|
|
21
|
+
|
|
22
|
+
/** The y coordinate, `vector[1]`. */
|
|
23
|
+
get y() { return this[1]; }
|
|
24
|
+
set y(value: number) { this[1] = value; }
|
|
25
|
+
|
|
26
|
+
/** The z coordinate, `vector[2]`. */
|
|
27
|
+
get z() { return this[2]; }
|
|
28
|
+
set z(value: number) { this[2] = value; }
|
|
29
|
+
|
|
30
|
+
/** A new vector: this one plus `other`, number by number. */
|
|
31
|
+
add(other: number[]) {
|
|
32
|
+
return new Vector(this[0] + other[0], this[1] + other[1], this[2] + other[2]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A new vector: this one minus `other`, the way from `other` to this point. */
|
|
36
|
+
subtract(other: number[]) {
|
|
37
|
+
return new Vector(this[0] - other[0], this[1] - other[1], this[2] - other[2]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A new vector with every number multiplied by `factor`. */
|
|
41
|
+
scale(factor: number) {
|
|
42
|
+
return new Vector(this[0] * factor, this[1] * factor, this[2] * factor);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The dot product with `other`; zero when the two are at right angles. */
|
|
46
|
+
dot(other: number[]) {
|
|
47
|
+
return this[0] * other[0] + this[1] * other[1] + this[2] * other[2];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The vector's length: the distance from the map's origin to this point. */
|
|
51
|
+
magnitude() {
|
|
52
|
+
return Math.sqrt(this.dot(this));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The distance from this point to `other`, in game units. */
|
|
56
|
+
distanceTo(other: number[]) {
|
|
57
|
+
return this.subtract(other).magnitude();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A new vector in the same direction, one unit long; a zero vector stays zero. */
|
|
61
|
+
normalize() {
|
|
62
|
+
const size = this.magnitude();
|
|
63
|
+
return size > 0 ? this.scale(1 / size) : new Vector();
|
|
64
|
+
}
|
|
65
|
+
}
|
package/bin/amxts.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The amxts command a project runs: `npx amxts --help`. The command is its own
|
|
3
|
+
// package, @amxts/cli, which the core depends on; a package manager links the
|
|
4
|
+
// bins of a project's own dependencies only, so the core carries this one.
|
|
5
|
+
// The command finds the project's core again and drives it through
|
|
6
|
+
// @amxts/core/cli-api.
|
|
7
|
+
import process from 'node:process';
|
|
8
|
+
import { main } from '@amxts/cli';
|
|
9
|
+
|
|
10
|
+
main(process.argv.slice(2));
|