Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
emcifuntik committed Sep 27, 2023
2 parents 4abe0a4 + 10729c8 commit 2d3c5a4
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 115 deletions.
1 change: 1 addition & 0 deletions client/src/bindings/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ extern V8Class v8Player("Player",
V8Helpers::SetAccessor<IPlayer, uint16_t, &IPlayer::GetMaxArmour>(isolate, tpl, "maxArmour");
V8Helpers::SetAccessor<IPlayer, float, &IPlayer::GetSpatialVolume, &IPlayer::SetSpatialVolume>(isolate, tpl, "spatialVolume");
V8Helpers::SetAccessor<IPlayer, float, &IPlayer::GetNonSpatialVolume, &IPlayer::SetNonSpatialVolume>(isolate, tpl, "nonSpatialVolume");
V8Helpers::SetAccessor<IPlayer, std::string, &IPlayer::GetTaskData>(isolate, tpl, "taskData");

// Weapon getters
V8Helpers::SetAccessor(isolate, tpl, "currentWeaponComponents", &CurrentWeaponComponentsGetter);
Expand Down
20 changes: 20 additions & 0 deletions client/src/events/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,23 @@ V8_LOCAL_EVENT_HANDLER entityHitEntity(EventType::ENTITY_HIT_ENTITY,
args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget()));
args.push_back(V8Helpers::JSValue(ev->GetWeapon()));
});

V8_LOCAL_EVENT_HANDLER playerStartTalking(EventType::PLAYER_START_TALKING,
"playerStartTalking",
[](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CPlayerStartTalkingEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();

args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer()));
});

V8_LOCAL_EVENT_HANDLER playerStopTalking(EventType::PLAYER_STOP_TALKING,
"playerStopTalking",
[](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CPlayerStopTalkingEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();

args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer()));
});
6 changes: 6 additions & 0 deletions client/src/events/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ V8_LOCAL_EVENT_HANDLER enterVehicle(EventType::PLAYER_START_ENTER_VEHICLE,

args.push_back(resource->GetOrCreateEntity(ev->GetTarget())->GetJSVal(isolate));
args.push_back(V8Helpers::JSValue(ev->GetSeat()));

// TODO (xLuxy): Maybe move up? Would cause breaking change
args.push_back(resource->GetOrCreateEntity(ev->GetPlayer())->GetJSVal(isolate));
});

V8_LOCAL_EVENT_HANDLER leaveVehicle(EventType::PLAYER_START_LEAVE_VEHICLE,
Expand All @@ -54,6 +57,9 @@ V8_LOCAL_EVENT_HANDLER leaveVehicle(EventType::PLAYER_START_LEAVE_VEHICLE,

args.push_back(resource->GetOrCreateEntity(ev->GetTarget())->GetJSVal(isolate));
args.push_back(V8Helpers::JSValue(ev->GetSeat()));

// TODO (xLuxy): Maybe move up? Would cause breaking change
args.push_back(resource->GetOrCreateEntity(ev->GetPlayer())->GetJSVal(isolate));
});

