@nativewrappers/common 0.0.122 → 0.0.123
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/decors/ConVar.d.ts +14 -0
- package/decors/ConVar.js +70 -0
- package/decors/Events.d.ts +29 -28
- package/decors/Events.js +76 -121
- package/decors/Exports.d.ts +1 -0
- package/decors/Exports.js +53 -0
- package/decors/Permissions.d.ts +3 -0
- package/decors/Permissions.js +49 -0
- package/decors/Resources.d.ts +8 -0
- package/decors/Resources.js +83 -0
- package/decors/Ticks.d.ts +9 -0
- package/decors/Ticks.js +32 -0
- package/index.d.ts +6 -1
- package/index.js +6 -1
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare enum ConVarType {
|
|
2
|
+
String = 0,
|
|
3
|
+
Integer = 1,
|
|
4
|
+
Float = 2,
|
|
5
|
+
Boolean = 3
|
|
6
|
+
}
|
|
7
|
+
type DeserializeFn<T> = (data: T) => unknown;
|
|
8
|
+
/**
|
|
9
|
+
* Gets the specified `ConVar`s value, this will bind to the param.
|
|
10
|
+
* @param name the convar name
|
|
11
|
+
* @param is_floating_point if the convar is floating point, this should be explicitly set to true if your convar will be a float
|
|
12
|
+
*/
|
|
13
|
+
export declare function ConVar<T>(name: string, is_floating_point?: boolean, deserialize?: DeserializeFn<T>): (_initialValue: any, context: ClassFieldDecoratorContext, ..._args: any[]) => void;
|
|
14
|
+
export {};
|
package/decors/ConVar.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
var ConVarType = /* @__PURE__ */ ((ConVarType2) => {
|
|
4
|
+
ConVarType2[ConVarType2["String"] = 0] = "String";
|
|
5
|
+
ConVarType2[ConVarType2["Integer"] = 1] = "Integer";
|
|
6
|
+
ConVarType2[ConVarType2["Float"] = 2] = "Float";
|
|
7
|
+
ConVarType2[ConVarType2["Boolean"] = 3] = "Boolean";
|
|
8
|
+
return ConVarType2;
|
|
9
|
+
})(ConVarType || {});
|
|
10
|
+
const get_convar_fn = /* @__PURE__ */ __name((con_var_type) => {
|
|
11
|
+
switch (con_var_type) {
|
|
12
|
+
case 0 /* String */:
|
|
13
|
+
return GetConvar;
|
|
14
|
+
case 1 /* Integer */:
|
|
15
|
+
return GetConvarInt;
|
|
16
|
+
case 2 /* Float */:
|
|
17
|
+
return GetConvarFloat;
|
|
18
|
+
case 3 /* Boolean */:
|
|
19
|
+
return GetConvarBool;
|
|
20
|
+
// needed so typescript wont complain about "unreachable code" for the error below
|
|
21
|
+
default:
|
|
22
|
+
}
|
|
23
|
+
throw new Error("Got invalid ConVarType");
|
|
24
|
+
}, "get_convar_fn");
|
|
25
|
+
function ConVar(name, is_floating_point, deserialize) {
|
|
26
|
+
return /* @__PURE__ */ __name(function actualDecorator(_initialValue, context, ..._args) {
|
|
27
|
+
if (context.private) {
|
|
28
|
+
throw new Error("ConVar does not work on private types, please mark the field as public");
|
|
29
|
+
}
|
|
30
|
+
context.addInitializer(function() {
|
|
31
|
+
const t = this;
|
|
32
|
+
const default_value = Reflect.get(t, context.name);
|
|
33
|
+
const default_type = typeof default_value;
|
|
34
|
+
let con_var_type = null;
|
|
35
|
+
if (default_type === "number") {
|
|
36
|
+
if (is_floating_point || !Number.isInteger(default_value)) {
|
|
37
|
+
con_var_type = 2 /* Float */;
|
|
38
|
+
} else {
|
|
39
|
+
con_var_type = 1 /* Integer */;
|
|
40
|
+
}
|
|
41
|
+
} else if (default_type === "boolean") {
|
|
42
|
+
con_var_type = 3 /* Boolean */;
|
|
43
|
+
} else if (default_type === "string") {
|
|
44
|
+
con_var_type = 0 /* String */;
|
|
45
|
+
}
|
|
46
|
+
if (!deserialize && con_var_type === null) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Failed to determine what to use to deserialize '${name}' was for var had type '${default_type}' which can't be deserialized without providing your own deserialize function.`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if (con_var_type === null) {
|
|
52
|
+
con_var_type = 0 /* String */;
|
|
53
|
+
}
|
|
54
|
+
const con_var_fn = get_convar_fn(con_var_type);
|
|
55
|
+
const get_convar_value = /* @__PURE__ */ __name(() => {
|
|
56
|
+
const data = con_var_fn(name, default_value);
|
|
57
|
+
return deserialize ? deserialize(data) : data;
|
|
58
|
+
}, "get_convar_value");
|
|
59
|
+
Reflect.set(t, context.name, get_convar_value());
|
|
60
|
+
AddConvarChangeListener(name, () => {
|
|
61
|
+
Reflect.set(t, context.name, get_convar_value());
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}, "actualDecorator");
|
|
65
|
+
}
|
|
66
|
+
__name(ConVar, "ConVar");
|
|
67
|
+
export {
|
|
68
|
+
ConVar,
|
|
69
|
+
ConVarType
|
|
70
|
+
};
|
package/decors/Events.d.ts
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
export declare enum ConVarType {
|
|
2
|
-
String = 0,
|
|
3
|
-
Integer = 1,
|
|
4
|
-
Float = 2,
|
|
5
|
-
Boolean = 3
|
|
6
|
-
}
|
|
7
1
|
/**
|
|
8
2
|
* Disables pretty printing in error messages
|
|
9
3
|
*/
|
|
10
4
|
export declare const DisablePrettyPrint: () => boolean;
|
|
11
|
-
export declare
|
|
5
|
+
export declare enum Binding {
|
|
6
|
+
/**
|
|
7
|
+
* No one can call this
|
|
8
|
+
*/
|
|
9
|
+
None = 0,
|
|
10
|
+
/**
|
|
11
|
+
* Server only accepts server calls, client only client calls
|
|
12
|
+
*/
|
|
13
|
+
Local = 1,
|
|
14
|
+
/**
|
|
15
|
+
* Server only accepts client calls, client only server calls
|
|
16
|
+
*/
|
|
17
|
+
Remote = 2,
|
|
18
|
+
/**
|
|
19
|
+
* Accept all incoming calls
|
|
20
|
+
* Server only accepts client calls, client only server calls
|
|
21
|
+
*/
|
|
22
|
+
All = 3
|
|
23
|
+
}
|
|
12
24
|
/**
|
|
13
25
|
* Registers the Event call for {@link eventName} to this method.
|
|
14
26
|
*
|
|
15
27
|
* This has internal pretty-printing to make errors easier to track, if
|
|
16
28
|
* you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
|
|
17
29
|
* using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
|
|
18
|
-
*
|
|
19
30
|
* @param eventName the event to bind to
|
|
20
31
|
*/
|
|
21
|
-
export declare function
|
|
32
|
+
export declare function CfxEvent(eventName: string, binding?: Binding): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
22
33
|
/**
|
|
23
34
|
* Registers the Event call for {@link eventName} to this method.
|
|
24
35
|
*
|
|
@@ -26,10 +37,9 @@ export declare function Event(eventName: string): (originalMethod: any, context:
|
|
|
26
37
|
* you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
|
|
27
38
|
* using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
|
|
28
39
|
*
|
|
29
|
-
* This is the same thing as just using `Event` but this disambiguates the call from DOM
|
|
30
40
|
* @param eventName the event to bind to
|
|
31
41
|
*/
|
|
32
|
-
export declare
|
|
42
|
+
export declare function Event(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
33
43
|
/**
|
|
34
44
|
* Registers the Net Event call for {@link eventName} to this method
|
|
35
45
|
*
|
|
@@ -42,24 +52,15 @@ export declare const CfxEvent: typeof Event;
|
|
|
42
52
|
* @param remoteOnly if the event should only accept remote calls, if set to true it will ignore any local call via `emit`, defaults to true
|
|
43
53
|
*/
|
|
44
54
|
export declare function NetEvent(eventName: string, remoteOnly?: boolean): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
55
|
+
export type NuiCallback = (data: string) => void;
|
|
45
56
|
/**
|
|
46
57
|
* Registers the NUI Event call for {eventName} to this method, the function signature
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
58
|
+
* will always be (data: unknown, cb: (data?: any) => void) => void
|
|
59
|
+
*
|
|
60
|
+
* There's two valid ways to return data into a callback, returning in the method
|
|
61
|
+
* you're currently using will automatically call the callback, or you can manually call the callback yourself
|
|
62
|
+
*
|
|
50
63
|
* @param eventName the event this will listen for
|
|
64
|
+
* @param dontErrorWhenCbIsntInvoked this will just block the event fro merroring when the callback is never invoked.
|
|
51
65
|
*/
|
|
52
|
-
export declare function NuiEvent(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
53
|
-
type DeserializeFn<T> = (data: T) => unknown;
|
|
54
|
-
/**
|
|
55
|
-
* Gets the specified `ConVar`s value, this will bind to the param.
|
|
56
|
-
* @param name the convar name
|
|
57
|
-
* @param is_floating_point if the convar is floating point, this should be explicitly set to true if your convar will be a float
|
|
58
|
-
*/
|
|
59
|
-
export declare function ConVar<T>(name: string, is_floating_point?: boolean, deserialize?: DeserializeFn<T>): (_initialValue: any, context: ClassFieldDecoratorContext, ..._args: any[]) => void;
|
|
60
|
-
/**
|
|
61
|
-
* Gets called per server/client tick, this is asyncronous though, if you await
|
|
62
|
-
* in it, it will not be called until whatever was being awaited resolves.
|
|
63
|
-
*/
|
|
64
|
-
export declare function SetTick(): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
65
|
-
export {};
|
|
66
|
+
export declare function NuiEvent(eventName: string, dontErrorWhenCbIsntInvoked?: boolean): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
package/decors/Events.js
CHANGED
|
@@ -1,61 +1,59 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import { GlobalData } from "../GlobalData";
|
|
4
|
-
var ConVarType = /* @__PURE__ */ ((ConVarType2) => {
|
|
5
|
-
ConVarType2[ConVarType2["String"] = 0] = "String";
|
|
6
|
-
ConVarType2[ConVarType2["Integer"] = 1] = "Integer";
|
|
7
|
-
ConVarType2[ConVarType2["Float"] = 2] = "Float";
|
|
8
|
-
ConVarType2[ConVarType2["Boolean"] = 3] = "Boolean";
|
|
9
|
-
return ConVarType2;
|
|
10
|
-
})(ConVarType || {});
|
|
11
4
|
const DisablePrettyPrint = /* @__PURE__ */ __name(() => GlobalData.EnablePrettyPrint = false, "DisablePrettyPrint");
|
|
12
5
|
const AsyncFunction = (async () => {
|
|
13
6
|
}).constructor;
|
|
14
|
-
|
|
7
|
+
var Binding = /* @__PURE__ */ ((Binding2) => {
|
|
8
|
+
Binding2[Binding2["None"] = 0] = "None";
|
|
9
|
+
Binding2[Binding2["Local"] = 1] = "Local";
|
|
10
|
+
Binding2[Binding2["Remote"] = 2] = "Remote";
|
|
11
|
+
Binding2[Binding2["All"] = 3] = "All";
|
|
12
|
+
return Binding2;
|
|
13
|
+
})(Binding || {});
|
|
14
|
+
function CfxEvent(eventName, binding = 1 /* Local */) {
|
|
15
15
|
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
16
16
|
if (context.private) {
|
|
17
|
-
throw new Error("
|
|
17
|
+
throw new Error("Event does not work on private methods, please mark the method as public");
|
|
18
18
|
}
|
|
19
19
|
context.addInitializer(function() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
const fn = (binding & 2 /* Remote */) !== 0 ? onNet : on;
|
|
21
|
+
const _t = this;
|
|
22
|
+
fn(eventName, async (...args) => {
|
|
23
|
+
const src = source;
|
|
24
|
+
if (_t.__permissionMap && binding & 2 /* Remote */) {
|
|
25
|
+
const permissions = _t.__permissionMap.get(context.name);
|
|
26
|
+
if (permissions) {
|
|
27
|
+
let hasPermission = false;
|
|
28
|
+
for (const perm of permissions) {
|
|
29
|
+
if (IsPlayerAceAllowed(src, perm)) {
|
|
30
|
+
hasPermission = true;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} else {
|
|
38
|
-
exportCb = /* @__PURE__ */ __name((...args) => {
|
|
39
|
-
try {
|
|
40
|
-
return originalMethod.call(this, ...args);
|
|
41
|
-
} catch (err) {
|
|
42
|
-
REMOVE_EVENT_LOG: {
|
|
43
|
-
if (!GlobalData.EnablePrettyPrint) return;
|
|
44
|
-
console.error("------- EXPORT ERROR --------");
|
|
45
|
-
console.error(`Call to ${exportName} errored`);
|
|
46
|
-
console.error(`Data: ${JSON.stringify(args)}`);
|
|
47
|
-
console.error(`Error: ${err}`);
|
|
48
|
-
console.error("------- END EXPORT ERROR --------");
|
|
34
|
+
if (!hasPermission) {
|
|
35
|
+
emit("@nativewrappers:no_permission", { eventName, method: context.name });
|
|
36
|
+
return;
|
|
49
37
|
}
|
|
50
|
-
throw err;
|
|
51
38
|
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
return await originalMethod.call(this, ...args);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
REMOVE_EVENT_LOG: {
|
|
44
|
+
if (!GlobalData.EnablePrettyPrint) return;
|
|
45
|
+
console.error("------- EVENT ERROR --------");
|
|
46
|
+
console.error(`Call to ${eventName} errored`);
|
|
47
|
+
console.error(`Data: ${JSON.stringify(args)}`);
|
|
48
|
+
console.error(`Error: ${e}`);
|
|
49
|
+
console.error("------- END EVENT ERROR --------");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
55
53
|
});
|
|
56
54
|
}, "actualDecorator");
|
|
57
55
|
}
|
|
58
|
-
__name(
|
|
56
|
+
__name(CfxEvent, "CfxEvent");
|
|
59
57
|
function Event(eventName) {
|
|
60
58
|
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
61
59
|
if (context.private) {
|
|
@@ -80,15 +78,31 @@ function Event(eventName) {
|
|
|
80
78
|
}, "actualDecorator");
|
|
81
79
|
}
|
|
82
80
|
__name(Event, "Event");
|
|
83
|
-
const CfxEvent = Event;
|
|
84
81
|
function NetEvent(eventName, remoteOnly = true) {
|
|
85
82
|
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
86
83
|
if (context.private) {
|
|
87
84
|
throw new Error("NetEvent does not work on private methods, please mark the method as public");
|
|
88
85
|
}
|
|
89
86
|
context.addInitializer(function() {
|
|
87
|
+
const _t = this;
|
|
90
88
|
onNet(eventName, async (...args) => {
|
|
91
89
|
const src = source;
|
|
90
|
+
if (_t.__permissionMap) {
|
|
91
|
+
const permissions = _t.__permissionMap.get(context.name);
|
|
92
|
+
if (permissions) {
|
|
93
|
+
let hasPermission = false;
|
|
94
|
+
for (const perm of permissions) {
|
|
95
|
+
if (IsPlayerAceAllowed(src, perm)) {
|
|
96
|
+
hasPermission = true;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!hasPermission) {
|
|
101
|
+
emit("@nativewrappers:no_permission", { eventName, method: context.name });
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
92
106
|
try {
|
|
93
107
|
$CLIENT: {
|
|
94
108
|
if (GlobalData.IS_CLIENT && remoteOnly && source !== 65535) {
|
|
@@ -112,97 +126,38 @@ function NetEvent(eventName, remoteOnly = true) {
|
|
|
112
126
|
}, "actualDecorator");
|
|
113
127
|
}
|
|
114
128
|
__name(NetEvent, "NetEvent");
|
|
115
|
-
function NuiEvent(eventName) {
|
|
129
|
+
function NuiEvent(eventName, dontErrorWhenCbIsntInvoked = false) {
|
|
116
130
|
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
117
131
|
if (context.private) {
|
|
118
132
|
throw new Error("NuiEvent does not work on private methods, please mark the method as public");
|
|
119
133
|
}
|
|
120
134
|
context.addInitializer(function() {
|
|
121
|
-
RegisterNuiCallback(eventName, (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
case 3 /* Boolean */:
|
|
137
|
-
return GetConvarBool;
|
|
138
|
-
// needed so typescript wont complain about "unreachable code" for the error below
|
|
139
|
-
default:
|
|
140
|
-
}
|
|
141
|
-
throw new Error("Got invalid ConVarType");
|
|
142
|
-
}, "get_convar_fn");
|
|
143
|
-
function ConVar(name, is_floating_point, deserialize) {
|
|
144
|
-
return /* @__PURE__ */ __name(function actualDecorator(_initialValue, context, ..._args) {
|
|
145
|
-
if (context.private) {
|
|
146
|
-
throw new Error("ConVar does not work on private types, please mark the field as public");
|
|
147
|
-
}
|
|
148
|
-
context.addInitializer(function() {
|
|
149
|
-
const t = this;
|
|
150
|
-
const default_value = Reflect.get(t, context.name);
|
|
151
|
-
const default_type = typeof default_value;
|
|
152
|
-
let con_var_type = null;
|
|
153
|
-
if (default_type === "number") {
|
|
154
|
-
if (is_floating_point || !Number.isInteger(default_value)) {
|
|
155
|
-
con_var_type = 2 /* Float */;
|
|
156
|
-
} else {
|
|
157
|
-
con_var_type = 1 /* Integer */;
|
|
135
|
+
RegisterNuiCallback(eventName, async (data, cb) => {
|
|
136
|
+
let wasInvoked = false;
|
|
137
|
+
const cbWrapper = /* @__PURE__ */ __name((args) => {
|
|
138
|
+
wasInvoked = true;
|
|
139
|
+
cb(args);
|
|
140
|
+
}, "cbWrapper");
|
|
141
|
+
const retData = await originalMethod.call(this, data, cbWrapper);
|
|
142
|
+
if (!wasInvoked && !retData) {
|
|
143
|
+
if (dontErrorWhenCbIsntInvoked) return;
|
|
144
|
+
throw new Error(
|
|
145
|
+
`Error in NuiEvent ${eventName} '@NuiEvent' expects you to return data in your callback, or to return from the function call`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
if (!wasInvoked) {
|
|
149
|
+
cb(retData);
|
|
158
150
|
}
|
|
159
|
-
} else if (default_type === "boolean") {
|
|
160
|
-
con_var_type = 3 /* Boolean */;
|
|
161
|
-
} else if (default_type === "string") {
|
|
162
|
-
con_var_type = 0 /* String */;
|
|
163
|
-
}
|
|
164
|
-
if (!deserialize && con_var_type === null) {
|
|
165
|
-
throw new Error(
|
|
166
|
-
`Failed to determine what to use to deserialize '${name}' was for var had type '${default_type}' which can't be deserialized without providing your own deserialize function.`
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
if (con_var_type === null) {
|
|
170
|
-
con_var_type = 0 /* String */;
|
|
171
|
-
}
|
|
172
|
-
const con_var_fn = get_convar_fn(con_var_type);
|
|
173
|
-
const get_convar_value = /* @__PURE__ */ __name(() => {
|
|
174
|
-
const data = con_var_fn(name, default_value);
|
|
175
|
-
return deserialize ? deserialize(data) : data;
|
|
176
|
-
}, "get_convar_value");
|
|
177
|
-
Reflect.set(t, context.name, get_convar_value());
|
|
178
|
-
AddConvarChangeListener(name, () => {
|
|
179
|
-
Reflect.set(t, context.name, get_convar_value());
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
}, "actualDecorator");
|
|
183
|
-
}
|
|
184
|
-
__name(ConVar, "ConVar");
|
|
185
|
-
function SetTick() {
|
|
186
|
-
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
187
|
-
if (context.private) {
|
|
188
|
-
throw new Error("SetTick does not work on private types, please mark the field as public");
|
|
189
|
-
}
|
|
190
|
-
context.addInitializer(function() {
|
|
191
|
-
setTick(async () => {
|
|
192
|
-
await originalMethod.call(this);
|
|
193
151
|
});
|
|
194
152
|
});
|
|
195
153
|
}, "actualDecorator");
|
|
196
154
|
}
|
|
197
|
-
__name(
|
|
155
|
+
__name(NuiEvent, "NuiEvent");
|
|
198
156
|
export {
|
|
157
|
+
Binding,
|
|
199
158
|
CfxEvent,
|
|
200
|
-
ConVar,
|
|
201
|
-
ConVarType,
|
|
202
159
|
DisablePrettyPrint,
|
|
203
160
|
Event,
|
|
204
|
-
Exports,
|
|
205
161
|
NetEvent,
|
|
206
|
-
NuiEvent
|
|
207
|
-
SetTick
|
|
162
|
+
NuiEvent
|
|
208
163
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Exports(exportName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { GlobalData } from "../GlobalData";
|
|
4
|
+
const AsyncFunction = (async () => {
|
|
5
|
+
}).constructor;
|
|
6
|
+
function Exports(exportName) {
|
|
7
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
8
|
+
if (context.private) {
|
|
9
|
+
throw new Error("Exports does not work on private methods, please mark the method as public");
|
|
10
|
+
}
|
|
11
|
+
context.addInitializer(function() {
|
|
12
|
+
let exportCb;
|
|
13
|
+
if (originalMethod instanceof AsyncFunction) {
|
|
14
|
+
exportCb = /* @__PURE__ */ __name(async (...args) => {
|
|
15
|
+
try {
|
|
16
|
+
return await originalMethod.call(this, ...args);
|
|
17
|
+
} catch (err) {
|
|
18
|
+
REMOVE_EVENT_LOG: {
|
|
19
|
+
if (!GlobalData.EnablePrettyPrint) return;
|
|
20
|
+
console.error("------- EXPORT ERROR --------");
|
|
21
|
+
console.error(`Call to ${exportName} errored`);
|
|
22
|
+
console.error(`Data: ${JSON.stringify(args)}`);
|
|
23
|
+
console.error(`Error: ${err}`);
|
|
24
|
+
console.error("------- END EXPORT ERROR --------");
|
|
25
|
+
}
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
}, "exportCb");
|
|
29
|
+
} else {
|
|
30
|
+
exportCb = /* @__PURE__ */ __name((...args) => {
|
|
31
|
+
try {
|
|
32
|
+
return originalMethod.call(this, ...args);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
REMOVE_EVENT_LOG: {
|
|
35
|
+
if (!GlobalData.EnablePrettyPrint) return;
|
|
36
|
+
console.error("------- EXPORT ERROR --------");
|
|
37
|
+
console.error(`Call to ${exportName} errored`);
|
|
38
|
+
console.error(`Data: ${JSON.stringify(args)}`);
|
|
39
|
+
console.error(`Error: ${err}`);
|
|
40
|
+
console.error("------- END EXPORT ERROR --------");
|
|
41
|
+
}
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
}, "exportCb");
|
|
45
|
+
}
|
|
46
|
+
exports(exportName, exportCb);
|
|
47
|
+
});
|
|
48
|
+
}, "actualDecorator");
|
|
49
|
+
}
|
|
50
|
+
__name(Exports, "Exports");
|
|
51
|
+
export {
|
|
52
|
+
Exports
|
|
53
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function RestrictToGroupAce(groupAceName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
2
|
+
export declare function RestrictToJobAce(jobAce: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
3
|
+
export declare function RestrictToAce(aceName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { GlobalData } from "../GlobalData";
|
|
4
|
+
const addAcePermission = /* @__PURE__ */ __name((aceName, context) => {
|
|
5
|
+
context.addInitializer(function() {
|
|
6
|
+
const _t = this;
|
|
7
|
+
_t.__permissionMap = _t.__permissionMap ?? /* @__PURE__ */ new Map();
|
|
8
|
+
const ace_list = _t.__permissionMap.get(context.name);
|
|
9
|
+
if (ace_list) {
|
|
10
|
+
ace_list.add(aceName);
|
|
11
|
+
} else {
|
|
12
|
+
_t.__permissionMap.set(context.name, /* @__PURE__ */ new Set([aceName]));
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}, "addAcePermission");
|
|
16
|
+
function RestrictToGroupAce(groupAceName) {
|
|
17
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
18
|
+
if (context.private) {
|
|
19
|
+
throw new Error("Exports does not work on private methods, please mark the method as public");
|
|
20
|
+
}
|
|
21
|
+
const groupAce = `group.${groupAceName}`;
|
|
22
|
+
addAcePermission(groupAce, context);
|
|
23
|
+
}, "actualDecorator");
|
|
24
|
+
}
|
|
25
|
+
__name(RestrictToGroupAce, "RestrictToGroupAce");
|
|
26
|
+
function RestrictToJobAce(jobAce) {
|
|
27
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
28
|
+
if (context.private) {
|
|
29
|
+
throw new Error("Exports does not work on private methods, please mark the method as public");
|
|
30
|
+
}
|
|
31
|
+
const groupAce = `job.${jobAce}`;
|
|
32
|
+
addAcePermission(groupAce, context);
|
|
33
|
+
}, "actualDecorator");
|
|
34
|
+
}
|
|
35
|
+
__name(RestrictToJobAce, "RestrictToJobAce");
|
|
36
|
+
function RestrictToAce(aceName) {
|
|
37
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
38
|
+
if (context.private) {
|
|
39
|
+
throw new Error("Exports does not work on private methods, please mark the method as public");
|
|
40
|
+
}
|
|
41
|
+
addAcePermission(aceName, context);
|
|
42
|
+
}, "actualDecorator");
|
|
43
|
+
}
|
|
44
|
+
__name(RestrictToAce, "RestrictToAce");
|
|
45
|
+
export {
|
|
46
|
+
RestrictToAce,
|
|
47
|
+
RestrictToGroupAce,
|
|
48
|
+
RestrictToJobAce
|
|
49
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Called whenever the specified resource is started, this will be called once on once on resource start if the resource is started.
|
|
3
|
+
*/
|
|
4
|
+
export declare function OnResourceStart(resource?: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Called whenever the specified resource is stopped.
|
|
7
|
+
*/
|
|
8
|
+
export declare function OnResoureStop(resource?: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { Event } from "./Events";
|
|
4
|
+
class ResourceWrapper {
|
|
5
|
+
static {
|
|
6
|
+
__name(this, "ResourceWrapper");
|
|
7
|
+
}
|
|
8
|
+
#on_resource_start = /* @__PURE__ */ new Map();
|
|
9
|
+
#on_resource_stop = /* @__PURE__ */ new Map();
|
|
10
|
+
#add_or_init(resource_fn_map, resource_name, fn) {
|
|
11
|
+
const fn_array = resource_fn_map.get(resource_name);
|
|
12
|
+
if (fn_array) {
|
|
13
|
+
fn_array.push(fn);
|
|
14
|
+
} else {
|
|
15
|
+
resource_fn_map.set(resource_name, [fn]);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Adds a function to get called whenever a resource is started
|
|
20
|
+
* @param resource_name The resource name to add to the start listener.
|
|
21
|
+
* @param fn The function to call
|
|
22
|
+
*/
|
|
23
|
+
add_to_resource_start(resource_name, fn) {
|
|
24
|
+
this.#add_or_init(this.#on_resource_start, resource_name, fn);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Adds a function to get called whenever a resource is stopped
|
|
28
|
+
* @param resource_name The resource name to add to the stop listener.
|
|
29
|
+
* @param fn The function to call
|
|
30
|
+
*/
|
|
31
|
+
add_to_resource_stop(resource_name, fn) {
|
|
32
|
+
this.#add_or_init(this.#on_resource_stop, resource_name, fn);
|
|
33
|
+
}
|
|
34
|
+
#call_for_resource(resource_fn_map, resource_name) {
|
|
35
|
+
const functions = resource_fn_map.get(resource_name);
|
|
36
|
+
if (functions) {
|
|
37
|
+
for (const fn of functions) {
|
|
38
|
+
fn();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
@Event("onResourceStart")
|
|
43
|
+
on_resource_start(resource_name) {
|
|
44
|
+
this.#call_for_resource(this.#on_resource_start, resource_name);
|
|
45
|
+
}
|
|
46
|
+
@Event("onResourceStop")
|
|
47
|
+
on_resource_stop(resource_name) {
|
|
48
|
+
this.#call_for_resource(this.#on_resource_stop, resource_name);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!globalThis.RESOURCE_WRAPPER) {
|
|
52
|
+
globalThis.RESOURCE_WRAPPER = new ResourceWrapper();
|
|
53
|
+
}
|
|
54
|
+
const RESOURCE_WRAPPER = globalThis.RESOURCE_WRAPPER;
|
|
55
|
+
function OnResourceStart(resource = GetCurrentResourceName()) {
|
|
56
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
57
|
+
if (context.private) {
|
|
58
|
+
throw new Error("OnResourceStart does not work on private types, please mark the field as public");
|
|
59
|
+
}
|
|
60
|
+
context.addInitializer(() => {
|
|
61
|
+
if (GetResourceState(resource) === "started") {
|
|
62
|
+
setImmediate(() => originalMethod.call());
|
|
63
|
+
}
|
|
64
|
+
RESOURCE_WRAPPER.add_to_resource_start(resource, originalMethod);
|
|
65
|
+
});
|
|
66
|
+
}, "actualDecorator");
|
|
67
|
+
}
|
|
68
|
+
__name(OnResourceStart, "OnResourceStart");
|
|
69
|
+
function OnResoureStop(resource = GetCurrentResourceName()) {
|
|
70
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
71
|
+
if (context.private) {
|
|
72
|
+
throw new Error("OnResourceStop does not work on private types, please mark the field as public");
|
|
73
|
+
}
|
|
74
|
+
context.addInitializer(() => {
|
|
75
|
+
RESOURCE_WRAPPER.add_to_resource_stop(resource, originalMethod);
|
|
76
|
+
});
|
|
77
|
+
}, "actualDecorator");
|
|
78
|
+
}
|
|
79
|
+
__name(OnResoureStop, "OnResoureStop");
|
|
80
|
+
export {
|
|
81
|
+
OnResourceStart,
|
|
82
|
+
OnResoureStop
|
|
83
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets called per server/client tick, this is asyncronous though, if you await
|
|
3
|
+
* in it, it will not be called until whatever was being awaited resolves.
|
|
4
|
+
*/
|
|
5
|
+
export declare function SetTick(): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Gets called on the frame after the class is initialized.
|
|
8
|
+
*/
|
|
9
|
+
export declare function SetImmediate(): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
package/decors/Ticks.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
function SetTick() {
|
|
4
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
5
|
+
if (context.private) {
|
|
6
|
+
throw new Error("SetTick does not work on private types, please mark the field as public");
|
|
7
|
+
}
|
|
8
|
+
context.addInitializer(function() {
|
|
9
|
+
setTick(async () => {
|
|
10
|
+
await originalMethod.call(this);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}, "actualDecorator");
|
|
14
|
+
}
|
|
15
|
+
__name(SetTick, "SetTick");
|
|
16
|
+
function SetImmediate() {
|
|
17
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
18
|
+
if (context.private) {
|
|
19
|
+
throw new Error("SetTick does not work on private types, please mark the field as public");
|
|
20
|
+
}
|
|
21
|
+
context.addInitializer(function() {
|
|
22
|
+
setImmediate(async () => {
|
|
23
|
+
await originalMethod.call(this);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}, "actualDecorator");
|
|
27
|
+
}
|
|
28
|
+
__name(SetImmediate, "SetImmediate");
|
|
29
|
+
export {
|
|
30
|
+
SetImmediate,
|
|
31
|
+
SetTick
|
|
32
|
+
};
|
package/index.d.ts
CHANGED
|
@@ -18,4 +18,9 @@ export * from "./utils/getStringFromUInt8Array";
|
|
|
18
18
|
export * from "./utils/getUInt32FromUint8Array";
|
|
19
19
|
export * from "./utils/randomInt";
|
|
20
20
|
export * from "./net/NetworkedMap";
|
|
21
|
-
export * from "./decors/
|
|
21
|
+
export * from "./decors/ConVar";
|
|
22
|
+
export * from "./decors/Events";
|
|
23
|
+
export * from "./decors/Exports";
|
|
24
|
+
export * from "./decors/Permissions";
|
|
25
|
+
export * from "./decors/Resources";
|
|
26
|
+
export * from "./decors/Ticks";
|
package/index.js
CHANGED
|
@@ -18,4 +18,9 @@ export * from "./utils/getStringFromUInt8Array";
|
|
|
18
18
|
export * from "./utils/getUInt32FromUint8Array";
|
|
19
19
|
export * from "./utils/randomInt";
|
|
20
20
|
export * from "./net/NetworkedMap";
|
|
21
|
-
export * from "./decors/
|
|
21
|
+
export * from "./decors/ConVar";
|
|
22
|
+
export * from "./decors/Events";
|
|
23
|
+
export * from "./decors/Exports";
|
|
24
|
+
export * from "./decors/Permissions";
|
|
25
|
+
export * from "./decors/Resources";
|
|
26
|
+
export * from "./decors/Ticks";
|