@nativewrappers/redm 0.0.77 → 0.0.78

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/index.d.ts CHANGED
@@ -8,4 +8,4 @@ export * from "./world";
8
8
  export * from "./GameConstants";
9
9
  export * from "./RelationshipGroup";
10
10
  export * from "./Attribute";
11
- export { Convar, Kvp, Resource, Command } from "./common/index";
11
+ export * from "./common/index";
package/index.js CHANGED
@@ -589,6 +589,65 @@ var Vector4 = class _Vector4 extends Vector {
589
589
  }
590
590
  };
591
591
 
592
+ // src/common/utils/PointF.ts
593
+ var PointF = class _PointF {
594
+ constructor(x, y, z) {
595
+ this.x = x;
596
+ this.y = y;
597
+ this.z = z;
598
+ }
599
+ static {
600
+ __name(this, "PointF");
601
+ }
602
+ static empty() {
603
+ return new _PointF(0, 0, 0);
604
+ }
605
+ };
606
+
607
+ // src/common/utils/Maths.ts
608
+ var Maths = class {
609
+ static {
610
+ __name(this, "Maths");
611
+ }
612
+ static clamp(num, min, max) {
613
+ return num <= min ? min : num >= max ? max : num;
614
+ }
615
+ static getRandomInt(min, max) {
616
+ min = Math.ceil(min);
617
+ max = Math.floor(max);
618
+ return Math.floor(Math.random() * (max - min)) + min;
619
+ }
620
+ };
621
+
622
+ // src/common/utils/Quaternion.ts
623
+ var Quaternion = class {
624
+ static {
625
+ __name(this, "Quaternion");
626
+ }
627
+ x;
628
+ y;
629
+ z;
630
+ w;
631
+ constructor(valueXOrVector, yOrW, z, w) {
632
+ if (valueXOrVector instanceof Vector3) {
633
+ this.x = valueXOrVector.x;
634
+ this.y = valueXOrVector.y;
635
+ this.z = valueXOrVector.z;
636
+ this.w = yOrW ?? 0;
637
+ } else if (yOrW === void 0) {
638
+ this.x = valueXOrVector;
639
+ this.y = valueXOrVector;
640
+ this.z = valueXOrVector;
641
+ this.w = valueXOrVector;
642
+ } else {
643
+ this.x = valueXOrVector;
644
+ this.y = yOrW;
645
+ this.z = z ?? 0;
646
+ this.w = w ?? 0;
647
+ }
648
+ }
649
+ };
650
+
592
651
  // src/common/utils/Color.ts
593
652
  var Color = class _Color {
594
653
  static {
@@ -619,6 +678,46 @@ var Color = class _Color {
619
678
  }
620
679
  };
621
680
 
681
+ // src/common/utils/cleanPlayerName.ts
682
+ var cleanPlayerName = /* @__PURE__ */ __name((original) => {
683
+ let displayName = original.substring(0, 75).replace(
684
+ // biome-ignore lint/suspicious/noMisleadingCharacterClass: <explanation>
685
+ /[\u0000-\u001F\u007F-\u009F\u200B-\u200D\uFEFF\u200E\uA9C1-\uA9C5\u239B-\u23AD]/g,
686
+ ""
687
+ ).replace(
688
+ /~(HUD_\S+|HC_\S+|[a-z]|[a1]_\d+|bold|italic|ws|wanted_star|nrt|EX_R\*|BLIP_\S+|ACCEPT|CANCEL|PAD_\S+|INPUT_\S+|INPUTGROUP_\S+)~/gi,
689
+ ""
690
+ ).replace(/\^\d/gi, "").replace(/\p{Mark}{2,}/gu, "").replace(/\s+/g, " ").trim();
691
+ if (!displayName.length) displayName = "empty name";
692
+ return displayName;
693
+ }, "cleanPlayerName");
694
+
695
+ // src/common/utils/enumValues.ts
696
+ function* enumValues(enumObj) {
697
+ let isStringEnum = true;
698
+ for (const property in enumObj) {
699
+ if (typeof enumObj[property] === "number") {
700
+ isStringEnum = false;
701
+ break;
702
+ }
703
+ }
704
+ for (const property in enumObj) {
705
+ if (isStringEnum || typeof enumObj[property] === "number") {
706
+ yield enumObj[property];
707
+ }
708
+ }
709
+ }
710
+ __name(enumValues, "enumValues");
711
+
712
+ // src/common/utils/getStringFromUInt8Array.ts
713
+ var getStringFromUInt8Array = /* @__PURE__ */ __name((buffer, start, end) => String.fromCharCode(...buffer.slice(start, end)).replace(/\u0000/g, ""), "getStringFromUInt8Array");
714
+
715
+ // src/common/utils/getUInt32FromUint8Array.ts
716
+ var getUInt32FromUint8Array = /* @__PURE__ */ __name((buffer, start, end) => new Uint32Array(buffer.slice(start, end).buffer)[0], "getUInt32FromUint8Array");
717
+
718
+ // src/common/utils/index.ts
719
+ var Delay = /* @__PURE__ */ __name((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)), "Delay");
720
+
622
721
  // src/redm/entities/BaseEntity.ts
