diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..cdc83465 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023-2024 alt:V Multiplayer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/client/src/bindings/HandlingData.cpp b/client/src/bindings/HandlingData.cpp index 71e264a2..e3889417 100644 --- a/client/src/bindings/HandlingData.cpp +++ b/client/src/bindings/HandlingData.cpp @@ -13,7 +13,6 @@ static void Constructor(const v8::FunctionCallbackInfo& info) auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "model doesn't exist"); - V8Helpers::SetObjectClass(info.GetIsolate(), info.This(), V8Class::ObjectClass::HANDLING_DATA); info.This()->SetInternalField(1, info[0]); } @@ -31,6 +30,16 @@ static void GetForHandlingName(const v8::FunctionCallbackInfo& info) V8_RETURN(v8HandlingData.New(isolate->GetEnteredOrMicrotaskContext(), args)); } +static void ReloadVehiclePhysics(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_UINT(1, modelHash); + + V8_RETURN_BOOLEAN(alt::ICore::Instance().ReloadVehiclePhysics(modelHash)); +} + static void HandlingNameHashGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -1733,10 +1742,11 @@ static void DamageFlagsSetter(v8::Local, v8::Local val, c extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); - + tpl->InstanceTemplate()->SetInternalFieldCount(static_cast(V8Class::InternalFields::COUNT)); V8Helpers::SetStaticMethod(isolate, tpl, "getForHandlingName", &GetForHandlingName); + V8Helpers::SetStaticMethod(isolate, tpl, "reloadVehiclePhysics", &ReloadVehiclePhysics); V8Helpers::SetAccessor(isolate, tpl, "handlingNameHash", &HandlingNameHashGetter); V8Helpers::SetAccessor(isolate, tpl, "mass", &MassGetter, &MassSetter); diff --git a/client/src/bindings/Ped.cpp b/client/src/bindings/Ped.cpp index bbc8648e..2b7237a5 100644 --- a/client/src/bindings/Ped.cpp +++ b/client/src/bindings/Ped.cpp @@ -70,6 +70,25 @@ static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) } } +static void StaticGetByRemoteId(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_INT32(1, id); + + alt::IBaseObject* entity = alt::ICore::Instance().GetBaseObjectByRemoteID(alt::IBaseObject::Type::PED, id); + + if(entity) + { + V8_RETURN_BASE_OBJECT(entity); + } + else + { + V8_RETURN_NULL(); + } +} + // clang-format off extern V8Class v8Entity; extern V8Class v8Ped("Ped", v8Entity, [](v8::Local tpl) @@ -81,6 +100,7 @@ extern V8Class v8Ped("Ped", v8Entity, [](v8::Local tpl) V8Helpers::SetStaticAccessor(isolate, tpl, "streamedIn", &StreamedInGetter); V8Helpers::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); V8Helpers::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); + V8Helpers::SetStaticMethod(isolate, tpl, "getByRemoteID", StaticGetByRemoteId); V8Helpers::SetAccessor(isolate, tpl, "currentWeapon"); V8Helpers::SetAccessor(isolate, tpl, "health"); diff --git a/client/src/bindings/V8Natives.cpp b/client/src/bindings/V8Natives.cpp index a2d7b888..2e71f3f6 100644 --- a/client/src/bindings/V8Natives.cpp +++ b/client/src/bindings/V8Natives.cpp @@ -47,11 +47,12 @@ static void* ToMemoryBuffer(v8::Local val, v8::Local ctx if(val->IsObject()) { v8::Local obj = val.As(); + auto cls = V8Helpers::GetObjectClass(obj); - if(obj->InternalFieldCount() == 2) + if(cls == V8Class::ObjectClass::MEMORY_BUFFER) { - void* memory = obj->GetAlignedPointerFromInternalField(0); - uint32_t size = obj->GetInternalField(0)->Uint32Value(ctx).ToChecked(); + void* memory = obj->GetAlignedPointerFromInternalField(1); + uint32_t size = obj->GetInternalField(2)->Uint32Value(ctx).ToChecked(); if(size > 0) return memory; } diff --git a/shared/V8Helpers.cpp b/shared/V8Helpers.cpp index 5f0d7d11..4cfca3a4 100644 --- a/shared/V8Helpers.cpp +++ b/shared/V8Helpers.cpp @@ -384,8 +384,12 @@ V8Class::ObjectClass V8Helpers::GetObjectClass(v8::Local obj) { if(obj->InternalFieldCount() <= static_cast(V8Class::InternalFields::OBJECT_CLASS)) return V8Class::ObjectClass::NONE; + + auto val = obj->GetInternalField(static_cast(V8Class::InternalFields::OBJECT_CLASS)); + if(!val->IsExternal()) + return V8Class::ObjectClass::NONE; - void* cls = obj->GetInternalField(static_cast(V8Class::InternalFields::OBJECT_CLASS)).As()->Value(); + void* cls = val.As()->Value(); return *reinterpret_cast(&cls); } diff --git a/shared/deps/cpp-sdk b/shared/deps/cpp-sdk index 95a2cfad..22e1fdd3 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 95a2cfadc2ba1de018c8c55c72b21984067b6181 +Subproject commit 22e1fdd37b8e379d04b279161571276cb7bb12da