V8_LOCAL_EVENT_HANDLER
Expand Down
38 changes: 15 additions & 23 deletions server/src/bindings/Checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,33 +112,27 @@ static void GetStreamSyncedMetaDataKeys(const v8::FunctionCallbackInfo<v8::Value
static void SetStreamSyncedMeta(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();

V8_CHECK_ARGS_LEN(2);
V8_ARG_TO_STRING(1, key);
V8_ARG_TO_MVALUE(2, value);

V8_GET_THIS_BASE_OBJECT(checkpoint, alt::ICheckpoint);

checkpoint->SetStreamSyncedMetaData(key, value);
}

static void SetMultipleStreamSyncedMetaData(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_GET_THIS_BASE_OBJECT(entity, alt::ICheckpoint);
if(info.Length() == 2)
{
V8_ARG_TO_STRING(1, key);
V8_ARG_TO_MVALUE(2, value);

V8_CHECK(info[0]->IsObject(), "Failed to convert argument 1 to object");
checkpoint->SetStreamSyncedMetaData(key, value);
}
else if(info.Length() == 1 && info[0]->IsObject())
{
auto dict = V8Helpers::CppValue<v8::Local<v8::Value>>(info[0].As<v8::Object>());
std::unordered_map<std::string, MValue> values;

auto dict = V8Helpers::CppValue<v8::Local<v8::Value>>(info[0].As<v8::Object>());
std::unordered_map<std::string, MValue> values;
if(dict.has_value())
{
for(auto& [key, value] : dict.value()) values[key] = V8Helpers::V8ToMValue(value);
}

if (dict.has_value())
{
for (auto& [key, value] : dict.value())
values[key] = V8Helpers::V8ToMValue(value);
checkpoint->SetMultipleStreamSyncedMetaData(values);
}

entity->SetMultipleStreamSyncedMetaData(values);
}

static void DeleteStreamSyncedMeta(const v8::FunctionCallbackInfo<v8::Value>& info)
Expand Down Expand Up @@ -172,7 +166,6 @@ static void StaticGetByID(const v8::FunctionCallbackInfo<v8::Value>& info)
}
}

// TODO (xLuxy): Checkpoints also exist on Client-side
extern V8Class v8Colshape;
extern V8Class v8Checkpoint("Checkpoint",
v8Colshape,
Expand All @@ -191,6 +184,5 @@ extern V8Class v8Checkpoint("Checkpoint",
V8Helpers::SetMethod(isolate, tpl, "getStreamSyncedMeta", GetStreamSyncedMeta);
V8Helpers::SetMethod(isolate, tpl, "getStreamSyncedMetaKeys", GetStreamSyncedMetaDataKeys);
V8Helpers::SetMethod(isolate, tpl, "setStreamSyncedMeta", SetStreamSyncedMeta);
V8Helpers::SetMethod(isolate, tpl, "setMultipleStreamSyncedMetaData", SetMultipleStreamSyncedMetaData);
V8Helpers::SetMethod(isolate, tpl, "deleteStreamSyncedMeta", DeleteStreamSyncedMeta);
});
12 changes: 1 addition & 11 deletions server/src/bindings/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,6 @@ static void DeleteSyncedMeta(const v8::FunctionCallbackInfo<v8::Value>& info)
alt::ICore::Instance().DeleteSyncedMetaData(key);
}

static void GetNetTime(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE();

uint32_t netTime = alt::ICore::Instance().GetNetTime();

V8_RETURN_UINT(netTime);
}

static void SetPassword(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
Expand Down Expand Up @@ -415,6 +406,7 @@ static void GetVehicleModelByHash(const v8::FunctionCallbackInfo<v8::Value>& inf
infoObj->Set(ctx, V8Helpers::JSValue("bones"), boneArr);

infoObj->Set(ctx, V8Helpers::JSValue("canAttachCars"), V8Helpers::JSValue(modelInfo.canAttachCars));
infoObj->Set(ctx, V8Helpers::JSValue("handlingNameHash"), V8Helpers::JSValue(modelInfo.handlingNameHash));

V8_RETURN(infoObj);
}
Expand Down Expand Up @@ -813,8 +805,6 @@ extern V8Module
V8Helpers::RegisterFunc(exports, "setSyncedMeta", &SetSyncedMeta);
V8Helpers::RegisterFunc(exports, "deleteSyncedMeta", &DeleteSyncedMeta);

V8Helpers::RegisterFunc(exports, "getNetTime", &GetNetTime);

V8Helpers::RegisterFunc(exports, "setPassword", &SetPassword);

V8Helpers::RegisterFunc(exports, "hashServerPassword", &HashServerPassword);
Expand Down
13 changes: 13 additions & 0 deletions server/src/events/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "cpp-sdk/events/CMetaDataChangeEvent.h"
#include "cpp-sdk/events/CClientDeleteObjectEvent.h"
#include "cpp-sdk/events/CClientRequestObjectEvent.h"
#include "cpp-sdk/events/CGivePedScriptedTaskEvent.h"

using alt::CEvent;
using EventType = CEvent::Type;
Expand Down Expand Up @@ -253,3 +254,15 @@ V8_LOCAL_EVENT_HANDLER clientRequestObject(EventType::CLIENT_REQUEST_OBJECT_EVEN
args.push_back(V8Helpers::JSValue(ev->GetModel()));
args.push_back(resource->CreateVector3(ev->GetPosition()));
});

