Skip to content

Commit

Permalink
Merge branch 'dev' into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Aug 17, 2024
2 parents f5a9da9 + 4ad0910 commit 2dce37f
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 14 deletions.
2 changes: 0 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ IndentWidth: 4
---
Language: Cpp
ColumnLimit: 190
AccessModifierOffset: 0
AlignAfterOpenBracket: true
#AlignConsecutiveAssignments: true
AlignConsecutiveBitFields: true
Expand All @@ -28,7 +27,6 @@ AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
#BitFieldColonSpacing: Both
BraceWrapping: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
Expand Down
27 changes: 25 additions & 2 deletions client/src/bindings/Handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,44 @@ static void DriveBiasFrontSetter(v8::Local<v8::String>, v8::Local<v8::Value> val
vehicle->GetHandling()->SetDriveBiasFront(fvalue);
}

static void DriveBiasRearGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& 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::String>, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& 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<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& 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::String>, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& 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<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
Expand Down Expand Up @@ -1230,6 +1252,7 @@ extern V8Class v8Handling("Handling", Constructor, [](v8::Local<v8::FunctionTemp
V8Helpers::SetAccessor(isolate, tpl, "percentSubmerged", &PercentSubmergedGetter, &PercentSubmergedSetter);
V8Helpers::SetAccessor(isolate, tpl, "percentSubmergedRatio", &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter);
V8Helpers::SetAccessor(isolate, tpl, "driveBiasFront", &DriveBiasFrontGetter, &DriveBiasFrontSetter);
V8Helpers::SetAccessor(isolate, tpl, "driveBiasRear", &DriveBiasRearGetter, &DriveBiasRearSetter);
V8Helpers::SetAccessor(isolate, tpl, "acceleration", &AccelerationGetter, &AccelerationSetter);
V8Helpers::SetAccessor(isolate, tpl, "initialDriveGears", &InitialDriveGearsGetter, &InitialDriveGearsSetter);
V8Helpers::SetAccessor(isolate, tpl, "driveInertia", &DriveInertiaGetter, &DriveInertiaSetter);
Expand Down
35 changes: 33 additions & 2 deletions client/src/bindings/HandlingData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,50 @@ static void DriveBiasFrontSetter(v8::Local<v8::String>, v8::Local<v8::Value> val
handling->SetDriveBiasFront(fvalue);
}

static void DriveBiasRearGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& 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::String>, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& 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<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear");

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->GetAcceleration());
V8_RETURN_NUMBER(handling->GetDriveBiasRear());
}

static void AccelerationSetter(v8::Local<v8::String>, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& info)
{
V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear");

V8_GET_ISOLATE_CONTEXT();

V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash);
Expand All @@ -343,7 +373,7 @@ static void AccelerationSetter(v8::Local<v8::String>, v8::Local<v8::Value> val,

V8_TO_NUMBER(val, fvalue);

handling->SetAcceleration(fvalue);
handling->SetDriveBiasRear(fvalue);
}

static void InitialDriveGearsGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
Expand Down Expand Up @@ -1759,6 +1789,7 @@ extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::Local<v8::Func
V8Helpers::SetAccessor(isolate, tpl, "percentSubmerged", &PercentSubmergedGetter, &PercentSubmergedSetter);
V8Helpers::SetAccessor(isolate, tpl, "percentSubmergedRatio", &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter);
V8Helpers::SetAccessor(isolate, tpl, "driveBiasFront", &DriveBiasFrontGetter, &DriveBiasFrontSetter);
V8Helpers::SetAccessor(isolate, tpl, "driveBiasRear", &DriveBiasRearGetter, &DriveBiasRearSetter);
V8Helpers::SetAccessor(isolate, tpl, "acceleration", &AccelerationGetter, &AccelerationSetter);
V8Helpers::SetAccessor(isolate, tpl, "initialDriveGears", &InitialDriveGearsGetter, &InitialDriveGearsSetter);
V8Helpers::SetAccessor(isolate, tpl, "driveInertia", &DriveInertiaGetter, &DriveInertiaSetter);
Expand Down
58 changes: 58 additions & 0 deletions client/src/bindings/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,48 @@ static void SetWheelTyreWidth(const v8::FunctionCallbackInfo<v8::Value>& info)
vehicle->SetWheelTyreWidth(wheel, value);
}

static void GetWheelDynamicFlag(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::Value>& 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<v8::Value>& 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<v8::Value>& 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<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
Expand All @@ -267,6 +309,15 @@ static void GetWheelSurfaceMaterial(const v8::FunctionCallbackInfo<v8::Value>& i
V8_RETURN_UINT(vehicle->GetWheelSurfaceMaterial(wheel));
}

static void SetupTransmission(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
Expand Down Expand Up @@ -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<IVehicle, float, &IVehicle::GetEngineTemperature, &IVehicle::SetEngineTemperature>(isolate, tpl, "engineTemperature");
V8Helpers::SetAccessor<IVehicle, float, &IVehicle::GetFuelLevel, &IVehicle::SetFuelLevel>(isolate, tpl, "fuelLevel");
V8Helpers::SetAccessor<IVehicle, float, &IVehicle::GetOilLevel, &IVehicle::SetOilLevel>(isolate, tpl, "oilLevel");
Expand All @@ -348,6 +404,8 @@ extern V8Class v8Vehicle("Vehicle",
V8Helpers::SetAccessor<IVehicle, float, &IVehicle::GetSteeringAngle, &IVehicle::SetSteeringAngle>(isolate, tpl, "steeringAngle");
V8Helpers::SetAccessor<IVehicle, float, &IVehicle::GetSuspensionHeight, &IVehicle::SetSuspensionHeight>(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);
Expand Down
2 changes: 1 addition & 1 deletion shared/bindings/BindingsMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<v8::Value>& info)
{
Expand Down
2 changes: 1 addition & 1 deletion shared/deps/cpp-sdk
10 changes: 5 additions & 5 deletions shared/helpers/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,11 @@ alt::MValueByteArray V8Helpers::V8ToRawBytes(v8::Local<v8::Value> 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();
Expand All @@ -547,14 +547,14 @@ v8::MaybeLocal<v8::Value> 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<v8::Value>();

// Check for magic bytes
uint8_t* magicBytesPtr;
if(!deserializer.ReadRawBytes(sizeof(magicBytes), (const void**)&magicBytesPtr)) return v8::MaybeLocal<v8::Value>();
if(memcmp(magicBytesPtr, magicBytes, sizeof(magicBytes)) != 0) return v8::MaybeLocal<v8::Value>();

bool headerValid;
if(!deserializer.ReadHeader(ctx).To(&headerValid) || !headerValid) return v8::MaybeLocal<v8::Value>();

// Deserialize the value
v8::MaybeLocal<v8::Value> result = deserializer.ReadValue(ctx);

Expand Down
24 changes: 23 additions & 1 deletion tools/enums-transpiler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// clang-format off
const https = require("https");
const fs = require("fs").promises;
const assert = require("assert");
const pathUtil = require("path");
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
});
});
}

0 comments on commit 2dce37f

Please sign in to comment.