Skip to content

Commit

Permalink
Merge branch 'dev' into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
C0kkie committed Jan 2, 2024
2 parents a43afcb + 4dcc6de commit 04ebe12
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on:
branches-ignore:
- '**'
tags:
- 'dev/*.*-dev*'
- 'rc/*.*-rc*'
- 'release/*.*'
- 'dev/*.*.*-dev.*'
- 'rc/*.*.*-rc.*'
- 'release/*.*.*'

jobs:
build-windows:
Expand Down
130 changes: 129 additions & 1 deletion client/src/bindings/ClientBindingsMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ static void GetPoolEntities(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(1);
V8_ARG_TO_STRING(1, pool);

auto entities = alt::ICore::Instance().GetPoolEntities(pool);
v8::Local<v8::Array> arr = v8::Array::New(isolate, entities.size());

Expand All @@ -1236,6 +1236,119 @@ static void GetPoolEntities(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_RETURN(arr);
}

static void GetVoicePlayers(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();

auto players = alt::ICore::Instance().GetVoicePlayers();
v8::Local<v8::Array> arr = v8::Array::New(isolate, players.size());

for (uint32_t i = 0; i < players.size(); ++i)
arr->Set(ctx, i, v8::Integer::NewFromUnsigned(isolate, players[i]));

V8_RETURN(arr);
}

static void RemoveVoicePlayer(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(1);

V8_ARG_TO_INT(1, playerId);

alt::ICore::Instance().RemoveVoicePlayer(playerId);
}

static void GetVoiceSpatialVolume(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(1);

V8_ARG_TO_INT(1, playerId);

V8_RETURN_NUMBER(alt::ICore::Instance().GetVoiceSpatialVolume(playerId));
}

static void SetVoiceSpatialVolume(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(2);

V8_ARG_TO_INT(1, playerId);
V8_ARG_TO_NUMBER(2, value);

alt::ICore::Instance().SetVoiceSpatialVolume(playerId, value);
}

static void GetVoiceNonSpatialVolume(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(1);

V8_ARG_TO_INT(1, playerId);

V8_RETURN_NUMBER(alt::ICore::Instance().GetVoiceNonSpatialVolume(playerId));
}

static void SetVoiceNonSpatialVolume(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(2);

V8_ARG_TO_INT(1, playerId);
V8_ARG_TO_NUMBER(2, value);

alt::ICore::Instance().SetVoiceNonSpatialVolume(playerId, value);
}

static void AddVoiceFilter(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_ARGS_LEN(2);

V8_ARG_TO_INT(1, playerId);
V8_ARG_TO_BASE_OBJECT(2, filter, alt::IAudioFilter, "AudioFilter");

alt::ICore::Instance().AddVoiceFilter(playerId, filter);
}

static void RemoveVoiceFilter(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_ARGS_LEN(1);

V8_ARG_TO_INT(1, playerId);

alt::ICore::Instance().RemoveVoiceFilter(playerId);
}

static void GetVoiceFilter(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_ARGS_LEN(1);

V8_ARG_TO_INT(1, playerId);

V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetVoiceFilter(playerId));
}

static void UpdateClipContext(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(1);
V8_CHECK(!info[0]->IsNullOrUndefined() && info[0]->IsObject(), "Argument 1 must be an object");

auto dict = V8Helpers::CppValue<v8::Local<v8::Value>>(info[0].As<v8::Object>());
std::unordered_map<std::string, std::string> context;

if(dict.has_value())
{
for(auto& [key, value] : dict.value()) V8Helpers::SafeToString(value, isolate, ctx, context[key]);
}

alt::ICore::Instance().UpdateClipContext(context);
}

