Skip to content

Commit

Permalink
fix(shared): always return values as bigint when using 64bit values
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Feb 15, 2024
1 parent 05d9152 commit dd9287b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
14 changes: 12 additions & 2 deletions shared/src/helpers/CallContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,18 @@ namespace js
using Type = std::conditional_t<std::is_enum_v<T>, int, T>;

if(errored) return;
// Use fast primitive setters if possible
if constexpr(std::is_same_v<Type, bool> || std::is_same_v<Type, double> || std::is_same_v<Type, float> || std::is_same_v<Type, int32_t> || std::is_same_v<Type, uint32_t>)

// Convert 64-bit integers to BigInt
if constexpr(std::is_same_v<Type, int64_t> || std::is_same_v<Type, uint64_t>)
{
bool constexpr isUnsigned = std::is_same_v<Type, uint64_t>;
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<Type, bool> || std::is_same_v<Type, double> || std::is_same_v<Type, float> || std::is_same_v<Type, int32_t> || std::is_same_v<Type, uint32_t>)
info.GetReturnValue().Set((Type)value);
else if constexpr(std::is_same_v<Type, std::nullptr_t>)
info.GetReturnValue().SetNull();
Expand Down
16 changes: 8 additions & 8 deletions types/server/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion types/server/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit dd9287b

Please sign in to comment.