Skip to content

Commit

Permalink
Merge branch 'dev' into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
vadzz-dev committed Jun 7, 2024
2 parents 65fa81b + 1c6d1f3 commit afc77d3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 7 deletions.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 12 additions & 2 deletions client/src/bindings/HandlingData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& 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]);
}
Expand All @@ -31,6 +30,16 @@ static void GetForHandlingName(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_RETURN(v8HandlingData.New(isolate->GetEnteredOrMicrotaskContext(), args));
}

static void ReloadVehiclePhysics(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
Expand Down Expand Up @@ -1733,10 +1742,11 @@ static void DamageFlagsSetter(v8::Local<v8::String>, v8::Local<v8::Value> val, c

extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::Local<v8::FunctionTemplate> tpl) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();

tpl->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(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);
Expand Down
20 changes: 20 additions & 0 deletions client/src/bindings/Ped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ static void StaticGetByScriptID(const v8::FunctionCallbackInfo<v8::Value>& info)
}
}

static void StaticGetByRemoteId(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::FunctionTemplate> tpl)
Expand All @@ -81,6 +100,7 @@ extern V8Class v8Ped("Ped", v8Entity, [](v8::Local<v8::FunctionTemplate> 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<IPed, uint32_t, &IPed::GetCurrentWeapon>(isolate, tpl, "currentWeapon");
V8Helpers::SetAccessor<IPed, uint16_t, &IPed::GetHealth>(isolate, tpl, "health");
Expand Down
7 changes: 4 additions & 3 deletions client/src/bindings/V8Natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ static void* ToMemoryBuffer(v8::Local<v8::Value> val, v8::Local<v8::Context> ctx
if(val->IsObject())
{
v8::Local<v8::Object> obj = val.As<v8::Object>();
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;
}
Expand Down
6 changes: 5 additions & 1 deletion shared/V8Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,12 @@ V8Class::ObjectClass V8Helpers::GetObjectClass(v8::Local<v8::Object> obj)
{
if(obj->InternalFieldCount() <= static_cast<int>(V8Class::InternalFields::OBJECT_CLASS))
return V8Class::ObjectClass::NONE;

auto val = obj->GetInternalField(static_cast<int>(V8Class::InternalFields::OBJECT_CLASS));
if(!val->IsExternal())
return V8Class::ObjectClass::NONE;

void* cls = obj->GetInternalField(static_cast<int>(V8Class::InternalFields::OBJECT_CLASS)).As<v8::External>()->Value();
void* cls = val.As<v8::External>()->Value();
return *reinterpret_cast<V8Class::ObjectClass*>(&cls);
}

Expand Down
2 changes: 1 addition & 1 deletion shared/deps/cpp-sdk
Submodule cpp-sdk updated 2 files
+1 −0 ICore.h
+1 −1 types/MValue.h

0 comments on commit afc77d3

Please sign in to comment.