@nativewrappers/fivem 0.0.137 → 0.0.138
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/common/BaseScript.d.ts +2 -0
- package/common/BaseScript.js +10 -0
- package/common/Command.js +6 -4
- package/common/GlobalData.d.ts +1 -0
- package/common/GlobalData.js +3 -0
- package/common/decors/Events.js +2 -2
- package/common/decors/Resources.d.ts +10 -2
- package/common/decors/Resources.js +35 -10
- package/common/net/NetworkedMap.d.ts +2 -2
- package/common/net/NetworkedMap.js +13 -1
- package/common-game/entities/CommonBaseEntityBone.d.ts +4 -4
- package/common-game/entities/CommonBaseEntityBone.js +11 -7
- package/common-game/entities/CommonEntityBone.d.ts +1 -1
- package/common-game/entities/CommonEntityBone.js +2 -2
- package/common-game/entities/CommonPedBone.d.ts +1 -1
- package/common-game/entities/CommonPedBone.js +2 -2
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
package/common/Command.js
CHANGED
|
@@ -14,6 +14,9 @@ function registerCommand(name, commandHandler, restricted = true) {
|
|
|
14
14
|
}
|
|
15
15
|
RegisterCommand(name, commandHandler, GlobalData.IS_CLIENT ? false : !!restricted);
|
|
16
16
|
$SERVER: {
|
|
17
|
+
$CLIENT: {
|
|
18
|
+
if (GlobalData.IS_CLIENT) return;
|
|
19
|
+
}
|
|
17
20
|
const ace = `command.${name}`;
|
|
18
21
|
if (typeof restricted === "string") {
|
|
19
22
|
if (IsPrincipalAceAllowed(restricted, ace)) return;
|
|
@@ -59,13 +62,12 @@ class Command {
|
|
|
59
62
|
const names = Array.isArray(name) ? name : [name];
|
|
60
63
|
for (const name2 of names) {
|
|
61
64
|
const commandObj = { ...this, name: `/${name2}` };
|
|
62
|
-
|
|
65
|
+
if (GlobalData.IS_CLIENT) {
|
|
66
|
+
emit("chat:addSuggestion", commandObj);
|
|
67
|
+
} else {
|
|
63
68
|
commands.push(commandObj);
|
|
64
69
|
emitNet("chat:addSuggestions", -1, commandObj);
|
|
65
70
|
}
|
|
66
|
-
$CLIENT: {
|
|
67
|
-
emit("chat:addSuggestion", commandObj);
|
|
68
|
-
}
|
|
69
71
|
}
|
|
70
72
|
}, 100);
|
|
71
73
|
}
|
package/common/GlobalData.d.ts
CHANGED
package/common/GlobalData.js
CHANGED
|
@@ -9,6 +9,8 @@ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
|
|
9
9
|
ErrorType2[ErrorType2["Immediate"] = 5] = "Immediate";
|
|
10
10
|
return ErrorType2;
|
|
11
11
|
})(ErrorType || {});
|
|
12
|
+
globalThis.OnError = (type, err) => {
|
|
13
|
+
};
|
|
12
14
|
class GlobalData {
|
|
13
15
|
static {
|
|
14
16
|
__name(this, "GlobalData");
|
|
@@ -27,6 +29,7 @@ class GlobalData {
|
|
|
27
29
|
* Called when one of the decors errors
|
|
28
30
|
*/
|
|
29
31
|
static OnError = /* @__PURE__ */ __name((type, err) => {
|
|
32
|
+
globalThis.OnError(type, err);
|
|
30
33
|
}, "OnError");
|
|
31
34
|
}
|
|
32
35
|
export {
|
package/common/decors/Events.js
CHANGED
|
@@ -20,7 +20,7 @@ function OnEvent(eventName) {
|
|
|
20
20
|
console.error("------- EVENT ERROR --------");
|
|
21
21
|
console.error(`Call to ${eventName} errored`);
|
|
22
22
|
console.error(`Data: ${JSON.stringify(args)}`);
|
|
23
|
-
|
|
23
|
+
globalThis.printError("event", e);
|
|
24
24
|
console.error("------- END EVENT ERROR --------");
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -70,7 +70,7 @@ function OnNetEvent(eventName, remoteOnly = true) {
|
|
|
70
70
|
console.error(`Call to ${eventName} errored`);
|
|
71
71
|
console.error(`Caller: ${src}`);
|
|
72
72
|
console.error(`Data: ${JSON.stringify(args)}`);
|
|
73
|
-
|
|
73
|
+
globalThis.printError("net event", e);
|
|
74
74
|
console.error("------- END NET EVENT ERROR --------");
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
type ResourceName = string;
|
|
2
|
+
type ResourceOrGlobal = ResourceName | "global";
|
|
3
|
+
export declare const EnsureResourceWrapperInit: () => void;
|
|
1
4
|
/**
|
|
2
5
|
* Called whenever the specified resource is started, this will be called once on once on resource start if the resource is started.
|
|
6
|
+
* NOTE: If you want to listen to *all* resource start/stop events you should send
|
|
7
|
+
* {@link resource} as "global"
|
|
3
8
|
*/
|
|
4
|
-
export declare function OnResourceStart(resource?:
|
|
9
|
+
export declare function OnResourceStart(resource?: ResourceOrGlobal): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
5
10
|
/**
|
|
6
11
|
* Called whenever the specified resource is stopped.
|
|
12
|
+
* NOTE: If you want to listen to *all* resource start/stop events you should send
|
|
13
|
+
* {@link resource} as "global"
|
|
7
14
|
*/
|
|
8
|
-
export declare function OnResourceStop(resource?:
|
|
15
|
+
export declare function OnResourceStop(resource?: ResourceOrGlobal): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
16
|
+
export {};
|
|
@@ -7,6 +7,10 @@ class ResourceWrapper {
|
|
|
7
7
|
}
|
|
8
8
|
#on_resource_start = /* @__PURE__ */ new Map();
|
|
9
9
|
#on_resource_stop = /* @__PURE__ */ new Map();
|
|
10
|
+
// used for global resource/start/stops, callers have to define their listener
|
|
11
|
+
// as "global"
|
|
12
|
+
#global_on_resource_start = [];
|
|
13
|
+
#global_on_resource_stop = [];
|
|
10
14
|
#add_or_init(resource_fn_map, resource_name, fn) {
|
|
11
15
|
const fn_array = resource_fn_map.get(resource_name);
|
|
12
16
|
if (fn_array) {
|
|
@@ -21,7 +25,11 @@ class ResourceWrapper {
|
|
|
21
25
|
* @param fn The function to call
|
|
22
26
|
*/
|
|
23
27
|
add_to_resource_start(resource_name, fn) {
|
|
24
|
-
|
|
28
|
+
if (resource_name === "global") {
|
|
29
|
+
this.#global_on_resource_start.push(fn);
|
|
30
|
+
} else {
|
|
31
|
+
this.#add_or_init(this.#on_resource_start, resource_name, fn);
|
|
32
|
+
}
|
|
25
33
|
}
|
|
26
34
|
/**
|
|
27
35
|
* Adds a function to get called whenever a resource is stopped
|
|
@@ -29,31 +37,47 @@ class ResourceWrapper {
|
|
|
29
37
|
* @param fn The function to call
|
|
30
38
|
*/
|
|
31
39
|
add_to_resource_stop(resource_name, fn) {
|
|
32
|
-
|
|
40
|
+
if (resource_name === "global") {
|
|
41
|
+
this.#global_on_resource_stop.push(fn);
|
|
42
|
+
} else {
|
|
43
|
+
this.#add_or_init(this.#on_resource_stop, resource_name, fn);
|
|
44
|
+
}
|
|
33
45
|
}
|
|
34
|
-
#call_for_resource(resource_fn_map, resource_name) {
|
|
46
|
+
#call_for_resource(resource_fn_map, global_array, resource_name) {
|
|
35
47
|
const functions = resource_fn_map.get(resource_name);
|
|
36
48
|
if (functions) {
|
|
37
49
|
for (const fn of functions) {
|
|
38
|
-
|
|
50
|
+
try {
|
|
51
|
+
fn(resource_name);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const fn of global_array) {
|
|
57
|
+
try {
|
|
58
|
+
fn(resource_name);
|
|
59
|
+
} catch (e) {
|
|
39
60
|
}
|
|
40
61
|
}
|
|
41
62
|
}
|
|
42
63
|
@Event("onResourceStart")
|
|
43
64
|
on_resource_start(resource_name) {
|
|
44
|
-
this.#call_for_resource(this.#on_resource_start, resource_name);
|
|
65
|
+
this.#call_for_resource(this.#on_resource_start, this.#global_on_resource_start, resource_name);
|
|
45
66
|
}
|
|
46
67
|
@Event("onResourceStop")
|
|
47
68
|
on_resource_stop(resource_name) {
|
|
48
|
-
this.#call_for_resource(this.#on_resource_stop, resource_name);
|
|
69
|
+
this.#call_for_resource(this.#on_resource_stop, this.#global_on_resource_stop, resource_name);
|
|
49
70
|
}
|
|
50
71
|
}
|
|
51
|
-
|
|
52
|
-
globalThis.RESOURCE_WRAPPER
|
|
53
|
-
|
|
72
|
+
const EnsureResourceWrapperInit = /* @__PURE__ */ __name(() => {
|
|
73
|
+
if (!globalThis.RESOURCE_WRAPPER) {
|
|
74
|
+
globalThis.RESOURCE_WRAPPER = new ResourceWrapper();
|
|
75
|
+
}
|
|
76
|
+
}, "EnsureResourceWrapperInit");
|
|
77
|
+
EnsureResourceWrapperInit();
|
|
54
78
|
const RESOURCE_WRAPPER = globalThis.RESOURCE_WRAPPER;
|
|
55
79
|
const onResourceStart = /* @__PURE__ */ __name((resource, originalMethod) => {
|
|
56
|
-
if (GetResourceState(resource) === "started") {
|
|
80
|
+
if (resource !== "global" && GetResourceState(resource) === "started") {
|
|
57
81
|
setImmediate(() => originalMethod.call());
|
|
58
82
|
}
|
|
59
83
|
RESOURCE_WRAPPER.add_to_resource_start(resource, originalMethod);
|
|
@@ -89,6 +113,7 @@ function OnResourceStop(resource = GetCurrentResourceName()) {
|
|
|
89
113
|
}
|
|
90
114
|
__name(OnResourceStop, "OnResourceStop");
|
|
91
115
|
export {
|
|
116
|
+
EnsureResourceWrapperInit,
|
|
92
117
|
OnResourceStart,
|
|
93
118
|
OnResourceStop
|
|
94
119
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type ChangeListener<V> = (value: V) => void;
|
|
1
|
+
type ChangeListener<V> = (value: V | undefined) => void;
|
|
2
2
|
/**
|
|
3
3
|
* not ready to be used just thoughts right now
|
|
4
4
|
*/
|
|
@@ -13,7 +13,7 @@ export declare class NetworkedMap<K, V> extends Map<K, V> {
|
|
|
13
13
|
hasSubscriber(sub: number): boolean;
|
|
14
14
|
subscriberCount(): number;
|
|
15
15
|
private handleSync;
|
|
16
|
-
listenForChange(key: K, fn: ChangeListener<V>): void;
|
|
16
|
+
listenForChange(key: K, fn: ChangeListener<V | undefined>): void;
|
|
17
17
|
set(key: K, value: V): this;
|
|
18
18
|
clear(): void;
|
|
19
19
|
delete(key: K): boolean;
|
|
@@ -76,7 +76,10 @@ class NetworkedMap extends Map {
|
|
|
76
76
|
console.error(`[NetworkedMap:resync] Tried to call resync on a source that wasn't already subscribed`);
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
|
-
const packed_data = msgpack_pack([
|
|
79
|
+
const packed_data = msgpack_pack([
|
|
80
|
+
this.#syncName,
|
|
81
|
+
[[5 /* Resync */, this.size === 0 ? [] : Array.from(this)]]
|
|
82
|
+
]);
|
|
80
83
|
TriggerClientEventInternal(
|
|
81
84
|
`${GlobalData.CurrentResource}:syncChanges`,
|
|
82
85
|
source2,
|
|
@@ -115,6 +118,13 @@ class NetworkedMap extends Map {
|
|
|
115
118
|
super.clear();
|
|
116
119
|
continue;
|
|
117
120
|
}
|
|
121
|
+
case 5 /* Resync */: {
|
|
122
|
+
for (const [, v] of this.#changeListeners) {
|
|
123
|
+
for (const fn of v) {
|
|
124
|
+
fn(void 0);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
118
128
|
case 4 /* Init */: {
|
|
119
129
|
super.clear();
|
|
120
130
|
const key_value = key;
|
|
@@ -134,6 +144,8 @@ class NetworkedMap extends Map {
|
|
|
134
144
|
/*
|
|
135
145
|
* Listens for the change on the specified key, it will get the resulting
|
|
136
146
|
* value on the change
|
|
147
|
+
* NOTE: When the server calls `resync` this will get ran with `undefined` for
|
|
148
|
+
* every change listener.
|
|
137
149
|
*/
|
|
138
150
|
listenForChange(key, fn) {
|
|
139
151
|
const listener = this.#changeListeners.get(key);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Vector3 } from "../../common/utils/Vector";
|
|
2
|
-
import
|
|
3
|
-
export declare abstract class CommonBaseEntityBone {
|
|
2
|
+
import { IHandle } from "./IHandle";
|
|
3
|
+
export declare abstract class CommonBaseEntityBone extends IHandle {
|
|
4
4
|
protected readonly owner: IHandle;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
constructor(owner: IHandle, boneInfo: number | string);
|
|
6
|
+
exists(): boolean;
|
|
7
7
|
get Index(): number;
|
|
8
8
|
get Owner(): IHandle;
|
|
9
9
|
get Position(): Vector3;
|
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import { Vector3 } from "../../common/utils/Vector";
|
|
4
|
-
|
|
4
|
+
import { IHandle } from "./IHandle";
|
|
5
|
+
class CommonBaseEntityBone extends IHandle {
|
|
5
6
|
static {
|
|
6
7
|
__name(this, "CommonBaseEntityBone");
|
|
7
8
|
}
|
|
8
9
|
owner;
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
constructor(owner, boneInfo) {
|
|
11
|
+
super(typeof boneInfo === "number" ? boneInfo : GetEntityBoneIndexByName(owner.Handle, boneInfo));
|
|
11
12
|
this.owner = owner;
|
|
12
|
-
|
|
13
|
+
}
|
|
14
|
+
// overwrite the `IHandle` exists function call
|
|
15
|
+
exists() {
|
|
16
|
+
return this.handle !== -1;
|
|
13
17
|
}
|
|
14
18
|
get Index() {
|
|
15
|
-
return this.
|
|
19
|
+
return this.handle;
|
|
16
20
|
}
|
|
17
21
|
get Owner() {
|
|
18
22
|
return this.owner;
|
|
19
23
|
}
|
|
20
24
|
get Position() {
|
|
21
|
-
return Vector3.fromArray(GetWorldPositionOfEntityBone(this.owner.Handle, this.
|
|
25
|
+
return Vector3.fromArray(GetWorldPositionOfEntityBone(this.owner.Handle, this.handle));
|
|
22
26
|
}
|
|
23
27
|
// public get Rotation(): Vector3 {
|
|
24
28
|
// return Vector3.fromArray(GetEntityBoneRotation(this.owner.Handle, this.index));
|
|
25
29
|
// }
|
|
26
30
|
get IsValid() {
|
|
27
|
-
return this.owner.exists() && this.
|
|
31
|
+
return this.owner.exists() && this.handle !== -1;
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
export {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommonBaseEntityBone } from "./CommonBaseEntityBone";
|
|
2
2
|
import type { IHandle } from "./IHandle";
|
|
3
3
|
export declare class CommonEntityBone extends CommonBaseEntityBone {
|
|
4
|
-
constructor(owner: IHandle,
|
|
4
|
+
constructor(owner: IHandle, boneIndexOrBoneName: number | string);
|
|
5
5
|
}
|
|
@@ -5,8 +5,8 @@ class CommonEntityBone extends CommonBaseEntityBone {
|
|
|
5
5
|
static {
|
|
6
6
|
__name(this, "CommonEntityBone");
|
|
7
7
|
}
|
|
8
|
-
constructor(owner,
|
|
9
|
-
super(owner,
|
|
8
|
+
constructor(owner, boneIndexOrBoneName) {
|
|
9
|
+
super(owner, boneIndexOrBoneName);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CommonBaseEntityBone } from "./CommonBaseEntityBone";
|
|
2
2
|
import type { IHandle } from "./IHandle";
|
|
3
3
|
export declare class CommonPedBone extends CommonBaseEntityBone {
|
|
4
|
-
constructor(owner: IHandle,
|
|
4
|
+
constructor(owner: IHandle, boneIndex: number);
|
|
5
5
|
get IsValid(): boolean;
|
|
6
6
|
}
|
|
@@ -5,8 +5,8 @@ class CommonPedBone extends CommonBaseEntityBone {
|
|
|
5
5
|
static {
|
|
6
6
|
__name(this, "CommonPedBone");
|
|
7
7
|
}
|
|
8
|
-
constructor(owner,
|
|
9
|
-
super(owner,
|
|
8
|
+
constructor(owner, boneIndex) {
|
|
9
|
+
super(owner, boneIndex);
|
|
10
10
|
}
|
|
11
11
|
get IsValid() {
|
|
12
12
|
return this.Owner.exists() && this.Index !== -1;
|
package/index.d.ts
CHANGED
|
@@ -172,6 +172,7 @@ export * from "./common-game/definitions/index.d";
|
|
|
172
172
|
export * from "./common-game/definitions/redm.d";
|
|
173
173
|
export * from "./common-game/cfx/StateBagChangeHandler";
|
|
174
174
|
export * from "./common-game/cfx/cfx";
|
|
175
|
+
export * from "./common/BaseScript";
|
|
175
176
|
export * from "./common/Command";
|
|
176
177
|
export * from "./common/Convar";
|
|
177
178
|
export * from "./common/GlobalData";
|
package/index.js
CHANGED
|
@@ -172,6 +172,7 @@ export * from "./common-game/definitions/index.d";
|
|
|
172
172
|
export * from "./common-game/definitions/redm.d";
|
|
173
173
|
export * from "./common-game/cfx/StateBagChangeHandler";
|
|
174
174
|
export * from "./common-game/cfx/cfx";
|
|
175
|
+
export * from "./common/BaseScript";
|
|
175
176
|
export * from "./common/Command";
|
|
176
177
|
export * from "./common/Convar";
|
|
177
178
|
export * from "./common/GlobalData";
|