@nativewrappers/common 0.0.125 → 0.0.127

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,163 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { GlobalData } from "../GlobalData";
4
+ const DisablePrettyPrint = /* @__PURE__ */ __name(() => GlobalData.EnablePrettyPrint = false, "DisablePrettyPrint");
5
+ const AsyncFunction = (async () => {
6
+ }).constructor;
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
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
16
+ if (context.private) {
17
+ throw new Error("Event does not work on private methods, please mark the method as public");
18
+ }
19
+ context.addInitializer(function() {
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
+ }
34
+ if (!hasPermission) {
35
+ emit("@nativewrappers:no_permission", { eventName, method: context.name });
36
+ return;
37
+ }
38
+ }
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
+ });
53
+ });
54
+ }, "actualDecorator");
55
+ }
56
+ __name(CfxEvent, "CfxEvent");
57
+ function Event(eventName) {
58
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
59
+ if (context.private) {
60
+ throw new Error("Event does not work on private methods, please mark the method as public");
61
+ }
62
+ context.addInitializer(function() {
63
+ on(eventName, async (...args) => {
64
+ try {
65
+ return await originalMethod.call(this, ...args);
66
+ } catch (e) {
67
+ REMOVE_EVENT_LOG: {
68
+ if (!GlobalData.EnablePrettyPrint) return;
69
+ console.error("------- EVENT ERROR --------");
70
+ console.error(`Call to ${eventName} errored`);
71
+ console.error(`Data: ${JSON.stringify(args)}`);
72
+ console.error(`Error: ${e}`);
73
+ console.error("------- END EVENT ERROR --------");
74
+ }
75
+ }
76
+ });
77
+ });
78
+ }, "actualDecorator");
79
+ }
80
+ __name(Event, "Event");
81
+ function NetEvent(eventName, remoteOnly = true) {
82
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
83
+ if (context.private) {
84
+ throw new Error("NetEvent does not work on private methods, please mark the method as public");
85
+ }
86
+ context.addInitializer(function() {
87
+ const _t = this;
88
+ onNet(eventName, async (...args) => {
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
+ }
106
+ try {
107
+ $CLIENT: {
108
+ if (GlobalData.IS_CLIENT && remoteOnly && source !== 65535) {
109
+ return;
110
+ }
111
+ }
112
+ return await originalMethod.call(this, ...args);
113
+ } catch (e) {
114
+ REMOVE_NET_EVENT_LOG: {
115
+ if (!GlobalData.EnablePrettyPrint) return;
116
+ console.error("------- NET EVENT ERROR --------");
117
+ console.error(`Call to ${eventName} errored`);
118
+ console.error(`Caller: ${src}`);
119
+ console.error(`Data: ${JSON.stringify(args)}`);
120
+ console.error(`Error: ${e}`);
121
+ console.error("------- END NET EVENT ERROR --------");
122
+ }
123
+ }
124
+ });
125
+ });
126
+ }, "actualDecorator");
127
+ }
128
+ __name(NetEvent, "NetEvent");
129
+ function NuiEvent(eventName, dontErrorWhenCbIsntInvoked = false) {
130
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
131
+ if (context.private) {
132
+ throw new Error("NuiEvent does not work on private methods, please mark the method as public");
133
+ }
134
+ context.addInitializer(function() {
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);
150
+ }
151
+ });
152
+ });
153
+ }, "actualDecorator");
154
+ }
155
+ __name(NuiEvent, "NuiEvent");
156
+ export {
157
+ Binding,
158
+ CfxEvent,
159
+ DisablePrettyPrint,
160
+ Event,
161
+ NetEvent,
162
+ NuiEvent
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 OnResourceStop(resource?: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
@@ -0,0 +1,94 @@
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
+ const onResourceStart = /* @__PURE__ */ __name((resource, originalMethod) => {
56
+ if (GetResourceState(resource) === "started") {
57
+ setImmediate(() => originalMethod.call());
58
+ }
59
+ RESOURCE_WRAPPER.add_to_resource_start(resource, originalMethod);
60
+ }, "onResourceStart");
61
+ function OnResourceStart(resource = GetCurrentResourceName()) {
62
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
63
+ if (context.private) {
64
+ throw new Error("OnResourceStart does not work on private types, please mark the field as public");
65
+ }
66
+ if (context.static) {
67
+ onResourceStart(resource, originalMethod);
68
+ } else {
69
+ context.addInitializer(function() {
70
+ onResourceStart(resource, originalMethod.bind(this));
71
+ });
72
+ }
73
+ }, "actualDecorator");
74
+ }
75
+ __name(OnResourceStart, "OnResourceStart");
76
+ function OnResourceStop(resource = GetCurrentResourceName()) {
77
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
78
+ if (context.private) {
79
+ throw new Error("OnResourceStop does not work on private types, please mark the field as public");
80
+ }
81
+ if (context.static) {
82
+ RESOURCE_WRAPPER.add_to_resource_stop(resource, originalMethod);
83
+ } else {
84
+ context.addInitializer(function() {
85
+ RESOURCE_WRAPPER.add_to_resource_stop(resource, originalMethod.bind(this));
86
+ });
87
+ }
88
+ }, "actualDecorator");
89
+ }
90
+ __name(OnResourceStop, "OnResourceStop");
91
+ export {
92
+ OnResourceStart,
93
+ OnResourceStop
94
+ };
@@ -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;
@@ -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
+ };
@@ -0,0 +1,28 @@
1
+ type ChangeListener<V> = (value: V) => void;
2
+ /**
3
+ * not ready to be used just thoughts right now
4
+ */
5
+ export declare class NetworkedMap<K, V> extends Map<K, V> {
6
+ #private;
7
+ constructor(syncName: string, initialValue?: [K, V][]);
8
+ get SyncName(): string;
9
+ private onPlayerDropped;
10
+ resync(source: number): void;
11
+ addSubscriber(source: number): void;
12
+ removeSubscriber(sub: number): boolean;
13
+ hasSubscriber(sub: number): boolean;
14
+ subscriberCount(): number;
15
+ private handleSync;
16
+ listenForChange(key: K, fn: ChangeListener<V>): void;
17
+ set(key: K, value: V): this;
18
+ clear(): void;
19
+ delete(key: K): boolean;
20
+ networkTick(): void;
21
+ [Symbol.dispose](): void;
22
+ /**
23
+ * Unregisters from the tick handler and removes the event listener
24
+ */
25
+ dispose(): void;
26
+ get [Symbol.toStringTag](): string;
27
+ }
28
+ export {};
@@ -0,0 +1,225 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { GlobalData } from "../GlobalData";
4
+ class NetworkedMapEventManager {
5
+ static {
6
+ __name(this, "NetworkedMapEventManager");
7
+ }
8
+ #syncedCalls = /* @__PURE__ */ new Map();
9
+ constructor() {
10
+ $SERVER: if (GlobalData.IS_SERVER) {
11
+ on("playerDropped", () => {
12
+ const src = source;
13
+ for (const [_k, map] of this.#syncedCalls) {
14
+ map.removeSubscriber(src);
15
+ }
16
+ });
17
+ return;
18
+ }
19
+ $CLIENT: {
20
+ RegisterResourceAsEventHandler(`${GlobalData.CurrentResource}:syncChanges`);
21
+ addRawEventListener(`${GlobalData.CurrentResource}:syncChanges`, (msgpack_data) => {
22
+ const data = msgpack_unpack(msgpack_data);
23
+ const syncName = data[0];
24
+ const syncData = data[1];
25
+ const map = this.#syncedCalls.get(syncName);
26
+ if (!map) {
27
+ throw new Error(`Tried to sync changes for a networked map but ${syncName} does't exist.`);
28
+ }
29
+ map.handleSync(syncData);
30
+ });
31
+ }
32
+ }
33
+ addNetworkedMap(map) {
34
+ this.#syncedCalls.set(map.SyncName, map);
35
+ }
36
+ removeNetworkedMap(syncName) {
37
+ this.#syncedCalls.delete(syncName);
38
+ }
39
+ }
40
+ const netManager = new NetworkedMapEventManager();
41
+ class NetworkedMap extends Map {
42
+ static {
43
+ __name(this, "NetworkedMap");
44
+ }
45
+ #syncName;
46
+ #queuedChanges = [];
47
+ #changeListeners = /* @__PURE__ */ new Map();
48
+ #subscribers = /* @__PURE__ */ new Set();
49
+ constructor(syncName, initialValue) {
50
+ super(initialValue);
51
+ this.#syncName = syncName;
52
+ GlobalData.NetworkedTicks.push(this);
53
+ netManager.addNetworkedMap(this);
54
+ $SERVER: {
55
+ if (!GlobalData.NetworkTick && GlobalData.IS_SERVER) {
56
+ GlobalData.NetworkTick = setTick(() => {
57
+ for (const networkedThis of GlobalData.NetworkedTicks) {
58
+ networkedThis.networkTick();
59
+ }
60
+ });
61
+ }
62
+ }
63
+ }
64
+ get SyncName() {
65
+ return this.#syncName;
66
+ }
67
+ // handles removing the player from the map whenever they're dropped
68
+ onPlayerDropped() {
69
+ this.removeSubscriber(source);
70
+ }
71
+ /*
72
+ * Resyncs the entire map to the client, useful for if there's a mismatch in the clients map (when multiple players change things, in cases like inventories)
73
+ *
74
+ * NOTE: This doesn't check that the player is already subscribed to the map, you should do your own due-diligence to only call this for players already subscribed
75
+ */
76
+ resync(source2) {
77
+ const packed_data = msgpack_pack([this.#syncName, [[4 /* Init */, this.size === 0 ? [] : Array.from(this)]]]);
78
+ TriggerClientEventInternal(
79
+ `${GlobalData.CurrentResource}:syncChanges`,
80
+ source2,
81
+ packed_data,
82
+ packed_data.length
83
+ );
84
+ }
85
+ /*
86
+ * Adds a new subscriber to the map
87
+ */
88
+ addSubscriber(source2) {
89
+ this.#subscribers.add(source2);
90
+ this.resync(source2);
91
+ }
92
+ removeSubscriber(sub) {
93
+ return this.#subscribers.delete(sub);
94
+ }
95
+ hasSubscriber(sub) {
96
+ return this.#subscribers.has(sub);
97
+ }
98
+ subscriberCount() {
99
+ return this.#subscribers.size;
100
+ }
101
+ handleSync(data) {
102
+ for (const [change_type, key, value, possibly_undefined_subvalue] of data) {
103
+ switch (change_type) {
104
+ case 1 /* Add */: {
105
+ this.set(key, value);
106
+ continue;
107
+ }
108
+ case 2 /* Remove */: {
109
+ super.delete(key);
110
+ continue;
111
+ }
112
+ case 3 /* Reset */: {
113
+ super.clear();
114
+ continue;
115
+ }
116
+ case 4 /* Init */: {
117
+ super.clear();
118
+ const key_value = key;
119
+ for (const [k, v] of key_value) {
120
+ this.set(k, v);
121
+ }
122
+ continue;
123
+ }
124
+ case 0 /* SubValueChanged */: {
125
+ const data2 = this.get(key);
126
+ data2[value] = possibly_undefined_subvalue;
127
+ continue;
128
+ }
129
+ }
130
+ }
131
+ }
132
+ /*
133
+ * Listens for the change on the specified key, it will get the resulting
134
+ * value on the change
135
+ */
136
+ listenForChange(key, fn) {
137
+ const listener = this.#changeListeners.get(key);
138
+ listener ? listener.push(fn) : this.#changeListeners.set(key, [fn]);
139
+ }
140
+ #triggerEventForSubscribers(data) {
141
+ const packed_data = msgpack_pack([this.#syncName, data]);
142
+ for (const sub of this.#subscribers) {
143
+ TriggerClientEventInternal(
144
+ `${GlobalData.CurrentResource}:syncChanges`,
145
+ sub,
146
+ packed_data,
147
+ packed_data.length
148
+ );
149
+ }
150
+ }
151
+ #pushChangeForListener(key, value) {
152
+ const listener = this.#changeListeners.get(key);
153
+ if (!listener) return;
154
+ for (const ln of listener) {
155
+ ln(value);
156
+ }
157
+ }
158
+ set(key, value) {
159
+ let v = value;
160
+ if (value instanceof Object) {
161
+ const curMap = this;
162
+ const objectChangeHandler = {
163
+ get(target, prop, reciever) {
164
+ return Reflect.get(target, prop, reciever);
165
+ },
166
+ set(target, p, newValue, receiver) {
167
+ const success = Reflect.set(target, p, newValue, receiver);
168
+ if (success) {
169
+ curMap.#pushChangeForListener(key, target);
170
+ $SERVER: {
171
+ curMap.#queuedChanges.push([0 /* SubValueChanged */, key, p, newValue]);
172
+ }
173
+ }
174
+ return success;
175
+ }
176
+ };
177
+ v = new Proxy(v, objectChangeHandler);
178
+ }
179
+ super.set(key, v);
180
+ this.#pushChangeForListener(key, v);
181
+ $SERVER: {
182
+ this.#queuedChanges.push([1 /* Add */, key, v]);
183
+ }
184
+ return this;
185
+ }
186
+ /*
187
+ * Resets the map to its default state
188
+ */
189
+ clear() {
190
+ $CLIENT: if (GlobalData.IS_CLIENT) throw new Error(`Cannot call 'clear' on client`);
191
+ this.#queuedChanges = [];
192
+ this.#queuedChanges.push([3 /* Reset */]);
193
+ super.clear();
194
+ }
195
+ delete(key) {
196
+ $CLIENT: if (GlobalData.IS_CLIENT) throw new Error(`Cannot call 'delete' on client`);
197
+ this.#queuedChanges.push([2 /* Remove */, key]);
198
+ return super.delete(key);
199
+ }
200
+ networkTick() {
201
+ if (this.#queuedChanges.length !== 0) {
202
+ this.#triggerEventForSubscribers(this.#queuedChanges);
203
+ this.#queuedChanges = [];
204
+ }
205
+ }
206
+ [Symbol.dispose]() {
207
+ this.#subscribers.clear();
208
+ this.#changeListeners.clear();
209
+ this.#queuedChanges = [];
210
+ netManager.removeNetworkedMap(this.#syncName);
211
+ GlobalData.NetworkedTicks.filter((v) => v !== this);
212
+ }
213
+ /**
214
+ * Unregisters from the tick handler and removes the event listener
215
+ */
216
+ dispose() {
217
+ this[Symbol.dispose]();
218
+ }
219
+ get [Symbol.toStringTag]() {
220
+ return "NetworkedMap";
221
+ }
222
+ }
223
+ export {
224
+ NetworkedMap
225
+ };
@@ -0,0 +1,5 @@
1
+ import type { Buffer } from "buffer";
2
+ export type MsgpackBuffer = {
3
+ buffer: Buffer;
4
+ type: number;
5
+ };
File without changes