@open-core/ragemp-adapter 0.1.1 → 1.0.0
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/dist/.tsbuildinfo/client.tsbuildinfo +1 -1
- package/dist/.tsbuildinfo/root.tsbuildinfo +1 -1
- package/dist/.tsbuildinfo/server.tsbuildinfo +1 -1
- package/dist/.tsbuildinfo/shared.tsbuildinfo +1 -1
- package/dist/client/create-ragemp-client-adapter.js +10 -3
- package/dist/client/native-chat.d.ts +10 -0
- package/dist/client/native-chat.js +69 -6
- package/dist/client/ragemp-camera-port.d.ts +19 -0
- package/dist/client/ragemp-camera-port.js +72 -0
- package/dist/client/ragemp-local-player-bridge.d.ts +3 -0
- package/dist/client/ragemp-local-player-bridge.js +10 -0
- package/dist/client/ragemp-ped-port.d.ts +23 -0
- package/dist/client/ragemp-ped-port.js +107 -0
- package/dist/client/ragemp-platform-bridge.js +1 -1
- package/dist/client/ragemp-progress-port.d.ts +21 -0
- package/dist/client/ragemp-progress-port.js +169 -0
- package/dist/client/ragemp-runtime-bridge.d.ts +2 -4
- package/dist/client/ragemp-runtime-bridge.js +3 -0
- package/dist/client/ragemp-spawn-bridge.d.ts +4 -4
- package/dist/client/ragemp-spawn-bridge.js +5 -3
- package/dist/client/ragemp-vehicle-port.d.ts +34 -0
- package/dist/client/ragemp-vehicle-port.js +272 -0
- package/dist/client/ragemp-webview-bridge.d.ts +5 -0
- package/dist/client/ragemp-webview-bridge.js +54 -12
- package/dist/server/ragemp-engine-events.d.ts +2 -5
- package/dist/server/ragemp-engine-events.js +3 -15
- package/dist/server/ragemp-entity-server.js +14 -1
- package/dist/server/ragemp-player-appearance-lifecycle-server.js +4 -3
- package/dist/server/ragemp-resourceinfo.js +3 -0
- package/dist/shared/exports-registry.d.ts +2 -2
- package/dist/shared/transport/helpers.d.ts +3 -3
- package/dist/shared/transport/helpers.js +33 -7
- package/dist/shared/transport/ragemp.events.d.ts +3 -3
- package/dist/shared/transport/ragemp.events.js +4 -2
- package/dist/shared/transport/ragemp.rpc.d.ts +4 -8
- package/dist/shared/transport/ragemp.rpc.js +21 -5
- package/package.json +5 -7
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.onNet = onNet;
|
|
4
4
|
exports.emitNet = emitNet;
|
|
5
|
+
const JSON_WIRE_PREFIX = '__OPENCORE_JSON__:';
|
|
6
|
+
function serializeWireValue(value) {
|
|
7
|
+
if (value === null || value === undefined)
|
|
8
|
+
return value;
|
|
9
|
+
if (Array.isArray(value) || (typeof value === 'object' && value.constructor === Object)) {
|
|
10
|
+
return `${JSON_WIRE_PREFIX}${JSON.stringify(value)}`;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function deserializeWireValue(value) {
|
|
15
|
+
if (typeof value !== 'string' || !value.startsWith(JSON_WIRE_PREFIX)) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(value.slice(JSON_WIRE_PREFIX.length));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function deserializeWireArgs(args) {
|
|
26
|
+
return args.map((arg) => deserializeWireValue(arg));
|
|
27
|
+
}
|
|
5
28
|
/**
|
|
6
29
|
* Resolves a player by numeric ID, returning undefined when the player no
|
|
7
30
|
* longer exists (disconnected, invalid handle, etc.).
|
|
@@ -21,7 +44,7 @@ function resolvePlayer(id) {
|
|
|
21
44
|
*
|
|
22
45
|
* Analogous to FiveM's `onNet`:
|
|
23
46
|
* - Server: RageMP prepends the PlayerMp as the first native argument.
|
|
24
|
-
* We expose it as-is so callers can read player.id before
|
|
47
|
+
* We expose it as-is so callers can read player.id before awaiting.
|
|
25
48
|
* - Client: no source argument; we pass undefined to keep the signature uniform.
|
|
26
49
|
*/
|
|
27
50
|
function onNet(context, event, handler) {
|
|
@@ -32,11 +55,13 @@ function onNet(context, event, handler) {
|
|
|
32
55
|
// all other events should be safe to guard this way.
|
|
33
56
|
if (!mp.players.exists(player.id))
|
|
34
57
|
return;
|
|
35
|
-
handler(player, ...args);
|
|
58
|
+
handler(player, ...deserializeWireArgs(args));
|
|
36
59
|
});
|
|
37
60
|
}
|
|
38
61
|
else {
|
|
39
|
-
mp.events.add(event, (...args) =>
|
|
62
|
+
mp.events.add(event, (...args) => {
|
|
63
|
+
handler(undefined, ...deserializeWireArgs(args));
|
|
64
|
+
});
|
|
40
65
|
}
|
|
41
66
|
}
|
|
42
67
|
/**
|
|
@@ -52,19 +77,20 @@ function onNet(context, event, handler) {
|
|
|
52
77
|
* network targets, matching FiveM's TriggerClientEvent semantics.
|
|
53
78
|
*/
|
|
54
79
|
function emitNet(context, event, target, ...payload) {
|
|
80
|
+
const serializedPayload = payload.map((item) => serializeWireValue(item));
|
|
55
81
|
if (context !== 'server') {
|
|
56
|
-
mp.events.callRemote(event, ...
|
|
82
|
+
mp.events.callRemote(event, ...serializedPayload);
|
|
57
83
|
return;
|
|
58
84
|
}
|
|
59
85
|
if (target === -1) {
|
|
60
|
-
mp.players.call(event,
|
|
86
|
+
mp.players.call(event, serializedPayload);
|
|
61
87
|
return;
|
|
62
88
|
}
|
|
63
89
|
if (Array.isArray(target)) {
|
|
64
90
|
for (const id of target) {
|
|
65
|
-
resolvePlayer(id)?.call(event,
|
|
91
|
+
resolvePlayer(id)?.call(event, serializedPayload);
|
|
66
92
|
}
|
|
67
93
|
return;
|
|
68
94
|
}
|
|
69
|
-
resolvePlayer(target)?.call(event,
|
|
95
|
+
resolvePlayer(target)?.call(event, serializedPayload);
|
|
70
96
|
}
|
|
@@ -2,9 +2,9 @@ import { EventsAPI, type RuntimeContext } from '@open-core/framework/contracts';
|
|
|
2
2
|
export declare class RageMPEvents extends EventsAPI<RuntimeContext> {
|
|
3
3
|
private readonly context;
|
|
4
4
|
constructor(context: RuntimeContext);
|
|
5
|
-
on(event: string, handler: (source: {
|
|
5
|
+
on<TArgs extends readonly unknown[]>(event: string, handler: (source: {
|
|
6
6
|
clientId: number | undefined;
|
|
7
7
|
raw: PlayerMp | undefined;
|
|
8
|
-
}, ...args:
|
|
9
|
-
emit(event: string, ...args:
|
|
8
|
+
}, ...args: TArgs) => void | Promise<void>): void;
|
|
9
|
+
emit(event: string, ...args: unknown[]): void;
|
|
10
10
|
}
|
|
@@ -16,7 +16,7 @@ class RageMPEvents extends contracts_1.EventsAPI {
|
|
|
16
16
|
}
|
|
17
17
|
on(event, handler) {
|
|
18
18
|
(0, helpers_1.onNet)(this.context, event, (source, ...args) => {
|
|
19
|
-
handler({ clientId: source?.id, raw: source }, ...args);
|
|
19
|
+
void handler({ clientId: source?.id, raw: source }, ...args);
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
emit(event, ...args) {
|
|
@@ -39,7 +39,9 @@ class RageMPEvents extends contracts_1.EventsAPI {
|
|
|
39
39
|
(0, helpers_1.emitNet)(this.context, event, target.clientID, ...payload);
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
if (typeof target === 'number') {
|
|
43
|
+
(0, helpers_1.emitNet)(this.context, event, target, ...payload);
|
|
44
|
+
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
exports.RageMPEvents = RageMPEvents;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RpcAPI, type RuntimeContext } from '@open-core/framework/contracts';
|
|
1
|
+
import { RpcAPI, type RpcContext, type RuntimeContext } from '@open-core/framework/contracts';
|
|
2
2
|
export declare class RageMPRpc<C extends RuntimeContext = RuntimeContext> extends RpcAPI<C> {
|
|
3
3
|
private readonly context;
|
|
4
4
|
private readonly pending;
|
|
@@ -9,13 +9,9 @@ export declare class RageMPRpc<C extends RuntimeContext = RuntimeContext> extend
|
|
|
9
9
|
private readonly responseEvent;
|
|
10
10
|
private readonly defaultTimeoutMs;
|
|
11
11
|
constructor(context: C);
|
|
12
|
-
on<TArgs extends
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
raw?: unknown;
|
|
16
|
-
}, ...args: TArgs) => TResult | Promise<TResult>): void;
|
|
17
|
-
call<TResult = unknown>(name: string, ...args: any[]): Promise<TResult>;
|
|
18
|
-
notify(name: string, ...args: any[]): Promise<void>;
|
|
12
|
+
on<TArgs extends readonly unknown[], TResult>(name: string, handler: (ctx: RpcContext, ...args: TArgs) => TResult | Promise<TResult>): void;
|
|
13
|
+
call<TResult = unknown>(name: string, ...args: unknown[]): Promise<TResult>;
|
|
14
|
+
notify(name: string, ...args: unknown[]): Promise<void>;
|
|
19
15
|
private normalizeInvocation;
|
|
20
16
|
private isValidTarget;
|
|
21
17
|
private sendAndWait;
|
|
@@ -3,7 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RageMPRpc = void 0;
|
|
4
4
|
const contracts_1 = require("@open-core/framework/contracts");
|
|
5
5
|
const helpers_1 = require("./helpers");
|
|
6
|
+
function asErrorInfo(error) {
|
|
7
|
+
if (error instanceof Error) {
|
|
8
|
+
return { message: error.message, name: error.name };
|
|
9
|
+
}
|
|
10
|
+
return { message: String(error) };
|
|
11
|
+
}
|
|
6
12
|
function getCurrentResourceNameSafe() {
|
|
13
|
+
if (typeof __OPENCORE_RESOURCE_NAME__ === 'string' && __OPENCORE_RESOURCE_NAME__.trim()) {
|
|
14
|
+
return __OPENCORE_RESOURCE_NAME__;
|
|
15
|
+
}
|
|
7
16
|
if (typeof __dirname !== 'string')
|
|
8
17
|
return 'default';
|
|
9
18
|
const parts = __dirname.replace(/\\/g, '/').split('/');
|
|
@@ -28,7 +37,7 @@ class RageMPRpc extends contracts_1.RpcAPI {
|
|
|
28
37
|
});
|
|
29
38
|
}
|
|
30
39
|
on(name, handler) {
|
|
31
|
-
this.handlers.set(name, handler);
|
|
40
|
+
this.handlers.set(name, (ctx, ...args) => handler(ctx, ...args));
|
|
32
41
|
}
|
|
33
42
|
call(name, ...args) {
|
|
34
43
|
const { target, payload } = this.normalizeInvocation(name, 'call', args);
|
|
@@ -76,7 +85,7 @@ class RageMPRpc extends contracts_1.RpcAPI {
|
|
|
76
85
|
this.pending.delete(id);
|
|
77
86
|
reject(new Error(`RageMPRpc: timeout waiting for '${input.kind}' response for '${input.name}' (${id})`));
|
|
78
87
|
}, this.defaultTimeoutMs);
|
|
79
|
-
this.pending.set(id, { resolve: resolve, reject, timeout });
|
|
88
|
+
this.pending.set(id, { resolve: (value) => resolve(value), reject, timeout });
|
|
80
89
|
if (this.context === 'server') {
|
|
81
90
|
const resolvedTarget = this.resolveServerTarget(target, input.kind, input.name);
|
|
82
91
|
(0, helpers_1.emitNet)(this.context, this.requestEvent, resolvedTarget, msg);
|
|
@@ -139,6 +148,7 @@ class RageMPRpc extends contracts_1.RpcAPI {
|
|
|
139
148
|
}
|
|
140
149
|
}
|
|
141
150
|
catch (err) {
|
|
151
|
+
const errorInfo = asErrorInfo(err);
|
|
142
152
|
if (msg.kind === 'notify') {
|
|
143
153
|
this.emitResponse(replyTarget, { kind: 'ack', id: msg.id });
|
|
144
154
|
return;
|
|
@@ -148,8 +158,8 @@ class RageMPRpc extends contracts_1.RpcAPI {
|
|
|
148
158
|
id: msg.id,
|
|
149
159
|
ok: false,
|
|
150
160
|
error: {
|
|
151
|
-
message:
|
|
152
|
-
name:
|
|
161
|
+
message: errorInfo.message,
|
|
162
|
+
name: errorInfo.name,
|
|
153
163
|
},
|
|
154
164
|
});
|
|
155
165
|
}
|
|
@@ -171,7 +181,13 @@ class RageMPRpc extends contracts_1.RpcAPI {
|
|
|
171
181
|
return;
|
|
172
182
|
}
|
|
173
183
|
const error = new Error(msg.error?.message ?? 'RageMPRpc: remote error');
|
|
174
|
-
|
|
184
|
+
if (msg.error?.name) {
|
|
185
|
+
Object.defineProperty(error, 'name', {
|
|
186
|
+
value: msg.error.name,
|
|
187
|
+
configurable: true,
|
|
188
|
+
writable: true,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
175
191
|
pending.reject(error);
|
|
176
192
|
}
|
|
177
193
|
emitResponse(target, msg) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-core/ragemp-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "External Rage Multiplayer adapter for OpenCore framework.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,20 +37,18 @@
|
|
|
37
37
|
"adapter"
|
|
38
38
|
],
|
|
39
39
|
"license": "MPL-2.0",
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"@open-core/framework": "v1.0.5-beta.2"
|
|
42
|
-
},
|
|
43
40
|
"peerDependencies": {
|
|
44
41
|
"reflect-metadata": "^0.2.2",
|
|
45
42
|
"tsyringe": "^4.10.0",
|
|
46
43
|
"zod": "^4.3.5"
|
|
47
44
|
},
|
|
48
45
|
"devDependencies": {
|
|
49
|
-
"@biomejs/biome": "^2.
|
|
46
|
+
"@biomejs/biome": "^2.4.8",
|
|
47
|
+
"@open-core/framework": "latest",
|
|
50
48
|
"@ragempcommunity/types-client": "^2.1.9",
|
|
51
49
|
"@ragempcommunity/types-server": "^2.1.9",
|
|
52
|
-
"@types/node": "^25.0
|
|
53
|
-
"typescript": "^
|
|
50
|
+
"@types/node": "^25.5.0",
|
|
51
|
+
"typescript": "^6.0.2"
|
|
54
52
|
},
|
|
55
53
|
"scripts": {
|
|
56
54
|
"build": "tsc -b",
|