V8_LOCAL_EVENT_HANDLER givePedScriptedTask(EventType::GIVE_PED_SCRIPTED_TASK,
"givePedScriptedTask",
[](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CGivePedScriptedTaskEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();

args.push_back(resource->GetBaseObjectOrNull(ev->GetSource()));
args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget()));
args.push_back(V8Helpers::JSValue(ev->GetTaskType()));
});
55 changes: 55 additions & 0 deletions server/src/events/Ped.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "stdafx.h"

#include "V8ResourceImpl.h"
#include "V8Helpers.h"

#include "CNodeResourceImpl.h"

#include "cpp-sdk/events/CPedDamageEvent.h"
#include "cpp-sdk/events/CPedDeathEvent.h"
#include "cpp-sdk/events/CPedHealEvent.h"

using alt::CEvent;
using EventType = CEvent::Type;

extern V8Class v8ConnectionInfo;

V8Helpers::LocalEventHandler pedDamage(EventType::PED_DAMAGE,
"pedDamage",
[](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CPedDamageEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();

args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget()));
args.push_back(resource->GetBaseObjectOrNull(ev->GetAttacker()));
args.push_back(V8Helpers::JSValue(ev->GetHealthDamage()));
args.push_back(V8Helpers::JSValue(ev->GetArmourDamage()));
args.push_back(V8Helpers::JSValue(ev->GetWeapon()));
});

V8Helpers::LocalEventHandler pedDeath(EventType::PED_DEATH,
"pedDeath",
[](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CPedDeathEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();

args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget()));
args.push_back(resource->GetBaseObjectOrNull(ev->GetKiller()));
args.push_back(V8Helpers::JSValue(ev->GetWeapon()));
});

V8Helpers::LocalEventHandler pedHeal(EventType::PED_HEAL,
"pedHeal",
[](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CPedHealEvent*>(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()));
});
60 changes: 34 additions & 26 deletions shared/bindings/BaseObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,27 @@ static void GetMeta(const v8::FunctionCallbackInfo<v8::Value>& info)
static void SetMeta(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();

V8_CHECK_ARGS_LEN(2);
V8_ARG_TO_STRING(1, key);
V8_ARG_TO_MVALUE(2, value);

V8_GET_THIS_BASE_OBJECT(obj, alt::IBaseObject);

obj->SetMetaData(key, value);
}