623
722
  var BaseEntity = class {
624
723
  static {
@@ -2810,6 +2909,332 @@ var NetworkedMapEventManager = class {
2810
2909
  }
2811
2910
  };
2812
2911
  var netManager = new NetworkedMapEventManager();
2912
+ var NetworkedMap = class extends Map {
2913
+ static {
2914
+ __name(this, "NetworkedMap");
2915
+ }
2916
+ #syncName;
2917
+ #queuedChanges = [];
2918
+ #changeListeners = /* @__PURE__ */ new Map();
2919
+ #subscribers = /* @__PURE__ */ new Set();
2920
+ constructor(syncName, initialValue) {
2921
+ super(initialValue);
2922
+ this.#syncName = syncName;
2923
+ GlobalData.NetworkedTicks.push(this);
2924
+ netManager.addNetworkedMap(this);
2925
+ }
2926
+ get SyncName() {
2927
+ return this.#syncName;
2928
+ }
2929
+ // handles removing the player from the map whenever they're dropped
2930
+ onPlayerDropped() {
2931
+ this.removeSubscriber(source);
2932
+ }
2933
+ /*
2934
+ * 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)
2935
+ *
2936
+ * 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
2937
+ */
2938
+ resync(source2) {
2939
+ const packed_data = msgpack_pack([this.#syncName, [[4 /* Init */, this.size === 0 ? [] : Array.from(this)]]]);
2940
+ TriggerClientEventInternal(
2941
+ `${GlobalData.CurrentResource}:syncChanges`,
2942
+ source2,
2943
+ packed_data,
2944
+ packed_data.length
2945
+ );
2946
+ }
2947
+ /*
2948
+ * Adds a new subscriber to the map
2949
+ */
2950
+ addSubscriber(source2) {
2951
+ this.#subscribers.add(source2);
2952
+ this.resync(source2);
2953
+ }
2954
+ removeSubscriber(sub) {
2955
+ return this.#subscribers.delete(sub);
2956
+ }
2957
+ hasSubscriber(sub) {
2958
+ return this.#subscribers.has(sub);
2959
+ }
2960
+ subscriberCount() {
2961
+ return this.#subscribers.size;
2962
+ }
2963
+ handleSync(data) {
2964
+ for (const [change_type, key, value, possibly_undefined_subvalue] of data) {
2965
+ switch (change_type) {
2966
+ case 1 /* Add */: {
2967
+ this.set(key, value);
2968
+ continue;
2969
+ }
2970
+ case 2 /* Remove */: {
2971
+ super.delete(key);
2972
+ continue;
2973
+ }
2974
+ case 3 /* Reset */: {
2975
+ super.clear();
2976
+ continue;
2977
+ }
2978
+ case 4 /* Init */: {
2979
+ super.clear();
2980
+ const key_value = key;
2981
+ for (const [k, v] of key_value) {
2982
+ this.set(k, v);
2983
+ }
2984
+ continue;
2985
+ }
2986
+ case 0 /* SubValueChanged */: {
2987
+ const data2 = this.get(key);
2988
+ data2[value] = possibly_undefined_subvalue;
2989
+ continue;
2990
+ }
2991
+ }
2992
+ }
2993
+ }
2994
+ /*
2995
+ * Listens for the change on the specified key, it will get the resulting
2996
+ * value on the change
2997
+ */
2998
+ listenForChange(key, fn) {
2999
+ const listener = this.#changeListeners.get(key);
3000
+ listener ? listener.push(fn) : this.#changeListeners.set(key, [fn]);
3001
+ }
3002
+ #triggerEventForSubscribers(data) {
3003
+ const packed_data = msgpack_pack([this.#syncName, data]);
3004
+ for (const sub of this.#subscribers) {
3005
+ TriggerClientEventInternal(
3006
+ `${GlobalData.CurrentResource}:syncChanges`,
3007
+ sub,
3008
+ packed_data,
3009
+ packed_data.length
3010
+ );
3011
+ }
3012
+ }
3013
+ #pushChangeForListener(key, value) {
3014
+ const listener = this.#changeListeners.get(key);
3015
+ if (!listener) return;
3016
+ for (const ln of listener) {
3017
+ ln(value);
3018
+ }
3019
+ }
3020
+ set(key, value) {
3021
+ let v = value;
3022
+ if (value instanceof Object) {
3023
+ const curMap = this;
3024
+ const objectChangeHandler = {
3025
+ get(target, prop, reciever) {
3026
+ return Reflect.get(target, prop, reciever);
3027
+ },
3028
+ set(target, p, newValue, receiver) {
3029
+ const success = Reflect.set(target, p, newValue, receiver);
3030
+ if (success) {
3031
+ curMap.#pushChangeForListener(key, target);
3032
+ }
3033
+ return success;
3034
+ }
3035
+ };
3036
+ v = new Proxy(v, objectChangeHandler);
3037
+ }
3038
+ super.set(key, v);
3039
+ this.#pushChangeForListener(key, v);
3040
+ return this;
3041
+ }
3042
+ /*
3043
+ * Resets the map to its default state
3044
+ */
3045
+ clear() {
3046
+ $CLIENT: if (GlobalData.IS_CLIENT) throw new Error(`Cannot call 'clear' on client`);
3047
+ this.#queuedChanges = [];
3048
+ this.#queuedChanges.push([3 /* Reset */]);
3049
+ super.clear();
3050
+ }
3051
+ delete(key) {
3052
+ $CLIENT: if (GlobalData.IS_CLIENT) throw new Error(`Cannot call 'delete' on client`);
3053
+ this.#queuedChanges.push([2 /* Remove */, key]);
3054
+ return super.delete(key);
3055
+ }
3056
+ networkTick() {
3057
+ if (this.#queuedChanges.length !== 0) {
3058
+ this.#triggerEventForSubscribers(this.#queuedChanges);
3059
+ this.#queuedChanges = [];
3060
+ }
3061
+ }
3062
+ [Symbol.dispose]() {
3063
+ this.#subscribers.clear();
3064
+ this.#changeListeners.clear();
3065
+ this.#queuedChanges = [];
3066
+ netManager.removeNetworkedMap(this.#syncName);
3067
+ GlobalData.NetworkedTicks.filter((v) => v !== this);
3068
+ }
3069
+ /**
3070
+ * Unregisters from the tick handler and removes the event listener
3071
+ */
3072
+ dispose() {
3073
+ this[Symbol.dispose]();
3074
+ }
3075
+ get [Symbol.toStringTag]() {
3076
+ return "NetworkedMap";
3077
+ }
3078
+ };
3079
+
3080
+ // src/common/decors/Events.ts
3081
+ var ConVarType = /* @__PURE__ */ ((ConVarType2) => {
3082
+ ConVarType2[ConVarType2["String"] = 0] = "String";
3083
+ ConVarType2[ConVarType2["Integer"] = 1] = "Integer";
3084
+ ConVarType2[ConVarType2["Float"] = 2] = "Float";
3085
+ ConVarType2[ConVarType2["Boolean"] = 3] = "Boolean";
3086
+ return ConVarType2;
3087
+ })(ConVarType || {});
3088
+ var DisablePrettyPrint = /* @__PURE__ */ __name(() => GlobalData.EnablePrettyPrint = false, "DisablePrettyPrint");
3089
+ function Exports(exportName) {
3090
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
3091
+ if (context.private) {
3092
+ throw new Error("Exports does not work on private methods, please mark the method as public");
3093
+ }
3094
+ context.addInitializer(function() {
3095
+ exports(exportName, (...args) => {
3096
+ return originalMethod.call(this, ...args);
3097
+ });
3098
+ });
3099
+ }, "actualDecorator");
3100
+ }
3101
+ __name(Exports, "Exports");
3102
+ function Event(eventName) {
3103
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
3104
+ if (context.private) {
3105
+ throw new Error("Event does not work on private methods, please mark the method as public");
3106
+ }
3107
+ context.addInitializer(function() {
3108
+ on(eventName, (...args) => {
3109
+ try {
3110
+ return originalMethod.call(this, ...args);
3111
+ } catch (e) {
3112
+ REMOVE_EVENT_LOG: {
3113
+ if (!GlobalData.EnablePrettyPrint) return;
3114
+ console.error("------- EVENT ERROR --------");
3115
+ console.error(`Call to ${eventName} errored`);
3116
+ console.error(`Data: ${JSON.stringify(args)}`);
3117
+ console.error(`Error: ${e}`);
3118
+ console.error("------- END EVENT ERROR --------");
3119
+ }
3120
+ }
3121
+ });
3122
+ });
3123
+ }, "actualDecorator");
3124
+ }
3125
+ __name(Event, "Event");
3126
+ function NetEvent(eventName, remoteOnly = true) {
3127
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
3128
+ if (context.private) {
3129
+ throw new Error("NetEvent does not work on private methods, please mark the method as public");
3130
+ }
3131
+ context.addInitializer(function() {
3132
+ onNet(eventName, (...args) => {
3133
+ const src = source;
3134
+ try {
3135
+ $CLIENT: {
3136
+ if (GlobalData.IS_CLIENT && remoteOnly && source !== 65535) {
3137
+ return;
3138
+ }
3139
+ }
3140
+ return originalMethod.call(this, ...args);
3141
+ } catch (e) {
3142
+ REMOVE_NET_EVENT_LOG: {
3143
+ if (!GlobalData.EnablePrettyPrint) return;
3144
+ console.error("------- NET EVENT ERROR --------");
3145
+ console.error(`Call to ${eventName} errored`);
3146
+ console.error(`Caller: ${src}`);
3147
+ console.error(`Data: ${JSON.stringify(args)}`);
3148
+ console.error(`Error: ${e}`);
3149
+ console.error("------- END NET EVENT ERROR --------");
3150
+ }
3151
+ }
3152
+ });
3153
+ });
3154
+ }, "actualDecorator");
3155
+ }
3156
+ __name(NetEvent, "NetEvent");
3157
+ function NuiEvent(eventName) {
3158
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
3159
+ if (context.private) {
3160
+ throw new Error("NuiEvent does not work on private methods, please mark the method as public");
3161
+ }
3162
+ context.addInitializer(function() {
3163
+ RegisterNuiCallback(eventName, (...args) => {
3164
+ return originalMethod.call(this, ...args);
3165
+ });
3166
+ });
3167
+ }, "actualDecorator");
3168
+ }
3169
+ __name(NuiEvent, "NuiEvent");
3170
+ var get_convar_fn = /* @__PURE__ */ __name((con_var_type) => {
3171
+ switch (con_var_type) {
3172
+ case 0 /* String */:
3173
+ return GetConvar;
3174
+ case 1 /* Integer */:
3175
+ return GetConvarInt;
3176
+ case 2 /* Float */:
3177
+ return GetConvarFloat;
3178
+ case 3 /* Boolean */:
3179
+ return GetConvarBool;
3180
+ // needed so typescript wont complain about "unreachable code" for the error below
3181
+ default:
3182
+ }
3183
+ throw new Error("Got invalid ConVarType");
3184
+ }, "get_convar_fn");
3185
+ function ConVar(name, is_floating_point, deserialize) {
3186
+ return /* @__PURE__ */ __name(function actualDecorator(_initialValue, context, ..._args) {
3187
+ if (context.private) {
3188
+ throw new Error("ConVar does not work on private types, please mark the field as public");
3189
+ }
3190
+ context.addInitializer(function() {
3191
+ const t = this;
3192
+ const default_value = Reflect.get(t, context.name);
3193
+ const default_type = typeof default_value;
3194
+ let con_var_type = null;
3195
+ if (default_type === "number") {
3196
+ if (is_floating_point || !Number.isInteger(default_value)) {
3197
+ con_var_type = 2 /* Float */;
3198
+ } else {
3199
+ con_var_type = 1 /* Integer */;
3200
+ }
3201
+ } else if (default_type === "boolean") {
3202
+ con_var_type = 3 /* Boolean */;
3203
+ } else if (default_value === "string") {
3204
+ con_var_type = 0 /* String */;
3205
+ }
3206
+ if (!deserialize && con_var_type === null) {
3207
+ throw new Error("You should provide a deserialize function if you want to convert this to an object type");
3208
+ }
3209
+ if (con_var_type === null) {
3210
+ con_var_type = 0 /* String */;
3211
+ }
3212
+ const con_var_fn = get_convar_fn(con_var_type);
3213
+ const get_convar_value = /* @__PURE__ */ __name(() => {
3214
+ const data = con_var_fn(name, default_value);
3215
+ return deserialize ? deserialize(data) : data;
3216
+ }, "get_convar_value");
3217
+ Reflect.set(t, context.name, get_convar_value());
3218
+ AddConvarChangeListener(name, () => {
3219
+ Reflect.set(t, context.name, get_convar_value());
3220
+ });
3221
+ });
3222
+ }, "actualDecorator");
3223
+ }
3224
+ __name(ConVar, "ConVar");
3225
+ function SetTick() {
3226
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
3227
+ if (context.private) {
3228
+ throw new Error("SetTick does not work on private types, please mark the field as public");
3229
+ }
3230
+ context.addInitializer(function() {
3231
+ setTick(async () => {
3232
+ await originalMethod.call(this);
3233
+ });
3234
+ });
3235
+ }, "actualDecorator");
3236
+ }
3237
+ __name(SetTick, "SetTick");
2813
3238
 
