Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
C0kkie committed Jan 12, 2024
2 parents 235a7bb + 6cd36af commit 49a2fab
Show file tree
Hide file tree
Showing 32 changed files with 628 additions and 270 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
11 changes: 9 additions & 2 deletions client/src/bindings/AudioFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,18 @@ static void AddVolumeEffect(const v8::FunctionCallbackInfo<v8::Value>& info)

V8_GET_THIS_BASE_OBJECT(filter, alt::IAudioFilter);

V8_CHECK_ARGS_LEN(2);
V8_CHECK_ARGS_LEN2(2, 3);
V8_ARG_TO_NUMBER(1, fVolume);
V8_ARG_TO_INT(2, priority);

V8_RETURN_UINT(filter->AddVolumeEffect(fVolume, priority));
int channel = -1;
if (info.Length() > 2)
{
V8_TO_UINT(info[2], channel2);
channel = channel2;
}

V8_RETURN_UINT(filter->AddVolumeEffect(fVolume, priority, channel));
}

static void AddPeakeqEffect(const v8::FunctionCallbackInfo<v8::Value>& info)
Expand Down
173 changes: 173 additions & 0 deletions client/src/bindings/ClientBindingsMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,13 @@ static void GetMsPerGameMinute(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_RETURN_INT(ICore::Instance().GetMsPerGameMinute());
}

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

V8_RETURN_NUMBER(ICore::Instance().GetServerTime());
}

static void SetMsPerGameMinute(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
Expand Down Expand Up @@ -1203,6 +1210,152 @@ static void IsFullScreen(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_RETURN_BOOLEAN(alt::ICore::Instance().IsFullScreen());
}

static void GetPoolSize(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(1);
V8_ARG_TO_STRING(1, pool);

V8_RETURN_UINT(alt::ICore::Instance().GetPoolSize(pool));
}

static void GetPoolCount(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_CHECK_ARGS_LEN(1);
V8_ARG_TO_STRING(1, pool);

V8_RETURN_UINT(alt::ICore::Instance().GetPoolCount(pool));
}

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());

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

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 @@ -1299,6 +1452,7 @@ extern V8Module altModule("alt",
// Time managements functions
V8Helpers::RegisterFunc(exports, "setMsPerGameMinute", &SetMsPerGameMinute);
V8Helpers::RegisterFunc(exports, "getMsPerGameMinute", &GetMsPerGameMinute);
V8Helpers::RegisterFunc(exports, "getServerTime", &GetServerTime);

// CEF rendering on texture
V8Helpers::RegisterFunc(exports, "isTextureExistInArchetype", &IsTextureExistInArchetype);
Expand Down Expand Up @@ -1390,4 +1544,23 @@ extern V8Module altModule("alt",

V8Helpers::RegisterFunc(exports, "evalModule", &EvalModule);
V8Helpers::RegisterFunc(exports, "isFullScreen", &IsFullScreen);

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);
});
39 changes: 31 additions & 8 deletions client/src/bindings/TextLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_ARG_TO_BOOLEAN_OPT(10, useStreaming, false);
V8_ARG_TO_UINT_OPT(11, streamingDistance, 0);

auto textLabel =
alt::ICore::Instance().CreateTextLabel(text, fontName, fontSize, scale, pos, rot, color, outlineWidth, outlineColor, useStreaming, streamingDistance, resource->GetResource());
auto textLabel = alt::ICore::Instance().CreateTextLabel(text, fontName, fontSize, scale, pos, rot, color, outlineWidth, outlineColor, useStreaming, streamingDistance, resource->GetResource());
V8_BIND_BASE_OBJECT(textLabel, "Failed to create textlabel");
}

// static void AllGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
// {
// V8_GET_ISOLATE_CONTEXT_RESOURCE();
// V8_RETURN(resource->GetAllTextLabel());
// }
static void AllGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_RETURN(resource->GetAllTextLabels());
}

static void StaticGetByID(const v8::FunctionCallbackInfo<v8::Value>& info)
{
Expand All @@ -51,6 +50,24 @@ static void StaticGetByID(const v8::FunctionCallbackInfo<v8::Value>& info)
}
}

static void AlignGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE();

V8_GET_THIS_BASE_OBJECT(label, alt::ITextLabel);

V8_RETURN_NUMBER(label->GetAlign());
}

static void AlignSetter(v8::Local<v8::String>, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_GET_THIS_BASE_OBJECT(label, alt::ITextLabel);

V8_TO_NUMBER(val, align);
label->SetAlign((alt::ITextLabel::Alignment) align);
}

extern V8Class v8WorldObject;
extern V8Class v8TextLabel("TextLabel",
v8WorldObject,
Expand All @@ -60,7 +77,7 @@ extern V8Class v8TextLabel("TextLabel",
using namespace alt;
v8::Isolate* isolate = v8::Isolate::GetCurrent();

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

V8Helpers::SetAccessor<ITextLabel, bool, &ITextLabel::IsStreamedIn>(isolate, tpl, "isStreamedIn");
Expand All @@ -69,6 +86,12 @@ extern V8Class v8TextLabel("TextLabel",
V8Helpers::SetAccessor<ITextLabel, IPlayer*, &ITextLabel::GetTarget>(isolate, tpl, "target");
V8Helpers::SetAccessor<ITextLabel, bool, &ITextLabel::IsVisible, &ITextLabel::SetVisible>(isolate, tpl, "visible");
V8Helpers::SetAccessor<ITextLabel, RGBA, &ITextLabel::GetColor, &ITextLabel::SetColor>(isolate, tpl, "color");
V8Helpers::SetAccessor<ITextLabel, RGBA, &ITextLabel::GetOutlineColor, &ITextLabel::SetOutlineColor>(isolate, tpl, "outlineColor");
V8Helpers::SetAccessor<ITextLabel, float, &ITextLabel::GetOutlineWidth, &ITextLabel::SetOutlineWidth>(isolate, tpl, "outlineWidth");
V8Helpers::SetAccessor<ITextLabel, float, &ITextLabel::GetFontSize, &ITextLabel::SetFontSize>(isolate, tpl, "fontSize");
V8Helpers::SetAccessor(isolate, tpl, "align", &AlignGetter, &AlignSetter);
V8Helpers::SetAccessor<ITextLabel, std::string, &ITextLabel::GetText, const std::string&, &ITextLabel::SetText>(isolate, tpl, "text");
V8Helpers::SetAccessor<ITextLabel, std::string, &ITextLabel::GetFont, const std::string&, &ITextLabel::SetFont>(isolate, tpl, "font");
V8Helpers::SetAccessor<ITextLabel, float, &ITextLabel::GetScale, &ITextLabel::SetScale>(isolate, tpl, "scale");
V8Helpers::SetAccessor<ITextLabel, Rotation, &ITextLabel::GetRotation, &ITextLabel::SetRotation>(isolate, tpl, "rot");
V8Helpers::SetAccessor<ITextLabel, bool, &ITextLabel::IsFacingCamera, &ITextLabel::SetFaceCamera>(isolate, tpl, "faceCamera");
Expand Down
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
Loading

0 comments on commit 49a2fab

Please sign in to comment.