@nativewrappers/server 0.0.64 → 0.0.72

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 (52) hide show
  1. package/README.md +45 -0
  2. package/cfx/StateBagChangeHandler.d.ts +1 -3
  3. package/common/Command.d.ts +30 -0
  4. package/common/Convar.d.ts +13 -0
  5. package/common/GlobalData.d.ts +8 -0
  6. package/common/Kvp.d.ts +69 -0
  7. package/common/Resource.d.ts +14 -0
  8. package/common/decors/Events.d.ts +54 -0
  9. package/common/index.d.ts +8 -0
  10. package/common/net/NetworkedMap.d.ts +28 -0
  11. package/common/types.d.ts +5 -0
  12. package/common/utils/ClassTypes.d.ts +11 -0
  13. package/common/utils/Color.d.ts +14 -0
  14. package/common/utils/Maths.d.ts +4 -0
  15. package/common/utils/PointF.d.ts +12 -0
  16. package/common/utils/Quaternion.d.ts +10 -0
  17. package/common/utils/Vector.d.ts +429 -0
  18. package/common/utils/Vector2.d.ts +1 -0
  19. package/common/utils/Vector3.d.ts +1 -0
  20. package/common/utils/Vector4.d.ts +1 -0
  21. package/common/utils/cleanPlayerName.d.ts +6 -0
  22. package/common/utils/enumValues.d.ts +12 -0
  23. package/common/utils/getStringFromUInt8Array.d.ts +8 -0
  24. package/common/utils/getUInt32FromUint8Array.d.ts +8 -0
  25. package/common/utils/index.d.ts +12 -0
  26. package/entities/BaseEntity.d.ts +3 -3
  27. package/entities/Ped.d.ts +1 -1
  28. package/entities/Vehicle.d.ts +3 -3
  29. package/index.d.ts +1 -1
  30. package/index.js +1807 -7
  31. package/package.json +7 -5
  32. package/type/Anticheat.d.ts +1 -1
  33. package/utils/index.d.ts +1 -1
  34. package/Events.js +0 -79
  35. package/Game.js +0 -55
  36. package/cfx/StateBagChangeHandler.js +0 -1
  37. package/cfx/index.js +0 -1
  38. package/entities/BaseEntity.js +0 -135
  39. package/entities/Entity.js +0 -12
  40. package/entities/Ped.js +0 -81
  41. package/entities/Player.js +0 -136
  42. package/entities/Prop.js +0 -32
  43. package/entities/Vehicle.js +0 -175
  44. package/entities/index.js +0 -5
  45. package/enum/PopulationType.js +0 -14
  46. package/enum/VehicleLockStatus.js +0 -10
  47. package/enum/VehicleType.js +0 -11
  48. package/enum/eEntityType.js +0 -6
  49. package/enum/index.js +0 -4
  50. package/type/Anticheat.js +0 -1
  51. package/type/Hash.js +0 -1
  52. package/utils/index.js +0 -1
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ <h1 align="center">Monorepo for a FiveM server/client wrapper</h1>
2
+
3
+ <p align="center">
4
+ <i>🔥 A Javascript/Typescript package for FiveM resource development 🎮</i>
5
+ <br>
6
+ <small>This project is in no way affiliated with FiveM or the Cfx.re Collective.</small>
7
+ </br></br>
8
+ <a href="https://github.com/nativewrappers/nativewrappers/blob/master/LICENSE">
9
+ <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat" alt="License: MIT">
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/@nativewrappers/fivem">
12
+ <img src="https://img.shields.io/npm/v/@nativewrappers/fivem?style=flat" alt="npm version">
13
+ </a>
14
+ <a href="https://www.npmjs.com/package/@nativewrappers/fivem">
15
+ <img src="https://img.shields.io/npm/dm/@nativewrappers/fivem?style=flat">
16
+ </a>
17
+ <a href="https://github.com/nativewrappers/nativewrappers/actions/workflows/config.yml">
18
+ <img src="https://github.com/nativewrappers/nativewrappers/actions/workflows/config.yml/badge.svg" alt="Workflow Status">
19
+ </a>
20
+ <a href="https://github.com/nativewrappers/nativewrappers/commits/master">
21
+ <img src="https://img.shields.io/github/last-commit/nativewrappers/fivem.svg?style=flat" alt="Last commit">
22
+ </a>
23
+ </p>
24
+
25
+ <h3 align="center">This project is currently iterating rapidly, there will be breaking changes.</h3>
26
+
27
+ <p align="center">
28
+ <h2 align="center"><a href="https://github.com/nativewrappers/nativewrappers/tree/main/docs">Documentation</a></h2>
29
+ <!-- <a href="https://forum.fivem.net/t/fivem-js-v1-3-2-javascript-typescript-wrapper-now-with-menu-class-nativeui/268640">Forum</a> -->
30
+ </p>
31
+
32
+ ## Features
33
+
34
+ - No runtime dependencies
35
+ - Entity management through class objects (i.e. `Vehicle` and `Ped` entities)
36
+ - Server and Client side variants on wrapper
37
+
38
+
39
+ ## Download & Install
40
+ ```
41
+ pnpm add @nativewrappers/redm # for redm,
42
+ pnpm add @nativewrappers/fivem # for fivem
43
+ pnpm add @nativewrappers/common # for any, should be game agnostic, provides Vector3, decors, kvps, helper functions, etc
44
+ pnpm add @nativewrappers/server # for server
45
+ ```
@@ -1,3 +1 @@
1
- export interface StateBagChangeHandler<T> {
2
- (bagName: string, key: string, value: T, reserved: number, replicated: boolean): void;
3
- }
1
+ export type StateBagChangeHandler<T> = (bagName: string, key: string, value: T, reserved: number, replicated: boolean) => void;
@@ -0,0 +1,30 @@
1
+ type Restricted = boolean | string | string[];
2
+ interface ParameterTypes {
3
+ number: number;
4
+ playerId: number;
5
+ string: string;
6
+ longString: string;
7
+ }
8
+ interface Parameter {
9
+ name: string;
10
+ type: keyof ParameterTypes;
11
+ help?: string;
12
+ optional?: boolean;
13
+ }
14
+ type MappedParameters<T extends Parameter[]> = {
15
+ [K in T[number] as K["name"]]: ParameterTypes[K["type"]];
16
+ } & {
17
+ source: number;
18
+ raw: string;
19
+ };
20
+ type CommandHandler<T extends Parameter[]> = (args: MappedParameters<T>) => void | Promise<void>;
21
+ export declare class Command<T extends Parameter[] = Parameter[]> {
22
+ #private;
23
+ readonly name: string | string[];
24
+ readonly help: string;
25
+ readonly params?: T | undefined;
26
+ constructor(name: string | string[], help: string, handler: CommandHandler<T>, params?: T | undefined, restricted?: Restricted);
27
+ private mapArguments;
28
+ call(source: number, args: string[], raw?: string): Promise<void>;
29
+ }
30
+ export {};
@@ -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,8 @@
1
+ export declare class GlobalData {
2
+ static CurrentResource: string;
3
+ static IS_SERVER: boolean;
4
+ static IS_CLIENT: boolean;
5
+ static NetworkTick: number | null;
6
+ static NetworkedTicks: any[];
7
+ static EnablePrettyPrint: boolean;
8
+ }
@@ -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,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
+ export declare enum ConVarType {
2
+ String = 0,
3
+ Integer = 1,
4
+ Float = 2,
5
+ Boolean = 3
6
+ }
7
+ /**
8
+ * Disables pretty printing in error messages
9
+ */
10
+ export declare const DisablePrettyPrint: () => boolean;
11
+ export declare function Exports(exportName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
12
+ /**
13
+ * Registers the Event call for {@link eventName} to this method.
14
+ *
15
+ * This has internal pretty-printing to make errors easier to track, if
16
+ * you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
17
+ * using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
18
+ *
19
+ * @param eventName the event to bind to
20
+ */
21
+ export declare function Event(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
22
+ /**
23
+ * Registers the Net Event call for {@link eventName} to this method
24
+ *
25
+ *
26
+ * This has internal pretty-printing to make errors easier to track, if
27
+ * you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
28
+ * using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
29
+ *
30
+ * @param eventName the event to bind this net event to
31
+ * @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
32
+ */
33
+ export declare function NetEvent(eventName: string, remoteOnly?: boolean): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
34
+ /**
35
+ * Registers the NUI Event call for {eventName} to this method, the function signature
36
+ * should be (data: unknown, cb: (data?: any) => void) => void
37
+ * You shoud always execute `cb` with 'ok' if you don't want to send data back to
38
+ * the UI, otherwise you'll cause a network error for the `fetch` request
39
+ * @param eventName the event this will listen for
40
+ */
41
+ export declare function NuiEvent(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
42
+ type DeserializeFn<T> = (data: T) => unknown;
43
+ /**
44
+ * Gets the specified `ConVar`s value, this will bind to the param.
45
+ * @param name the convar name
46
+ * @param is_floating_point if the convar is floating point, this should be explicitly set to true if your convar will be a float
47
+ */
48
+ export declare function ConVar<T>(name: string, is_floating_point?: boolean, deserialize?: DeserializeFn<T>): (_initialValue: any, context: ClassFieldDecoratorContext, ..._args: any[]) => void;
49
+ /**
50
+ * Gets called per server/client tick, this is asyncronous though, if you await
51
+ * in it, it will not be called until whatever was being awaited resolves.
52
+ */
53
+ export declare function SetTick(): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
54
+ export {};
@@ -0,0 +1,8 @@
1
+ export * from "./utils";
2
+ export * from "./net/NetworkedMap";
3
+ export * from "./decors/Events";
4
+ export * from "./Convar";
5
+ export * from "./Command";
6
+ export * from "./Kvp";
7
+ export * from "./Resource";
8
+ export * from "./utils/index";
@@ -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,5 @@
1
+ import type { Buffer } from "buffer";
2
+ export type MsgpackBuffer = {
3
+ buffer: Buffer;
4
+ type: number;
5
+ };
@@ -0,0 +1,11 @@
1
+ export declare enum ClassTypes {
2
+ Ped = 0,
3
+ Prop = 1,
4
+ Vehicle = 2,
5
+ Entity = 3,
6
+ Player = 4,
7
+ Vector2 = 5,
8
+ Vector3 = 6,
9
+ Vector4 = 7,
10
+ Quanterion = 8
11
+ }
@@ -0,0 +1,14 @@
1
+ export declare class Color {
2
+ static Transparent: Color;
3
+ static Black: Color;
4
+ static White: Color;
5
+ static WhiteSmoke: Color;
6
+ static fromArgb(a: number, r: number, g: number, b: number): Color;
7
+ static fromRgb(r: number, g: number, b: number): Color;
8
+ static fromArray(primitive: [number, number, number] | number[]): Color;
9
+ a: number;
10
+ r: number;
11
+ g: number;
12
+ b: number;
13
+ constructor(r: number, g: number, b: number, a?: number);
14
+ }
@@ -0,0 +1,4 @@
1
+ export declare abstract class Maths {
2
+ static clamp(num: number, min: number, max: number): number;
3
+ static getRandomInt(min: number, max: number): number;
4
+ }
@@ -0,0 +1,12 @@
1
+ export interface PointF {
2
+ x: number;
3
+ y: number;
4
+ z: number;
5
+ }
6
+ export declare class PointF implements PointF {
7
+ x: number;
8
+ y: number;
9
+ z: number;
10
+ static empty(): PointF;
11
+ constructor(x: number, y: number, z: number);
12
+ }
@@ -0,0 +1,10 @@
1
+ import { Vector3 } from "./Vector3";
2
+ export declare class Quaternion {
3
+ x: number;
4
+ y: number;
5
+ z: number;
6
+ w: number;
7
+ constructor(value: number);
8
+ constructor(vector: Vector3, w: number);
9
+ constructor(x: number, y: number, z: number, w: number);
10
+ }