2814
3239
  // src/common/Convar.ts
2815
3240
  var Convar = class {
@@ -3134,28 +3559,46 @@ var Resource = class {
3134
3559
  };
3135
3560
  export {
3136
3561
  Attributes,
3562
+ Color,
3137
3563
  Command,
3564
+ ConVar,
3565
+ ConVarType,
3138
3566
  Controls,
3139
3567
  Convar,
3140
3568
  CoreAttribute,
3569
+ Delay,
3570
+ DisablePrettyPrint,
3141
3571
  Entity,
3572
+ Event,
3573
+ Exports,
3142
3574
  Game,
3143
3575
  GameConstants,
3144
3576
  KeyHash,
3145
3577
  KnockOffVehicle,
3146
3578
  Kvp,
3579
+ Maths,
3580
+ NetEvent,
3581
+ NetworkedMap,
3582
+ NuiEvent,
3147
3583
  Ped,
3148
3584
  PedAttribute,
3149
3585
  Player,
3586
+ PointF,
3587
+ Quaternion,
3150
3588
  RawControls,
3151
3589
  RawKeys,
3152
3590
  Relationship,
3153
3591
  RelationshipGroup,
3154
3592
  Resource,
3593
+ SetTick,
3155
3594
  TamingState,
3595
+ Vector2,
3596
+ Vector3,
3597
+ Vector4,
3156
3598
  Vehicle,
3157
3599
  VehicleSeat,
3158
3600
  Volume,
3601
+ cleanPlayerName,
3159
3602
  createDraftVehicle,
3160
3603
  createPed,
3161
3604
  createProp,
@@ -3163,5 +3606,8 @@ export {
3163
3606
  eAttributeCore,
3164
3607
  eDamageCleanliness,
3165
3608
  eHudStatusEffect,
3166
- ePedAttribute
3609
+ ePedAttribute,
3610
+ enumValues,
3611
+ getStringFromUInt8Array,
3612
+ getUInt32FromUint8Array
3167
3613
  };
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "version": "0.0.77",
11
+ "version": "0.0.78",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/nativewrappers/nativewrappers.git"