@nativewrappers/common 0.0.126 → 0.0.128

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 (103) hide show
  1. package/common-game/CommonGameConstants.d.ts +7 -0
  2. package/common-game/CommonGameConstants.js +24 -0
  3. package/common-game/CommonModel.d.ts +99 -0
  4. package/common-game/CommonModel.js +172 -0
  5. package/common-game/CommonTasks.d.ts +44 -0
  6. package/common-game/CommonTasks.js +233 -0
  7. package/common-game/cfx/StateBagChangeHandler.d.ts +1 -0
  8. package/common-game/cfx/StateBagChangeHandler.js +0 -0
  9. package/common-game/cfx/cfx.d.ts +6 -0
  10. package/common-game/cfx/cfx.js +4 -0
  11. package/common-game/common/Command.d.ts +77 -0
  12. package/common-game/common/Command.js +152 -0
  13. package/common-game/common/Convar.d.ts +13 -0
  14. package/common-game/common/Convar.js +58 -0
  15. package/common-game/common/GlobalData.d.ts +12 -0
  16. package/common-game/common/GlobalData.js +20 -0
  17. package/common-game/common/Kvp.d.ts +69 -0
  18. package/common-game/common/Kvp.js +137 -0
  19. package/common-game/common/Resource.d.ts +14 -0
  20. package/common-game/common/Resource.js +54 -0
  21. package/common-game/common/decors/ConVar.d.ts +14 -0
  22. package/common-game/common/decors/ConVar.js +70 -0
  23. package/common-game/common/decors/Events.d.ts +66 -0
  24. package/common-game/common/decors/Events.js +163 -0
  25. package/common-game/common/decors/Exports.d.ts +1 -0
  26. package/common-game/common/decors/Exports.js +53 -0
  27. package/common-game/common/decors/Permissions.d.ts +3 -0
  28. package/common-game/common/decors/Permissions.js +49 -0
  29. package/common-game/common/decors/Resources.d.ts +8 -0
  30. package/common-game/common/decors/Resources.js +94 -0
  31. package/common-game/common/decors/Ticks.d.ts +9 -0
  32. package/common-game/common/decors/Ticks.js +32 -0
  33. package/common-game/common/net/NetworkedMap.d.ts +28 -0
  34. package/common-game/common/net/NetworkedMap.js +225 -0
  35. package/common-game/common/types.d.ts +5 -0
  36. package/common-game/common/types.js +0 -0
  37. package/common-game/common/utils/ClassTypes.d.ts +11 -0
  38. package/common-game/common/utils/ClassTypes.js +15 -0
  39. package/common-game/common/utils/Color.d.ts +14 -0
  40. package/common-game/common/utils/Color.js +33 -0
  41. package/common-game/common/utils/Delay.d.ts +1 -0
  42. package/common-game/common/utils/Delay.js +6 -0
  43. package/common-game/common/utils/Maths.d.ts +4 -0
  44. package/common-game/common/utils/Maths.js +18 -0
  45. package/common-game/common/utils/Point.d.ts +9 -0
  46. package/common-game/common/utils/Point.js +36 -0
  47. package/common-game/common/utils/PointF.d.ts +7 -0
  48. package/common-game/common/utils/PointF.js +18 -0
  49. package/common-game/common/utils/Quaternion.d.ts +10 -0
  50. package/common-game/common/utils/Quaternion.js +33 -0
  51. package/common-game/common/utils/Vector.d.ts +429 -0
  52. package/common-game/common/utils/Vector.js +589 -0
  53. package/common-game/common/utils/cleanPlayerName.d.ts +6 -0
  54. package/common-game/common/utils/cleanPlayerName.js +17 -0
  55. package/common-game/common/utils/enumValues.d.ts +12 -0
  56. package/common-game/common/utils/enumValues.js +20 -0
  57. package/common-game/common/utils/getStringFromUInt8Array.d.ts +8 -0
  58. package/common-game/common/utils/getStringFromUInt8Array.js +6 -0
  59. package/common-game/common/utils/getUInt32FromUint8Array.d.ts +8 -0
  60. package/common-game/common/utils/getUInt32FromUint8Array.js +6 -0
  61. package/common-game/common/utils/randomInt.d.ts +1 -0
  62. package/common-game/common/utils/randomInt.js +9 -0
  63. package/common-game/definitions/index.d.js +0 -0
  64. package/common-game/definitions/redm.d.js +0 -0
  65. package/common-game/entities/CommonBaseEntity.d.ts +116 -0
  66. package/common-game/entities/CommonBaseEntity.js +266 -0
  67. package/common-game/entities/CommonBaseEntityBone.d.ts +11 -0
  68. package/common-game/entities/CommonBaseEntityBone.js +32 -0
  69. package/common-game/entities/CommonBaseEntityBoneCollection.d.ts +9 -0
  70. package/common-game/entities/CommonBaseEntityBoneCollection.js +17 -0
  71. package/common-game/entities/CommonEntityBone.d.ts +5 -0
  72. package/common-game/entities/CommonEntityBone.js +14 -0
  73. package/common-game/entities/CommonEntityBoneCollection.d.ts +9 -0
  74. package/common-game/entities/CommonEntityBoneCollection.js +24 -0
  75. package/common-game/entities/CommonEntityType.d.ts +4 -0
  76. package/common-game/entities/CommonEntityType.js +0 -0
  77. package/common-game/entities/CommonPed.d.ts +16 -0
  78. package/common-game/entities/CommonPed.js +52 -0
  79. package/common-game/entities/CommonPedBone.d.ts +6 -0
  80. package/common-game/entities/CommonPedBone.js +17 -0
  81. package/common-game/entities/CommonPedBoneCollection.d.ts +10 -0
  82. package/common-game/entities/CommonPedBoneCollection.js +31 -0
  83. package/common-game/entities/CommonPlayer.d.ts +61 -0
  84. package/common-game/entities/CommonPlayer.js +156 -0
  85. package/common-game/entities/CommonProp.d.ts +15 -0
  86. package/common-game/entities/CommonProp.js +43 -0
  87. package/common-game/entities/CommonVehicle.d.ts +11 -0
  88. package/common-game/entities/CommonVehicle.js +36 -0
  89. package/common-game/entities/GetEntityClassIdFromHandle.d.ts +2 -0
  90. package/common-game/entities/GetEntityClassIdFromHandle.js +23 -0
  91. package/common-game/entities/IHandle.d.ts +6 -0
  92. package/common-game/entities/IHandle.js +20 -0
  93. package/common-game/enums/VehicleSeat.d.ts +13 -0
  94. package/common-game/enums/VehicleSeat.js +17 -0
  95. package/common-game/index.d.ts +50 -0
  96. package/common-game/index.js +50 -0
  97. package/common-game/interfaces/Dimension.d.ts +5 -0
  98. package/common-game/interfaces/Dimension.js +0 -0
  99. package/common-game/utils/Animations.d.ts +19 -0
  100. package/common-game/utils/Animations.js +43 -0
  101. package/index.d.ts +52 -1
  102. package/index.js +52 -1
  103. package/package.json +1 -1
