From dd9287beb1a6195e739de92321e8f08c8982458a Mon Sep 17 00:00:00 2001 From: xLuxy <67131061+xLuxy@users.noreply.github.com> Date: Thu, 15 Feb 2024 03:12:23 +0100 Subject: [PATCH] fix(shared): always return values as bigint when using 64bit values --- shared/src/helpers/CallContext.h | 14 ++++++++++++-- types/server/index.d.ts | 16 ++++++++-------- types/server/package.json | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/shared/src/helpers/CallContext.h b/shared/src/helpers/CallContext.h index 5c2136ded..112ece68d 100644 --- a/shared/src/helpers/CallContext.h +++ b/shared/src/helpers/CallContext.h @@ -158,8 +158,18 @@ namespace js using Type = std::conditional_t, int, T>; if(errored) return; - // Use fast primitive setters if possible - if constexpr(std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v) + + // Convert 64-bit integers to BigInt + if constexpr(std::is_same_v || std::is_same_v) + { + bool constexpr isUnsigned = std::is_same_v; + if constexpr(isUnsigned) + info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(info.GetIsolate(), value)); + else + info.GetReturnValue().Set(v8::BigInt::New(info.GetIsolate(), value)); + } + // Then try to convert the value to primitive types + else if constexpr(std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v) info.GetReturnValue().Set((Type)value); else if constexpr(std::is_same_v) info.GetReturnValue().SetNull(); diff --git a/types/server/index.d.ts b/types/server/index.d.ts index 9ed9d006a..cdd06ec0a 100644 --- a/types/server/index.d.ts +++ b/types/server/index.d.ts @@ -298,12 +298,12 @@ declare module "@altv/server" { export class Metric { readonly name: string; - value: number; + value: bigint; readonly valid: boolean; constructor(name: string, type?: altShared.Enums.MetricType); - add(value: number): void; + add(value: bigint | number): void; inc(): void; begin(): void; @@ -376,10 +376,10 @@ declare module "@altv/server" { readonly name: string; readonly ip: string; - readonly socialID: number | bigint; + readonly socialID: bigint; readonly socialClubName: string; - readonly hwidHash: number | bigint; - readonly hwidExHash: number | bigint; + readonly hwidHash: bigint; + readonly hwidExHash: bigint; readonly cloudID: string; readonly cloudAuthResult: altShared.Enums.CloudAuthResult; @@ -931,12 +931,12 @@ declare module "@altv/server" { export abstract class ConnectionInfo { readonly name: string; - readonly socialID: number | bigint; + readonly socialID: bigint; readonly cloudID: string; readonly cloudAuthResult: altShared.Enums.CloudAuthResult; readonly socialName: string; - readonly hwidHash: number | bigint; - readonly hwidExHash: number | bigint; + readonly hwidHash: bigint; + readonly hwidExHash: bigint; readonly authToken: string; readonly versionMajor: number; readonly versionMinor: number; diff --git a/types/server/package.json b/types/server/package.json index 52d48d453..23f19f80d 100644 --- a/types/server/package.json +++ b/types/server/package.json @@ -1,6 +1,6 @@ { "name": "@altv/server", - "version": "0.0.31", + "version": "0.0.32", "description": "This package contains the type definitions for the alt:V JS module v2 server types", "types": "index.d.ts", "files": [