From f5a9da963f313f7c6f632cb56eadfb3e0b22e7a8 Mon Sep 17 00:00:00 2001 From: Blue Date: Mon, 29 Jul 2024 18:00:26 +0200 Subject: [PATCH 1/8] update sdk --- shared/deps/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/deps/cpp-sdk b/shared/deps/cpp-sdk index 95a2cfad..22e1fdd3 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 95a2cfadc2ba1de018c8c55c72b21984067b6181 +Subproject commit 22e1fdd37b8e379d04b279161571276cb7bb12da From 55e23aa8149e9d7525acbf9bb274d181e46ae5c7 Mon Sep 17 00:00:00 2001 From: vadzz Date: Sun, 4 Aug 2024 15:59:41 +0300 Subject: [PATCH 2/8] feat(client): implement new sdk methods ALTV-278 --- .clang-format | 2 - client/src/bindings/Handling.cpp | 27 ++++++++++++- client/src/bindings/HandlingData.cpp | 35 ++++++++++++++++- client/src/bindings/Vehicle.cpp | 58 ++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 6 deletions(-) diff --git a/.clang-format b/.clang-format index 7cbf8ef7..8dd3281c 100644 --- a/.clang-format +++ b/.clang-format @@ -4,7 +4,6 @@ IndentWidth: 4 --- Language: Cpp ColumnLimit: 190 -AccessModifierOffset: 0 AlignAfterOpenBracket: true #AlignConsecutiveAssignments: true AlignConsecutiveBitFields: true @@ -28,7 +27,6 @@ AlwaysBreakTemplateDeclarations: Yes BinPackArguments: false BinPackParameters: false #BitFieldColonSpacing: Both -BraceWrapping: Custom BraceWrapping: AfterCaseLabel: true AfterClass: true diff --git a/client/src/bindings/Handling.cpp b/client/src/bindings/Handling.cpp index ce119d60..d572511d 100644 --- a/client/src/bindings/Handling.cpp +++ b/client/src/bindings/Handling.cpp @@ -221,22 +221,44 @@ static void DriveBiasFrontSetter(v8::Local, v8::Local val vehicle->GetHandling()->SetDriveBiasFront(fvalue); } +static void DriveBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + + V8_RETURN_NUMBER(vehicle->GetHandling()->GetDriveBiasRear()); +} + +static void DriveBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + + V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); + vehicle->GetHandling()->SetDriveBiasRear(fvalue); +} + static void AccelerationGetter(v8::Local, const v8::PropertyCallbackInfo& info) { + V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear"); + V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - V8_RETURN_NUMBER(vehicle->GetHandling()->GetAcceleration()); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetDriveBiasRear()); } static void AccelerationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { + V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear"); + V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); vehicle->ReplaceHandling(); - vehicle->GetHandling()->SetAcceleration(fvalue); + vehicle->GetHandling()->SetDriveBiasRear(fvalue); } static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -1230,6 +1252,7 @@ extern V8Class v8Handling("Handling", Constructor, [](v8::Local, v8::Local val handling->SetDriveBiasFront(fvalue); } +static void DriveBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + V8_RETURN_NUMBER(handling->GetDriveBiasRear()); +} + +static void DriveBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + V8_TO_NUMBER(val, fvalue); + + handling->SetDriveBiasRear(fvalue); +} + static void AccelerationGetter(v8::Local, const v8::PropertyCallbackInfo& info) { + V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear"); + V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); @@ -329,11 +357,13 @@ static void AccelerationGetter(v8::Local, const v8::PropertyCallback auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - V8_RETURN_NUMBER(handling->GetAcceleration()); + V8_RETURN_NUMBER(handling->GetDriveBiasRear()); } static void AccelerationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { + V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear"); + V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); @@ -343,7 +373,7 @@ static void AccelerationSetter(v8::Local, v8::Local val, V8_TO_NUMBER(val, fvalue); - handling->SetAcceleration(fvalue); + handling->SetDriveBiasRear(fvalue); } static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -1759,6 +1789,7 @@ extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::Local& info) vehicle->SetWheelTyreWidth(wheel, value); } +static void GetWheelDynamicFlag(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_INT(1, wheel); + V8_ARG_TO_UINT(2, flag); + V8_RETURN_BOOLEAN(vehicle->GetWheelDynamicFlag(wheel, flag)); +} + +static void SetWheelDynamicFlag(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + V8_CHECK_ARGS_LEN(3); + V8_ARG_TO_INT(1, wheel); + V8_ARG_TO_UINT(2, flag); + V8_ARG_TO_BOOLEAN(3, value); + vehicle->SetWheelDynamicFlag(wheel, flag, value); +} + +static void GetWheelConfigFlag(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_INT(1, wheel); + V8_ARG_TO_UINT(2, flag); + V8_RETURN_BOOLEAN(vehicle->GetWheelConfigFlag(wheel, flag)); +} + +static void SetWheelConfigFlag(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + V8_CHECK_ARGS_LEN(3); + V8_ARG_TO_INT(1, wheel); + V8_ARG_TO_UINT(2, flag); + V8_ARG_TO_BOOLEAN(3, value); + vehicle->SetWheelConfigFlag(wheel, flag, value); +} + static void GetWheelSurfaceMaterial(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -267,6 +309,15 @@ static void GetWheelSurfaceMaterial(const v8::FunctionCallbackInfo& i V8_RETURN_UINT(vehicle->GetWheelSurfaceMaterial(wheel)); } +static void SetupTransmission(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + V8_CHECK_ARGS_LEN(0); + + vehicle->SetupTransmission(); +} + static void StaticGetByRemoteId(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -331,6 +382,11 @@ extern V8Class v8Vehicle("Vehicle", V8Helpers::SetMethod(isolate, tpl, "getWheelTyreWidth", GetWheelTyreWidth); V8Helpers::SetMethod(isolate, tpl, "setWheelTyreWidth", SetWheelTyreWidth); + V8Helpers::SetMethod(isolate, tpl, "getWheelDynamicFlag", GetWheelDynamicFlag); + V8Helpers::SetMethod(isolate, tpl, "setWheelDynamicFlag", SetWheelDynamicFlag); + V8Helpers::SetMethod(isolate, tpl, "getWheelConfigFlag", GetWheelConfigFlag); + V8Helpers::SetMethod(isolate, tpl, "setWheelConfigFlag", SetWheelConfigFlag); + V8Helpers::SetAccessor(isolate, tpl, "engineTemperature"); V8Helpers::SetAccessor(isolate, tpl, "fuelLevel"); V8Helpers::SetAccessor(isolate, tpl, "oilLevel"); @@ -348,6 +404,8 @@ extern V8Class v8Vehicle("Vehicle", V8Helpers::SetAccessor(isolate, tpl, "steeringAngle"); V8Helpers::SetAccessor(isolate, tpl, "suspensionHeight"); + V8Helpers::SetMethod(isolate, tpl, "setupTransmission", SetupTransmission); + /*GETTERS BELOW ARE UNIMPLEMENTED V8Helpers::SetAccessor(isolate, tpl, "isDestroyed", &IsDestroyedGetter); V8Helpers::SetAccessor(isolate, tpl, "driver", &DriverGetter); From e21b1e4ac034a95d0ebbdb98af3d01fda627ddcc Mon Sep 17 00:00:00 2001 From: doxoh Date: Thu, 8 Aug 2024 13:13:30 +0200 Subject: [PATCH 3/8] chore: update sdk --- shared/deps/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/deps/cpp-sdk b/shared/deps/cpp-sdk index 22e1fdd3..b1ced940 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 22e1fdd37b8e379d04b279161571276cb7bb12da +Subproject commit b1ced94027a7b3c0c2167b12e45da80b49c8527b From 8a7c3454e22088d594fff40590a615cc64159b1b Mon Sep 17 00:00:00 2001 From: vadzz Date: Thu, 8 Aug 2024 15:14:09 +0300 Subject: [PATCH 4/8] Bump SDK --- shared/deps/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/deps/cpp-sdk b/shared/deps/cpp-sdk index 22e1fdd3..b1ced940 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 22e1fdd37b8e379d04b279161571276cb7bb12da +Subproject commit b1ced94027a7b3c0c2167b12e45da80b49c8527b From b9dbbca8be869d0113e711175f8c612c00fbe079 Mon Sep 17 00:00:00 2001 From: vadzz Date: Thu, 8 Aug 2024 15:16:22 +0300 Subject: [PATCH 5/8] chore: sdk --- shared/deps/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/deps/cpp-sdk b/shared/deps/cpp-sdk index b1ced940..defcd54b 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit b1ced94027a7b3c0c2167b12e45da80b49c8527b +Subproject commit defcd54bae97199ef3f82a47a06c0b69f47eb912 From 4168d6e6faa5475f8a0331b94b0459bd0fe375cb Mon Sep 17 00:00:00 2001 From: doxoh Date: Fri, 9 Aug 2024 10:05:29 +0200 Subject: [PATCH 6/8] fix #319 --- shared/bindings/BindingsMain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/bindings/BindingsMain.cpp b/shared/bindings/BindingsMain.cpp index ac64f040..a291be98 100644 --- a/shared/bindings/BindingsMain.cpp +++ b/shared/bindings/BindingsMain.cpp @@ -3,7 +3,7 @@ #include "../V8Helpers.h" #include "../V8ResourceImpl.h" #include "../V8Module.h" -#include "JSEnums.h" +#include "../JSEnums.h" static void HashCb(const v8::FunctionCallbackInfo& info) { From 88b992a90248bb84568073e432f749006f5cd513 Mon Sep 17 00:00:00 2001 From: doxoh Date: Fri, 9 Aug 2024 10:28:39 +0200 Subject: [PATCH 7/8] fix #319 --- tools/enums-transpiler.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tools/enums-transpiler.js b/tools/enums-transpiler.js index 83ce60c5..88ebb239 100644 --- a/tools/enums-transpiler.js +++ b/tools/enums-transpiler.js @@ -1,4 +1,5 @@ // clang-format off +const https = require("https"); const fs = require("fs").promises; const assert = require("assert"); const pathUtil = require("path"); @@ -140,7 +141,7 @@ const modules = [ let jsCode = ""; for (const m of modules) { - const content = await (await fetch(m)).text(); + const content = await fetchContent(m); jsCode += transpileTSEnums(content); } @@ -210,3 +211,24 @@ function showLog(...args) { function showError(...args) { console.error(`[${getTime()}]`, ...args); } + +function fetchContent(url) { + return new Promise((resolve, reject) => { + https.get(url, (response) => { + let data = ''; + + // A chunk of data has been received. + response.on('data', (chunk) => { + data += chunk; + }); + + // The whole response has been received. + response.on('end', () => { + resolve(data); + }); + + }).on('error', (error) => { + reject(error); + }); + }); + } \ No newline at end of file From 4ad0910b81990eaab9a6011907afb7d3abd004a4 Mon Sep 17 00:00:00 2001 From: xshady <54737754+xxshady@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:51:57 +0300 Subject: [PATCH 8/8] fix raw bytes (de)serialization (#322) --- shared/helpers/Serialization.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shared/helpers/Serialization.cpp b/shared/helpers/Serialization.cpp index 9bd23f80..5275f905 100644 --- a/shared/helpers/Serialization.cpp +++ b/shared/helpers/Serialization.cpp @@ -518,11 +518,11 @@ alt::MValueByteArray V8Helpers::V8ToRawBytes(v8::Local val) v8::ValueSerializer serializer(isolate, &delegate); delegate.SetSerializer(&serializer); - serializer.WriteHeader(); - // Write the magic bytes to the buffer serializer.WriteRawBytes(magicBytes, sizeof(magicBytes)); + serializer.WriteHeader(); + // Write the serialized value to the buffer bool result; if(!serializer.WriteValue(ctx, val).To(&result) || !result) return alt::MValueByteArray(); @@ -547,14 +547,14 @@ v8::MaybeLocal V8Helpers::RawBytesToV8(alt::MValueByteArrayConst rawB v8::ValueDeserializer deserializer(isolate, data, size, &delegate); delegate.SetDeserializer(&deserializer); - bool headerValid; - if(!deserializer.ReadHeader(ctx).To(&headerValid) || !headerValid) return v8::MaybeLocal(); - // Check for magic bytes uint8_t* magicBytesPtr; if(!deserializer.ReadRawBytes(sizeof(magicBytes), (const void**)&magicBytesPtr)) return v8::MaybeLocal(); if(memcmp(magicBytesPtr, magicBytes, sizeof(magicBytes)) != 0) return v8::MaybeLocal(); + bool headerValid; + if(!deserializer.ReadHeader(ctx).To(&headerValid) || !headerValid) return v8::MaybeLocal(); + // Deserialize the value v8::MaybeLocal result = deserializer.ReadValue(ctx);