@@ -0,0 +1,152 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { GlobalData } from "./GlobalData";
4
+ const commands = [];
5
+ $SERVER: {
6
+ on("playerJoining", () => emitNet("chat:addSuggestions", source, commands));
7
+ }
8
+ function registerCommand(name, commandHandler, restricted = true) {
9
+ if (Array.isArray(name)) {
10
+ for (const command of name) {
11
+ registerCommand(command, commandHandler, restricted);
12
+ }
13
+ return;
14
+ }
15
+ RegisterCommand(name, commandHandler, GlobalData.IS_CLIENT ? false : !!restricted);
16
+ $SERVER: {
17
+ const ace = `command.${name}`;
18
+ if (typeof restricted === "string") {
19
+ if (IsPrincipalAceAllowed(restricted, ace)) return;
20
+ return ExecuteCommand(`add_ace ${restricted} ${ace} allow`);
21
+ }
22
+ if (Array.isArray(restricted)) {
23
+ for (const principal of restricted) {
24
+ if (!IsPrincipalAceAllowed(principal, ace)) ExecuteCommand(`add_ace ${restricted} ${ace} allow`);
25
+ }
26
+ }
27
+ }
28
+ }
29
+ __name(registerCommand, "registerCommand");
30
+ class Command {
31
+ /**
32
+ * Registers a new executable command with optional parameter validation and permission restrictions.
33
+ * @param name The unique identifier(s) for the command, either as a single string or an array of strings.
34
+ * @param handler The function to execute when the command is executed.
35
+ * @param help A description of the command, displayed as a chat suggestion.
36
+ * @param params An optional array of parameter definitions specifying the command's expected arguments,
37
+ * including their names, types, and descriptive help text for chat suggestions.
38
+ * @param restricted Determines the command's access permissions:
39
+ * - Defaults to `true`, restricting usage to users with the "command.commandName" ACE permission.
40
+ * - A string such as `"group.admin"` grants the command permission to the specified principal.
41
+ * - An array of strings grants permission to multiple principals.
42
+ */
43
+ constructor(name, handler, help, params, restricted = true) {
44
+ this.name = name;
45
+ this.help = help;
46
+ this.params = params;
47
+ this.#handler = handler;
48
+ registerCommand(name, (source2, args, raw) => this.call(source2, args, raw), restricted);
49
+ if (params) {
50
+ for (const parameter of params) {
51
+ if (parameter.type) {
52
+ const defaultString = parameter.defaultValue !== void 0 ? `[default: ${parameter.defaultValue}]` : "";
53
+ const typeString = `[type: ${parameter.type}] ${defaultString}`;
54
+ parameter.help = parameter.help ? `${parameter.help} ${typeString}` : `${typeString}`;
55
+ }
56
+ }
57
+ }
58
+ setTimeout(() => {
59
+ const names = Array.isArray(name) ? name : [name];
60
+ for (const name2 of names) {
61
+ const commandObj = { ...this, name: `/${name2}` };
62
+ $SERVER: {
63
+ commands.push(commandObj);
64
+ emitNet("chat:addSuggestions", -1, commandObj);
65
+ }
66
+ $CLIENT: {
67
+ emit("chat:addSuggestion", commandObj);
68
+ }
69
+ }
70
+ }, 100);
71
+ }
72
+ static {
73
+ __name(this, "Command");
74
+ }
75
+ #handler;
76
+ /**
77
+ * Maps the arguments received from a command call to the defined parameters while validating the argument types.
78
+ * @param source The client that executed the command, or -1 if executed by the server.
79
+ * @param args The arguments passed to the command.
80
+ * @param raw The raw input string passed to the command.
81
+ * @returns A mapped object containing parsed parameters.
82
+ */
83
+ mapArguments(source2, args, raw) {
84
+ const mapped = {
85
+ source: source2,
86
+ raw
87
+ };
88
+ if (!this.params) return mapped;
89
+ const result = this.params.every((param, index) => {
90
+ const arg = args[index];
91
+ let value = arg;
92
+ const hasDefaultValue = param.defaultValue !== void 0;
93
+ const hasArg = typeof arg === "string";
94
+ if (!hasArg && hasDefaultValue) {
95
+ value = param.defaultValue;
96
+ } else {
97
+ switch (param.type) {
98
+ case "number":
99
+ if (hasDefaultValue && !hasArg) {
100
+ value = param.defaultValue;
101
+ } else {
102
+ value = +arg;
103
+ }
104
+ break;
105
+ case "string":
106
+ value = !Number(arg) ? arg : false;
107
+ break;
108
+ case "playerId":
109
+ $SERVER: {
110
+ value = arg === "me" ? source2 : +arg;
111
+ if (!value || !DoesPlayerExist(value.toString())) value = void 0;
112
+ }
113
+ $CLIENT: {
114
+ value = arg === "me" ? GetPlayerServerId(PlayerId()) : +arg;
115
+ if (!value || GetPlayerFromServerId(value) === -1) value = void 0;
116
+ }
117
+ break;
118
+ case "longString":
119
+ value = raw.substring(raw.indexOf(arg));
120
+ break;
121
+ }
122
+ }
123
+ if (value === void 0 && (!param.optional || param.optional && arg)) {
124
+ return Citizen.trace(
125
+ `^1command '${raw.split(" ")[0] || raw}' received an invalid ${param.type} for argument ${index + 1} (${param.name}), received '${arg}'^0`
126
+ );
127
+ }
128
+ mapped[param.name] = value;
129
+ return true;
130
+ });
131
+ return result ? mapped : null;
132
+ }
133
+ /**
134
+ * Executes the command with the given arguments and source, validating and mapping the arguments before calling the handler.
135
+ * @param source The client that executed the command.
136
+ * @param args The arguments passed to the command.
137
+ * @param raw The raw input string passed to the command.
138
+ */
139
+ async call(source2, args, raw = args.join(" ")) {
140
+ const parsed = this.mapArguments(source2, args, raw);
141
+ if (!parsed) return;
142
+ try {
143
+ await this.#handler(parsed);
144
+ } catch (err) {
145
+ Citizen.trace(`^1command '${raw.split(" ")[0] || raw}' failed to execute!^0
146
+ ${err.message}`);
147
+ }
148
+ }
149
+ }
150
+ export {
151
+ Command
152
+ };
@@ -0,0 +1,13 @@
1
+ export declare class Convar {
2
+ /**
3
+ * @returns the current console buffer
4
+ */
5
+ buffer(): string;
6
+ get(variable: string, defaultVar: string): string;
7
+ getInt(variable: string, defaultVar: number): number;
8
+ getFloat(varName: string, defaultVar: number): number;
9
+ getBool(varName: string, defaultVar: boolean): boolean;
10
+ set(variable: string, value: string): void;
11
+ setReplicated(variable: string, value: string): void;
12
+ setServerInfo(variable: string, value: string): void;
13
+ }
@@ -0,0 +1,58 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { GlobalData } from "./GlobalData";
4
+ class Convar {
5
+ static {
6
+ __name(this, "Convar");
7
+ }
8
+ /**
9
+ * @returns the current console buffer
10
+ */
11
+ buffer() {
12
+ $CLIENT: {
13
+ if (GlobalData.IS_CLIENT) {
14
+ throw new Error("This function isn't available on the client");
15
+ }
16
+ }
17
+ return GetConsoleBuffer();
18
+ }
19
+ get(variable, defaultVar) {
20
+ return GetConvar(variable, defaultVar);
21
+ }
22
+ getInt(variable, defaultVar) {
23
+ return GetConvarInt(variable, defaultVar);
24
+ }
25
+ getFloat(varName, defaultVar) {
26
+ return GetConvarFloat(varName, defaultVar);
27
+ }
28
+ getBool(varName, defaultVar) {
29
+ return GetConvarBool(varName, defaultVar);
30
+ }
31
+ set(variable, value) {
32
+ $CLIENT: {
33
+ if (GlobalData.IS_CLIENT) {
34
+ throw new Error("This function isn't available on the client");
35
+ }
36
+ }
37
+ SetConvar(variable, value);
38
+ }
39
+ setReplicated(variable, value) {
40
+ $CLIENT: {
41
+ if (GlobalData.IS_CLIENT) {
42
+ throw new Error("This function isn't available on the client");
43
+ }
44
+ }
45
+ SetConvarReplicated(variable, value);
46
+ }
47
+ setServerInfo(variable, value) {
48
+ $CLIENT: {
49
+ if (GlobalData.IS_CLIENT) {
50
+ throw new Error("This function isn't available on the client");
51
+ }
52
+ }
53
+ SetConvarServerInfo(variable, value);
54
+ }
55
+ }
56
+ export {
57
+ Convar
58
+ };
@@ -0,0 +1,12 @@
1
+ export declare class GlobalData {
2
+ static CurrentResource: string;
3
+ static GameName: string;
4
+ static GameBuild: number;
5
+ static IS_SERVER: boolean;
6
+ static IS_REDM: boolean;
7
+ static IS_FIVEM: boolean;
8
+ static IS_CLIENT: boolean;
9
+ static NetworkTick: number | null;
10
+ static NetworkedTicks: any[];
11
+ static EnablePrettyPrint: boolean;
12
+ }
@@ -0,0 +1,20 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ class GlobalData {
4
+ static {
5
+ __name(this, "GlobalData");
6
+ }
7
+ static CurrentResource = GetCurrentResourceName();
8
+ static GameName = GetGameName();
9
+ static GameBuild = GetGameBuildNumber();
10
+ static IS_SERVER = IsDuplicityVersion();
11
+ static IS_REDM = GetGameName() === "redm";
12
+ static IS_FIVEM = GetGameName() === "fivem";
13
+ static IS_CLIENT = !GlobalData.IS_SERVER;
14
+ static NetworkTick = null;
15
+ static NetworkedTicks = [];
16
+ static EnablePrettyPrint = true;
17
+ }
18
+ export {
19
+ GlobalData
20
+ };
@@ -0,0 +1,69 @@
1
+ type KvpSchema = Record<string, string | number | object>;
2
+ type KvpObject<T> = T extends `${infer Prefix}.${infer Rest}` ? Rest extends `${string}.${string}` ? never : Prefix : never;
3
+ type ValidJsonKey<Schema> = {
4
+ [K in keyof Schema]: K extends string ? `${K}.${string}` : never;
5
+ }[keyof Schema];
6
+ export declare class Kvp<Schema extends KvpSchema> {
7
+ /**
8
+ * Returns the value associated with a key as a number.
9
+ */
10
+ getNumber<K extends string & keyof Schema>(key: K): number;
11
+ /**
12
+ * Returns the value associated with a key as a float.
13
+ */
14
+ getFloat<K extends string & keyof Schema>(key: K): number;
15
+ /**
16
+ * Returns the value associated with a key as a string.
17
+ */
18
+ getString<K extends string & keyof Schema>(key: K): string | null;
19
+ /**
20
+ * Returns the value associated with a key as a parsed JSON string.
21
+ */
22
+ getJson<K extends string, O = KvpObject<K>>(key: K extends ValidJsonKey<O> ? K : never): (O extends string ? Schema[O] : null) | null;
23
+ /**
24
+ * Sets the value associated with a key as a number.
25
+ * @param async set the value using an async operation.
26
+ */
27
+ setNumber<K extends string & keyof Schema>(key: K, value: number, async?: boolean): void;
28
+ /**
29
+ * Sets the value associated with a key as a float.
30
+ * @param async set the value using an async operation.
31
+ */
32
+ setFloat<K extends string & keyof Schema>(key: K, value: number, async?: boolean): void;
33
+ /**
34
+ * Sets the value associated with a key as a string.
35
+ * @param async set the value using an async operation.
36
+ */
37
+ setString<K extends string & keyof Schema>(key: K, value: string, async?: boolean): void;
38
+ /**
39
+ * Sets the value associated with a key as a JSON string.
40
+ * @param async set the value using an async operation.
41
+ */
42
+ setJson<K extends string, O = KvpObject<K>>(key: K extends ValidJsonKey<O> ? K : never, value: O extends string ? Schema[O] : never, async?: boolean): void;
43
+ /**
44
+ * Sets the value associated with a key as a JSON string.
45
+ * @param async set the value using an async operation.
46
+ */
47
+ set<K extends string, O = KvpObject<K>>(key: K extends keyof Schema ? K : O extends string ? K : never, value: K extends keyof Schema ? Schema[K] : O extends string ? Schema[O] : never, async?: boolean): void;
48
+ /**
49
+ * Deletes the specified value for key.
50
+ * @param async remove the value using an async operation
51
+ */
52
+ delete(key: string, async?: boolean): void;
53
+ /**
54
+ * Commits pending asynchronous operations to disk, ensuring data consistency.
55
+ *
56
+ * Should be called after calling set methods using the async flag.
57
+ */
58
+ flush(): void;
59
+ getAllKeys(prefix: string): (keyof Schema)[];
60
+ /**
61
+ * Returns an array of keys which match or contain the given keys.
62
+ */
63
+ getKeys<K extends (string & keyof Schema) | string[]>(prefix: K): (keyof Schema)[];
64
+ /**
65
+ * Get all values from keys in an array as the specified type.
66
+ */
67
+ getValuesAsType<K extends (string & keyof Schema) | (string & keyof Schema)[]>(prefix: K, type: any): (string | number | Schema[string] | null)[];
68
+ }
69
+ export {};
@@ -0,0 +1,137 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ class Kvp {
4
+ static {
5
+ __name(this, "Kvp");
6
+ }
7
+ /**
8
+ * Returns the value associated with a key as a number.
9
+ */
10
+ getNumber(key) {
11
+ return GetResourceKvpInt(key);
12
+ }
13
+ /**
14
+ * Returns the value associated with a key as a float.
15
+ */
16
+ getFloat(key) {
17
+ return GetResourceKvpFloat(key);
18
+ }
19
+ /**
20
+ * Returns the value associated with a key as a string.
21
+ */
22
+ getString(key) {
23
+ return GetResourceKvpString(key);
24
+ }
25
+ /**
26
+ * Returns the value associated with a key as a parsed JSON string.
27
+ */
28
+ getJson(key) {
29
+ const str = GetResourceKvpString(key);
30
+ return str ? JSON.parse(str) : null;
31
+ }
32
+ /**
33
+ * Sets the value associated with a key as a number.
34
+ * @param async set the value using an async operation.
35
+ */
36
+ setNumber(key, value, async = false) {
37
+ return async ? SetResourceKvpIntNoSync(key, value) : SetResourceKvpInt(key, value);
38
+ }
39
+ /**
40
+ * Sets the value associated with a key as a float.
41
+ * @param async set the value using an async operation.
42
+ */
43
+ setFloat(key, value, async = false) {
44
+ return async ? SetResourceKvpFloatNoSync(key, value) : SetResourceKvpFloat(key, value);
45
+ }
46
+ /**
47
+ * Sets the value associated with a key as a string.
48
+ * @param async set the value using an async operation.
49
+ */
50
+ setString(key, value, async = false) {
51
+ return async ? SetResourceKvpNoSync(key, value) : SetResourceKvp(key, value);
52
+ }
53
+ /**
54
+ * Sets the value associated with a key as a JSON string.
55
+ * @param async set the value using an async operation.
56
+ */
57
+ setJson(key, value, async = false) {
58
+ const str = JSON.stringify(value);
59
+ return async ? SetResourceKvpNoSync(key, str) : SetResourceKvp(key, str);
60
+ }
61
+ /**
62
+ * Sets the value associated with a key as a JSON string.
63
+ * @param async set the value using an async operation.
64
+ */
65
+ set(key, value, async = false) {
66
+ switch (typeof value) {
67
+ case "function":
68
+ case "symbol":
69
+ throw new Error(`Failed to set Kvp for invalid type '${typeof value}'`);
70
+ case "undefined":
71
+ return this.delete(key, async);
72
+ case "object":
73
+ return this.setJson(key, value, async);
74
+ case "boolean":
75
+ value = value ? 1 : 0;
76
+ case "number":
77
+ return Number.isInteger(value) ? this.setNumber(key, value, async) : this.setFloat(key, value, async);
78
+ default:
79
+ value = String(value);
80
+ return this.setString(key, value, async);
81
+ }
82
+ }
83
+ /**
84
+ * Deletes the specified value for key.
85
+ * @param async remove the value using an async operation
86
+ */
87
+ delete(key, async = false) {
88
+ return async ? DeleteResourceKvpNoSync(key) : DeleteResourceKvp(key);
89
+ }
90
+ /**
91
+ * Commits pending asynchronous operations to disk, ensuring data consistency.
92
+ *
93
+ * Should be called after calling set methods using the async flag.
94
+ */
95
+ flush() {
96
+ FlushResourceKvp();
97
+ }
98
+ getAllKeys(prefix) {
99
+ const keys = [];
100
+ const handle = StartFindKvp(prefix);
101
+ if (handle === -1) return keys;
102
+ let key;
103
+ do {
104
+ key = FindKvp(handle);
105
+ if (key) keys.push(key);
106
+ } while (key);
107
+ EndFindKvp(handle);
108
+ return keys;
109
+ }
110
+ /**
111
+ * Returns an array of keys which match or contain the given keys.
112
+ */
113
+ getKeys(prefix) {
114
+ return typeof prefix === "string" ? this.getAllKeys(prefix) : prefix.flatMap((key) => this.getAllKeys(key));
115
+ }
116
+ /**
117
+ * Get all values from keys in an array as the specified type.
118
+ */
119
+ getValuesAsType(prefix, type) {
120
+ const values = this.getKeys(prefix);
121
+ return values.map((key) => {
122
+ switch (type) {
123
+ case "number":
124
+ return this.getNumber(key);
125
+ case "float":
126
+ return this.getFloat(key);
127
+ case "string":
128
+ return this.getString(key);
129
+ default:
130
+ return this.getJson(key);
131
+ }
132
+ });
133
+ }
134
+ }
135
+ export {
136
+ Kvp
137
+ };
@@ -0,0 +1,14 @@
1
+ export declare class Resource {
2
+ name: string;
3
+ constructor(name: string);
4
+ getMetadata(metadataKey: string, index: number): string;
5
+ getPath(): string;
6
+ loadFile(fileName: string): string;
7
+ saveFile(fileName: string, data: string, length: number): boolean;
8
+ scheduleTick(): void;
9
+ start(): void;
10
+ stop(): void;
11
+ static startResource(name: string): void;
12
+ static stopResource(name: string): void;
13
+ static resourceCount(): number;
14
+ }
@@ -0,0 +1,54 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { GlobalData } from "./GlobalData";
4
+ class Resource {
5
+ constructor(name) {
6
+ this.name = name;
7
+ }
8
+ static {
9
+ __name(this, "Resource");
10
+ }
11
+ getMetadata(metadataKey, index) {
12
+ return GetResourceMetadata(this.name, metadataKey, index);
13
+ }
14
+ getPath() {
15
+ return GetResourcePath(this.name);
16
+ }
17
+ loadFile(fileName) {
18
+ return LoadResourceFile(this.name, fileName);
19
+ }
20
+ saveFile(fileName, data, length) {
21
+ $CLIENT: {
22
+ if (GlobalData.IS_CLIENT) {
23
+ throw new Error("This function isn't available on the client");
24
+ }
25
+ }
26
+ return SaveResourceFile(this.name, fileName, data, length);
27
+ }
28
+ scheduleTick() {
29
+ $CLIENT: {
30
+ if (GlobalData.IS_CLIENT) {
31
+ throw new Error("This function isn't available on the client");
32
+ }
33
+ }
34
+ return ScheduleResourceTick(this.name);
35
+ }
36
+ start() {
37
+ StartResource(this.name);
38
+ }
39
+ stop() {
40
+ StopResource(this.name);
41
+ }
42
+ static startResource(name) {
43
+ StartResource(name);
44
+ }
45
+ static stopResource(name) {
46
+ StopResource(name);
47
+ }
48
+ static resourceCount() {
49
+ return GetNumResources();
50
+ }
51
+ }
52
+ export {
53
+ Resource
54
+ };
@@ -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 {};
@@ -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
+ };
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Disables pretty printing in error messages
3
+ */
4
+ export declare const DisablePrettyPrint: () => boolean;
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
+ }
24
+ /**
25
+ * Registers the Event call for {@link eventName} to this method.
26
+ *
27
+ * This has internal pretty-printing to make errors easier to track, if
28
+ * you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
29
+ * using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
30
+ * @param eventName the event to bind to
31
+ */
32
+ export declare function CfxEvent(eventName: string, binding?: Binding): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
33
+ /**
34
+ * Registers the Event call for {@link eventName} to this method.
35
+ *
36
+ * This has internal pretty-printing to make errors easier to track, if
37
+ * you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
38
+ * using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
39
+ *
40
+ * @param eventName the event to bind to
41
+ */
42
+ export declare function Event(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
43
+ /**
44
+ * Registers the Net Event call for {@link eventName} to this method
45
+ *
46
+ *
47
+ * This has internal pretty-printing to make errors easier to track, if
48
+ * you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
49
+ * using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
50
+ *
51
+ * @param eventName the event to bind this net event to
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
53
+ */
54
+ export declare function NetEvent(eventName: string, remoteOnly?: boolean): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
55
+ export type NuiCallback = (data: string) => void;
56
+ /**
57
+ * Registers the NUI Event call for {eventName} to this method, the function signature
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
+ *
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.
65
+ */
66
+ export declare function NuiEvent(eventName: string, dontErrorWhenCbIsntInvoked?: boolean): (originalMethod: any, context: ClassMethodDecoratorContext) => void;