From 820303f5e540d23d14f3fc1580095ebb156ec0a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20van=20L=C3=BCck?= <53119369+vanlueckn@users.noreply.github.com> Date: Sat, 26 Aug 2023 09:14:17 +0200 Subject: [PATCH 01/20] client: fix v8 argument size effects (#294) * client: fix v8 argument size chorus * client: fix v8 argument size echo4 effect --- client/src/bindings/AudioFilter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/bindings/AudioFilter.cpp b/client/src/bindings/AudioFilter.cpp index ea44fe1b..9a6d2c03 100644 --- a/client/src/bindings/AudioFilter.cpp +++ b/client/src/bindings/AudioFilter.cpp @@ -174,7 +174,7 @@ static void AddChorusEffect(const v8::FunctionCallbackInfo& info) V8_GET_THIS_BASE_OBJECT(filter, alt::IAudioFilter); - V8_CHECK_ARGS_LEN(6); + V8_CHECK_ARGS_LEN(7); V8_ARG_TO_NUMBER(1, fDryMix); V8_ARG_TO_NUMBER(2, fWetMix); V8_ARG_TO_NUMBER(3, fFeedback); @@ -244,7 +244,7 @@ static void AddEcho4Effect(const v8::FunctionCallbackInfo& info) V8_GET_THIS_BASE_OBJECT(filter, alt::IAudioFilter); - V8_CHECK_ARGS_LEN(4); + V8_CHECK_ARGS_LEN(5); V8_ARG_TO_NUMBER(1, fDryMix); V8_ARG_TO_NUMBER(2, fWetMix); V8_ARG_TO_NUMBER(3, fFeedback); From d84e4b5ee50f6ceda9bd5f2cd22fa279530df968 Mon Sep 17 00:00:00 2001 From: fabian Date: Sun, 27 Aug 2023 02:28:44 +0200 Subject: [PATCH 02/20] remove old alt::Array convert --- shared/helpers/Convert.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/shared/helpers/Convert.h b/shared/helpers/Convert.h index 687d16dd..8a8295cf 100644 --- a/shared/helpers/Convert.h +++ b/shared/helpers/Convert.h @@ -82,16 +82,6 @@ namespace V8Helpers return v8::BigInt::NewFromUnsigned(v8::Isolate::GetCurrent(), val); } template - inline v8::Local JSValue(alt::Array& arr) - { - auto jsArr = v8::Array::New(v8::Isolate::GetCurrent(), arr.GetSize()); - for(int i = 0; i < arr.GetSize(); i++) - { - jsArr->Set(v8::Isolate::GetCurrent()->GetEnteredOrMicrotaskContext(), i, JSValue(arr[i])); - } - return jsArr; - } - template inline v8::Local JSValue(std::vector& arr) { auto jsArr = v8::Array::New(v8::Isolate::GetCurrent(), arr.size()); From bcfb2b5b775f25d1de76db492bb069485a0e7b26 Mon Sep 17 00:00:00 2001 From: Blue Date: Sun, 27 Aug 2023 19:58:13 +0200 Subject: [PATCH 03/20] shared: 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 d7aed4c1..952a2d9f 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit d7aed4c1639b10c438d78d9697379693a2b8c74e +Subproject commit 952a2d9f815659035157493a0647208cebcaa3ce From ff4d9640e93419fcd96cabe82754873f0dea27ef Mon Sep 17 00:00:00 2001 From: Blue Date: Tue, 29 Aug 2023 15:35:33 +0200 Subject: [PATCH 04/20] server: add streaminglimit getter & seter --- server/src/bindings/Main.cpp | 112 +++++++++++++++++++++++++++++++++++ shared/deps/cpp-sdk | 2 +- 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/server/src/bindings/Main.cpp b/server/src/bindings/Main.cpp index 3c4515d1..530f0c62 100644 --- a/server/src/bindings/Main.cpp +++ b/server/src/bindings/Main.cpp @@ -589,6 +589,102 @@ static void SetVoiceExternal(const v8::FunctionCallbackInfo& info) alt::ICore::Instance().SetVoiceExternal(host, port); } +static void GetStreamingDistance(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_UINT(alt::ICore::Instance().GetStreamingDistance()); +} + +static void SetStreamingDistance(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_UINT(1, distance); + + alt::ICore::Instance().SetStreamingDistance(distance); +} + +static void GetStreamingTickRate(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_UINT(alt::ICore::Instance().GetStreamingTickRate()); +} + +static void SetStreamingTickRate(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_UINT(1, tickrate); + + alt::ICore::Instance().SetStreamingTickRate(tickrate); +} + +static void GetStreamerThreadCount(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_UINT(alt::ICore::Instance().GetStreamerThreadCount()); +} + +static void SetStreamerThreadCount(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_UINT(1, count); + + alt::ICore::Instance().SetStreamerThreadCount(count); +} + +static void GetMaxStreamingPeds(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_UINT(alt::ICore::Instance().GetMaxStreamingPeds()); +} + +static void SetMaxStreamingPeds(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_UINT(1, limit); + + alt::ICore::Instance().SetMaxStreamingPeds(limit); +} + +static void GetMaxStreamingObjects(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_UINT(alt::ICore::Instance().GetMaxStreamingObjects()); +} + +static void SetMaxStreamingObjects(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_UINT(1, limit); + + alt::ICore::Instance().SetMaxStreamingObjects(limit); +} + +static void GetMaxStreamingVehicles(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_UINT(alt::ICore::Instance().GetMaxStreamingVehicles()); +} + +static void SetMaxStreamingVehicles(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_UINT(1, limit); + + alt::ICore::Instance().SetMaxStreamingVehicles(limit); +} + extern V8Class v8Player, v8Vehicle, v8Blip, v8AreaBlip, v8RadiusBlip, v8PointBlip, v8Checkpoint, v8VoiceChannel, v8Colshape, v8ColshapeCylinder, v8ColshapeSphere, v8ColshapeCircle, v8ColshapeCuboid, v8ColshapeRectangle, v8ColshapePolygon, v8Ped, v8Object, v8VirtualEntity, v8VirtualEntityGroup, v8Marker, v8ConnectionInfo; @@ -645,5 +741,21 @@ extern V8Module V8Helpers::RegisterFunc(exports, "setVoiceExternalPublic", &SetVoiceExternalPublic); V8Helpers::RegisterFunc(exports, "setVoiceExternal", &SetVoiceExternal); + V8Helpers::RegisterFunc(exports, "getMaxStreamingPeds", &GetMaxStreamingPeds); + V8Helpers::RegisterFunc(exports, "getMaxStreamingObjects", &GetMaxStreamingObjects); + V8Helpers::RegisterFunc(exports, "getMaxStreamingVehicles", &GetMaxStreamingVehicles); + V8Helpers::RegisterFunc(exports, "setMaxStreamingPeds", &SetMaxStreamingPeds); + V8Helpers::RegisterFunc(exports, "setMaxStreamingObjects", &SetMaxStreamingObjects); + V8Helpers::RegisterFunc(exports, "setMaxStreamingVehicles", &SetMaxStreamingVehicles); + + V8Helpers::RegisterFunc(exports, "getStreamerThreadCount", &GetStreamerThreadCount); + V8Helpers::RegisterFunc(exports, "setStreamerThreadCount", &SetStreamerThreadCount); + + V8Helpers::RegisterFunc(exports, "getStreamingTickRate", &GetStreamingTickRate); + V8Helpers::RegisterFunc(exports, "setStreamingTickRate", &SetStreamingTickRate); + + V8Helpers::RegisterFunc(exports, "getStreamingDistance", &GetStreamingDistance); + V8Helpers::RegisterFunc(exports, "setStreamingDistance", &SetStreamingDistance); + V8_OBJECT_SET_STRING(exports, "rootDir", alt::ICore::Instance().GetRootDirectory()); }); diff --git a/shared/deps/cpp-sdk b/shared/deps/cpp-sdk index 952a2d9f..29284a83 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 952a2d9f815659035157493a0647208cebcaa3ce +Subproject commit 29284a834f886df34f2f5e824bdf5b89b316e1bf From c89f68585ced0084090e5a9947879b3f93563218 Mon Sep 17 00:00:00 2001 From: Blue Date: Tue, 29 Aug 2023 15:37:42 +0200 Subject: [PATCH 05/20] server: add playerheal event --- server/src/events/Player.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/src/events/Player.cpp b/server/src/events/Player.cpp index 873cfb23..e1af453f 100644 --- a/server/src/events/Player.cpp +++ b/server/src/events/Player.cpp @@ -218,3 +218,17 @@ V8_LOCAL_EVENT_HANDLER playerSpawn(EventType::PLAYER_SPAWN, args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer())); }); + +V8_LOCAL_EVENT_HANDLER playerHeal(EventType::PLAYER_HEAL, + "playerHeal", + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) + { + auto ev = static_cast(e); + v8::Isolate* isolate = resource->GetIsolate(); + + args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); + args.push_back(V8Helpers::JSValue(ev->GetOldHealth())); + args.push_back(V8Helpers::JSValue(ev->GetNewHealth())); + args.push_back(V8Helpers::JSValue(ev->GetOldArmour())); + args.push_back(V8Helpers::JSValue(ev->GetNewArmour())); + }); From 3f12024bba01a017e4fcd16dc91848e0c99d64d7 Mon Sep 17 00:00:00 2001 From: Blue Date: Wed, 30 Aug 2023 14:05:46 +0200 Subject: [PATCH 06/20] add more thread setter/getter --- server/src/bindings/Main.cpp | 114 +++++++++++++++++++++++++++++++++++ shared/deps/cpp-sdk | 2 +- 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/server/src/bindings/Main.cpp b/server/src/bindings/Main.cpp index 530f0c62..c432d5e6 100644 --- a/server/src/bindings/Main.cpp +++ b/server/src/bindings/Main.cpp @@ -685,6 +685,102 @@ static void SetMaxStreamingVehicles(const v8::FunctionCallbackInfo& i alt::ICore::Instance().SetMaxStreamingVehicles(limit); } +static void GetMigrationThreadCount(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_UINT(alt::ICore::Instance().GetMigrationThreadCount()); +} + +static void SetMigrationThreadCount(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_UINT(1, count); + + alt::ICore::Instance().SetMigrationThreadCount(count); +} + +static void GetSyncSendThreadCount(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_UINT(alt::ICore::Instance().GetSyncSendThreadCount()); +} + +static void SetSyncSendThreadCount(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_UINT(1, count); + + alt::ICore::Instance().SetSyncSendThreadCount(count); +} + +static void GetSyncReceiveThreadCount(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_UINT(alt::ICore::Instance().GetSyncReceiveThreadCount()); +} + +static void SetSyncReceiveThreadCount(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_UINT(1, count); + + alt::ICore::Instance().SetSyncReceiveThreadCount(count); +} + +static void GetMigrationTickRate(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_UINT(alt::ICore::Instance().GetMigrationTickRate()); +} + +static void SetMigrationTickRate(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_UINT(1, tickrate); + + alt::ICore::Instance().SetMigrationTickRate(tickrate); +} + +static void GetColShapeTickRate(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_UINT(alt::ICore::Instance().GetColShapeTickRate()); +} + +static void SetColShapeTickRate(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_UINT(1, tickrate); + + alt::ICore::Instance().SetColShapeTickRate(tickrate); +} + +static void GetMigrationDistance(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_UINT(alt::ICore::Instance().GetMigrationDistance()); +} + +static void SetMigrationDistance(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_UINT(1, tickrate); + + alt::ICore::Instance().SetMigrationDistance(tickrate); +} + extern V8Class v8Player, v8Vehicle, v8Blip, v8AreaBlip, v8RadiusBlip, v8PointBlip, v8Checkpoint, v8VoiceChannel, v8Colshape, v8ColshapeCylinder, v8ColshapeSphere, v8ColshapeCircle, v8ColshapeCuboid, v8ColshapeRectangle, v8ColshapePolygon, v8Ped, v8Object, v8VirtualEntity, v8VirtualEntityGroup, v8Marker, v8ConnectionInfo; @@ -751,11 +847,29 @@ extern V8Module V8Helpers::RegisterFunc(exports, "getStreamerThreadCount", &GetStreamerThreadCount); V8Helpers::RegisterFunc(exports, "setStreamerThreadCount", &SetStreamerThreadCount); + V8Helpers::RegisterFunc(exports, "getMigrationThreadCount", &GetMigrationThreadCount); + V8Helpers::RegisterFunc(exports, "setMigrationThreadCount", &SetMigrationThreadCount); + + V8Helpers::RegisterFunc(exports, "getSyncSendThreadCount", &GetSyncSendThreadCount); + V8Helpers::RegisterFunc(exports, "setSyncSendThreadCount", &SetSyncSendThreadCount); + + V8Helpers::RegisterFunc(exports, "getSyncReceiveThreadCount", &GetSyncReceiveThreadCount); + V8Helpers::RegisterFunc(exports, "setSyncReceiveThreadCount", &SetSyncReceiveThreadCount); + V8Helpers::RegisterFunc(exports, "getStreamingTickRate", &GetStreamingTickRate); V8Helpers::RegisterFunc(exports, "setStreamingTickRate", &SetStreamingTickRate); + V8Helpers::RegisterFunc(exports, "getMigrationTickRate", &GetMigrationTickRate); + V8Helpers::RegisterFunc(exports, "setMigrationTickRate", &SetMigrationTickRate); + + V8Helpers::RegisterFunc(exports, "getColShapeTickRate", &GetColShapeTickRate); + V8Helpers::RegisterFunc(exports, "setColShapeTickRate", &SetColShapeTickRate); + V8Helpers::RegisterFunc(exports, "getStreamingDistance", &GetStreamingDistance); V8Helpers::RegisterFunc(exports, "setStreamingDistance", &SetStreamingDistance); + V8Helpers::RegisterFunc(exports, "getMigrationDistance", &GetMigrationDistance); + V8Helpers::RegisterFunc(exports, "setMigrationDistance", &SetMigrationDistance); + V8_OBJECT_SET_STRING(exports, "rootDir", alt::ICore::Instance().GetRootDirectory()); }); diff --git a/shared/deps/cpp-sdk b/shared/deps/cpp-sdk index 29284a83..a56286dd 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 29284a834f886df34f2f5e824bdf5b89b316e1bf +Subproject commit a56286dd2f1705f8149e00873986263e08963ac2 From 655a5b303419f84a29cdbef877f3e85664017201 Mon Sep 17 00:00:00 2001 From: Blue Date: Wed, 30 Aug 2023 14:19:31 +0200 Subject: [PATCH 07/20] client: add waitforspawn localvehicle & localped --- shared/bindings/Utils.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shared/bindings/Utils.js b/shared/bindings/Utils.js index cd62140d..4ecb0142 100644 --- a/shared/bindings/Utils.js +++ b/shared/bindings/Utils.js @@ -1,4 +1,5 @@ -// // @ts-check // uncomment if you need typescript checks, e.g. for gta natives update +// // @ts-check // uncomment if you need typescript checks, e.g. for gta natives +// update /// // clang-format off // Utils JS bindings @@ -291,6 +292,14 @@ if (alt.isClient && !alt.isWorker) { return alt.Utils.waitFor(() => this.scriptID !== 0, timeout); } + alt.LocalVehicle.prototype.waitForSpawn = function(timeout = 2000) { + return alt.Utils.waitFor(() => this.scriptID !== 0, timeout); + } + + alt.LocalPed.prototype.waitForSpawn = function(timeout = 2000) { + return alt.Utils.waitFor(() => this.scriptID !== 0, timeout); + } + alt.Utils.drawText2dThisFrame = function( text, pos2d = new alt.Vector2(0.5), From d495dc3ef571d4653f297262888c57861175ecaa Mon Sep 17 00:00:00 2001 From: Mohammad Reza Gharabaghi <40915667+mrgharabaghi@users.noreply.github.com> Date: Wed, 30 Aug 2023 13:57:31 +0100 Subject: [PATCH 08/20] client: Add forgotten getByID and getByScriptID (#292) --- client/src/bindings/Audio.cpp | 23 ++++++ client/src/bindings/AudioOutput.cpp | 85 +-------------------- client/src/bindings/AudioOutputAttached.cpp | 74 ++++++++++++++++++ client/src/bindings/AudioOutputFrontend.cpp | 54 +++++++++++++ client/src/bindings/AudioOutputWorld.cpp | 57 ++++++++++++++ client/src/bindings/LocalObject.cpp | 40 ++++++++++ 6 files changed, 250 insertions(+), 83 deletions(-) create mode 100644 client/src/bindings/AudioOutputAttached.cpp create mode 100644 client/src/bindings/AudioOutputFrontend.cpp create mode 100644 client/src/bindings/AudioOutputWorld.cpp diff --git a/client/src/bindings/Audio.cpp b/client/src/bindings/Audio.cpp index e43760f5..43ed6bb3 100644 --- a/client/src/bindings/Audio.cpp +++ b/client/src/bindings/Audio.cpp @@ -2,7 +2,9 @@ #include "helpers/BindHelpers.h" #include "V8ResourceImpl.h" #include "V8Class.h" + #include "../CV8ScriptRuntime.h" + #include "cpp-sdk/script-objects/IAudio.h" #include "cpp-sdk/script-objects/IAudioOutput.h" @@ -133,6 +135,25 @@ static void AudioCountGetter(v8::Local name, const v8::PropertyCallb V8_RETURN_UINT(alt::ICore::Instance().GetBaseObjects(alt::IBaseObject::Type::AUDIO).size()); } +static void StaticGetByID(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_INT(1, id); + + alt::IBaseObject* baseObject = alt::ICore::Instance().GetBaseObjectByID(alt::IBaseObject::Type::AUDIO, id); + + if(baseObject) + { + V8_RETURN_BASE_OBJECT(baseObject); + } + else + { + V8_RETURN_NULL(); + } +} + extern V8Class v8BaseObject; extern V8Class v8Audio("Audio", v8BaseObject, @@ -142,6 +163,8 @@ extern V8Class v8Audio("Audio", using namespace alt; v8::Isolate* isolate = v8::Isolate::GetCurrent(); + V8Helpers::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); + V8Helpers::SetStaticAccessor(isolate, tpl, "all", &AllAudioGetter); V8Helpers::SetStaticAccessor(isolate, tpl, "count", &AudioCountGetter); diff --git a/client/src/bindings/AudioOutput.cpp b/client/src/bindings/AudioOutput.cpp index da28133f..3330b10e 100644 --- a/client/src/bindings/AudioOutput.cpp +++ b/client/src/bindings/AudioOutput.cpp @@ -2,12 +2,11 @@ #include "helpers/BindHelpers.h" #include "V8ResourceImpl.h" #include "V8Class.h" + #include "../CV8ScriptRuntime.h" + #include "cpp-sdk/objects/IWorldObject.h" #include "cpp-sdk/script-objects/IAudioOutput.h" -#include "cpp-sdk/script-objects/IAudioFrontendOutput.h" -#include "cpp-sdk/script-objects/IAudioWorldOutput.h" -#include "cpp-sdk/script-objects/IAudioAttachedOutput.h" static void Constructor(const v8::FunctionCallbackInfo& info) { @@ -16,44 +15,6 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_CHECK(false, "You can't use constructor of abstract class"); } -static void ConstructorFrontend(const v8::FunctionCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK_CONSTRUCTOR(); - V8_CHECK_ARGS_LEN_MIN_MAX(0, 1); - - V8_ARG_TO_INT_OPT(1, categoryHash, alt::ICore::Instance().Hash("radio")); - - auto output = alt::ICore::Instance().CreateFrontendOutput(categoryHash, resource->GetResource()); - V8_BIND_BASE_OBJECT(output, "Failed to create AudioOutputFrontend"); -} - -static void ConstructorWorld(const v8::FunctionCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK_CONSTRUCTOR(); - V8_CHECK_ARGS_LEN_MIN_MAX(1, 2); - - V8_ARG_TO_VECTOR3(1, pos); - V8_ARG_TO_INT_OPT(2, categoryHash, alt::ICore::Instance().Hash("radio")); - - auto output = alt::ICore::Instance().CreateWorldOutput(categoryHash, pos, resource->GetResource()); - V8_BIND_BASE_OBJECT(output, "Failed to create AudioOutputWorld"); -} - -static void ConstructorAttached(const v8::FunctionCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK_CONSTRUCTOR(); - V8_CHECK_ARGS_LEN_MIN_MAX(1, 2); - - V8_ARG_TO_BASE_OBJECT(1, entity, alt::IWorldObject, "IWorldObject"); - V8_ARG_TO_INT_OPT(2, categoryHash, alt::ICore::Instance().Hash("radio")); - - auto output = alt::ICore::Instance().CreateAttachedOutput(categoryHash, entity, resource->GetResource()); - V8_BIND_BASE_OBJECT(output, "Failed to create AudioOutputAttached"); -} - static void AllAudioOutputGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -66,23 +27,6 @@ static void AudioOutputCountGetter(v8::Local name, const v8::Propert V8_RETURN_UINT(alt::ICore::Instance().GetBaseObjects(alt::IBaseObject::Type::AUDIO_OUTPUT).size()); } -static void EntityGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(ent, alt::IAudioAttachedOutput); - V8_RETURN_BASE_OBJECT(ent->GetEntity()); -} - -static void EntitySetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(_this, alt::IAudioAttachedOutput); - - V8_TO_WORLDOBJECT(val, entity); - - _this->SetEntity(entity); -} - static void GetFilter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -129,28 +73,3 @@ extern V8Class v8AudioOutput("AudioOutput", V8Helpers::SetAccessor(isolate, tpl, "category"); V8Helpers::SetAccessor(isolate, tpl, "filter", &GetFilter, &SetFilter); }); - -extern V8Class v8AudioOutputFrontend("AudioOutputFrontend", - v8AudioOutput, - &ConstructorFrontend, - [](v8::Local tpl) { - - }); - -extern V8Class v8AudioOutputWorld("AudioOutputWorld", - v8AudioOutput, - &ConstructorWorld, - [](v8::Local tpl) - { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - V8Helpers::SetAccessor(isolate, tpl, "pos"); - }); - -extern V8Class v8AudioOutputAttached("AudioOutputAttached", - v8AudioOutput, - &ConstructorAttached, - [](v8::Local tpl) - { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - V8Helpers::SetAccessor(isolate, tpl, "entity", &EntityGetter, &EntitySetter); - }); diff --git a/client/src/bindings/AudioOutputAttached.cpp b/client/src/bindings/AudioOutputAttached.cpp new file mode 100644 index 00000000..6344853f --- /dev/null +++ b/client/src/bindings/AudioOutputAttached.cpp @@ -0,0 +1,74 @@ +#include "V8Helpers.h" +#include "helpers/BindHelpers.h" +#include "V8ResourceImpl.h" +#include "V8Class.h" + +#include "../CV8ScriptRuntime.h" + +#include "cpp-sdk/objects/IWorldObject.h" +#include "cpp-sdk/script-objects/IAudioOutput.h" +#include "cpp-sdk/script-objects/IAudioAttachedOutput.h" + +static void Constructor(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN_MIN_MAX(1, 2); + + V8_ARG_TO_BASE_OBJECT(1, entity, alt::IWorldObject, "IWorldObject"); + V8_ARG_TO_INT_OPT(2, categoryHash, alt::ICore::Instance().Hash("radio")); + + auto output = alt::ICore::Instance().CreateAttachedOutput(categoryHash, entity, resource->GetResource()); + V8_BIND_BASE_OBJECT(output, "Failed to create AudioOutputAttached"); +} + +static void EntityGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(ent, alt::IAudioAttachedOutput); + V8_RETURN_BASE_OBJECT(ent->GetEntity()); +} + +static void EntitySetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(_this, alt::IAudioAttachedOutput); + + V8_TO_WORLDOBJECT(val, entity); + + _this->SetEntity(entity); +} + +static void StaticGetByID(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_INT(1, id); + + alt::IBaseObject* baseObject = alt::ICore::Instance().GetBaseObjectByID(alt::IBaseObject::Type::AUDIO_OUTPUT_ATTACHED, id); + + if(baseObject) + { + V8_RETURN_BASE_OBJECT(baseObject); + } + else + { + V8_RETURN_NULL(); + } +} + +using namespace alt; + +extern V8Class v8AudioOutput; +extern V8Class v8AudioOutputAttached("AudioOutputAttached", + v8AudioOutput, + &Constructor, + [](v8::Local tpl) + { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8Helpers::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); + + V8Helpers::SetAccessor(isolate, tpl, "entity", &EntityGetter, &EntitySetter); + }); diff --git a/client/src/bindings/AudioOutputFrontend.cpp b/client/src/bindings/AudioOutputFrontend.cpp new file mode 100644 index 00000000..cbe31d43 --- /dev/null +++ b/client/src/bindings/AudioOutputFrontend.cpp @@ -0,0 +1,54 @@ +#include "V8Helpers.h" +#include "helpers/BindHelpers.h" +#include "V8ResourceImpl.h" +#include "V8Class.h" + +#include "../CV8ScriptRuntime.h" + +#include "cpp-sdk/objects/IWorldObject.h" +#include "cpp-sdk/script-objects/IAudioOutput.h" +#include "cpp-sdk/script-objects/IAudioFrontendOutput.h" + +static void Constructor(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN_MIN_MAX(0, 1); + + V8_ARG_TO_INT_OPT(1, categoryHash, alt::ICore::Instance().Hash("radio")); + + auto output = alt::ICore::Instance().CreateFrontendOutput(categoryHash, resource->GetResource()); + V8_BIND_BASE_OBJECT(output, "Failed to create AudioOutputFrontend"); +} + +static void StaticGetByID(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_INT(1, id); + + alt::IBaseObject* baseObject = alt::ICore::Instance().GetBaseObjectByID(alt::IBaseObject::Type::AUDIO_OUTPUT_FRONTEND, id); + + if(baseObject) + { + V8_RETURN_BASE_OBJECT(baseObject); + } + else + { + V8_RETURN_NULL(); + } +} + +using namespace alt; + +extern V8Class v8AudioOutput; +extern V8Class v8AudioOutputFrontend("AudioOutputFrontend", + v8AudioOutput, + &Constructor, + [](v8::Local tpl) + { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8Helpers::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); + }); diff --git a/client/src/bindings/AudioOutputWorld.cpp b/client/src/bindings/AudioOutputWorld.cpp new file mode 100644 index 00000000..f337dd95 --- /dev/null +++ b/client/src/bindings/AudioOutputWorld.cpp @@ -0,0 +1,57 @@ +#include "V8Helpers.h" +#include "helpers/BindHelpers.h" +#include "V8ResourceImpl.h" +#include "V8Class.h" + +#include "../CV8ScriptRuntime.h" + +#include "cpp-sdk/objects/IWorldObject.h" +#include "cpp-sdk/script-objects/IAudioOutput.h" +#include "cpp-sdk/script-objects/IAudioWorldOutput.h" + +static void Constructor(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN_MIN_MAX(1, 2); + + V8_ARG_TO_VECTOR3(1, pos); + V8_ARG_TO_INT_OPT(2, categoryHash, alt::ICore::Instance().Hash("radio")); + + auto output = alt::ICore::Instance().CreateWorldOutput(categoryHash, pos, resource->GetResource()); + V8_BIND_BASE_OBJECT(output, "Failed to create AudioOutputWorld"); +} + +static void StaticGetByID(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_INT(1, id); + + alt::IBaseObject* baseObject = alt::ICore::Instance().GetBaseObjectByID(alt::IBaseObject::Type::AUDIO_OUTPUT_WORLD, id); + + if(baseObject) + { + V8_RETURN_BASE_OBJECT(baseObject); + } + else + { + V8_RETURN_NULL(); + } +} + +using namespace alt; + +extern V8Class v8AudioOutput; +extern V8Class v8AudioOutputWorld("AudioOutputWorld", + v8AudioOutput, + &Constructor, + [](v8::Local tpl) + { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8Helpers::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); + + V8Helpers::SetAccessor(isolate, tpl, "pos"); + }); diff --git a/client/src/bindings/LocalObject.cpp b/client/src/bindings/LocalObject.cpp index 411a7864..867304c5 100644 --- a/client/src/bindings/LocalObject.cpp +++ b/client/src/bindings/LocalObject.cpp @@ -210,6 +210,43 @@ static void TextureVariatioGetter(v8::Local, const v8::PropertyCallb V8_RETURN_UINT(object->GetTextureVariation()); } +static void StaticGetByID(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_INT(1, id); + + alt::IBaseObject* baseObject = alt::ICore::Instance().GetBaseObjectByID(alt::IBaseObject::Type::LOCAL_OBJECT, id); + + if(baseObject && baseObject->GetType() == alt::IEntity::Type::LOCAL_OBJECT) + { + V8_RETURN_BASE_OBJECT(baseObject); + } + else + { + V8_RETURN_NULL(); + } +} + +static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INT(1, scriptGuid); + + alt::IWorldObject* entity = alt::ICore::Instance().GetWorldObjectByScriptID(scriptGuid); + + if(entity && (entity->GetType() == alt::IWorldObject::Type::LOCAL_OBJECT)) + { + V8_RETURN_BASE_OBJECT(entity); + } + else + { + V8_RETURN_NULL(); + } +} + extern V8Class v8Object; extern V8Class v8LocalObject("LocalObject", v8Object, @@ -221,6 +258,9 @@ extern V8Class v8LocalObject("LocalObject", V8Helpers::SetMethod(isolate, tpl, "toString", ToString); + V8Helpers::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); + V8Helpers::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); + V8Helpers::SetStaticAccessor(isolate, tpl, "all", &AllGetter); V8Helpers::SetStaticAccessor(isolate, tpl, "count", &CountGetter); From fa9f25c9c9ecbfd4ed231d1d5ebbfae316c37157 Mon Sep 17 00:00:00 2001 From: Blue Date: Sat, 2 Sep 2023 14:19:56 +0200 Subject: [PATCH 09/20] client: enable isCrouching & isStealthy getter --- client/src/bindings/Player.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/bindings/Player.cpp b/client/src/bindings/Player.cpp index 72bfbb74..64e0803d 100644 --- a/client/src/bindings/Player.cpp +++ b/client/src/bindings/Player.cpp @@ -213,8 +213,8 @@ extern V8Class v8Player("Player", V8Helpers::SetAccessor(isolate, tpl, "isParachuting"); // V8Helpers::SetAccessor(isolate, tpl, "isSuperJumpEnabled"); - // V8Helpers::SetAccessor(isolate, tpl, "isCrouching"); - // V8Helpers::SetAccessor(isolate, tpl, "isStealthy"); + V8Helpers::SetAccessor(isolate, tpl, "isCrouching"); + V8Helpers::SetAccessor(isolate, tpl, "isStealthy"); V8Helpers::SetAccessor(isolate, tpl, "filter", &GetFilter, &SetFilter); }); From 6a8f5a2241233384fd08ebbb037b5710dfbe68ce Mon Sep 17 00:00:00 2001 From: Blue Date: Sat, 2 Sep 2023 14:25:14 +0200 Subject: [PATCH 10/20] client: add hasWeaponComponent --- client/src/bindings/Player.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/client/src/bindings/Player.cpp b/client/src/bindings/Player.cpp index 64e0803d..5e7633eb 100644 --- a/client/src/bindings/Player.cpp +++ b/client/src/bindings/Player.cpp @@ -153,6 +153,39 @@ static void SetFilter(v8::Local, v8::Local val, const v8: } } +static void WeaponHasComponent(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(2); + V8_GET_THIS_BASE_OBJECT(player, IPlayer); + + uint32_t hash; + if(info[0]->IsNumber()) + { + V8_ARG_TO_UINT(1, weaponHash); + hash = weaponHash; + } + else + { + V8_ARG_TO_STRING(1, weaponHash); + hash = alt::ICore::Instance().Hash(weaponHash); + } + + uint32_t componentHash; + if(info[0]->IsNumber()) + { + V8_ARG_TO_UINT(2, componenthash); + componentHash = componenthash; + } + else + { + V8_ARG_TO_STRING(2, componenthash); + componentHash = alt::ICore::Instance().Hash(componenthash); + } + + V8_RETURN_BOOLEAN(player->HasWeaponComponent(hash, componentHash)); +} + extern V8Class v8Entity; extern V8Class v8Player("Player", v8Entity, @@ -187,6 +220,7 @@ extern V8Class v8Player("Player", // Weapon getters V8Helpers::SetAccessor(isolate, tpl, "currentWeaponComponents", &CurrentWeaponComponentsGetter); + V8Helpers::SetMethod(isolate, tpl, "hasWeaponComponent", &WeaponHasComponent); // V8Helpers::SetAccessor(isolate, tpl, "currentWeaponTintIndex", &CurrentWeaponTintIndexGetter); V8Helpers::SetAccessor(isolate, tpl, "currentWeapon"); V8Helpers::SetAccessor(isolate, tpl, "entityAimingAt"); From 4b59b5bed757b2a44e6ade362bdf655d182e03cc Mon Sep 17 00:00:00 2001 From: Blue Date: Sat, 2 Sep 2023 14:30:41 +0200 Subject: [PATCH 11/20] client: add currentWeaponTintIndex & getWeaponTintIndex --- client/src/bindings/Player.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/client/src/bindings/Player.cpp b/client/src/bindings/Player.cpp index 5e7633eb..e1fd1981 100644 --- a/client/src/bindings/Player.cpp +++ b/client/src/bindings/Player.cpp @@ -186,6 +186,27 @@ static void WeaponHasComponent(const v8::FunctionCallbackInfo& info) V8_RETURN_BOOLEAN(player->HasWeaponComponent(hash, componentHash)); } +static void GetWeaponTintIndex(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(2); + V8_GET_THIS_BASE_OBJECT(player, IPlayer); + + uint32_t hash; + if(info[0]->IsNumber()) + { + V8_ARG_TO_UINT(1, weaponHash); + hash = weaponHash; + } + else + { + V8_ARG_TO_STRING(1, weaponHash); + hash = alt::ICore::Instance().Hash(weaponHash); + } + + V8_RETURN_UINT(player->GetWeaponTintIndex(hash)); +} + extern V8Class v8Entity; extern V8Class v8Player("Player", v8Entity, @@ -221,7 +242,8 @@ extern V8Class v8Player("Player", // Weapon getters V8Helpers::SetAccessor(isolate, tpl, "currentWeaponComponents", &CurrentWeaponComponentsGetter); V8Helpers::SetMethod(isolate, tpl, "hasWeaponComponent", &WeaponHasComponent); - // V8Helpers::SetAccessor(isolate, tpl, "currentWeaponTintIndex", &CurrentWeaponTintIndexGetter); + V8Helpers::SetMethod(isolate, tpl, "getWeaponTintIndex", &GetWeaponTintIndex); + V8Helpers::SetAccessor(isolate, tpl, "currentWeaponTintIndex"); V8Helpers::SetAccessor(isolate, tpl, "currentWeapon"); V8Helpers::SetAccessor(isolate, tpl, "entityAimingAt"); V8Helpers::SetAccessor(isolate, tpl, "entityAimOffset"); From 95428ec9e45c13fbca1d009bc697000dfd4e602c Mon Sep 17 00:00:00 2001 From: Marcel N <67131061+xLuxy@users.noreply.github.com> Date: Sun, 3 Sep 2023 01:05:10 +0200 Subject: [PATCH 12/20] Add WeaponObject.getByID and WeaponObject.getByScriptID methods (#297) * client: Add WeaponObject.getByID and WeaponObject.getByScriptID methods * update WeaponObject.cpp * Fix build * simplyfy getByID and getByScriptID --- client/src/bindings/WeaponObject.cpp | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/client/src/bindings/WeaponObject.cpp b/client/src/bindings/WeaponObject.cpp index 602a9390..ca3e8e54 100644 --- a/client/src/bindings/WeaponObject.cpp +++ b/client/src/bindings/WeaponObject.cpp @@ -111,6 +111,38 @@ static void CountGetter(v8::Local name, const v8::PropertyCallbackIn V8_RETURN_UINT(alt::ICore::Instance().GetWeaponObjects().size()); } +static void StaticGetByID(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INT(1, id); + + alt::IBaseObject* baseObject = alt::ICore::Instance().GetBaseObjectByID(alt::IBaseObject::Type::LOCAL_OBJECT, id); + + if(baseObject && baseObject->GetType() == alt::IEntity::Type::LOCAL_OBJECT) + { + V8_RETURN_BASE_OBJECT(baseObject); + } + + V8_RETURN_NULL(); +} + +static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INT(1, scriptId); + + alt::IWorldObject* entity = alt::ICore::Instance().GetWorldObjectByScriptID(scriptId); + + if(entity && (entity->GetType() == alt::IWorldObject::Type::LOCAL_OBJECT)) + { + V8_RETURN_BASE_OBJECT(entity); + } + + V8_RETURN_NULL(); +} + extern V8Class v8LocalObject; extern V8Class v8WeaponObject("WeaponObject", v8LocalObject, @@ -122,6 +154,8 @@ extern V8Class v8WeaponObject("WeaponObject", V8Helpers::SetStaticAccessor(isolate, tpl, "all", &AllGetter); V8Helpers::SetStaticAccessor(isolate, tpl, "count", &CountGetter); + V8Helpers::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); + V8Helpers::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); V8Helpers::SetAccessor(isolate, tpl, "tintIndex"); V8Helpers::SetMethod(isolate, tpl, "setComponentTintIndex", &GetComponentTintIndex); From 54cbf80c1eb81d8e25a04ff392636209ceaf6ee5 Mon Sep 17 00:00:00 2001 From: Blue Date: Sun, 3 Sep 2023 01:39:03 +0200 Subject: [PATCH 13/20] client: fix weapobject getby --- client/src/bindings/WeaponObject.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/src/bindings/WeaponObject.cpp b/client/src/bindings/WeaponObject.cpp index ca3e8e54..fc28dbf3 100644 --- a/client/src/bindings/WeaponObject.cpp +++ b/client/src/bindings/WeaponObject.cpp @@ -122,6 +122,7 @@ static void StaticGetByID(const v8::FunctionCallbackInfo& info) if(baseObject && baseObject->GetType() == alt::IEntity::Type::LOCAL_OBJECT) { V8_RETURN_BASE_OBJECT(baseObject); + return; } V8_RETURN_NULL(); @@ -138,6 +139,7 @@ static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) if(entity && (entity->GetType() == alt::IWorldObject::Type::LOCAL_OBJECT)) { V8_RETURN_BASE_OBJECT(entity); + return; } V8_RETURN_NULL(); From 7e9417f235c47b0c8456dd8f5343034d4404f81f Mon Sep 17 00:00:00 2001 From: Marcel N <67131061+xLuxy@users.noreply.github.com> Date: Sun, 3 Sep 2023 14:07:18 +0200 Subject: [PATCH 14/20] shared: Fix Vector(2/3).normalize() returning NaNs when dividing by zero (#298) --- shared/bindings/Vector2.js | 2 +- shared/bindings/Vector3.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/bindings/Vector2.js b/shared/bindings/Vector2.js index f7110589..4be2b62b 100644 --- a/shared/bindings/Vector2.js +++ b/shared/bindings/Vector2.js @@ -111,7 +111,7 @@ alt.Vector2.prototype.inverse = function() { alt.Vector2.prototype.normalize = function() { const length = this.length; - return new alt.Vector2(this.x / length, this.y / length); + return new alt.Vector2(this.x == 0 ? 0 : this.x / length, this.y == 0 ? 0 : this.y / length); } alt.Vector2.prototype.distanceTo = function(vector) { diff --git a/shared/bindings/Vector3.js b/shared/bindings/Vector3.js index eb2a6755..8f65d83b 100644 --- a/shared/bindings/Vector3.js +++ b/shared/bindings/Vector3.js @@ -136,7 +136,7 @@ alt.Vector3.prototype.inverse = function() { alt.Vector3.prototype.normalize = function() { const length = this.length; - return new alt.Vector3(this.x / length, this.y / length, this.z / length); + return new alt.Vector3(this.x == 0 ? 0 : this.x / length, this.y == 0 ? 0: this.y / length, this.z == 0 ? 0 : this.z / length); } alt.Vector3.prototype.distanceTo = function(vector) { From 449188bc70e0075a7016571e327fc9d3da805974 Mon Sep 17 00:00:00 2001 From: Marcel N <67131061+xLuxy@users.noreply.github.com> Date: Mon, 4 Sep 2023 00:42:27 +0200 Subject: [PATCH 15/20] server: Add vehicle passengers getter (#296) --- server/src/CNodeResourceImpl.cpp | 51 ++++++++++++++++++++++++++++++++ server/src/CNodeResourceImpl.h | 1 + server/src/bindings/Vehicle.cpp | 22 ++++++++++++++ shared/IRuntimeEventHandler.h | 4 +++ shared/V8ResourceImpl.h | 4 +++ 5 files changed, 82 insertions(+) diff --git a/server/src/CNodeResourceImpl.cpp b/server/src/CNodeResourceImpl.cpp index 0c70c51a..09e32741 100644 --- a/server/src/CNodeResourceImpl.cpp +++ b/server/src/CNodeResourceImpl.cpp @@ -140,6 +140,8 @@ void CNodeResourceImpl::OnEvent(const alt::CEvent* e) v8::Context::Scope scope(GetContext()); // env->PushAsyncCallbackScope(); + HandleVehiclePassengerSeatEvents(e); + V8Helpers::EventHandler* handler = V8Helpers::EventHandler::Get(e); if(!handler) return; @@ -186,6 +188,55 @@ void CNodeResourceImpl::OnEvent(const alt::CEvent* e) return; } +void CNodeResourceImpl::HandleVehiclePassengerSeatEvents(const alt::CEvent* ev) +{ + auto evType = ev->GetType(); + + if (evType == alt::CEvent::Type::PLAYER_ENTER_VEHICLE) + { + auto event = static_cast(ev); + auto vehicle = event->GetTarget(); + auto player = event->GetPlayer(); + auto seat = event->GetSeat(); + + if (!vehiclePassengers.contains(vehicle)) + vehiclePassengers[vehicle] = {}; + + vehiclePassengers[vehicle][seat] = player; + } + else if (evType == alt::CEvent::Type::PLAYER_LEAVE_VEHICLE) + { + auto event = static_cast(ev); + auto vehicle = event->GetTarget(); + auto player = event->GetPlayer(); + + if (vehiclePassengers.contains(vehicle)) + { + for ( auto it = vehiclePassengers[vehicle].begin(); it != vehiclePassengers[vehicle].end(); ) + { + if (it->second == player) + it = vehiclePassengers[vehicle].erase(it); + else + ++it; + } + + if (vehiclePassengers[vehicle].empty()) + vehiclePassengers.erase(vehicle); + } + } + else if (evType == alt::CEvent::Type::PLAYER_CHANGE_VEHICLE_SEAT) + { + auto event = static_cast(ev); + auto vehicle = event->GetTarget(); + + if (!vehiclePassengers.contains(vehicle)) + vehiclePassengers[vehicle] = {}; + + vehiclePassengers[vehicle].erase(event->GetOldSeat()); + vehiclePassengers[vehicle][event->GetNewSeat()] = event->GetPlayer(); + } +} + void CNodeResourceImpl::OnTick() { v8::Locker locker(isolate); diff --git a/server/src/CNodeResourceImpl.h b/server/src/CNodeResourceImpl.h index d17242f4..3581c63a 100644 --- a/server/src/CNodeResourceImpl.h +++ b/server/src/CNodeResourceImpl.h @@ -25,6 +25,7 @@ class CNodeResourceImpl : public V8ResourceImpl bool Stop() override; void OnEvent(const alt::CEvent* ev) override; + void HandleVehiclePassengerSeatEvents(const alt::CEvent* ev); void OnTick() override; bool MakeClient(alt::IResource::CreationInfo* info, std::vector) override; diff --git a/server/src/bindings/Vehicle.cpp b/server/src/bindings/Vehicle.cpp index dd841a35..48f79231 100644 --- a/server/src/bindings/Vehicle.cpp +++ b/server/src/bindings/Vehicle.cpp @@ -229,6 +229,27 @@ static void RoofClosedGetter(v8::Local name, const v8::PropertyCallb V8_RETURN_BOOLEAN(_this->GetRoofState() == 1); } +static void GetPassengers(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(_this, IVehicle); + + auto obj = v8::Object::New(isolate); + auto passengers = V8ResourceImpl::vehiclePassengers[_this]; + + if (!passengers.empty()) + { + for (auto& [seat, player] : passengers) + { + auto entity = resource->GetBaseObjectOrNull(player); + if (!entity->IsNull()) + obj->Set(ctx, seat, entity); + } + } + + V8_RETURN(obj); +} + extern V8Class v8Entity; extern V8Class v8Vehicle("Vehicle", v8Entity, @@ -244,6 +265,7 @@ extern V8Class v8Vehicle("Vehicle", // Common getter/setters V8Helpers::SetAccessor(isolate, tpl, "destroyed"); V8Helpers::SetAccessor(isolate, tpl, "driver"); + V8Helpers::SetAccessor(isolate, tpl, "passengers", &GetPassengers); V8Helpers::SetAccessor(isolate, tpl, "velocity"); V8Helpers::SetAccessor(isolate, tpl, "quaternion"); diff --git a/shared/IRuntimeEventHandler.h b/shared/IRuntimeEventHandler.h index e18cc9e2..f5507202 100644 --- a/shared/IRuntimeEventHandler.h +++ b/shared/IRuntimeEventHandler.h @@ -15,6 +15,10 @@ class IRuntimeEventHandler // All events the module uses, which need to be enabled and never disabled static constexpr std::array internalEvents = { EventType::CONNECTION_COMPLETE, EventType::DISCONNECT_EVENT, EventType::GAME_ENTITY_CREATE, EventType::GAME_ENTITY_DESTROY, EventType::RESOURCE_STOP +#ifdef ALT_SERVER_API + // required for vehicle seat stuff + , EventType::PLAYER_ENTER_VEHICLE, EventType::PLAYER_LEAVE_VEHICLE, EventType::PLAYER_CHANGE_VEHICLE_SEAT +#endif }; // Keeps track of the event handlers registered for all events diff --git a/shared/V8ResourceImpl.h b/shared/V8ResourceImpl.h index a382e9f4..8e7d69d3 100644 --- a/shared/V8ResourceImpl.h +++ b/shared/V8ResourceImpl.h @@ -313,6 +313,10 @@ class V8ResourceImpl : public alt::IResource::Impl return static_cast(ctx->GetAlignedPointerFromEmbedderData(1)); } +#ifdef ALT_SERVER_API + static inline std::unordered_map> vehiclePassengers{}; +#endif + protected: v8::Isolate* isolate; alt::IResource* resource; From e2f7ae1b331ec541246df0a1edb2a2b220de83aa Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Sun, 10 Sep 2023 00:52:17 +0300 Subject: [PATCH 16/20] client: add vehicle steeringAngle setter --- client/src/bindings/Vehicle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/bindings/Vehicle.cpp b/client/src/bindings/Vehicle.cpp index b564fbcc..9c206b07 100644 --- a/client/src/bindings/Vehicle.cpp +++ b/client/src/bindings/Vehicle.cpp @@ -345,7 +345,7 @@ extern V8Class v8Vehicle("Vehicle", V8Helpers::SetMethod(isolate, tpl, "getWheelSurfaceMaterial", GetWheelSurfaceMaterial); - V8Helpers::SetAccessor(isolate, tpl, "steeringAngle"); + V8Helpers::SetAccessor(isolate, tpl, "steeringAngle"); V8Helpers::SetAccessor(isolate, tpl, "suspensionHeight"); /*GETTERS BELOW ARE UNIMPLEMENTED From b43c86508b3e3b59843e67d818cab57c6a3b3b9f Mon Sep 17 00:00:00 2001 From: Blue Date: Sat, 9 Sep 2023 23:59:08 +0200 Subject: [PATCH 17/20] shared: 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 a56286dd..8d413726 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit a56286dd2f1705f8149e00873986263e08963ac2 +Subproject commit 8d4137268d821fbdc0fb5c954c350a2608072335 From adfceb5662043e0f3896b6163435d388fb75d888 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sun, 10 Sep 2023 10:36:20 +0200 Subject: [PATCH 18/20] move event cancel logic to its own class --- shared/V8ResourceImpl.cpp | 4 ++-- shared/deps/cpp-sdk | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shared/V8ResourceImpl.cpp b/shared/V8ResourceImpl.cpp index de9429f8..ea54422b 100644 --- a/shared/V8ResourceImpl.cpp +++ b/shared/V8ResourceImpl.cpp @@ -515,7 +515,7 @@ void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent* ev, const std::vecto if(retn.IsEmpty()) return false; v8::Local returnValue = retn.ToLocalChecked(); - if(ev && returnValue->IsFalse()) ev->Cancel(); + if(ev && returnValue->IsFalse() && ev->IsCancellable()) static_cast(ev)->Cancel(); else if(ev && ev->GetType() == alt::CEvent::Type::WEAPON_DAMAGE_EVENT && returnValue->IsNumber()) static_cast(const_cast(ev))->SetDamageValue((uint32_t)returnValue->NumberValue(GetContext()).ToChecked()); // todo: add this once a generic Cancel() with string as arg has been added to the sdk @@ -544,7 +544,7 @@ void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent* ev, const std::vecto else if(state == v8::Promise::PromiseState::kFulfilled) { v8::Local value = promise->Result(); - if(value->IsFalse()) ev->Cancel(); + if(value->IsFalse() && ev->IsCancellable()) static_cast(ev)->Cancel(); break; } else if(state == v8::Promise::PromiseState::kRejected) diff --git a/shared/deps/cpp-sdk b/shared/deps/cpp-sdk index 8d413726..7eb7c90f 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 8d4137268d821fbdc0fb5c954c350a2608072335 +Subproject commit 7eb7c90fc934221125cac11f6c14d8cc9276f710 From a9d226de8bee91d18c650dbee3c479d7a228018a Mon Sep 17 00:00:00 2001 From: Blue Date: Sun, 10 Sep 2023 15:34:33 +0200 Subject: [PATCH 19/20] 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 7eb7c90f..4ac10c63 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 7eb7c90fc934221125cac11f6c14d8cc9276f710 +Subproject commit 4ac10c631e45eb81798f7b49a7bcdb0ff8a8dc05 From 132b88b9c347b7122eaa82349a63992b6ac4b33d Mon Sep 17 00:00:00 2001 From: Blue Date: Sun, 10 Sep 2023 19:44:26 +0200 Subject: [PATCH 20/20] 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 4ac10c63..ab604174 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 4ac10c631e45eb81798f7b49a7bcdb0ff8a8dc05 +Subproject commit ab604174853306108976057a6c1e9c5f0b54c27c