extern V8Module sharedModule;
extern V8Class v8Player, v8Player, v8Vehicle, v8WebView, v8HandlingData, v8LocalStorage, v8MemoryBuffer, v8MapZoomData, v8Discord, v8Voice, v8WebSocketClient, v8Checkpoint, v8HttpClient,
v8Audio, v8LocalPlayer, v8Profiler, v8Worker, v8RmlDocument, v8RmlElement, v8WeaponData, v8FocusData, v8LocalObject, v8TextEncoder, v8TextDecoder, v8Object, v8VirtualEntityGroup,
Expand Down Expand Up @@ -1427,4 +1540,19 @@ extern V8Module altModule("alt",
V8Helpers::RegisterFunc(exports, "getPoolSize", &GetPoolSize);
V8Helpers::RegisterFunc(exports, "getPoolCount", &GetPoolCount);
V8Helpers::RegisterFunc(exports, "getPoolEntities", &GetPoolEntities);

// Voice related functions
V8Helpers::RegisterFunc(exports, "getVoicePlayers", &GetVoicePlayers);
V8Helpers::RegisterFunc(exports, "removeVoicePlayer", &RemoveVoicePlayer);

V8Helpers::RegisterFunc(exports, "getVoiceSpatialVolume", &GetVoiceSpatialVolume);
V8Helpers::RegisterFunc(exports, "setVoiceSpatialVolume", &SetVoiceSpatialVolume);

V8Helpers::RegisterFunc(exports, "getVoiceNonSpatialVolume", &GetVoiceNonSpatialVolume);
V8Helpers::RegisterFunc(exports, "setVoiceNonSpatialVolume", &SetVoiceNonSpatialVolume);

V8Helpers::RegisterFunc(exports, "addVoiceFilter", &AddVoiceFilter);
V8Helpers::RegisterFunc(exports, "removeVoiceFilter", &RemoveVoiceFilter);
V8Helpers::RegisterFunc(exports, "getVoiceFilter", &GetVoiceFilter);
V8Helpers::RegisterFunc(exports, "updateClipContext", &UpdateClipContext);
});
4 changes: 2 additions & 2 deletions client/src/bindings/V8Natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ inline void ShowNativeArgParseErrorMsg(V8ResourceImpl* resource, v8::Local<v8::V
<< "(" << V8Helpers::GetJSValueTypeName(val) << ")"
<< " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")";

Log::Error << source.ToString() << " " << errorMsg.str() << Log::Endl;
Log::Error << source.ToString(isolate) << " " << errorMsg.str() << Log::Endl;
Log::Error << "Check the documentation for the needed arguments of this native." << Log::Endl;

resource->DispatchErrorEvent(errorMsg.str(), source.GetFileName(), source.GetLineNumber(), V8Helpers::GetStackTrace(errorMsg.str()));
Expand All @@ -109,7 +109,7 @@ inline void ShowNativeArgMismatchErrorMsg(V8ResourceImpl* resource, alt::INative
std::stringstream errorMsg;
errorMsg << "Native argument size mismatch. Expected: " << expected << ", Received: " << received << " (" << native->GetName() << ")";

Log::Error << source.ToString() << " " << errorMsg.str() << Log::Endl;
Log::Error << source.ToString(isolate) << " " << errorMsg.str() << Log::Endl;
Log::Error << "Check the documentation for the needed arguments of this native." << Log::Endl;

resource->DispatchErrorEvent(errorMsg.str(), source.GetFileName(), source.GetLineNumber(), V8Helpers::GetStackTrace(errorMsg.str()));
Expand Down
4 changes: 2 additions & 2 deletions client/src/workers/CWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ void CWorker::SetupIsolate()
case v8::kPromiseRejectAfterResolved:
{
std::ostringstream stream;
stream << location.ToString() << " Promise rejected after being resolved (" << *v8::String::Utf8Value(isolate, value->ToString(ctx).ToLocalChecked()) << ")";
stream << location.ToString(isolate) << " Promise rejected after being resolved (" << *v8::String::Utf8Value(isolate, value->ToString(ctx).ToLocalChecked()) << ")";
worker->EmitError(stream.str());
break;
}
case v8::kPromiseResolveAfterResolved:
{
std::ostringstream stream;
stream << location.ToString() << " Promise resolved after being resolved (" << *v8::String::Utf8Value(isolate, value->ToString(ctx).ToLocalChecked()) << ")";
stream << location.ToString(isolate) << " Promise resolved after being resolved (" << *v8::String::Utf8Value(isolate, value->ToString(ctx).ToLocalChecked()) << ")";
worker->EmitError(stream.str());
break;
}
Expand Down
20 changes: 19 additions & 1 deletion server/src/bindings/ConnectionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,26 @@ static void BranchGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v
}

static void BuildGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_DEPRECATE("ConnectionInfo build", "versionMajor & versionMinor");

V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_GET_THIS_BASE_OBJECT(con, alt::IConnectionInfo);
V8_RETURN_UINT(con->GetVersionMajor());
}

static void VersionMajorGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_GET_THIS_BASE_OBJECT(con, alt::IConnectionInfo);
V8_RETURN_UINT(con->GetVersionMajor());
}

static void VersionMinorGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_GET_THIS_BASE_OBJECT(con, alt::IConnectionInfo);
V8_RETURN_UINT(con->GetBuild());
V8_RETURN_UINT(con->GetVersionMinor());
}

