From 12dd50b3fe221f6786f18ec6b299b22406c8fb46 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 12 Nov 2020 06:27:33 +0100 Subject: [PATCH 01/22] Adapt for updated helpers Former-commit-id: 5a91e4e576ea9b986800ef73830637eda256361e --- CMakeLists.txt | 1 + src/bindings/Blip.cpp | 5 ++-- src/bindings/Checkpoint.cpp | 3 +- src/bindings/ColShape.cpp | 13 +++++---- src/bindings/Main.cpp | 55 +++++++++++++++++++++++------------ src/bindings/Player.cpp | 3 +- src/bindings/Vehicle.cpp | 3 +- src/bindings/VoiceChannel.cpp | 3 +- src/helpers | 2 +- src/stdafx.h | 2 +- 10 files changed, 58 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27643a43..8f381be3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ add_definitions(-DBUILDING_CHAKRASHIM=1) add_definitions(-DHTTP_PARSER_STRICT=0) add_definitions(-DNGHTTP2_STATICLIB) add_definitions(-DHAVE_INSPECTOR=1) +add_definitions(-DALT_SERVER_API) file(GLOB_RECURSE PROJECT_SOURCE_FILES "src/*.h" "src/*.hpp" "src/*.cpp") diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index ad7ad5dd..dbd3cb7b 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -29,11 +29,12 @@ static void PointConstructor(const v8::FunctionCallbackInfo& info) V8Helpers::Throw(isolate, "Failed to create Blip"); } -static V8Class v8Blip("Blip", "WorldObject", nullptr, [](v8::Local tpl) { +extern V8Class v8WorldObject; +extern V8Class v8Blip("Blip", v8WorldObject, nullptr, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); }); -static V8Class v8PointBlip("PointBlip", "Blip", PointConstructor, [](v8::Local tpl) { +extern V8Class v8PointBlip("PointBlip", v8Blip, PointConstructor, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); }); diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index 69f93cfc..46543faf 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -37,6 +37,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8Helpers::Throw(isolate, "Failed to create Checkpoint"); } -static V8Class v8Checkpoint("Checkpoint", "Colshape", Constructor, [](v8::Local tpl) { +extern V8Class v8Colshape; +extern V8Class v8Checkpoint("Checkpoint", v8Colshape, Constructor, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); }); diff --git a/src/bindings/ColShape.cpp b/src/bindings/ColShape.cpp index be09b757..2506ab87 100755 --- a/src/bindings/ColShape.cpp +++ b/src/bindings/ColShape.cpp @@ -71,7 +71,8 @@ static void PlayersOnlySetter(v8::Local name, v8::Local v _this->SetPlayersOnly(playersOnly); } -static V8Class v8Colshape("Colshape", "WorldObject", nullptr, [](v8::Local tpl) { +extern V8Class v8WorldObject; +extern V8Class v8Colshape("Colshape", v8WorldObject, nullptr, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); V8::SetAccessor(isolate, tpl, "colshapeType", ColshapeTypeGetter); @@ -80,7 +81,7 @@ static V8Class v8Colshape("Colshape", "WorldObject", nullptr, [](v8::Local& info) +extern V8Class v8ColshapeCylinder("ColshapeCylinder", v8Colshape, [](const v8::FunctionCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); @@ -105,7 +106,7 @@ static V8Class v8ColshapeCylinder("ColshapeCylinder", "Colshape", [](const v8::F V8Helpers::Throw(isolate, "Failed to create ColshapeCylinder"); }, [](v8::Local tpl) {}); -static V8Class v8ColshapeSphere("ColshapeSphere", "Colshape", [](const v8::FunctionCallbackInfo& info) +extern V8Class v8ColshapeSphere("ColshapeSphere", v8Colshape, [](const v8::FunctionCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); @@ -128,7 +129,7 @@ static V8Class v8ColshapeSphere("ColshapeSphere", "Colshape", [](const v8::Funct V8Helpers::Throw(isolate, "Failed to create ColshapeSphere"); }, [](v8::Local tpl) {}); -static V8Class v8ColshapeCircle("ColshapeCircle", "Colshape", [](const v8::FunctionCallbackInfo& info) +extern V8Class v8ColshapeCircle("ColshapeCircle", v8Colshape, [](const v8::FunctionCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); @@ -150,7 +151,7 @@ static V8Class v8ColshapeCircle("ColshapeCircle", "Colshape", [](const v8::Funct V8Helpers::Throw(isolate, "Failed to create ColshapeCircle"); }, [](v8::Local tpl) {}); -static V8Class v8ColshapeCuboid("ColshapeCuboid", "Colshape", [](const v8::FunctionCallbackInfo& info) +extern V8Class v8ColshapeCuboid("ColshapeCuboid", v8Colshape, [](const v8::FunctionCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); @@ -175,7 +176,7 @@ static V8Class v8ColshapeCuboid("ColshapeCuboid", "Colshape", [](const v8::Funct V8Helpers::Throw(isolate, "Failed to create ColshapeCuboid"); }, [](v8::Local tpl) {}); -static V8Class v8ColshapeRectangle("ColshapeRectangle", "Colshape", [](const v8::FunctionCallbackInfo& info) +extern V8Class v8ColshapeRectangle("ColshapeRectangle", v8Colshape, [](const v8::FunctionCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 14fa5ab0..f64e8a4d 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -242,26 +242,45 @@ static void ResourceLoaded(const v8::FunctionCallbackInfo& info) } } +extern V8Class v8Vector3, + v8RGBA, + v8File, + v8BaseObject, + v8WorldObject, + v8Entity, + v8Player, + v8Vehicle, + v8Blip, + v8PointBlip, + v8Checkpoint, + v8VoiceChannel, + v8Colshape, + v8ColshapeCylinder, + v8ColshapeSphere, + v8ColshapeCircle, + v8ColshapeCuboid, + v8ColshapeRectangle; + static V8Module v8Alt("alt", { - "Vector3", - "RGBA", - "File", - "BaseObject", - "WorldObject", - "Entity", - "Player", - "Vehicle", - "Blip", - "PointBlip", - "Checkpoint", - "VoiceChannel", - "Colshape", - "ColshapeCylinder", - "ColshapeSphere", - "ColshapeCircle", - "ColshapeCuboid", - "ColshapeRectangle" + v8Vector3, + v8RGBA, + v8File, + v8BaseObject, + v8WorldObject, + v8Entity, + v8Player, + v8Vehicle, + v8Blip, + v8PointBlip, + v8Checkpoint, + v8VoiceChannel, + v8Colshape, + v8ColshapeCylinder, + v8ColshapeSphere, + v8ColshapeCircle, + v8ColshapeCuboid, + v8ColshapeRectangle }, [](v8::Local ctx, v8::Local exports) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 694d90d9..4339fd6e 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -589,7 +589,8 @@ static void StaticGetByID(const v8::FunctionCallbackInfo& info) } } -static V8Class v8Player("Player", "Entity", nullptr, [](v8::Local tpl) { +extern V8Class v8Entity; +extern V8Class v8Player("Player", v8Entity, nullptr, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Local proto = tpl->PrototypeTemplate(); diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 033897d1..dbff2b82 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -101,7 +101,8 @@ static void StaticGetByID(const v8::FunctionCallbackInfo& info) } } -static V8Class v8Vehicle("Vehicle", "Entity", Constructor, [](v8::Local tpl) { +extern V8Class v8Entity; +extern V8Class v8Vehicle("Vehicle", v8Entity, Constructor, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Local proto = tpl->PrototypeTemplate(); diff --git a/src/bindings/VoiceChannel.cpp b/src/bindings/VoiceChannel.cpp index 91ecf617..11ef5077 100644 --- a/src/bindings/VoiceChannel.cpp +++ b/src/bindings/VoiceChannel.cpp @@ -147,7 +147,8 @@ static void Constructor(const v8::FunctionCallbackInfo& info) "Failed to create VoiceChannel, make sure voice chat is enabled"); } -static V8Class v8VoiceChannel("VoiceChannel", "BaseObject", Constructor, [](v8::Local tpl) { +extern V8Class v8BaseObject; +extern V8Class v8VoiceChannel("VoiceChannel", v8BaseObject, Constructor, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); V8::SetMethod(isolate, tpl, "addPlayer", &AddPlayer); diff --git a/src/helpers b/src/helpers index 3d5ef898..a7544dbe 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 3d5ef8988ccf71145cfaf040b0ea9596b8cd4ead +Subproject commit a7544dbeb312e689e6cbf599cd8975038e5905a1 diff --git a/src/stdafx.h b/src/stdafx.h index 51fb968d..ed2828fb 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -18,7 +18,7 @@ #include #include "cpp-sdk/SDK.h" -#include "Log.h" +#include "helpers/Log.h" #include "node.h" #include "node_platform.h" #include "node_internals.h" From a9cdfcbf19179806a0d4db30bef7ee1e4465f450 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 12 Nov 2020 06:39:35 +0100 Subject: [PATCH 02/22] Update helpers Former-commit-id: 1bd740cae3b85dfd62c6072639978408c99d2ed1 --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index a7544dbe..90de823f 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit a7544dbeb312e689e6cbf599cd8975038e5905a1 +Subproject commit 90de823f49f9d7f032af97545b3404809cd78880 From 67ab5f45385785d34c5095e5f71c9ccbe8a9ec7c Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 12 Nov 2020 06:44:09 +0100 Subject: [PATCH 03/22] Add missing include Former-commit-id: 7ac037081cde05d56603ef5297af461cea11178a --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 90de823f..9315826b 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 90de823f49f9d7f032af97545b3404809cd78880 +Subproject commit 9315826b5609a31e39ca42e0d8a5cc7383949e50 From d05a9d3e95e30638d058beeb188fc74deb83197a Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 12 Nov 2020 06:47:57 +0100 Subject: [PATCH 04/22] Update helpers Former-commit-id: f18f84dcbf46099d55f6809dd4d0d4f74aaabb94 --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 9315826b..df52cfa7 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 9315826b5609a31e39ca42e0d8a5cc7383949e50 +Subproject commit df52cfa76ab649da48454cbd8cc7b6326d629d41 From 71972e634913d89b9b414ad8e6661503b61b4979 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 12 Nov 2020 06:54:37 +0100 Subject: [PATCH 05/22] Add missing include Former-commit-id: e72047551f6f7b55dbdbb4d61d31b76042597a27 --- src/CNodeResourceImpl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CNodeResourceImpl.h b/src/CNodeResourceImpl.h index 98846052..b2dcb780 100644 --- a/src/CNodeResourceImpl.h +++ b/src/CNodeResourceImpl.h @@ -8,6 +8,8 @@ #include "helpers/V8Entity.h" #include "helpers/V8Helpers.h" +#include "node.h" + class CNodeScriptRuntime; class CNodeResourceImpl : public V8ResourceImpl From 33e776c639da8e4f0837753ae64b5691c0010739 Mon Sep 17 00:00:00 2001 From: Hazard Date: Fri, 13 Nov 2020 07:42:53 +0100 Subject: [PATCH 06/22] Fixed startup bug, updated to SDK v43 Former-commit-id: db6f2da28a798277f99398f816b7a397de98e8ad --- src/bindings/Main.cpp | 2 +- src/cpp-sdk | 2 +- src/helpers | 2 +- src/node-module.cpp | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index f64e8a4d..6416f0c4 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -261,7 +261,7 @@ extern V8Class v8Vector3, v8ColshapeCuboid, v8ColshapeRectangle; -static V8Module v8Alt("alt", +extern V8Module v8Alt("alt", { v8Vector3, v8RGBA, diff --git a/src/cpp-sdk b/src/cpp-sdk index 0f074b78..f81e52ba 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 0f074b788f1896b4fd7c0ccc05cb1376e098def5 +Subproject commit f81e52baaba41a31052265407ddaa6f0fa116de6 diff --git a/src/helpers b/src/helpers index df52cfa7..fdc5ee1e 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit df52cfa76ab649da48454cbd8cc7b6326d629d41 +Subproject commit fdc5ee1e334085e12f9b6b91355be3cc0daaec0d diff --git a/src/node-module.cpp b/src/node-module.cpp index fee46364..11e2fede 100644 --- a/src/node-module.cpp +++ b/src/node-module.cpp @@ -24,12 +24,13 @@ //v8::V8::Dispose(); }*/ +extern V8Module v8Alt; static void Initialize(v8::Local exports) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope handle_scope(isolate); - V8Module::All().at("alt")->Register(isolate, isolate->GetEnteredContext(), exports); + v8Alt.Register(isolate, isolate->GetEnteredContext(), exports); } NODE_MODULE_LINKED(alt, Initialize) From f550e19bc944fdf32cb2634279b657a747e1a173 Mon Sep 17 00:00:00 2001 From: agrippa1994 Date: Sat, 14 Nov 2020 18:47:02 +0100 Subject: [PATCH 07/22] add troubleshooting guide Former-commit-id: 39189201acf1d621c6f17c4dcc9d9a48c54c8a64 --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index d9ae29c6..36d01f20 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,27 @@ # altv-js-module JS module for alt:V Multiplayer. Powered by NodeJS & v8 + +## Troubleshooting +**Problem**: I want to build a native Node.js addon with +[node-gyp](https://github.com/nodejs/node-gyp) but the alt:V server can not load +it and responds with following error: +``` +./altv-server: symbol lookup error: /usr/share/addon/binding.node: undefined symbol: node_module_register +``` +**Solution**: Add a C++ file to your project with following content and include +it the ```sources``` in your ```binding.gyp``` file. +```cpp +#include +#include + +extern "C" NODE_EXTERN void node_module_register(void* mod) { + auto base_ptr = dlopen("libnode.so.72", RTLD_NOW | RTLD_GLOBAL); + if (base_ptr == nullptr) { + return; + } + auto register_func = reinterpret_cast(dlsym(base_ptr, "node_module_register")); + if (register_func == nullptr) { + return; + } + register_func(mod); +} From 9a665692fb9dc37791c981448c4690a272b9a104 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 21 Nov 2020 11:05:53 +0100 Subject: [PATCH 08/22] Added DefaultDimension and GlobalDimension Former-commit-id: 73a9dea04a0602f68fc4b1f7e718bb603b8f5650 --- src/bindings/Main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 6416f0c4..900a0ac8 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -314,4 +314,7 @@ extern V8Module v8Alt("alt", alt::IResource* resource = V8ResourceImpl::GetResource(ctx); V8_CHECK(resource, "invalid resource"); exports->Set(isolate->GetEnteredContext(), v8::String::NewFromUtf8(isolate, "resourceName"), v8::String::NewFromUtf8(isolate, resource->GetName().CStr())); + + exports->Set(isolate->GetEnteredContext(), v8::String::NewFromUtf8(isolate, "DefaultDimension"), v8::Integer::New(isolate, alt::DEFAULT_DIMENSION)); + exports->Set(isolate->GetEnteredContext(), v8::String::NewFromUtf8(isolate, "GlobalDimension"), v8::Integer::New(isolate, alt::GLOBAL_DIMENSION)); }); From dbbceabee18234bdb545e4023fc0191c2ae0379c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 21 Nov 2020 16:45:21 +0100 Subject: [PATCH 09/22] Change capitalization for dimension constants Former-commit-id: 22c5171f0f7f5f91ee543834e67455a4feefb150 --- src/bindings/Main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 900a0ac8..ddf9a4ea 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -315,6 +315,6 @@ extern V8Module v8Alt("alt", V8_CHECK(resource, "invalid resource"); exports->Set(isolate->GetEnteredContext(), v8::String::NewFromUtf8(isolate, "resourceName"), v8::String::NewFromUtf8(isolate, resource->GetName().CStr())); - exports->Set(isolate->GetEnteredContext(), v8::String::NewFromUtf8(isolate, "DefaultDimension"), v8::Integer::New(isolate, alt::DEFAULT_DIMENSION)); - exports->Set(isolate->GetEnteredContext(), v8::String::NewFromUtf8(isolate, "GlobalDimension"), v8::Integer::New(isolate, alt::GLOBAL_DIMENSION)); + exports->Set(isolate->GetEnteredContext(), v8::String::NewFromUtf8(isolate, "defaultDimension"), v8::Integer::New(isolate, alt::DEFAULT_DIMENSION)); + exports->Set(isolate->GetEnteredContext(), v8::String::NewFromUtf8(isolate, "globalDimension"), v8::Integer::New(isolate, alt::GLOBAL_DIMENSION)); }); From 6ca2125ab1f779f60a23fffec3b7b0ab6c1b9762 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 25 Nov 2020 23:10:35 +0100 Subject: [PATCH 10/22] add vehicleDestroy, vehicleAttach, vehicleDetach event Former-commit-id: 23c8caa076cc55ba7766ce7965f82aedbee3bdcf --- src/cpp-sdk | 2 +- src/events/Vehicle.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/helpers | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index f81e52ba..348d5030 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit f81e52baaba41a31052265407ddaa6f0fa116de6 +Subproject commit 348d5030990ef5d1d2c7abb9ca79964a3353772b diff --git a/src/events/Vehicle.cpp b/src/events/Vehicle.cpp index dcf54837..e6484761 100644 --- a/src/events/Vehicle.cpp +++ b/src/events/Vehicle.cpp @@ -3,6 +3,10 @@ #include "helpers/V8ResourceImpl.h" #include "helpers/V8Helpers.h" +#include "cpp-sdk/events/CVehicleAttachEvent.h" +#include "cpp-sdk/events/CVehicleDetachEvent.h" +#include "cpp-sdk/events/CNetOwnerChangeEvent.h" + using alt::CEvent; using EventType = CEvent::Type; @@ -13,4 +17,37 @@ V8::LocalEventHandler vehicleDestroy( auto ev = static_cast(e); args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); } +); + +V8::LocalEventHandler vehicleAttach( + EventType::VEHICLE_ATTACH, + "vehicleAttach", + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + + args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); + args.push_back(resource->GetBaseObjectOrNull(ev->GetAttached())); + } +); + +V8::LocalEventHandler vehicleDetach( + EventType::VEHICLE_DETACH, + "vehicleDetach", + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + + args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); + args.push_back(resource->GetBaseObjectOrNull(ev->GetDetached())); + } +); + +V8::LocalEventHandler netOwnerChange( + EventType::NETOWNER_CHANGE, + "netOwnerChange", + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + + args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); + args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer())); + } ); \ No newline at end of file diff --git a/src/helpers b/src/helpers index fdc5ee1e..1da29ddc 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit fdc5ee1e334085e12f9b6b91355be3cc0daaec0d +Subproject commit 1da29ddcd902202b945902e403e5d1c47c6b37e7 From 7befbc0ce7ac754217a30781e5cb335a573d4828 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 25 Nov 2020 23:56:09 +0100 Subject: [PATCH 11/22] add oldowner parameter Former-commit-id: aae0bbd8b7f1705896487d77ffafa0e3b69c29f0 --- src/cpp-sdk | 2 +- src/events/Vehicle.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index 348d5030..f05a63bd 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 348d5030990ef5d1d2c7abb9ca79964a3353772b +Subproject commit f05a63bd6f41f7a0bc503891fc7e889a14bd73dd diff --git a/src/events/Vehicle.cpp b/src/events/Vehicle.cpp index e6484761..75878ea0 100644 --- a/src/events/Vehicle.cpp +++ b/src/events/Vehicle.cpp @@ -48,6 +48,7 @@ V8::LocalEventHandler netOwnerChange( auto ev = static_cast(e); args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); - args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer())); + args.push_back(resource->GetBaseObjectOrNull(ev->GetNewOwner())); + args.push_back(resource->GetBaseObjectOrNull(ev->GetOldOwner())); } ); \ No newline at end of file From becc210a596d72a77b0b49c5184d469de5e09ef2 Mon Sep 17 00:00:00 2001 From: Vektor Date: Thu, 26 Nov 2020 00:04:26 +0100 Subject: [PATCH 12/22] attempt to fix linux build Former-commit-id: 7243a73d403e84401349decb300aac1248ae731c --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 1da29ddc..464d3191 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 1da29ddcd902202b945902e403e5d1c47c6b37e7 +Subproject commit 464d319161055057102ae7e9b0ed202905f1b19c From c6234eddb211e9473df37bb3f0dc2fcbf71453d6 Mon Sep 17 00:00:00 2001 From: Vektor Date: Thu, 26 Nov 2020 12:00:08 +0100 Subject: [PATCH 13/22] add vehicle getAttached and getAttachedTo methods Former-commit-id: ae33e4f6180d1d4ccc841eeda7f11bebd41fd226 --- src/bindings/Vehicle.cpp | 18 ++++++++++++++++++ src/cpp-sdk | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index dbff2b82..f87acc18 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -20,6 +20,20 @@ static void DriverGetter(v8::Local name, const v8::PropertyCallbackI V8_RETURN_BASE_OBJECT(_this->GetDriver()); } +static void GetAttached(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(_this, IVehicle); + V8_RETURN_BASE_OBJECT(_this->GetAttached()); +} + +static void GetAttachedTo(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(_this, IVehicle); + V8_RETURN_BASE_OBJECT(_this->GetAttachedTo()); +} + static void DestroyedGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -223,4 +237,8 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, Constructor, [](v8::LocalSet(v8::String::NewFromUtf8(isolate, "getScriptDataBase64"), v8::FunctionTemplate::New(isolate, &GetScriptData)); proto->Set(v8::String::NewFromUtf8(isolate, "setScriptDataBase64"), v8::FunctionTemplate::New(isolate, &SetScriptData)); + + + proto->Set(v8::String::NewFromUtf8(isolate, "getAttached"), v8::FunctionTemplate::New(isolate, &GetAttached)); + proto->Set(v8::String::NewFromUtf8(isolate, "getAttachedTo"), v8::FunctionTemplate::New(isolate, &GetAttachedTo)); }); diff --git a/src/cpp-sdk b/src/cpp-sdk index f05a63bd..25880468 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit f05a63bd6f41f7a0bc503891fc7e889a14bd73dd +Subproject commit 25880468da1fa89597a71b75931b453f3c1fc4a5 From f82305248f570ef2bbe93165305aaa36081a280e Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 27 Nov 2020 11:57:40 +0100 Subject: [PATCH 14/22] Removed resourceName getter Former-commit-id: 6b830136c897a74ebc7919bc266fa63f1f405f64 --- src/bindings/Main.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index ddf9a4ea..9c95a6da 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -311,10 +311,6 @@ extern V8Module v8Alt("alt", alt::StringView rootDir = alt::ICore::Instance().GetRootDirectory(); exports->Set(isolate->GetEnteredContext(), v8::String::NewFromUtf8(isolate, "rootDir"), v8::String::NewFromUtf8(isolate, rootDir.CStr())); - alt::IResource* resource = V8ResourceImpl::GetResource(ctx); - V8_CHECK(resource, "invalid resource"); - exports->Set(isolate->GetEnteredContext(), v8::String::NewFromUtf8(isolate, "resourceName"), v8::String::NewFromUtf8(isolate, resource->GetName().CStr())); - exports->Set(isolate->GetEnteredContext(), v8::String::NewFromUtf8(isolate, "defaultDimension"), v8::Integer::New(isolate, alt::DEFAULT_DIMENSION)); exports->Set(isolate->GetEnteredContext(), v8::String::NewFromUtf8(isolate, "globalDimension"), v8::Integer::New(isolate, alt::GLOBAL_DIMENSION)); }); From 136ba4f74a613ca715b440bca9fbc61ddcccbcd2 Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 27 Nov 2020 15:22:29 +0100 Subject: [PATCH 15/22] update helpers and cpp sdk Former-commit-id: 6cb4fb00b30abadb7d79035aec6dcf54871ec303 --- src/cpp-sdk | 2 +- src/helpers | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index 25880468..c272e834 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 25880468da1fa89597a71b75931b453f3c1fc4a5 +Subproject commit c272e834212f04a9e6f2c2b6668fe39c2319f634 diff --git a/src/helpers b/src/helpers index 464d3191..57105860 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 464d319161055057102ae7e9b0ed202905f1b19c +Subproject commit 57105860543fafb45ee2a5796cf00397916c96dd From a31e085895e774c2360737d7942e0a4d03a2825e Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 30 Nov 2020 12:25:26 +0100 Subject: [PATCH 16/22] add player.clearBloodDamage Former-commit-id: 51990faef7585461c16fe0213ed8ac472374475a --- src/bindings/Player.cpp | 16 ++++++++++++++++ src/cpp-sdk | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 4339fd6e..e1b83666 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -478,6 +478,21 @@ static void RemoveAllWeapons(const v8::FunctionCallbackInfo& info) player->RemoveAllWeapons(); } +static void ClearBloodDamage(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + Ref player = _this->GetHandle().As(); + + player->ClearBloodDamage(); +} + static void AddWeaponComponent(const v8::FunctionCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); @@ -627,6 +642,7 @@ extern V8Class v8Player("Player", v8Entity, nullptr, [](v8::LocalSet(v8::String::NewFromUtf8(isolate, "setDateTime"), v8::FunctionTemplate::New(isolate, &SetDateTime)); proto->Set(v8::String::NewFromUtf8(isolate, "setWeather"), v8::FunctionTemplate::New(isolate, &SetWeather)); + proto->Set(v8::String::NewFromUtf8(isolate, "clearBloodDamage"), v8::FunctionTemplate::New(isolate, &ClearBloodDamage)); proto->Set(v8::String::NewFromUtf8(isolate, "giveWeapon"), v8::FunctionTemplate::New(isolate, &GiveWeapon)); proto->Set(v8::String::NewFromUtf8(isolate, "removeWeapon"), v8::FunctionTemplate::New(isolate, &RemoveWeapon)); proto->Set(v8::String::NewFromUtf8(isolate, "removeAllWeapons"), v8::FunctionTemplate::New(isolate, &RemoveAllWeapons)); diff --git a/src/cpp-sdk b/src/cpp-sdk index c272e834..2888c40c 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit c272e834212f04a9e6f2c2b6668fe39c2319f634 +Subproject commit 2888c40c5d33bf570de1c409e6e382ae6bfe1129 From 63adbf5ddaed8b1807b320abb669dfecfa52f71c Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 5 Dec 2020 03:05:23 +0100 Subject: [PATCH 17/22] add IVehicle::SetFixed Former-commit-id: d86c572146af108d85c3f842bb3a5c3a421a3772 --- src/bindings/Vehicle.cpp | 1 + src/bindings/vehicle/Damage.h | 12 ++++++++++++ src/cpp-sdk | 2 +- src/helpers | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index f87acc18..5ada8818 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -230,6 +230,7 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, Constructor, [](v8::LocalSet(v8::String::NewFromUtf8(isolate, "setArmoredWindowShootCount"), v8::FunctionTemplate::New(isolate, &SetArmoredWindowShootCount)); proto->Set(v8::String::NewFromUtf8(isolate, "getDamageStatusBase64"), v8::FunctionTemplate::New(isolate, &GetDamageStatus)); proto->Set(v8::String::NewFromUtf8(isolate, "setDamageStatusBase64"), v8::FunctionTemplate::New(isolate, &SetDamageStatus)); + proto->Set(v8::String::NewFromUtf8(isolate, "setFixed"), v8::FunctionTemplate::New(isolate, &SetFixed)); //Script getters/setters proto->SetAccessor(v8::String::NewFromUtf8(isolate, "manualEngineControl"), &ManualEngineControlGetter, &ManualEngineControlSetter); diff --git a/src/bindings/vehicle/Damage.h b/src/bindings/vehicle/Damage.h index f3e48a0c..59070fb6 100644 --- a/src/bindings/vehicle/Damage.h +++ b/src/bindings/vehicle/Damage.h @@ -324,6 +324,18 @@ namespace V8::Vehicle vehicle->LoadDamageDataFromBase64(*damageStatus); } + void SetFixed(const v8::FunctionCallbackInfo& info) + { + v8::Isolate* isolate = info.GetIsolate(); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + Ref vehicle = _this->GetHandle().As(); + + vehicle->SetFixed(); + } + void GetDamageStatus(const v8::FunctionCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); diff --git a/src/cpp-sdk b/src/cpp-sdk index 2888c40c..8fd6ecf5 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 2888c40c5d33bf570de1c409e6e382ae6bfe1129 +Subproject commit 8fd6ecf5a9d827ad872bef538c4e0fc3c7a356f5 diff --git a/src/helpers b/src/helpers index 57105860..14fa0191 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 57105860543fafb45ee2a5796cf00397916c96dd +Subproject commit 14fa019105fcc64838f441e001b4d457dcd2c69d From 8932a1f45cc8d0e930325b4421619087525bd9cf Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 5 Dec 2020 14:00:29 +0100 Subject: [PATCH 18/22] rename setFixed to repair Former-commit-id: c3afd6c4837e3ca32c9b53b76d8a494347d0a78a --- src/bindings/Vehicle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 5ada8818..3d8b732e 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -230,7 +230,7 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, Constructor, [](v8::LocalSet(v8::String::NewFromUtf8(isolate, "setArmoredWindowShootCount"), v8::FunctionTemplate::New(isolate, &SetArmoredWindowShootCount)); proto->Set(v8::String::NewFromUtf8(isolate, "getDamageStatusBase64"), v8::FunctionTemplate::New(isolate, &GetDamageStatus)); proto->Set(v8::String::NewFromUtf8(isolate, "setDamageStatusBase64"), v8::FunctionTemplate::New(isolate, &SetDamageStatus)); - proto->Set(v8::String::NewFromUtf8(isolate, "setFixed"), v8::FunctionTemplate::New(isolate, &SetFixed)); + proto->Set(v8::String::NewFromUtf8(isolate, "repair"), v8::FunctionTemplate::New(isolate, &SetFixed)); //Script getters/setters proto->SetAccessor(v8::String::NewFromUtf8(isolate, "manualEngineControl"), &ManualEngineControlGetter, &ManualEngineControlSetter); From d4264fe6842f27c23a2c05d436baab83e4dbc196 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sun, 6 Dec 2020 01:24:01 +0100 Subject: [PATCH 19/22] properly shutdown v8 platform Former-commit-id: 784868fd8cc1d0cc3ee2261d3642be066580b01f --- src/CNodeScriptRuntime.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/CNodeScriptRuntime.cpp b/src/CNodeScriptRuntime.cpp index 8d431595..0938c3d3 100644 --- a/src/CNodeScriptRuntime.cpp +++ b/src/CNodeScriptRuntime.cpp @@ -64,13 +64,9 @@ void CNodeScriptRuntime::OnDispose() } while (uv_loop_alive(uv_default_loop())); }*/ - platform->DrainTasks(isolate); - platform->CancelPendingDelayedTasks(isolate); - platform->UnregisterIsolate(isolate); - - isolate->Dispose(); + v8::V8::Dispose(); + v8::V8::ShutdownPlatform(); - platform.release(); //node::FreePlatform(platform.release()); } From fa3030f76a0dbb3c99a64411fb42ca37798de695 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sun, 6 Dec 2020 17:58:45 +0100 Subject: [PATCH 20/22] update helpers & sdk Former-commit-id: 432f235d2ed2872b6302c95afcf651325ec0cb9a --- src/cpp-sdk | 2 +- src/helpers | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index 8fd6ecf5..db8bc52c 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 8fd6ecf5a9d827ad872bef538c4e0fc3c7a356f5 +Subproject commit db8bc52c871ede16c69c60a4765eb8d727400aa5 diff --git a/src/helpers b/src/helpers index 14fa0191..28feb50f 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 14fa019105fcc64838f441e001b4d457dcd2c69d +Subproject commit 28feb50ff84b943900a50622805ac4d429a7ab96 From c0ea6cf86777446bb4ed7267bdc616453380a975 Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 7 Dec 2020 10:23:27 +0100 Subject: [PATCH 21/22] add player entering vehicle event Former-commit-id: 41dfbc856182f077240f8f5004e04411f122d0d9 --- src/cpp-sdk | 2 +- src/events/Player.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index db8bc52c..0c302387 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit db8bc52c871ede16c69c60a4765eb8d727400aa5 +Subproject commit 0c302387515be1c2422a8715737df1aa59d64099 diff --git a/src/events/Player.cpp b/src/events/Player.cpp index 7713b928..17307b76 100644 --- a/src/events/Player.cpp +++ b/src/events/Player.cpp @@ -8,6 +8,7 @@ #include "cpp-sdk/events/CPlayerDamageEvent.h" #include "cpp-sdk/events/CPlayerDeathEvent.h" #include "cpp-sdk/events/CPlayerEnterVehicleEvent.h" +#include "cpp-sdk/events/CPlayerEnteringVehicleEvent.h" #include "cpp-sdk/events/CPlayerLeaveVehicleEvent.h" #include "cpp-sdk/events/CPlayerChangeVehicleSeatEvent.h" #include "cpp-sdk/events/CPlayerWeaponChangeEvent.h" @@ -74,6 +75,18 @@ V8::LocalEventHandler playerEnterVehicle( } ); +V8::LocalEventHandler playerEnteringVehicle( + EventType::PLAYER_ENTERING_VEHICLE, + "playerEnteringVehicle", // TODO: don't change names, it's okay + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + + args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer())); + args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); + args.push_back(v8::Integer::New(resource->GetIsolate(), ev->GetSeat())); + } +); + V8::LocalEventHandler playerLeaveVehicle( EventType::PLAYER_LEAVE_VEHICLE, "playerLeftVehicle", // TODO: change name for consistency From 1c93fd3610d401c8674cdd90e00a5ee2a92c5317 Mon Sep 17 00:00:00 2001 From: Vektor Date: Tue, 8 Dec 2020 12:37:11 +0100 Subject: [PATCH 22/22] Update sdk Former-commit-id: 1316c6c8fe1aadb013e6d1286679c93fbfaba6ac --- src/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index 0c302387..3e8d71e7 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 0c302387515be1c2422a8715737df1aa59d64099 +Subproject commit 3e8d71e76b760e8c97684090fda65782e212eeed