static void SetMultipleMetaData(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_GET_THIS_BASE_OBJECT(obj, alt::IBaseObject);
if (info.Length() == 2)
{
V8_ARG_TO_STRING(1, key);
V8_ARG_TO_MVALUE(2, value);

V8_CHECK(info[0]->IsObject(), "Failed to convert argument 1 to object");
obj->SetMetaData(key, value);
}
else if (info.Length() == 1 && info[0]->IsObject())
{
auto dict = V8Helpers::CppValue<v8::Local<v8::Value>>(info[0].As<v8::Object>());
std::unordered_map<std::string, MValue> values;

auto dict = V8Helpers::CppValue<v8::Local<v8::Value>>(info[0].As<v8::Object>());
std::unordered_map<std::string, MValue> values;
if(dict.has_value())
{
for(auto& [key, value] : dict.value()) values[key] = V8Helpers::V8ToMValue(value);
}

if(dict.has_value())
{
for(auto& [key, value] : dict.value()) values[key] = V8Helpers::V8ToMValue(value);
obj->SetMultipleMetaData(values);
}

obj->SetMultipleMetaData(values);
}

static void DeleteMeta(const v8::FunctionCallbackInfo<v8::Value>& info)
Expand Down Expand Up @@ -172,14 +167,28 @@ static void StaticGetById(const v8::FunctionCallbackInfo<v8::Value>& info)
static void SetSyncedMeta(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_GET_THIS_BASE_OBJECT(ent, alt::IBaseObject);

V8_CHECK_ARGS_LEN(2);
V8_ARG_TO_STRING(1, key);
V8_ARG_TO_MVALUE(2, value);
if (info.Length() == 2)
{
V8_ARG_TO_STRING(1, key);
V8_ARG_TO_MVALUE(2, value);

V8_GET_THIS_BASE_OBJECT(ent, alt::IBaseObject);
ent->SetSyncedMetaData(key, value);
}
else if (info.Length() == 1 && info[0]->IsObject())
{
auto dict = V8Helpers::CppValue<v8::Local<v8::Value>>(info[0].As<v8::Object>());
std::unordered_map<std::string, MValue> values;

ent->SetSyncedMetaData(key, value);
if (dict.has_value())
{
for (auto& [key, value] : dict.value())
values[key] = V8Helpers::V8ToMValue(value);
}

ent->SetMultipleSyncedMetaData(values);
}
}

static void DeleteSyncedMeta(const v8::FunctionCallbackInfo<v8::Value>& info)
Expand Down Expand Up @@ -234,7 +243,6 @@ extern V8Class v8BaseObject("BaseObject",
V8Helpers::SetMethod(isolate, tpl, "hasMeta", HasMeta);
V8Helpers::SetMethod(isolate, tpl, "getMeta", GetMeta);
V8Helpers::SetMethod(isolate, tpl, "setMeta", SetMeta);
V8Helpers::SetMethod(isolate, tpl, "setMultipleMetaData", SetMultipleMetaData);
V8Helpers::SetMethod(isolate, tpl, "deleteMeta", DeleteMeta);
V8Helpers::SetMethod(isolate, tpl, "getMetaDataKeys", GetMetaDataKeys);
V8Helpers::SetMethod(isolate, tpl, "destroy", Destroy);
Expand Down
11 changes: 11 additions & 0 deletions shared/bindings/BindingsMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,15 @@ static void GetVoiceConnectionState(const v8::FunctionCallbackInfo<v8::Value>& i
V8_RETURN_NUMBER(alt::ICore::Instance().GetVoiceConnectionState());
}

static void GetNetTime(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE();

uint32_t netTime = alt::ICore::Instance().GetNetTime();

V8_RETURN_UINT(netTime);
}

extern V8Class v8BaseObject, v8WorldObject, v8Entity, v8File, v8RGBA, v8Vector2, v8Vector3, v8Quaternion, v8Blip, v8AreaBlip, v8RadiusBlip, v8PointBlip, v8Resource, v8Utils;

extern V8Module
Expand Down Expand Up @@ -511,6 +520,8 @@ extern V8Module

V8Helpers::RegisterFunc(exports, "getVoiceConnectionState", &GetVoiceConnectionState);

V8Helpers::RegisterFunc(exports, "getNetTime", &GetNetTime);

V8_OBJECT_SET_STRING(exports, "version", alt::ICore::Instance().GetVersion());
V8_OBJECT_SET_STRING(exports, "branch", alt::ICore::Instance().GetBranch());
// V8_OBJECT_SET_RAW_STRING(exports, "sdkVersion", ALT_SDK_VERSION);
Expand Down
Loading

0 comments on commit 2d3c5a4

Please sign in to comment.