static void CdnUrlGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
Expand Down Expand Up @@ -216,6 +232,8 @@ extern V8Class v8ConnectionInfo("ConnectionInfo",
V8Helpers::SetAccessor(isolate, tpl, "isDebug", &IsDebugGetter);
V8Helpers::SetAccessor(isolate, tpl, "branch", &BranchGetter);
V8Helpers::SetAccessor(isolate, tpl, "build", &BuildGetter);
V8Helpers::SetAccessor(isolate, tpl, "versionMajor", &VersionMajorGetter);
V8Helpers::SetAccessor(isolate, tpl, "versionMinor", &VersionMinorGetter);
V8Helpers::SetAccessor(isolate, tpl, "cdnUrl", &CdnUrlGetter);
V8Helpers::SetAccessor(isolate, tpl, "passwordHash", &PasswordHashGetter);
V8Helpers::SetAccessor(isolate, tpl, "ip", &IpGetter);
Expand Down
20 changes: 20 additions & 0 deletions server/src/bindings/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ static void CountGetter(v8::Local<v8::String> name, const v8::PropertyCallbackIn
V8_RETURN_UINT(alt::ICore::Instance().GetBaseObjects(alt::IBaseObject::Type::OBJECT).size());
}

static void StaticGetByID(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_ARGS_LEN(1);

V8_ARG_TO_INT(1, id);

alt::IBaseObject* entity = alt::ICore::Instance().GetBaseObjectByID(alt::IBaseObject::Type::OBJECT, id);

if(entity)
{
V8_RETURN_BASE_OBJECT(entity);
}
else
{
V8_RETURN_NULL();
}
}

// clang-format off
extern V8Class v8Entity;
extern V8Class v8Object("Object", v8Entity, Constructor, [](v8::Local<v8::FunctionTemplate> tpl)
Expand All @@ -74,6 +93,7 @@ extern V8Class v8Object("Object", v8Entity, Constructor, [](v8::Local<v8::Functi

V8Helpers::SetStaticAccessor(isolate, tpl, "all", &AllGetter);
V8Helpers::SetStaticAccessor(isolate, tpl, "count", &CountGetter);
V8Helpers::SetStaticMethod(isolate, tpl, "getByID", &StaticGetByID);

V8Helpers::SetMethod<alt::IObject, &alt::IObject::ActivatePhysics>(isolate, tpl, "activatePhysics");
V8Helpers::SetMethod<alt::IObject, &alt::IObject::PlaceOnGroundProperly>(isolate, tpl, "placeOnGroundProperly");
Expand Down
1 change: 1 addition & 0 deletions server/src/bindings/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,7 @@ static void GetDecorations(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_NEW_OBJECT(decorationsObj);
V8_OBJECT_SET_UINT(decorationsObj, "collection", decoration.collection);
V8_OBJECT_SET_UINT(decorationsObj, "overlay", decoration.overlay);
V8_OBJECT_SET_INT(decorationsObj, "count", decoration.count);

decorationsArr->Set(ctx, i, decorationsObj);
}
Expand Down
56 changes: 56 additions & 0 deletions server/src/bindings/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,61 @@ static void GetPassengers(v8::Local<v8::String>, const v8::PropertyCallbackInfo<
V8_RETURN(obj);
}

static void SetBadge(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN_MIN_MAX(3, 6);
V8_GET_THIS_BASE_OBJECT(_this, IVehicle);

uint32_t textureDictionary;
if (info[0]->IsString())
{
V8_ARG_TO_STRING(1, textureDictionaryName);
textureDictionary = alt::ICore::Instance().Hash(textureDictionaryName);
}
else
{
V8_ARG_TO_UINT(1, _textureDictionary);
textureDictionary = _textureDictionary;
}

uint32_t texture;
if (info[1]->IsString())
{
V8_ARG_TO_STRING(2, textureName);
texture = alt::ICore::Instance().Hash(textureName);
}
else
{
V8_ARG_TO_UINT(2, _texture);
texture = _texture;
}

alt::VehicleBadgePosition positions[4];
for (int i = 0; i < 4; i++)
{
if (!info[i + 2]->IsObject()) break;

V8_ARG_TO_OBJECT(i + 3, dict);

if (dict.IsEmpty()) break;

V8_TO_BOOLEAN(V8Helpers::Get(ctx, dict, "active"), active);
V8_TO_NUMBER(V8Helpers::Get(ctx, dict, "size"), size);
V8_TO_INT32(V8Helpers::Get(ctx, dict, "boneIndex"), boneIndex);
V8_TO_INT32(V8Helpers::Get(ctx, dict, "alpha"), alpha);

V8_TO_VECTOR3(V8Helpers::Get(ctx, dict, "offset"), offset);
V8_TO_VECTOR3(V8Helpers::Get(ctx, dict, "direction"), direction);
V8_TO_VECTOR3(V8Helpers::Get(ctx, dict, "side"), side);

positions[i] = alt::VehicleBadgePosition((uint8_t)alpha, (float)size, (int16_t)boneIndex, offset, direction, side);
positions[i].active = active;
}

_this->SetBadge(textureDictionary, texture, positions);
}

extern V8Class v8Entity;
extern V8Class v8Vehicle("Vehicle",
v8Entity,
Expand Down Expand Up @@ -439,4 +494,5 @@ extern V8Class v8Vehicle("Vehicle",
V8Helpers::SetMethod(isolate, tpl, "setWeaponCapacity", &SetWeaponCapacity);
V8Helpers::SetAccessor<IVehicle, bool, &IVehicle::GetHybridExtraActive, &IVehicle::SetHybridExtraActive>(isolate, tpl, "hybridExtraActive");
V8Helpers::SetAccessor<IVehicle, uint8_t, &IVehicle::GetHybridExtraState, &IVehicle::SetHybridExtraState>(isolate, tpl, "hybridExtraState");
V8Helpers::SetMethod(isolate, tpl, "setBadge", &SetBadge);
});
3 changes: 2 additions & 1 deletion server/src/events/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ V8Helpers::LocalEventHandler playerConnectDenied(EventType::PLAYER_CONNECT_DENIE
args.push_back(V8Helpers::JSValue(ev->GetPasswordHash()));
args.push_back(V8Helpers::JSValue(ev->IsDebug()));
args.push_back(V8Helpers::JSValue(ev->GetBranch()));
args.push_back(V8Helpers::JSValue(ev->GetMajorVersion()));
args.push_back(V8Helpers::JSValue(ev->GetVersionMajor()));
// TODO: no idea where to put version minor to not break backward compatibility, not sure it's needed at all
args.push_back(V8Helpers::JSValue(ev->GetCdnUrl()));
args.push_back(V8Helpers::JSValue(ev->GetDiscordId()));
});
Expand Down
11 changes: 6 additions & 5 deletions shared/V8Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,18 @@ V8Helpers::SourceLocation::SourceLocation(std::string&& _fileName, int _line, v8
context.Reset(ctx->GetIsolate(), ctx);
}

std::string V8Helpers::SourceLocation::ToString()
std::string V8Helpers::SourceLocation::ToString(v8::Isolate* isolate)
{
auto isolate = v8::Isolate::GetCurrent();

std::stringstream stream;
stream << "[";

// Check if not inside a worker
if(!(*static_cast<bool*>(isolate->GetData(v8::Isolate::GetNumberOfDataSlots() - 1))))
bool* isWorker = static_cast<bool*>(isolate->GetData(v8::Isolate::GetNumberOfDataSlots() - 1));
if (!isWorker || !(*isWorker))
{
stream << V8ResourceImpl::Get(context.Get(v8::Isolate::GetCurrent()))->GetResource()->GetName() << ":";
stream << V8ResourceImpl::Get(context.Get(isolate))->GetResource()->GetName() << ":";
}

stream << fileName << ":" << line << "]";
return stream.str();
}
Expand Down
2 changes: 1 addition & 1 deletion shared/V8Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace V8Helpers
return line;
}

std::string ToString();
std::string ToString(v8::Isolate* isolate);

static SourceLocation GetCurrent(v8::Isolate* isolate, V8ResourceImpl* resource = nullptr);

Expand Down
2 changes: 1 addition & 1 deletion shared/V8ResourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void V8ResourceImpl::OnRemoveBaseObject(alt::IBaseObject* handle)
if(!ent) return;

auto entityType = handle->GetType();
if(entityType == alt::IBaseObject::Type::PLAYER || entityType == alt::IBaseObject::Type::LOCAL_PLAYER || entityType == alt::IBaseObject::Type::VEHICLE)
if(entityType == alt::IBaseObject::Type::PLAYER || entityType == alt::IBaseObject::Type::LOCAL_PLAYER || entityType == alt::IBaseObject::Type::VEHICLE || entityType == alt::IBaseObject::Type::PED || entityType == alt::IBaseObject::Type::OBJECT)
{
std::vector<V8Helpers::EventCallback*> handlers = GetLocalHandlers("removeEntity");
std::vector<v8::Local<v8::Value>> args{ ent->GetJSVal(isolate) };
Expand Down
Loading

0 comments on commit 04ebe12

Please sign in to comment.