From c12d19a3f83abdade48c13dff12fb3201821a5fa Mon Sep 17 00:00:00 2001 From: VadZz Date: Sun, 31 May 2020 16:47:23 +0300 Subject: [PATCH 001/564] Initial commit --- PromiseRejections.cpp | 57 +++++ PromiseRejections.h | 32 +++ V8Class.cpp | 29 +++ V8Class.h | 125 ++++++++++ V8Entity.h | 101 ++++++++ V8Helpers.cpp | 527 +++++++++++++++++++++++++++++++++++++++ V8Helpers.h | 234 +++++++++++++++++ V8Module.h | 69 +++++ V8ResourceImpl.cpp | 285 +++++++++++++++++++++ V8ResourceImpl.h | 295 ++++++++++++++++++++++ V8Timer.h | 50 ++++ bindings/BaseObject.cpp | 144 +++++++++++ bindings/Entity.cpp | 405 ++++++++++++++++++++++++++++++ bindings/File.cpp | 88 +++++++ bindings/Main.cpp | 334 +++++++++++++++++++++++++ bindings/RGBA.cpp | 44 ++++ bindings/Vector3.cpp | 41 +++ bindings/WorldObject.cpp | 90 +++++++ events/Main.cpp | 19 ++ 19 files changed, 2969 insertions(+) create mode 100644 PromiseRejections.cpp create mode 100644 PromiseRejections.h create mode 100644 V8Class.cpp create mode 100644 V8Class.h create mode 100644 V8Entity.h create mode 100644 V8Helpers.cpp create mode 100644 V8Helpers.h create mode 100644 V8Module.h create mode 100644 V8ResourceImpl.cpp create mode 100644 V8ResourceImpl.h create mode 100644 V8Timer.h create mode 100644 bindings/BaseObject.cpp create mode 100644 bindings/Entity.cpp create mode 100644 bindings/File.cpp create mode 100644 bindings/Main.cpp create mode 100644 bindings/RGBA.cpp create mode 100644 bindings/Vector3.cpp create mode 100644 bindings/WorldObject.cpp create mode 100644 events/Main.cpp diff --git a/PromiseRejections.cpp b/PromiseRejections.cpp new file mode 100644 index 00000000..706d9033 --- /dev/null +++ b/PromiseRejections.cpp @@ -0,0 +1,57 @@ +#include "stdafx.h" + +#include "V8ResourceImpl.h" +#include "V8Helpers.h" + +#include "PromiseRejections.h" + +void V8::PromiseRejections::RejectedWithNoHandler(V8ResourceImpl* resource, v8::PromiseRejectMessage& data) +{ + v8::Isolate* isolate = resource->GetIsolate(); + + queue.push_back(std::make_unique(isolate, data.GetPromise(), + data.GetValue(), V8::SourceLocation::GetCurrent(isolate))); +} + +void V8::PromiseRejections::HandlerAdded(V8ResourceImpl* resource, v8::PromiseRejectMessage& data) +{ + v8::Isolate* isolate = resource->GetIsolate(); + + auto newEnd = std::remove_if( + queue.begin(), queue.end(), + [&](std::unique_ptr& rejection) { + return rejection->promise.Get(isolate) == data.GetPromise(); + } + ); + + queue.erase(newEnd, queue.end()); +} + +void V8::PromiseRejections::ProcessQueue(V8ResourceImpl* resource) +{ + v8::Isolate* isolate = resource->GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + for (auto& rejection : queue) + { + if (rejection->location.GetLineNumber() != 0) + { + Log::Error << "[V8] Unhandled promise rejection at " + << resource->GetResource()->GetName() << ":" << rejection->location.GetFileName() << ":" << rejection->location.GetLineNumber() + << " (" << *v8::String::Utf8Value(isolate, rejection->value.Get(isolate)->ToString(ctx).ToLocalChecked()) << ")" << Log::Endl; + } + else + { + Log::Error << "[V8] Unhandled promise rejection at " + << resource->GetResource()->GetName() << ":" << rejection->location.GetFileName() + << " (" << *v8::String::Utf8Value(isolate, rejection->value.Get(isolate)->ToString(ctx).ToLocalChecked()) << ")" << Log::Endl; + } + } + + queue.clear(); +} + +V8::PromiseRejection::PromiseRejection(v8::Isolate* isolate, v8::Local _promise, v8::Local _value, V8::SourceLocation&& _location) : + promise(isolate, _promise), value(isolate, _value), location(std::move(_location)) +{ +} diff --git a/PromiseRejections.h b/PromiseRejections.h new file mode 100644 index 00000000..14034a2d --- /dev/null +++ b/PromiseRejections.h @@ -0,0 +1,32 @@ +#pragma once + +// Inspired by chromium and nodejs + +#include "v8.h" +#include "V8Helpers.h" + +class V8ResourceImpl; + +namespace V8 +{ + struct PromiseRejection + { + v8::Persistent promise; + v8::Persistent value; + V8::SourceLocation location; + + PromiseRejection(v8::Isolate* isolate, v8::Local promise, + v8::Local value, V8::SourceLocation&& location); + }; + + class PromiseRejections + { + public: + void RejectedWithNoHandler(V8ResourceImpl* resource, v8::PromiseRejectMessage& data); + void HandlerAdded(V8ResourceImpl* resource, v8::PromiseRejectMessage& data); + void ProcessQueue(V8ResourceImpl* resource); + + private: + std::vector> queue; + }; +} \ No newline at end of file diff --git a/V8Class.cpp b/V8Class.cpp new file mode 100644 index 00000000..44f65a3a --- /dev/null +++ b/V8Class.cpp @@ -0,0 +1,29 @@ +#include "stdafx.h" + +#include "V8Helpers.h" +#include "V8Class.h" + +v8::Local V8Class::New(v8::Local ctx, std::vector>& args) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + v8::Local _tpl = tpl.Get(isolate); + v8::Local obj; + + V8Helpers::TryCatch([&] { + v8::MaybeLocal maybeObj = _tpl->GetFunction(ctx).ToLocalChecked()->CallAsConstructor(ctx, args.size(), args.data()); + + if (!maybeObj.IsEmpty()) + { + obj = maybeObj.ToLocalChecked(); + return true; + } + else + { + obj = v8::Null(isolate); + return false; + } + }); + + return obj; +} diff --git a/V8Class.h b/V8Class.h new file mode 100644 index 00000000..abbbc1de --- /dev/null +++ b/V8Class.h @@ -0,0 +1,125 @@ +#pragma once + +#include +#include + +class V8Class +{ + using InitCallback = std::function)>; + + std::string parentName; + std::string name; + v8::FunctionCallback constructor; + InitCallback initCb; + v8::Persistent tpl; + bool isWrapper; + bool loaded = false; + +public: + + static auto& All() + { + static std::unordered_map _All; + return _All; + } + + V8Class( + const std::string& className, + const std::string& parentName, + v8::FunctionCallback constructor, + InitCallback&& init = {}, + bool _isWrapper = true // TODO: refactor + ) : parentName(parentName), + name(className), + constructor(constructor), + initCb(std::move(init)), + isWrapper(_isWrapper) + { + All()[name] = this; + } + + const std::string& GetName() + { + return name; + } + + v8::Local CreateInstance(v8::Local ctx) + { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + v8::Local _tpl = tpl.Get(isolate); + v8::Local obj = _tpl->InstanceTemplate()->NewInstance(ctx).ToLocalChecked(); + + return obj; + } + + v8::Local JSValue(v8::Isolate* isolate, v8::Local ctx) + { + return tpl.Get(isolate)->GetFunction(ctx).ToLocalChecked(); + } + + v8::Local New(v8::Local ctx, std::vector>& args); + + static V8Class* Get(const std::string& name) + { + auto it = All().find(name); + + if (it != All().end()) + return it->second; + else + return nullptr; + } + + static void LoadAll(v8::Isolate* isolate) + { + for (auto& p : All()) + p.second->Load(isolate); + } + + void Load(v8::Isolate* isolate) + { + if (loaded) + return; + + loaded = true; + + v8::Local _tpl = v8::FunctionTemplate::New(isolate, constructor); + _tpl->SetClassName(v8::String::NewFromUtf8(isolate, name.c_str(), v8::NewStringType::kNormal).ToLocalChecked()); + + if (isWrapper) + _tpl->InstanceTemplate()->SetInternalFieldCount(1); + + if (initCb) + initCb(_tpl); + + if (!parentName.empty()) + { + V8Class* parentClass = Get(parentName); + + if (!parentClass) + { + std::string msg = "[V8] Class '" + name + + "' attempted to inherit non-existant class '" + parentName + "'"; + + Log::Error << msg << Log::Endl; + throw std::runtime_error(msg); + } + + parentClass->Load(isolate); + + _tpl->Inherit(parentClass->tpl.Get(isolate)); + } + + if (!tpl.IsEmpty()) + { + Log::Error << "Already loaded " << name << Log::Endl; + } + + tpl.Reset(isolate, _tpl); + } + + void Register(v8::Isolate* isolate, v8::Local context, v8::Local exports) + { + exports->Set(context, v8::String::NewFromUtf8(isolate, name.c_str(), v8::NewStringType::kNormal).ToLocalChecked(), tpl.Get(isolate)->GetFunction(context).ToLocalChecked()); + } +}; \ No newline at end of file diff --git a/V8Entity.h b/V8Entity.h new file mode 100644 index 00000000..e38e1196 --- /dev/null +++ b/V8Entity.h @@ -0,0 +1,101 @@ +#pragma once + +#include + +#include "cpp-sdk/entities/IEntity.h" + +#include "V8Class.h" +#include "V8Helpers.h" + +class V8Entity +{ + V8Class* _class; + alt::Ref handle; + v8::Persistent jsVal; + +public: + /*V8Entity(v8::Local ctx, V8Class* __class, alt::Ref _handle) : + _class(__class), + handle(_handle) + { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + v8::Local obj = _class->New(ctx); + + //v8::Local meta = EntityMeta::Get(this); + + obj->SetInternalField(0, v8::External::New(isolate, this)); + //obj->Set(v8::String::NewFromUtf8(isolate, "meta"), meta); + + jsVal.Reset(isolate, obj); + }*/ + + V8Entity(v8::Local ctx, V8Class* __class, v8::Local obj, alt::Ref _handle) : + _class(__class), + handle(_handle) + { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + obj->SetInternalField(0, v8::External::New(isolate, this)); + jsVal.Reset(isolate, obj); + } + + V8Class* GetClass() { return _class; } + + alt::Ref GetHandle() { return handle; } + + v8::Local GetJSVal() { return jsVal.Get(v8::Isolate::GetCurrent()); } + + static bool IsEntity(v8::Local val) + { + if (!val->IsObject()) + return false; + + v8::Local obj = val.As(); + if (obj->InternalFieldCount() != 1) + return false; + + return true; + } + + static V8Entity* Get(v8::Local val) + { + if (!val->IsObject()) + return nullptr; + + v8::Local obj = val.As(); + if (obj->InternalFieldCount() != 1) + return nullptr; + + v8::Local i = obj->GetInternalField(0); + if (!i->IsExternal()) + return nullptr; + + return static_cast(i.As()->Value()); + } + + static V8Class* GetClass(alt::Ref handle) + { + if (!handle) + return nullptr; + + switch (handle->GetType()) + { + case alt::IBaseObject::Type::PLAYER: + return V8Class::Get("Player"); + case alt::IBaseObject::Type::VEHICLE: + return V8Class::Get("Vehicle"); + case alt::IBaseObject::Type::BLIP: + return V8Class::Get("Blip"); + case alt::IBaseObject::Type::WEBVIEW: + return V8Class::Get("WebView"); + case alt::IBaseObject::Type::VOICE_CHANNEL: + return V8Class::Get("VoiceChannel"); + case alt::IBaseObject::Type::COLSHAPE: + return V8Class::Get("Colshape"); + case alt::IBaseObject::Type::CHECKPOINT: + return V8Class::Get("Checkpoint"); + } + + return nullptr; + } +}; \ No newline at end of file diff --git a/V8Helpers.cpp b/V8Helpers.cpp new file mode 100644 index 00000000..16b38984 --- /dev/null +++ b/V8Helpers.cpp @@ -0,0 +1,527 @@ +#include "stdafx.h" + +#include "cpp-sdk/ICore.h" +#include "V8ResourceImpl.h" +#include "V8Helpers.h" + +bool V8Helpers::TryCatch(const std::function& fn) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Local context = isolate->GetEnteredContext(); + v8::TryCatch tryCatch(isolate); + + alt::IResource* resource = V8ResourceImpl::GetResource(context); + + if (!fn()) + { + v8::Local exception = tryCatch.Exception(); + v8::Local message = tryCatch.Message(); + + if (!message.IsEmpty() && !context.IsEmpty()) + { + v8::MaybeLocal maybeSourceLine = message->GetSourceLine(context); + v8::Maybe line = message->GetLineNumber(context); + v8::ScriptOrigin origin = message->GetScriptOrigin(); + + if (!origin.ResourceName()->IsUndefined()) + { + Log::Error << "[V8] Exception at " << resource->GetName() << ":" + << *v8::String::Utf8Value(isolate, origin.ResourceName()) << ":" << line.ToChecked() << Log::Endl; + + if (!maybeSourceLine.IsEmpty()) + { + v8::Local sourceLine = maybeSourceLine.ToLocalChecked(); + + if (sourceLine->Length() <= 80) + { + Log::Error << " " << *v8::String::Utf8Value(isolate, sourceLine) << Log::Endl; + } + else + { + Log::Error << " " << std::string{ *v8::String::Utf8Value(isolate, sourceLine), 80 } << "..." << Log::Endl; + } + } + } + else + { + Log::Error << "[V8] Exception at " << resource->GetName() << Log::Endl; + } + + v8::MaybeLocal stackTrace = tryCatch.StackTrace(context); + if (!stackTrace.IsEmpty() && stackTrace.ToLocalChecked()->IsString()) + { + v8::String::Utf8Value stackTraceStr(isolate, stackTrace.ToLocalChecked().As()); + Log::Error << " " << *stackTraceStr << Log::Endl; + } + } + else if (!exception.IsEmpty()) + { + Log::Error << "[V8] Exception: " + << *v8::String::Utf8Value(isolate, exception) << Log::Endl; + } + else + { + Log::Error << "[V8] Exception occured" << Log::Endl; + } + + return false; + + } + + return true; +} + +void V8Helpers::FunctionCallback(const v8::FunctionCallbackInfo& info) +{ + auto fn = static_cast(info.Data().As()->Value()); + + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Local ctx = isolate->GetEnteredContext(); + V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); + + Log::Debug << "FunctionCallback " << resource->GetResource()->GetName() << " " << V8ResourceImpl::Get(isolate->GetEnteredContext())->GetResource()->GetName() << Log::Endl; + + alt::MValueArgs args; + + for (uint64_t i = 0; i < info.Length(); ++i) + args.Push(V8Helpers::V8ToMValue(info[i])); + + alt::MValue res = (*fn)->Call(args); + + info.GetReturnValue().Set(V8Helpers::MValueToV8(res)); +} + +alt::MValue V8Helpers::V8ToMValue(v8::Local val) +{ + auto& core = alt::ICore::Instance(); + + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Local ctx = isolate->GetEnteredContext(); + + if (val.IsEmpty()) + return core.CreateMValueNone(); + + if (val->IsUndefined()) + return core.CreateMValueNone(); + + if (val->IsNull()) + return core.CreateMValueNil(); + + if (val->IsBoolean()) + return core.CreateMValueBool(val->BooleanValue(isolate)); + + if (val->IsInt32()) + return core.CreateMValueInt(val->Int32Value(ctx).ToChecked()); + + if (val->IsUint32()) + return core.CreateMValueUInt(val->Uint32Value(ctx).ToChecked()); + + if (val->IsBigInt()) + return core.CreateMValueInt(val->IntegerValue(ctx).ToChecked()); + + if (val->IsNumber()) + return core.CreateMValueDouble(val->NumberValue(ctx).ToChecked()); + + if (val->IsString()) + return core.CreateMValueString(*v8::String::Utf8Value(isolate, val)); + + if (val->IsObject()) + { + if (val->IsArray()) + { + v8::Local v8Arr = val.As(); + alt::MValueList list = core.CreateMValueList(v8Arr->Length()); + + for (uint32_t i = 0; i < v8Arr->Length(); ++i) + list->Set(i, V8ToMValue(v8Arr->Get(ctx, i).ToLocalChecked())); + + return list; + } + else if (val->IsFunction()) + { + v8::Local v8Func = val.As(); + return V8ResourceImpl::Get(ctx)->GetFunction(v8Func); + } + else if (val->IsArrayBuffer()) + { + v8::ArrayBuffer::Contents v8Buffer = val.As()->GetContents(); + return core.CreateMValueByteArray((uint8_t*)v8Buffer.Data(), v8Buffer.ByteLength()); + } + else + { + V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); + v8::Local v8Obj = val.As(); + + //if (v8Obj->InstanceOf(ctx, v8Vector3->JSValue(isolate, ctx)).ToChecked()) + if (resource->IsVector3(v8Obj)) + { + v8::Local x = v8Obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local y = v8Obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local z = v8Obj->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + + return core.CreateMValueVector3( + alt::Vector3f{ + x->Value(), + y->Value(), + z->Value() + } + ); + } + else if (resource->IsRGBA(v8Obj)) + { + v8::Local r = v8Obj->Get(ctx, V8::RGBA_RKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local g = v8Obj->Get(ctx, V8::RGBA_GKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local b = v8Obj->Get(ctx, V8::RGBA_BKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local a = v8Obj->Get(ctx, V8::RGBA_AKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + + return core.CreateMValueRGBA( + alt::RGBA{ + (uint8_t)r->Value(), + (uint8_t)g->Value(), + (uint8_t)b->Value(), + (uint8_t)a->Value() + } + ); + } + else if (resource->IsBaseObject(v8Obj)) + { + V8Entity* ent = V8Entity::Get(v8Obj); + Log::Debug << "Instanceof BaseObject" << Log::Endl; + + if (!ent) + { + Log::Warning << "Has internal field but is not entity" << Log::Endl; + return core.CreateMValueNil(); + } + else + return core.CreateMValueBaseObject(ent->GetHandle()); + } + else + { + alt::MValueDict dict = core.CreateMValueDict(); + v8::Local keys = v8Obj->GetOwnPropertyNames(ctx).ToLocalChecked(); + + for (uint32_t i = 0; i < keys->Length(); ++i) + { + v8::Local v8Key = keys->Get(ctx, i).ToLocalChecked(); + if (!v8Obj->Get(ctx, v8Key).ToLocalChecked()->IsUndefined()) + { + std::string key = *v8::String::Utf8Value(isolate, v8Key->ToString(ctx).ToLocalChecked()); + dict->Set(key, V8ToMValue(v8Obj->Get(ctx, v8Key).ToLocalChecked())); + } + } + + return dict; + } + } + } + + return core.CreateMValueNone(); +} + +v8::Local V8Helpers::MValueToV8(alt::MValueConst val) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Local ctx = isolate->GetEnteredContext(); + + switch (val->GetType()) + { + case alt::IMValue::Type::NONE: + return v8::Undefined(isolate); + case alt::IMValue::Type::NIL: + return v8::Null(isolate); + case alt::IMValue::Type::BOOL: + return v8::Boolean::New(isolate, val.As()->Value()); + case alt::IMValue::Type::INT: + { + int64_t _val = val.As()->Value(); + + if (_val >= INT_MIN && _val <= INT_MAX) + return v8::Integer::New(isolate, _val); + + return v8::BigInt::New(isolate, _val); + } + case alt::IMValue::Type::UINT: + { + uint64_t _val = val.As()->Value(); + + if (_val <= UINT_MAX) + return v8::Integer::NewFromUnsigned(isolate, _val); + + return v8::BigInt::New(isolate, _val); + } + case alt::IMValue::Type::DOUBLE: + return v8::Number::New(isolate, val.As()->Value()); + case alt::IMValue::Type::STRING: + return v8::String::NewFromUtf8(isolate, val.As()->Value().CStr(), v8::NewStringType::kNormal).ToLocalChecked(); + case alt::IMValue::Type::LIST: + { + alt::MValueListConst list = val.As(); + v8::Local v8Arr = v8::Array::New(isolate, list->GetSize()); + + for (uint32_t i = 0; i < list->GetSize(); ++i) + v8Arr->Set(ctx, i, MValueToV8(list->Get(i))); + + return v8Arr; + } + case alt::IMValue::Type::DICT: + { + alt::MValueDictConst dict = val.As(); + v8::Local v8Obj = v8::Object::New(isolate); + + for (auto it = dict->Begin(); it; it = dict->Next()) + { + v8Obj->Set(ctx, v8::String::NewFromUtf8(isolate, it->GetKey().CStr(), v8::NewStringType::kNormal).ToLocalChecked(), MValueToV8(it->GetValue())); + } + + return v8Obj; + } + case alt::IMValue::Type::BASE_OBJECT: + { + alt::Ref ref = val.As()->Value(); + + if (!ref) + { + return v8::Null(isolate); + } + else + { + V8Entity* v8Ent = V8ResourceImpl::Get(ctx)->GetOrCreateEntity(ref.Get(), "BaseObject"); + return v8Ent->GetJSVal(); + } + } + case alt::IMValue::Type::FUNCTION: + { + alt::MValueFunctionConst fn = val.As(); + v8::Local extFn = v8::External::New(isolate, new alt::MValueFunctionConst(fn)); + return v8::Function::New(ctx, V8Helpers::FunctionCallback, extFn).ToLocalChecked(); + } + case alt::IMValue::Type::VECTOR3: + return V8ResourceImpl::Get(ctx)->CreateVector3(val.As()->Value()); + case alt::IMValue::Type::RGBA: + return V8ResourceImpl::Get(ctx)->CreateRGBA(val.As()->Value()); + case alt::IMValue::Type::BYTE_ARRAY: + { + alt::MValueByteArrayConst buffer = val.As(); + v8::Local v8Buffer = v8::ArrayBuffer::New(isolate, buffer->GetSize()); + std::memcpy(v8Buffer->GetContents().Data(), buffer->GetData(), buffer->GetSize()); + return v8Buffer; + } + default: + Log::Warning << "V8::MValueToV8 Unknown MValue type" << (int)val->GetType() << Log::Endl; + } + + return v8::Undefined(isolate); +} + +void V8::DefineOwnProperty(v8::Isolate* isolate, v8::Local ctx, v8::Local val, const char* name, v8::Local value, v8::PropertyAttribute attributes) +{ + val->DefineOwnProperty(ctx, v8::String::NewFromUtf8(isolate, name, + v8::NewStringType::kInternalized).ToLocalChecked(), value, attributes); +} + +void V8::DefineOwnProperty(v8::Isolate* isolate, v8::Local ctx, v8::Local val, v8::Local name, v8::Local value, v8::PropertyAttribute attributes) +{ + val->DefineOwnProperty(ctx, name, value, attributes); +} + +void V8::SetAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) +{ + tpl->PrototypeTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, name, + v8::NewStringType::kInternalized).ToLocalChecked(), getter, setter, + v8::Local(), v8::AccessControl::DEFAULT, + setter != nullptr ? v8::PropertyAttribute::None : v8::PropertyAttribute::ReadOnly); +} + +void V8::SetMethod(v8::Isolate* isolate, v8::Local tpl, const char* name, v8::FunctionCallback callback) +{ + tpl->PrototypeTemplate()->Set(isolate, name, v8::FunctionTemplate::New(isolate, callback)); +} + +void V8::SetStaticAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) +{ + tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, name, + v8::NewStringType::kInternalized).ToLocalChecked(), getter, setter); +} + +void V8::SetStaticMethod(v8::Isolate* isolate, v8::Local tpl, const char* name, v8::FunctionCallback callback) +{ + tpl->Set(isolate, name, v8::FunctionTemplate::New(isolate, callback)); +} + +v8::Local V8::Get(v8::Local ctx, v8::Local obj, const char* name) +{ + return obj->Get(ctx, v8::String::NewFromUtf8(ctx->GetIsolate(), name, + v8::NewStringType::kInternalized).ToLocalChecked()).ToLocalChecked(); +} + +void V8::SetFunction(v8::Isolate* isolate, v8::Local ctx, v8::Local target, const char* name, v8::FunctionCallback cb, void* userData) +{ + v8::Local _name = v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized).ToLocalChecked(); + + v8::Local fn = v8::Function::New(ctx, cb, v8::External::New(isolate, userData)).ToLocalChecked(); + fn->SetName(_name); + + target->Set(ctx, _name, fn); +} + +v8::Local V8::New(v8::Isolate* isolate, v8::Local ctx, v8::Local constructor, std::vector>& args) +{ + v8::Local obj; + + V8Helpers::TryCatch([&] { + v8::MaybeLocal maybeObj = constructor->CallAsConstructor(ctx, args.size(), args.data()); + + if (maybeObj.IsEmpty()) + return false; + + obj = maybeObj.ToLocalChecked(); + return true; + }); + + return obj; +} + +V8::SourceLocation V8::SourceLocation::GetCurrent(v8::Isolate* isolate) +{ + v8::Local stackTrace = v8::StackTrace::CurrentStackTrace(isolate, 1); + if (stackTrace->GetFrameCount() > 0) + { + v8::Local frame = stackTrace->GetFrame(isolate, 0); + + v8::Local name = frame->GetScriptName(); + if (!name.IsEmpty()) + { + std::string fileName = *v8::String::Utf8Value(isolate, frame->GetScriptName()); + int line = frame->GetLineNumber(); + + return SourceLocation{ std::move(fileName), line }; + } + else if (frame->IsEval()) + { + return SourceLocation{ "[eval]", 0 }; + } + } + + return SourceLocation{ "[unknown]", 0 }; +} + +V8::SourceLocation::SourceLocation(std::string&& _fileName, int _line) : + fileName(_fileName), line(_line) +{ +} + +v8::Local V8::Vector3_XKey(v8::Isolate* isolate) +{ + static v8::Persistent xKey{ isolate, v8::String::NewFromUtf8(isolate, "x", + v8::NewStringType::kInternalized).ToLocalChecked() }; + + return xKey.Get(isolate); +} + +v8::Local V8::Vector3_YKey(v8::Isolate* isolate) +{ + static v8::Persistent yKey{ isolate, v8::String::NewFromUtf8(isolate, "y", + v8::NewStringType::kInternalized).ToLocalChecked() }; + + return yKey.Get(isolate); +} + +v8::Local V8::Vector3_ZKey(v8::Isolate* isolate) +{ + static v8::Persistent zKey{ isolate, v8::String::NewFromUtf8(isolate, "z", + v8::NewStringType::kInternalized).ToLocalChecked() }; + + return zKey.Get(isolate); +} + +v8::Local V8::RGBA_RKey(v8::Isolate* isolate) +{ + static v8::Persistent rKey{ isolate, v8::String::NewFromUtf8(isolate, "r", + v8::NewStringType::kInternalized).ToLocalChecked() }; + + return rKey.Get(isolate); +} + +v8::Local V8::RGBA_GKey(v8::Isolate* isolate) +{ + static v8::Persistent gKey{ isolate, v8::String::NewFromUtf8(isolate, "g", + v8::NewStringType::kInternalized).ToLocalChecked() }; + + return gKey.Get(isolate); +} + +v8::Local V8::RGBA_BKey(v8::Isolate* isolate) +{ + static v8::Persistent bKey{ isolate, v8::String::NewFromUtf8(isolate, "b", + v8::NewStringType::kInternalized).ToLocalChecked() }; + + return bKey.Get(isolate); +} + +v8::Local V8::RGBA_AKey(v8::Isolate* isolate) +{ + static v8::Persistent aKey{ isolate, v8::String::NewFromUtf8(isolate, "a", + v8::NewStringType::kInternalized).ToLocalChecked() }; + + return aKey.Get(isolate); +} + +bool V8::SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool* out) +{ + *out = val->ToBoolean(isolate)->Value(); + return true; +} + +bool V8::SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String* out) +{ + v8::MaybeLocal maybeString = val->ToString(ctx); + if (!maybeString.IsEmpty()) + { + *out = *v8::String::Utf8Value(isolate, maybeString.ToLocalChecked()); + return true; + } + + return false; +} + +std::vector V8::EventHandler::GetCallbacks(V8ResourceImpl* impl, const alt::CEvent* e) +{ + return callbacksGetter(impl, e); +} + +std::vector> V8::EventHandler::GetArgs(V8ResourceImpl* impl, const alt::CEvent* e) +{ + std::vector> args; + argsGetter(impl, e, args); + return args; +} + +V8::EventHandler* V8::EventHandler::Get(const alt::CEvent* e) +{ + auto& _all = all(); + auto it = _all.find(e->GetType()); + + return (it != _all.end()) ? it->second : nullptr; +} + +void V8::EventHandler::Register(alt::CEvent::Type type, EventHandler* handler) +{ + auto& _all = all(); + if (_all.count(type) == 0) + { + _all.insert({ type, handler }); + } + else + { + Log::Error << "Handler for " << (int)type << " already defined" << Log::Endl; + } +} + +V8::EventHandler::CallbacksGetter V8::LocalEventHandler::GetCallbacksGetter(const std::string& name) +{ + return [name](V8ResourceImpl* resource, const alt::CEvent*) -> std::vector + { + return resource->GetLocalHandlers(name); + }; +} diff --git a/V8Helpers.h b/V8Helpers.h new file mode 100644 index 00000000..3de9a4a2 --- /dev/null +++ b/V8Helpers.h @@ -0,0 +1,234 @@ +#pragma once + +#include +#include + +#include + +#include "cpp-sdk/entities/IEntity.h" +#include "cpp-sdk/types/MValue.h" + +class V8Helpers +{ +public: + struct HashFunc + { + size_t operator()(v8::Local fn) const + { + return fn->GetIdentityHash(); + } + }; + + struct EqFunc + { + size_t operator()(v8::Local lhs, v8::Local rhs) const + { + return lhs->StrictEquals(rhs); + } + }; + + class Binding + { + public: + using Callback = std::function ctx, v8::Local exports)>; + + Binding(Callback&& fn) + { + All().push_back(std::move(fn)); + } + + static std::vector& All() + { + static std::vector _All; + return _All; + } + + static void RegisterAll(v8::Local ctx, v8::Local exports) + { + for (auto& binding : All()) + binding(ctx, exports); + } + }; + + static void Throw(v8::Isolate* isolate, const std::string& msg) + { + isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(isolate, msg.data(), v8::NewStringType::kNormal, msg.size()).ToLocalChecked())); + } + + static void RegisterFunc(v8::Local exports, const std::string& _name, v8::FunctionCallback cb, void* data = nullptr) + { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Local ctx = isolate->GetEnteredContext(); + + v8::Local name = v8::String::NewFromUtf8(isolate, _name.data(), v8::NewStringType::kNormal, _name.size()).ToLocalChecked(); + + v8::Local fn = v8::Function::New(ctx, cb, v8::External::New(isolate, data)).ToLocalChecked(); + fn->SetName(name); + + exports->Set(ctx, name, fn); + } + + static bool TryCatch(const std::function& fn); + + static void FunctionCallback(const v8::FunctionCallbackInfo& info); + + static alt::MValue V8ToMValue(v8::Local val); + + static v8::Local MValueToV8(alt::MValueConst val); + + static void MValueArgsToV8(alt::MValueArgs args, std::vector>& v8Args) + { + for (uint64_t i = 0; i < args.GetSize(); ++i) + v8Args.push_back(MValueToV8(args[i])); + } + + static void SetAccessor(v8::Local tpl, v8::Isolate* isolate, const char* name, v8::AccessorGetterCallback getter, + v8::AccessorSetterCallback setter = nullptr) + { + tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, name, + v8::NewStringType::kInternalized).ToLocalChecked(), getter, setter); + } +}; + +class V8ResourceImpl; + +namespace V8 +{ + class SourceLocation + { + public: + SourceLocation(std::string&& fileName, int line); + SourceLocation() { }; + + const std::string& GetFileName() const { return fileName; } + int GetLineNumber() const { return line; } + + static SourceLocation GetCurrent(v8::Isolate* isolate); + + private: + std::string fileName; + int line = 0; + }; + + struct EventCallback + { + v8::UniquePersistent fn; + SourceLocation location; + bool removed = false; + + EventCallback(v8::Isolate* isolate, v8::Local _fn, SourceLocation&& location) : + fn(isolate, _fn), location(std::move(location)) { } + }; + + class EventHandler + { + public: + using CallbacksGetter = std::function(V8ResourceImpl* resource, const alt::CEvent*)>; + using ArgsGetter = std::function>& args)>; + + EventHandler(alt::CEvent::Type type, CallbacksGetter&& _handlersGetter, ArgsGetter&& _argsGetter) : + callbacksGetter(std::move(_handlersGetter)), argsGetter(std::move(_argsGetter)) + { + Register(type, this); + } + + std::vector GetCallbacks(V8ResourceImpl* impl, const alt::CEvent* e); + std::vector> GetArgs(V8ResourceImpl* impl, const alt::CEvent* e); + + static EventHandler* Get(const alt::CEvent* e); + + private: + CallbacksGetter callbacksGetter; + ArgsGetter argsGetter; + + static std::unordered_map& all() + { + static std::unordered_map _all; + return _all; + } + + static void Register(alt::CEvent::Type type, EventHandler* handler); + }; + + class LocalEventHandler : public EventHandler + { + public: + LocalEventHandler(alt::CEvent::Type type, const std::string& name, ArgsGetter&& argsGetter) : + EventHandler(type, std::move(GetCallbacksGetter(name)), std::move(argsGetter)) { } + + private: + static CallbacksGetter GetCallbacksGetter(const std::string& name); + }; + + void DefineOwnProperty(v8::Isolate* isolate, v8::Local ctx, v8::Local val, + const char* name, v8::Local value, v8::PropertyAttribute attributes = v8::PropertyAttribute::None); + + void DefineOwnProperty(v8::Isolate* isolate, v8::Local ctx, v8::Local val, + v8::Local name, v8::Local value, v8::PropertyAttribute attributes = v8::PropertyAttribute::None); + + void SetAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name, + v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter = nullptr); + + void SetMethod(v8::Isolate* isolate, v8::Local tpl, const char* name, + v8::FunctionCallback callback); + + void SetStaticAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name, + v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter = nullptr); + + void SetStaticMethod(v8::Isolate* isolate, v8::Local tpl, const char* name, + v8::FunctionCallback callback); + + void SetFunction(v8::Isolate* isolate, v8::Local ctx, v8::Local target, + const char* name, v8::FunctionCallback cb, void* userData = nullptr); + + v8::Local Get(v8::Local ctx, v8::Local obj, const char* name); + + void RegisterSharedMain(v8::Local ctx, v8::Local exports); + + v8::Local New(v8::Isolate* isolate, v8::Local ctx, v8::Local constructor, std::vector>& args); + + // TODO: create c++ classes for v8 classes and move there + v8::Local Vector3_XKey(v8::Isolate* isolate); + v8::Local Vector3_YKey(v8::Isolate* isolate); + v8::Local Vector3_ZKey(v8::Isolate* isolate); + + v8::Local RGBA_RKey(v8::Isolate* isolate); + v8::Local RGBA_GKey(v8::Isolate* isolate); + v8::Local RGBA_BKey(v8::Isolate* isolate); + v8::Local RGBA_AKey(v8::Isolate* isolate); + + bool SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool* out); + bool SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String* out); +} + +#define V8_GET_ISOLATE(info) v8::Isolate* isolate = (info).GetIsolate() +#define V8_GET_CONTEXT(isolate) v8::Local ctx = (isolate)->GetEnteredContext() +#define V8_GET_ISOLATE_CONTEXT() \ + V8_GET_ISOLATE(info); \ + V8_GET_CONTEXT(isolate) + +#define V8_CHECK_RETN(a, b, c) if (!(a)) { V8Helpers::Throw(isolate, (b)); return c; } +#define V8_CHECK(a, b) V8_CHECK_RETN(a, b,) + +#define V8_GET_THIS_ENTITY(val, type) \ + ::alt::Ref val; \ + { \ + V8Entity* __val = V8Entity::Get(info.This()); \ + V8_CHECK(__val, "entity is invalid"); \ + val = __val->GetHandle().As(); \ + } + + +#define V8_CHECK_ARGS_LEN(count) V8_CHECK((info).Length() == (count), #count " arguments expected") + +#define V8_TO_BOOLEAN(idx, val) \ + bool val; \ + V8_CHECK_RETN(V8::SafeToBoolean(info[(idx) - 1], isolate, &val), "Failed to convert argument " #idx " to bool",) + +// idx starts with 1 +#define V8_TO_STRING(idx, val) \ + alt::String val; \ + V8_CHECK_RETN(V8::SafeToString(info[(idx) - 1], isolate, ctx, &val), "Failed to convert argument " #idx " to string",) + +#define V8_RETURN(val) info.GetReturnValue().Set(val) +#define V8_RETURN_BOOL(val) V8_RETURN(v8::Boolean::New(isolate, (val))) diff --git a/V8Module.h b/V8Module.h new file mode 100644 index 00000000..98ca8532 --- /dev/null +++ b/V8Module.h @@ -0,0 +1,69 @@ +#pragma once + +#include +#include +#include +#include +#include "V8Class.h" +#include + +class V8Module { + using Callback = std::function ctx, v8::Local exports)>; + +public: + + static std::map& All() + { + static std::map all; + return all; + } + + static bool Exists(const std::string& name) + { + if (All().find(name) == All().end()) + return false; + else + return true; + } + + std::string moduleName; + std::unordered_set classes; + Callback creator; + + V8Module( + std::string moduleName, + std::initializer_list _classes, + Callback fn + ) : moduleName(moduleName), classes(_classes), creator(fn) + { + All()[moduleName] = this; + } + + void Register(v8::Isolate* isolate, v8::Local context, v8::Local exports) + { + // Load all classes + for (auto& c : classes) + { + V8Class* v8class = V8Class::Get(c); + if (!v8class) + { + auto msg = "[V8] Module '" + moduleName + + "' is attempting to load non-existant class '" + c + "'"; + + Log::Error << msg << Log::Endl; + //throw std::runtime_error(msg); + } + + v8class->Register(isolate, context, exports); + } + + creator(context, exports); + } + + v8::Local GetExports(v8::Isolate* isolate, v8::Local context) + { + v8::Local _exports = v8::Object::New(isolate); + Register(isolate, context, _exports); + return _exports; + } +}; diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp new file mode 100644 index 00000000..4708cf9f --- /dev/null +++ b/V8ResourceImpl.cpp @@ -0,0 +1,285 @@ +#include "stdafx.h" + +#include "cpp-sdk/entities/IPlayer.h" +#include "cpp-sdk/entities/IVehicle.h" + +#include "V8ResourceImpl.h" + +#ifdef ALT_SERVER_API +#include "CNodeResourceImpl.h" +#include "node.h" +#endif + +using namespace alt; + +bool V8ResourceImpl::Start() +{ + vector3Class.Reset(isolate, V8Class::Get("Vector3")->JSValue(isolate, GetContext())); + rgbaClass.Reset(isolate, V8Class::Get("RGBA")->JSValue(isolate, GetContext())); + baseObjectClass.Reset(isolate, V8Class::Get("BaseObject")->JSValue(isolate, GetContext())); + + return true; +} + +void V8ResourceImpl::OnTick() +{ + for (auto& id : oldTimers) + timers.erase(id); + + oldTimers.clear(); + + for (auto& p : timers) + { + int64_t time = GetTime(); + + if (!p.second->Update(time)) + RemoveTimer(p.first); + + if (GetTime() - time > 10) + { + auto& location = p.second->GetLocation(); + + if (location.GetLineNumber() != 0) + { + Log::Warning << "Timer at " + << resource->GetName() << ":" << location.GetFileName() << ":" << location.GetLineNumber() + << " was too long " << GetTime() - time << "ms" << Log::Endl; + } + else + { + Log::Warning << "Timer at " + << resource->GetName() << ":" << location.GetFileName() + << " was too long " << GetTime() - time << "ms" << Log::Endl; + } + } + } + + for (auto it = localHandlers.begin(); it != localHandlers.end();) + { + if (it->second.removed) + it = localHandlers.erase(it); + else + ++it; + } + + for (auto it = remoteHandlers.begin(); it != remoteHandlers.end();) + { + if (it->second.removed) + it = remoteHandlers.erase(it); + else + ++it; + } + + promiseRejections.ProcessQueue(this); +} + +v8::Local V8ResourceImpl::CreateVector3(alt::Vector3f vec) +{ + std::vector> args{ + v8::Number::New(isolate, vec[0]), + v8::Number::New(isolate, vec[1]), + v8::Number::New(isolate, vec[2]) + }; + + return V8::New(isolate, GetContext(), vector3Class.Get(isolate), args); +} + +v8::Local V8ResourceImpl::CreateRGBA(alt::RGBA rgba) +{ + std::vector> args{ + v8::Number::New(isolate, rgba.r), + v8::Number::New(isolate, rgba.g), + v8::Number::New(isolate, rgba.b), + v8::Number::New(isolate, rgba.a) + }; + + return V8::New(isolate, GetContext(), rgbaClass.Get(isolate), args); +} + +bool V8ResourceImpl::IsVector3(v8::Local val) +{ + return val->InstanceOf(GetContext(), vector3Class.Get(isolate)).ToChecked(); +} + +bool V8ResourceImpl::IsRGBA(v8::Local val) +{ + return val->InstanceOf(GetContext(), rgbaClass.Get(isolate)).ToChecked(); +} + +bool V8ResourceImpl::IsBaseObject(v8::Local val) +{ + return val->InstanceOf(GetContext(), baseObjectClass.Get(isolate)).ToChecked(); +} + +void V8ResourceImpl::OnCreateBaseObject(alt::Ref handle) +{ + NotifyPoolUpdate(handle.Get()); +} + +void V8ResourceImpl::OnRemoveBaseObject(alt::Ref handle) +{ + NotifyPoolUpdate(handle.Get()); + + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + v8::Context::Scope scope(GetContext()); + + V8Entity* ent = GetEntity(handle.Get()); + + if (!ent) + return; + + entities.erase(handle.Get()); + + // TODO: ent->SetWeak(); + ent->GetJSVal()->SetInternalField(0, v8::External::New(isolate, nullptr)); + delete ent; +} + +void V8ResourceImpl::NotifyPoolUpdate(alt::IBaseObject* ent) +{ + switch (ent->GetType()) + { + case alt::IBaseObject::Type::PLAYER: + playerPoolDirty = true; + break; + case alt::IBaseObject::Type::VEHICLE: + vehiclePoolDirty = true; + break; + } +} + +v8::Local V8ResourceImpl::GetAllPlayers() +{ + if (playerPoolDirty) + { + playerPoolDirty = false; + + Array> all = ICore::Instance().GetPlayers(); + v8::Local jsAll = v8::Array::New(isolate, all.GetSize()); + + for (uint32_t i = 0; i < all.GetSize(); ++i) + jsAll->Set(GetContext(), i, GetOrCreateEntity(all[i].Get())->GetJSVal()); + + players.Reset(isolate, jsAll); + return jsAll; + } + + return players.Get(isolate); +} + +v8::Local V8ResourceImpl::GetAllVehicles() +{ + if (vehiclePoolDirty) + { + vehiclePoolDirty = false; + + Array> all = ICore::Instance().GetVehicles(); + v8::Local jsAll = v8::Array::New(isolate, all.GetSize()); + + for (uint32_t i = 0; i < all.GetSize(); ++i) + jsAll->Set(GetContext(), i, GetOrCreateEntity(all[i].Get())->GetJSVal()); + + vehicles.Reset(isolate, jsAll); + return jsAll; + } + + return vehicles.Get(isolate); +} + +std::vector V8ResourceImpl::GetLocalHandlers(const std::string& name) +{ + std::vector handlers; + auto range = localHandlers.equal_range(name); + + for (auto it = range.first; it != range.second; ++it) + handlers.push_back(&it->second); + + return handlers; +} + +std::vector V8ResourceImpl::GetRemoteHandlers(const std::string& name) +{ + std::vector handlers; + auto range = remoteHandlers.equal_range(name); + + for (auto it = range.first; it != range.second; ++it) + handlers.push_back(&it->second); + + return handlers; +} + +void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent* ev, const std::vector& handlers, std::vector>& args) +{ + for (auto handler : handlers) + { + int64_t time = GetTime(); + + if (handler->removed) + continue; + + V8Helpers::TryCatch([&] { + v8::MaybeLocal retn = handler->fn.Get(isolate)->Call(GetContext(), v8::Undefined(isolate), args.size(), args.data()); + + if (retn.IsEmpty()) + return false; + + if (ev && retn.ToLocalChecked()->IsFalse()) + ev->Cancel(); + + return true; + }); + + if (GetTime() - time > 5) + { + if (handler->location.GetLineNumber() != 0) + { + Log::Warning << "Event handler at " + << resource->GetName() << ":" << handler->location.GetFileName() << ":" << handler->location.GetLineNumber() + << " was too long " << (GetTime() - time) << "ms" << Log::Endl; + } + else + { + Log::Warning << "Event handler at " + << resource->GetName() << ":" << handler->location.GetFileName() + << " was too long " << (GetTime() - time) << "ms" << Log::Endl; + } + } + } +} + +alt::MValue V8ResourceImpl::FunctionImpl::Call(alt::MValueArgs args) const +{ + v8::Isolate* isolate = resource->GetIsolate(); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + v8::Local ctx = resource->GetContext(); + v8::Context::Scope scope(ctx); + +#ifdef ALT_SERVER_API + CNodeResourceImpl* nodeRes = static_cast(resource); + node::CallbackScope callbackScope(isolate, nodeRes->GetAsyncResource(), nodeRes->GetAsyncContext()); +#endif // ALT_SERVER_API + + std::vector> v8Args; + V8Helpers::MValueArgsToV8(args, v8Args); + + alt::MValue res; + V8Helpers::TryCatch([&] { + v8::MaybeLocal _res = function.Get(isolate)->CallAsFunction(resource->GetContext(), v8::Undefined(isolate), v8Args.size(), v8Args.data()); + + if (_res.IsEmpty()) + return false; + + res = V8Helpers::V8ToMValue(_res.ToLocalChecked()); + return true; + }); + + if (res.IsEmpty()) + res = alt::ICore::Instance().CreateMValueNone(); + + return res; +} diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h new file mode 100644 index 00000000..0f7c7885 --- /dev/null +++ b/V8ResourceImpl.h @@ -0,0 +1,295 @@ +#pragma once + +#include +#include + +#include "cpp-sdk/types/MValue.h" +#include "cpp-sdk/IResource.h" +#include "cpp-sdk/IBaseObject.h" + +#include "V8Entity.h" +#include "V8Timer.h" +#include "PromiseRejections.h" + +class V8ResourceImpl : public alt::IResource::Impl +{ +public: + class FunctionImpl : public alt::IMValueFunction::Impl + { + public: + FunctionImpl(V8ResourceImpl* _resource, v8::Local fn) : + resource(_resource), + function(_resource->GetIsolate(), fn) + { + + } + + alt::MValue Call(alt::MValueArgs args) const override; + + private: + V8ResourceImpl* resource; + v8::UniquePersistent function; + }; + + V8ResourceImpl(v8::Isolate* _isolate, alt::IResource* _resource) : + isolate(_isolate), + resource(_resource) + { + + } + + struct PathInfo + { + alt::IPackage* pkg = nullptr; + std::string fileName; + std::string prefix; + }; + + bool Start() override; + + void OnTick() override; + + inline alt::IResource* GetResource() { return resource; } + inline v8::Isolate* GetIsolate() { return isolate; } + inline v8::Local GetContext() { return context.Get(isolate); } + + void SubscribeLocal(const std::string& ev, v8::Local cb, V8::SourceLocation&& location) + { + localHandlers.insert({ ev, V8::EventCallback{ isolate, cb, std::move(location) } }); + } + + void SubscribeRemote(const std::string& ev, v8::Local cb, V8::SourceLocation&& location) + { + remoteHandlers.insert({ ev, V8::EventCallback{ isolate, cb, std::move(location) } }); + } + + void UnsubscribeLocal(const std::string& ev, v8::Local cb) + { + auto range = localHandlers.equal_range(ev); + + for (auto it = range.first; it != range.second; ++it) + { + if (it->second.fn.Get(isolate)->StrictEquals(cb)) + it->second.removed = true; + } + } + + void UnsubscribeRemote(const std::string& ev, v8::Local cb) + { + auto range = remoteHandlers.equal_range(ev); + + for (auto it = range.first; it != range.second; ++it) + { + if (it->second.fn.Get(isolate)->StrictEquals(cb)) + it->second.removed = true; + } + } + + void DispatchStartEvent(bool error) + { + std::vector> args; + args.push_back(v8::Boolean::New(isolate, error)); + + InvokeEventHandlers(nullptr, GetLocalHandlers("resourceStart"), args); + } + + void DispatchStopEvent() + { + std::vector> args; + InvokeEventHandlers(nullptr, GetLocalHandlers("resourceStop"), args); + } + + V8Entity* GetEntity(alt::IBaseObject* handle) + { + auto it = entities.find(handle); + + if (it == entities.end()) + return nullptr; + + return it->second; + } + + V8Entity* CreateEntity(alt::IBaseObject* handle) + { + V8Class* _class = V8Entity::GetClass(handle); + + V8Entity* ent = new V8Entity(GetContext(), _class, _class->CreateInstance(GetContext()), handle); + entities.insert({ handle, ent }); + return ent; + } + + V8Entity* BindEntity(v8::Local val, alt::IBaseObject* handle) + { + V8Class* _class = V8Entity::GetClass(handle); + V8Entity* ent = new V8Entity(GetContext(), _class, val, handle); + entities.insert({ handle, ent }); + return ent; + } + + V8Entity* GetOrCreateEntity(alt::IBaseObject* handle, const char* className = "") + { + if (!handle) + Log::Error << __FUNCTION__ << " received invalid handle please contact developers if you see this" << Log::Endl; + + V8Entity* ent = GetEntity(handle); + + if (!ent) + ent = CreateEntity(handle); + + return ent; + } + + v8::Local CreateVector3(alt::Vector3f vec); + v8::Local CreateRGBA(alt::RGBA rgba); + + bool IsVector3(v8::Local val); + bool IsRGBA(v8::Local val); + bool IsBaseObject(v8::Local val); + + void OnCreateBaseObject(alt::Ref handle) override; + void OnRemoveBaseObject(alt::Ref handle) override; + + alt::MValue GetFunction(v8::Local val) + { + FunctionImpl* impl = new FunctionImpl{ this, val.As() }; + return alt::ICore::Instance().CreateMValueFunction(impl); + } + + uint32_t CreateTimer(v8::Local context, v8::Local callback, uint32_t interval, bool once, V8::SourceLocation&& location) + { + uint32_t id = nextTimerId++; + //Log::Debug << "Create timer " << id << Log::Endl; + timers[id] = new V8Timer{ isolate, context, GetTime(), callback, interval, once, std::move(location) }; + + return id; + } + + void RemoveTimer(uint32_t id) + { + oldTimers.push_back(id); + } + + uint32_t GetTimersCount() + { + return timers.size(); + } + + PathInfo Resolve(const std::string& path, const std::string& currentModulePath) + { + PathInfo pathInfo; + + if (path.size() > 1 && path.at(0) == '@') + { + std::string packName; + size_t slash = path.find_first_of('/'); + + if (slash == std::string::npos) + { + packName = path.substr(1); + pathInfo.fileName = ""; + } + else + { + packName = path.substr(1, slash - 1); + pathInfo.fileName = path.substr(slash + 1); + } + + pathInfo.prefix = "@" + packName + "/"; + +#ifndef ALT_CLIENT_API + // pathInfo.pkg = ICore::Instance().GetAssetPack(packName); +#else + auto& resourceManager = CGame::Instance().GetResourceManager(); + auto& assetManager = resourceManager.GetAssetManager(); + pathInfo.pkg = assetManager.GetAssetPack(packName); +#endif + } + else + { + if ((path.size() >= 2 && path[0] == '.' && path[1] == '/') || + (path.size() >= 3 && path[0] == '.' && path[1] == '.' && path[2] == '/')) + { + std::filesystem::path modulePath(currentModulePath); + std::filesystem::path cwd(""); + if (modulePath.has_parent_path()) + cwd = modulePath.parent_path(); + + cwd.append(path); + std::filesystem::path targetFilePath = cwd.lexically_normal(); + + pathInfo.fileName = targetFilePath.generic_u8string(); + } + else if (path.size() > 0 && path[0] == '/') + { + pathInfo.fileName = path.substr(1); + } + else + { + Log::Warning << "Full paths without / in the beginning are deprecated. Consider starting your paths with /" << Log::Endl; + pathInfo.fileName = path; + } + + pathInfo.prefix = ""; + pathInfo.pkg = resource->GetPackage(); + } + + return pathInfo; + } + + void NotifyPoolUpdate(alt::IBaseObject* ent); + + v8::Local GetAllPlayers(); + v8::Local GetAllVehicles(); + + std::vector GetLocalHandlers(const std::string& name); + std::vector GetRemoteHandlers(const std::string& name); + + static V8ResourceImpl* Get(v8::Local ctx) + { + alt::IResource* resource = GetResource(ctx); + return resource + ? static_cast(resource->GetImpl()) + : nullptr; + } + + static alt::IResource* GetResource(v8::Local ctx) + { + return static_cast(ctx->GetAlignedPointerFromEmbedderData(1)); + } + +protected: + v8::Isolate* isolate; + alt::IResource* resource; + + v8::Persistent context; + + std::unordered_map entities; + std::unordered_map timers; + + std::unordered_multimap localHandlers; + std::unordered_multimap remoteHandlers; + + uint32_t nextTimerId = 0; + std::vector oldTimers; + + bool playerPoolDirty = true; + v8::UniquePersistent players; + + bool vehiclePoolDirty = true; + v8::UniquePersistent vehicles; + + V8::PromiseRejections promiseRejections; + + v8::Persistent vector3Class; + v8::Persistent rgbaClass; + v8::Persistent baseObjectClass; + + // TEMP + static int64_t GetTime() + { + return std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()).count(); + } + + void InvokeEventHandlers(const alt::CEvent* ev, const std::vector& handlers, std::vector>& args); +}; diff --git a/V8Timer.h b/V8Timer.h new file mode 100644 index 00000000..16a1758c --- /dev/null +++ b/V8Timer.h @@ -0,0 +1,50 @@ +#pragma once + +#include "V8Helpers.h" +#include "V8ResourceImpl.h" + +class V8Timer +{ +public: + V8Timer(v8::Isolate* _isolate, v8::Local _context, int64_t curTime, v8::Local _callback, uint32_t _interval, bool _once, V8::SourceLocation&& _location) : + isolate(_isolate), + context(_isolate, _context), + lastRun(curTime), + callback(_isolate, _callback), + interval(_interval), + once(_once), + location(std::move(_location)) + { + //Log::Debug << "Create timer: " << curTime << " " << interval << Log::Endl; + } + + bool Update(int64_t curTime) + { + if (curTime - lastRun >= interval) + { + V8Helpers::TryCatch([&] { + v8::MaybeLocal result = callback.Get(isolate)->CallAsFunction(context.Get(isolate), + v8::Undefined(isolate), 0, nullptr); + + return !result.IsEmpty(); + }); + + lastRun = curTime; + + return !once; + } + + return true; + } + + const V8::SourceLocation& GetLocation() const { return location; } + +private: + v8::Isolate* isolate; + v8::Persistent context; + v8::Persistent callback; + int64_t interval; + int64_t lastRun = 0; + bool once; + V8::SourceLocation location; +}; diff --git a/bindings/BaseObject.cpp b/bindings/BaseObject.cpp new file mode 100644 index 00000000..1b486d32 --- /dev/null +++ b/bindings/BaseObject.cpp @@ -0,0 +1,144 @@ +#include "stdafx.h" + +#include "../V8Helpers.h" +#include "../V8ResourceImpl.h" +#include "../V8Class.h" +#include "../V8Entity.h" + +static void TypeGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref obj = _this->GetHandle(); + uint32_t type = static_cast(obj->GetType()); + + info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(info.GetIsolate(), type)); +} + +static void ValidGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + info.GetReturnValue().Set(v8::Boolean::New(isolate, _this != nullptr)); +} + +static void HasMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref obj = _this->GetHandle(); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + info.GetReturnValue().Set(v8::Boolean::New(isolate, obj->HasMetaData(*v8::String::Utf8Value(isolate, key)))); +} + +static void GetMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref obj = _this->GetHandle(); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + + alt::MValueConst val = obj->GetMetaData(*v8::String::Utf8Value(isolate, key)); + info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); +} + +static void SetMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref obj = _this->GetHandle(); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + v8::Local value = info[1]; + + obj->SetMetaData(*v8::String::Utf8Value(isolate, key), V8Helpers::V8ToMValue(value)); +} + +static void DeleteMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref obj = _this->GetHandle(); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + + obj->DeleteMetaData(*v8::String::Utf8Value(isolate, key)); +} + +static void Destroy(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + +#ifdef ALT_SERVER_API + alt::ICore::Instance().DestroyBaseObject(_this->GetHandle()); +#else + CGame::Instance().DestroyBaseObject(_this->GetHandle()); +#endif // ALT_SERVER_API +} + +static V8Class v8baseObject("BaseObject", "", nullptr, [](v8::Local tpl) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8::SetAccessor(isolate, tpl, "type", &TypeGetter); + V8::SetAccessor(isolate, tpl, "valid", &ValidGetter); + + V8::SetMethod(isolate, tpl, "hasMeta", HasMeta); + V8::SetMethod(isolate, tpl, "getMeta", GetMeta); + V8::SetMethod(isolate, tpl, "setMeta", SetMeta); + V8::SetMethod(isolate, tpl, "deleteMeta", DeleteMeta); + V8::SetMethod(isolate, tpl, "destroy", Destroy); +}); diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp new file mode 100644 index 00000000..2a5c4369 --- /dev/null +++ b/bindings/Entity.cpp @@ -0,0 +1,405 @@ +#include "stdafx.h" + +#include "../V8Helpers.h" +#include "../V8ResourceImpl.h" +#include "../V8Class.h" +#include "../V8Entity.h" +#include "cpp-sdk/entities/IPlayer.h" + +using namespace alt; + +static void IDGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + Ref ent = _this->GetHandle().As(); + + info.GetReturnValue().Set(v8::Integer::New(isolate, ent->GetID())); +} + +static void OwnerGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + Ref ent = _this->GetHandle().As(); + + Ref owner = ent->GetNetworkOwner(); + + if (!owner.IsEmpty()) + info.GetReturnValue().Set(resource->GetOrCreateEntity(owner.Get())->GetJSVal()); + else + info.GetReturnValue().Set(v8::Null(isolate)); +} + +static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + Ref ent = _this->GetHandle().As(); + + alt::Position _pos = ent->GetPosition(); + info.GetReturnValue().Set(resource->CreateVector3(_pos)); +} + +static void DimensionGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + Ref ent = _this->GetHandle().As(); + + info.GetReturnValue().Set(v8::Integer::New(isolate, ent->GetDimension())); +} + +static void RotationGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref ent = _this->GetHandle().As(); + + alt::Rotation _rot = ent->GetRotation(); + info.GetReturnValue().Set(resource->CreateVector3(_rot)); +} + +static void ModelGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref ent = _this->GetHandle().As(); + info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, ent->GetModel())); +} + +static void HasSyncedMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref ent = _this->GetHandle().As(); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + info.GetReturnValue().Set(v8::Boolean::New(isolate, ent->HasSyncedMetaData(*v8::String::Utf8Value(isolate, key)))); +} + +static void GetSyncedMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref ent = _this->GetHandle().As(); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + + alt::MValueConst val = ent->GetSyncedMetaData(*v8::String::Utf8Value(isolate, key)); + info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); +} + +static void HasStreamSyncedMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref ent = _this->GetHandle().As(); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + info.GetReturnValue().Set(v8::Boolean::New(isolate, ent->HasStreamSyncedMetaData(*v8::String::Utf8Value(isolate, key)))); +} + +static void GetStreamSyncedMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref ent = _this->GetHandle().As(); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + + alt::MValueConst val = ent->GetStreamSyncedMetaData(*v8::String::Utf8Value(isolate, key)); + info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); +} + +#ifdef ALT_SERVER_API + +static void RotationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8_CHECK(val->IsObject(), "object expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref obj = _this->GetHandle().As(); + + v8::Local pos = val.As(); + + v8::Local x = pos->Get(v8::String::NewFromUtf8(isolate, "x"))->ToNumber(isolate); + v8::Local y = pos->Get(v8::String::NewFromUtf8(isolate, "y"))->ToNumber(isolate); + v8::Local z = pos->Get(v8::String::NewFromUtf8(isolate, "z"))->ToNumber(isolate); + + obj->SetRotation({ float(x->Value()), float(y->Value()), float(z->Value()) }); +} + +static void ModelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8_CHECK(val->IsNumber() || val->IsString(), "model can be number or string"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref player = _this->GetHandle().As(); + V8_CHECK(player, "model can be set only for player"); + + if (val->IsNumber()) + { + player->SetModel(val->ToInteger(isolate)->Value()); + } + else + { + v8::String::Utf8Value strVal{ isolate, val }; + player->SetModel(alt::ICore::Instance().Hash(*strVal)); + } +} + +static void SetSyncedMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref ent = _this->GetHandle().As(); + + v8::Local key = info[0]->ToString(isolate); + + ent->SetSyncedMetaData(*v8::String::Utf8Value(isolate, key), V8Helpers::V8ToMValue(info[1])); +} + +static void DeleteSyncedMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref ent = _this->GetHandle().As(); + + v8::Local key = info[0]->ToString(isolate); + ent->DeleteSyncedMetaData(*v8::String::Utf8Value(isolate, key)); +} + +static void SetStreamSyncedMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref ent = _this->GetHandle().As(); + + v8::Local key = info[0]->ToString(isolate); + + ent->SetStreamSyncedMetaData(*v8::String::Utf8Value(isolate, key), V8Helpers::V8ToMValue(info[1])); +} + +static void DeleteStreamSyncedMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref ent = _this->GetHandle().As(); + + v8::Local key = info[0]->ToString(isolate); + ent->DeleteStreamSyncedMetaData(*v8::String::Utf8Value(isolate, key)); +} + +#endif // ALT_SERVER_API + +#ifdef ALT_CLIENT_API + +static void ScriptIDGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref entity = _this->GetHandle().As(); + info.GetReturnValue().Set(v8::Integer::New(isolate, entity->GetScriptID())); +} + +static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + uint16_t scriptID = info[0]->ToInteger(ctx).ToLocalChecked()->Value(); + alt::Ref entity = CGame::Instance().GetEntityByScriptID(scriptID); + + if (entity) + info.GetReturnValue().Set(resource->GetOrCreateEntity(entity.Get(), "Entity")->GetJSVal()); + else + info.GetReturnValue().Set(v8::Null(isolate)); +} + +#endif // ALT_CLIENT_API + +static void StaticGetByID(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + uint16_t id = info[0]->ToInteger(ctx).ToLocalChecked()->Value(); + + alt::Ref entity = alt::ICore::Instance().GetEntityByID(id); + + if (entity) + info.GetReturnValue().Set(resource->GetOrCreateEntity(entity.Get(), "Entity")->GetJSVal()); + else + info.GetReturnValue().Set(v8::Null(isolate)); +} + +static V8Class v8entity("Entity", "WorldObject", nullptr, [](v8::Local tpl) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); + + V8::SetAccessor(isolate, tpl, "id", IDGetter); + V8::SetAccessor(isolate, tpl, "netOwner", OwnerGetter); + + V8::SetMethod(isolate, tpl, "hasSyncedMeta", HasSyncedMeta); + V8::SetMethod(isolate, tpl, "getSyncedMeta", GetSyncedMeta); + + V8::SetMethod(isolate, tpl, "hasStreamSyncedMeta", HasStreamSyncedMeta); + V8::SetMethod(isolate, tpl, "getStreamSyncedMeta", GetStreamSyncedMeta); + +#ifdef ALT_SERVER_API + V8::SetAccessor(isolate, tpl, "rot", RotationGetter, RotationSetter); + V8::SetAccessor(isolate, tpl, "model", ModelGetter, ModelSetter); + + V8::SetMethod(isolate, tpl, "setSyncedMeta", SetSyncedMeta); + V8::SetMethod(isolate, tpl, "deleteSyncedMeta", DeleteSyncedMeta); + + V8::SetMethod(isolate, tpl, "setStreamSyncedMeta", SetStreamSyncedMeta); + V8::SetMethod(isolate, tpl, "deleteStreamSyncedMeta", DeleteStreamSyncedMeta); +#endif // ALT_SERVER_API + +#ifdef ALT_CLIENT_API + V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); + + V8::SetAccessor(isolate, tpl, "pos", PositionGetter); + //V8::SetAccessor(isolate, tpl, "dimension", DimensionGetter); + V8::SetAccessor(isolate, tpl, "rot", RotationGetter); + V8::SetAccessor(isolate, tpl, "model", ModelGetter); + V8::SetAccessor(isolate, tpl, "scriptID", ScriptIDGetter); +#endif // ALT_CLIENT_API +}); diff --git a/bindings/File.cpp b/bindings/File.cpp new file mode 100644 index 00000000..9390d0b2 --- /dev/null +++ b/bindings/File.cpp @@ -0,0 +1,88 @@ +#include "stdafx.h" + +#include "../V8Helpers.h" +#include "../V8ResourceImpl.h" +#include "../V8Class.h" + +static void StaticExists(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK(info[0]->IsString(), "fileName must be a string"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + std::string _path = *v8::String::Utf8Value(isolate, info[0].As()); + +#ifdef ALT_CLIENT + V8ResourceImpl::PathInfo path = resource->Resolve(_path, ""); + V8_CHECK(path.pkg, "invalid asset pack"); + bool exists = path.pkg->FileExists(path.fileName); +#else + bool exists = alt::ICore::Instance().FileExists(_path); +#endif + + info.GetReturnValue().Set(v8::Boolean::New(isolate, exists)); +} + +static void StaticRead(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() >= 1, "at least 1 arg expected"); + V8_CHECK(info[0]->IsString(), "fileName must be a string"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + std::string name = *v8::String::Utf8Value(isolate, info[0].As()); + + std::string encoding = "utf-8"; + + if (info.Length() >= 2) + { + V8_CHECK(info[1]->IsString(), "encoding must be a string"); + encoding = *v8::String::Utf8Value(isolate, info[1].As()); + } + +#ifdef ALT_CLIENT + V8ResourceImpl::PathInfo path = resource->Resolve(name, ""); + V8_CHECK(path.pkg, "invalid asset pack"); + + alt::IPackage::File* file = path.pkg->OpenFile(path.fileName); + V8_CHECK(file, "file does not exist"); + + alt::String data(path.pkg->GetFileSize(file)); + path.pkg->ReadFile(file, data.GetData(), data.GetSize()); + path.pkg->CloseFile(file); +#else + alt::String data = alt::ICore::Instance().FileRead(name); +#endif // ALT_CLIENT + + if (encoding == "utf-8") + { + info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, data.GetData(), v8::NewStringType::kNormal, data.GetSize()).ToLocalChecked()); + } + else if (encoding == "utf-16") + { + info.GetReturnValue().Set(v8::String::NewFromTwoByte(isolate, (uint16_t*)data.GetData(), v8::NewStringType::kNormal, data.GetSize() / 2).ToLocalChecked()); + } + else if (encoding == "binary") + { + v8::Local buffer = v8::ArrayBuffer::New(isolate, data.GetSize()); + v8::ArrayBuffer::Contents contents = buffer->GetContents(); + + std::memcpy(contents.Data(), data.GetData(), data.GetSize()); + + info.GetReturnValue().Set(buffer); + } +} + +static V8Class v8File("File", "", nullptr, [](v8::Local tpl) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8::SetStaticMethod(isolate, tpl, "exists", StaticExists); + V8::SetStaticMethod(isolate, tpl, "read", StaticRead); +}); diff --git a/bindings/Main.cpp b/bindings/Main.cpp new file mode 100644 index 00000000..d8b2efe4 --- /dev/null +++ b/bindings/Main.cpp @@ -0,0 +1,334 @@ +#include "stdafx.h" + +#include "../V8Helpers.h" +#include "../V8ResourceImpl.h" + +static void HashCb(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK(info[0]->IsString(), "string expected"); + + v8::String::Utf8Value str(isolate, info[0]); + uint32_t hash = alt::ICore::Instance().Hash(*str); + + info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(info.GetIsolate(), hash)); +} + +static void On(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 2, "on expects 2 args"); + V8_CHECK(info[0]->IsString(), "eventName must be a string"); + V8_CHECK(info[1]->IsFunction(), "callback must be a function"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); + V8_CHECK(resource, "Invalid resource"); + + std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + v8::Local callback = info[1].As(); + + resource->SubscribeLocal(evName, callback, V8::SourceLocation::GetCurrent(isolate)); +} + +static void Off(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 2, "on expects 2 args"); + V8_CHECK(info[0]->IsString(), "eventName must be a string"); + V8_CHECK(info[1]->IsFunction(), "callback must be a function"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + v8::Local callback = info[1].As(); + + resource->UnsubscribeLocal(evName, callback); +} + +static void Emit(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8_CHECK(info.Length() >= 1, "emitClient expects at least 1 arg"); + V8_CHECK(info[0]->IsString(), "eventName must be a string"); + + std::string name = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + alt::MValueArgs args; + + for (int i = 1; i < info.Length(); ++i) + args.Push(V8Helpers::V8ToMValue(info[i])); + + alt::ICore::Instance().TriggerLocalEvent(name, args); +} + + +static void HasMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + info.GetReturnValue().Set(v8::Boolean::New(isolate, alt::ICore::Instance().HasMetaData(*v8::String::Utf8Value(isolate, key)))); +} + +static void GetMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + + alt::MValueConst val = alt::ICore::Instance().GetMetaData(*v8::String::Utf8Value(isolate, key)); + info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); +} + +static void SetMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + v8::Local value = info[1]; + + alt::ICore::Instance().SetMetaData(*v8::String::Utf8Value(isolate, key), V8Helpers::V8ToMValue(value)); +} + +static void DeleteMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + alt::ICore::Instance().DeleteMetaData(*v8::String::Utf8Value(isolate, key)); +} + +static void HasSyncedMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + info.GetReturnValue().Set(v8::Boolean::New(isolate, alt::ICore::Instance().HasSyncedMetaData(*v8::String::Utf8Value(isolate, key)))); +} + +static void GetSyncedMeta(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + + alt::MValueConst val = alt::ICore::Instance().GetSyncedMetaData(*v8::String::Utf8Value(isolate, key)); + info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); +} + +static void Log(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + std::stringstream ss; + + for (int i = 0; i < info.Length(); ++i) + { + v8::Local val = info[i]; + + if (i > 0) + ss << " "; + + ss << *v8::String::Utf8Value(isolate, val->ToString(ctx).ToLocalChecked()); + } + + alt::ICore::Instance().LogColored(ss.str()); +} + +static void LogWarning(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + std::stringstream ss; + + for (int i = 0; i < info.Length(); ++i) + { + v8::Local val = info[i]; + + if (i > 0) + ss << " "; + + ss << *v8::String::Utf8Value(isolate, val->ToString(ctx).ToLocalChecked()); + } + + alt::ICore::Instance().LogWarning(ss.str()); +} + +static void LogError(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + std::stringstream ss; + + for (int i = 0; i < info.Length(); ++i) + { + v8::Local val = info[i]; + + if (i > 0) + ss << " "; + + ss << *v8::String::Utf8Value(isolate, val->ToString(ctx).ToLocalChecked()); + } + + alt::ICore::Instance().LogError(ss.str()); +} + +static void SetTimeout(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + V8_CHECK(info[0]->IsFunction(), "function expected"); + V8_CHECK(info[1]->IsNumber(), "number expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + v8::Local ctx = isolate->GetEnteredContext(); + + v8::Local callback = info[0].As(); + v8::Local time = info[1]->ToUint32(ctx).ToLocalChecked(); + + uint32_t id = resource->CreateTimer(ctx, callback, time->Value(), true, V8::SourceLocation::GetCurrent(isolate)); + + info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, id)); +} + +static void SetInterval(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + V8_CHECK(info[0]->IsFunction(), "function expected"); + V8_CHECK(info[1]->IsNumber(), "number expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + v8::Local ctx = isolate->GetEnteredContext(); + + v8::Local callback = info[0].As(); + v8::Local time = info[1]->ToUint32(ctx).ToLocalChecked(); + + uint32_t id = resource->CreateTimer(ctx, callback, time->Value(), false, V8::SourceLocation::GetCurrent(isolate)); + + info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, id)); +} + +static void NextTick(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK(info[0]->IsFunction(), "function expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + v8::Local ctx = isolate->GetEnteredContext(); + + v8::Local callback = info[0].As(); + + uint32_t id = resource->CreateTimer(ctx, callback, 0, true, V8::SourceLocation::GetCurrent(isolate)); + + info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, id)); +} + +static void EveryTick(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK(info[0]->IsFunction(), "function expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + v8::Local ctx = isolate->GetEnteredContext(); + + v8::Local callback = info[0].As(); + + uint32_t id = resource->CreateTimer(ctx, callback, 0, false, V8::SourceLocation::GetCurrent(isolate)); + + info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, id)); +} + +static void ClearTimer(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK(info[0]->IsNumber(), "number expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + v8::Local ctx = isolate->GetEnteredContext(); + + v8::Local time = info[0]->ToUint32(ctx).ToLocalChecked(); + + resource->RemoveTimer(time->Value()); +} + +void V8::RegisterSharedMain(v8::Local ctx, v8::Local exports) +{ + v8::Isolate* isolate = ctx->GetIsolate(); + + V8Helpers::RegisterFunc(exports, "hash", &HashCb); + + V8Helpers::RegisterFunc(exports, "log", &Log); + V8Helpers::RegisterFunc(exports, "logWarning", &LogWarning); + V8Helpers::RegisterFunc(exports, "logError", &LogError); + + V8Helpers::RegisterFunc(exports, "on", &On); + V8Helpers::RegisterFunc(exports, "off", &Off); + V8Helpers::RegisterFunc(exports, "emit", &Emit); + + V8Helpers::RegisterFunc(exports, "hasMeta", &HasMeta); + V8Helpers::RegisterFunc(exports, "getMeta", &GetMeta); + V8Helpers::RegisterFunc(exports, "setMeta", &SetMeta); + V8Helpers::RegisterFunc(exports, "deleteMeta", &DeleteMeta); + + V8Helpers::RegisterFunc(exports, "hasSyncedMeta", &HasSyncedMeta); + V8Helpers::RegisterFunc(exports, "getSyncedMeta", &GetSyncedMeta); + + V8Helpers::RegisterFunc(exports, "nextTick", &NextTick); + V8Helpers::RegisterFunc(exports, "everyTick", &EveryTick); + V8Helpers::RegisterFunc(exports, "setTimeout", &SetTimeout); + V8Helpers::RegisterFunc(exports, "setInterval", &SetInterval); + V8Helpers::RegisterFunc(exports, "clearTimer", &ClearTimer); + V8Helpers::RegisterFunc(exports, "clearNextTick", &ClearTimer); + V8Helpers::RegisterFunc(exports, "clearEveryTick", &ClearTimer); + V8Helpers::RegisterFunc(exports, "clearTimeout", &ClearTimer); + V8Helpers::RegisterFunc(exports, "clearInterval", &ClearTimer); + + V8::DefineOwnProperty(isolate, ctx, exports, "DefaultDimension", v8::Integer::New(isolate, alt::DEFAULT_DIMENSION)); + V8::DefineOwnProperty(isolate, ctx, exports, "GlobalDimension", v8::Integer::New(isolate, alt::GLOBAL_DIMENSION)); +} diff --git a/bindings/RGBA.cpp b/bindings/RGBA.cpp new file mode 100644 index 00000000..6e175afe --- /dev/null +++ b/bindings/RGBA.cpp @@ -0,0 +1,44 @@ +#include "stdafx.h" + +#include "../V8Class.h" +#include "../V8Helpers.h" +#include "../V8ResourceImpl.h" + +static void ToString(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + v8::Local r = info.This()->Get(ctx, V8::RGBA_RKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local g = info.This()->Get(ctx, V8::RGBA_GKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local b = info.This()->Get(ctx, V8::RGBA_BKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local a = info.This()->Get(ctx, V8::RGBA_AKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + + std::ostringstream ss; + ss << "RGBA{ r: " << r->Value() << ", g: " << r->Value() << ", b: " << b->Value() << ", a: " << a->Value() << " }"; + + info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, ss.str().c_str(), v8::NewStringType::kNormal).ToLocalChecked()); +} + +static V8Class v8RGBA("RGBA", "", [](const v8::FunctionCallbackInfo& info) { + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 4, "4 args expected"); + + v8::Local _this = info.This(); + + v8::Local r = info[0]->ToNumber(ctx).ToLocalChecked(); + v8::Local g = info[1]->ToNumber(ctx).ToLocalChecked(); + v8::Local b = info[2]->ToNumber(ctx).ToLocalChecked(); + v8::Local a = info[3]->ToNumber(ctx).ToLocalChecked(); + + V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_RKey(isolate), r, v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_GKey(isolate), g, v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_BKey(isolate), b, v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_AKey(isolate), a, v8::PropertyAttribute::ReadOnly); +}, [](v8::Local tpl) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8::SetMethod(isolate, tpl, "toString", ToString); +}, false); diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp new file mode 100644 index 00000000..63a7ee1c --- /dev/null +++ b/bindings/Vector3.cpp @@ -0,0 +1,41 @@ +#include "stdafx.h" + +#include "../V8Class.h" +#include "../V8Helpers.h" +#include "../V8ResourceImpl.h" + +static void ToString(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetCurrentContext(); + + v8::Local x = info.This()->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local y = info.This()->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local z = info.This()->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + + std::ostringstream ss; + ss << "Vector3{ x: " << x->Value() << ", y: " << y->Value() << ", z: " << z->Value() << " }"; + + info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, ss.str().c_str(), v8::NewStringType::kNormal).ToLocalChecked()); +} + +static V8Class v8Vector3("Vector3", "", [] (const v8::FunctionCallbackInfo& info) { + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 3, "3 args expected"); + + v8::Local _this = info.This(); + + v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); + v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); + v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); + + V8::DefineOwnProperty(isolate, ctx, _this, V8::Vector3_XKey(isolate), x, v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, ctx, _this, V8::Vector3_YKey(isolate), y, v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, ctx, _this, V8::Vector3_ZKey(isolate), z, v8::PropertyAttribute::ReadOnly); +}, [](v8::Local tpl) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8::SetMethod(isolate, tpl, "toString", ToString); +}, false); diff --git a/bindings/WorldObject.cpp b/bindings/WorldObject.cpp new file mode 100644 index 00000000..44ff3878 --- /dev/null +++ b/bindings/WorldObject.cpp @@ -0,0 +1,90 @@ +#include "stdafx.h" + +#include "../V8Helpers.h" +#include "../V8ResourceImpl.h" +#include "../V8Class.h" +#include "../V8Entity.h" + +using namespace alt; + +static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + Ref obj = _this->GetHandle().As(); + + alt::Position _pos = obj->GetPosition(); + info.GetReturnValue().Set(resource->CreateVector3(_pos)); +} + +static void PositionSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(val->IsObject(), "object expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + Ref obj = _this->GetHandle().As(); + + v8::Local pos = val.As(); + + v8::Local x = V8::Get(ctx, pos, "x")->ToNumber(ctx).ToLocalChecked(); + v8::Local y = V8::Get(ctx, pos, "y")->ToNumber(ctx).ToLocalChecked(); + v8::Local z = V8::Get(ctx, pos, "z")->ToNumber(ctx).ToLocalChecked(); + + obj->SetPosition({ float(x->Value()), float(y->Value()), float(z->Value()) }); +} + +#ifdef ALT_SERVER_API +static void DimensionGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + Ref obj = _this->GetHandle().As(); + + info.GetReturnValue().Set(v8::Integer::New(isolate, obj->GetDimension())); +} + +static void DimensionSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + Ref obj = _this->GetHandle().As(); + + obj->SetDimension(val->ToInteger(isolate)->Value()); +} +#endif // ALT_SERVER_API + +static V8Class v8worldObject("WorldObject", "BaseObject", nullptr, [](v8::Local tpl) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8::SetAccessor(isolate, tpl, "pos", PositionGetter, PositionSetter); + +#ifdef ALT_SERVER_API + V8::SetAccessor(isolate, tpl, "dimension", DimensionGetter, DimensionSetter); +#endif // ALT_SERVER_API +}); \ No newline at end of file diff --git a/events/Main.cpp b/events/Main.cpp new file mode 100644 index 00000000..3f787f19 --- /dev/null +++ b/events/Main.cpp @@ -0,0 +1,19 @@ +#include "stdafx.h" + +#include "../V8ResourceImpl.h" +#include "../V8Helpers.h" + +using EventType = alt::CEvent::Type; + +V8::LocalEventHandler consoleCommand( + EventType::CONSOLE_COMMAND_EVENT, + "consoleCommand", + [](V8ResourceImpl* resource, const alt::CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + v8::Isolate* isolate = resource->GetIsolate(); + + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetName().GetData(), v8::NewStringType::kNormal, ev->GetName().GetSize()).ToLocalChecked()); + for (auto& arg : ev->GetArgs()) + args.push_back(v8::String::NewFromUtf8(isolate, arg.GetData(), v8::NewStringType::kNormal, arg.GetSize()).ToLocalChecked()); + } +); From 1643c9b5d4295417e51ca8b57ec60329efa18b94 Mon Sep 17 00:00:00 2001 From: VadZz Date: Sat, 6 Jun 2020 03:14:18 +0300 Subject: [PATCH 002/564] Added V8_GET_RESOURCE, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_BIND_BASE_OBJECT, V8::SafeToNumber --- V8Helpers.cpp | 12 ++++++++++++ V8Helpers.h | 26 +++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 16b38984..941197a5 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -473,6 +473,18 @@ bool V8::SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool* out return true; } +bool V8::SafeToNumber(v8::Local val, v8::Local ctx, double* out) +{ + v8::MaybeLocal maybeNumber = val->ToNumber(ctx); + if (!maybeNumber.IsEmpty()) + { + *out = maybeNumber.ToLocalChecked()->Value(); + return true; + } + + return false; +} + bool V8::SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String* out) { v8::MaybeLocal maybeString = val->ToString(ctx); diff --git a/V8Helpers.h b/V8Helpers.h index 3de9a4a2..7db8e654 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -198,6 +198,7 @@ namespace V8 v8::Local RGBA_AKey(v8::Isolate* isolate); bool SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool* out); + bool SafeToNumber(v8::Local val, v8::Local ctx, double* out); bool SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String* out); } @@ -207,6 +208,14 @@ namespace V8 V8_GET_ISOLATE(info); \ V8_GET_CONTEXT(isolate) +#define V8_GET_RESOURCE() \ + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); \ + V8_CHECK(resource, "invalid resource"); + +#define V8_GET_ISOLATE_CONTEXT_RESOURCE() \ + V8_GET_ISOLATE_CONTEXT(); \ + V8_GET_RESOURCE() + #define V8_CHECK_RETN(a, b, c) if (!(a)) { V8Helpers::Throw(isolate, (b)); return c; } #define V8_CHECK(a, b) V8_CHECK_RETN(a, b,) @@ -221,14 +230,25 @@ namespace V8 #define V8_CHECK_ARGS_LEN(count) V8_CHECK((info).Length() == (count), #count " arguments expected") +// idx starts with 1 #define V8_TO_BOOLEAN(idx, val) \ bool val; \ - V8_CHECK_RETN(V8::SafeToBoolean(info[(idx) - 1], isolate, &val), "Failed to convert argument " #idx " to bool",) + V8_CHECK(V8::SafeToBoolean(info[(idx) - 1], isolate, &val), "Failed to convert argument " #idx " to bool") + +#define V8_TO_NUMBER(idx, val) \ + double val; \ + V8_CHECK(V8::SafeToNumber(info[(idx) - 1], ctx, &val), "Failed to convert argument " #idx " to number") -// idx starts with 1 #define V8_TO_STRING(idx, val) \ alt::String val; \ - V8_CHECK_RETN(V8::SafeToString(info[(idx) - 1], isolate, ctx, &val), "Failed to convert argument " #idx " to string",) + V8_CHECK(V8::SafeToString(info[(idx) - 1], isolate, ctx, &val), "Failed to convert argument " #idx " to string") #define V8_RETURN(val) info.GetReturnValue().Set(val) #define V8_RETURN_BOOL(val) V8_RETURN(v8::Boolean::New(isolate, (val))) + +#define V8_BIND_BASE_OBJECT(baseObjectRef, error) \ + { \ + auto baseObject = (baseObjectRef); \ + V8_CHECK(!baseObject.IsEmpty(), error); \ + resource->BindEntity(info.This(), baseObject.Get()); \ + } From f23854316d4083cf832502656b1e4137add21516 Mon Sep 17 00:00:00 2001 From: VadZz Date: Sat, 6 Jun 2020 03:49:28 +0300 Subject: [PATCH 003/564] Small refactoring --- V8Helpers.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index 7db8e654..2159428f 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -230,16 +230,22 @@ namespace V8 #define V8_CHECK_ARGS_LEN(count) V8_CHECK((info).Length() == (count), #count " arguments expected") +#define V8_TO_BOOLEAN(v8Val, val) \ + bool val; \ + V8_CHECK(V8::SafeToBoolean((v8Val), isolate, &val), "Failed to convert value to boolean") + // idx starts with 1 -#define V8_TO_BOOLEAN(idx, val) \ +#define V8_ARG_TO_BOOLEAN(idx, val) \ bool val; \ - V8_CHECK(V8::SafeToBoolean(info[(idx) - 1], isolate, &val), "Failed to convert argument " #idx " to bool") + V8_CHECK(V8::SafeToBoolean(info[(idx) - 1], isolate, &val), "Failed to convert argument " #idx " to boolean") -#define V8_TO_NUMBER(idx, val) \ +// idx starts with 1 +#define V8_ARG_TO_NUMBER(idx, val) \ double val; \ V8_CHECK(V8::SafeToNumber(info[(idx) - 1], ctx, &val), "Failed to convert argument " #idx " to number") -#define V8_TO_STRING(idx, val) \ +// idx starts with 1 +#define V8_ARG_TO_STRING(idx, val) \ alt::String val; \ V8_CHECK(V8::SafeToString(info[(idx) - 1], isolate, ctx, &val), "Failed to convert argument " #idx " to string") From 98469e337d3b929082c7fac0a7970c31791cb9e1 Mon Sep 17 00:00:00 2001 From: VadZz Date: Sat, 6 Jun 2020 19:45:15 +0300 Subject: [PATCH 004/564] More refactoring --- V8Helpers.cpp | 32 +++++++++++++++++++--------- V8Helpers.h | 36 +++++++++++++++++++++++-------- bindings/Entity.cpp | 52 ++++++++++----------------------------------- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 941197a5..9ae59ae6 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -467,30 +467,42 @@ v8::Local V8::RGBA_AKey(v8::Isolate* isolate) return aKey.Get(isolate); } -bool V8::SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool* out) +bool V8::SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool& out) { - *out = val->ToBoolean(isolate)->Value(); + out = val->ToBoolean(isolate)->Value(); return true; } -bool V8::SafeToNumber(v8::Local val, v8::Local ctx, double* out) +bool V8::SafeToInteger(v8::Local val, v8::Local ctx, int64_t& out) { - v8::MaybeLocal maybeNumber = val->ToNumber(ctx); - if (!maybeNumber.IsEmpty()) + v8::MaybeLocal maybeVal = val->ToInteger(ctx); + if (!maybeVal.IsEmpty()) { - *out = maybeNumber.ToLocalChecked()->Value(); + out = maybeVal.ToLocalChecked()->Value(); return true; } return false; } -bool V8::SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String* out) +bool V8::SafeToNumber(v8::Local val, v8::Local ctx, double& out) { - v8::MaybeLocal maybeString = val->ToString(ctx); - if (!maybeString.IsEmpty()) + v8::MaybeLocal maybeVal = val->ToNumber(ctx); + if (!maybeVal.IsEmpty()) { - *out = *v8::String::Utf8Value(isolate, maybeString.ToLocalChecked()); + out = maybeVal.ToLocalChecked()->Value(); + return true; + } + + return false; +} + +bool V8::SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String& out) +{ + v8::MaybeLocal maybeVal = val->ToString(ctx); + if (!maybeVal.IsEmpty()) + { + out = *v8::String::Utf8Value(isolate, maybeVal.ToLocalChecked()); return true; } diff --git a/V8Helpers.h b/V8Helpers.h index 2159428f..e2dd9c9a 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -197,9 +197,10 @@ namespace V8 v8::Local RGBA_BKey(v8::Isolate* isolate); v8::Local RGBA_AKey(v8::Isolate* isolate); - bool SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool* out); - bool SafeToNumber(v8::Local val, v8::Local ctx, double* out); - bool SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String* out); + bool SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool& out); + bool SafeToInteger(v8::Local val, v8::Local ctx, int64_t& out); + bool SafeToNumber(v8::Local val, v8::Local ctx, double& out); + bool SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String& out); } #define V8_GET_ISOLATE(info) v8::Isolate* isolate = (info).GetIsolate() @@ -219,12 +220,13 @@ namespace V8 #define V8_CHECK_RETN(a, b, c) if (!(a)) { V8Helpers::Throw(isolate, (b)); return c; } #define V8_CHECK(a, b) V8_CHECK_RETN(a, b,) -#define V8_GET_THIS_ENTITY(val, type) \ +#define V8_GET_THIS_BASE_OBJECT(val, type) \ ::alt::Ref val; \ { \ V8Entity* __val = V8Entity::Get(info.This()); \ - V8_CHECK(__val, "entity is invalid"); \ + V8_CHECK(__val, "baseobject is invalid"); \ val = __val->GetHandle().As(); \ + V8_CHECK(val, "baseobject is not of type " #type); \ } @@ -232,25 +234,41 @@ namespace V8 #define V8_TO_BOOLEAN(v8Val, val) \ bool val; \ - V8_CHECK(V8::SafeToBoolean((v8Val), isolate, &val), "Failed to convert value to boolean") + V8_CHECK(V8::SafeToBoolean((v8Val), isolate, val), "Failed to convert value to boolean") // idx starts with 1 #define V8_ARG_TO_BOOLEAN(idx, val) \ bool val; \ - V8_CHECK(V8::SafeToBoolean(info[(idx) - 1], isolate, &val), "Failed to convert argument " #idx " to boolean") + V8_CHECK(V8::SafeToBoolean(info[(idx) - 1], isolate, val), "Failed to convert argument " #idx " to boolean") + +// idx starts with 1 +#define V8_ARG_TO_INTEGER(idx, val) \ + int64_t val; \ + V8_CHECK(V8::SafeToInteger(info[(idx) - 1], ctx, val), "Failed to convert argument " #idx " to integer") // idx starts with 1 #define V8_ARG_TO_NUMBER(idx, val) \ double val; \ - V8_CHECK(V8::SafeToNumber(info[(idx) - 1], ctx, &val), "Failed to convert argument " #idx " to number") + V8_CHECK(V8::SafeToNumber(info[(idx) - 1], ctx, val), "Failed to convert argument " #idx " to number") // idx starts with 1 #define V8_ARG_TO_STRING(idx, val) \ alt::String val; \ - V8_CHECK(V8::SafeToString(info[(idx) - 1], isolate, ctx, &val), "Failed to convert argument " #idx " to string") + V8_CHECK(V8::SafeToString(info[(idx) - 1], isolate, ctx, val), "Failed to convert argument " #idx " to string") #define V8_RETURN(val) info.GetReturnValue().Set(val) +#define V8_RETURN_NULL() V8_RETURN(v8::Null(isolate)) #define V8_RETURN_BOOL(val) V8_RETURN(v8::Boolean::New(isolate, (val))) +#define V8_RETURN_INTEGER(val) V8_RETURN(v8::Integer::New(isolate, (val))) + +#define V8_RETURN_BASE_OBJECT(baseObjectRef) \ + { \ + auto baseObject = (baseObjectRef); \ + if (!baseObject.IsEmpty()) \ + V8_RETURN(resource->GetOrCreateEntity(baseObject.Get())->GetJSVal()); \ + else \ + V8_RETURN_NULL(); \ + } #define V8_BIND_BASE_OBJECT(baseObjectRef, error) \ { \ diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index 2a5c4369..bee0bc7d 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -315,57 +315,27 @@ static void DeleteStreamSyncedMeta(const v8::FunctionCallbackInfo& in static void ScriptIDGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); - - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity* _this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref entity = _this->GetHandle().As(); - info.GetReturnValue().Set(v8::Integer::New(isolate, entity->GetScriptID())); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(_this, IEntity); + V8_RETURN_INTEGER(_this->GetScriptGuid()); } static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - uint16_t scriptID = info[0]->ToInteger(ctx).ToLocalChecked()->Value(); - alt::Ref entity = CGame::Instance().GetEntityByScriptID(scriptID); - - if (entity) - info.GetReturnValue().Set(resource->GetOrCreateEntity(entity.Get(), "Entity")->GetJSVal()); - else - info.GetReturnValue().Set(v8::Null(isolate)); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, scriptGuid); + V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid)); } #endif // ALT_CLIENT_API static void StaticGetByID(const v8::FunctionCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - uint16_t id = info[0]->ToInteger(ctx).ToLocalChecked()->Value(); - - alt::Ref entity = alt::ICore::Instance().GetEntityByID(id); - - if (entity) - info.GetReturnValue().Set(resource->GetOrCreateEntity(entity.Get(), "Entity")->GetJSVal()); - else - info.GetReturnValue().Set(v8::Null(isolate)); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, id); + V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id)); } static V8Class v8entity("Entity", "WorldObject", nullptr, [](v8::Local tpl) { From da52b1b575a8e3802f374f5cf88e9054dadca172 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Fri, 3 Jul 2020 18:44:28 +0300 Subject: [PATCH 005/564] Vector3::toString output 4 decimal digits, new constructors for Vector3 --- V8Helpers.cpp | 5 +++ V8Helpers.h | 14 +++++++- bindings/Vector3.cpp | 81 +++++++++++++++++++++++++++++++++++--------- 3 files changed, 83 insertions(+), 17 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 9ae59ae6..5dbf53b8 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -355,6 +355,11 @@ v8::Local V8::Get(v8::Local ctx, v8::Local o v8::NewStringType::kInternalized).ToLocalChecked()).ToLocalChecked(); } +v8::Local V8::Get(v8::Local ctx, v8::Local obj, v8::Local name) +{ + return obj->Get(ctx, name).ToLocalChecked(); +} + void V8::SetFunction(v8::Isolate* isolate, v8::Local ctx, v8::Local target, const char* name, v8::FunctionCallback cb, void* userData) { v8::Local _name = v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized).ToLocalChecked(); diff --git a/V8Helpers.h b/V8Helpers.h index e2dd9c9a..c7ee9d9a 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -182,6 +182,7 @@ namespace V8 const char* name, v8::FunctionCallback cb, void* userData = nullptr); v8::Local Get(v8::Local ctx, v8::Local obj, const char* name); + v8::Local Get(v8::Local ctx, v8::Local obj, v8::Local name); void RegisterSharedMain(v8::Local ctx, v8::Local exports); @@ -230,12 +231,22 @@ namespace V8 } -#define V8_CHECK_ARGS_LEN(count) V8_CHECK((info).Length() == (count), #count " arguments expected") +#define V8_CHECK_CONSTRUCTOR() V8_CHECK(info.IsConstructCall(), "function can't be called without new") + +#define V8_CHECK_ARGS_LEN(count) V8_CHECK(info.Length() == (count), #count " arguments expected") +#define V8_CHECK_ARGS_LEN2(count1, count2) V8_CHECK(info.Length() == (count1) || info.Length() == (count2), #count1 " or " #count2 " arguments expected") #define V8_TO_BOOLEAN(v8Val, val) \ bool val; \ V8_CHECK(V8::SafeToBoolean((v8Val), isolate, val), "Failed to convert value to boolean") +#define V8_TO_NUMBER(v8Val, val) \ + double val; \ + V8_CHECK(V8::SafeToNumber((v8Val), ctx, val), "Failed to convert value to number") + +// idx starts with 1 +#define V8_ARG_CHECK_NUMBER(idx) V8_CHECK(info[(idx) - 1]->IsNumber(), "Argument " #idx " must be a number") + // idx starts with 1 #define V8_ARG_TO_BOOLEAN(idx, val) \ bool val; \ @@ -260,6 +271,7 @@ namespace V8 #define V8_RETURN_NULL() V8_RETURN(v8::Null(isolate)) #define V8_RETURN_BOOL(val) V8_RETURN(v8::Boolean::New(isolate, (val))) #define V8_RETURN_INTEGER(val) V8_RETURN(v8::Integer::New(isolate, (val))) +#define V8_RETURN_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val), v8::NewStringType::kNormal).ToLocalChecked()) #define V8_RETURN_BASE_OBJECT(baseObjectRef) \ { \ diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index 63a7ee1c..e4b7e1ea 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -6,35 +6,84 @@ static void ToString(const v8::FunctionCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetCurrentContext(); + V8_GET_ISOLATE_CONTEXT(); - v8::Local x = info.This()->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local y = info.This()->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local z = info.This()->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); std::ostringstream ss; - ss << "Vector3{ x: " << x->Value() << ", y: " << y->Value() << ", z: " << z->Value() << " }"; + ss << std::fixed << std::setprecision(4) + << "Vector3{ x: " << x << ", y: " << y << ", z: " << z << " }"; - info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, ss.str().c_str(), v8::NewStringType::kNormal).ToLocalChecked()); + V8_RETURN_STRING(ss.str().c_str()); } -static V8Class v8Vector3("Vector3", "", [] (const v8::FunctionCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); +static void Constructor(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 3, "3 args expected"); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN2(1, 3); v8::Local _this = info.This(); - - v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); - v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); - v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); + + v8::Local x, y, z; + + if (info.Length() == 3) + { + V8_ARG_CHECK_NUMBER(1); + V8_ARG_CHECK_NUMBER(2); + V8_ARG_CHECK_NUMBER(3); + + x = info[0]; + y = info[1]; + z = info[2]; + } + else + { + v8::Local val = info[0]; + + if (val->IsArray()) + { + v8::Local arr = val.As(); + V8_CHECK(arr->Length() == 3, "Argument must be an array of 3 numbers"); + + x = arr->Get(ctx, 0).ToLocalChecked(); + y = arr->Get(ctx, 1).ToLocalChecked(); + z = arr->Get(ctx, 2).ToLocalChecked(); + + V8_CHECK(x->IsNumber(), "Argument must be an array of 3 numbers"); + V8_CHECK(y->IsNumber(), "Argument must be an array of 3 numbers"); + V8_CHECK(z->IsNumber(), "Argument must be an array of 3 numbers"); + } + else if (val->IsObject()) + { + v8::Local obj = val.As(); + + x = obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(); + y = obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(); + z = obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(); + + V8_CHECK(x->IsNumber(), "x must be a number"); + V8_CHECK(y->IsNumber(), "y must be a number"); + V8_CHECK(z->IsNumber(), "z must be a number"); + } + else + { + V8Helpers::Throw(isolate, "Argument must be an array of 3 numbers or Vector3Like"); + return; + } + } V8::DefineOwnProperty(isolate, ctx, _this, V8::Vector3_XKey(isolate), x, v8::PropertyAttribute::ReadOnly); V8::DefineOwnProperty(isolate, ctx, _this, V8::Vector3_YKey(isolate), y, v8::PropertyAttribute::ReadOnly); V8::DefineOwnProperty(isolate, ctx, _this, V8::Vector3_ZKey(isolate), z, v8::PropertyAttribute::ReadOnly); -}, [](v8::Local tpl) { +} + +static V8Class v8Vector3("Vector3", "", Constructor, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); V8::SetMethod(isolate, tpl, "toString", ToString); From d0ba4368423eddc427fe8b06781405b08e4a71f8 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Mon, 6 Jul 2020 19:02:57 +0300 Subject: [PATCH 006/564] Added missing header --- bindings/Vector3.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index e4b7e1ea..e3a02093 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -1,5 +1,7 @@ #include "stdafx.h" +#include + #include "../V8Class.h" #include "../V8Helpers.h" #include "../V8ResourceImpl.h" From dd181baec7d08a3de5fc4363b668e9846e0b092a Mon Sep 17 00:00:00 2001 From: drakeee Date: Tue, 21 Jul 2020 19:34:30 +0200 Subject: [PATCH 007/564] Calling an exported function would crash the server without v8::Locker. --- V8ResourceImpl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 4708cf9f..8ab50cd4 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -253,6 +253,7 @@ void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent* ev, const std::vecto alt::MValue V8ResourceImpl::FunctionImpl::Call(alt::MValueArgs args) const { v8::Isolate* isolate = resource->GetIsolate(); + v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); From 2321bdb2c94c7c8325a39720e5175ac87161483e Mon Sep 17 00:00:00 2001 From: drakeee Date: Tue, 21 Jul 2020 20:24:24 +0200 Subject: [PATCH 008/564] Lockers don't needed. --- V8ResourceImpl.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 8ab50cd4..46d19a3b 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -120,7 +120,6 @@ void V8ResourceImpl::OnRemoveBaseObject(alt::Ref handle) { NotifyPoolUpdate(handle.Get()); - v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -253,7 +252,6 @@ void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent* ev, const std::vecto alt::MValue V8ResourceImpl::FunctionImpl::Call(alt::MValueArgs args) const { v8::Isolate* isolate = resource->GetIsolate(); - v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); From b11f7fe1b35871c1972cfe8fe2a0ae03a44a4069 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Wed, 22 Jul 2020 20:38:47 +0300 Subject: [PATCH 009/564] New features from SDK --- V8Helpers.h | 33 ++++++++++++++++++++++++++++++++- bindings/Entity.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/V8Helpers.h b/V8Helpers.h index c7ee9d9a..0ecdda01 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -202,6 +202,20 @@ namespace V8 bool SafeToInteger(v8::Local val, v8::Local ctx, int64_t& out); bool SafeToNumber(v8::Local val, v8::Local ctx, double& out); bool SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String& out); + + template + bool SafeToBaseObject(v8::Local val, v8::Isolate* isolate, alt::Ref& out) + { + V8Entity* v8BaseObject = V8Entity::Get(val); + if (!v8BaseObject) + return false; + + out = v8BaseObject->GetHandle().As(); + if (out.IsEmpty()) + return false; + + return true; + } } #define V8_GET_ISOLATE(info) v8::Isolate* isolate = (info).GetIsolate() @@ -252,6 +266,18 @@ namespace V8 bool val; \ V8_CHECK(V8::SafeToBoolean(info[(idx) - 1], isolate, val), "Failed to convert argument " #idx " to boolean") +// idx starts with 1 +#define V8_ARG_TO_BOOLEAN_OPT(idx, val, defaultVal) \ + bool val; \ + if (info.Length() >= (idx)) \ + { \ + V8_CHECK(V8::SafeToBoolean(info[(idx) - 1], isolate, val), "Failed to convert argument " #idx " to boolean"); \ + } \ + else \ + { \ + val = defaultVal; \ + } + // idx starts with 1 #define V8_ARG_TO_INTEGER(idx, val) \ int64_t val; \ @@ -267,9 +293,14 @@ namespace V8 alt::String val; \ V8_CHECK(V8::SafeToString(info[(idx) - 1], isolate, ctx, val), "Failed to convert argument " #idx " to string") +// idx starts with 1 +#define V8_ARG_TO_BASE_OBJECT(idx, val, type, jsClassName) \ + alt::Ref val; \ + V8_CHECK(V8::SafeToBaseObject(info[(idx)-1], isolate, val), "Argument " #idx " must be a " jsClassName) + #define V8_RETURN(val) info.GetReturnValue().Set(val) #define V8_RETURN_NULL() V8_RETURN(v8::Null(isolate)) -#define V8_RETURN_BOOL(val) V8_RETURN(v8::Boolean::New(isolate, (val))) +#define V8_RETURN_BOOLEAN(val) V8_RETURN(v8::Boolean::New(isolate, (val))) #define V8_RETURN_INTEGER(val) V8_RETURN(v8::Integer::New(isolate, (val))) #define V8_RETURN_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val), v8::NewStringType::kNormal).ToLocalChecked()) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index bee0bc7d..a4e7ae10 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -309,6 +309,27 @@ static void DeleteStreamSyncedMeta(const v8::FunctionCallbackInfo& in ent->DeleteStreamSyncedMetaData(*v8::String::Utf8Value(isolate, key)); } +static void SetNetOwner(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN2(1, 2); + V8_GET_THIS_BASE_OBJECT(_this, IEntity); + V8_ARG_TO_BASE_OBJECT(1, player, IPlayer, "Player"); + V8_ARG_TO_BOOLEAN_OPT(2, disableMigration, false); + + _this->SetNetworkOwner(player, disableMigration); +} + +static void ResetNetOwner(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN2(0, 1); + V8_GET_THIS_BASE_OBJECT(_this, IEntity); + V8_ARG_TO_BOOLEAN_OPT(1, disableMigration, false); + + _this->SetNetworkOwner(nullptr, disableMigration); +} + #endif // ALT_SERVER_API #ifdef ALT_CLIENT_API @@ -344,6 +365,7 @@ static V8Class v8entity("Entity", "WorldObject", nullptr, [](v8::Local Date: Thu, 23 Jul 2020 18:01:05 +0300 Subject: [PATCH 010/564] Fixed includes --- V8Entity.h | 1 - V8Helpers.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/V8Entity.h b/V8Entity.h index e38e1196..1477e9cd 100644 --- a/V8Entity.h +++ b/V8Entity.h @@ -5,7 +5,6 @@ #include "cpp-sdk/entities/IEntity.h" #include "V8Class.h" -#include "V8Helpers.h" class V8Entity { diff --git a/V8Helpers.h b/V8Helpers.h index 0ecdda01..2fac6cc3 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -7,6 +7,7 @@ #include "cpp-sdk/entities/IEntity.h" #include "cpp-sdk/types/MValue.h" +#include "V8Entity.h" class V8Helpers { From 12bf1330bb7e439c104c9291f3bfe19d92b2c34d Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Thu, 23 Jul 2020 19:52:41 +0300 Subject: [PATCH 011/564] Refactored some stuff returned lockers back --- V8Entity.h | 2 +- V8Helpers.cpp | 11 +---------- V8Helpers.h | 9 +-------- V8ResourceImpl.cpp | 37 ++++++++++++++++++++++++++++++++++--- V8ResourceImpl.h | 8 ++++++++ bindings/Entity.cpp | 19 +++---------------- 6 files changed, 48 insertions(+), 38 deletions(-) diff --git a/V8Entity.h b/V8Entity.h index 1477e9cd..91611550 100644 --- a/V8Entity.h +++ b/V8Entity.h @@ -42,7 +42,7 @@ class V8Entity alt::Ref GetHandle() { return handle; } - v8::Local GetJSVal() { return jsVal.Get(v8::Isolate::GetCurrent()); } + v8::Local GetJSVal(v8::Isolate* isolate) { return jsVal.Get(isolate); } static bool IsEntity(v8::Local val) { diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 5dbf53b8..de1700ba 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -279,16 +279,7 @@ v8::Local V8Helpers::MValueToV8(alt::MValueConst val) case alt::IMValue::Type::BASE_OBJECT: { alt::Ref ref = val.As()->Value(); - - if (!ref) - { - return v8::Null(isolate); - } - else - { - V8Entity* v8Ent = V8ResourceImpl::Get(ctx)->GetOrCreateEntity(ref.Get(), "BaseObject"); - return v8Ent->GetJSVal(); - } + return V8ResourceImpl::Get(ctx)->GetBaseObjectOrNull(ref); } case alt::IMValue::Type::FUNCTION: { diff --git a/V8Helpers.h b/V8Helpers.h index 2fac6cc3..fbfbb2b3 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -305,14 +305,7 @@ namespace V8 #define V8_RETURN_INTEGER(val) V8_RETURN(v8::Integer::New(isolate, (val))) #define V8_RETURN_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val), v8::NewStringType::kNormal).ToLocalChecked()) -#define V8_RETURN_BASE_OBJECT(baseObjectRef) \ - { \ - auto baseObject = (baseObjectRef); \ - if (!baseObject.IsEmpty()) \ - V8_RETURN(resource->GetOrCreateEntity(baseObject.Get())->GetJSVal()); \ - else \ - V8_RETURN_NULL(); \ - } +#define V8_RETURN_BASE_OBJECT(baseObjectRef) V8_RETURN(resource->GetBaseObjectOrNull(baseObjectRef)) #define V8_BIND_BASE_OBJECT(baseObjectRef, error) \ { \ diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 46d19a3b..1207386d 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -73,6 +73,25 @@ void V8ResourceImpl::OnTick() promiseRejections.ProcessQueue(this); } +v8::Local V8ResourceImpl::GetBaseObjectOrNull(alt::IBaseObject* handle) +{ + if (handle == nullptr) + { + return v8::Null(isolate); + } + else + { + V8Entity* ent = GetEntity(handle); + if (ent == nullptr) + { + Log::Warning << "[GetBaseObjectOrNull] handle is not valid. Please contact developers with reproduction steps" << Log::Endl; + return v8::Null(isolate); + } + + return ent->GetJSVal(isolate); + } +} + v8::Local V8ResourceImpl::CreateVector3(alt::Vector3f vec) { std::vector> args{ @@ -113,6 +132,15 @@ bool V8ResourceImpl::IsBaseObject(v8::Local val) void V8ResourceImpl::OnCreateBaseObject(alt::Ref handle) { + { + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + v8::Context::Scope scope(GetContext()); + CreateEntity(handle.Get()); + } + NotifyPoolUpdate(handle.Get()); } @@ -120,6 +148,7 @@ void V8ResourceImpl::OnRemoveBaseObject(alt::Ref handle) { NotifyPoolUpdate(handle.Get()); + v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -133,7 +162,7 @@ void V8ResourceImpl::OnRemoveBaseObject(alt::Ref handle) entities.erase(handle.Get()); // TODO: ent->SetWeak(); - ent->GetJSVal()->SetInternalField(0, v8::External::New(isolate, nullptr)); + ent->GetJSVal(isolate)->SetInternalField(0, v8::External::New(isolate, nullptr)); delete ent; } @@ -160,7 +189,7 @@ v8::Local V8ResourceImpl::GetAllPlayers() v8::Local jsAll = v8::Array::New(isolate, all.GetSize()); for (uint32_t i = 0; i < all.GetSize(); ++i) - jsAll->Set(GetContext(), i, GetOrCreateEntity(all[i].Get())->GetJSVal()); + jsAll->Set(GetContext(), i, GetBaseObjectOrNull(all[i])); players.Reset(isolate, jsAll); return jsAll; @@ -179,7 +208,7 @@ v8::Local V8ResourceImpl::GetAllVehicles() v8::Local jsAll = v8::Array::New(isolate, all.GetSize()); for (uint32_t i = 0; i < all.GetSize(); ++i) - jsAll->Set(GetContext(), i, GetOrCreateEntity(all[i].Get())->GetJSVal()); + jsAll->Set(GetContext(), i, GetBaseObjectOrNull(all[i])); vehicles.Reset(isolate, jsAll); return jsAll; @@ -252,6 +281,8 @@ void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent* ev, const std::vecto alt::MValue V8ResourceImpl::FunctionImpl::Call(alt::MValueArgs args) const { v8::Isolate* isolate = resource->GetIsolate(); + + v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index 0f7c7885..3587e6b4 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -139,6 +139,14 @@ class V8ResourceImpl : public alt::IResource::Impl return ent; } + v8::Local GetBaseObjectOrNull(alt::IBaseObject* handle); + + template + v8::Local GetBaseObjectOrNull(alt::Ref& handle) + { + return GetBaseObjectOrNull(handle.Get()); + } + v8::Local CreateVector3(alt::Vector3f vec); v8::Local CreateRGBA(alt::RGBA rgba); diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index a4e7ae10..d25b35ce 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -25,22 +25,9 @@ static void IDGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); - - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity* _this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - Ref ent = _this->GetHandle().As(); - - Ref owner = ent->GetNetworkOwner(); - - if (!owner.IsEmpty()) - info.GetReturnValue().Set(resource->GetOrCreateEntity(owner.Get())->GetJSVal()); - else - info.GetReturnValue().Set(v8::Null(isolate)); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(_this, IEntity); + V8_RETURN_BASE_OBJECT(_this->GetNetworkOwner()); } static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo& info) From 849a87c60e253792247a3b236c7d1539e1cfd7f7 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Thu, 23 Jul 2020 20:04:45 +0300 Subject: [PATCH 012/564] Fixed non-const ref --- V8ResourceImpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index 3587e6b4..b1c1c420 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -142,7 +142,7 @@ class V8ResourceImpl : public alt::IResource::Impl v8::Local GetBaseObjectOrNull(alt::IBaseObject* handle); template - v8::Local GetBaseObjectOrNull(alt::Ref& handle) + v8::Local GetBaseObjectOrNull(const alt::Ref& handle) { return GetBaseObjectOrNull(handle.Get()); } From 61c10ce6dabfcf332efa7436bbf7f96bbae3dbb0 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Fri, 24 Jul 2020 02:39:49 +0300 Subject: [PATCH 013/564] Fixed some bugs --- V8Entity.h | 28 ---------------------------- V8ResourceImpl.cpp | 20 +++++++++++--------- V8ResourceImpl.h | 8 +------- 3 files changed, 12 insertions(+), 44 deletions(-) diff --git a/V8Entity.h b/V8Entity.h index 91611550..8c42faac 100644 --- a/V8Entity.h +++ b/V8Entity.h @@ -13,22 +13,6 @@ class V8Entity v8::Persistent jsVal; public: - /*V8Entity(v8::Local ctx, V8Class* __class, alt::Ref _handle) : - _class(__class), - handle(_handle) - { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - - v8::Local obj = _class->New(ctx); - - //v8::Local meta = EntityMeta::Get(this); - - obj->SetInternalField(0, v8::External::New(isolate, this)); - //obj->Set(v8::String::NewFromUtf8(isolate, "meta"), meta); - - jsVal.Reset(isolate, obj); - }*/ - V8Entity(v8::Local ctx, V8Class* __class, v8::Local obj, alt::Ref _handle) : _class(__class), handle(_handle) @@ -44,18 +28,6 @@ class V8Entity v8::Local GetJSVal(v8::Isolate* isolate) { return jsVal.Get(isolate); } - static bool IsEntity(v8::Local val) - { - if (!val->IsObject()) - return false; - - v8::Local obj = val.As(); - if (obj->InternalFieldCount() != 1) - return false; - - return true; - } - static V8Entity* Get(v8::Local val) { if (!val->IsObject()) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 1207386d..234c4d1f 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -73,6 +73,12 @@ void V8ResourceImpl::OnTick() promiseRejections.ProcessQueue(this); } +void V8ResourceImpl::BindEntity(v8::Local val, alt::IBaseObject* handle) +{ + V8Entity* ent = new V8Entity(GetContext(), V8Entity::GetClass(handle), val, handle); + entities.insert({ handle, ent }); +} + v8::Local V8ResourceImpl::GetBaseObjectOrNull(alt::IBaseObject* handle) { if (handle == nullptr) @@ -81,14 +87,7 @@ v8::Local V8ResourceImpl::GetBaseObjectOrNull(alt::IBaseObject* handl } else { - V8Entity* ent = GetEntity(handle); - if (ent == nullptr) - { - Log::Warning << "[GetBaseObjectOrNull] handle is not valid. Please contact developers with reproduction steps" << Log::Endl; - return v8::Null(isolate); - } - - return ent->GetJSVal(isolate); + return GetOrCreateEntity(handle)->GetJSVal(isolate); } } @@ -132,6 +131,9 @@ bool V8ResourceImpl::IsBaseObject(v8::Local val) void V8ResourceImpl::OnCreateBaseObject(alt::Ref handle) { + Log::Debug << "OnCreateBaseObject " << handle.Get() << " " << (entities.find(handle.Get()) != entities.end()) << Log::Endl; + + /*if (entities.find(handle.Get()) == entities.end()) { v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); @@ -139,7 +141,7 @@ void V8ResourceImpl::OnCreateBaseObject(alt::Ref handle) v8::Context::Scope scope(GetContext()); CreateEntity(handle.Get()); - } + }*/ NotifyPoolUpdate(handle.Get()); } diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index b1c1c420..f6a998c7 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -118,13 +118,7 @@ class V8ResourceImpl : public alt::IResource::Impl return ent; } - V8Entity* BindEntity(v8::Local val, alt::IBaseObject* handle) - { - V8Class* _class = V8Entity::GetClass(handle); - V8Entity* ent = new V8Entity(GetContext(), _class, val, handle); - entities.insert({ handle, ent }); - return ent; - } + void BindEntity(v8::Local val, alt::IBaseObject* handle); V8Entity* GetOrCreateEntity(alt::IBaseObject* handle, const char* className = "") { From f194fe3e7c5854456b7b0e3b5dd350e335a2de93 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Thu, 20 Aug 2020 06:02:12 +0300 Subject: [PATCH 014/564] Added keys for fire info --- V8Helpers.cpp | 16 ++++++++++++++++ V8Helpers.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index de1700ba..98114051 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -463,6 +463,22 @@ v8::Local V8::RGBA_AKey(v8::Isolate* isolate) return aKey.Get(isolate); } +v8::Local V8::Fire_PosKey(v8::Isolate* isolate) +{ + static v8::Persistent aKey{ isolate, v8::String::NewFromUtf8(isolate, "pos", + v8::NewStringType::kInternalized).ToLocalChecked() }; + + return aKey.Get(isolate); +} + +v8::Local V8::Fire_WeaponKey(v8::Isolate* isolate) +{ + static v8::Persistent aKey{ isolate, v8::String::NewFromUtf8(isolate, "weapon", + v8::NewStringType::kInternalized).ToLocalChecked() }; + + return aKey.Get(isolate); +} + bool V8::SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool& out) { out = val->ToBoolean(isolate)->Value(); diff --git a/V8Helpers.h b/V8Helpers.h index fbfbb2b3..c220628d 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -199,6 +199,9 @@ namespace V8 v8::Local RGBA_BKey(v8::Isolate* isolate); v8::Local RGBA_AKey(v8::Isolate* isolate); + v8::Local Fire_PosKey(v8::Isolate* isolate); + v8::Local Fire_WeaponKey(v8::Isolate* isolate); + bool SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool& out); bool SafeToInteger(v8::Local val, v8::Local ctx, int64_t& out); bool SafeToNumber(v8::Local val, v8::Local ctx, double& out); From 3343f07e66149a9bcdcf15032ff3ce8a899a07dd Mon Sep 17 00:00:00 2001 From: Hazard Date: Sat, 19 Sep 2020 23:42:21 +0200 Subject: [PATCH 015/564] Don't override Tick on client --- V8ResourceImpl.cpp | 4 ++++ V8ResourceImpl.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 234c4d1f..64d8ea2e 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -21,7 +21,11 @@ bool V8ResourceImpl::Start() return true; } +#ifdef ALT_SERVER void V8ResourceImpl::OnTick() +#else +void V8ResourceImpl::Tick() +#endif { for (auto& id : oldTimers) timers.erase(id); diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index f6a998c7..27d457fe 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -47,7 +47,11 @@ class V8ResourceImpl : public alt::IResource::Impl bool Start() override; +#ifdef ALT_SERVER void OnTick() override; +#else + void Tick(); +#endif inline alt::IResource* GetResource() { return resource; } inline v8::Isolate* GetIsolate() { return isolate; } From a135014670bb10ff626b1e17651fe687f077dd88 Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 28 Sep 2020 14:14:36 +0200 Subject: [PATCH 016/564] fix macros --- V8ResourceImpl.cpp | 2 +- V8ResourceImpl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 64d8ea2e..2569a96d 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -21,7 +21,7 @@ bool V8ResourceImpl::Start() return true; } -#ifdef ALT_SERVER +#ifdef ALT_SERVER_API void V8ResourceImpl::OnTick() #else void V8ResourceImpl::Tick() diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index 27d457fe..d8e0372d 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -47,7 +47,7 @@ class V8ResourceImpl : public alt::IResource::Impl bool Start() override; -#ifdef ALT_SERVER +#ifdef ALT_SERVER_API void OnTick() override; #else void Tick(); From c60eeae579517a211fc47a0e325d9ffee14da5cc Mon Sep 17 00:00:00 2001 From: Martin <7252614+Lhoerion@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:28:32 +0200 Subject: [PATCH 017/564] Fix Vector3 ctor object reading --- bindings/Vector3.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index e3a02093..045f6fe2 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -66,8 +66,8 @@ static void Constructor(const v8::FunctionCallbackInfo& info) v8::Local obj = val.As(); x = obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(); - y = obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(); - z = obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(); + y = obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(); + z = obj->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(); V8_CHECK(x->IsNumber(), "x must be a number"); V8_CHECK(y->IsNumber(), "y must be a number"); From e12869370fac12f78107b87414f5f19f7de43d1c Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 7 Oct 2020 12:33:12 +0200 Subject: [PATCH 018/564] added alt.Version and alt.Branch --- bindings/Main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index d8b2efe4..6aa52968 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -331,4 +331,7 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8::DefineOwnProperty(isolate, ctx, exports, "DefaultDimension", v8::Integer::New(isolate, alt::DEFAULT_DIMENSION)); V8::DefineOwnProperty(isolate, ctx, exports, "GlobalDimension", v8::Integer::New(isolate, alt::GLOBAL_DIMENSION)); + + V8::DefineOwnProperty(isolate, ctx, exports, "Version", v8::String::NewFromUtf8(isolate, ALTV_VERSION).ToLocalChecked()); + V8::DefineOwnProperty(isolate, ctx, exports, "Branch", v8::String::NewFromUtf8(isolate, ALTV_BRANCH).ToLocalChecked()); } From c26a3dd97c3f007c5db24c2a10982be59e5a0a66 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 7 Oct 2020 16:51:30 +0200 Subject: [PATCH 019/564] fix non-client build --- bindings/Main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 6aa52968..360bf352 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -332,6 +332,8 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8::DefineOwnProperty(isolate, ctx, exports, "DefaultDimension", v8::Integer::New(isolate, alt::DEFAULT_DIMENSION)); V8::DefineOwnProperty(isolate, ctx, exports, "GlobalDimension", v8::Integer::New(isolate, alt::GLOBAL_DIMENSION)); +#ifdef ALT_CLIENT V8::DefineOwnProperty(isolate, ctx, exports, "Version", v8::String::NewFromUtf8(isolate, ALTV_VERSION).ToLocalChecked()); V8::DefineOwnProperty(isolate, ctx, exports, "Branch", v8::String::NewFromUtf8(isolate, ALTV_BRANCH).ToLocalChecked()); +#endif } From 43524543e70f0f8772abb54342034c5d60fff72f Mon Sep 17 00:00:00 2001 From: Hazard Date: Fri, 30 Oct 2020 12:13:20 +0100 Subject: [PATCH 020/564] Initial commit --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..d206a899 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +altv-client-js From ab6ab6816c1be2cb9ec6f5ae47ec0d6032aac614 Mon Sep 17 00:00:00 2001 From: Hazard Date: Fri, 30 Oct 2020 12:15:55 +0100 Subject: [PATCH 021/564] Added cpp-sdk and helpers --- .gitmodules | 6 ++++++ deps/cpp-sdk | 1 + src/helpers | 1 + 3 files changed, 8 insertions(+) create mode 100644 .gitmodules create mode 160000 deps/cpp-sdk create mode 160000 src/helpers diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..de37459f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "deps/cpp-sdk"] + path = deps/cpp-sdk + url = https://github.com/altmp/cpp-sdk.git +[submodule "src/helpers"] + path = src/helpers + url = https://github.com/altmp/v8-helpers.git diff --git a/deps/cpp-sdk b/deps/cpp-sdk new file mode 160000 index 00000000..6addd980 --- /dev/null +++ b/deps/cpp-sdk @@ -0,0 +1 @@ +Subproject commit 6addd980bdea3fb0aa3d3dfef1f400172cd3c708 diff --git a/src/helpers b/src/helpers new file mode 160000 index 00000000..c26a3dd9 --- /dev/null +++ b/src/helpers @@ -0,0 +1 @@ +Subproject commit c26a3dd97c3f007c5db24c2a10982be59e5a0a66 From 16c33b01b86f76a774763cd4496966f8626b7498 Mon Sep 17 00:00:00 2001 From: Hazard Date: Sat, 31 Oct 2020 23:41:41 +0100 Subject: [PATCH 022/564] Changes for altv-client-js --- Log.h | 104 ++++++++++++++++++++++ PromiseRejections.cpp | 33 ++++--- V8Class.cpp | 5 +- V8Class.h | 50 +++++------ V8Helpers.cpp | 182 ++++++++++++++++++++------------------- V8ResourceImpl.cpp | 61 ++++++------- V8ResourceImpl.h | 157 ++++++++++----------------------- bindings/BaseObject.cpp | 63 +++++++------- bindings/Entity.cpp | 139 +++++++++++++++--------------- bindings/File.cpp | 23 +++-- bindings/Main.cpp | 94 ++++++++++---------- bindings/RGBA.cpp | 14 ++- bindings/Vector3.cpp | 17 ++-- bindings/WorldObject.cpp | 37 ++++---- events/Main.cpp | 14 +-- 15 files changed, 506 insertions(+), 487 deletions(-) create mode 100644 Log.h diff --git a/Log.h b/Log.h new file mode 100644 index 00000000..8b347221 --- /dev/null +++ b/Log.h @@ -0,0 +1,104 @@ +#pragma once + +#include +#include "cpp-sdk/ICore.h" + +class Log +{ + std::stringstream buf; + + typedef Log &(*LogFn)(Log &); + static Log *_Instance; + + enum Type + { + INFO, + DEBUG, + WARNING, + ERROR, + COLORED + } type = INFO; + + Log() = default; + +public: + Log(const Log &) = delete; + Log(Log &&) = delete; + Log &operator=(const Log &) = delete; + + template + Log &Put(const T &val) + { + buf << val; + return *this; + } + Log &Put(LogFn val) { return val(*this); } + Log &SetType(Type _type) + { + type = _type; + return *this; + } + template + Log &operator<<(const T &val) { return Put(val); } + + static constexpr struct Log_Info + { + template + Log &operator<<(const T &val) const { return Instance().SetType(INFO).Put(val); } + } Info{}; + + static constexpr struct Log_Debug + { + template + Log &operator<<(const T &val) const { return Instance().SetType(DEBUG).Put(val); } + } Debug{}; + + static constexpr struct Log_Warning + { + template + Log &operator<<(const T &val) const { return Instance().SetType(WARNING).Put(val); } + } Warning{}; + + static constexpr struct Log_Error + { + template + Log &operator<<(const T &val) const { return Instance().SetType(ERROR).Put(val); } + } Error{}; + + static constexpr struct Log_Colored + { + template + Log &operator<<(const T &val) const { return Instance().SetType(COLORED).Put(val); } + } Colored{}; + + static Log &Endl(Log &log) + { + switch (log.type) + { + case INFO: + alt::ICore::Instance().LogInfo(log.buf.str()); + break; + case DEBUG: + alt::ICore::Instance().LogDebug(log.buf.str().c_str()); + break; + case WARNING: + alt::ICore::Instance().LogWarning(log.buf.str().c_str()); + break; + case ERROR: + alt::ICore::Instance().LogError(log.buf.str().c_str()); + break; + case COLORED: + alt::ICore::Instance().LogColored(log.buf.str().c_str()); + break; + } + + log.buf.str(""); + return log; + } + + static Log &Instance() + { + static Log _Instance; + return _Instance; + } +}; \ No newline at end of file diff --git a/PromiseRejections.cpp b/PromiseRejections.cpp index 706d9033..cfd806be 100644 --- a/PromiseRejections.cpp +++ b/PromiseRejections.cpp @@ -1,57 +1,54 @@ -#include "stdafx.h" #include "V8ResourceImpl.h" #include "V8Helpers.h" #include "PromiseRejections.h" -void V8::PromiseRejections::RejectedWithNoHandler(V8ResourceImpl* resource, v8::PromiseRejectMessage& data) +void V8::PromiseRejections::RejectedWithNoHandler(V8ResourceImpl *resource, v8::PromiseRejectMessage &data) { - v8::Isolate* isolate = resource->GetIsolate(); + v8::Isolate *isolate = resource->GetIsolate(); queue.push_back(std::make_unique(isolate, data.GetPromise(), - data.GetValue(), V8::SourceLocation::GetCurrent(isolate))); + data.GetValue(), V8::SourceLocation::GetCurrent(isolate))); } -void V8::PromiseRejections::HandlerAdded(V8ResourceImpl* resource, v8::PromiseRejectMessage& data) +void V8::PromiseRejections::HandlerAdded(V8ResourceImpl *resource, v8::PromiseRejectMessage &data) { - v8::Isolate* isolate = resource->GetIsolate(); + v8::Isolate *isolate = resource->GetIsolate(); auto newEnd = std::remove_if( queue.begin(), queue.end(), - [&](std::unique_ptr& rejection) { + [&](std::unique_ptr &rejection) { return rejection->promise.Get(isolate) == data.GetPromise(); - } - ); + }); queue.erase(newEnd, queue.end()); } -void V8::PromiseRejections::ProcessQueue(V8ResourceImpl* resource) +void V8::PromiseRejections::ProcessQueue(V8ResourceImpl *resource) { - v8::Isolate* isolate = resource->GetIsolate(); + v8::Isolate *isolate = resource->GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); - for (auto& rejection : queue) + for (auto &rejection : queue) { if (rejection->location.GetLineNumber() != 0) { Log::Error << "[V8] Unhandled promise rejection at " - << resource->GetResource()->GetName() << ":" << rejection->location.GetFileName() << ":" << rejection->location.GetLineNumber() - << " (" << *v8::String::Utf8Value(isolate, rejection->value.Get(isolate)->ToString(ctx).ToLocalChecked()) << ")" << Log::Endl; + << resource->GetResource()->GetName() << ":" << rejection->location.GetFileName() << ":" << rejection->location.GetLineNumber() + << " (" << *v8::String::Utf8Value(isolate, rejection->value.Get(isolate)->ToString(ctx).ToLocalChecked()) << ")" << Log::Endl; } else { Log::Error << "[V8] Unhandled promise rejection at " - << resource->GetResource()->GetName() << ":" << rejection->location.GetFileName() - << " (" << *v8::String::Utf8Value(isolate, rejection->value.Get(isolate)->ToString(ctx).ToLocalChecked()) << ")" << Log::Endl; + << resource->GetResource()->GetName() << ":" << rejection->location.GetFileName() + << " (" << *v8::String::Utf8Value(isolate, rejection->value.Get(isolate)->ToString(ctx).ToLocalChecked()) << ")" << Log::Endl; } } queue.clear(); } -V8::PromiseRejection::PromiseRejection(v8::Isolate* isolate, v8::Local _promise, v8::Local _value, V8::SourceLocation&& _location) : - promise(isolate, _promise), value(isolate, _value), location(std::move(_location)) +V8::PromiseRejection::PromiseRejection(v8::Isolate *isolate, v8::Local _promise, v8::Local _value, V8::SourceLocation &&_location) : promise(isolate, _promise), value(isolate, _value), location(std::move(_location)) { } diff --git a/V8Class.cpp b/V8Class.cpp index 44f65a3a..22b8982f 100644 --- a/V8Class.cpp +++ b/V8Class.cpp @@ -1,11 +1,10 @@ -#include "stdafx.h" #include "V8Helpers.h" #include "V8Class.h" -v8::Local V8Class::New(v8::Local ctx, std::vector>& args) +v8::Local V8Class::New(v8::Local ctx, std::vector> &args) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local _tpl = tpl.Get(isolate); v8::Local obj; diff --git a/V8Class.h b/V8Class.h index abbbc1de..5c46d97b 100644 --- a/V8Class.h +++ b/V8Class.h @@ -3,10 +3,12 @@ #include #include +#include "Log.h" + class V8Class { using InitCallback = std::function)>; - + std::string parentName; std::string name; v8::FunctionCallback constructor; @@ -16,36 +18,35 @@ class V8Class bool loaded = false; public: - - static auto& All() + static auto &All() { - static std::unordered_map _All; + static std::unordered_map _All; return _All; } V8Class( - const std::string& className, - const std::string& parentName, + const std::string &className, + const std::string &parentName, v8::FunctionCallback constructor, - InitCallback&& init = {}, + InitCallback &&init = {}, bool _isWrapper = true // TODO: refactor - ) : parentName(parentName), - name(className), - constructor(constructor), - initCb(std::move(init)), - isWrapper(_isWrapper) + ) : parentName(parentName), + name(className), + constructor(constructor), + initCb(std::move(init)), + isWrapper(_isWrapper) { All()[name] = this; } - const std::string& GetName() + const std::string &GetName() { return name; } v8::Local CreateInstance(v8::Local ctx) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local _tpl = tpl.Get(isolate); v8::Local obj = _tpl->InstanceTemplate()->NewInstance(ctx).ToLocalChecked(); @@ -53,14 +54,14 @@ class V8Class return obj; } - v8::Local JSValue(v8::Isolate* isolate, v8::Local ctx) + v8::Local JSValue(v8::Isolate *isolate, v8::Local ctx) { return tpl.Get(isolate)->GetFunction(ctx).ToLocalChecked(); } - v8::Local New(v8::Local ctx, std::vector>& args); + v8::Local New(v8::Local ctx, std::vector> &args); - static V8Class* Get(const std::string& name) + static V8Class *Get(const std::string &name) { auto it = All().find(name); @@ -70,13 +71,13 @@ class V8Class return nullptr; } - static void LoadAll(v8::Isolate* isolate) + static void LoadAll(v8::Isolate *isolate) { - for (auto& p : All()) + for (auto &p : All()) p.second->Load(isolate); } - void Load(v8::Isolate* isolate) + void Load(v8::Isolate *isolate) { if (loaded) return; @@ -94,12 +95,11 @@ class V8Class if (!parentName.empty()) { - V8Class* parentClass = Get(parentName); + V8Class *parentClass = Get(parentName); if (!parentClass) { - std::string msg = "[V8] Class '" + name - + "' attempted to inherit non-existant class '" + parentName + "'"; + std::string msg = "[V8] Class '" + name + "' attempted to inherit non-existant class '" + parentName + "'"; Log::Error << msg << Log::Endl; throw std::runtime_error(msg); @@ -109,7 +109,7 @@ class V8Class _tpl->Inherit(parentClass->tpl.Get(isolate)); } - + if (!tpl.IsEmpty()) { Log::Error << "Already loaded " << name << Log::Endl; @@ -118,7 +118,7 @@ class V8Class tpl.Reset(isolate, _tpl); } - void Register(v8::Isolate* isolate, v8::Local context, v8::Local exports) + void Register(v8::Isolate *isolate, v8::Local context, v8::Local exports) { exports->Set(context, v8::String::NewFromUtf8(isolate, name.c_str(), v8::NewStringType::kNormal).ToLocalChecked(), tpl.Get(isolate)->GetFunction(context).ToLocalChecked()); } diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 98114051..11215313 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -1,16 +1,15 @@ -#include "stdafx.h" #include "cpp-sdk/ICore.h" #include "V8ResourceImpl.h" #include "V8Helpers.h" -bool V8Helpers::TryCatch(const std::function& fn) +bool V8Helpers::TryCatch(const std::function &fn) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local context = isolate->GetEnteredContext(); v8::TryCatch tryCatch(isolate); - alt::IResource* resource = V8ResourceImpl::GetResource(context); + alt::IResource *resource = V8ResourceImpl::GetResource(context); if (!fn()) { @@ -26,7 +25,7 @@ bool V8Helpers::TryCatch(const std::function& fn) if (!origin.ResourceName()->IsUndefined()) { Log::Error << "[V8] Exception at " << resource->GetName() << ":" - << *v8::String::Utf8Value(isolate, origin.ResourceName()) << ":" << line.ToChecked() << Log::Endl; + << *v8::String::Utf8Value(isolate, origin.ResourceName()) << ":" << line.ToChecked() << Log::Endl; if (!maybeSourceLine.IsEmpty()) { @@ -38,7 +37,7 @@ bool V8Helpers::TryCatch(const std::function& fn) } else { - Log::Error << " " << std::string{ *v8::String::Utf8Value(isolate, sourceLine), 80 } << "..." << Log::Endl; + Log::Error << " " << std::string{*v8::String::Utf8Value(isolate, sourceLine), 80} << "..." << Log::Endl; } } } @@ -57,7 +56,7 @@ bool V8Helpers::TryCatch(const std::function& fn) else if (!exception.IsEmpty()) { Log::Error << "[V8] Exception: " - << *v8::String::Utf8Value(isolate, exception) << Log::Endl; + << *v8::String::Utf8Value(isolate, exception) << Log::Endl; } else { @@ -65,19 +64,18 @@ bool V8Helpers::TryCatch(const std::function& fn) } return false; - } return true; } -void V8Helpers::FunctionCallback(const v8::FunctionCallbackInfo& info) +void V8Helpers::FunctionCallback(const v8::FunctionCallbackInfo &info) { - auto fn = static_cast(info.Data().As()->Value()); + auto fn = static_cast(info.Data().As()->Value()); - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local ctx = isolate->GetEnteredContext(); - V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); + V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); Log::Debug << "FunctionCallback " << resource->GetResource()->GetName() << " " << V8ResourceImpl::Get(isolate->GetEnteredContext())->GetResource()->GetName() << Log::Endl; @@ -93,9 +91,9 @@ void V8Helpers::FunctionCallback(const v8::FunctionCallbackInfo& info alt::MValue V8Helpers::V8ToMValue(v8::Local val) { - auto& core = alt::ICore::Instance(); + auto &core = alt::ICore::Instance(); - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local ctx = isolate->GetEnteredContext(); if (val.IsEmpty()) @@ -145,11 +143,11 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) else if (val->IsArrayBuffer()) { v8::ArrayBuffer::Contents v8Buffer = val.As()->GetContents(); - return core.CreateMValueByteArray((uint8_t*)v8Buffer.Data(), v8Buffer.ByteLength()); + return core.CreateMValueByteArray((uint8_t *)v8Buffer.Data(), v8Buffer.ByteLength()); } else { - V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); + V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); v8::Local v8Obj = val.As(); //if (v8Obj->InstanceOf(ctx, v8Vector3->JSValue(isolate, ctx)).ToChecked()) @@ -163,9 +161,7 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) alt::Vector3f{ x->Value(), y->Value(), - z->Value() - } - ); + z->Value()}); } else if (resource->IsRGBA(v8Obj)) { @@ -179,13 +175,11 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) (uint8_t)r->Value(), (uint8_t)g->Value(), (uint8_t)b->Value(), - (uint8_t)a->Value() - } - ); + (uint8_t)a->Value()}); } else if (resource->IsBaseObject(v8Obj)) { - V8Entity* ent = V8Entity::Get(v8Obj); + V8Entity *ent = V8Entity::Get(v8Obj); Log::Debug << "Instanceof BaseObject" << Log::Endl; if (!ent) @@ -221,7 +215,7 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) v8::Local V8Helpers::MValueToV8(alt::MValueConst val) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local ctx = isolate->GetEnteredContext(); switch (val->GetType()) @@ -305,45 +299,50 @@ v8::Local V8Helpers::MValueToV8(alt::MValueConst val) return v8::Undefined(isolate); } -void V8::DefineOwnProperty(v8::Isolate* isolate, v8::Local ctx, v8::Local val, const char* name, v8::Local value, v8::PropertyAttribute attributes) +void V8::DefineOwnProperty(v8::Isolate *isolate, v8::Local ctx, v8::Local val, const char *name, v8::Local value, v8::PropertyAttribute attributes) { - val->DefineOwnProperty(ctx, v8::String::NewFromUtf8(isolate, name, - v8::NewStringType::kInternalized).ToLocalChecked(), value, attributes); + val->DefineOwnProperty(ctx, v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized).ToLocalChecked(), value, attributes); } -void V8::DefineOwnProperty(v8::Isolate* isolate, v8::Local ctx, v8::Local val, v8::Local name, v8::Local value, v8::PropertyAttribute attributes) +void V8::DefineOwnProperty(v8::Isolate *isolate, v8::Local ctx, v8::Local val, v8::Local name, v8::Local value, v8::PropertyAttribute attributes) { val->DefineOwnProperty(ctx, name, value, attributes); } -void V8::SetAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) +void V8::SetAccessor(v8::Isolate *isolate, v8::Local tpl, const char *name, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) { tpl->PrototypeTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, name, - v8::NewStringType::kInternalized).ToLocalChecked(), getter, setter, - v8::Local(), v8::AccessControl::DEFAULT, - setter != nullptr ? v8::PropertyAttribute::None : v8::PropertyAttribute::ReadOnly); + v8::NewStringType::kInternalized) + .ToLocalChecked(), + getter, setter, + v8::Local(), v8::AccessControl::DEFAULT, + setter != nullptr ? v8::PropertyAttribute::None : v8::PropertyAttribute::ReadOnly); } -void V8::SetMethod(v8::Isolate* isolate, v8::Local tpl, const char* name, v8::FunctionCallback callback) +void V8::SetMethod(v8::Isolate *isolate, v8::Local tpl, const char *name, v8::FunctionCallback callback) { tpl->PrototypeTemplate()->Set(isolate, name, v8::FunctionTemplate::New(isolate, callback)); } -void V8::SetStaticAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) +void V8::SetStaticAccessor(v8::Isolate *isolate, v8::Local tpl, const char *name, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) { tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, name, - v8::NewStringType::kInternalized).ToLocalChecked(), getter, setter); + v8::NewStringType::kInternalized) + .ToLocalChecked(), + getter, setter); } -void V8::SetStaticMethod(v8::Isolate* isolate, v8::Local tpl, const char* name, v8::FunctionCallback callback) +void V8::SetStaticMethod(v8::Isolate *isolate, v8::Local tpl, const char *name, v8::FunctionCallback callback) { tpl->Set(isolate, name, v8::FunctionTemplate::New(isolate, callback)); } -v8::Local V8::Get(v8::Local ctx, v8::Local obj, const char* name) +v8::Local V8::Get(v8::Local ctx, v8::Local obj, const char *name) { return obj->Get(ctx, v8::String::NewFromUtf8(ctx->GetIsolate(), name, - v8::NewStringType::kInternalized).ToLocalChecked()).ToLocalChecked(); + v8::NewStringType::kInternalized) + .ToLocalChecked()) + .ToLocalChecked(); } v8::Local V8::Get(v8::Local ctx, v8::Local obj, v8::Local name) @@ -351,7 +350,7 @@ v8::Local V8::Get(v8::Local ctx, v8::Local o return obj->Get(ctx, name).ToLocalChecked(); } -void V8::SetFunction(v8::Isolate* isolate, v8::Local ctx, v8::Local target, const char* name, v8::FunctionCallback cb, void* userData) +void V8::SetFunction(v8::Isolate *isolate, v8::Local ctx, v8::Local target, const char *name, v8::FunctionCallback cb, void *userData) { v8::Local _name = v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized).ToLocalChecked(); @@ -361,7 +360,7 @@ void V8::SetFunction(v8::Isolate* isolate, v8::Local ctx, v8::Local target->Set(ctx, _name, fn); } -v8::Local V8::New(v8::Isolate* isolate, v8::Local ctx, v8::Local constructor, std::vector>& args) +v8::Local V8::New(v8::Isolate *isolate, v8::Local ctx, v8::Local constructor, std::vector> &args) { v8::Local obj; @@ -378,7 +377,7 @@ v8::Local V8::New(v8::Isolate* isolate, v8::Local ctx, v return obj; } -V8::SourceLocation V8::SourceLocation::GetCurrent(v8::Isolate* isolate) +V8::SourceLocation V8::SourceLocation::GetCurrent(v8::Isolate *isolate) { v8::Local stackTrace = v8::StackTrace::CurrentStackTrace(isolate, 1); if (stackTrace->GetFrameCount() > 0) @@ -391,101 +390,109 @@ V8::SourceLocation V8::SourceLocation::GetCurrent(v8::Isolate* isolate) std::string fileName = *v8::String::Utf8Value(isolate, frame->GetScriptName()); int line = frame->GetLineNumber(); - return SourceLocation{ std::move(fileName), line }; + return SourceLocation{std::move(fileName), line}; } else if (frame->IsEval()) { - return SourceLocation{ "[eval]", 0 }; + return SourceLocation{"[eval]", 0}; } } - return SourceLocation{ "[unknown]", 0 }; + return SourceLocation{"[unknown]", 0}; } -V8::SourceLocation::SourceLocation(std::string&& _fileName, int _line) : - fileName(_fileName), line(_line) +V8::SourceLocation::SourceLocation(std::string &&_fileName, int _line) : fileName(_fileName), line(_line) { } -v8::Local V8::Vector3_XKey(v8::Isolate* isolate) +v8::Local V8::Vector3_XKey(v8::Isolate *isolate) { - static v8::Persistent xKey{ isolate, v8::String::NewFromUtf8(isolate, "x", - v8::NewStringType::kInternalized).ToLocalChecked() }; + static v8::Persistent xKey{isolate, v8::String::NewFromUtf8(isolate, "x", + v8::NewStringType::kInternalized) + .ToLocalChecked()}; return xKey.Get(isolate); } -v8::Local V8::Vector3_YKey(v8::Isolate* isolate) +v8::Local V8::Vector3_YKey(v8::Isolate *isolate) { - static v8::Persistent yKey{ isolate, v8::String::NewFromUtf8(isolate, "y", - v8::NewStringType::kInternalized).ToLocalChecked() }; + static v8::Persistent yKey{isolate, v8::String::NewFromUtf8(isolate, "y", + v8::NewStringType::kInternalized) + .ToLocalChecked()}; return yKey.Get(isolate); } -v8::Local V8::Vector3_ZKey(v8::Isolate* isolate) +v8::Local V8::Vector3_ZKey(v8::Isolate *isolate) { - static v8::Persistent zKey{ isolate, v8::String::NewFromUtf8(isolate, "z", - v8::NewStringType::kInternalized).ToLocalChecked() }; + static v8::Persistent zKey{isolate, v8::String::NewFromUtf8(isolate, "z", + v8::NewStringType::kInternalized) + .ToLocalChecked()}; return zKey.Get(isolate); } -v8::Local V8::RGBA_RKey(v8::Isolate* isolate) +v8::Local V8::RGBA_RKey(v8::Isolate *isolate) { - static v8::Persistent rKey{ isolate, v8::String::NewFromUtf8(isolate, "r", - v8::NewStringType::kInternalized).ToLocalChecked() }; + static v8::Persistent rKey{isolate, v8::String::NewFromUtf8(isolate, "r", + v8::NewStringType::kInternalized) + .ToLocalChecked()}; return rKey.Get(isolate); } -v8::Local V8::RGBA_GKey(v8::Isolate* isolate) +v8::Local V8::RGBA_GKey(v8::Isolate *isolate) { - static v8::Persistent gKey{ isolate, v8::String::NewFromUtf8(isolate, "g", - v8::NewStringType::kInternalized).ToLocalChecked() }; + static v8::Persistent gKey{isolate, v8::String::NewFromUtf8(isolate, "g", + v8::NewStringType::kInternalized) + .ToLocalChecked()}; return gKey.Get(isolate); } -v8::Local V8::RGBA_BKey(v8::Isolate* isolate) +v8::Local V8::RGBA_BKey(v8::Isolate *isolate) { - static v8::Persistent bKey{ isolate, v8::String::NewFromUtf8(isolate, "b", - v8::NewStringType::kInternalized).ToLocalChecked() }; + static v8::Persistent bKey{isolate, v8::String::NewFromUtf8(isolate, "b", + v8::NewStringType::kInternalized) + .ToLocalChecked()}; return bKey.Get(isolate); } -v8::Local V8::RGBA_AKey(v8::Isolate* isolate) +v8::Local V8::RGBA_AKey(v8::Isolate *isolate) { - static v8::Persistent aKey{ isolate, v8::String::NewFromUtf8(isolate, "a", - v8::NewStringType::kInternalized).ToLocalChecked() }; + static v8::Persistent aKey{isolate, v8::String::NewFromUtf8(isolate, "a", + v8::NewStringType::kInternalized) + .ToLocalChecked()}; return aKey.Get(isolate); } -v8::Local V8::Fire_PosKey(v8::Isolate* isolate) +v8::Local V8::Fire_PosKey(v8::Isolate *isolate) { - static v8::Persistent aKey{ isolate, v8::String::NewFromUtf8(isolate, "pos", - v8::NewStringType::kInternalized).ToLocalChecked() }; + static v8::Persistent aKey{isolate, v8::String::NewFromUtf8(isolate, "pos", + v8::NewStringType::kInternalized) + .ToLocalChecked()}; return aKey.Get(isolate); } -v8::Local V8::Fire_WeaponKey(v8::Isolate* isolate) +v8::Local V8::Fire_WeaponKey(v8::Isolate *isolate) { - static v8::Persistent aKey{ isolate, v8::String::NewFromUtf8(isolate, "weapon", - v8::NewStringType::kInternalized).ToLocalChecked() }; + static v8::Persistent aKey{isolate, v8::String::NewFromUtf8(isolate, "weapon", + v8::NewStringType::kInternalized) + .ToLocalChecked()}; return aKey.Get(isolate); } -bool V8::SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool& out) +bool V8::SafeToBoolean(v8::Local val, v8::Isolate *isolate, bool &out) { out = val->ToBoolean(isolate)->Value(); return true; } -bool V8::SafeToInteger(v8::Local val, v8::Local ctx, int64_t& out) +bool V8::SafeToInteger(v8::Local val, v8::Local ctx, int64_t &out) { v8::MaybeLocal maybeVal = val->ToInteger(ctx); if (!maybeVal.IsEmpty()) @@ -497,7 +504,7 @@ bool V8::SafeToInteger(v8::Local val, v8::Local ctx, int return false; } -bool V8::SafeToNumber(v8::Local val, v8::Local ctx, double& out) +bool V8::SafeToNumber(v8::Local val, v8::Local ctx, double &out) { v8::MaybeLocal maybeVal = val->ToNumber(ctx); if (!maybeVal.IsEmpty()) @@ -509,7 +516,7 @@ bool V8::SafeToNumber(v8::Local val, v8::Local ctx, doub return false; } -bool V8::SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String& out) +bool V8::SafeToString(v8::Local val, v8::Isolate *isolate, v8::Local ctx, alt::String &out) { v8::MaybeLocal maybeVal = val->ToString(ctx); if (!maybeVal.IsEmpty()) @@ -521,32 +528,32 @@ bool V8::SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local< return false; } -std::vector V8::EventHandler::GetCallbacks(V8ResourceImpl* impl, const alt::CEvent* e) +std::vector V8::EventHandler::GetCallbacks(V8ResourceImpl *impl, const alt::CEvent *e) { return callbacksGetter(impl, e); } -std::vector> V8::EventHandler::GetArgs(V8ResourceImpl* impl, const alt::CEvent* e) +std::vector> V8::EventHandler::GetArgs(V8ResourceImpl *impl, const alt::CEvent *e) { std::vector> args; argsGetter(impl, e, args); return args; } -V8::EventHandler* V8::EventHandler::Get(const alt::CEvent* e) +V8::EventHandler *V8::EventHandler::Get(const alt::CEvent *e) { - auto& _all = all(); + auto &_all = all(); auto it = _all.find(e->GetType()); - + return (it != _all.end()) ? it->second : nullptr; } -void V8::EventHandler::Register(alt::CEvent::Type type, EventHandler* handler) +void V8::EventHandler::Register(alt::CEvent::Type type, EventHandler *handler) { - auto& _all = all(); + auto &_all = all(); if (_all.count(type) == 0) { - _all.insert({ type, handler }); + _all.insert({type, handler}); } else { @@ -554,10 +561,9 @@ void V8::EventHandler::Register(alt::CEvent::Type type, EventHandler* handler) } } -V8::EventHandler::CallbacksGetter V8::LocalEventHandler::GetCallbacksGetter(const std::string& name) +V8::EventHandler::CallbacksGetter V8::LocalEventHandler::GetCallbacksGetter(const std::string &name) { - return [name](V8ResourceImpl* resource, const alt::CEvent*) -> std::vector - { + return [name](V8ResourceImpl *resource, const alt::CEvent *) -> std::vector { return resource->GetLocalHandlers(name); }; } diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 2569a96d..5b32f955 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -1,4 +1,3 @@ -#include "stdafx.h" #include "cpp-sdk/entities/IPlayer.h" #include "cpp-sdk/entities/IVehicle.h" @@ -21,18 +20,14 @@ bool V8ResourceImpl::Start() return true; } -#ifdef ALT_SERVER_API void V8ResourceImpl::OnTick() -#else -void V8ResourceImpl::Tick() -#endif { - for (auto& id : oldTimers) + for (auto &id : oldTimers) timers.erase(id); oldTimers.clear(); - for (auto& p : timers) + for (auto &p : timers) { int64_t time = GetTime(); @@ -41,19 +36,19 @@ void V8ResourceImpl::Tick() if (GetTime() - time > 10) { - auto& location = p.second->GetLocation(); + auto &location = p.second->GetLocation(); if (location.GetLineNumber() != 0) { Log::Warning << "Timer at " - << resource->GetName() << ":" << location.GetFileName() << ":" << location.GetLineNumber() - << " was too long " << GetTime() - time << "ms" << Log::Endl; + << resource->GetName() << ":" << location.GetFileName() << ":" << location.GetLineNumber() + << " was too long " << GetTime() - time << "ms" << Log::Endl; } else { Log::Warning << "Timer at " - << resource->GetName() << ":" << location.GetFileName() - << " was too long " << GetTime() - time << "ms" << Log::Endl; + << resource->GetName() << ":" << location.GetFileName() + << " was too long " << GetTime() - time << "ms" << Log::Endl; } } } @@ -77,13 +72,13 @@ void V8ResourceImpl::Tick() promiseRejections.ProcessQueue(this); } -void V8ResourceImpl::BindEntity(v8::Local val, alt::IBaseObject* handle) +void V8ResourceImpl::BindEntity(v8::Local val, alt::IBaseObject *handle) { - V8Entity* ent = new V8Entity(GetContext(), V8Entity::GetClass(handle), val, handle); - entities.insert({ handle, ent }); + V8Entity *ent = new V8Entity(GetContext(), V8Entity::GetClass(handle), val, handle); + entities.insert({handle, ent}); } -v8::Local V8ResourceImpl::GetBaseObjectOrNull(alt::IBaseObject* handle) +v8::Local V8ResourceImpl::GetBaseObjectOrNull(alt::IBaseObject *handle) { if (handle == nullptr) { @@ -100,8 +95,7 @@ v8::Local V8ResourceImpl::CreateVector3(alt::Vector3f vec) std::vector> args{ v8::Number::New(isolate, vec[0]), v8::Number::New(isolate, vec[1]), - v8::Number::New(isolate, vec[2]) - }; + v8::Number::New(isolate, vec[2])}; return V8::New(isolate, GetContext(), vector3Class.Get(isolate), args); } @@ -112,8 +106,7 @@ v8::Local V8ResourceImpl::CreateRGBA(alt::RGBA rgba) v8::Number::New(isolate, rgba.r), v8::Number::New(isolate, rgba.g), v8::Number::New(isolate, rgba.b), - v8::Number::New(isolate, rgba.a) - }; + v8::Number::New(isolate, rgba.a)}; return V8::New(isolate, GetContext(), rgbaClass.Get(isolate), args); } @@ -160,7 +153,7 @@ void V8ResourceImpl::OnRemoveBaseObject(alt::Ref handle) v8::Context::Scope scope(GetContext()); - V8Entity* ent = GetEntity(handle.Get()); + V8Entity *ent = GetEntity(handle.Get()); if (!ent) return; @@ -172,7 +165,7 @@ void V8ResourceImpl::OnRemoveBaseObject(alt::Ref handle) delete ent; } -void V8ResourceImpl::NotifyPoolUpdate(alt::IBaseObject* ent) +void V8ResourceImpl::NotifyPoolUpdate(alt::IBaseObject *ent) { switch (ent->GetType()) { @@ -223,9 +216,9 @@ v8::Local V8ResourceImpl::GetAllVehicles() return vehicles.Get(isolate); } -std::vector V8ResourceImpl::GetLocalHandlers(const std::string& name) +std::vector V8ResourceImpl::GetLocalHandlers(const std::string &name) { - std::vector handlers; + std::vector handlers; auto range = localHandlers.equal_range(name); for (auto it = range.first; it != range.second; ++it) @@ -234,9 +227,9 @@ std::vector V8ResourceImpl::GetLocalHandlers(const std::stri return handlers; } -std::vector V8ResourceImpl::GetRemoteHandlers(const std::string& name) +std::vector V8ResourceImpl::GetRemoteHandlers(const std::string &name) { - std::vector handlers; + std::vector handlers; auto range = remoteHandlers.equal_range(name); for (auto it = range.first; it != range.second; ++it) @@ -245,7 +238,7 @@ std::vector V8ResourceImpl::GetRemoteHandlers(const std::str return handlers; } -void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent* ev, const std::vector& handlers, std::vector>& args) +void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent *ev, const std::vector &handlers, std::vector> &args) { for (auto handler : handlers) { @@ -271,14 +264,14 @@ void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent* ev, const std::vecto if (handler->location.GetLineNumber() != 0) { Log::Warning << "Event handler at " - << resource->GetName() << ":" << handler->location.GetFileName() << ":" << handler->location.GetLineNumber() - << " was too long " << (GetTime() - time) << "ms" << Log::Endl; + << resource->GetName() << ":" << handler->location.GetFileName() << ":" << handler->location.GetLineNumber() + << " was too long " << (GetTime() - time) << "ms" << Log::Endl; } else { Log::Warning << "Event handler at " - << resource->GetName() << ":" << handler->location.GetFileName() - << " was too long " << (GetTime() - time) << "ms" << Log::Endl; + << resource->GetName() << ":" << handler->location.GetFileName() + << " was too long " << (GetTime() - time) << "ms" << Log::Endl; } } } @@ -286,7 +279,7 @@ void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent* ev, const std::vecto alt::MValue V8ResourceImpl::FunctionImpl::Call(alt::MValueArgs args) const { - v8::Isolate* isolate = resource->GetIsolate(); + v8::Isolate *isolate = resource->GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); @@ -296,7 +289,7 @@ alt::MValue V8ResourceImpl::FunctionImpl::Call(alt::MValueArgs args) const v8::Context::Scope scope(ctx); #ifdef ALT_SERVER_API - CNodeResourceImpl* nodeRes = static_cast(resource); + CNodeResourceImpl *nodeRes = static_cast(resource); node::CallbackScope callbackScope(isolate, nodeRes->GetAsyncResource(), nodeRes->GetAsyncContext()); #endif // ALT_SERVER_API @@ -312,7 +305,7 @@ alt::MValue V8ResourceImpl::FunctionImpl::Call(alt::MValueArgs args) const res = V8Helpers::V8ToMValue(_res.ToLocalChecked()); return true; - }); + }); if (res.IsEmpty()) res = alt::ICore::Instance().CreateMValueNone(); diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index d8e0372d..f8d2565a 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -17,57 +17,49 @@ class V8ResourceImpl : public alt::IResource::Impl class FunctionImpl : public alt::IMValueFunction::Impl { public: - FunctionImpl(V8ResourceImpl* _resource, v8::Local fn) : - resource(_resource), - function(_resource->GetIsolate(), fn) + FunctionImpl(V8ResourceImpl *_resource, v8::Local fn) : resource(_resource), + function(_resource->GetIsolate(), fn) { - } alt::MValue Call(alt::MValueArgs args) const override; private: - V8ResourceImpl* resource; + V8ResourceImpl *resource; v8::UniquePersistent function; }; - V8ResourceImpl(v8::Isolate* _isolate, alt::IResource* _resource) : - isolate(_isolate), - resource(_resource) + V8ResourceImpl(v8::Isolate *_isolate, alt::IResource *_resource) : isolate(_isolate), + resource(_resource) { - } struct PathInfo { - alt::IPackage* pkg = nullptr; + alt::IPackage *pkg = nullptr; std::string fileName; std::string prefix; }; bool Start() override; -#ifdef ALT_SERVER_API void OnTick() override; -#else - void Tick(); -#endif - inline alt::IResource* GetResource() { return resource; } - inline v8::Isolate* GetIsolate() { return isolate; } + inline alt::IResource *GetResource() { return resource; } + inline v8::Isolate *GetIsolate() { return isolate; } inline v8::Local GetContext() { return context.Get(isolate); } - void SubscribeLocal(const std::string& ev, v8::Local cb, V8::SourceLocation&& location) + void SubscribeLocal(const std::string &ev, v8::Local cb, V8::SourceLocation &&location) { - localHandlers.insert({ ev, V8::EventCallback{ isolate, cb, std::move(location) } }); + localHandlers.insert({ev, V8::EventCallback{isolate, cb, std::move(location)}}); } - void SubscribeRemote(const std::string& ev, v8::Local cb, V8::SourceLocation&& location) + void SubscribeRemote(const std::string &ev, v8::Local cb, V8::SourceLocation &&location) { - remoteHandlers.insert({ ev, V8::EventCallback{ isolate, cb, std::move(location) } }); + remoteHandlers.insert({ev, V8::EventCallback{isolate, cb, std::move(location)}}); } - void UnsubscribeLocal(const std::string& ev, v8::Local cb) + void UnsubscribeLocal(const std::string &ev, v8::Local cb) { auto range = localHandlers.equal_range(ev); @@ -78,7 +70,7 @@ class V8ResourceImpl : public alt::IResource::Impl } } - void UnsubscribeRemote(const std::string& ev, v8::Local cb) + void UnsubscribeRemote(const std::string &ev, v8::Local cb) { auto range = remoteHandlers.equal_range(ev); @@ -103,7 +95,7 @@ class V8ResourceImpl : public alt::IResource::Impl InvokeEventHandlers(nullptr, GetLocalHandlers("resourceStop"), args); } - V8Entity* GetEntity(alt::IBaseObject* handle) + V8Entity *GetEntity(alt::IBaseObject *handle) { auto it = entities.find(handle); @@ -113,23 +105,23 @@ class V8ResourceImpl : public alt::IResource::Impl return it->second; } - V8Entity* CreateEntity(alt::IBaseObject* handle) + V8Entity *CreateEntity(alt::IBaseObject *handle) { - V8Class* _class = V8Entity::GetClass(handle); + V8Class *_class = V8Entity::GetClass(handle); - V8Entity* ent = new V8Entity(GetContext(), _class, _class->CreateInstance(GetContext()), handle); - entities.insert({ handle, ent }); + V8Entity *ent = new V8Entity(GetContext(), _class, _class->CreateInstance(GetContext()), handle); + entities.insert({handle, ent}); return ent; } - void BindEntity(v8::Local val, alt::IBaseObject* handle); + void BindEntity(v8::Local val, alt::IBaseObject *handle); - V8Entity* GetOrCreateEntity(alt::IBaseObject* handle, const char* className = "") + V8Entity *GetOrCreateEntity(alt::IBaseObject *handle, const char *className = "") { if (!handle) Log::Error << __FUNCTION__ << " received invalid handle please contact developers if you see this" << Log::Endl; - V8Entity* ent = GetEntity(handle); + V8Entity *ent = GetEntity(handle); if (!ent) ent = CreateEntity(handle); @@ -137,10 +129,10 @@ class V8ResourceImpl : public alt::IResource::Impl return ent; } - v8::Local GetBaseObjectOrNull(alt::IBaseObject* handle); + v8::Local GetBaseObjectOrNull(alt::IBaseObject *handle); - template - v8::Local GetBaseObjectOrNull(const alt::Ref& handle) + template + v8::Local GetBaseObjectOrNull(const alt::Ref &handle) { return GetBaseObjectOrNull(handle.Get()); } @@ -157,15 +149,15 @@ class V8ResourceImpl : public alt::IResource::Impl alt::MValue GetFunction(v8::Local val) { - FunctionImpl* impl = new FunctionImpl{ this, val.As() }; + FunctionImpl *impl = new FunctionImpl{this, val.As()}; return alt::ICore::Instance().CreateMValueFunction(impl); } - uint32_t CreateTimer(v8::Local context, v8::Local callback, uint32_t interval, bool once, V8::SourceLocation&& location) + uint32_t CreateTimer(v8::Local context, v8::Local callback, uint32_t interval, bool once, V8::SourceLocation &&location) { uint32_t id = nextTimerId++; //Log::Debug << "Create timer " << id << Log::Endl; - timers[id] = new V8Timer{ isolate, context, GetTime(), callback, interval, once, std::move(location) }; + timers[id] = new V8Timer{isolate, context, GetTime(), callback, interval, once, std::move(location)}; return id; } @@ -180,97 +172,35 @@ class V8ResourceImpl : public alt::IResource::Impl return timers.size(); } - PathInfo Resolve(const std::string& path, const std::string& currentModulePath) - { - PathInfo pathInfo; - - if (path.size() > 1 && path.at(0) == '@') - { - std::string packName; - size_t slash = path.find_first_of('/'); - - if (slash == std::string::npos) - { - packName = path.substr(1); - pathInfo.fileName = ""; - } - else - { - packName = path.substr(1, slash - 1); - pathInfo.fileName = path.substr(slash + 1); - } - - pathInfo.prefix = "@" + packName + "/"; - -#ifndef ALT_CLIENT_API - // pathInfo.pkg = ICore::Instance().GetAssetPack(packName); -#else - auto& resourceManager = CGame::Instance().GetResourceManager(); - auto& assetManager = resourceManager.GetAssetManager(); - pathInfo.pkg = assetManager.GetAssetPack(packName); -#endif - } - else - { - if ((path.size() >= 2 && path[0] == '.' && path[1] == '/') || - (path.size() >= 3 && path[0] == '.' && path[1] == '.' && path[2] == '/')) - { - std::filesystem::path modulePath(currentModulePath); - std::filesystem::path cwd(""); - if (modulePath.has_parent_path()) - cwd = modulePath.parent_path(); - - cwd.append(path); - std::filesystem::path targetFilePath = cwd.lexically_normal(); - - pathInfo.fileName = targetFilePath.generic_u8string(); - } - else if (path.size() > 0 && path[0] == '/') - { - pathInfo.fileName = path.substr(1); - } - else - { - Log::Warning << "Full paths without / in the beginning are deprecated. Consider starting your paths with /" << Log::Endl; - pathInfo.fileName = path; - } - - pathInfo.prefix = ""; - pathInfo.pkg = resource->GetPackage(); - } - - return pathInfo; - } - - void NotifyPoolUpdate(alt::IBaseObject* ent); + void NotifyPoolUpdate(alt::IBaseObject *ent); v8::Local GetAllPlayers(); v8::Local GetAllVehicles(); - std::vector GetLocalHandlers(const std::string& name); - std::vector GetRemoteHandlers(const std::string& name); + std::vector GetLocalHandlers(const std::string &name); + std::vector GetRemoteHandlers(const std::string &name); - static V8ResourceImpl* Get(v8::Local ctx) + static V8ResourceImpl *Get(v8::Local ctx) { - alt::IResource* resource = GetResource(ctx); + alt::IResource *resource = GetResource(ctx); return resource - ? static_cast(resource->GetImpl()) - : nullptr; + ? static_cast(resource->GetImpl()) + : nullptr; } - static alt::IResource* GetResource(v8::Local ctx) + static alt::IResource *GetResource(v8::Local ctx) { - return static_cast(ctx->GetAlignedPointerFromEmbedderData(1)); + return static_cast(ctx->GetAlignedPointerFromEmbedderData(1)); } protected: - v8::Isolate* isolate; - alt::IResource* resource; + v8::Isolate *isolate; + alt::IResource *resource; v8::Persistent context; - std::unordered_map entities; - std::unordered_map timers; + std::unordered_map entities; + std::unordered_map timers; std::unordered_multimap localHandlers; std::unordered_multimap remoteHandlers; @@ -294,8 +224,9 @@ class V8ResourceImpl : public alt::IResource::Impl static int64_t GetTime() { return std::chrono::duration_cast( - std::chrono::steady_clock::now().time_since_epoch()).count(); + std::chrono::steady_clock::now().time_since_epoch()) + .count(); } - void InvokeEventHandlers(const alt::CEvent* ev, const std::vector& handlers, std::vector>& args); + void InvokeEventHandlers(const alt::CEvent *ev, const std::vector &handlers, std::vector> &args); }; diff --git a/bindings/BaseObject.cpp b/bindings/BaseObject.cpp index 1b486d32..0af04d45 100644 --- a/bindings/BaseObject.cpp +++ b/bindings/BaseObject.cpp @@ -1,18 +1,17 @@ -#include "stdafx.h" #include "../V8Helpers.h" #include "../V8ResourceImpl.h" #include "../V8Class.h" #include "../V8Entity.h" -static void TypeGetter(v8::Local, const v8::PropertyCallbackInfo& info) +static void TypeGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref obj = _this->GetHandle(); @@ -21,28 +20,28 @@ static void TypeGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) +static void ValidGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); info.GetReturnValue().Set(v8::Boolean::New(isolate, _this != nullptr)); } -static void HasMeta(const v8::FunctionCallbackInfo& info) +static void HasMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 1, "1 arg expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref obj = _this->GetHandle(); @@ -51,17 +50,17 @@ static void HasMeta(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(v8::Boolean::New(isolate, obj->HasMetaData(*v8::String::Utf8Value(isolate, key)))); } -static void GetMeta(const v8::FunctionCallbackInfo& info) +static void GetMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 1, "1 arg expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref obj = _this->GetHandle(); @@ -72,17 +71,17 @@ static void GetMeta(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); } -static void SetMeta(const v8::FunctionCallbackInfo& info) +static void SetMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 2, "2 args expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref obj = _this->GetHandle(); @@ -93,17 +92,17 @@ static void SetMeta(const v8::FunctionCallbackInfo& info) obj->SetMetaData(*v8::String::Utf8Value(isolate, key), V8Helpers::V8ToMValue(value)); } -static void DeleteMeta(const v8::FunctionCallbackInfo& info) +static void DeleteMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 1, "1 arg expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref obj = _this->GetHandle(); @@ -113,25 +112,21 @@ static void DeleteMeta(const v8::FunctionCallbackInfo& info) obj->DeleteMetaData(*v8::String::Utf8Value(isolate, key)); } -static void Destroy(const v8::FunctionCallbackInfo& info) +static void Destroy(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); -#ifdef ALT_SERVER_API alt::ICore::Instance().DestroyBaseObject(_this->GetHandle()); -#else - CGame::Instance().DestroyBaseObject(_this->GetHandle()); -#endif // ALT_SERVER_API } static V8Class v8baseObject("BaseObject", "", nullptr, [](v8::Local tpl) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetAccessor(isolate, tpl, "type", &TypeGetter); V8::SetAccessor(isolate, tpl, "valid", &ValidGetter); diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index d25b35ce..89fb981a 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -1,4 +1,3 @@ -#include "stdafx.h" #include "../V8Helpers.h" #include "../V8ResourceImpl.h" @@ -8,14 +7,14 @@ using namespace alt; -static void IDGetter(v8::Local, const v8::PropertyCallbackInfo& info) +static void IDGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); Ref ent = _this->GetHandle().As(); @@ -23,21 +22,21 @@ static void IDGetter(v8::Local, const v8::PropertyCallbackInfoGetID())); } -static void OwnerGetter(v8::Local, const v8::PropertyCallbackInfo& info) +static void OwnerGetter(v8::Local, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_GET_THIS_BASE_OBJECT(_this, IEntity); V8_RETURN_BASE_OBJECT(_this->GetNetworkOwner()); } -static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo& info) +static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); Ref ent = _this->GetHandle().As(); @@ -46,14 +45,14 @@ static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo info.GetReturnValue().Set(resource->CreateVector3(_pos)); } -static void DimensionGetter(v8::Local, const v8::PropertyCallbackInfo& info) +static void DimensionGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); Ref ent = _this->GetHandle().As(); @@ -61,14 +60,14 @@ static void DimensionGetter(v8::Local, const v8::PropertyCallbackInf info.GetReturnValue().Set(v8::Integer::New(isolate, ent->GetDimension())); } -static void RotationGetter(v8::Local, const v8::PropertyCallbackInfo& info) +static void RotationGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref ent = _this->GetHandle().As(); @@ -77,31 +76,31 @@ static void RotationGetter(v8::Local, const v8::PropertyCallbackInfo info.GetReturnValue().Set(resource->CreateVector3(_rot)); } -static void ModelGetter(v8::Local, const v8::PropertyCallbackInfo& info) +static void ModelGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref ent = _this->GetHandle().As(); info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, ent->GetModel())); } -static void HasSyncedMeta(const v8::FunctionCallbackInfo& info) +static void HasSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 1, "1 arg expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref ent = _this->GetHandle().As(); @@ -110,17 +109,17 @@ static void HasSyncedMeta(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(v8::Boolean::New(isolate, ent->HasSyncedMetaData(*v8::String::Utf8Value(isolate, key)))); } -static void GetSyncedMeta(const v8::FunctionCallbackInfo& info) +static void GetSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 1, "1 arg expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref ent = _this->GetHandle().As(); @@ -131,17 +130,17 @@ static void GetSyncedMeta(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); } -static void HasStreamSyncedMeta(const v8::FunctionCallbackInfo& info) +static void HasStreamSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 1, "1 arg expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); + V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref ent = _this->GetHandle().As(); @@ -150,17 +149,17 @@ static void HasStreamSyncedMeta(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(v8::Boolean::New(isolate, ent->HasStreamSyncedMetaData(*v8::String::Utf8Value(isolate, key)))); } -static void GetStreamSyncedMeta(const v8::FunctionCallbackInfo& info) +static void GetStreamSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 1, "1 arg expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref ent = _this->GetHandle().As(); @@ -173,16 +172,16 @@ static void GetStreamSyncedMeta(const v8::FunctionCallbackInfo& info) #ifdef ALT_SERVER_API -static void RotationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +static void RotationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); V8_CHECK(val->IsObject(), "object expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref obj = _this->GetHandle().As(); @@ -193,19 +192,19 @@ static void RotationSetter(v8::Local, v8::Local val, cons v8::Local y = pos->Get(v8::String::NewFromUtf8(isolate, "y"))->ToNumber(isolate); v8::Local z = pos->Get(v8::String::NewFromUtf8(isolate, "z"))->ToNumber(isolate); - obj->SetRotation({ float(x->Value()), float(y->Value()), float(z->Value()) }); + obj->SetRotation({float(x->Value()), float(y->Value()), float(z->Value())}); } -static void ModelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +static void ModelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); V8_CHECK(val->IsNumber() || val->IsString(), "model can be number or string"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref player = _this->GetHandle().As(); @@ -217,21 +216,21 @@ static void ModelSetter(v8::Local, v8::Local val, const v } else { - v8::String::Utf8Value strVal{ isolate, val }; + v8::String::Utf8Value strVal{isolate, val}; player->SetModel(alt::ICore::Instance().Hash(*strVal)); } } -static void SetSyncedMeta(const v8::FunctionCallbackInfo& info) +static void SetSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); V8_CHECK(info.Length() == 2, "2 args expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref ent = _this->GetHandle().As(); @@ -241,16 +240,16 @@ static void SetSyncedMeta(const v8::FunctionCallbackInfo& info) ent->SetSyncedMetaData(*v8::String::Utf8Value(isolate, key), V8Helpers::V8ToMValue(info[1])); } -static void DeleteSyncedMeta(const v8::FunctionCallbackInfo& info) +static void DeleteSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); V8_CHECK(info.Length() == 1, "1 arg expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref ent = _this->GetHandle().As(); @@ -259,16 +258,16 @@ static void DeleteSyncedMeta(const v8::FunctionCallbackInfo& info) ent->DeleteSyncedMetaData(*v8::String::Utf8Value(isolate, key)); } -static void SetStreamSyncedMeta(const v8::FunctionCallbackInfo& info) +static void SetStreamSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); V8_CHECK(info.Length() == 2, "2 args expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref ent = _this->GetHandle().As(); @@ -278,16 +277,16 @@ static void SetStreamSyncedMeta(const v8::FunctionCallbackInfo& info) ent->SetStreamSyncedMetaData(*v8::String::Utf8Value(isolate, key), V8Helpers::V8ToMValue(info[1])); } -static void DeleteStreamSyncedMeta(const v8::FunctionCallbackInfo& info) +static void DeleteStreamSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); V8_CHECK(info.Length() == 1, "1 arg expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); alt::Ref ent = _this->GetHandle().As(); @@ -296,7 +295,7 @@ static void DeleteStreamSyncedMeta(const v8::FunctionCallbackInfo& in ent->DeleteStreamSyncedMetaData(*v8::String::Utf8Value(isolate, key)); } -static void SetNetOwner(const v8::FunctionCallbackInfo& info) +static void SetNetOwner(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN2(1, 2); @@ -307,7 +306,7 @@ static void SetNetOwner(const v8::FunctionCallbackInfo& info) _this->SetNetworkOwner(player, disableMigration); } -static void ResetNetOwner(const v8::FunctionCallbackInfo& info) +static void ResetNetOwner(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN2(0, 1); @@ -321,14 +320,14 @@ static void ResetNetOwner(const v8::FunctionCallbackInfo& info) #ifdef ALT_CLIENT_API -static void ScriptIDGetter(v8::Local, const v8::PropertyCallbackInfo& info) +static void ScriptIDGetter(v8::Local, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(_this, IEntity); V8_RETURN_INTEGER(_this->GetScriptGuid()); } -static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) +static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); @@ -338,7 +337,7 @@ static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) #endif // ALT_CLIENT_API -static void StaticGetByID(const v8::FunctionCallbackInfo& info) +static void StaticGetByID(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); @@ -347,7 +346,7 @@ static void StaticGetByID(const v8::FunctionCallbackInfo& info) } static V8Class v8entity("Entity", "WorldObject", nullptr, [](v8::Local tpl) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); diff --git a/bindings/File.cpp b/bindings/File.cpp index 9390d0b2..2a5e337d 100644 --- a/bindings/File.cpp +++ b/bindings/File.cpp @@ -1,23 +1,22 @@ -#include "stdafx.h" #include "../V8Helpers.h" #include "../V8ResourceImpl.h" #include "../V8Class.h" -static void StaticExists(const v8::FunctionCallbackInfo& info) +static void StaticExists(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8_CHECK(info.Length() == 1, "1 arg expected"); V8_CHECK(info[0]->IsString(), "fileName must be a string"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); V8_CHECK(resource, "Invalid resource"); std::string _path = *v8::String::Utf8Value(isolate, info[0].As()); #ifdef ALT_CLIENT - V8ResourceImpl::PathInfo path = resource->Resolve(_path, ""); + auto path = alt::ICore::Instance().Resolve(resource, _path, ""); V8_CHECK(path.pkg, "invalid asset pack"); bool exists = path.pkg->FileExists(path.fileName); #else @@ -27,14 +26,14 @@ static void StaticExists(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(v8::Boolean::New(isolate, exists)); } -static void StaticRead(const v8::FunctionCallbackInfo& info) +static void StaticRead(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8_CHECK(info.Length() >= 1, "at least 1 arg expected"); V8_CHECK(info[0]->IsString(), "fileName must be a string"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); std::string name = *v8::String::Utf8Value(isolate, info[0].As()); @@ -48,10 +47,10 @@ static void StaticRead(const v8::FunctionCallbackInfo& info) } #ifdef ALT_CLIENT - V8ResourceImpl::PathInfo path = resource->Resolve(name, ""); + auto path = alt::ICore::Instance().Resolve(resource, name, ""); V8_CHECK(path.pkg, "invalid asset pack"); - alt::IPackage::File* file = path.pkg->OpenFile(path.fileName); + alt::IPackage::File *file = path.pkg->OpenFile(path.fileName); V8_CHECK(file, "file does not exist"); alt::String data(path.pkg->GetFileSize(file)); @@ -67,7 +66,7 @@ static void StaticRead(const v8::FunctionCallbackInfo& info) } else if (encoding == "utf-16") { - info.GetReturnValue().Set(v8::String::NewFromTwoByte(isolate, (uint16_t*)data.GetData(), v8::NewStringType::kNormal, data.GetSize() / 2).ToLocalChecked()); + info.GetReturnValue().Set(v8::String::NewFromTwoByte(isolate, (uint16_t *)data.GetData(), v8::NewStringType::kNormal, data.GetSize() / 2).ToLocalChecked()); } else if (encoding == "binary") { @@ -81,7 +80,7 @@ static void StaticRead(const v8::FunctionCallbackInfo& info) } static V8Class v8File("File", "", nullptr, [](v8::Local tpl) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetStaticMethod(isolate, tpl, "exists", StaticExists); V8::SetStaticMethod(isolate, tpl, "read", StaticRead); diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 360bf352..e896ab87 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -1,11 +1,10 @@ -#include "stdafx.h" #include "../V8Helpers.h" #include "../V8ResourceImpl.h" -static void HashCb(const v8::FunctionCallbackInfo& info) +static void HashCb(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); V8_CHECK(info.Length() == 1, "1 arg expected"); V8_CHECK(info[0]->IsString(), "string expected"); @@ -16,16 +15,16 @@ static void HashCb(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(info.GetIsolate(), hash)); } -static void On(const v8::FunctionCallbackInfo& info) +static void On(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 2, "on expects 2 args"); V8_CHECK(info[0]->IsString(), "eventName must be a string"); V8_CHECK(info[1]->IsFunction(), "callback must be a function"); - V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); + V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); V8_CHECK(resource, "Invalid resource"); std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); @@ -34,15 +33,15 @@ static void On(const v8::FunctionCallbackInfo& info) resource->SubscribeLocal(evName, callback, V8::SourceLocation::GetCurrent(isolate)); } -static void Off(const v8::FunctionCallbackInfo& info) +static void Off(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); V8_CHECK(info.Length() == 2, "on expects 2 args"); V8_CHECK(info[0]->IsString(), "eventName must be a string"); V8_CHECK(info[1]->IsFunction(), "callback must be a function"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "Invalid resource"); std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); @@ -51,9 +50,9 @@ static void Off(const v8::FunctionCallbackInfo& info) resource->UnsubscribeLocal(evName, callback); } -static void Emit(const v8::FunctionCallbackInfo& info) +static void Emit(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); V8_CHECK(info.Length() >= 1, "emitClient expects at least 1 arg"); V8_CHECK(info[0]->IsString(), "eventName must be a string"); @@ -67,10 +66,9 @@ static void Emit(const v8::FunctionCallbackInfo& info) alt::ICore::Instance().TriggerLocalEvent(name, args); } - -static void HasMeta(const v8::FunctionCallbackInfo& info) +static void HasMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 1, "1 arg expected"); @@ -79,9 +77,9 @@ static void HasMeta(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(v8::Boolean::New(isolate, alt::ICore::Instance().HasMetaData(*v8::String::Utf8Value(isolate, key)))); } -static void GetMeta(const v8::FunctionCallbackInfo& info) +static void GetMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 1, "1 arg expected"); @@ -92,9 +90,9 @@ static void GetMeta(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); } -static void SetMeta(const v8::FunctionCallbackInfo& info) +static void SetMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 2, "2 args expected"); @@ -105,9 +103,9 @@ static void SetMeta(const v8::FunctionCallbackInfo& info) alt::ICore::Instance().SetMetaData(*v8::String::Utf8Value(isolate, key), V8Helpers::V8ToMValue(value)); } -static void DeleteMeta(const v8::FunctionCallbackInfo& info) +static void DeleteMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 1, "1 arg expected"); @@ -116,9 +114,9 @@ static void DeleteMeta(const v8::FunctionCallbackInfo& info) alt::ICore::Instance().DeleteMetaData(*v8::String::Utf8Value(isolate, key)); } -static void HasSyncedMeta(const v8::FunctionCallbackInfo& info) +static void HasSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 1, "1 arg expected"); @@ -127,9 +125,9 @@ static void HasSyncedMeta(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(v8::Boolean::New(isolate, alt::ICore::Instance().HasSyncedMetaData(*v8::String::Utf8Value(isolate, key)))); } -static void GetSyncedMeta(const v8::FunctionCallbackInfo& info) +static void GetSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(info.Length() == 1, "1 arg expected"); @@ -140,9 +138,9 @@ static void GetSyncedMeta(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); } -static void Log(const v8::FunctionCallbackInfo& info) +static void Log(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); std::stringstream ss; @@ -160,9 +158,9 @@ static void Log(const v8::FunctionCallbackInfo& info) alt::ICore::Instance().LogColored(ss.str()); } -static void LogWarning(const v8::FunctionCallbackInfo& info) +static void LogWarning(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); std::stringstream ss; @@ -180,9 +178,9 @@ static void LogWarning(const v8::FunctionCallbackInfo& info) alt::ICore::Instance().LogWarning(ss.str()); } -static void LogError(const v8::FunctionCallbackInfo& info) +static void LogError(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); std::stringstream ss; @@ -200,15 +198,15 @@ static void LogError(const v8::FunctionCallbackInfo& info) alt::ICore::Instance().LogError(ss.str()); } -static void SetTimeout(const v8::FunctionCallbackInfo& info) +static void SetTimeout(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8_CHECK(info.Length() == 2, "2 args expected"); V8_CHECK(info[0]->IsFunction(), "function expected"); V8_CHECK(info[1]->IsNumber(), "number expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "Invalid resource"); v8::Local ctx = isolate->GetEnteredContext(); @@ -221,15 +219,15 @@ static void SetTimeout(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, id)); } -static void SetInterval(const v8::FunctionCallbackInfo& info) +static void SetInterval(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8_CHECK(info.Length() == 2, "2 args expected"); V8_CHECK(info[0]->IsFunction(), "function expected"); V8_CHECK(info[1]->IsNumber(), "number expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "Invalid resource"); v8::Local ctx = isolate->GetEnteredContext(); @@ -242,14 +240,14 @@ static void SetInterval(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, id)); } -static void NextTick(const v8::FunctionCallbackInfo& info) +static void NextTick(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8_CHECK(info.Length() == 1, "1 arg expected"); V8_CHECK(info[0]->IsFunction(), "function expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "Invalid resource"); v8::Local ctx = isolate->GetEnteredContext(); @@ -261,14 +259,14 @@ static void NextTick(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, id)); } -static void EveryTick(const v8::FunctionCallbackInfo& info) +static void EveryTick(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8_CHECK(info.Length() == 1, "1 arg expected"); V8_CHECK(info[0]->IsFunction(), "function expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "Invalid resource"); v8::Local ctx = isolate->GetEnteredContext(); @@ -280,14 +278,14 @@ static void EveryTick(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, id)); } -static void ClearTimer(const v8::FunctionCallbackInfo& info) +static void ClearTimer(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8_CHECK(info.Length() == 1, "1 arg expected"); V8_CHECK(info[0]->IsNumber(), "number expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "Invalid resource"); v8::Local ctx = isolate->GetEnteredContext(); @@ -299,7 +297,7 @@ static void ClearTimer(const v8::FunctionCallbackInfo& info) void V8::RegisterSharedMain(v8::Local ctx, v8::Local exports) { - v8::Isolate* isolate = ctx->GetIsolate(); + v8::Isolate *isolate = ctx->GetIsolate(); V8Helpers::RegisterFunc(exports, "hash", &HashCb); @@ -333,7 +331,7 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8::DefineOwnProperty(isolate, ctx, exports, "GlobalDimension", v8::Integer::New(isolate, alt::GLOBAL_DIMENSION)); #ifdef ALT_CLIENT - V8::DefineOwnProperty(isolate, ctx, exports, "Version", v8::String::NewFromUtf8(isolate, ALTV_VERSION).ToLocalChecked()); - V8::DefineOwnProperty(isolate, ctx, exports, "Branch", v8::String::NewFromUtf8(isolate, ALTV_BRANCH).ToLocalChecked()); + V8::DefineOwnProperty(isolate, ctx, exports, "Version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); + V8::DefineOwnProperty(isolate, ctx, exports, "Branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); #endif } diff --git a/bindings/RGBA.cpp b/bindings/RGBA.cpp index 6e175afe..083c6dbb 100644 --- a/bindings/RGBA.cpp +++ b/bindings/RGBA.cpp @@ -1,12 +1,11 @@ -#include "stdafx.h" #include "../V8Class.h" #include "../V8Helpers.h" #include "../V8ResourceImpl.h" -static void ToString(const v8::FunctionCallbackInfo& info) +static void ToString(const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); v8::Local r = info.This()->Get(ctx, V8::RGBA_RKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); @@ -20,7 +19,8 @@ static void ToString(const v8::FunctionCallbackInfo& info) info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, ss.str().c_str(), v8::NewStringType::kNormal).ToLocalChecked()); } -static V8Class v8RGBA("RGBA", "", [](const v8::FunctionCallbackInfo& info) { +static V8Class v8RGBA( + "RGBA", "", [](const v8::FunctionCallbackInfo &info) { v8::Isolate* isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); @@ -36,9 +36,7 @@ static V8Class v8RGBA("RGBA", "", [](const v8::FunctionCallbackInfo& V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_RKey(isolate), r, v8::PropertyAttribute::ReadOnly); V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_GKey(isolate), g, v8::PropertyAttribute::ReadOnly); V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_BKey(isolate), b, v8::PropertyAttribute::ReadOnly); - V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_AKey(isolate), a, v8::PropertyAttribute::ReadOnly); -}, [](v8::Local tpl) { + V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_AKey(isolate), a, v8::PropertyAttribute::ReadOnly); }, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); - V8::SetMethod(isolate, tpl, "toString", ToString); -}, false); + V8::SetMethod(isolate, tpl, "toString", ToString); }, false); diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index 045f6fe2..af673db1 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -1,4 +1,3 @@ -#include "stdafx.h" #include @@ -6,7 +5,7 @@ #include "../V8Helpers.h" #include "../V8ResourceImpl.h" -static void ToString(const v8::FunctionCallbackInfo& info) +static void ToString(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); @@ -18,12 +17,12 @@ static void ToString(const v8::FunctionCallbackInfo& info) std::ostringstream ss; ss << std::fixed << std::setprecision(4) - << "Vector3{ x: " << x << ", y: " << y << ", z: " << z << " }"; + << "Vector3{ x: " << x << ", y: " << y << ", z: " << z << " }"; V8_RETURN_STRING(ss.str().c_str()); } -static void Constructor(const v8::FunctionCallbackInfo& info) +static void Constructor(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); @@ -85,8 +84,10 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8::DefineOwnProperty(isolate, ctx, _this, V8::Vector3_ZKey(isolate), z, v8::PropertyAttribute::ReadOnly); } -static V8Class v8Vector3("Vector3", "", Constructor, [](v8::Local tpl) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); +static V8Class v8Vector3( + "Vector3", "", Constructor, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); - V8::SetMethod(isolate, tpl, "toString", ToString); -}, false); + V8::SetMethod(isolate, tpl, "toString", ToString); + }, + false); diff --git a/bindings/WorldObject.cpp b/bindings/WorldObject.cpp index 44ff3878..8674d2d7 100644 --- a/bindings/WorldObject.cpp +++ b/bindings/WorldObject.cpp @@ -1,4 +1,3 @@ -#include "stdafx.h" #include "../V8Helpers.h" #include "../V8ResourceImpl.h" @@ -7,14 +6,14 @@ using namespace alt; -static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo& info) +static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); Ref obj = _this->GetHandle().As(); @@ -23,17 +22,17 @@ static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo info.GetReturnValue().Set(resource->CreateVector3(_pos)); } -static void PositionSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +static void PositionSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); V8_CHECK(val->IsObject(), "object expected"); - V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); + V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); Ref obj = _this->GetHandle().As(); @@ -44,18 +43,18 @@ static void PositionSetter(v8::Local, v8::Local val, cons v8::Local y = V8::Get(ctx, pos, "y")->ToNumber(ctx).ToLocalChecked(); v8::Local z = V8::Get(ctx, pos, "z")->ToNumber(ctx).ToLocalChecked(); - obj->SetPosition({ float(x->Value()), float(y->Value()), float(z->Value()) }); + obj->SetPosition({float(x->Value()), float(y->Value()), float(z->Value())}); } #ifdef ALT_SERVER_API -static void DimensionGetter(v8::Local, const v8::PropertyCallbackInfo& info) +static void DimensionGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); Ref obj = _this->GetHandle().As(); @@ -63,14 +62,14 @@ static void DimensionGetter(v8::Local, const v8::PropertyCallbackInf info.GetReturnValue().Set(v8::Integer::New(isolate, obj->GetDimension())); } -static void DimensionSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +static void DimensionSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); + v8::Isolate *isolate = info.GetIsolate(); - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); - V8Entity* _this = V8Entity::Get(info.This()); + V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); Ref obj = _this->GetHandle().As(); @@ -80,7 +79,7 @@ static void DimensionSetter(v8::Local, v8::Local val, con #endif // ALT_SERVER_API static V8Class v8worldObject("WorldObject", "BaseObject", nullptr, [](v8::Local tpl) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetAccessor(isolate, tpl, "pos", PositionGetter, PositionSetter); diff --git a/events/Main.cpp b/events/Main.cpp index 3f787f19..0a4e6036 100644 --- a/events/Main.cpp +++ b/events/Main.cpp @@ -1,19 +1,19 @@ -#include "stdafx.h" #include "../V8ResourceImpl.h" #include "../V8Helpers.h" +#include "cpp-sdk/events/CConsoleCommandEvent.h" + using EventType = alt::CEvent::Type; V8::LocalEventHandler consoleCommand( EventType::CONSOLE_COMMAND_EVENT, "consoleCommand", - [](V8ResourceImpl* resource, const alt::CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - v8::Isolate* isolate = resource->GetIsolate(); + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); args.push_back(v8::String::NewFromUtf8(isolate, ev->GetName().GetData(), v8::NewStringType::kNormal, ev->GetName().GetSize()).ToLocalChecked()); - for (auto& arg : ev->GetArgs()) + for (auto &arg : ev->GetArgs()) args.push_back(v8::String::NewFromUtf8(isolate, arg.GetData(), v8::NewStringType::kNormal, arg.GetSize()).ToLocalChecked()); - } -); + }); From 3c2e799a84b4e3aeb151d6112fe22d8e23155637 Mon Sep 17 00:00:00 2001 From: Hazard Date: Sat, 31 Oct 2020 23:45:12 +0100 Subject: [PATCH 023/564] Extracted client-js script runtime from client (Blip, Handling, MapZoomData, MemoryBuffer, Player, Vehicle files disabled) --- .gitignore | 4 + .vscode/c_cpp_properties.json | 25 + .vscode/settings.json | 67 + .vscode/tasks.json | 17 + CMakeLists.txt | 75 + deps/cpp-sdk | 2 +- src/CV8Resource.cpp | 779 ++++++++++ src/CV8Resource.h | 162 ++ src/CV8ScriptRuntime.cpp | 89 ++ src/CV8ScriptRuntime.h | 122 ++ src/V8Entity.h | 0 src/bindings/Blip.cpp | 924 ++++++++++++ src/bindings/Discord.cpp | 54 + src/bindings/Handling.cpp | 2183 +++++++++++++++++++++++++++ src/bindings/HandlingData.cpp | 1774 ++++++++++++++++++++++ src/bindings/LocalStorage.cpp | 96 ++ src/bindings/Main.cpp | 903 +++++++++++ src/bindings/MapZoomData.cpp | 208 +++ src/bindings/MemoryBuffer.cpp | 201 +++ src/bindings/Player.cpp | 384 +++++ src/bindings/V8Natives.cpp | 255 ++++ src/bindings/Vehicle.cpp | 183 +++ src/bindings/Voice.cpp | 24 + src/bindings/WebView.cpp | 223 +++ src/helpers | 2 +- src/inspector/CV8InspectorChannel.h | 24 + src/inspector/CV8InspectorClient.h | 11 + src/main.cpp | 0 28 files changed, 8789 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 CMakeLists.txt create mode 100644 src/CV8Resource.cpp create mode 100644 src/CV8Resource.h create mode 100644 src/CV8ScriptRuntime.cpp create mode 100644 src/CV8ScriptRuntime.h create mode 100644 src/V8Entity.h create mode 100644 src/bindings/Blip.cpp create mode 100644 src/bindings/Discord.cpp create mode 100644 src/bindings/Handling.cpp create mode 100644 src/bindings/HandlingData.cpp create mode 100644 src/bindings/LocalStorage.cpp create mode 100644 src/bindings/Main.cpp create mode 100644 src/bindings/MapZoomData.cpp create mode 100644 src/bindings/MemoryBuffer.cpp create mode 100644 src/bindings/Player.cpp create mode 100644 src/bindings/V8Natives.cpp create mode 100644 src/bindings/Vehicle.cpp create mode 100644 src/bindings/Voice.cpp create mode 100644 src/bindings/WebView.cpp create mode 100644 src/inspector/CV8InspectorChannel.h create mode 100644 src/inspector/CV8InspectorClient.h create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..0b890095 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + +BUILD/ + +deps/v8/ diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..46dbcb67 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,25 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**", + "${workspaceFolder}/deps", + "${workspaceFolder}/deps/v8/include" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE", + "ALT_CLIENT_API", + "ALT_CLIENT" + ], + "windowsSdkVersion": "10.0.19041.0", + "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "msvc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..9e959e7c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,67 @@ +{ + "files.associations": { + "algorithm": "cpp", + "array": "cpp", + "atomic": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "filesystem": "cpp", + "fstream": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "utility": "cpp", + "vector": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xmemory0": "cpp", + "xstddef": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..12902f7d --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,17 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Build", + "type": "shell", + "command": "cmake --build BUILD", + "problemMatcher": ["$msCompile"], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..8f79a5fc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,75 @@ +cmake_minimum_required (VERSION 3.10) + +project(altv-client-js) + +set(ALTV_DEPS_DIR ${CMAKE_SOURCE_DIR}/deps) + +file(GLOB_RECURSE PROJECT_SOURCE_FILES "src/*.h" "src/*.hpp" "src/*.cpp" "src/*.c") +# file(GLOB_RECURSE SHARED_SOURCE_FILES +# "${ALTV_SHARED}/src/*.h" +# "${ALTV_SHARED}/src/*.hpp" +# "${ALTV_SHARED}/src/*.cpp" +# ) + +macro(GroupSources curdir groupindex) + file(GLOB children RELATIVE ${curdir} ${curdir}/*) + + foreach(child ${children}) + if(IS_DIRECTORY ${curdir}/${child}) + GroupSources(${curdir}/${child} ${groupindex}/${child}) + else() + + string(REPLACE "/" "\\" groupname ${groupindex}) + + source_group(${groupname} FILES ${curdir}/${child}) + endif() + endforeach() +endmacro() + +GroupSources(${PROJECT_SOURCE_DIR}/src "Source Files") + +include_directories( + ${ALTV_DEPS_DIR} + ${ALTV_DEPS_DIR}/v8/include +) + +link_directories( + ${ALTV_DEPS_DIR}/v8/lib/${CMAKE_BUILD_TYPE} +) + +# Definitions +add_definitions( + # Compliation + -DCXX_COMPILER_ID="${CMAKE_CXX_COMPILER_ID}" + + # Platform + -DUNICODE + -D_UNICODE + + -DALT_CLIENT + -DALT_CLIENT_API +) + +add_library( + ${PROJECT_NAME} SHARED + ${PROJECT_SOURCE_FILES} +) + +target_link_libraries(${PROJECT_NAME} + # Platform binaries + Winmm.lib + DbgHelp.lib + + # V8 + v8_monolith.lib +) + +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /Zi /bigobj") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /bigobj") +set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG:FULL /OPT:REF /OPT:ICF") + +set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD 17 +# RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/BIN/Debug/client" +# RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/BIN/Release/client" +) \ No newline at end of file diff --git a/deps/cpp-sdk b/deps/cpp-sdk index 6addd980..d82ca63c 160000 --- a/deps/cpp-sdk +++ b/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 6addd980bdea3fb0aa3d3dfef1f400172cd3c708 +Subproject commit d82ca63c5c20ef55ab987c288bd80a71a4884e85 diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp new file mode 100644 index 00000000..cc33b34b --- /dev/null +++ b/src/CV8Resource.cpp @@ -0,0 +1,779 @@ +#include "cpp-sdk/entities/IEntity.h" +#include "cpp-sdk/entities/IPlayer.h" + +#include "cpp-sdk/events/CEvent.h" +#include "cpp-sdk/events/CClientScriptEvent.h" +#include "cpp-sdk/events/CServerScriptEvent.h" +#include "cpp-sdk/events/CWebViewEvent.h" +#include "cpp-sdk/events/CKeyboardEvent.h" +#include "cpp-sdk/events/CConnectionComplete.h" +#include "cpp-sdk/events/CDisconnectEvent.h" +#include "cpp-sdk/events/CGameEntityCreateEvent.h" +#include "cpp-sdk/events/CGameEntityDestroyEvent.h" +#include "cpp-sdk/events/CSyncedMetaDataChangeEvent.h" +#include "cpp-sdk/events/CStreamSyncedMetaDataChangeEvent.h" +#include "cpp-sdk/events/CGlobalSyncedMetaDataChangeEvent.h" +#include "cpp-sdk/events/CRemoveEntityEvent.h" +#include "cpp-sdk/events/CResourceStartEvent.h" +#include "cpp-sdk/events/CResourceStopEvent.h" +#include "cpp-sdk/events/CResourceErrorEvent.h" +#include "cpp-sdk/events/CRenderEvent.h" +#include "cpp-sdk/SDK.h" + +#include "CV8ScriptRuntime.h" +#include "CV8Resource.h" +#include "bindings/V8Natives.h" +#include "helpers/V8Module.h" + +static void StaticRequire(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK(info[0]->IsString(), "moduleName must be a string"); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + std::string name{*v8::String::Utf8Value{isolate, info[0]}}; + + v8::MaybeLocal _exports = static_cast(resource)->Require(name); + + if (!_exports.IsEmpty()) + info.GetReturnValue().Set(_exports.ToLocalChecked()); + else + V8Helpers::Throw(isolate, "No such module " + name); +} + +bool CV8ResourceImpl::Start() +{ + if (resource->GetMain().IsEmpty()) + return false; + + resource->EnableNatives(); + + v8::Locker locker(isolate); + v8::Isolate::Scope isolate_scope(isolate); + v8::HandleScope handle_scope(isolate); + + v8::Local ctx = v8::Context::New(isolate); + + context.Reset(isolate, ctx); + ctx->SetAlignedPointerInEmbedderData(1, resource); + + V8ResourceImpl::Start(); + + v8::Context::Scope context_scope(ctx); + + //Log::Debug(V8ResourceImpl::GetResource(ctx)); + //Log::Debug(V8ResourceImpl::GetResource(isolate->GetEnteredContext())); + + /*runtime->GetInspector()->contextCreated({ + ctx, + 1, + v8_inspector::StringView{ (uint8_t*)name.CStr(), name.GetSize() } + });*/ + + std::string path = resource->GetMain().ToString(); + + alt::IPackage *pkg = resource->GetPackage(); + alt::IPackage::File *file = pkg->OpenFile(path); + + alt::String src{pkg->GetFileSize(file)}; + + pkg->ReadFile(file, src.GetData(), src.GetSize()); + pkg->CloseFile(file); + + Log::Info << "[V8] Starting script" << path; + + v8::Local sourceCode = v8::String::NewFromUtf8(isolate, src.GetData(), v8::NewStringType::kNormal, src.GetSize()).ToLocalChecked(); + + v8::ScriptOrigin scriptOrigin{ + v8::String::NewFromUtf8(isolate, path.c_str()).ToLocalChecked(), + v8::Local(), + v8::Local(), + v8::Local(), + v8::Local(), + v8::Local(), + v8::Local(), + v8::Local(), + v8::True(isolate), + v8::Local()}; + + bool result = V8Helpers::TryCatch([&]() { + v8::ScriptCompiler::Source source{sourceCode, scriptOrigin}; + v8::MaybeLocal maybeModule = v8::ScriptCompiler::CompileModule(isolate, &source); + + if (maybeModule.IsEmpty()) + return false; + + v8::Local curModule = maybeModule.ToLocalChecked(); + + modules.emplace(path, v8::UniquePersistent{isolate, curModule}); + + ctx->Global()->Set(ctx, v8::String::NewFromUtf8(isolate, "__internal_get_exports").ToLocalChecked(), v8::Function::New(ctx, &StaticRequire).ToLocalChecked()); + bool res = curModule->InstantiateModule(ctx, CV8ScriptRuntime::ResolveModule).IsJust(); + + if (!res) + return false; + + v8::MaybeLocal v = curModule->Evaluate(ctx); + + if (v.IsEmpty()) + return false; + + alt::MValue _exports = V8Helpers::V8ToMValue(curModule->GetModuleNamespace()); + resource->SetExports(_exports.As()); + + Log::Info << "[V8] Started script" << path; + return true; + }); + + if (!result) + { + modules.erase(path); + } + + DispatchStartEvent(!result); + + return result; +} + +bool CV8ResourceImpl::Stop() +{ + std::vector> objects(ownedObjects.size()); + + for (auto handle : ownedObjects) + objects.push_back(handle); + + ownedObjects.clear(); + + // ????? + // for (auto handle : objects) + // { + // CGame::Instance().DestroyBaseObject(handle); + // } + + //runtime->GetInspector()->contextDestroyed(context.Get(isolate)); + + if (!context.IsEmpty()) + { + resource->PushNativeUpdate(); + + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + v8::Context::Scope scope(GetContext()); + + DispatchStopEvent(); + } + + return true; +} + +bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) +{ + resource->PushNativeUpdate(); + + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + auto ctx = GetContext(); + if (ctx.IsEmpty()) + return true; + v8::Context::Scope scope(ctx); + + std::vector handlers; + + switch (e->GetType()) + { + case alt::CEvent::Type::RENDER: + { + handlers = GetLocalHandlers("render"); + break; + } + case alt::CEvent::Type::WEB_VIEW_EVENT: + { + auto ev = static_cast(e); + auto it = webViewHandlers.find(ev->GetTarget()); + + if (it != webViewHandlers.end()) + { + auto range = it->second.equal_range(ev->GetName().ToString()); + + for (auto it = range.first; it != range.second; ++it) + handlers.push_back(&it->second); + } + + break; + } + case alt::CEvent::Type::CLIENT_SCRIPT_EVENT: + { + auto ev = static_cast(e); + handlers = GetLocalHandlers(ev->GetName().ToString()); + break; + } + case alt::CEvent::Type::SERVER_SCRIPT_EVENT: + { + auto ev = static_cast(e); + handlers = GetRemoteHandlers(ev->GetName().ToString()); + break; + } + case alt::CEvent::Type::KEYBOARD_EVENT: + { + auto ev = static_cast(e); + + if (ev->GetKeyState() == alt::CKeyboardEvent::KeyState::UP) + handlers = GetLocalHandlers("keyup"); + else if (ev->GetKeyState() == alt::CKeyboardEvent::KeyState::DOWN) + handlers = GetLocalHandlers("keydown"); + + break; + } + case alt::CEvent::Type::CONNECTION_COMPLETE: + { + handlers = GetLocalHandlers("connectionComplete"); + break; + } + case alt::CEvent::Type::DISCONNECT_EVENT: + { + handlers = GetLocalHandlers("disconnect"); + break; + } + case alt::CEvent::Type::REMOVE_ENTITY_EVENT: + { + handlers = GetLocalHandlers("removeEntity"); + break; + } + case alt::CEvent::Type::CONSOLE_COMMAND_EVENT: + { + handlers = GetLocalHandlers("consoleCommand"); + break; + } + case alt::CEvent::Type::GAME_ENTITY_CREATE: + { + handlers = GetLocalHandlers("gameEntityCreate"); + break; + } + case alt::CEvent::Type::GAME_ENTITY_DESTROY: + { + handlers = GetLocalHandlers("gameEntityDestroy"); + break; + } + case alt::CEvent::Type::SYNCED_META_CHANGE: + { + handlers = GetLocalHandlers("syncedMetaChange"); + break; + } + case alt::CEvent::Type::STREAM_SYNCED_META_CHANGE: + { + handlers = GetLocalHandlers("streamSyncedMetaChange"); + break; + } + case alt::CEvent::Type::GLOBAL_META_CHANGE: + { + handlers = GetLocalHandlers("globalMetaChange"); + break; + } + case alt::CEvent::Type::GLOBAL_SYNCED_META_CHANGE: + { + handlers = GetLocalHandlers("globalSyncedMetaChange"); + break; + } + case alt::CEvent::Type::RESOURCE_START: + { + handlers = GetLocalHandlers("anyResourceStart"); + break; + } + case alt::CEvent::Type::RESOURCE_STOP: + { + handlers = GetLocalHandlers("anyResourceStop"); + break; + } + case alt::CEvent::Type::RESOURCE_ERROR: + { + handlers = GetLocalHandlers("anyResourceError"); + break; + } + } + + if (handlers.size() > 0) + { + std::vector> args; + + switch (e->GetType()) + { + case alt::CEvent::Type::WEB_VIEW_EVENT: + { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + + break; + } + case alt::CEvent::Type::CLIENT_SCRIPT_EVENT: + { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + + break; + } + case alt::CEvent::Type::SERVER_SCRIPT_EVENT: + { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + + break; + } + case alt::CEvent::Type::KEYBOARD_EVENT: + { + auto ev = static_cast(e); + + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetKeyCode())); + + break; + } + case alt::CEvent::Type::CONNECTION_COMPLETE: + { + break; + } + case alt::CEvent::Type::DISCONNECT_EVENT: + { + break; + } + case alt::CEvent::Type::REMOVE_ENTITY_EVENT: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetEntity().Get())->GetJSVal(isolate)); + + break; + } + case alt::CEvent::Type::CONSOLE_COMMAND_EVENT: + { + auto ev = static_cast(e); + + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetName().CStr()).ToLocalChecked()); + for (auto &arg : ev->GetArgs()) + args.push_back(v8::String::NewFromUtf8(isolate, arg.CStr()).ToLocalChecked()); + + break; + } + case alt::CEvent::Type::GAME_ENTITY_CREATE: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + + break; + } + case alt::CEvent::Type::GAME_ENTITY_DESTROY: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + + break; + } + case alt::CEvent::Type::SYNCED_META_CHANGE: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + + break; + } + case alt::CEvent::Type::STREAM_SYNCED_META_CHANGE: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + + break; + } + case alt::CEvent::Type::GLOBAL_META_CHANGE: + { + auto ev = static_cast(e); + + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + + break; + } + case alt::CEvent::Type::GLOBAL_SYNCED_META_CHANGE: + { + auto ev = static_cast(e); + + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + + break; + } + case alt::CEvent::Type::RESOURCE_START: + { + auto ev = static_cast(e); + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); + break; + } + case alt::CEvent::Type::RESOURCE_STOP: + { + auto ev = static_cast(e); + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); + break; + } + case alt::CEvent::Type::RESOURCE_ERROR: + { + auto ev = static_cast(e); + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); + break; + } + } + + InvokeEventHandlers(e, handlers, args); + } + + return true; +} + +void CV8ResourceImpl::OnTick() +{ + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + v8::Context::Scope scope(GetContext()); + + int64_t time = GetTime(); + + V8ResourceImpl::OnTick(); + + if (GetTime() - time > 10) + { + Log::Warning << "Resource" << resource->GetName() << "tick was too long" << GetTime() - time, "ms"; + } + + for (auto &view : webViewHandlers) + { + for (auto it = view.second.begin(); it != view.second.end();) + { + if (it->second.removed) + it = view.second.erase(it); + else + ++it; + } + } +} + +void CV8ResourceImpl::OnPromiseRejectedWithNoHandler(v8::PromiseRejectMessage &data) +{ + promiseRejections.RejectedWithNoHandler(this, data); +} + +void CV8ResourceImpl::OnPromiseHandlerAdded(v8::PromiseRejectMessage &data) +{ + promiseRejections.HandlerAdded(this, data); +} + +static v8::MaybeLocal CompileESM(v8::Isolate *isolate, const std::string &name, const std::string &src) +{ + v8::Local sourceCode = v8::String::NewFromUtf8(isolate, src.data(), v8::NewStringType::kNormal, src.size()).ToLocalChecked(); + + v8::ScriptOrigin scriptOrigin{ + v8::String::NewFromUtf8(isolate, name.c_str()).ToLocalChecked(), + v8::Local(), + v8::Local(), + v8::Local(), + v8::Local(), + v8::Local(), + v8::Local(), + v8::Local(), + v8::True(isolate), + v8::Local()}; + + v8::ScriptCompiler::Source source{sourceCode, scriptOrigin}; + return v8::ScriptCompiler::CompileModule(isolate, &source); +} + +static v8::MaybeLocal WrapModule(v8::Isolate *isolate, const std::deque &_exportKeys, const std::string &name, bool exportAsDefault = false) +{ + bool hasDefault = false; + std::stringstream src; + + src << "const _exports = __internal_get_exports('" << name << "');\n"; + + for (auto &key : _exportKeys) + { + if (key == "default") + { + src << "export default _exports['" << key << "'];\n"; + hasDefault = true; + } + else + { + src << "export let " << key << " = _exports['" << key << "'];\n"; + } + } + + if (!hasDefault && exportAsDefault) + src << "export default _exports;"; + + return CompileESM(isolate, name, src.str()); +} + +bool CV8ResourceImpl::IsValidModule(const std::string &name) +{ + if (V8Module::Exists(name)) + return true; + + alt::IResource *resource = alt::ICore::Instance().GetResource(name); + if (resource) + return true; + + return false; +} + +std::deque CV8ResourceImpl::GetModuleKeys(const std::string &name) +{ + auto &v8module = V8Module::All().find(name); + if (v8module != V8Module::All().end()) + { + auto _exports = v8module->second->GetExports(isolate, GetContext()); + v8::Local v8Keys = _exports->GetOwnPropertyNames(GetContext()).ToLocalChecked(); + + std::deque keys; + + for (uint32_t i = 0; i < v8Keys->Length(); ++i) + { + v8::Local v8Key = v8Keys->Get(GetContext(), i).ToLocalChecked().As(); + keys.push_back(*v8::String::Utf8Value(isolate, v8Key)); + } + + return keys; + } + + alt::IResource *resource = alt::ICore::Instance().GetResource(name); + if (resource) + { + std::deque keys; + + alt::MValueDict _exports = resource->GetExports(); + for (auto it = _exports->Begin(); it; it = _exports->Next()) + keys.push_back(it->GetKey().ToString()); + + return keys; + } + + return {}; +} + +std::string CV8ResourceImpl::GetModulePath(v8::Local moduleHandle) +{ + for (auto &md : modules) + { + if (md.second == moduleHandle) + return md.first; + } + + return std::string{}; +} + +static bool IsSystemModule(const std::string &name) +{ + return V8Module::Exists(name); +} + +v8::MaybeLocal CV8ResourceImpl::Require(const std::string &name) +{ + auto it = requires.find(name); + + if (it != requires.end()) + return it->second.Get(isolate); + + auto &v8module = V8Module::All().find(name); + if (v8module != V8Module::All().end()) + { + auto _exports = v8module->second->GetExports(isolate, GetContext()); + requires.insert({name, v8::UniquePersistent{isolate, _exports}}); + + return _exports; + } + + alt::IResource *resource = alt::ICore::Instance().GetResource(name); + if (resource) + { + v8::Local _exports = V8Helpers::MValueToV8(resource->GetExports()); + + requires.insert({name, v8::UniquePersistent{isolate, _exports}}); + + return _exports; + } + + return v8::MaybeLocal(); +} + +v8::MaybeLocal CV8ResourceImpl::ResolveFile(const std::string &name, v8::Local referrer) +{ + auto path = alt::ICore::Instance().Resolve(resource, name, GetModulePath(referrer)); + + if (!path.pkg) + return v8::MaybeLocal(); + + auto fileName = path.fileName.ToString(); + + if (fileName.size() == 0) + { + if (path.pkg->FileExists("index.js")) + fileName = "index.js"; + else if (path.pkg->FileExists("index.mjs")) + fileName = "index.mjs"; + else + return v8::MaybeLocal(); + } + else + { + if (path.pkg->FileExists(fileName + ".js")) + fileName += ".js"; + else if (path.pkg->FileExists(fileName + ".mjs")) + fileName += ".mjs"; + else if (path.pkg->FileExists(fileName + "/index.js")) + fileName += "/index.js"; + else if (path.pkg->FileExists(fileName + "/index.mjs")) + fileName += "/index.mjs"; + else if (!path.pkg->FileExists(fileName)) + return v8::MaybeLocal(); + } + + std::string fullName = path.prefix.ToString() + fileName; + + auto it = modules.find(fullName); + + if (it != modules.end()) + return it->second.Get(isolate); + + v8::MaybeLocal maybeModule; + + V8Helpers::TryCatch([&] { + alt::IPackage::File *file = path.pkg->OpenFile(fileName); + + std::string src(path.pkg->GetFileSize(file), '\0'); + path.pkg->ReadFile(file, src.data(), src.size()); + path.pkg->CloseFile(file); + + maybeModule = CompileESM(isolate, fullName, src); + + if (maybeModule.IsEmpty()) + return false; + + v8::Local _module = maybeModule.ToLocalChecked(); + + modules.emplace(fullName, v8::UniquePersistent{isolate, _module}); + /*v8::Maybe res = _module->InstantiateModule(GetContext(), CV8ScriptRuntime::ResolveModule); + if (res.IsNothing()) + return false; + + v8::MaybeLocal res2 = _module->Evaluate(GetContext()); + if (res2.IsEmpty()) + return false;*/ + + return true; + }); + + if (maybeModule.IsEmpty()) + { + modules.erase(fullName); + } + + return maybeModule; +} + +v8::MaybeLocal CV8ResourceImpl::ResolveModule(const std::string &_name, v8::Local referrer) +{ + v8::MaybeLocal maybeModule; + + std::string name = _name; + + if (name == "alt-client") + name = "alt"; + + auto it = modules.find(name); + if (it != modules.end()) + { + maybeModule = it->second.Get(isolate); + } + + if (maybeModule.IsEmpty()) + { + if (IsValidModule(name)) + { + V8Helpers::TryCatch([&] { + maybeModule = WrapModule(isolate, GetModuleKeys(name), name, IsSystemModule(name)); + + if (!maybeModule.IsEmpty()) + { + v8::Local _module = maybeModule.ToLocalChecked(); + + modules.emplace(name, v8::UniquePersistent{isolate, _module}); + + /*v8::Maybe res = _module->InstantiateModule(GetContext(), CV8ScriptRuntime::ResolveModule); + if (res.IsNothing()) + { + Log::Info(__LINE__, "res.IsNothing()"); + return false; + } + + v8::MaybeLocal res2 = _module->Evaluate(GetContext()); + if (res2.IsEmpty()) + { + Log::Info(__LINE__, "res2.IsEmpty()"); + return false; + }*/ + + return true; + } + + Log::Info << __LINE__ << "maybeModule.IsEmpty()"; + return false; + }); + + if (maybeModule.IsEmpty()) + { + modules.erase(name); + isolate->ThrowException(v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, ("Failed to load module: " + name).c_str()).ToLocalChecked())); + return v8::MaybeLocal{}; + } + } + } + + if (maybeModule.IsEmpty()) + { + maybeModule = ResolveFile(name, referrer); + } + + if (maybeModule.IsEmpty()) + { + modules.erase(name); + isolate->ThrowException(v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, ("No such module: " + name).c_str()).ToLocalChecked())); + return v8::MaybeLocal{}; + } + + /*v8::Local _module = maybeModule.ToLocalChecked(); + if (_module->GetStatus() != v8::Module::kEvaluated) + { + modules.erase(name); + isolate->ThrowException(v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, ("Failed to import: " + name).c_str()))); + return v8::MaybeLocal{ }; + }*/ + + return maybeModule; +} diff --git a/src/CV8Resource.h b/src/CV8Resource.h new file mode 100644 index 00000000..89817e60 --- /dev/null +++ b/src/CV8Resource.h @@ -0,0 +1,162 @@ +#pragma once + +#include "cpp-sdk/IResource.h" +#include "cpp-sdk/entities/IEntity.h" + +#include "helpers/V8ResourceImpl.h" + +#include + +#include "helpers/Log.h" + +class CV8ScriptRuntime; + +class CV8ResourceImpl : public V8ResourceImpl +{ +public: + CV8ResourceImpl(alt::IResource *resource, v8::Isolate *isolate) : V8ResourceImpl(isolate, resource) + { + } + + ~CV8ResourceImpl() + { + Log::Debug << __FUNCTION__; + } + + bool Start() override; + + bool Stop() override; + + bool OnEvent(const alt::CEvent *ev) override; + + void OnTick() override; + + void OnPromiseRejectedWithNoHandler(v8::PromiseRejectMessage &data); + void OnPromiseHandlerAdded(v8::PromiseRejectMessage &data); + + void SubscribeWebView(alt::Ref view, const std::string &evName, v8::Local cb, V8::SourceLocation &&location) + { + webViewHandlers[view].insert({evName, V8::EventCallback{isolate, cb, std::move(location)}}); + } + + void UnsubscribeWebView(alt::Ref view, const std::string &evName, v8::Local cb) + { + auto it = webViewHandlers.find(view); + if (it != webViewHandlers.end()) + { + auto &viewEvents = it->second; + auto range = viewEvents.equal_range(evName); + + for (auto it = range.first; it != range.second; ++it) + { + if (it->second.fn.Get(isolate)->StrictEquals(cb)) + it->second.removed = true; + } + } + } + + void AddGxtText(uint32_t hash, const std::string &text) + { + std::unique_lock lock(gxtAccessMutex); + if (gxtEntries.count(hash) > 0) + gxtEntries[hash] = text; + else + gxtEntries.insert(std::pair(hash, text)); + } + + void RemoveGxtText(uint32_t hash) + { + std::unique_lock lock(gxtAccessMutex); + if (gxtEntries.count(hash) > 0) + gxtEntries.erase(hash); + } + + const std::string &GetGxtText(uint32_t hash) + { + static std::string emptyString = ""; + std::unique_lock lock(gxtAccessMutex); + if (gxtEntries.count(hash) > 0) + return gxtEntries[hash]; + return emptyString; + } + + void AddOwned(alt::Ref handle) + { + ownedObjects.insert(handle); + } + + void OnRemoveBaseObject(alt::Ref handle) + { + ownedObjects.erase(handle); + + if (handle->GetType() == alt::IBaseObject::Type::WEBVIEW) + webViewHandlers.erase(handle.As()); + + V8ResourceImpl::OnRemoveBaseObject(handle); + } + + bool ToggleCursor(bool state) + { + if (cursorsCount > 0 || state) + { + cursorsCount += state ? 1 : -1; + return true; + } + + return false; + } + + void ToggleGameControls(bool state) + { + gameControlsEnabled = state; + } + + bool CursorVisible() + { + return cursorsCount > 0; + } + + bool GameControlsActive() + { + return gameControlsEnabled; + } + + v8::Local GetLocalStorage() + { + if (localStorage.IsEmpty()) + { + std::vector> args; + localStorage.Reset(isolate, V8Class::Get("LocalStorage")->New(GetContext(), args).As()); + } + + return localStorage.Get(isolate); + } + + bool IsValidModule(const std::string &name); + std::deque GetModuleKeys(const std::string &name); + std::string GetModulePath(v8::Local moduleHandle); + + v8::MaybeLocal Require(const std::string &name); + v8::MaybeLocal ResolveFile(const std::string &name, v8::Local referrer); + v8::MaybeLocal ResolveModule(const std::string &name, v8::Local referrer); + +private: + using WebViewEvents = std::unordered_multimap; + + CV8ScriptRuntime *runtime; + + std::unordered_map> requires; + std::unordered_map> modules; + + std::unordered_map, WebViewEvents> webViewHandlers; + std::unordered_map gxtEntries; + + std::unordered_set> ownedObjects; + + v8::Persistent localStorage; + + std::mutex gxtAccessMutex; + + uint32_t cursorsCount = 0; + bool gameControlsEnabled = true; +}; diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp new file mode 100644 index 00000000..7f424b6a --- /dev/null +++ b/src/CV8ScriptRuntime.cpp @@ -0,0 +1,89 @@ + +//#include "helpers/bindings/BaseObject.h" +//#include "helpers/bindings/WorldObject.h" +//#include "helpers/bindings/Entity.h" +//#include "bindings/Player.h" +//#include "bindings/Vehicle.h" +//#include "bindings/WebView.h" + +#include "CV8ScriptRuntime.h" +#include "inspector/CV8InspectorClient.h" +#include "inspector/CV8InspectorChannel.h" + +CV8ScriptRuntime::CV8ScriptRuntime() +{ + platform = v8::platform::NewDefaultPlatform(); + v8::V8::InitializePlatform(platform.get()); + v8::V8::Initialize(); + + create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); + + isolate = v8::Isolate::New(create_params); + isolate->SetFatalErrorHandler([](const char *location, const char *message) { + Log::Error << "[V8] " << location << ": " << message << Log::Endl; + }); + + isolate->SetPromiseRejectCallback([](v8::PromiseRejectMessage message) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Local value = message.GetValue(); + v8::Local ctx = isolate->GetEnteredContext(); + + CV8ResourceImpl *resource = static_cast(V8ResourceImpl::Get(ctx)); + if (resource) + { + if (message.GetEvent() == v8::PromiseRejectEvent::kPromiseRejectWithNoHandler) + { + resource->OnPromiseRejectedWithNoHandler(message); + } + else if (message.GetEvent() == v8::PromiseRejectEvent::kPromiseHandlerAddedAfterReject) + { + resource->OnPromiseHandlerAdded(message); + } + else if (message.GetEvent() == v8::PromiseRejectEvent::kPromiseRejectAfterResolved) + { + Log::Warning << "[V8] Promise rejected after being resolved in resource " + << resource->GetResource()->GetName() << " (" + << *v8::String::Utf8Value(isolate, value->ToString(ctx).ToLocalChecked()) + << ")" << Log::Endl; + } + else if (message.GetEvent() == v8::PromiseRejectEvent::kPromiseResolveAfterResolved) + { + Log::Warning << "[V8] Promise resolved after being resolved in resource " + << resource->GetResource()->GetName() << " (" + << *v8::String::Utf8Value(isolate, value->ToString(ctx).ToLocalChecked()) + << ")" << Log::Endl; + } + } + else + { + Log::Error << "You're not supposed to ever see this"; + } + }); + + /*isolate->SetHostImportModuleDynamicallyCallback([](v8::Local context, v8::Local referrer, v8::Local specifier) { + + return v8::MaybeLocal(); + });*/ + + /*{ + v8::Locker locker(isolate); + v8::Isolate::Scope isolate_scope(isolate); + v8::HandleScope handle_scope(isolate); + + inspectorClient.reset(new alt::CV8InspectorClient); + inspectorChannel.reset(new alt::CV8InspectorChannel); + + inspector = v8_inspector::V8Inspector::create(isolate, inspectorClient.get()); + + v8_inspector::StringView inspectorView{ (uint8_t*)inspectorViewStr, strlen(inspectorViewStr) }; + inspectorSession = inspector->connect(1, inspectorChannel.get(), inspectorView); + }*/ + + { + v8::Locker locker(isolate); + v8::Isolate::Scope isolate_scope(isolate); + v8::HandleScope handle_scope(isolate); + + V8Class::LoadAll(isolate); + } +} diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h new file mode 100644 index 00000000..109f94c9 --- /dev/null +++ b/src/CV8ScriptRuntime.h @@ -0,0 +1,122 @@ +#pragma once + +#include "v8.h" +#include "v8-inspector.h" +#include "libplatform/libplatform.h" + +#include "cpp-sdk/IScriptRuntime.h" + +#include "CV8Resource.h" + +class CV8ScriptRuntime : public alt::IScriptRuntime +{ + static constexpr char inspectorViewStr[] = "alt:V Multiplayer"; + + std::unique_ptr platform; + v8::Isolate::CreateParams create_params; + v8::Isolate *isolate; + std::unique_ptr inspectorClient; + std::unique_ptr inspectorChannel; + std::unique_ptr inspector; + std::unique_ptr inspectorSession; + +public: + CV8ScriptRuntime(); + + v8::Isolate *GetIsolate() const { return isolate; } + + v8_inspector::V8Inspector *GetInspector() const { return inspector.get(); } + + alt::IResource::Impl *CreateImpl(alt::IResource *resource) override + { + return new CV8ResourceImpl(resource, isolate); + } + + void DestroyImpl(alt::IResource::Impl *impl) override + { + delete static_cast(impl); + } + + void OnTick() override + { + v8::Locker locker(isolate); + v8::Isolate::Scope isolate_scope(isolate); + v8::HandleScope handle_scope(isolate); + + v8::platform::PumpMessageLoop(platform.get(), isolate); + } + + void HeapBenchmark() + { + v8::HeapStatistics heapStats; + isolate->GetHeapStatistics(&heapStats); + Log::Info << "================ Heap benchmark info =================" << Log::Endl; + Log::Info << "total_heap_size = " << formatBytes(heapStats.total_heap_size()) << Log::Endl; + Log::Info << "total_heap_size_executable = " << formatBytes(heapStats.total_heap_size_executable()) << Log::Endl; + Log::Info << "total_physical_size = " << formatBytes(heapStats.total_physical_size()) << Log::Endl; + Log::Info << "total_available_size = " << formatBytes(heapStats.total_available_size()) << Log::Endl; + Log::Info << "used_heap_size = " << formatBytes(heapStats.used_heap_size()) << Log::Endl; + Log::Info << "heap_size_limit = " << formatBytes(heapStats.heap_size_limit()) << Log::Endl; + Log::Info << "malloced_memory = " << formatBytes(heapStats.malloced_memory()) << Log::Endl; + Log::Info << "external_memory = " << formatBytes(heapStats.external_memory()) << Log::Endl; + Log::Info << "peak_malloced_memory = " << formatBytes(heapStats.peak_malloced_memory()) << Log::Endl; + Log::Info << "number_of_native_contexts = " << heapStats.number_of_native_contexts() << Log::Endl; + Log::Info << "number_of_detached_contexts = " << heapStats.number_of_detached_contexts() << Log::Endl; + Log::Info << "======================================================" << Log::Endl; + } + + ~CV8ScriptRuntime() + { + isolate->Dispose(); + v8::V8::Dispose(); + v8::V8::ShutdownPlatform(); + delete create_params.array_buffer_allocator; + } + + static v8::MaybeLocal ResolveModule(v8::Local ctx, v8::Local specifier, v8::Local referrer) + { + V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); + if (!resource) + { + ctx->GetIsolate()->ThrowException(v8::Exception::ReferenceError(v8::String::NewFromUtf8(ctx->GetIsolate(), "Invalid resource").ToLocalChecked())); + return v8::MaybeLocal{}; + } + + std::string _specifier = *v8::String::Utf8Value{ctx->GetIsolate(), specifier}; + return static_cast(resource)->ResolveModule(_specifier, referrer); + } + + static std::string formatBytes(uint64_t bytes) + { + static std::string result = ""; + const char *sizes[5] = {"bytes", "KB", "MB", "GB", "TB"}; + + if (bytes == 0) + { + result = "0 bytes"; + return result; + } + else if (bytes == 1) + { + result = "1 byte"; + return result; + } + + uint64_t left = std::floor(std::log(bytes) / std::log(1024)); + + if (left == 0) + { + std::stringstream ss; + ss << bytes + " bytes"; + result = ss.str(); + return result; + } + else + { + std::stringstream ss; + ss << std::setprecision(2) << std::fixed << (bytes / std::pow(1024, left)) << " " << sizes[left]; + result = ss.str(); + return result; + } + }; +}; \ No newline at end of file diff --git a/src/V8Entity.h b/src/V8Entity.h new file mode 100644 index 00000000..e69de29b diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp new file mode 100644 index 00000000..df3da283 --- /dev/null +++ b/src/bindings/Blip.cpp @@ -0,0 +1,924 @@ + +// #include "../CV8Resource.h" +// #include "../helpers/V8Class.h" +// #include "script-objects/CBlip.h" + +// static void Constructor(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(info.IsConstructCall(), "Blip constructor is not a function"); + +// // xyz as obj +// /* +// V8_CHECK(info.Length() == 2, "new Blip(...) expects 2 args"); + +// V8_CHECK(info[0]->IsObject(), "pos must be an object of {x, y, z}"); +// auto pos = info[1]->ToObject(isolate); +// double x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x")).ToLocalChecked() +// ->NumberValue(ctx).ToChecked(); +// double y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y")).ToLocalChecked() +// ->NumberValue(ctx).ToChecked(); +// double z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z")).ToLocalChecked() +// ->NumberValue(ctx).ToChecked(); + +// V8_CHECK(info[1]->IsNumber(), "type must be an unsigned integer"); +// */ + +// /* +// let blip = new alt.Blip(0, 0, 72, 11, 50, 50); +// blip.rotation = 0; +// */ + +// // xyz as args + +// V8_CHECK(false, "You can't use constructor of abstract class"); +// } + +// static void ConstructorAreaBlip(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8_CHECK(info.IsConstructCall(), "AreaBlip constructor is not a function"); + +// V8_CHECK(info.Length() == 5, "new AreaBlip(...) expects 5 args"); +// V8_CHECK(info[0]->IsNumber(), "x must be a number"); +// V8_CHECK(info[1]->IsNumber(), "y must be a number"); +// V8_CHECK(info[2]->IsNumber(), "z must be a number"); +// V8_CHECK(info[3]->IsNumber(), "width must be a number"); +// V8_CHECK(info[4]->IsNumber(), "height must be a number"); + +// v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); +// v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); +// v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); +// v8::Local width = info[3]->ToNumber(ctx).ToLocalChecked(); +// v8::Local height = info[4]->ToNumber(ctx).ToLocalChecked(); + +// alt::Ref blip = alt::CBlip::CreateBlipForArea({x->Value(), y->Value(), z->Value()}, width->Value(), height->Value()); + +// V8_CHECK(blip, "Blip creation failed"); + +// static_cast(resource)->AddOwned(blip); +// resource->BindEntity(info.This(), blip.Get()); +// } + +// static void ConstructorRadiusBlip(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8_CHECK(info.IsConstructCall(), "RadiusBlip constructor is not a function"); + +// V8_CHECK(info.Length() == 4, "new RadiusBlip(...) expects 4 args"); +// V8_CHECK(info[0]->IsNumber(), "x must be a number"); +// V8_CHECK(info[1]->IsNumber(), "y must be a number"); +// V8_CHECK(info[2]->IsNumber(), "z must be a number"); +// V8_CHECK(info[3]->IsNumber(), "radius must be a number"); + +// v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); +// v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); +// v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); +// v8::Local radius = info[3]->ToNumber(ctx).ToLocalChecked(); +// alt::Ref blip = alt::CBlip::CreateBlipForRadius({x->Value(), y->Value(), z->Value()}, radius->Value()); + +// V8_CHECK(blip, "Blip creation failed"); + +// static_cast(resource)->AddOwned(blip); +// resource->BindEntity(info.This(), blip.Get()); +// } + +// static void ConstructorPointBlip(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8_CHECK(info.IsConstructCall(), "PointBlip constructor is not a function"); + +// V8_CHECK(info.Length() == 3, "new PointBlip(...) expects 3 args"); +// V8_CHECK(info[0]->IsNumber(), "x must be a number"); +// V8_CHECK(info[1]->IsNumber(), "y must be a number"); +// V8_CHECK(info[2]->IsNumber(), "z must be a number"); + +// v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); +// v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); +// v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); +// alt::Ref blip = alt::CBlip::Create(alt::IBlip::BlipType::DESTINATION, {x->Value(), y->Value(), z->Value()}); + +// V8_CHECK(blip, "Blip creation failed"); + +// static_cast(resource)->AddOwned(blip); +// resource->BindEntity(info.This(), blip.Get()); +// } + +// static void ConstructorPedBlip(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8_CHECK(info.IsConstructCall(), "PedBlip constructor is not a function"); + +// V8_CHECK(info.Length() == 1, "new PedBlip(...) expects 1 arg"); +// V8_CHECK(info[0]->IsNumber(), "pedId must be a number"); + +// uint32_t pedId = info[0]->IntegerValue(ctx).ToChecked(); +// alt::Ref blip = alt::CBlip::CreateBlipForEntity(alt::IBlip::BlipType::PED, pedId); + +// V8_CHECK(blip, "Blip creation failed"); + +// static_cast(resource)->AddOwned(blip); +// resource->BindEntity(info.This(), blip.Get()); +// } + +// static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8_CHECK(info.IsConstructCall(), "VehicleBlip constructor is not a function"); + +// V8_CHECK(info.Length() == 1, "new VehicleBlip(...) expects 1 arg"); +// V8_CHECK(info[0]->IsNumber(), "vehicleId must be a number"); + +// uint32_t vehicleId = info[0]->IntegerValue(ctx).ToChecked(); +// alt::Ref blip = alt::CBlip::CreateBlipForEntity(alt::IBlip::BlipType::VEHICLE, vehicleId); + +// V8_CHECK(blip, "Blip creation failed"); + +// static_cast(resource)->AddOwned(blip); +// resource->BindEntity(info.This(), blip.Get()); +// } + +// //static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetScale())); +// //} + +// static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsNumber(), "scale must be a number"); +// double val = value->NumberValue(ctx).ToChecked(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); + +// blip->SetScale(val); +// } + +// /** +// * Scale XY +// * */ +// //static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // auto scale = blip->GetScaleXY(); +// // +// // +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, )); +// //} + +// /** +// * Scale XY +// * */ +// //static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // V8_CHECK(value->IsNumber(), "scale must be a number"); +// // double val = value->NumberValue(ctx).ToChecked(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // blip->SetScale(val); +// //} + +// //static void SpriteGetter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void SpriteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsNumber(), "sprite must be an integer"); +// int sprite = value->IntegerValue(ctx).ToChecked(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); + +// blip->SetSprite(sprite); +// } + +// //static void ColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void ColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsNumber(), "color must be an integer"); +// int val = value->IntegerValue(ctx).ToChecked(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetColor(val); +// } + +// //static void SecondaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void SecondaryColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsNumber(), "secondaryColor must be an unsigned integer"); +// int val = value->IntegerValue(ctx).ToChecked(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetSecondaryColor(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void AlphaSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsNumber(), "alpha must be an integer"); +// int val = value->IntegerValue(ctx).ToChecked(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetAlpha(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void FlashTimerSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsNumber(), "flashTimer must be an integer"); +// int val = value->IntegerValue(ctx).ToChecked(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetFlashTimer(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void FlashIntervalSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsNumber(), "flashInterval must be an integer"); +// int val = value->IntegerValue(ctx).ToChecked(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetFlashInterval(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void FriendlySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetAsFriendly(val); +// } + +// //static void RouteGetter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void RouteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetRoute(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void BrightSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetBright(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void NumberSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsNumber(), "number must be an integer"); +// auto val = value->IntegerValue(ctx).ToChecked(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetNumber(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void ShowConeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetShowCone(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void FlashesSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetFlashes(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void FlashesAlternateSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetFlashesAlternate(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void ShortRangeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetAsShortRange(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void PrioritySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsNumber(), "priority must be an integer"); +// auto val = value->IntegerValue(ctx).ToChecked(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetPriority(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +// //} + +// static void RotationSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsNumber(), "rotation must be a number"); +// auto val = value->NumberValue(ctx).ToChecked(); + +// Log::Debug << "nextRotation = " << val << Log::Endl; + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetRotation(val); +// } + +// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// //{ +// // v8::Isolate* isolate = info.GetIsolate(); +// // auto ctx = isolate->GetEnteredContext(); +// // +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // +// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->())); +// //} + +// static void GxtNameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsString(), "gxtName must be a string"); +// auto val = *v8::String::Utf8Value(info.GetIsolate(), value->ToString(ctx).ToLocalChecked()); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetGxtName(val); +// } + +// static void NameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsString(), "name must be a string"); +// auto val = *v8::String::Utf8Value(info.GetIsolate(), value->ToString(ctx).ToLocalChecked()); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetName(val); +// } + +// /* +// static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +// { +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); + +// auto ret = v8::Number::New(isolate, blip->GETTER())); +// info.GetReturnValue().Set(ret); +// } +// */ + +// static void RouteColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsNumber(), "routeColor must be unsigned integer"); +// auto val = value->IntegerValue(ctx).ToChecked(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetRouteColor(val); +// } + +// static void PulseSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetPulse(val); +// } + +// static void AsMissionCreatorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetAsMissionCreator(val); +// } + +// static void tickVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetTickVisible(val); +// } + +// static void headingIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetHeadingIndicatorVisible(val); +// } + +// static void outlineIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetOutlineIndicatorVisible(val); +// } + +// static void friendIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetFriendIndicatorVisible(val); +// } + +// static void crewIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetCrewIndicatorVisible(val); +// } + +// static void categorySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(value->IsNumber(), "category must be integer"); +// auto val = value->IntegerValue(ctx).ToChecked(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetCategory(val); +// } + +// static void highDetailSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetAsHighDetail(val); +// } + +// static void shrinkedSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// auto val = value->ToBoolean(isolate)->Value(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetShrinked(val); +// } + +// static void Fade(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(info.Length() == 2, "2 args expected"); + +// V8_CHECK(info[0]->IsNumber(), "opacity must be an unsigned integer"); +// uint32_t opacity = info[0]->IntegerValue(ctx).ToChecked(); + +// V8_CHECK(info[1]->IsNumber(), "duration must be an unsigned integer"); +// uint32_t duration = info[1]->IntegerValue(ctx).ToChecked(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref blip = _this->GetHandle().As(); + +// blip->Fade(opacity, duration); +// } + +// static V8Class v8blip("Blip", "WorldObject", Constructor, [](v8::Local tpl) { +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); + +// /* +// let ped = game.playerPedId(); +// let coords = game.getEntityCoords(ped, true); + +// let area = new alt.AreaBlip(coords.x, coords.y, coords.z, 30, 30); +// area.color = 5; +// area.rotation = 0; +// */ + +// V8::SetAccessor(isolate, tpl, "sprite", nullptr, &SpriteSetter); +// V8::SetAccessor(isolate, tpl, "scale", nullptr, &ScaleSetter); +// V8::SetAccessor(isolate, tpl, "color", nullptr, &ColorSetter); +// V8::SetAccessor(isolate, tpl, "secondaryColor", nullptr, &SecondaryColorSetter); +// V8::SetAccessor(isolate, tpl, "alpha", nullptr, &AlphaSetter); +// V8::SetAccessor(isolate, tpl, "flashTimer", nullptr, &FlashTimerSetter); +// V8::SetAccessor(isolate, tpl, "flashInterval", nullptr, &FlashIntervalSetter); +// V8::SetAccessor(isolate, tpl, "route", nullptr, &RouteSetter); +// V8::SetAccessor(isolate, tpl, "bright", nullptr, &BrightSetter); +// V8::SetAccessor(isolate, tpl, "number", nullptr, &NumberSetter); +// V8::SetAccessor(isolate, tpl, "showCone", nullptr, &ShowConeSetter); +// V8::SetAccessor(isolate, tpl, "flashes", nullptr, &FlashesSetter); +// V8::SetAccessor(isolate, tpl, "flashesAlternate", nullptr, &FlashesAlternateSetter); +// V8::SetAccessor(isolate, tpl, "shortRange", nullptr, &ShortRangeSetter); +// V8::SetAccessor(isolate, tpl, "priority", nullptr, &PrioritySetter); +// V8::SetAccessor(isolate, tpl, "heading", nullptr, &RotationSetter); +// V8::SetAccessor(isolate, tpl, "gxtName", nullptr, &GxtNameSetter); +// V8::SetAccessor(isolate, tpl, "name", nullptr, &NameSetter); +// V8::SetAccessor(isolate, tpl, "routeColor", nullptr, &RouteColorSetter); +// V8::SetAccessor(isolate, tpl, "pulse", nullptr, &PulseSetter); +// V8::SetAccessor(isolate, tpl, "asMissionCreator", nullptr, &AsMissionCreatorSetter); +// V8::SetAccessor(isolate, tpl, "tickVisible", nullptr, &tickVisibleSetter); +// V8::SetAccessor(isolate, tpl, "headingIndicatorVisible", nullptr, &headingIndicatorVisibleSetter); +// V8::SetAccessor(isolate, tpl, "outlineIndicatorVisible", nullptr, &outlineIndicatorVisibleSetter); +// V8::SetAccessor(isolate, tpl, "friendIndicatorVisible", nullptr, &friendIndicatorVisibleSetter); +// V8::SetAccessor(isolate, tpl, "crewIndicatorVisible", nullptr, &crewIndicatorVisibleSetter); +// V8::SetAccessor(isolate, tpl, "category", nullptr, &categorySetter); +// V8::SetAccessor(isolate, tpl, "highDetail", nullptr, &highDetailSetter); +// V8::SetAccessor(isolate, tpl, "shrinked", nullptr, &shrinkedSetter); + +// V8::SetMethod(isolate, tpl, "fade", &Fade); +// }); + +// static V8Class v8AreaBlip("AreaBlip", "Blip", ConstructorAreaBlip, [](v8::Local tpl) { +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); + +// v8::Local proto = tpl->PrototypeTemplate(); +// }); + +// static V8Class v8RadiusBlip("RadiusBlip", "Blip", ConstructorRadiusBlip, [](v8::Local tpl) { +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); + +// v8::Local proto = tpl->PrototypeTemplate(); +// }); + +// static V8Class v8PointBlip("PointBlip", "Blip", ConstructorPointBlip, [](v8::Local tpl) { +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); + +// v8::Local proto = tpl->PrototypeTemplate(); +// }); + +// static V8Class v8PedBlip("PedBlip", "Blip", ConstructorPedBlip, [](v8::Local tpl) { +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); + +// v8::Local proto = tpl->PrototypeTemplate(); +// }); + +// static V8Class v8VehicleBlip("VehicleBlip", "Blip", ConstructorVehicleBlip, [](v8::Local tpl) { +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); + +// v8::Local proto = tpl->PrototypeTemplate(); +// }); diff --git a/src/bindings/Discord.cpp b/src/bindings/Discord.cpp new file mode 100644 index 00000000..c5d07f9a --- /dev/null +++ b/src/bindings/Discord.cpp @@ -0,0 +1,54 @@ + +#include "../CV8Resource.h" +#include "../helpers/V8Class.h" +#include "../helpers/V8Helpers.h" + +struct DiscordRequestOAuth2TokenCallbackData +{ + CV8ResourceImpl *resource; + v8::Persistent resolver; +}; + +static void CurrentUserGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Local ctx = isolate->GetEnteredContext(); + + auto discord = alt::ICore::Instance().GetDiscordManager(); + if (discord->IsUserDataReady()) + { + v8::Local discordInfo = v8::Object::New(isolate); + + discordInfo->Set( + ctx, + v8::String::NewFromUtf8(isolate, "id").ToLocalChecked(), + v8::String::NewFromUtf8(isolate, discord->GetUserID().CStr()).ToLocalChecked()); + + discordInfo->Set( + ctx, + v8::String::NewFromUtf8(isolate, "name").ToLocalChecked(), + v8::String::NewFromUtf8(isolate, discord->GetUsername().CStr()).ToLocalChecked()); + + discordInfo->Set( + ctx, + v8::String::NewFromUtf8(isolate, "discriminator").ToLocalChecked(), + v8::String::NewFromUtf8(isolate, discord->GetDiscriminator().CStr()).ToLocalChecked()); + + discordInfo->Set( + ctx, + v8::String::NewFromUtf8(isolate, "avatar").ToLocalChecked(), + v8::String::NewFromUtf8(isolate, discord->GetAvatar().CStr()).ToLocalChecked()); + + info.GetReturnValue().Set(discordInfo); + } + else + { + info.GetReturnValue().Set(v8::Null(isolate)); + } +} + +static V8Class v8Discord("Discord", "", nullptr, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8::SetStaticAccessor(isolate, tpl, "currentUser", &CurrentUserGetter); +}); diff --git a/src/bindings/Handling.cpp b/src/bindings/Handling.cpp new file mode 100644 index 00000000..840c0891 --- /dev/null +++ b/src/bindings/Handling.cpp @@ -0,0 +1,2183 @@ + +// #include "../CV8Resource.h" +// #include "../helpers/V8Helpers.h" +// #include "../helpers/V8Class.h" +// #include "../helpers/V8Entity.h" +// #include "../helpers/V8ResourceImpl.h" +// #include "cpp-sdk/entities/IVehicle.h" + +// static void Constructor(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(info.IsConstructCall(), "Handling constructor is not a function"); +// V8_CHECK(info.Length() == 1, "new Handling(...) expects 1 arg"); + +// V8_CHECK(info[0]->IsObject(), "vehicle must be an object"); +// auto objVehicle = info[0]->ToObject(ctx).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// info.This()->SetInternalField(0, info[0]); +// } + +// static void IsModified(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As().Get(); + +// V8_RETURN_BOOLEAN(netVehicle->customHandling != nullptr); +// } + +// static void Reset(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto refVehicle = v8vehicle->GetHandle().As(); + +// CHandlingData::Reset(refVehicle); +// } + +// static void HandlingNameHashGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->HandlingNameHash)); +// } + +// static void MassGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->Mass)); +// } + +// static void MassSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "mass must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->Mass = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void InitialDragCoeffGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->InitialDragCoeff)); +// } + +// static void InitialDragCoeffSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "initialDragCoeff must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->InitialDragCoeff = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void DownforceModifierGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->DownforceModifier)); +// } + +// static void DownforceModifierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "downforceModifier must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->DownforceModifier = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void unkFloat1Getter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->unkFloat1)); +// } + +// static void unkFloat1Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "unkFloat1 must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->unkFloat1 = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void unkFloat2Getter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->unkFloat2)); +// } + +// static void unkFloat2Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "unkFloat2 must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->unkFloat2 = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void CentreOfMassOffsetGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(resource->CreateVector3(((CHandlingData *)vehicle->GetHandling())->CentreOfMassOffset)); +// } + +// static void CentreOfMassOffsetSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// V8_CHECK(val->IsObject(), "centreOfMassOffset must be a Vector3"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// v8::Local pos = val.As(); + +// v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); +// v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); +// v8::Local z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + +// ((CHandlingData *)vehicle->GetHandling())->CentreOfMassOffset = {(float)x->Value(), (float)y->Value(), (float)z->Value()}; +// } + +// static void InertiaMultiplierGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(resource->CreateVector3(((CHandlingData *)vehicle->GetHandling())->InertiaMultiplier)); +// } + +// static void InertiaMultiplierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8_CHECK(val->IsObject(), "inertiaMultiplier must be a Vector3"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// v8::Local pos = val.As(); + +// v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); +// v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); +// v8::Local z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + +// ((CHandlingData *)vehicle->GetHandling())->InertiaMultiplier = {(float)x->Value(), (float)y->Value(), (float)z->Value()}; +// } + +// static void PercentSubmergedGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->PercentSubmerged)); +// } + +// static void PercentSubmergedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "percentSubmerged must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->PercentSubmerged = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void PercentSubmergedRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->PercentSubmergedRatio)); +// } + +// static void PercentSubmergedRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "percentSubmergedRatio must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->PercentSubmergedRatio = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void DriveBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->DriveBiasFront)); +// } + +// static void DriveBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "driveBiasFront must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->DriveBiasFront = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void AccelerationGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->Acceleration)); +// } + +// static void AccelerationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "acceleration must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->Acceleration = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->InitialDriveGears)); +// } + +// static void InitialDriveGearsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "initialDriveGears must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->InitialDriveGears = val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value(); +// } + +// static void DriveInertiaGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->DriveInertia)); +// } + +// static void DriveInertiaSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "driveInertia must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->DriveInertia = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void ClutchChangeRateScaleUpShiftGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->ClutchChangeRateScaleUpShift)); +// } + +// static void ClutchChangeRateScaleUpShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "clutchChangeRateScaleUpShift must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->ClutchChangeRateScaleUpShift = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void ClutchChangeRateScaleDownShiftGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->ClutchChangeRateScaleDownShift)); +// } + +// static void ClutchChangeRateScaleDownShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "clutchChangeRateScaleDownShift must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->ClutchChangeRateScaleDownShift = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void InitialDriveForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->InitialDriveForce)); +// } + +// static void InitialDriveForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "initialDriveForce must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->InitialDriveForce = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void DriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->DriveMaxFlatVel)); +// } + +// static void DriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "driveMaxFlatVel must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->DriveMaxFlatVel = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void InitialDriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->InitialDriveMaxFlatVel)); +// } + +// static void InitialDriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "initialDriveMaxFlatVel must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->InitialDriveMaxFlatVel = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void BrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->BrakeForce)); +// } + +// static void BrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "brakeForce must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->BrakeForce = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void unkFloat4Getter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->unkFloat4)); +// } + +// static void unkFloat4Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "unkFloat4 must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->unkFloat4 = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void BrakeBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->BrakeBiasFront)); +// } + +// static void BrakeBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "brakeBiasFront must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->BrakeBiasFront = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void BrakeBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->BrakeBiasRear)); +// } + +// static void BrakeBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "brakeBiasRear must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->BrakeBiasRear = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void HandBrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->HandBrakeForce)); +// } + +// static void HandBrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "handBrakeForce must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->HandBrakeForce = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SteeringLockGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SteeringLock)); +// } + +// static void SteeringLockSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "steeringLock must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SteeringLock = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SteeringLockRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SteeringLockRatio)); +// } + +// static void SteeringLockRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "steeringLockRatio must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SteeringLockRatio = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void TractionCurveMaxGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionCurveMax)); +// } + +// static void TractionCurveMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "tractionCurveMax must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->TractionCurveMax = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void TractionCurveMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionCurveMaxRatio)); +// } + +// static void TractionCurveMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "tractionCurveMaxRatio must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->TractionCurveMaxRatio = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void TractionCurveMinGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionCurveMin)); +// } + +// static void TractionCurveMinSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "tractionCurveMin must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->TractionCurveMin = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void TractionCurveMinRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionCurveMinRatio)); +// } + +// static void TractionCurveMinRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "tractionCurveMinRatio must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->TractionCurveMinRatio = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void TractionCurveLateralGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionCurveLateral)); +// } + +// static void TractionCurveLateralSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "tractionCurveLateral must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->TractionCurveLateral = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void TractionCurveLateralRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionCurveLateralRatio)); +// } + +// static void TractionCurveLateralRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "tractionCurveLateralRatio must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->TractionCurveLateralRatio = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void TractionSpringDeltaMaxGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionSpringDeltaMax)); +// } + +// static void TractionSpringDeltaMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "tractionSpringDeltaMax must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->TractionSpringDeltaMax = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void TractionSpringDeltaMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionSpringDeltaMaxRatio)); +// } + +// static void TractionSpringDeltaMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "tractionSpringDeltaMaxRatio must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->TractionSpringDeltaMaxRatio = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void LowSpeedTractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->LowSpeedTractionLossMult)); +// } + +// static void LowSpeedTractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "lowSpeedTractionLossMult must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->LowSpeedTractionLossMult = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void CamberStiffnesssGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->CamberStiffnesss)); +// } + +// static void CamberStiffnesssSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "camberStiffnesss must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->CamberStiffnesss = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void TractionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionBiasFront)); +// } + +// static void TractionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "tractionBiasFront must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->TractionBiasFront = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void TractionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionBiasRear)); +// } + +// static void TractionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "tractionBiasRear must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->TractionBiasRear = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void TractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionLossMult)); +// } + +// static void TractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "tractionLossMult must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->TractionLossMult = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SuspensionForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionForce)); +// } + +// static void SuspensionForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "suspensionForce must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SuspensionForce = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SuspensionCompDampGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionCompDamp)); +// } + +// static void SuspensionCompDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "suspensionCompDamp must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SuspensionCompDamp = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SuspensionReboundDampGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionReboundDamp)); +// } + +// static void SuspensionReboundDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "suspensionReboundDamp must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SuspensionReboundDamp = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SuspensionUpperLimitGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionUpperLimit)); +// } + +// static void SuspensionUpperLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "suspensionUpperLimit must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SuspensionUpperLimit = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SuspensionLowerLimitGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionLowerLimit)); +// } + +// static void SuspensionLowerLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "suspensionLowerLimit must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SuspensionLowerLimit = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SuspensionRaiseGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionRaise)); +// } + +// static void SuspensionRaiseSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "suspensionRaise must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SuspensionRaise = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SuspensionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionBiasFront)); +// } + +// static void SuspensionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "suspensionBiasFront must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SuspensionBiasFront = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SuspensionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionBiasRear)); +// } + +// static void SuspensionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "suspensionBiasRear must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SuspensionBiasRear = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void AntiRollBarForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->AntiRollBarForce)); +// } + +// static void AntiRollBarForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "antiRollBarForce must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->AntiRollBarForce = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void AntiRollBarBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->AntiRollBarBiasFront)); +// } + +// static void AntiRollBarBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "antiRollBarBiasFront must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->AntiRollBarBiasFront = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void AntiRollBarBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->AntiRollBarBiasRear)); +// } + +// static void AntiRollBarBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "antiRollBarBiasRear must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->AntiRollBarBiasRear = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void RollCentreHeightFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->RollCentreHeightFront)); +// } + +// static void RollCentreHeightFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "rollCentreHeightFront must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->RollCentreHeightFront = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void RollCentreHeightRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->RollCentreHeightRear)); +// } + +// static void RollCentreHeightRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "rollCentreHeightRear must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->RollCentreHeightRear = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void CollisionDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->CollisionDamageMult)); +// } + +// static void CollisionDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "collisionDamageMult must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->CollisionDamageMult = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void WeaponDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->WeaponDamageMult)); +// } + +// static void WeaponDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "weaponDamageMult must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->WeaponDamageMult = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void DeformationDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->DeformationDamageMult)); +// } + +// static void DeformationDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "deformationDamageMult must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->DeformationDamageMult = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void EngineDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->EngineDamageMult)); +// } + +// static void EngineDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "engineDamageMult must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->EngineDamageMult = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void PetrolTankVolumeGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->PetrolTankVolume)); +// } + +// static void PetrolTankVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "petrolTankVolume must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->PetrolTankVolume = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void OilVolumeGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->OilVolume)); +// } + +// static void OilVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "oilVolume must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->OilVolume = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void unkFloat5Getter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->unkFloat5)); +// } + +// static void unkFloat5Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "unkFloat5 must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->unkFloat5 = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SeatOffsetDistXGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SeatOffsetDistX)); +// } + +// static void SeatOffsetDistXSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "seatOffsetDistX must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SeatOffsetDistX = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SeatOffsetDistYGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SeatOffsetDistY)); +// } + +// static void SeatOffsetDistYSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "seatOffsetDistY must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SeatOffsetDistY = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void SeatOffsetDistZGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SeatOffsetDistZ)); +// } + +// static void SeatOffsetDistZSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "seatOffsetDistZ must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->SeatOffsetDistZ = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void MonetaryValueGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->MonetaryValue)); +// } + +// static void MonetaryValueSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "monetaryValue must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->MonetaryValue = val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value(); +// } + +// static void ModelFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->ModelFlags)); +// } + +// static void ModelFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "modelFlags must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->ModelFlags = val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value(); +// } + +// static void HandlingFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->HandlingFlags)); +// } + +// static void HandlingFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "handlingFlags must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->HandlingFlags = val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value(); +// } + +// static void DamageFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->DamageFlags)); +// } + +// static void DamageFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "damageFlags must be a number"); + +// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// auto v8vehicle = V8Entity::Get(objVehicle); +// V8_CHECK(v8vehicle, "entity is invalid"); + +// auto netVehicle = v8vehicle->GetHandle().As(); +// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); +// CHandlingData::Replace(netVehicle); + +// ((CHandlingData *)vehicle->GetHandling())->DamageFlags = val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value(); +// } + +// static V8Class v8HandlingData( +// "Handling", "", Constructor, [](v8::Local tpl) { +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); + +// v8::Local proto = tpl->PrototypeTemplate(); + +// tpl->InstanceTemplate()->SetInternalFieldCount(1); + +// proto->Set(isolate, "isModified", v8::FunctionTemplate::New(isolate, &IsModified)); +// proto->Set(isolate, "reset", v8::FunctionTemplate::New(isolate, &Reset)); + +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingNameHash").ToLocalChecked(), &HandlingNameHashGetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "mass").ToLocalChecked(), &MassGetter, &MassSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDragCoeff").ToLocalChecked(), &InitialDragCoeffGetter, &InitialDragCoeffSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "downforceModifier").ToLocalChecked(), &DownforceModifierGetter, &DownforceModifierSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat1").ToLocalChecked(), &unkFloat1Getter, &unkFloat1Setter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat2").ToLocalChecked(), &unkFloat2Getter, &unkFloat2Setter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "centreOfMassOffset").ToLocalChecked(), &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "inertiaMultiplier").ToLocalChecked(), &InertiaMultiplierGetter, &InertiaMultiplierSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmerged").ToLocalChecked(), &PercentSubmergedGetter, &PercentSubmergedSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmergedRatio").ToLocalChecked(), &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveBiasFront").ToLocalChecked(), &DriveBiasFrontGetter, &DriveBiasFrontSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "acceleration").ToLocalChecked(), &AccelerationGetter, &AccelerationSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveGears").ToLocalChecked(), &InitialDriveGearsGetter, &InitialDriveGearsSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveInertia").ToLocalChecked(), &DriveInertiaGetter, &DriveInertiaSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleUpShift").ToLocalChecked(), &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleDownShift").ToLocalChecked(), &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveForce").ToLocalChecked(), &InitialDriveForceGetter, &InitialDriveForceSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveMaxFlatVel").ToLocalChecked(), &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveMaxFlatVel").ToLocalChecked(), &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeForce").ToLocalChecked(), &BrakeForceGetter, &BrakeForceSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat4").ToLocalChecked(), &unkFloat4Getter, &unkFloat4Setter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasFront").ToLocalChecked(), &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasRear").ToLocalChecked(), &BrakeBiasRearGetter, &BrakeBiasRearSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handBrakeForce").ToLocalChecked(), &HandBrakeForceGetter, &HandBrakeForceSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLock").ToLocalChecked(), &SteeringLockGetter, &SteeringLockSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLockRatio").ToLocalChecked(), &SteeringLockRatioGetter, &SteeringLockRatioSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMax").ToLocalChecked(), &TractionCurveMaxGetter, &TractionCurveMaxSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMaxRatio").ToLocalChecked(), &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMin").ToLocalChecked(), &TractionCurveMinGetter, &TractionCurveMinSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMinRatio").ToLocalChecked(), &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateral").ToLocalChecked(), &TractionCurveLateralGetter, &TractionCurveLateralSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateralRatio").ToLocalChecked(), &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMax").ToLocalChecked(), &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMaxRatio").ToLocalChecked(), &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lowSpeedTractionLossMult").ToLocalChecked(), &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "camberStiffnesss").ToLocalChecked(), &CamberStiffnesssGetter, &CamberStiffnesssSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasFront").ToLocalChecked(), &TractionBiasFrontGetter, &TractionBiasFrontSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasRear").ToLocalChecked(), &TractionBiasRearGetter, &TractionBiasRearSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionLossMult").ToLocalChecked(), &TractionLossMultGetter, &TractionLossMultSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionForce").ToLocalChecked(), &SuspensionForceGetter, &SuspensionForceSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionCompDamp").ToLocalChecked(), &SuspensionCompDampGetter, &SuspensionCompDampSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionReboundDamp").ToLocalChecked(), &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionUpperLimit").ToLocalChecked(), &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionLowerLimit").ToLocalChecked(), &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionRaise").ToLocalChecked(), &SuspensionRaiseGetter, &SuspensionRaiseSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasFront").ToLocalChecked(), &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasRear").ToLocalChecked(), &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarForce").ToLocalChecked(), &AntiRollBarForceGetter, &AntiRollBarForceSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasFront").ToLocalChecked(), &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasRear").ToLocalChecked(), &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightFront").ToLocalChecked(), &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightRear").ToLocalChecked(), &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "collisionDamageMult").ToLocalChecked(), &CollisionDamageMultGetter, &CollisionDamageMultSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "weaponDamageMult").ToLocalChecked(), &WeaponDamageMultGetter, &WeaponDamageMultSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "deformationDamageMult").ToLocalChecked(), &DeformationDamageMultGetter, &DeformationDamageMultSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "engineDamageMult").ToLocalChecked(), &EngineDamageMultGetter, &EngineDamageMultSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "petrolTankVolume").ToLocalChecked(), &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "oilVolume").ToLocalChecked(), &OilVolumeGetter, &OilVolumeSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat5").ToLocalChecked(), &unkFloat5Getter, &unkFloat5Setter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistX").ToLocalChecked(), &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistY").ToLocalChecked(), &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistZ").ToLocalChecked(), &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "monetaryValue").ToLocalChecked(), &MonetaryValueGetter, &MonetaryValueSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modelFlags").ToLocalChecked(), &ModelFlagsGetter, &ModelFlagsSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingFlags").ToLocalChecked(), &HandlingFlagsGetter, &HandlingFlagsSetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "damageFlags").ToLocalChecked(), &DamageFlagsGetter, &DamageFlagsSetter); +// }, +// false); \ No newline at end of file diff --git a/src/bindings/HandlingData.cpp b/src/bindings/HandlingData.cpp new file mode 100644 index 00000000..7a9150c8 --- /dev/null +++ b/src/bindings/HandlingData.cpp @@ -0,0 +1,1774 @@ + +#include "../CV8Resource.h" +#include "../helpers/V8Class.h" + +static void Constructor(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.IsConstructCall(), "HandlingData constructor is not a function"); + V8_CHECK(info.Length() == 1, "new HandlingData(...) expects 1 arg"); + + V8_CHECK(info[0]->IsNumber(), "modelHash must be a number"); + uint32_t modelHash = info[0]->Uint32Value(ctx).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "model doesn't exist"); + + info.This()->SetInternalField(0, info[0]); +} + +static void GetForHandlingName(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 1, "HandlingData.getForHandlingName expects 1 arg"); + V8_CHECK(info[0]->IsNumber(), "modelHash must be a number"); + uint32_t modelHash = info[0]->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + static V8Class *handlingDataClass = V8Class::Get("HandlingData"); + + std::vector> args{ + v8::Number::New(isolate, modelHash)}; + + info.GetReturnValue().Set(handlingDataClass->New(isolate->GetEnteredContext(), args)); +} + +static void HandlingNameHashGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetHandlingNameHash())); +} + +static void MassGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetMass())); +} + +static void MassSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "mass must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetMass((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void InitialDragCoeffGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetInitialDragCoeff())); +} + +static void InitialDragCoeffSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "initialDragCoeff must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetInitialDragCoeff((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void DownforceModifierGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetDownforceModifier())); +} + +static void DownforceModifierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "downforceModifier must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetDownforceModifier((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void unkFloat1Getter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetunkFloat1())); +} + +static void unkFloat1Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "unkFloat1 must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetunkFloat1((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void unkFloat2Getter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetunkFloat2())); +} + +static void unkFloat2Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "unkFloat2 must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetunkFloat2((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void CentreOfMassOffsetGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(resource->CreateVector3(handling->GetCentreOfMassOffset())); +} + +static void CentreOfMassOffsetSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + V8_CHECK(val->IsObject(), "centreOfMassOffset must be a Vector3"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + v8::Local pos = val.As(); + + v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + + handling->SetCentreOfMassOffset({(float)x->Value(), (float)y->Value(), (float)z->Value()}); +} + +static void InertiaMultiplierGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(resource->CreateVector3(handling->GetInertiaMultiplier())); +} + +static void InertiaMultiplierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + V8_CHECK(val->IsObject(), "inertiaMultiplier must be a Vector3"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + v8::Local pos = val.As(); + + v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + + handling->SetInertiaMultiplier({(float)x->Value(), (float)y->Value(), (float)z->Value()}); +} + +static void PercentSubmergedGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetPercentSubmerged())); +} + +static void PercentSubmergedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "percentSubmerged must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetPercentSubmerged((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void PercentSubmergedRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetPercentSubmergedRatio())); +} + +static void PercentSubmergedRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "percentSubmergedRatio must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetPercentSubmergedRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void DriveBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetDriveBiasFront())); +} + +static void DriveBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "driveBiasFront must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetDriveBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void AccelerationGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetAcceleration())); +} + +static void AccelerationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "acceleration must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetAcceleration((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetInitialDriveGears())); +} + +static void InitialDriveGearsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "initialDriveGears must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetInitialDriveGears(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); +} + +static void DriveInertiaGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetDriveInertia())); +} + +static void DriveInertiaSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "driveInertia must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetDriveInertia((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void ClutchChangeRateScaleUpShiftGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetClutchChangeRateScaleUpShift())); +} + +static void ClutchChangeRateScaleUpShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "clutchChangeRateScaleUpShift must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetClutchChangeRateScaleUpShift((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void ClutchChangeRateScaleDownShiftGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetClutchChangeRateScaleDownShift())); +} + +static void ClutchChangeRateScaleDownShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "clutchChangeRateScaleDownShift must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetClutchChangeRateScaleDownShift((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void InitialDriveForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetInitialDriveForce())); +} + +static void InitialDriveForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "initialDriveForce must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetInitialDriveForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void DriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetDriveMaxFlatVel())); +} + +static void DriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "driveMaxFlatVel must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetDriveMaxFlatVel((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void InitialDriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetInitialDriveMaxFlatVel())); +} + +static void InitialDriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "initialDriveMaxFlatVel must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetInitialDriveMaxFlatVel((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void BrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetBrakeForce())); +} + +static void BrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "brakeForce must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetBrakeForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void unkFloat4Getter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetunkFloat4())); +} + +static void unkFloat4Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "unkFloat4 must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetunkFloat4((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void BrakeBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetBrakeBiasFront())); +} + +static void BrakeBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "brakeBiasFront must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetBrakeBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void BrakeBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetBrakeBiasRear())); +} + +static void BrakeBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "brakeBiasRear must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetBrakeBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void HandBrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetHandBrakeForce())); +} + +static void HandBrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "handBrakeForce must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetHandBrakeForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SteeringLockGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSteeringLock())); +} + +static void SteeringLockSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "steeringLock must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSteeringLock((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SteeringLockRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSteeringLockRatio())); +} + +static void SteeringLockRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "steeringLockRatio must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSteeringLockRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void TractionCurveMaxGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionCurveMax())); +} + +static void TractionCurveMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionCurveMax must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetTractionCurveMax((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void TractionCurveMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionCurveMaxRatio())); +} + +static void TractionCurveMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionCurveMaxRatio must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetTractionCurveMaxRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void TractionCurveMinGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionCurveMin())); +} + +static void TractionCurveMinSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionCurveMin must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetTractionCurveMin((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void TractionCurveMinRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionCurveMinRatio())); +} + +static void TractionCurveMinRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionCurveMinRatio must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetTractionCurveMinRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void TractionCurveLateralGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionCurveLateral())); +} + +static void TractionCurveLateralSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionCurveLateral must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetTractionCurveLateral((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void TractionCurveLateralRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionCurveLateralRatio())); +} + +static void TractionCurveLateralRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionCurveLateralRatio must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetTractionCurveLateralRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void TractionSpringDeltaMaxGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionSpringDeltaMax())); +} + +static void TractionSpringDeltaMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionSpringDeltaMax must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetTractionSpringDeltaMax((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void TractionSpringDeltaMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionSpringDeltaMaxRatio())); +} + +static void TractionSpringDeltaMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionSpringDeltaMaxRatio must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetTractionSpringDeltaMaxRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void LowSpeedTractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetLowSpeedTractionLossMult())); +} + +static void LowSpeedTractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "lowSpeedTractionLossMult must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetLowSpeedTractionLossMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void CamberStiffnesssGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetCamberStiffnesss())); +} + +static void CamberStiffnesssSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "camberStiffnesss must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetCamberStiffnesss((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void TractionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionBiasFront())); +} + +static void TractionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionBiasFront must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetTractionBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void TractionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionBiasRear())); +} + +static void TractionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionBiasRear must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetTractionBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void TractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionLossMult())); +} + +static void TractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionLossMult must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetTractionLossMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SuspensionForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionForce())); +} + +static void SuspensionForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionForce must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSuspensionForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SuspensionCompDampGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionCompDamp())); +} + +static void SuspensionCompDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionCompDamp must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSuspensionCompDamp((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SuspensionReboundDampGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionReboundDamp())); +} + +static void SuspensionReboundDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionReboundDamp must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSuspensionReboundDamp((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SuspensionUpperLimitGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionUpperLimit())); +} + +static void SuspensionUpperLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionUpperLimit must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSuspensionUpperLimit((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SuspensionLowerLimitGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionLowerLimit())); +} + +static void SuspensionLowerLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionLowerLimit must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSuspensionLowerLimit((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SuspensionRaiseGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionRaise())); +} + +static void SuspensionRaiseSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionRaise must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSuspensionRaise((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SuspensionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionBiasFront())); +} + +static void SuspensionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionBiasFront must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSuspensionBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SuspensionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionBiasRear())); +} + +static void SuspensionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionBiasRear must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSuspensionBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void AntiRollBarForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetAntiRollBarForce())); +} + +static void AntiRollBarForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "antiRollBarForce must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetAntiRollBarForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void AntiRollBarBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetAntiRollBarBiasFront())); +} + +static void AntiRollBarBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "antiRollBarBiasFront must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetAntiRollBarBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void AntiRollBarBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetAntiRollBarBiasRear())); +} + +static void AntiRollBarBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "antiRollBarBiasRear must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetAntiRollBarBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void RollCentreHeightFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetRollCentreHeightFront())); +} + +static void RollCentreHeightFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "rollCentreHeightFront must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetRollCentreHeightFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void RollCentreHeightRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetRollCentreHeightRear())); +} + +static void RollCentreHeightRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "rollCentreHeightRear must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetRollCentreHeightRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void CollisionDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetCollisionDamageMult())); +} + +static void CollisionDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "collisionDamageMult must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetCollisionDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void WeaponDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetWeaponDamageMult())); +} + +static void WeaponDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "weaponDamageMult must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetWeaponDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void DeformationDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetDeformationDamageMult())); +} + +static void DeformationDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "deformationDamageMult must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetDeformationDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void EngineDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetEngineDamageMult())); +} + +static void EngineDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "engineDamageMult must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetEngineDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void PetrolTankVolumeGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetPetrolTankVolume())); +} + +static void PetrolTankVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "petrolTankVolume must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetPetrolTankVolume((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void OilVolumeGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetOilVolume())); +} + +static void OilVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "oilVolume must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetOilVolume((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void unkFloat5Getter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetunkFloat5())); +} + +static void unkFloat5Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "unkFloat5 must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetunkFloat5((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SeatOffsetDistXGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSeatOffsetDistX())); +} + +static void SeatOffsetDistXSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "seatOffsetDistX must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSeatOffsetDistX((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SeatOffsetDistYGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSeatOffsetDistY())); +} + +static void SeatOffsetDistYSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "seatOffsetDistY must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSeatOffsetDistY((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void SeatOffsetDistZGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSeatOffsetDistZ())); +} + +static void SeatOffsetDistZSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "seatOffsetDistZ must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetSeatOffsetDistZ((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} + +static void MonetaryValueGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetMonetaryValue())); +} + +static void MonetaryValueSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "monetaryValue must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetMonetaryValue(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); +} + +static void ModelFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetModelFlags())); +} + +static void ModelFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "modelFlags must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetModelFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); +} + +static void HandlingFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetHandlingFlags())); +} + +static void HandlingFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "handlingFlags must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetHandlingFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); +} + +static void DamageFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetDamageFlags())); +} + +static void DamageFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "damageFlags must be a number"); + + uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + handling->SetDamageFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); +} + +static V8Class v8HandlingData( + "HandlingData", "", Constructor, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + v8::Local proto = tpl->PrototypeTemplate(); + + tpl->InstanceTemplate()->SetInternalFieldCount(1); + + tpl->Set(isolate, "getForHandlingName", v8::FunctionTemplate::New(isolate, &GetForHandlingName)); + + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingNameHash").ToLocalChecked(), &HandlingNameHashGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "mass").ToLocalChecked(), &MassGetter, &MassSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDragCoeff").ToLocalChecked(), &InitialDragCoeffGetter, &InitialDragCoeffSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "downforceModifier").ToLocalChecked(), &DownforceModifierGetter, &DownforceModifierSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat1").ToLocalChecked(), &unkFloat1Getter, &unkFloat1Setter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat2").ToLocalChecked(), &unkFloat2Getter, &unkFloat2Setter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "centreOfMassOffset").ToLocalChecked(), &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "inertiaMultiplier").ToLocalChecked(), &InertiaMultiplierGetter, &InertiaMultiplierSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmerged").ToLocalChecked(), &PercentSubmergedGetter, &PercentSubmergedSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmergedRatio").ToLocalChecked(), &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveBiasFront").ToLocalChecked(), &DriveBiasFrontGetter, &DriveBiasFrontSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "acceleration").ToLocalChecked(), &AccelerationGetter, &AccelerationSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveGears").ToLocalChecked(), &InitialDriveGearsGetter, &InitialDriveGearsSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveInertia").ToLocalChecked(), &DriveInertiaGetter, &DriveInertiaSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleUpShift").ToLocalChecked(), &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleDownShift").ToLocalChecked(), &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveForce").ToLocalChecked(), &InitialDriveForceGetter, &InitialDriveForceSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveMaxFlatVel").ToLocalChecked(), &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveMaxFlatVel").ToLocalChecked(), &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeForce").ToLocalChecked(), &BrakeForceGetter, &BrakeForceSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat4").ToLocalChecked(), &unkFloat4Getter, &unkFloat4Setter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasFront").ToLocalChecked(), &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasRear").ToLocalChecked(), &BrakeBiasRearGetter, &BrakeBiasRearSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handBrakeForce").ToLocalChecked(), &HandBrakeForceGetter, &HandBrakeForceSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLock").ToLocalChecked(), &SteeringLockGetter, &SteeringLockSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLockRatio").ToLocalChecked(), &SteeringLockRatioGetter, &SteeringLockRatioSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMax").ToLocalChecked(), &TractionCurveMaxGetter, &TractionCurveMaxSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMaxRatio").ToLocalChecked(), &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMin").ToLocalChecked(), &TractionCurveMinGetter, &TractionCurveMinSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMinRatio").ToLocalChecked(), &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateral").ToLocalChecked(), &TractionCurveLateralGetter, &TractionCurveLateralSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateralRatio").ToLocalChecked(), &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMax").ToLocalChecked(), &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMaxRatio").ToLocalChecked(), &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lowSpeedTractionLossMult").ToLocalChecked(), &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "camberStiffnesss").ToLocalChecked(), &CamberStiffnesssGetter, &CamberStiffnesssSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasFront").ToLocalChecked(), &TractionBiasFrontGetter, &TractionBiasFrontSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasRear").ToLocalChecked(), &TractionBiasRearGetter, &TractionBiasRearSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionLossMult").ToLocalChecked(), &TractionLossMultGetter, &TractionLossMultSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionForce").ToLocalChecked(), &SuspensionForceGetter, &SuspensionForceSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionCompDamp").ToLocalChecked(), &SuspensionCompDampGetter, &SuspensionCompDampSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionReboundDamp").ToLocalChecked(), &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionUpperLimit").ToLocalChecked(), &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionLowerLimit").ToLocalChecked(), &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionRaise").ToLocalChecked(), &SuspensionRaiseGetter, &SuspensionRaiseSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasFront").ToLocalChecked(), &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasRear").ToLocalChecked(), &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarForce").ToLocalChecked(), &AntiRollBarForceGetter, &AntiRollBarForceSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasFront").ToLocalChecked(), &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasRear").ToLocalChecked(), &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightFront").ToLocalChecked(), &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightRear").ToLocalChecked(), &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "collisionDamageMult").ToLocalChecked(), &CollisionDamageMultGetter, &CollisionDamageMultSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "weaponDamageMult").ToLocalChecked(), &WeaponDamageMultGetter, &WeaponDamageMultSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "deformationDamageMult").ToLocalChecked(), &DeformationDamageMultGetter, &DeformationDamageMultSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "engineDamageMult").ToLocalChecked(), &EngineDamageMultGetter, &EngineDamageMultSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "petrolTankVolume").ToLocalChecked(), &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "oilVolume").ToLocalChecked(), &OilVolumeGetter, &OilVolumeSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat5").ToLocalChecked(), &unkFloat5Getter, &unkFloat5Setter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistX").ToLocalChecked(), &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistY").ToLocalChecked(), &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistZ").ToLocalChecked(), &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "monetaryValue").ToLocalChecked(), &MonetaryValueGetter, &MonetaryValueSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modelFlags").ToLocalChecked(), &ModelFlagsGetter, &ModelFlagsSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingFlags").ToLocalChecked(), &HandlingFlagsGetter, &HandlingFlagsSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "damageFlags").ToLocalChecked(), &DamageFlagsGetter, &DamageFlagsSetter); + }, + false); diff --git a/src/bindings/LocalStorage.cpp b/src/bindings/LocalStorage.cpp new file mode 100644 index 00000000..6a9f9cb1 --- /dev/null +++ b/src/bindings/LocalStorage.cpp @@ -0,0 +1,96 @@ + +#include "../helpers/V8Class.h" +#include "../helpers/V8Helpers.h" +#include "../helpers/V8ResourceImpl.h" +#include "../CV8Resource.h" +#include "cpp-sdk/SDK.h" + +static void StaticGet(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + info.GetReturnValue().Set(static_cast(resource)->GetLocalStorage()); +} + +static void Get(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + alt::MValueConst val = resource->GetLocalStorage()->Get(key); + + info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); +} + +static void Set(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + + alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + alt::MValue val = V8Helpers::V8ToMValue(info[1]); + + resource->GetLocalStorage()->Set(key, val); +} + +static void Delete(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + resource->GetLocalStorage()->Delete(key); +} + +static void DeleteAll(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + resource->GetLocalStorage()->Clear(); +} + +static void Save(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + V8_CHECK(resource->GetLocalStorage()->Save(), "exceeded max local storage size (4MB)"); +} + +static V8Class v8LocalStorage( + "LocalStorage", "", nullptr, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + tpl->Set(isolate, "get", v8::FunctionTemplate::New(isolate, &StaticGet)); + + v8::Local proto = tpl->PrototypeTemplate(); + + proto->Set(isolate, "get", v8::FunctionTemplate::New(isolate, &Get)); + proto->Set(isolate, "set", v8::FunctionTemplate::New(isolate, &Set)); + proto->Set(isolate, "delete", v8::FunctionTemplate::New(isolate, &Delete)); + proto->Set(isolate, "deleteAll", v8::FunctionTemplate::New(isolate, &DeleteAll)); + proto->Set(isolate, "save", v8::FunctionTemplate::New(isolate, &Save)); + }, + false); diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp new file mode 100644 index 00000000..4de1bd50 --- /dev/null +++ b/src/bindings/Main.cpp @@ -0,0 +1,903 @@ + +#include "../CV8ScriptRuntime.h" +#include "cpp-sdk/entities/IPlayer.h" +#include "../helpers/V8Module.h" + +#include "cpp-sdk/SDK.h" + +#include "../helpers/Log.h" + +using namespace alt; + +static void OnServer(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 2, "onServer expects 2 args"); + V8_CHECK(info[0]->IsString(), "eventName must be a string"); + V8_CHECK(info[1]->IsFunction(), "callback must be a function"); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + v8::Local callback = info[1].As(); + + resource->SubscribeRemote(evName, callback, V8::SourceLocation::GetCurrent(isolate)); +} + +static void OffServer(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 2, "onServer expects 2 args"); + V8_CHECK(info[0]->IsString(), "eventName must be a string"); + V8_CHECK(info[1]->IsFunction(), "callback must be a function"); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + v8::Local callback = info[1].As(); + + resource->UnsubscribeRemote(evName, callback); +} + +static void EmitServer(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() >= 1, "emitServer expects at least 1 arg"); + V8_CHECK(info[0]->IsString(), "eventName must be a string"); + + std::string name = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + alt::MValueArgs args; + + for (int i = 1; i < info.Length(); ++i) + args.Push(V8Helpers::V8ToMValue(info[i])); + + alt::ICore::Instance().TriggerServerEvent(name, args); +} + +/** +type: 'function', +name: 'gameControlsEnabled', +description: 'Returns a bool if is game controls enabled', +returns: { + dataType: 'bool', + description: 'If is game controls enabled' +} +*/ +static void GameControlsEnabled(const v8::FunctionCallbackInfo &info) +{ + info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), alt::ICore::Instance().AreControlsEnabled())); +} + +/** +type: 'function', +name: 'toggleGameControls', +description: 'Toggles a game controls', +parameters: [ + { + name: 'state', + dataType: 'bool', + description: '`true` for enable controls, `false` to disable controls' + } +] +*/ +static void ToggleGameControls(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 1, "toggleGameControls expects 1 arg"); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + CV8ResourceImpl *jsResource = static_cast(resource); + bool state = info[0]->ToBoolean(isolate)->Value(); + + jsResource->ToggleGameControls(state); +} + +static void ToggleVoiceControls(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 1, "toggleVoiceControls expects 1 arg"); + + /*V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + CV8ResourceImpl* jsResource = static_cast(resource);*/ + + bool state = info[0]->ToBoolean(isolate)->Value(); + + // TODO: make it resource-bound + //jsResource->ToggleGameControls(state); + alt::ICore::Instance().ToggleVoiceControls(state); +} + +static void ShowCursor(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() >= 1, "showCursor expects 1 or 2 args"); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + CV8ResourceImpl *jsResource = static_cast(resource); + bool state = info[0]->ToBoolean(isolate)->Value(); + + if (!jsResource->ToggleCursor(state)) + { + if (alt::ICore::Instance().IsDebug()) + { + V8Helpers::Throw(isolate, "Cursor state can't go < 0"); + } + else + { + Log::Warning << "Cursor state can't go < 0"; + } + } +} + +static void CursorPosGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + alt::Vector2i pos = alt::ICore::Instance().GetCursorPosition(); + + v8::Local obj = v8::Object::New(isolate); + + obj->Set(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked(), v8::Integer::New(isolate, pos[0])); + obj->Set(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked(), v8::Integer::New(isolate, pos[1])); + + info.GetReturnValue().Set(obj); +} + +static void CursorPosSetter(v8::Local name, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(val->IsObject(), "cursorPos must be a object"); + + v8::Local x = val.As()->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked(); + v8::Local y = val.As()->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked(); + + ICore::Instance().SetCursorPosition({x->ToInteger(ctx).ToLocalChecked()->Value(), + y->ToInteger(ctx).ToLocalChecked()->Value()}); +} + +static void LoadModel(const v8::FunctionCallbackInfo &info) +{ + Log::Warning << "loadModel is deprecated, this function has no effect" << Log::Endl; +} + +static void LoadModelAsync(const v8::FunctionCallbackInfo &info) +{ + Log::Warning << "loadModelAsync is deprecated, this function has no effect" << Log::Endl; +} + +static void IsTextureExistInArchetype(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + + v8::Local modelHash = info[0]->ToInteger(ctx).ToLocalChecked(); + std::string modelName = *v8::String::Utf8Value(info.GetIsolate(), info[1].As()); + + void *texture = ICore::Instance().GetTextureFromDrawable(modelHash->Value(), modelName); + + info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), texture != nullptr)); +} + +static void RequestIPL(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + std::string iplName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + + ICore::Instance().RequestIPL(iplName.c_str()); +} + +static void RemoveIPL(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + std::string iplName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + + ICore::Instance().RemoveIPL(iplName.c_str()); +} + +static void GetLicenseHash(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + auto ctx = isolate->GetEnteredContext(); + + auto licenseHash = ICore::Instance().GetLicenseHash(); + info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, licenseHash.CStr()).ToLocalChecked()); +} + +static void SetCamFrozen(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + v8::Local state = info[0]->ToBoolean(isolate); + + ICore::Instance().SetCamFrozen(state->Value()); +} + +// static void IsInSandbox(const v8::FunctionCallbackInfo &info) +// { +// info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), CGame::Instance().IsSandbox())); +// } + +static void IsInDebug(const v8::FunctionCallbackInfo &info) +{ + info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), alt::ICore::Instance().IsDebug())); +} + +static void IsVoiceActivityInputEnabled(const v8::FunctionCallbackInfo &info) +{ + info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), ICore::Instance().IsVoiceActivationEnabled())); +} + +static void AddGxtText(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + + std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + std::string textValue = *v8::String::Utf8Value(info.GetIsolate(), info[1].As()); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + static_cast(resource)->AddGxtText(ICore::Instance().Hash(key), textValue); +} + +static void RemoveGxtText(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + + V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); + V8_CHECK(resource, "Invalid resource"); + static_cast(resource)->RemoveGxtText(ICore::Instance().Hash(key)); +} + +static void GetGxtText(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + std::string text = static_cast(resource)->GetGxtText(ICore::Instance().Hash(key)); + info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, text.c_str()).ToLocalChecked()); +} + +static void GetMsPerGameMinute(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + int32_t ms = ICore::Instance().GetMsPerGameMinute(); + info.GetReturnValue().Set(v8::Integer::New(isolate, ms)); +} + +static void SetMsPerGameMinute(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + v8::Local ms = info[0]->ToInteger(ctx).ToLocalChecked(); + ICore::Instance().SetMsPerGameMinute(ms->Value()); +} + +static void BeginScaleformMovieMethodMinimap(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + std::string methodName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + bool result = ICore::Instance().BeginScaleformMovieMethodMinimap(methodName.c_str()); + info.GetReturnValue().Set(v8::Boolean::New(isolate, result)); +} + +static void GetLocale(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + auto locale = ICore::Instance().GetLocale(); + + info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, locale.CStr()).ToLocalChecked()); +} + +static void SetWeatherCycle(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + V8_CHECK(info[0]->IsArray(), "weathers must be an array"); + V8_CHECK(info[1]->IsArray(), "timeMultipliers must be an array"); + + v8::Local weathers = info[0].As(); + v8::Local multipliers = info[1].As(); + + V8_CHECK(weathers->Length() <= 256, "weathers count must be <= 256"); + V8_CHECK(multipliers->Length() <= 256, "multipliers count must be <= 256"); + V8_CHECK(weathers->Length() == multipliers->Length(), "weathers count and multipliers count must be the same"); + + Array weathersVec; + Array multipliersVec; + + for (int i = 0; i < weathers->Length(); ++i) + { + v8::Local weatherVal = weathers->Get(ctx, i).ToLocalChecked(); + uint32_t weatherNum = weatherVal->ToUint32(ctx).ToLocalChecked()->Value(); + V8_CHECK(weatherNum >= 0 && weatherNum <= 14, "weather ids must be >= 0 && <= 14"); + weathersVec.Push(weatherNum); + + v8::Local multiplierVal = multipliers->Get(ctx, i).ToLocalChecked(); + uint32_t multiplierNum = multiplierVal->ToUint32(ctx).ToLocalChecked()->Value(); + V8_CHECK(multiplierNum > 0 && multiplierNum <= 720, "multipliers must be > 0 && <= 720"); + multipliersVec.Push(multiplierNum); + } + + ICore::Instance().SetWeatherCycle(weathersVec, multipliersVec); +} + +static void SetWeatherSyncActive(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK(info[0]->IsBoolean(), "activeState must be boolean"); + + v8::Local isActive = info[0].As(); + + ICore::Instance().SetWeatherSyncActive(isActive->Value()); +} + +static void SetCharStat(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + V8_CHECK(info[0]->IsString(), "statName must be string"); + + std::string statName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + IStatData *targetStat = alt::ICore::Instance().GetStatData(statName); + V8_CHECK(targetStat != nullptr, "stat with this name not found"); + + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(strcmp(targetStat->GetStatType(), "NONE") != 0 && strcmp(targetStat->GetStatType(), "PROFILE_SETTING") != 0, "target stat can't be edited"); + + if (!strcmp(targetStat->GetStatType(), "INT")) + { + V8_CHECK(info[1]->IsNumber(), "value must be number"); + int32_t intValue = info[1]->ToInt32(ctx).ToLocalChecked()->Value(); + targetStat->SetInt32Value(intValue); + info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "INT64")) + { + V8_CHECK(info[1]->IsNumber(), "value must be number"); + int64_t intValue = info[1]->ToBigInt(ctx).ToLocalChecked()->Int64Value(); + targetStat->SetInt64Value(intValue); + info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "TEXTLABEL")) + { + V8_CHECK(info[1]->IsNumber(), "value must be number"); + int32_t intValue = info[1]->ToInt32(ctx).ToLocalChecked()->Value(); + targetStat->SetInt32Value(intValue); + info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "FLOAT")) + { + V8_CHECK(info[1]->IsNumber(), "value must be number"); + float floatValue = info[1]->ToNumber(ctx).ToLocalChecked()->Value(); + targetStat->SetFloatValue(floatValue); + info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "BOOL")) + { + V8_CHECK(info[1]->IsBoolean(), "value must be boolean"); + bool boolValue = info[1]->ToBoolean(isolate)->Value(); + targetStat->SetBoolValue(boolValue); + info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "STRING")) + { + V8_CHECK(info[1]->IsString(), "value must be string"); + std::string stringValue = *v8::String::Utf8Value(info.GetIsolate(), info[1].As()); + targetStat->SetStringValue(stringValue.c_str()); + info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "UINT8")) + { + V8_CHECK(info[1]->IsNumber(), "value must be number"); + uint8_t intValue = info[1]->ToUint32(ctx).ToLocalChecked()->Value(); + targetStat->SetUInt8Value(intValue); + info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "UINT16")) + { + V8_CHECK(info[1]->IsNumber(), "value must be number"); + uint16_t intValue = info[1]->ToUint32(ctx).ToLocalChecked()->Value(); + targetStat->SetUInt16Value(intValue); + info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "UINT32")) + { + V8_CHECK(info[1]->IsNumber(), "value must be number"); + uint32_t intValue = info[1]->ToUint32(ctx).ToLocalChecked()->Value(); + targetStat->SetUInt32Value(intValue); + info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + return; + } + else if ( + !strcmp(targetStat->GetStatType(), "UINT64") || + !strcmp(targetStat->GetStatType(), "POS") || + !strcmp(targetStat->GetStatType(), "DATE") || + !strcmp(targetStat->GetStatType(), "PACKED") || + !strcmp(targetStat->GetStatType(), "USERID")) + { + V8_CHECK(info[1]->IsNumber(), "value must be number"); + uint64_t intValue = info[1]->ToBigInt(ctx).ToLocalChecked()->Uint64Value(); + targetStat->SetUInt64Value(intValue); + info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + return; + } + + info.GetReturnValue().Set(v8::Boolean::New(isolate, false)); +} + +static void GetCharStat(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK(info[0]->IsString(), "statName must be string"); + + std::string statName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + IStatData *targetStat = alt::ICore::Instance().GetStatData(statName); + V8_CHECK(targetStat != nullptr, "stat with this name not found"); + + V8_CHECK(strcmp(targetStat->GetStatType(), "NONE") != 0 && strcmp(targetStat->GetStatType(), "PROFILE_SETTING") != 0, "target stat can't be readed"); + + if (!strcmp(targetStat->GetStatType(), "INT")) + { + int32_t intValue = targetStat->GetInt32Value(); + info.GetReturnValue().Set(v8::Integer::New(isolate, intValue)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "INT64")) + { + int64_t intValue = targetStat->GetInt64Value(); + info.GetReturnValue().Set(v8::BigInt::New(isolate, intValue)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "TEXTLABEL")) + { + int32_t intValue = targetStat->GetInt32Value(); + info.GetReturnValue().Set(v8::Integer::New(isolate, intValue)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "FLOAT")) + { + float floatValue = targetStat->GetFloatValue(); + info.GetReturnValue().Set(v8::Number::New(isolate, floatValue)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "BOOL")) + { + bool boolValue = targetStat->GetBoolValue(); + info.GetReturnValue().Set(v8::Boolean::New(isolate, boolValue)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "STRING")) + { + const char *stringValue = targetStat->GetStringValue(); + info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, stringValue).ToLocalChecked()); + return; + } + else if (!strcmp(targetStat->GetStatType(), "UINT8")) + { + uint8_t intValue = targetStat->GetUInt8Value(); + info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, intValue)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "UINT16")) + { + uint16_t intValue = targetStat->GetUInt16Value(); + info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, intValue)); + return; + } + else if (!strcmp(targetStat->GetStatType(), "UINT32")) + { + uint32_t intValue = targetStat->GetUInt32Value(); + info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, intValue)); + return; + } + else if ( + !strcmp(targetStat->GetStatType(), "UINT64") || + !strcmp(targetStat->GetStatType(), "POS") || + !strcmp(targetStat->GetStatType(), "DATE") || + !strcmp(targetStat->GetStatType(), "PACKED") || + !strcmp(targetStat->GetStatType(), "USERID")) + { + uint64_t intValue = targetStat->GetUInt64Value(); + info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(isolate, intValue)); + return; + } + + info.GetReturnValue().Set(v8::Null(isolate)); +} + +static void ResetCharStat(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK(info[0]->IsString(), "statName must be string"); + + std::string statName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + IStatData *targetStat = alt::ICore::Instance().GetStatData(statName); + V8_CHECK(targetStat != nullptr, "stat with this name not found"); + + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(strcmp(targetStat->GetStatType(), "NONE") != 0 && strcmp(targetStat->GetStatType(), "PROFILE_SETTING") != 0, "target stat can't be reseted"); + targetStat->Reset(); + info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); +} + +static void IsMenuOpen(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + info.GetReturnValue().Set(v8::Boolean::New(isolate, ICore::Instance().IsMenuOpen())); +} + +static void IsConsoleOpen(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + info.GetReturnValue().Set(v8::Boolean::New(isolate, ICore::Instance().IsConsoleOpen())); +} + +static void IsKeyDown(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + uint32_t keycode = info[0]->ToUint32(ctx).ToLocalChecked()->Value(); + + info.GetReturnValue().Set(v8::Boolean::New(isolate, alt::ICore::Instance().GetKeyState(keycode).IsDown())); +} + +static void IsKeyToggled(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + uint32_t keycode = info[0]->ToUint32(ctx).ToLocalChecked()->Value(); + + info.GetReturnValue().Set(v8::Boolean::New(isolate, alt::ICore::Instance().GetKeyState(keycode).IsToggled())); +} + +static void SetConfigFlag(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, flag); + V8_ARG_TO_BOOLEAN(2, state); + + ICore::Instance().SetConfigFlag(flag, state); +} + +static void GetConfigFlag(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_STRING(1, flag); + + V8_RETURN_BOOLEAN(ICore::Instance().GetConfigFlag(flag)); +} + +static void DoesConfigFlagExist(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_STRING(1, flag); + + V8_RETURN_BOOLEAN(ICore::Instance().DoesConfigFlagExist(flag)); +} + +// extern V8Class v8MemoryBuffer; +// static void GetEntityMemoryByID(const v8::FunctionCallbackInfo &info) +// { +// V8_GET_ISOLATE_CONTEXT(); + +// #ifdef NDEBUG +// auto &game = CGame::Instance(); +// V8_CHECK(game.IsDebug() && IsDevOrInternalBranch(), "Must be in debug mode and dev branch"); +// #endif + +// V8_CHECK_ARGS_LEN(1); +// V8_ARG_TO_INTEGER(1, id); + +// ::CEntity *addr = funcs::GetEntityFromScriptID<::CEntity *>(id); + +// auto buf = v8MemoryBuffer.CreateInstance(ctx); +// buf->SetAlignedPointerInInternalField(0, addr); +// buf->SetInternalField(1, v8::Integer::NewFromUnsigned(isolate, UINT32_MAX)); + +// V8_RETURN(buf); +// } + +// static void SetAngularVelocity(const v8::FunctionCallbackInfo &info) +// { +// V8_GET_ISOLATE_CONTEXT(); +// V8_CHECK_ARGS_LEN(4); + +// V8_ARG_TO_INTEGER(1, id); +// V8_ARG_TO_NUMBER(2, x); +// V8_ARG_TO_NUMBER(3, y); +// V8_ARG_TO_NUMBER(4, z); + +// ::CDynamicEntity *ent = funcs::GetEntityFromScriptID<::CDynamicEntity *>(id); + +// ent->SetAngularVelocity({x, y, z, 0.0}); +// } + +static void GetPermissionState(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK(info[0]->IsUint32(), "1st arg must be permission id"); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + auto permnum = info[0].As()->Value(); + V8_CHECK(permnum < (uint32_t)alt::Permission::All, "Invalid permission"); + auto perm = (alt::Permission)permnum; + + auto state = alt::ICore::Instance().GetPermissionState(perm); + info.GetReturnValue().Set(v8::Uint32::NewFromUnsigned(isolate, (uint8_t)state)); +} + +static void IsInStreamerMode(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + info.GetReturnValue().Set(v8::Boolean::New(isolate, alt::ICore::Instance().IsInStreamerMode())); +} + +static void TakeScreenshot(const v8::FunctionCallbackInfo &info) +{ + static std::list> promises; + static v8::Isolate *_isolate = v8::Isolate::GetCurrent(); + + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(ICore::Instance().IsDebug(), "Must be in debug mode"); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + auto &api = alt::ICore::Instance(); + auto state = api.GetPermissionState(alt::Permission::ScreenCapture); + V8_CHECK(state != alt::PermissionState::Denied, "No permissions"); + V8_CHECK(state != alt::PermissionState::Unspecified, "Permissions not specified"); + + auto &persistent = promises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); + + api.TakeScreenshot([](alt::StringView base64, const void *userData) { + v8::Isolate *isolate = _isolate; + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + auto persistent = (v8::UniquePersistent *)userData; + auto resolver = persistent->Get(isolate); + auto ctx = resolver->CreationContext(); + { + v8::Context::Scope ctxscope(ctx); + resolver->Resolve(resolver->CreationContext(), v8::String::NewFromUtf8(isolate, base64.CStr()).ToLocalChecked()); + } + + promises.remove(*persistent); + }, + &persistent); + + info.GetReturnValue().Set(persistent.Get(isolate)->GetPromise()); +} + +static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &info) +{ + static std::list> promises; + static v8::Isolate *_isolate = v8::Isolate::GetCurrent(); + + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(ICore::Instance().IsDebug(), "Must be in debug mode"); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + auto &api = alt::ICore::Instance(); + auto state = api.GetPermissionState(alt::Permission::ScreenCapture); + V8_CHECK(state != alt::PermissionState::Denied, "No permissions"); + V8_CHECK(state != alt::PermissionState::Unspecified, "Permissions not specified"); + + auto &persistent = promises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); + + api.TakeScreenshotGameOnly([](alt::StringView base64, const void *userData) { + v8::Isolate *isolate = _isolate; + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + auto persistent = (v8::UniquePersistent *)userData; + auto resolver = persistent->Get(isolate); + auto ctx = resolver->CreationContext(); + { + v8::Context::Scope ctxscope(ctx); + resolver->Resolve(resolver->CreationContext(), v8::String::NewFromUtf8(isolate, base64.CStr()).ToLocalChecked()); + } + + promises.remove(*persistent); + ctx->Exit(); + }, + &persistent); + + info.GetReturnValue().Set(persistent.Get(isolate)->GetPromise()); +} + +static V8Module altModule("alt", + { + "Vector3", + "RGBA", + "BaseObject", + "WorldObject", + "Entity", + "Player", + "Vehicle", + "WebView", + "Blip", + "AreaBlip", + "RadiusBlip", + "PointBlip", + "HandlingData", + "LocalStorage", + "MemoryBuffer", + "File", + "MapZoomData", + "Discord", + "Voice" + /*"PedBlip", + "VehicleBlip"*/ + }, + [](v8::Local ctx, v8::Local exports) { + V8::RegisterSharedMain(ctx, exports); + + V8Helpers::RegisterFunc(exports, "onServer", &OnServer); + V8Helpers::RegisterFunc(exports, "offServer", &OffServer); + V8Helpers::RegisterFunc(exports, "emitServer", &EmitServer); + V8Helpers::RegisterFunc(exports, "gameControlsEnabled", &GameControlsEnabled); + V8Helpers::RegisterFunc(exports, "toggleGameControls", &ToggleGameControls); + V8Helpers::RegisterFunc(exports, "toggleVoiceControls", &ToggleVoiceControls); + V8Helpers::RegisterFunc(exports, "showCursor", &ShowCursor); + V8Helpers::RegisterFunc(exports, "isMenuOpen", &IsMenuOpen); + V8Helpers::RegisterFunc(exports, "isConsoleOpen", &IsConsoleOpen); + //V8Helpers::RegisterFunc(exports, "drawRect2D", &DrawRect2D); + + V8Helpers::RegisterFunc(exports, "requestIpl", &RequestIPL); + V8Helpers::RegisterFunc(exports, "removeIpl", &RemoveIPL); + //V8Helpers::RegisterFunc(exports, "wait", &ScriptWait); + //V8Helpers::RegisterFunc(exports, "isInSandbox", &IsInSandbox); + V8Helpers::RegisterFunc(exports, "isInDebug", &IsInDebug); + V8Helpers::RegisterFunc(exports, "setCamFrozen", &SetCamFrozen); + + V8Helpers::RegisterFunc(exports, "getLicenseHash", &GetLicenseHash); + + //Gxt texts functions + V8Helpers::RegisterFunc(exports, "addGxtText", &AddGxtText); + V8Helpers::RegisterFunc(exports, "removeGxtText", &RemoveGxtText); + V8Helpers::RegisterFunc(exports, "getGxtText", &GetGxtText); + + //Voice functions + V8Helpers::RegisterFunc(exports, "isVoiceActivityInputEnabled", &IsVoiceActivityInputEnabled); + + //Time managements functions + V8Helpers::RegisterFunc(exports, "setMsPerGameMinute", &SetMsPerGameMinute); + V8Helpers::RegisterFunc(exports, "getMsPerGameMinute", &GetMsPerGameMinute); + + //CEF rendering on texture + V8Helpers::RegisterFunc(exports, "isTextureExistInArchetype", &IsTextureExistInArchetype); + + //Scaleform additionals + V8Helpers::RegisterFunc(exports, "beginScaleformMovieMethodMinimap", &BeginScaleformMovieMethodMinimap); + +#ifndef NDEBUG + // V8Helpers::RegisterFunc(exports, "getVehWheels", &GetVehWheels); +#endif + + V8Helpers::RegisterFunc(exports, "getLocale", &GetLocale); + + V8Helpers::RegisterFunc(exports, "setWeatherCycle", &SetWeatherCycle); + V8Helpers::RegisterFunc(exports, "setWeatherSyncActive", &SetWeatherSyncActive); + + V8Helpers::RegisterFunc(exports, "setStat", &SetCharStat); + V8Helpers::RegisterFunc(exports, "getStat", &GetCharStat); + V8Helpers::RegisterFunc(exports, "resetStat", &ResetCharStat); + + V8Helpers::RegisterFunc(exports, "isKeyDown", &IsKeyDown); + V8Helpers::RegisterFunc(exports, "isKeyToggled", &IsKeyToggled); + + V8Helpers::RegisterFunc(exports, "setConfigFlag", &SetConfigFlag); + V8Helpers::RegisterFunc(exports, "getConfigFlag", &GetConfigFlag); + V8Helpers::RegisterFunc(exports, "doesConfigFlagExist", &DoesConfigFlagExist); + + // V8Helpers::RegisterFunc(exports, "getEntityMemoryByID", &GetEntityMemoryByID); + + // V8Helpers::RegisterFunc(exports, "setRotationVelocity", &SetAngularVelocity); + // V8Helpers::RegisterFunc(exports, "setAngularVelocity", &SetAngularVelocity); + + V8Helpers::RegisterFunc(exports, "isInStreamerMode", &IsInStreamerMode); + + V8Helpers::RegisterFunc(exports, "takeScreenshot", &TakeScreenshot); + V8Helpers::RegisterFunc(exports, "takeScreenshotGameOnly", &TakeScreenshotGameOnly); + }); diff --git a/src/bindings/MapZoomData.cpp b/src/bindings/MapZoomData.cpp new file mode 100644 index 00000000..87801ba4 --- /dev/null +++ b/src/bindings/MapZoomData.cpp @@ -0,0 +1,208 @@ +// #include "../CV8Resource.h" +// #include "../helpers/V8Class.h" + +// static void Constructor(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(info.IsConstructCall(), "HandlingData constructor is not a function"); +// V8_CHECK(info.Length() == 1, "new HandlingData(...) expects 1 arg"); + +// V8_CHECK(info[0]->IsNumber() || info[0]->IsString(), "zoomDataId must be a number or string"); + +// if (info[0]->IsNumber()) +// { +// uint8_t zoomDataId = info[0]->Uint32Value(ctx).ToChecked(); +// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); +// V8_CHECK(data, "zoomData with this id not found"); +// info.This()->SetInternalField(0, info[0]); +// } +// else +// { +// std::string zoomDataAlias = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); +// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataAlias); +// V8_CHECK(data, "zoomData with this id not found"); +// uint8_t id = CMapZoomData::Instance().GetIdFromAlias(zoomDataAlias); +// info.This()->SetInternalField(0, v8::Integer::NewFromUnsigned(isolate, id)); +// } +// } + +// static void Get(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8_CHECK(info.Length() == 1, "MapZoomData.get expects 1 arg"); +// V8_CHECK(info[0]->IsNumber() || info[0]->IsString(), "zoomDataId must be a number or string"); + +// static V8Class *mapZoomDataClass = V8Class::Get("MapZoomData"); + +// std::vector> args{ +// info[0]}; + +// info.GetReturnValue().Set(mapZoomDataClass->New(isolate->GetEnteredContext(), args)); +// } + +// static void ResetAll(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// CMapZoomData::Instance().ResetAll(); +// } + +// static void fZoomScaleGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + +// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); +// V8_CHECK(data, "zoom data not found"); + +// info.GetReturnValue().Set(v8::Number::New(isolate, data->fZoomScale)); +// } + +// static void fZoomScaleSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "fZoomScale must be a number"); + +// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + +// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); +// V8_CHECK(data, "zoom data not found"); + +// data->fZoomScale = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void fZoomSpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + +// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); +// V8_CHECK(data, "zoom data not found"); + +// info.GetReturnValue().Set(v8::Number::New(isolate, data->fZoomSpeed)); +// } + +// static void fZoomSpeedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "fZoomSpeed must be a number"); + +// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + +// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); +// V8_CHECK(data, "zoom data not found"); + +// data->fZoomSpeed = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void fScrollSpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + +// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); +// V8_CHECK(data, "zoom data not found"); + +// info.GetReturnValue().Set(v8::Number::New(isolate, data->fScrollSpeed)); +// } + +// static void fScrollSpeedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "fScrollSpeed must be a number"); + +// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + +// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); +// V8_CHECK(data, "zoom data not found"); + +// data->fScrollSpeed = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void vTilesXGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + +// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); +// V8_CHECK(data, "zoom data not found"); + +// info.GetReturnValue().Set(v8::Number::New(isolate, data->vTilesX)); +// } + +// static void vTilesXSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "vTilesX must be a number"); + +// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + +// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); +// V8_CHECK(data, "zoom data not found"); + +// data->vTilesX = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void vTilesYGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + +// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); +// V8_CHECK(data, "zoom data not found"); + +// info.GetReturnValue().Set(v8::Number::New(isolate, data->vTilesY)); +// } + +// static void vTilesYSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// V8_CHECK(val->IsNumber(), "vTilesY must be a number"); + +// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + +// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); +// V8_CHECK(data, "zoom data not found"); + +// data->vTilesY = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); +// } + +// static void Reset(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); + +// alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); +// V8_CHECK(resource, "Invalid resource"); + +// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + +// CMapZoomData::Instance().Reset(zoomDataId); +// } + +// static V8Class v8mapZoomData( +// "MapZoomData", "", Constructor, [](v8::Local tpl) { +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); + +// v8::Local proto = tpl->PrototypeTemplate(); + +// tpl->InstanceTemplate()->SetInternalFieldCount(1); + +// tpl->Set(isolate, "get", v8::FunctionTemplate::New(isolate, &Get)); +// tpl->Set(isolate, "resetAll", v8::FunctionTemplate::New(isolate, &ResetAll)); + +// V8::SetAccessor(isolate, tpl, "fZoomScale", &fZoomScaleGetter, &fZoomScaleSetter); +// V8::SetAccessor(isolate, tpl, "fZoomSpeed", &fZoomSpeedGetter, &fZoomSpeedSetter); +// V8::SetAccessor(isolate, tpl, "fScrollSpeed", &fScrollSpeedGetter, &fScrollSpeedSetter); +// V8::SetAccessor(isolate, tpl, "vTilesX", &vTilesXGetter, &vTilesXSetter); +// V8::SetAccessor(isolate, tpl, "vTilesY", &vTilesYGetter, &vTilesYSetter); +// V8::SetMethod(isolate, tpl, "reset", &Reset); +// }, +// false); diff --git a/src/bindings/MemoryBuffer.cpp b/src/bindings/MemoryBuffer.cpp new file mode 100644 index 00000000..599daa68 --- /dev/null +++ b/src/bindings/MemoryBuffer.cpp @@ -0,0 +1,201 @@ + +// #include "../CV8Resource.h" +// #include "../helpers/V8Class.h" +// #include "memory/CMemoryCacheStorage.h" +// #include "core/CGame.h" + +// //static void weakCallbackForObjectHolder(const v8::WeakCallbackInfo& data) { +// // uint8_t* memory = (uint8_t*)data.GetInternalField(0); +// // delete data.GetParameter(); +// //} + +// //static void WeakCallback(v8::WeakCallbackData data) +// //{ +// // Local val = data.GetValue(); +// // int* ptr = retinterpret_cast(val->GetAlignedPointerFromINternalField(0)); +// // delete ptr; +// // fprintf(stdout, "Deleted internal object!\n"); +// //} + +// static void Constructor(const v8::FunctionCallbackInfo& info) +// { +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8_CHECK(info.IsConstructCall(), "MemoryBuffer constructor is not a function"); +// V8_CHECK(info.Length() == 1, "new MemoryBuffer(...) expects 1 arg"); + +// if(info[0]->IsString()) +// { +// #ifdef NDEBUG +// V8_CHECK(CGame::Instance().IsDebug() && IsDevOrInternalBranch(), "must be in debug mode and dev branch to use memory patterns"); +// #endif +// V8_ARG_TO_STRING(0, str); +// auto mem = CMemory::Pattern(str.ToString()).Search(true); +// V8_CHECK(mem.IsValid(), "Pattern not found"); +// info.This()->SetAlignedPointerInInternalField(0, mem.GetAddress()); +// info.This()->SetInternalField(1, v8::Integer::NewFromUnsigned(isolate, UINT32_MAX)); +// } +// else { +// V8_CHECK(info[0]->IsNumber(), "size must be a number or a string pattern"); +// uint32_t size = info[0]->Uint32Value(ctx).ToChecked(); +// if(size == 0) +// { +// info.This()->SetAlignedPointerInInternalField(0, nullptr); +// info.This()->SetInternalField(1, v8::Integer::NewFromUnsigned(isolate, 0)); +// return; +// } +// V8_CHECK(size <= 1024, "You can't allocate > 1KB"); + +// uint8_t* allocatedMemory = new uint8_t[size]; +// memset(allocatedMemory, 0, size); +// info.This()->SetAlignedPointerInInternalField(0, allocatedMemory); +// info.This()->SetInternalField(1, v8::Integer::NewFromUnsigned(isolate, size)); +// } + +// /*v8::UniquePersistent persistent(isolate, info.This()); +// persistent.SetWeak(info.This(), weakCallbackForObjectHolder, v8::WeakCallbackType::kInternalFields);*/ +// } + +// static void FreeBuffer(const v8::FunctionCallbackInfo& info) +// { +// v8::Isolate* isolate = v8::Isolate::GetCurrent(); + +// V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "Invalid resource"); + +// uint8_t* memory = (uint8_t*)info.This()->GetAlignedPointerFromInternalField(0); +// if (memory != nullptr) +// { +// delete memory; +// info.This()->SetAlignedPointerInInternalField(0, nullptr); +// info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); +// return; +// } +// info.GetReturnValue().Set(v8::Boolean::New(isolate, false)); +// } + +// static void GetAddress(const v8::FunctionCallbackInfo& info) +// { +// v8::Isolate* isolate = v8::Isolate::GetCurrent(); + +// #ifdef NDEBUG +// V8_CHECK(CGame::Instance().IsDebug() && IsDevOrInternalBranch(), "must be in debug mode and dev branch to get the address of memory buffers"); +// #endif + +// V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "Invalid resource"); + +// uintptr_t memory = (uintptr_t)info.This()->GetAlignedPointerFromInternalField(0); +// info.GetReturnValue().Set(v8::BigInt::New(isolate, memory)); +// } + +// template +// static void GetDataOfType(const v8::FunctionCallbackInfo& info) +// { +// v8::Isolate* isolate = v8::Isolate::GetCurrent(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "Invalid resource"); + +// bool isString = false; +// if (std::is_same_v) +// { +// V8_CHECK(info.Length() == 2, "2 args expected"); +// isString = true; +// } +// else +// { +// V8_CHECK(info.Length() == 1, "1 arg expected"); +// } + +// V8_CHECK(info[0]->IsNumber(), "offset must be a number"); +// uint32_t offset = info[0]->Uint32Value(ctx).ToChecked(); + +// uint32_t strLength = 0; + +// if (isString) +// strLength = info[1]->Uint32Value(ctx).ToChecked(); + +// uint8_t* memory = (uint8_t*)info.This()->GetAlignedPointerFromInternalField(0); +// uint16_t size = info.This()->GetInternalField(1)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); +// if (memory == nullptr || size == 0) +// { +// info.GetReturnValue().Set(v8::Null(isolate)); +// return; +// } + +// #ifdef NDEBUG +// if(!(CGame::Instance().IsDebug() && std::string(ALTV_BRANCH)=="dev")) +// #endif +// { +// if (isString) +// { +// V8_CHECK((offset + strLength) <= size, "Offset is out of bounds"); +// } +// else +// { +// V8_CHECK((offset + sizeof(T)) <= size, "Offset is out of bounds"); +// } +// } + +// if (!isString) +// { +// if (std::is_same_v || std::is_same_v || std::is_same_v) +// { +// info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, *(uint32_t*)((uintptr_t)memory + offset))); +// return; +// } +// else if (std::is_same_v) +// { +// info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(isolate, *(uint64_t*)((uintptr_t)memory + offset))); +// return; +// } +// else if (std::is_same_v || std::is_same_v || std::is_same_v) +// { +// info.GetReturnValue().Set(v8::Integer::New(isolate, *(int32_t*)((uintptr_t)memory + offset))); +// return; +// } +// else if (std::is_same_v) +// { +// info.GetReturnValue().Set(v8::BigInt::New(isolate, *(int64_t*)((uintptr_t)memory + offset))); +// return; +// } +// else if (std::is_same_v || std::is_same_v) +// { +// info.GetReturnValue().Set(v8::Number::New(isolate, *(double*)((uintptr_t)memory + offset))); +// return; +// } +// } +// else +// { +// char* newString = new char[strLength + 1]; +// memcpy_s(newString, strLength + 1, (void*)((uintptr_t)memory + offset), strLength); +// newString[strLength] = 0; +// info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, newString).ToLocalChecked()); +// delete newString; +// } +// } + +// V8Class v8MemoryBuffer("MemoryBuffer", "", Constructor, [](v8::Local tpl) { +// v8::Isolate* isolate = v8::Isolate::GetCurrent(); + +// v8::Local proto = tpl->PrototypeTemplate(); + +// tpl->InstanceTemplate()->SetInternalFieldCount(2); + +// proto->Set(isolate, "free", v8::FunctionTemplate::New(isolate, &FreeBuffer)); +// proto->Set(isolate, "address", v8::FunctionTemplate::New(isolate, &GetAddress)); +// proto->Set(isolate, "ubyte", v8::FunctionTemplate::New(isolate, &GetDataOfType)); +// proto->Set(isolate, "ushort", v8::FunctionTemplate::New(isolate, &GetDataOfType)); +// proto->Set(isolate, "uint", v8::FunctionTemplate::New(isolate, &GetDataOfType)); +// proto->Set(isolate, "ulong", v8::FunctionTemplate::New(isolate, &GetDataOfType)); +// proto->Set(isolate, "byte", v8::FunctionTemplate::New(isolate, &GetDataOfType)); +// proto->Set(isolate, "short", v8::FunctionTemplate::New(isolate, &GetDataOfType)); +// proto->Set(isolate, "int", v8::FunctionTemplate::New(isolate, &GetDataOfType)); +// proto->Set(isolate, "long", v8::FunctionTemplate::New(isolate, &GetDataOfType)); +// proto->Set(isolate, "float", v8::FunctionTemplate::New(isolate, &GetDataOfType)); +// proto->Set(isolate, "double", v8::FunctionTemplate::New(isolate, &GetDataOfType)); +// proto->Set(isolate, "string", v8::FunctionTemplate::New(isolate, &GetDataOfType)); +// }, false); diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp new file mode 100644 index 00000000..e49be441 --- /dev/null +++ b/src/bindings/Player.cpp @@ -0,0 +1,384 @@ + +// #include "../helpers/V8Helpers.h" +// #include "../helpers/V8Class.h" +// #include "../helpers/V8Entity.h" +// #include "../helpers/V8ResourceImpl.h" + +// #include "cpp-sdk/entities/IPlayer.h" + +// static void NameGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, player->GetName().c_str()).ToLocalChecked()); +// } + +// static void VehicleGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); +// alt::Ref vehicle = player->GetVehicle(); + +// if (vehicle) +// info.GetReturnValue().Set(resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); +// else +// info.GetReturnValue().Set(v8::Null(info.GetIsolate())); +// } + +// static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// info.GetReturnValue().Set(v8::Boolean::New(isolate, player->IsTalking())); +// } + +// static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, player->GetMicLevel())); +// } + +// static void GiveWeapon(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + +// V8_CHECK(info[1]->IsNumber(), "ammoCount must be a number"); +// uint32_t ammoCount = info[1]->NumberValue(ctx).ToChecked(); + +// CPed *ped = player->GetGamePed(); +// if (ped) +// ped->ikManager.pedInventory->AddWeapon(weaponHash, ammoCount); +// } + +// static void RemoveWeapon(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + +// CPed *ped = player->GetGamePed(); +// if (ped) +// info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), ped->ikManager.pedInventory->RemoveWeapon(weaponHash))); +// else +// info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), false)); +// } + +// static void RemoveAllWeapons(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// CPed *ped = player->GetGamePed(); +// if (ped) +// { +// CPedInventory::RemoveAllWeapons(ped); +// } +// } + +// static void AddWeaponComponent(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + +// V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); +// uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); + +// CPed *ped = player->GetGamePed(); +// if (ped) +// ped->ikManager.pedInventory->AddWeaponComponent(weaponHash, componentHash); +// } + +// static void RemoveWeaponComponent(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + +// V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); +// uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); + +// CPed *ped = player->GetGamePed(); +// if (ped) +// ped->ikManager.pedInventory->RemoveWeaponComponent(weaponHash, componentHash); +// } + +// static void WeaponHasComponent(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + +// V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); +// uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); + +// CPed *ped = player->GetGamePed(); +// if (ped) +// info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), ped->ikManager.pedInventory->WeaponHasComponent(weaponHash, componentHash))); +// else +// info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), false)); +// } + +// static void SetWeaponTintIndex(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + +// V8_CHECK(info[1]->IsNumber(), "tintIndex must be a number"); +// uint8_t tintIndex = info[1]->NumberValue(ctx).ToChecked(); + +// CPed *ped = player->GetGamePed(); +// if (ped) +// ped->ikManager.pedInventory->SetWeaponTintIndex(weaponHash, tintIndex); +// } + +// static void GetWeaponTintIndex(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + +// CPed *ped = player->GetGamePed(); +// if (ped) +// info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), ped->ikManager.pedInventory->GetWeaponTintIndex(weaponHash))); +// else +// info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), false)); +// } + +// static void SetCurrentWeapon(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + +// CPed *ped = player->GetGamePed(); +// if (ped) +// ped->ikManager.pedWeaponManager->SetCurrentWeapon(weaponHash, false); +// } + +// static void GetCurrentWeapon(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref player = _this->GetHandle().As(); + +// CPed *ped = player->GetGamePed(); +// if (ped) +// info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), ped->ikManager.pedWeaponManager->currentWeaponHash)); +// else +// info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), 0)); +// } + +// static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// v8::Local ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); +// V8_CHECK(resource, "invalid resource"); + +// v8::Local arr = v8::Array::New(info.GetIsolate()); + +// uint16_t i = 0; +// CGame::Instance().GetEntityManager().ForEach([&](alt::Ref ent) { +// auto player = ent.As(); + +// if (player) +// arr->Set(ctx, i++, resource->GetOrCreateEntity(player.Get(), "Player")->GetJSVal(isolate)); +// }); + +// info.GetReturnValue().Set(arr); +// } + +// static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "Invalid resource"); + +// auto localPlayer = CGame::Instance().GetLocalPlayer(); +// if (!localPlayer) +// info.GetReturnValue().Set(v8::Null(isolate)); +// else +// info.GetReturnValue().Set(resource->GetOrCreateEntity(localPlayer.Get(), "Player")->GetJSVal(isolate)); +// } + +// static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) +// { +// V8_GET_ISOLATE_CONTEXT_RESOURCE(); +// V8_CHECK_ARGS_LEN(1); +// V8_ARG_TO_INTEGER(1, scriptGuid); +// V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid).As()); +// } + +// static void StaticGetByID(const v8::FunctionCallbackInfo &info) +// { +// V8_GET_ISOLATE_CONTEXT_RESOURCE(); +// V8_CHECK_ARGS_LEN(1); +// V8_ARG_TO_INTEGER(1, id); +// V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id).As()); +// } + +// static V8Class v8player("Player", "Entity", nullptr, [](v8::Local tpl) { +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); + +// v8::Local proto = tpl->PrototypeTemplate(); + +// V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); +// V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); + +// tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, "all").ToLocalChecked(), &AllGetter); +// tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, "local").ToLocalChecked(), &LocalGetter); + +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "name").ToLocalChecked(), &NameGetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "vehicle").ToLocalChecked(), &VehicleGetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isTalking").ToLocalChecked(), &TalkingGetter); +// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "micLevel").ToLocalChecked(), &MicLevelGetter); + +// if (CGame::Instance().IsSandbox()) +// { +// proto->Set(isolate, "giveWeapon", v8::FunctionTemplate::New(isolate, &GiveWeapon)); +// proto->Set(isolate, "removeWeapon", v8::FunctionTemplate::New(isolate, &RemoveWeapon)); +// proto->Set(isolate, "removeAllWeapons", v8::FunctionTemplate::New(isolate, &RemoveAllWeapons)); +// proto->Set(isolate, "addWeaponComponent", v8::FunctionTemplate::New(isolate, &AddWeaponComponent)); +// proto->Set(isolate, "removeWeaponComponent", v8::FunctionTemplate::New(isolate, &RemoveWeaponComponent)); +// proto->Set(isolate, "weaponHasComponent", v8::FunctionTemplate::New(isolate, &WeaponHasComponent)); + +// proto->Set(isolate, "setWeaponTintIndex", v8::FunctionTemplate::New(isolate, &SetWeaponTintIndex)); +// proto->Set(isolate, "getWeaponTintIndex", v8::FunctionTemplate::New(isolate, &GetWeaponTintIndex)); + +// proto->Set(isolate, "setCurrentWeapon", v8::FunctionTemplate::New(isolate, &SetCurrentWeapon)); +// proto->Set(isolate, "getCurrentWeapon", v8::FunctionTemplate::New(isolate, &GetCurrentWeapon)); +// } +// }); diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp new file mode 100644 index 00000000..9ed35bee --- /dev/null +++ b/src/bindings/V8Natives.cpp @@ -0,0 +1,255 @@ + +#include "../helpers/V8Helpers.h" +#include "V8Natives.h" +#include "../helpers/V8Module.h" +#include "../helpers/Log.h" + +static uint64_t pointers[32]; +static uint32_t pointersCount = 0; + +static uint32_t returnsCount = 1; + +static char *SaveString(const char *str) +{ + static char *stringValues[256] = {0}; + static int nextString = 0; + + if (stringValues[nextString]) + free(stringValues[nextString]); + + char *_str = _strdup(str); + stringValues[nextString] = _str; + nextString = (nextString + 1) % 256; + + return _str; +} + +template +static T *SavePointer(T val) +{ + T *ptr = reinterpret_cast(&pointers[pointersCount++]); + *ptr = val; + return ptr; +} + +template <> +static alt::INative::Vector3 *SavePointer(alt::INative::Vector3 val) +{ + alt::INative::Vector3 *ptr = reinterpret_cast(&pointers[pointersCount]); + pointersCount += 3; + *ptr = val; + return ptr; +} + +static void *ToMemoryBuffer(v8::Local val, v8::Local ctx) +{ + if (val->IsObject()) + { + v8::Local obj = val.As(); + + if (obj->InternalFieldCount() == 2) + { + void *memory = obj->GetAlignedPointerFromInternalField(0); + uint32_t size = obj->GetInternalField(0)->Uint32Value(ctx).ToChecked(); + + if (size > 0) + return memory; + } + } + + return nullptr; +} + +static void PushArg(alt::INative::Context *scrCtx, alt::INative::Type argType, v8::Isolate *isolate, v8::Local val) +{ + using ArgType = alt::INative::Type; + + v8::Local v8Ctx = isolate->GetEnteredContext(); + + switch (argType) + { + case alt::INative::Type::ARG_BOOL: + scrCtx->Push((int32_t)val->ToBoolean(isolate)->Value()); + break; + case alt::INative::Type::ARG_BOOL_PTR: + ++returnsCount; + scrCtx->Push(SavePointer((int32_t)val->ToBoolean(isolate)->Value())); + break; + case alt::INative::Type::ARG_INT32: + scrCtx->Push((int32_t)val->ToInteger(v8Ctx).ToLocalChecked()->Value()); + break; + case alt::INative::Type::ARG_INT32_PTR: + ++returnsCount; + scrCtx->Push(SavePointer((int32_t)val->ToInteger(v8Ctx).ToLocalChecked()->Value())); + break; + case alt::INative::Type::ARG_UINT32: + scrCtx->Push((uint32_t)val->ToInteger(v8Ctx).ToLocalChecked()->Value()); + break; + case alt::INative::Type::ARG_UINT32_PTR: + ++returnsCount; + scrCtx->Push(SavePointer((uint32_t)val->ToInteger(v8Ctx).ToLocalChecked()->Value())); + break; + case alt::INative::Type::ARG_FLOAT: + scrCtx->Push((float)val->ToNumber(v8Ctx).ToLocalChecked()->Value()); + break; + case alt::INative::Type::ARG_FLOAT_PTR: + ++returnsCount; + scrCtx->Push(SavePointer((float)val->ToNumber(v8Ctx).ToLocalChecked()->Value())); + break; + case alt::INative::Type::ARG_VECTOR3_PTR: + ++returnsCount; + scrCtx->Push(SavePointer(alt::INative::Vector3{})); // TODO: Add initializer + break; + case alt::INative::Type::ARG_STRING: + if (val->IsString()) + scrCtx->Push(SaveString(*v8::String::Utf8Value(isolate, val->ToString(v8Ctx).ToLocalChecked()))); + else + scrCtx->Push((char *)nullptr); + break; + case alt::INative::Type::ARG_STRUCT: + scrCtx->Push(ToMemoryBuffer(val, v8Ctx)); + break; + default: + Log::Error << "Unknown native arg type" << (int)argType; + } +} + +static void PushPointerReturn(alt::INative::Type argType, v8::Local retns, v8::Isolate *isolate, v8::Local ctx) +{ + using ArgType = alt::INative::Type; + + switch (argType) + { + case alt::INative::Type::ARG_BOOL_PTR: + retns->Set(ctx, returnsCount++, v8::Boolean::New(isolate, *reinterpret_cast(&pointers[pointersCount++]))); + break; + case alt::INative::Type::ARG_INT32_PTR: + retns->Set(ctx, returnsCount++, v8::Integer::New(isolate, *reinterpret_cast(&pointers[pointersCount++]))); + break; + case alt::INative::Type::ARG_UINT32_PTR: + retns->Set(ctx, returnsCount++, v8::Integer::NewFromUnsigned(isolate, *reinterpret_cast(&pointers[pointersCount++]))); + break; + case alt::INative::Type::ARG_FLOAT_PTR: + retns->Set(ctx, returnsCount++, v8::Number::New(isolate, *reinterpret_cast(&pointers[pointersCount++]))); + break; + case alt::INative::Type::ARG_VECTOR3_PTR: + { + alt::INative::Vector3 *val = reinterpret_cast(&pointers[pointersCount]); + pointersCount += 3; + + v8::Local v8Ctx = isolate->GetEnteredContext(); + v8::Local vec = v8::Object::New(isolate); + + V8::DefineOwnProperty(isolate, v8Ctx, vec, "x", v8::Number::New(isolate, val->x), v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, v8Ctx, vec, "y", v8::Number::New(isolate, val->y), v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, v8Ctx, vec, "z", v8::Number::New(isolate, val->z), v8::PropertyAttribute::ReadOnly); + + retns->Set(ctx, returnsCount++, vec); + break; + } + } +} + +static v8::Local GetReturn(alt::INative::Context *scrCtx, alt::INative::Type retnType, v8::Isolate *isolate) +{ + using ArgType = alt::INative::Type; + + v8::Local v8Ctx = isolate->GetEnteredContext(); + + switch (retnType) + { + case alt::INative::Type::ARG_BOOL: + return v8::Boolean::New(isolate, scrCtx->ResultBool()); + case alt::INative::Type::ARG_INT32: + return v8::Integer::New(isolate, scrCtx->ResultInt()); + case alt::INative::Type::ARG_UINT32: + return v8::Integer::NewFromUnsigned(isolate, scrCtx->ResultUint()); + case alt::INative::Type::ARG_FLOAT: + return v8::Number::New(isolate, scrCtx->ResultFloat()); + case alt::INative::Type::ARG_VECTOR3: + { + alt::INative::Vector3 val = scrCtx->ResultVector3(); + + v8::Local v8Ctx = isolate->GetEnteredContext(); + v8::Local vec = v8::Object::New(isolate); + + V8::DefineOwnProperty(isolate, v8Ctx, vec, "x", v8::Number::New(isolate, val.x), v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, v8Ctx, vec, "y", v8::Number::New(isolate, val.y), v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, v8Ctx, vec, "z", v8::Number::New(isolate, val.z), v8::PropertyAttribute::ReadOnly); + + return vec; + } + case alt::INative::Type::ARG_STRING: + if (!scrCtx->ResultString()) + return v8::Null(isolate); + + return v8::String::NewFromUtf8(isolate, scrCtx->ResultString()).ToLocalChecked(); + case alt::INative::Type::ARG_VOID: + return v8::Undefined(isolate); + default: + Log::Error << "Unknown native return type" << (int)retnType; + return v8::Undefined(isolate); + } +} + +static void InvokeNative(const v8::FunctionCallbackInfo &info) +{ + static alt::INative::Context *ctx = alt::ICore::Instance().GetNativesContext(); + + v8::Isolate *isolate = info.GetIsolate(); + v8::Local v8Ctx = isolate->GetCurrentContext(); + + auto native = static_cast(info.Data().As()->Value()); + + if (!native->IsValid()) + { + info.GetReturnValue().Set(v8::Boolean::New(isolate, false)); + return; + } + + auto args = native->GetArgTypes(); + uint32_t argsSize = args.GetSize(); + + ctx->Reset(); + pointersCount = 0; + returnsCount = 1; + + for (uint32_t i = 0; i < argsSize; ++i) + PushArg(ctx, args[i], isolate, info[i]); + + if (!native->Invoke(ctx)) + { + V8Helpers::Throw(isolate, "Native call failed"); + return; + } + + if (returnsCount == 1) + { + info.GetReturnValue().Set(GetReturn(ctx, native->GetRetnType(), isolate)); + } + else + { + v8::Local retns = v8::Array::New(isolate, returnsCount); + retns->Set(v8Ctx, 0, GetReturn(ctx, native->GetRetnType(), isolate)); + + pointersCount = 0; + returnsCount = 1; + + for (uint32_t i = 0; i < argsSize; ++i) + PushPointerReturn(args[i], retns, isolate, v8Ctx); + + info.GetReturnValue().Set(retns); + } +} + +static void RegisterNatives(v8::Local ctx, v8::Local exports) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + for (auto native : alt::ICore::Instance().GetAllNatives()) + { + V8::SetFunction(isolate, ctx, exports, native->GetName().CStr(), InvokeNative, native); + } +} + +static V8Module nativesModule("natives", {}, RegisterNatives); diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp new file mode 100644 index 00000000..3dd4a993 --- /dev/null +++ b/src/bindings/Vehicle.cpp @@ -0,0 +1,183 @@ + +// #include "../helpers/V8Helpers.h" +// #include "../helpers/V8Class.h" +// #include "../helpers/V8Entity.h" +// #include "../helpers/V8ResourceImpl.h" +// #include "cpp-sdk/entities/IVehicle.h" + +// using namespace alt; + +// static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// static V8Class *handlingClass = V8Class::Get("Handling"); + +// std::vector> args{ +// info.This()}; + +// info.GetReturnValue().Set(handlingClass->New(isolate->GetEnteredContext(), args)); +// } + +// static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref vehicle = _this->GetHandle().As(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetWheelSpeed())); +// } + +// static void GearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref vehicle = _this->GetHandle().As(); + +// info.GetReturnValue().Set(v8::Integer::New(isolate, vehicle->GetCurrentGear())); +// } + +// static void RPMGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref vehicle = _this->GetHandle().As(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetCurrentRPM())); +// } + +// static void WheelsCountGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref vehicle = _this->GetHandle().As(); + +// info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetWheelsCount())); +// } + +// static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// alt::Ref vehicle = _this->GetHandle().As(); + +// info.GetReturnValue().Set(resource->CreateVector3(vehicle->GetSpeedVector())); +// } + +// static void GravityGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// V8_GET_ISOLATE_CONTEXT(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// auto vehicle = _this->GetHandle().As()->GetGameVehicle(); +// V8_CHECK(vehicle, "Could not retrieve game vehicle"); + +// Log::Debug("GRAVITY", vehicle->gravity); +// auto ret = v8::Number::New(isolate, vehicle->gravity); +// Log::Debug("RET GRAVITY", ret->NumberValue(ctx).ToChecked()); +// info.GetReturnValue().Set(ret); +// } + +// static void GravitySetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// V8_GET_ISOLATE_CONTEXT(); +// V8_CHECK(val->IsNumber(), "val must be a number"); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8_CHECK(val->IsNumber(), "val needs to be a nummber (float)"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// auto vehicle = _this->GetHandle().As()->GetGameVehicle(); +// V8_CHECK(vehicle, "Could not retrieve game vehicle"); + +// Log::Debug("GRAVITY", vehicle->gravity); +// auto newval = val->NumberValue(ctx).ToChecked(); +// Log::Debug("NEW GRAVITY", newval); +// vehicle->gravity = newval; +// } + +// static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// v8::Local ctx = isolate->GetEnteredContext(); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// v8::Local arr = v8::Array::New(info.GetIsolate()); + +// uint16_t i = 0; +// CGame::Instance().GetEntityManager().ForEach([&](Ref ent) { +// auto vehicle = ent.As(); + +// if (vehicle) +// arr->Set(ctx, i++, resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); +// }); + +// info.GetReturnValue().Set(arr); +// } + +// static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) +// { +// V8_GET_ISOLATE_CONTEXT_RESOURCE(); +// V8_CHECK_ARGS_LEN(1); +// V8_ARG_TO_INTEGER(1, scriptGuid); +// V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid).As()); +// } + +// static void StaticGetByID(const v8::FunctionCallbackInfo &info) +// { +// V8_GET_ISOLATE_CONTEXT_RESOURCE(); +// V8_CHECK_ARGS_LEN(1); +// V8_ARG_TO_INTEGER(1, id); +// V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id).As()); +// } + +// static V8Class v8vehicle("Vehicle", "Entity", nullptr, [](v8::Local tpl) { +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); + +// v8::Local proto = tpl->PrototypeTemplate(); + +// V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); +// V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); + +// V8::SetStaticAccessor(isolate, tpl, "all", &AllGetter); + +// V8::SetAccessor(isolate, tpl, "speed", &SpeedGetter); +// V8::SetAccessor(isolate, tpl, "gear", &GearGetter); +// V8::SetAccessor(isolate, tpl, "rpm", &RPMGetter); +// V8::SetAccessor(isolate, tpl, "wheelsCount", &WheelsCountGetter); +// V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); +// V8::SetAccessor(isolate, tpl, "gravity", &GravityGetter, &GravitySetter); +// V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); +// }); diff --git a/src/bindings/Voice.cpp b/src/bindings/Voice.cpp new file mode 100644 index 00000000..2464817b --- /dev/null +++ b/src/bindings/Voice.cpp @@ -0,0 +1,24 @@ + +#include "../helpers/V8Helpers.h" +#include "../helpers/V8ResourceImpl.h" +#include "../helpers/V8Class.h" + +static void StaticGetInputMuted(v8::Local name, const v8::PropertyCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_BOOLEAN(alt::ICore::Instance().IsVoiceInputMuted()); +} + +static void StaticSetInputMuted(v8::Local name, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_TO_BOOLEAN(value, state); + + alt::ICore::Instance().SetVoiceInputMuted(state); +} + +static V8Class v8Voice("Voice", "", nullptr, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8::SetStaticAccessor(isolate, tpl, "muteInput", StaticGetInputMuted, StaticSetInputMuted); +}); diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp new file mode 100644 index 00000000..d7b280aa --- /dev/null +++ b/src/bindings/WebView.cpp @@ -0,0 +1,223 @@ + +#include "../helpers/V8Helpers.h" +#include "../helpers/V8Class.h" +#include "../helpers/V8Entity.h" +#include "../helpers/V8ResourceImpl.h" +#include "../CV8Resource.h" +#include "cpp-sdk/script-objects/IWebView.h" + +using namespace alt; + +static void On(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + V8_CHECK(info[0]->IsString(), "eventName must be a string"); + V8_CHECK(info[1]->IsFunction(), "callback must be a function"); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref view = _this->GetHandle().As(); + std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + + static_cast(resource)->SubscribeWebView(view, evName, info[1].As(), V8::SourceLocation::GetCurrent(isolate)); +} + +static void Off(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 2, "2 args expected"); + V8_CHECK(info[0]->IsString(), "eventName must be a string"); + V8_CHECK(info[1]->IsFunction(), "callback must be a function"); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref view = _this->GetHandle().As(); + std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + + static_cast(resource)->UnsubscribeWebView(view, evName, info[1].As()); +} + +static void Emit(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() >= 1, "WebView.emit expects atleast 1 arg"); + V8_CHECK(info[0]->IsString(), "eventName must be a string"); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref view = _this->GetHandle().As(); + std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + + alt::MValueArgs mvArgs; + + for (int i = 1; i < info.Length(); ++i) + mvArgs.Push(V8Helpers::V8ToMValue(info[i])); + + view->Trigger(evName, mvArgs); +} + +static void Focus(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref view = _this->GetHandle().As(); + + view->Focus(); +} + +static void Unfocus(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref view = _this->GetHandle().As(); + + view->Unfocus(); +} + +static void SetURL(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK(info[0]->IsString(), "string expected"); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref view = _this->GetHandle().As(); + + v8::String::Utf8Value url(info.GetIsolate(), info[0].As()); + + view->SetUrl(*url); +} + +static void IsVisibleGetter(v8::Local property, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref view = _this->GetHandle().As(); + + info.GetReturnValue().Set(v8::Boolean::New(isolate, view->IsVisible())); +} + +static void IsVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref view = _this->GetHandle().As(); + + view->SetVisible(value->BooleanValue(isolate)); +} + +static void URLGetter(v8::Local property, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref view = _this->GetHandle().As(); + + info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, view->GetUrl().CStr()).ToLocalChecked()); +} + +static void URLSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetCurrentContext(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref view = _this->GetHandle().As(); + + v8::String::Utf8Value url{isolate, value->ToString(ctx).ToLocalChecked()}; + view->SetUrl(*url); +} + +static V8Class v8webview( + "WebView", "BaseObject", [](const v8::FunctionCallbackInfo &info) { + v8::Isolate *isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetCurrentContext(); + + V8_CHECK(info.IsConstructCall(), "WebView is not a function"); + V8_CHECK(info.Length() > 0 && info.Length() <= 3, "new WebView(...) expects 1, 2 or 3 args"); + V8_CHECK(info[0]->IsString(), "url must be a string"); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + v8::Local url = info[0].As(); + + alt::Ref view = nullptr; + + if (info.Length() == 3) + { + v8::Local modelHash = info[1]->ToInteger(ctx).ToLocalChecked(); + v8::Local targetTexture = info[2]->ToString(ctx).ToLocalChecked(); + + uint32_t drawableHash = modelHash->Value(); + std::string targetTextureStr = *v8::String::Utf8Value(info.GetIsolate(), targetTexture); + + auto texture = alt::ICore::Instance().GetTextureFromDrawable(drawableHash, targetTextureStr); + V8_CHECK(texture != nullptr, "Texture not found"); + + view = alt::ICore::Instance().CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), (uint32_t)drawableHash, targetTextureStr); + V8_CHECK(!view.IsEmpty(), "Interactive WebView cannot be created"); + } + else if (info.Length() == 2) + { + v8::Local isOverlay = info[1]->ToBoolean(isolate); + bool isOverlayBool = isOverlay->Value(); + + view = alt::ICore::Instance().CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), {0, 0}, {0, 0}, true, isOverlayBool); + } + else + { + view = alt::ICore::Instance().CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), {0, 0}, {0, 0}, true, false); + } + + static_cast(resource)->AddOwned(view); + resource->BindEntity(info.This(), view.Get()); }, + [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8::SetAccessor(isolate, tpl, "isVisible", &IsVisibleGetter, &IsVisibleSetter); + V8::SetAccessor(isolate, tpl, "url", &URLGetter, &URLSetter); + + v8::Local proto = tpl->PrototypeTemplate(); + + proto->Set(isolate, "on", v8::FunctionTemplate::New(isolate, &On)); + proto->Set(isolate, "off", v8::FunctionTemplate::New(isolate, &Off)); + proto->Set(isolate, "emit", v8::FunctionTemplate::New(isolate, &Emit)); + proto->Set(isolate, "focus", v8::FunctionTemplate::New(isolate, &Focus)); + proto->Set(isolate, "unfocus", v8::FunctionTemplate::New(isolate, &Unfocus)); + }); diff --git a/src/helpers b/src/helpers index c26a3dd9..16c33b01 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit c26a3dd97c3f007c5db24c2a10982be59e5a0a66 +Subproject commit 16c33b01b86f76a774763cd4496966f8626b7498 diff --git a/src/inspector/CV8InspectorChannel.h b/src/inspector/CV8InspectorChannel.h new file mode 100644 index 00000000..871e610d --- /dev/null +++ b/src/inspector/CV8InspectorChannel.h @@ -0,0 +1,24 @@ +#pragma once + +#include "v8-inspector.h" + +namespace alt +{ + class CV8InspectorChannel : public v8_inspector::V8Inspector::Channel + { + void sendResponse(int callId, std::unique_ptr message) + { + Log::Debug << __FUNCTION__ << callId << message->string().characters8(); + } + + void sendNotification(std::unique_ptr message) + { + Log::Debug << __FUNCTION__ << message->string().characters8(); + } + + void flushProtocolNotifications() + { + Log::Debug << __FUNCTION__; + } + }; +} // namespace alt diff --git a/src/inspector/CV8InspectorClient.h b/src/inspector/CV8InspectorClient.h new file mode 100644 index 00000000..cbd22c37 --- /dev/null +++ b/src/inspector/CV8InspectorClient.h @@ -0,0 +1,11 @@ +#pragma once + +#include "v8-inspector.h" + +namespace alt +{ + class CV8InspectorClient : public v8_inspector::V8InspectorClient + { + + }; +} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 00000000..e69de29b From a3fb99e682c9c5cad59154e36a03ef232b062e74 Mon Sep 17 00:00:00 2001 From: Hazard Date: Mon, 2 Nov 2020 00:28:03 +0100 Subject: [PATCH 024/564] Wrapped player bindings --- deps/cpp-sdk | 2 +- src/CV8Resource.cpp | 1 - src/bindings/Player.cpp | 556 ++++++++++++++++++------------------- src/bindings/V8Natives.cpp | 1 - 4 files changed, 264 insertions(+), 296 deletions(-) diff --git a/deps/cpp-sdk b/deps/cpp-sdk index d82ca63c..cbeae04b 160000 --- a/deps/cpp-sdk +++ b/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit d82ca63c5c20ef55ab987c288bd80a71a4884e85 +Subproject commit cbeae04b368e6cc6384eecb058ab7170c3ab9d2a diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index cc33b34b..542c165f 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -22,7 +22,6 @@ #include "CV8ScriptRuntime.h" #include "CV8Resource.h" -#include "bindings/V8Natives.h" #include "helpers/V8Module.h" static void StaticRequire(const v8::FunctionCallbackInfo &info) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index e49be441..da68b5de 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -1,384 +1,354 @@ -// #include "../helpers/V8Helpers.h" -// #include "../helpers/V8Class.h" -// #include "../helpers/V8Entity.h" -// #include "../helpers/V8ResourceImpl.h" +#include "../helpers/V8Helpers.h" +#include "../helpers/V8Class.h" +#include "../helpers/V8Entity.h" +#include "../helpers/V8ResourceImpl.h" -// #include "cpp-sdk/entities/IPlayer.h" +#include "cpp-sdk/entities/IPlayer.h" +#include "cpp-sdk/entities/IVehicle.h" -// static void NameGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void NameGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, player->GetName().c_str()).ToLocalChecked()); -// } + info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, player->GetName().CStr()).ToLocalChecked()); +} -// static void VehicleGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void VehicleGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); -// alt::Ref vehicle = player->GetVehicle(); + alt::Ref player = _this->GetHandle().As(); + alt::Ref vehicle = player->GetVehicle(); -// if (vehicle) -// info.GetReturnValue().Set(resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); -// else -// info.GetReturnValue().Set(v8::Null(info.GetIsolate())); -// } + if (vehicle) + info.GetReturnValue().Set(resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); + else + info.GetReturnValue().Set(v8::Null(info.GetIsolate())); +} -// static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// info.GetReturnValue().Set(v8::Boolean::New(isolate, player->IsTalking())); -// } + info.GetReturnValue().Set(v8::Boolean::New(isolate, player->IsTalking())); +} -// static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, player->GetMicLevel())); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, player->GetMicLevel())); +} -// static void GiveWeapon(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void GiveWeapon(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); + uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); -// V8_CHECK(info[1]->IsNumber(), "ammoCount must be a number"); -// uint32_t ammoCount = info[1]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[1]->IsNumber(), "ammoCount must be a number"); + uint32_t ammoCount = info[1]->NumberValue(ctx).ToChecked(); -// CPed *ped = player->GetGamePed(); -// if (ped) -// ped->ikManager.pedInventory->AddWeapon(weaponHash, ammoCount); -// } + player->GiveWeapon(weaponHash, ammoCount, false); // todo: allow setter for selected +} -// static void RemoveWeapon(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void RemoveWeapon(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); + uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); -// CPed *ped = player->GetGamePed(); -// if (ped) -// info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), ped->ikManager.pedInventory->RemoveWeapon(weaponHash))); -// else -// info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), false)); -// } + info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), player->RemoveWeapon(weaponHash))); +} -// static void RemoveAllWeapons(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void RemoveAllWeapons(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// CPed *ped = player->GetGamePed(); -// if (ped) -// { -// CPedInventory::RemoveAllWeapons(ped); -// } -// } + player->RemoveAllWeapons(); +} -// static void AddWeaponComponent(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void AddWeaponComponent(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); + uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); -// V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); -// uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); + uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); -// CPed *ped = player->GetGamePed(); -// if (ped) -// ped->ikManager.pedInventory->AddWeaponComponent(weaponHash, componentHash); -// } + player->AddWeaponComponent(weaponHash, componentHash); +} -// static void RemoveWeaponComponent(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void RemoveWeaponComponent(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); + uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); -// V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); -// uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); + uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); -// CPed *ped = player->GetGamePed(); -// if (ped) -// ped->ikManager.pedInventory->RemoveWeaponComponent(weaponHash, componentHash); -// } + player->RemoveWeaponComponent(weaponHash, componentHash); +} -// static void WeaponHasComponent(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void WeaponHasComponent(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); + uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); -// V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); -// uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); + uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); -// CPed *ped = player->GetGamePed(); -// if (ped) -// info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), ped->ikManager.pedInventory->WeaponHasComponent(weaponHash, componentHash))); -// else -// info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), false)); -// } + info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), player->HasWeaponComponent(weaponHash, componentHash))); +} -// static void SetWeaponTintIndex(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void SetWeaponTintIndex(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); + uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); -// V8_CHECK(info[1]->IsNumber(), "tintIndex must be a number"); -// uint8_t tintIndex = info[1]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[1]->IsNumber(), "tintIndex must be a number"); + uint8_t tintIndex = info[1]->NumberValue(ctx).ToChecked(); -// CPed *ped = player->GetGamePed(); -// if (ped) -// ped->ikManager.pedInventory->SetWeaponTintIndex(weaponHash, tintIndex); -// } + player->SetWeaponTintIndex(weaponHash, tintIndex); +} -// static void GetWeaponTintIndex(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void GetWeaponTintIndex(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); + uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); -// CPed *ped = player->GetGamePed(); -// if (ped) -// info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), ped->ikManager.pedInventory->GetWeaponTintIndex(weaponHash))); -// else -// info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), false)); -// } + info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), player->GetWeaponTintIndex(weaponHash))); +} -// static void SetCurrentWeapon(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void SetCurrentWeapon(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); + uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); -// CPed *ped = player->GetGamePed(); -// if (ped) -// ped->ikManager.pedWeaponManager->SetCurrentWeapon(weaponHash, false); -// } + player->SetCurrentWeapon(weaponHash); +} -// static void GetCurrentWeapon(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void GetCurrentWeapon(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref player = _this->GetHandle().As(); + alt::Ref player = _this->GetHandle().As(); -// CPed *ped = player->GetGamePed(); -// if (ped) -// info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), ped->ikManager.pedWeaponManager->currentWeaponHash)); -// else -// info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), 0)); -// } - -// static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// v8::Local ctx = isolate->GetEnteredContext(); + info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), player->GetCurrentWeapon())); +} -// V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); -// V8_CHECK(resource, "invalid resource"); - -// v8::Local arr = v8::Array::New(info.GetIsolate()); +static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); -// uint16_t i = 0; -// CGame::Instance().GetEntityManager().ForEach([&](alt::Ref ent) { -// auto player = ent.As(); + V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); + V8_CHECK(resource, "invalid resource"); -// if (player) -// arr->Set(ctx, i++, resource->GetOrCreateEntity(player.Get(), "Player")->GetJSVal(isolate)); -// }); + v8::Local arr = v8::Array::New(info.GetIsolate()); -// info.GetReturnValue().Set(arr); -// } + uint16_t i = 0; + for (auto player : alt::ICore::Instance().GetPlayers()) + { + if (player) + arr->Set(ctx, i++, resource->GetOrCreateEntity(player.Get(), "Player")->GetJSVal(isolate)); + }; -// static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); + info.GetReturnValue().Set(arr); +} -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "Invalid resource"); - -// auto localPlayer = CGame::Instance().GetLocalPlayer(); -// if (!localPlayer) -// info.GetReturnValue().Set(v8::Null(isolate)); -// else -// info.GetReturnValue().Set(resource->GetOrCreateEntity(localPlayer.Get(), "Player")->GetJSVal(isolate)); -// } - -// static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) -// { -// V8_GET_ISOLATE_CONTEXT_RESOURCE(); -// V8_CHECK_ARGS_LEN(1); -// V8_ARG_TO_INTEGER(1, scriptGuid); -// V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid).As()); -// } - -// static void StaticGetByID(const v8::FunctionCallbackInfo &info) -// { -// V8_GET_ISOLATE_CONTEXT_RESOURCE(); -// V8_CHECK_ARGS_LEN(1); -// V8_ARG_TO_INTEGER(1, id); -// V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id).As()); -// } - -// static V8Class v8player("Player", "Entity", nullptr, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); - -// v8::Local proto = tpl->PrototypeTemplate(); - -// V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); -// V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); - -// tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, "all").ToLocalChecked(), &AllGetter); -// tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, "local").ToLocalChecked(), &LocalGetter); - -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "name").ToLocalChecked(), &NameGetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "vehicle").ToLocalChecked(), &VehicleGetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isTalking").ToLocalChecked(), &TalkingGetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "micLevel").ToLocalChecked(), &MicLevelGetter); - -// if (CGame::Instance().IsSandbox()) -// { -// proto->Set(isolate, "giveWeapon", v8::FunctionTemplate::New(isolate, &GiveWeapon)); -// proto->Set(isolate, "removeWeapon", v8::FunctionTemplate::New(isolate, &RemoveWeapon)); -// proto->Set(isolate, "removeAllWeapons", v8::FunctionTemplate::New(isolate, &RemoveAllWeapons)); -// proto->Set(isolate, "addWeaponComponent", v8::FunctionTemplate::New(isolate, &AddWeaponComponent)); -// proto->Set(isolate, "removeWeaponComponent", v8::FunctionTemplate::New(isolate, &RemoveWeaponComponent)); -// proto->Set(isolate, "weaponHasComponent", v8::FunctionTemplate::New(isolate, &WeaponHasComponent)); - -// proto->Set(isolate, "setWeaponTintIndex", v8::FunctionTemplate::New(isolate, &SetWeaponTintIndex)); -// proto->Set(isolate, "getWeaponTintIndex", v8::FunctionTemplate::New(isolate, &GetWeaponTintIndex)); - -// proto->Set(isolate, "setCurrentWeapon", v8::FunctionTemplate::New(isolate, &SetCurrentWeapon)); -// proto->Set(isolate, "getCurrentWeapon", v8::FunctionTemplate::New(isolate, &GetCurrentWeapon)); -// } -// }); +static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + auto localPlayer = alt::ICore::Instance().GetLocalPlayer(); + if (!localPlayer) + info.GetReturnValue().Set(v8::Null(isolate)); + else + info.GetReturnValue().Set(resource->GetOrCreateEntity(localPlayer.Get(), "Player")->GetJSVal(isolate)); +} + +static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, scriptGuid); + V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid).As()); +} + +static void StaticGetByID(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, id); + V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id).As()); +} + +static V8Class v8player("Player", "Entity", nullptr, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + v8::Local proto = tpl->PrototypeTemplate(); + + V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); + V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); + + tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, "all").ToLocalChecked(), &AllGetter); + tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, "local").ToLocalChecked(), &LocalGetter); + + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "name").ToLocalChecked(), &NameGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "vehicle").ToLocalChecked(), &VehicleGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isTalking").ToLocalChecked(), &TalkingGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "micLevel").ToLocalChecked(), &MicLevelGetter); + + if (alt::ICore::Instance().IsSandbox()) + { + proto->Set(isolate, "giveWeapon", v8::FunctionTemplate::New(isolate, &GiveWeapon)); + proto->Set(isolate, "removeWeapon", v8::FunctionTemplate::New(isolate, &RemoveWeapon)); + proto->Set(isolate, "removeAllWeapons", v8::FunctionTemplate::New(isolate, &RemoveAllWeapons)); + proto->Set(isolate, "addWeaponComponent", v8::FunctionTemplate::New(isolate, &AddWeaponComponent)); + proto->Set(isolate, "removeWeaponComponent", v8::FunctionTemplate::New(isolate, &RemoveWeaponComponent)); + proto->Set(isolate, "weaponHasComponent", v8::FunctionTemplate::New(isolate, &WeaponHasComponent)); + + proto->Set(isolate, "setWeaponTintIndex", v8::FunctionTemplate::New(isolate, &SetWeaponTintIndex)); + proto->Set(isolate, "getWeaponTintIndex", v8::FunctionTemplate::New(isolate, &GetWeaponTintIndex)); + + proto->Set(isolate, "setCurrentWeapon", v8::FunctionTemplate::New(isolate, &SetCurrentWeapon)); + proto->Set(isolate, "getCurrentWeapon", v8::FunctionTemplate::New(isolate, &GetCurrentWeapon)); + } +}); diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 9ed35bee..aa12c592 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -1,6 +1,5 @@ #include "../helpers/V8Helpers.h" -#include "V8Natives.h" #include "../helpers/V8Module.h" #include "../helpers/Log.h" From 467f4dd54041fbded3ff972d86386703139ed8c6 Mon Sep 17 00:00:00 2001 From: Hazard Date: Mon, 2 Nov 2020 01:01:11 +0100 Subject: [PATCH 025/564] Wrapped vehicles and handling --- deps/cpp-sdk | 2 +- src/bindings/Handling.cpp | 2904 ++++++++++++++++++------------------- src/bindings/Vehicle.cpp | 229 ++- 3 files changed, 1503 insertions(+), 1632 deletions(-) diff --git a/deps/cpp-sdk b/deps/cpp-sdk index cbeae04b..3c01a668 160000 --- a/deps/cpp-sdk +++ b/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit cbeae04b368e6cc6384eecb058ab7170c3ab9d2a +Subproject commit 3c01a668938b23f5f32b0f6680f59225f0b62ee0 diff --git a/src/bindings/Handling.cpp b/src/bindings/Handling.cpp index 840c0891..4c8d0883 100644 --- a/src/bindings/Handling.cpp +++ b/src/bindings/Handling.cpp @@ -1,2183 +1,2055 @@ -// #include "../CV8Resource.h" -// #include "../helpers/V8Helpers.h" -// #include "../helpers/V8Class.h" -// #include "../helpers/V8Entity.h" -// #include "../helpers/V8ResourceImpl.h" -// #include "cpp-sdk/entities/IVehicle.h" +#include "../CV8Resource.h" +#include "../helpers/V8Helpers.h" +#include "../helpers/V8Class.h" +#include "../helpers/V8Entity.h" +#include "../helpers/V8ResourceImpl.h" +#include "cpp-sdk/entities/IVehicle.h" -// static void Constructor(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void Constructor(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(info.IsConstructCall(), "Handling constructor is not a function"); -// V8_CHECK(info.Length() == 1, "new Handling(...) expects 1 arg"); + V8_CHECK(info.IsConstructCall(), "Handling constructor is not a function"); + V8_CHECK(info.Length() == 1, "new Handling(...) expects 1 arg"); -// V8_CHECK(info[0]->IsObject(), "vehicle must be an object"); -// auto objVehicle = info[0]->ToObject(ctx).ToLocalChecked(); + V8_CHECK(info[0]->IsObject(), "vehicle must be an object"); + auto objVehicle = info[0]->ToObject(ctx).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// info.This()->SetInternalField(0, info[0]); -// } + info.This()->SetInternalField(0, info[0]); +} -// static void IsModified(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void IsModified(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As().Get(); + auto netVehicle = v8vehicle->GetHandle().As().Get(); -// V8_RETURN_BOOLEAN(netVehicle->customHandling != nullptr); -// } + V8_RETURN_BOOLEAN(netVehicle->IsHandlingModified()); +} -// static void Reset(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void Reset(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto refVehicle = v8vehicle->GetHandle().As(); + auto refVehicle = v8vehicle->GetHandle().As(); -// CHandlingData::Reset(refVehicle); -// } + refVehicle->ResetHandling(); +} -// static void HandlingNameHashGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void HandlingNameHashGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->HandlingNameHash)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, (vehicle->GetHandling())->GetHandlingNameHash())); +} -// static void MassGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void MassGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->Mass)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetMass())); +} -// static void MassSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "mass must be a number"); +static void MassSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "mass must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->Mass = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetMass((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void InitialDragCoeffGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void InitialDragCoeffGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->InitialDragCoeff)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetInitialDragCoeff())); +} -// static void InitialDragCoeffSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "initialDragCoeff must be a number"); +static void InitialDragCoeffSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "initialDragCoeff must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->InitialDragCoeff = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetInitialDragCoeff((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void DownforceModifierGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void DownforceModifierGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->DownforceModifier)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetDownforceModifier())); +} -// static void DownforceModifierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "downforceModifier must be a number"); +static void DownforceModifierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "downforceModifier must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->DownforceModifier = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetDownforceModifier((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void unkFloat1Getter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void unkFloat1Getter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->unkFloat1)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetunkFloat1())); +} -// static void unkFloat1Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "unkFloat1 must be a number"); +static void unkFloat1Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "unkFloat1 must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->unkFloat1 = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetunkFloat1((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void unkFloat2Getter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void unkFloat2Getter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->unkFloat2)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetunkFloat2())); +} -// static void unkFloat2Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "unkFloat2 must be a number"); +static void unkFloat2Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "unkFloat2 must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->unkFloat2 = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetunkFloat2((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void CentreOfMassOffsetGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void CentreOfMassOffsetGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(resource->CreateVector3(((CHandlingData *)vehicle->GetHandling())->CentreOfMassOffset)); -// } + info.GetReturnValue().Set(resource->CreateVector3((vehicle->GetHandling()->GetCentreOfMassOffset()))); +} -// static void CentreOfMassOffsetSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(val->IsObject(), "centreOfMassOffset must be a Vector3"); +static void CentreOfMassOffsetSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + V8_CHECK(val->IsObject(), "centreOfMassOffset must be a Vector3"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// v8::Local pos = val.As(); + v8::Local pos = val.As(); -// v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); -// v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); -// v8::Local z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); -// ((CHandlingData *)vehicle->GetHandling())->CentreOfMassOffset = {(float)x->Value(), (float)y->Value(), (float)z->Value()}; -// } + vehicle->GetHandling()->SetCentreOfMassOffset({(float)x->Value(), (float)y->Value(), (float)z->Value()}); +} -// static void InertiaMultiplierGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void InertiaMultiplierGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(resource->CreateVector3(((CHandlingData *)vehicle->GetHandling())->InertiaMultiplier)); -// } + info.GetReturnValue().Set(resource->CreateVector3((vehicle->GetHandling()->GetInertiaMultiplier()))); +} -// static void InertiaMultiplierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void InertiaMultiplierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8_CHECK(val->IsObject(), "inertiaMultiplier must be a Vector3"); + V8_CHECK(val->IsObject(), "inertiaMultiplier must be a Vector3"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// v8::Local pos = val.As(); + v8::Local pos = val.As(); -// v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); -// v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); -// v8::Local z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); -// ((CHandlingData *)vehicle->GetHandling())->InertiaMultiplier = {(float)x->Value(), (float)y->Value(), (float)z->Value()}; -// } + vehicle->GetHandling()->SetInertiaMultiplier({(float)x->Value(), (float)y->Value(), (float)z->Value()}); +} -// static void PercentSubmergedGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void PercentSubmergedGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->PercentSubmerged)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetPercentSubmerged())); +} -// static void PercentSubmergedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "percentSubmerged must be a number"); +static void PercentSubmergedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "percentSubmerged must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->PercentSubmerged = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetPercentSubmerged((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void PercentSubmergedRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void PercentSubmergedRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->PercentSubmergedRatio)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetPercentSubmergedRatio())); +} -// static void PercentSubmergedRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "percentSubmergedRatio must be a number"); +static void PercentSubmergedRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "percentSubmergedRatio must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->PercentSubmergedRatio = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetPercentSubmergedRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void DriveBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void DriveBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->DriveBiasFront)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetDriveBiasFront())); +} -// static void DriveBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "driveBiasFront must be a number"); +static void DriveBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "driveBiasFront must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->DriveBiasFront = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetDriveBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void AccelerationGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void AccelerationGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->Acceleration)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetAcceleration())); +} -// static void AccelerationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "acceleration must be a number"); +static void AccelerationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "acceleration must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->Acceleration = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetAcceleration((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->InitialDriveGears)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetInitialDriveGears())); +} -// static void InitialDriveGearsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "initialDriveGears must be a number"); +static void InitialDriveGearsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "initialDriveGears must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->InitialDriveGears = val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value(); -// } + vehicle->GetHandling()->SetInitialDriveGears(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); +} -// static void DriveInertiaGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void DriveInertiaGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->DriveInertia)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetDriveInertia())); +} -// static void DriveInertiaSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "driveInertia must be a number"); +static void DriveInertiaSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "driveInertia must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->DriveInertia = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetDriveInertia((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void ClutchChangeRateScaleUpShiftGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void ClutchChangeRateScaleUpShiftGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->ClutchChangeRateScaleUpShift)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetClutchChangeRateScaleUpShift())); +} -// static void ClutchChangeRateScaleUpShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "clutchChangeRateScaleUpShift must be a number"); +static void ClutchChangeRateScaleUpShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "clutchChangeRateScaleUpShift must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->ClutchChangeRateScaleUpShift = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetClutchChangeRateScaleUpShift((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void ClutchChangeRateScaleDownShiftGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void ClutchChangeRateScaleDownShiftGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->ClutchChangeRateScaleDownShift)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetClutchChangeRateScaleDownShift())); +} -// static void ClutchChangeRateScaleDownShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "clutchChangeRateScaleDownShift must be a number"); +static void ClutchChangeRateScaleDownShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "clutchChangeRateScaleDownShift must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->ClutchChangeRateScaleDownShift = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetClutchChangeRateScaleDownShift((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void InitialDriveForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void InitialDriveForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->InitialDriveForce)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetInitialDriveForce())); +} -// static void InitialDriveForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "initialDriveForce must be a number"); +static void InitialDriveForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "initialDriveForce must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->InitialDriveForce = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetInitialDriveForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void DriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void DriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->DriveMaxFlatVel)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetDriveMaxFlatVel())); +} -// static void DriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "driveMaxFlatVel must be a number"); +static void DriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "driveMaxFlatVel must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->DriveMaxFlatVel = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetDriveMaxFlatVel((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void InitialDriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void InitialDriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->InitialDriveMaxFlatVel)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetInitialDriveMaxFlatVel())); +} -// static void InitialDriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "initialDriveMaxFlatVel must be a number"); +static void InitialDriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "initialDriveMaxFlatVel must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->InitialDriveMaxFlatVel = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetInitialDriveMaxFlatVel((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void BrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void BrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->BrakeForce)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetBrakeForce())); +} -// static void BrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "brakeForce must be a number"); +static void BrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "brakeForce must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->BrakeForce = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetBrakeForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void unkFloat4Getter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void unkFloat4Getter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->unkFloat4)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetunkFloat4())); +} -// static void unkFloat4Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "unkFloat4 must be a number"); +static void unkFloat4Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "unkFloat4 must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->unkFloat4 = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetunkFloat4((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void BrakeBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void BrakeBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->BrakeBiasFront)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetBrakeBiasFront())); +} -// static void BrakeBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "brakeBiasFront must be a number"); +static void BrakeBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "brakeBiasFront must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->BrakeBiasFront = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetBrakeBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void BrakeBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void BrakeBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->BrakeBiasRear)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetBrakeBiasRear())); +} -// static void BrakeBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "brakeBiasRear must be a number"); +static void BrakeBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "brakeBiasRear must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->BrakeBiasRear = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetBrakeBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void HandBrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void HandBrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->HandBrakeForce)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetHandBrakeForce())); +} -// static void HandBrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "handBrakeForce must be a number"); +static void HandBrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "handBrakeForce must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->HandBrakeForce = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetHandBrakeForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SteeringLockGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SteeringLockGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SteeringLock)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSteeringLock())); +} -// static void SteeringLockSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "steeringLock must be a number"); +static void SteeringLockSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "steeringLock must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SteeringLock = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSteeringLock((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SteeringLockRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SteeringLockRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SteeringLockRatio)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSteeringLockRatio())); +} -// static void SteeringLockRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "steeringLockRatio must be a number"); +static void SteeringLockRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "steeringLockRatio must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SteeringLockRatio = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSteeringLockRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void TractionCurveMaxGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void TractionCurveMaxGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionCurveMax)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionCurveMax())); +} -// static void TractionCurveMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "tractionCurveMax must be a number"); +static void TractionCurveMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionCurveMax must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->TractionCurveMax = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetTractionCurveMax((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void TractionCurveMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void TractionCurveMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionCurveMaxRatio)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionCurveMaxRatio())); +} -// static void TractionCurveMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "tractionCurveMaxRatio must be a number"); +static void TractionCurveMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionCurveMaxRatio must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->TractionCurveMaxRatio = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetTractionCurveMaxRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void TractionCurveMinGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void TractionCurveMinGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionCurveMin)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionCurveMin())); +} -// static void TractionCurveMinSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "tractionCurveMin must be a number"); +static void TractionCurveMinSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionCurveMin must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->TractionCurveMin = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetTractionCurveMin((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void TractionCurveMinRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void TractionCurveMinRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionCurveMinRatio)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionCurveMinRatio())); +} -// static void TractionCurveMinRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "tractionCurveMinRatio must be a number"); +static void TractionCurveMinRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionCurveMinRatio must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->TractionCurveMinRatio = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetTractionCurveMinRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void TractionCurveLateralGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void TractionCurveLateralGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionCurveLateral)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionCurveLateral())); +} -// static void TractionCurveLateralSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "tractionCurveLateral must be a number"); +static void TractionCurveLateralSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionCurveLateral must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->TractionCurveLateral = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetTractionCurveLateral((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void TractionCurveLateralRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void TractionCurveLateralRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionCurveLateralRatio)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionCurveLateralRatio())); +} -// static void TractionCurveLateralRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "tractionCurveLateralRatio must be a number"); +static void TractionCurveLateralRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionCurveLateralRatio must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->TractionCurveLateralRatio = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetTractionCurveLateralRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void TractionSpringDeltaMaxGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void TractionSpringDeltaMaxGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionSpringDeltaMax)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionSpringDeltaMax())); +} -// static void TractionSpringDeltaMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "tractionSpringDeltaMax must be a number"); +static void TractionSpringDeltaMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionSpringDeltaMax must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->TractionSpringDeltaMax = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetTractionSpringDeltaMax((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void TractionSpringDeltaMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void TractionSpringDeltaMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionSpringDeltaMaxRatio)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionSpringDeltaMaxRatio())); +} -// static void TractionSpringDeltaMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "tractionSpringDeltaMaxRatio must be a number"); +static void TractionSpringDeltaMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionSpringDeltaMaxRatio must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->TractionSpringDeltaMaxRatio = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetTractionSpringDeltaMaxRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void LowSpeedTractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void LowSpeedTractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->LowSpeedTractionLossMult)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetLowSpeedTractionLossMult())); +} -// static void LowSpeedTractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "lowSpeedTractionLossMult must be a number"); +static void LowSpeedTractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "lowSpeedTractionLossMult must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->LowSpeedTractionLossMult = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetLowSpeedTractionLossMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void CamberStiffnesssGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void CamberStiffnesssGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->CamberStiffnesss)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetCamberStiffnesss())); +} -// static void CamberStiffnesssSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "camberStiffnesss must be a number"); +static void CamberStiffnesssSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "camberStiffnesss must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->CamberStiffnesss = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetCamberStiffnesss((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void TractionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void TractionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionBiasFront)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionBiasFront())); +} -// static void TractionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "tractionBiasFront must be a number"); +static void TractionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionBiasFront must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->TractionBiasFront = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetTractionBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void TractionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void TractionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionBiasRear)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionBiasRear())); +} -// static void TractionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "tractionBiasRear must be a number"); +static void TractionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionBiasRear must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->TractionBiasRear = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetTractionBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void TractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void TractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->TractionLossMult)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionLossMult())); +} -// static void TractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "tractionLossMult must be a number"); +static void TractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "tractionLossMult must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->TractionLossMult = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetTractionLossMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SuspensionForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SuspensionForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionForce)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionForce())); +} -// static void SuspensionForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "suspensionForce must be a number"); +static void SuspensionForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionForce must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SuspensionForce = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSuspensionForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SuspensionCompDampGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SuspensionCompDampGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionCompDamp)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionCompDamp())); +} -// static void SuspensionCompDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "suspensionCompDamp must be a number"); +static void SuspensionCompDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionCompDamp must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SuspensionCompDamp = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSuspensionCompDamp((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SuspensionReboundDampGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SuspensionReboundDampGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionReboundDamp)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionReboundDamp())); +} -// static void SuspensionReboundDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "suspensionReboundDamp must be a number"); +static void SuspensionReboundDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionReboundDamp must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SuspensionReboundDamp = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSuspensionReboundDamp((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SuspensionUpperLimitGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SuspensionUpperLimitGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionUpperLimit)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionUpperLimit())); +} -// static void SuspensionUpperLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "suspensionUpperLimit must be a number"); +static void SuspensionUpperLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionUpperLimit must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SuspensionUpperLimit = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSuspensionUpperLimit((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SuspensionLowerLimitGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SuspensionLowerLimitGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionLowerLimit)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionLowerLimit())); +} -// static void SuspensionLowerLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "suspensionLowerLimit must be a number"); +static void SuspensionLowerLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionLowerLimit must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SuspensionLowerLimit = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSuspensionLowerLimit((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SuspensionRaiseGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SuspensionRaiseGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionRaise)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionRaise())); +} -// static void SuspensionRaiseSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "suspensionRaise must be a number"); +static void SuspensionRaiseSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionRaise must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SuspensionRaise = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSuspensionRaise((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SuspensionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SuspensionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionBiasFront)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionBiasFront())); +} -// static void SuspensionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "suspensionBiasFront must be a number"); +static void SuspensionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionBiasFront must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SuspensionBiasFront = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSuspensionBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SuspensionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SuspensionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SuspensionBiasRear)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionBiasRear())); +} -// static void SuspensionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "suspensionBiasRear must be a number"); +static void SuspensionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "suspensionBiasRear must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SuspensionBiasRear = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSuspensionBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void AntiRollBarForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void AntiRollBarForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->AntiRollBarForce)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetAntiRollBarForce())); +} -// static void AntiRollBarForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "antiRollBarForce must be a number"); +static void AntiRollBarForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "antiRollBarForce must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->AntiRollBarForce = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetAntiRollBarForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void AntiRollBarBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void AntiRollBarBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->AntiRollBarBiasFront)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetAntiRollBarBiasFront())); +} -// static void AntiRollBarBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "antiRollBarBiasFront must be a number"); +static void AntiRollBarBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "antiRollBarBiasFront must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->AntiRollBarBiasFront = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetAntiRollBarBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void AntiRollBarBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void AntiRollBarBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->AntiRollBarBiasRear)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetAntiRollBarBiasRear())); +} -// static void AntiRollBarBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "antiRollBarBiasRear must be a number"); +static void AntiRollBarBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "antiRollBarBiasRear must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->AntiRollBarBiasRear = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetAntiRollBarBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void RollCentreHeightFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void RollCentreHeightFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->RollCentreHeightFront)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetRollCentreHeightFront())); +} -// static void RollCentreHeightFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "rollCentreHeightFront must be a number"); +static void RollCentreHeightFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "rollCentreHeightFront must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->RollCentreHeightFront = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetRollCentreHeightFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void RollCentreHeightRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void RollCentreHeightRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->RollCentreHeightRear)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetRollCentreHeightRear())); +} -// static void RollCentreHeightRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "rollCentreHeightRear must be a number"); +static void RollCentreHeightRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "rollCentreHeightRear must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->RollCentreHeightRear = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetRollCentreHeightRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void CollisionDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void CollisionDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->CollisionDamageMult)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetCollisionDamageMult())); +} -// static void CollisionDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "collisionDamageMult must be a number"); +static void CollisionDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "collisionDamageMult must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->CollisionDamageMult = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetCollisionDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void WeaponDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void WeaponDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->WeaponDamageMult)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetWeaponDamageMult())); +} -// static void WeaponDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "weaponDamageMult must be a number"); +static void WeaponDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "weaponDamageMult must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->WeaponDamageMult = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetWeaponDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void DeformationDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void DeformationDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->DeformationDamageMult)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetDeformationDamageMult())); +} -// static void DeformationDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "deformationDamageMult must be a number"); +static void DeformationDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "deformationDamageMult must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->DeformationDamageMult = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetDeformationDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void EngineDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void EngineDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->EngineDamageMult)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetEngineDamageMult())); +} -// static void EngineDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "engineDamageMult must be a number"); +static void EngineDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "engineDamageMult must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->EngineDamageMult = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetEngineDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void PetrolTankVolumeGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void PetrolTankVolumeGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->PetrolTankVolume)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetPetrolTankVolume())); +} -// static void PetrolTankVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "petrolTankVolume must be a number"); +static void PetrolTankVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "petrolTankVolume must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->PetrolTankVolume = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetPetrolTankVolume((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void OilVolumeGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void OilVolumeGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->OilVolume)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetOilVolume())); +} -// static void OilVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "oilVolume must be a number"); +static void OilVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "oilVolume must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->OilVolume = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetOilVolume((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void unkFloat5Getter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void unkFloat5Getter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->unkFloat5)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetunkFloat5())); +} -// static void unkFloat5Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "unkFloat5 must be a number"); +static void unkFloat5Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "unkFloat5 must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->unkFloat5 = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetunkFloat5((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SeatOffsetDistXGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SeatOffsetDistXGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SeatOffsetDistX)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSeatOffsetDistX())); +} -// static void SeatOffsetDistXSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "seatOffsetDistX must be a number"); +static void SeatOffsetDistXSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "seatOffsetDistX must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SeatOffsetDistX = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSeatOffsetDistX((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SeatOffsetDistYGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SeatOffsetDistYGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SeatOffsetDistY)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSeatOffsetDistY())); +} -// static void SeatOffsetDistYSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "seatOffsetDistY must be a number"); +static void SeatOffsetDistYSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "seatOffsetDistY must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SeatOffsetDistY = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSeatOffsetDistY((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void SeatOffsetDistZGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SeatOffsetDistZGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->SeatOffsetDistZ)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSeatOffsetDistZ())); +} -// static void SeatOffsetDistZSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "seatOffsetDistZ must be a number"); +static void SeatOffsetDistZSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "seatOffsetDistZ must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->SeatOffsetDistZ = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + vehicle->GetHandling()->SetSeatOffsetDistZ((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void MonetaryValueGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void MonetaryValueGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->MonetaryValue)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetMonetaryValue())); +} -// static void MonetaryValueSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "monetaryValue must be a number"); +static void MonetaryValueSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "monetaryValue must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->MonetaryValue = val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value(); -// } + vehicle->GetHandling()->SetMonetaryValue(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); +} -// static void ModelFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void ModelFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->ModelFlags)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetModelFlags())); +} -// static void ModelFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "modelFlags must be a number"); +static void ModelFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "modelFlags must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); + auto vehicle = v8vehicle->GetHandle().As(); -// ((CHandlingData *)vehicle->GetHandling())->ModelFlags = val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value(); -// } + vehicle->GetHandling()->SetModelFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); +} -// static void HandlingFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void HandlingFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); + auto vehicle = v8vehicle->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->HandlingFlags)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetHandlingFlags())); +} -// static void HandlingFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "handlingFlags must be a number"); +static void HandlingFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "handlingFlags must be a number"); -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); - -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); - -// ((CHandlingData *)vehicle->GetHandling())->HandlingFlags = val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value(); -// } - -// static void DamageFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); - -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); - -// auto vehicle = (CVehicle *)v8vehicle->GetHandle().As()->GetGameEntity(); - -// info.GetReturnValue().Set(v8::Number::New(isolate, ((CHandlingData *)vehicle->GetHandling())->DamageFlags)); -// } - -// static void DamageFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "damageFlags must be a number"); - -// auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - -// auto v8vehicle = V8Entity::Get(objVehicle); -// V8_CHECK(v8vehicle, "entity is invalid"); - -// auto netVehicle = v8vehicle->GetHandle().As(); -// auto vehicle = (CVehicle *)netVehicle->GetGameEntity(); -// CHandlingData::Replace(netVehicle); - -// ((CHandlingData *)vehicle->GetHandling())->DamageFlags = val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value(); -// } - -// static V8Class v8HandlingData( -// "Handling", "", Constructor, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); - -// v8::Local proto = tpl->PrototypeTemplate(); - -// tpl->InstanceTemplate()->SetInternalFieldCount(1); - -// proto->Set(isolate, "isModified", v8::FunctionTemplate::New(isolate, &IsModified)); -// proto->Set(isolate, "reset", v8::FunctionTemplate::New(isolate, &Reset)); - -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingNameHash").ToLocalChecked(), &HandlingNameHashGetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "mass").ToLocalChecked(), &MassGetter, &MassSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDragCoeff").ToLocalChecked(), &InitialDragCoeffGetter, &InitialDragCoeffSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "downforceModifier").ToLocalChecked(), &DownforceModifierGetter, &DownforceModifierSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat1").ToLocalChecked(), &unkFloat1Getter, &unkFloat1Setter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat2").ToLocalChecked(), &unkFloat2Getter, &unkFloat2Setter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "centreOfMassOffset").ToLocalChecked(), &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "inertiaMultiplier").ToLocalChecked(), &InertiaMultiplierGetter, &InertiaMultiplierSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmerged").ToLocalChecked(), &PercentSubmergedGetter, &PercentSubmergedSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmergedRatio").ToLocalChecked(), &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveBiasFront").ToLocalChecked(), &DriveBiasFrontGetter, &DriveBiasFrontSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "acceleration").ToLocalChecked(), &AccelerationGetter, &AccelerationSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveGears").ToLocalChecked(), &InitialDriveGearsGetter, &InitialDriveGearsSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveInertia").ToLocalChecked(), &DriveInertiaGetter, &DriveInertiaSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleUpShift").ToLocalChecked(), &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleDownShift").ToLocalChecked(), &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveForce").ToLocalChecked(), &InitialDriveForceGetter, &InitialDriveForceSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveMaxFlatVel").ToLocalChecked(), &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveMaxFlatVel").ToLocalChecked(), &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeForce").ToLocalChecked(), &BrakeForceGetter, &BrakeForceSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat4").ToLocalChecked(), &unkFloat4Getter, &unkFloat4Setter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasFront").ToLocalChecked(), &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasRear").ToLocalChecked(), &BrakeBiasRearGetter, &BrakeBiasRearSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handBrakeForce").ToLocalChecked(), &HandBrakeForceGetter, &HandBrakeForceSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLock").ToLocalChecked(), &SteeringLockGetter, &SteeringLockSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLockRatio").ToLocalChecked(), &SteeringLockRatioGetter, &SteeringLockRatioSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMax").ToLocalChecked(), &TractionCurveMaxGetter, &TractionCurveMaxSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMaxRatio").ToLocalChecked(), &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMin").ToLocalChecked(), &TractionCurveMinGetter, &TractionCurveMinSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMinRatio").ToLocalChecked(), &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateral").ToLocalChecked(), &TractionCurveLateralGetter, &TractionCurveLateralSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateralRatio").ToLocalChecked(), &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMax").ToLocalChecked(), &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMaxRatio").ToLocalChecked(), &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lowSpeedTractionLossMult").ToLocalChecked(), &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "camberStiffnesss").ToLocalChecked(), &CamberStiffnesssGetter, &CamberStiffnesssSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasFront").ToLocalChecked(), &TractionBiasFrontGetter, &TractionBiasFrontSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasRear").ToLocalChecked(), &TractionBiasRearGetter, &TractionBiasRearSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionLossMult").ToLocalChecked(), &TractionLossMultGetter, &TractionLossMultSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionForce").ToLocalChecked(), &SuspensionForceGetter, &SuspensionForceSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionCompDamp").ToLocalChecked(), &SuspensionCompDampGetter, &SuspensionCompDampSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionReboundDamp").ToLocalChecked(), &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionUpperLimit").ToLocalChecked(), &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionLowerLimit").ToLocalChecked(), &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionRaise").ToLocalChecked(), &SuspensionRaiseGetter, &SuspensionRaiseSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasFront").ToLocalChecked(), &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasRear").ToLocalChecked(), &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarForce").ToLocalChecked(), &AntiRollBarForceGetter, &AntiRollBarForceSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasFront").ToLocalChecked(), &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasRear").ToLocalChecked(), &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightFront").ToLocalChecked(), &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightRear").ToLocalChecked(), &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "collisionDamageMult").ToLocalChecked(), &CollisionDamageMultGetter, &CollisionDamageMultSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "weaponDamageMult").ToLocalChecked(), &WeaponDamageMultGetter, &WeaponDamageMultSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "deformationDamageMult").ToLocalChecked(), &DeformationDamageMultGetter, &DeformationDamageMultSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "engineDamageMult").ToLocalChecked(), &EngineDamageMultGetter, &EngineDamageMultSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "petrolTankVolume").ToLocalChecked(), &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "oilVolume").ToLocalChecked(), &OilVolumeGetter, &OilVolumeSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat5").ToLocalChecked(), &unkFloat5Getter, &unkFloat5Setter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistX").ToLocalChecked(), &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistY").ToLocalChecked(), &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistZ").ToLocalChecked(), &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "monetaryValue").ToLocalChecked(), &MonetaryValueGetter, &MonetaryValueSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modelFlags").ToLocalChecked(), &ModelFlagsGetter, &ModelFlagsSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingFlags").ToLocalChecked(), &HandlingFlagsGetter, &HandlingFlagsSetter); -// proto->SetAccessor(v8::String::NewFromUtf8(isolate, "damageFlags").ToLocalChecked(), &DamageFlagsGetter, &DamageFlagsSetter); -// }, -// false); \ No newline at end of file + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); + + auto vehicle = v8vehicle->GetHandle().As(); + + vehicle->GetHandling()->SetHandlingFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); +} + +static void DamageFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); + + auto vehicle = v8vehicle->GetHandle().As(); + + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetDamageFlags())); +} + +static void DamageFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "damageFlags must be a number"); + + auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + + auto v8vehicle = V8Entity::Get(objVehicle); + V8_CHECK(v8vehicle, "entity is invalid"); + + auto vehicle = v8vehicle->GetHandle().As(); + + vehicle->GetHandling()->SetDamageFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); +} + +static V8Class v8HandlingData( + "Handling", "", Constructor, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + v8::Local proto = tpl->PrototypeTemplate(); + + tpl->InstanceTemplate()->SetInternalFieldCount(1); + + proto->Set(isolate, "isModified", v8::FunctionTemplate::New(isolate, &IsModified)); + proto->Set(isolate, "reset", v8::FunctionTemplate::New(isolate, &Reset)); + + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingNameHash").ToLocalChecked(), &HandlingNameHashGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "mass").ToLocalChecked(), &MassGetter, &MassSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDragCoeff").ToLocalChecked(), &InitialDragCoeffGetter, &InitialDragCoeffSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "downforceModifier").ToLocalChecked(), &DownforceModifierGetter, &DownforceModifierSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat1").ToLocalChecked(), &unkFloat1Getter, &unkFloat1Setter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat2").ToLocalChecked(), &unkFloat2Getter, &unkFloat2Setter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "centreOfMassOffset").ToLocalChecked(), &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "inertiaMultiplier").ToLocalChecked(), &InertiaMultiplierGetter, &InertiaMultiplierSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmerged").ToLocalChecked(), &PercentSubmergedGetter, &PercentSubmergedSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmergedRatio").ToLocalChecked(), &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveBiasFront").ToLocalChecked(), &DriveBiasFrontGetter, &DriveBiasFrontSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "acceleration").ToLocalChecked(), &AccelerationGetter, &AccelerationSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveGears").ToLocalChecked(), &InitialDriveGearsGetter, &InitialDriveGearsSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveInertia").ToLocalChecked(), &DriveInertiaGetter, &DriveInertiaSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleUpShift").ToLocalChecked(), &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleDownShift").ToLocalChecked(), &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveForce").ToLocalChecked(), &InitialDriveForceGetter, &InitialDriveForceSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveMaxFlatVel").ToLocalChecked(), &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveMaxFlatVel").ToLocalChecked(), &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeForce").ToLocalChecked(), &BrakeForceGetter, &BrakeForceSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat4").ToLocalChecked(), &unkFloat4Getter, &unkFloat4Setter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasFront").ToLocalChecked(), &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasRear").ToLocalChecked(), &BrakeBiasRearGetter, &BrakeBiasRearSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handBrakeForce").ToLocalChecked(), &HandBrakeForceGetter, &HandBrakeForceSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLock").ToLocalChecked(), &SteeringLockGetter, &SteeringLockSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLockRatio").ToLocalChecked(), &SteeringLockRatioGetter, &SteeringLockRatioSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMax").ToLocalChecked(), &TractionCurveMaxGetter, &TractionCurveMaxSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMaxRatio").ToLocalChecked(), &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMin").ToLocalChecked(), &TractionCurveMinGetter, &TractionCurveMinSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMinRatio").ToLocalChecked(), &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateral").ToLocalChecked(), &TractionCurveLateralGetter, &TractionCurveLateralSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateralRatio").ToLocalChecked(), &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMax").ToLocalChecked(), &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMaxRatio").ToLocalChecked(), &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lowSpeedTractionLossMult").ToLocalChecked(), &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "camberStiffnesss").ToLocalChecked(), &CamberStiffnesssGetter, &CamberStiffnesssSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasFront").ToLocalChecked(), &TractionBiasFrontGetter, &TractionBiasFrontSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasRear").ToLocalChecked(), &TractionBiasRearGetter, &TractionBiasRearSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionLossMult").ToLocalChecked(), &TractionLossMultGetter, &TractionLossMultSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionForce").ToLocalChecked(), &SuspensionForceGetter, &SuspensionForceSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionCompDamp").ToLocalChecked(), &SuspensionCompDampGetter, &SuspensionCompDampSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionReboundDamp").ToLocalChecked(), &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionUpperLimit").ToLocalChecked(), &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionLowerLimit").ToLocalChecked(), &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionRaise").ToLocalChecked(), &SuspensionRaiseGetter, &SuspensionRaiseSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasFront").ToLocalChecked(), &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasRear").ToLocalChecked(), &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarForce").ToLocalChecked(), &AntiRollBarForceGetter, &AntiRollBarForceSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasFront").ToLocalChecked(), &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasRear").ToLocalChecked(), &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightFront").ToLocalChecked(), &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightRear").ToLocalChecked(), &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "collisionDamageMult").ToLocalChecked(), &CollisionDamageMultGetter, &CollisionDamageMultSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "weaponDamageMult").ToLocalChecked(), &WeaponDamageMultGetter, &WeaponDamageMultSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "deformationDamageMult").ToLocalChecked(), &DeformationDamageMultGetter, &DeformationDamageMultSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "engineDamageMult").ToLocalChecked(), &EngineDamageMultGetter, &EngineDamageMultSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "petrolTankVolume").ToLocalChecked(), &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "oilVolume").ToLocalChecked(), &OilVolumeGetter, &OilVolumeSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat5").ToLocalChecked(), &unkFloat5Getter, &unkFloat5Setter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistX").ToLocalChecked(), &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistY").ToLocalChecked(), &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistZ").ToLocalChecked(), &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "monetaryValue").ToLocalChecked(), &MonetaryValueGetter, &MonetaryValueSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modelFlags").ToLocalChecked(), &ModelFlagsGetter, &ModelFlagsSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingFlags").ToLocalChecked(), &HandlingFlagsGetter, &HandlingFlagsSetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "damageFlags").ToLocalChecked(), &DamageFlagsGetter, &DamageFlagsSetter); + }, + false); \ No newline at end of file diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 3dd4a993..e36fb7fa 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -1,89 +1,89 @@ -// #include "../helpers/V8Helpers.h" -// #include "../helpers/V8Class.h" -// #include "../helpers/V8Entity.h" -// #include "../helpers/V8ResourceImpl.h" -// #include "cpp-sdk/entities/IVehicle.h" +#include "../helpers/V8Helpers.h" +#include "../helpers/V8Class.h" +#include "../helpers/V8Entity.h" +#include "../helpers/V8ResourceImpl.h" +#include "cpp-sdk/entities/IVehicle.h" -// using namespace alt; +using namespace alt; -// static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// static V8Class *handlingClass = V8Class::Get("Handling"); + static V8Class *handlingClass = V8Class::Get("Handling"); -// std::vector> args{ -// info.This()}; + std::vector> args{ + info.This()}; -// info.GetReturnValue().Set(handlingClass->New(isolate->GetEnteredContext(), args)); -// } + info.GetReturnValue().Set(handlingClass->New(isolate->GetEnteredContext(), args)); +} -// static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref vehicle = _this->GetHandle().As(); + alt::Ref vehicle = _this->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetWheelSpeed())); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetWheelSpeed())); +} -// static void GearGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void GearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref vehicle = _this->GetHandle().As(); + alt::Ref vehicle = _this->GetHandle().As(); -// info.GetReturnValue().Set(v8::Integer::New(isolate, vehicle->GetCurrentGear())); -// } + info.GetReturnValue().Set(v8::Integer::New(isolate, vehicle->GetCurrentGear())); +} -// static void RPMGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void RPMGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref vehicle = _this->GetHandle().As(); + alt::Ref vehicle = _this->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetCurrentRPM())); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetCurrentRPM())); +} -// static void WheelsCountGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void WheelsCountGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref vehicle = _this->GetHandle().As(); + alt::Ref vehicle = _this->GetHandle().As(); -// info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetWheelsCount())); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetWheelsCount())); +} -// static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref vehicle = _this->GetHandle().As(); + alt::Ref vehicle = _this->GetHandle().As(); -// info.GetReturnValue().Set(resource->CreateVector3(vehicle->GetSpeedVector())); -// } + info.GetReturnValue().Set(resource->CreateVector3(vehicle->GetSpeedVector())); +} // static void GravityGetter(v8::Local, const v8::PropertyCallbackInfo &info) // { @@ -95,7 +95,7 @@ // V8Entity *_this = V8Entity::Get(info.This()); // V8_CHECK(_this, "entity is invalid"); -// auto vehicle = _this->GetHandle().As()->GetGameVehicle(); +// auto vehicle = _this->GetHandle().As()->GetGameVehicle(); // V8_CHECK(vehicle, "Could not retrieve game vehicle"); // Log::Debug("GRAVITY", vehicle->gravity); @@ -117,7 +117,7 @@ // V8Entity *_this = V8Entity::Get(info.This()); // V8_CHECK(_this, "entity is invalid"); -// auto vehicle = _this->GetHandle().As()->GetGameVehicle(); +// auto vehicle = _this->GetHandle().As()->GetGameVehicle(); // V8_CHECK(vehicle, "Could not retrieve game vehicle"); // Log::Debug("GRAVITY", vehicle->gravity); @@ -126,58 +126,57 @@ // vehicle->gravity = newval; // } -// static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// v8::Local ctx = isolate->GetEnteredContext(); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); - -// v8::Local arr = v8::Array::New(info.GetIsolate()); - -// uint16_t i = 0; -// CGame::Instance().GetEntityManager().ForEach([&](Ref ent) { -// auto vehicle = ent.As(); - -// if (vehicle) -// arr->Set(ctx, i++, resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); -// }); - -// info.GetReturnValue().Set(arr); -// } - -// static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) -// { -// V8_GET_ISOLATE_CONTEXT_RESOURCE(); -// V8_CHECK_ARGS_LEN(1); -// V8_ARG_TO_INTEGER(1, scriptGuid); -// V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid).As()); -// } - -// static void StaticGetByID(const v8::FunctionCallbackInfo &info) -// { -// V8_GET_ISOLATE_CONTEXT_RESOURCE(); -// V8_CHECK_ARGS_LEN(1); -// V8_ARG_TO_INTEGER(1, id); -// V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id).As()); -// } - -// static V8Class v8vehicle("Vehicle", "Entity", nullptr, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); - -// v8::Local proto = tpl->PrototypeTemplate(); - -// V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); -// V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); - -// V8::SetStaticAccessor(isolate, tpl, "all", &AllGetter); - -// V8::SetAccessor(isolate, tpl, "speed", &SpeedGetter); -// V8::SetAccessor(isolate, tpl, "gear", &GearGetter); -// V8::SetAccessor(isolate, tpl, "rpm", &RPMGetter); -// V8::SetAccessor(isolate, tpl, "wheelsCount", &WheelsCountGetter); -// V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); -// V8::SetAccessor(isolate, tpl, "gravity", &GravityGetter, &GravitySetter); -// V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); -// }); +static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + v8::Local ctx = isolate->GetEnteredContext(); + + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + v8::Local arr = v8::Array::New(info.GetIsolate()); + + uint16_t i = 0; + for (auto vehicle : alt::ICore::Instance().GetVehicles()) + { + if (vehicle) + arr->Set(ctx, i++, resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); + }; + + info.GetReturnValue().Set(arr); +} + +static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, scriptGuid); + V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid).As()); +} + +static void StaticGetByID(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, id); + V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id).As()); +} + +static V8Class v8vehicle("Vehicle", "Entity", nullptr, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + v8::Local proto = tpl->PrototypeTemplate(); + + V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); + V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); + + V8::SetStaticAccessor(isolate, tpl, "all", &AllGetter); + + V8::SetAccessor(isolate, tpl, "speed", &SpeedGetter); + V8::SetAccessor(isolate, tpl, "gear", &GearGetter); + V8::SetAccessor(isolate, tpl, "rpm", &RPMGetter); + V8::SetAccessor(isolate, tpl, "wheelsCount", &WheelsCountGetter); + V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); + // V8::SetAccessor(isolate, tpl, "gravity", &GravityGetter, &GravitySetter); + V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); +}); From 7549089c0d0d82338fbc620ff36ff0af38d2adde Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 4 Nov 2020 04:53:19 +0100 Subject: [PATCH 026/564] Fix for static init, refactors and use of symbols --- V8Class.cpp | 18 +++ V8Class.h | 76 ++++++------- V8Entity.h | 46 ++++---- V8Helpers.h | 230 ++++++++++++++++++++------------------- V8Module.h | 76 +++++++------ V8ResourceImpl.cpp | 13 ++- V8ResourceImpl.h | 2 +- V8Timer.h | 21 ++-- bindings/BaseObject.cpp | 2 +- bindings/Entity.cpp | 5 +- bindings/File.cpp | 2 +- bindings/RGBA.cpp | 6 +- bindings/Vector3.cpp | 7 +- bindings/WorldObject.cpp | 3 +- 14 files changed, 269 insertions(+), 238 deletions(-) diff --git a/V8Class.cpp b/V8Class.cpp index 22b8982f..36193f92 100644 --- a/V8Class.cpp +++ b/V8Class.cpp @@ -26,3 +26,21 @@ v8::Local V8Class::New(v8::Local ctx, std::vector V8Class::CreateInstance(v8::Isolate *isolate, v8::Local ctx, std::vector> args) +{ + v8::Local constructor = JSValue(isolate, ctx); + v8::Local obj; + + V8Helpers::TryCatch([&] { + v8::MaybeLocal maybeObj = constructor->CallAsConstructor(ctx, args.size(), args.data()); + + if (maybeObj.IsEmpty()) + return false; + + obj = maybeObj.ToLocalChecked(); + return true; + }); + + return obj; +} diff --git a/V8Class.h b/V8Class.h index 5c46d97b..c2bd5767 100644 --- a/V8Class.h +++ b/V8Class.h @@ -9,12 +9,11 @@ class V8Class { using InitCallback = std::function)>; - std::string parentName; + V8Class *parent = nullptr; std::string name; v8::FunctionCallback constructor; InitCallback initCb; v8::Persistent tpl; - bool isWrapper; bool loaded = false; public: @@ -26,15 +25,40 @@ class V8Class V8Class( const std::string &className, - const std::string &parentName, + V8Class &parent, v8::FunctionCallback constructor, - InitCallback &&init = {}, - bool _isWrapper = true // TODO: refactor - ) : parentName(parentName), - name(className), - constructor(constructor), - initCb(std::move(init)), - isWrapper(_isWrapper) + InitCallback &&init = {}) : parent(&parent), + name(className), + constructor(constructor), + initCb(std::move(init)) + { + All()[name] = this; + } + + V8Class( + const std::string &className, + V8Class &parent, + InitCallback &&init = {}) : parent(&parent), + name(className), + initCb(std::move(init)) + { + All()[name] = this; + } + + V8Class( + const std::string &className, + v8::FunctionCallback constructor, + InitCallback &&init = {}) : name(className), + constructor(constructor), + initCb(std::move(init)) + { + All()[name] = this; + } + + V8Class( + const std::string &className, + InitCallback &&init = {}) : name(className), + initCb(std::move(init)) { All()[name] = this; } @@ -54,6 +78,8 @@ class V8Class return obj; } + v8::Local CreateInstance(v8::Isolate *isolate, v8::Local ctx, std::vector> args); + v8::Local JSValue(v8::Isolate *isolate, v8::Local ctx) { return tpl.Get(isolate)->GetFunction(ctx).ToLocalChecked(); @@ -61,16 +87,6 @@ class V8Class v8::Local New(v8::Local ctx, std::vector> &args); - static V8Class *Get(const std::string &name) - { - auto it = All().find(name); - - if (it != All().end()) - return it->second; - else - return nullptr; - } - static void LoadAll(v8::Isolate *isolate) { for (auto &p : All()) @@ -87,27 +103,13 @@ class V8Class v8::Local _tpl = v8::FunctionTemplate::New(isolate, constructor); _tpl->SetClassName(v8::String::NewFromUtf8(isolate, name.c_str(), v8::NewStringType::kNormal).ToLocalChecked()); - if (isWrapper) - _tpl->InstanceTemplate()->SetInternalFieldCount(1); - if (initCb) initCb(_tpl); - if (!parentName.empty()) + if (parent) { - V8Class *parentClass = Get(parentName); - - if (!parentClass) - { - std::string msg = "[V8] Class '" + name + "' attempted to inherit non-existant class '" + parentName + "'"; - - Log::Error << msg << Log::Endl; - throw std::runtime_error(msg); - } - - parentClass->Load(isolate); - - _tpl->Inherit(parentClass->tpl.Get(isolate)); + parent->Load(isolate); + _tpl->Inherit(parent->tpl.Get(isolate)); } if (!tpl.IsEmpty()) diff --git a/V8Entity.h b/V8Entity.h index 8c42faac..c10b624d 100644 --- a/V8Entity.h +++ b/V8Entity.h @@ -2,33 +2,32 @@ #include -#include "cpp-sdk/entities/IEntity.h" +#include "cpp-sdk/objects/IEntity.h" #include "V8Class.h" class V8Entity { - V8Class* _class; + V8Class *_class; alt::Ref handle; v8::Persistent jsVal; public: - V8Entity(v8::Local ctx, V8Class* __class, v8::Local obj, alt::Ref _handle) : - _class(__class), - handle(_handle) + V8Entity(v8::Local ctx, V8Class *__class, v8::Local obj, alt::Ref _handle) : _class(__class), + handle(_handle) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); obj->SetInternalField(0, v8::External::New(isolate, this)); jsVal.Reset(isolate, obj); } - V8Class* GetClass() { return _class; } + V8Class *GetClass() { return _class; } alt::Ref GetHandle() { return handle; } - v8::Local GetJSVal(v8::Isolate* isolate) { return jsVal.Get(isolate); } + v8::Local GetJSVal(v8::Isolate *isolate) { return jsVal.Get(isolate); } - static V8Entity* Get(v8::Local val) + static V8Entity *Get(v8::Local val) { if (!val->IsObject()) return nullptr; @@ -41,30 +40,35 @@ class V8Entity if (!i->IsExternal()) return nullptr; - return static_cast(i.As()->Value()); + return static_cast(i.As()->Value()); } - static V8Class* GetClass(alt::Ref handle) + static V8Class *GetClass(alt::Ref handle) { + extern V8Class v8Player, v8Vehicle, v8Blip, v8WebView, v8VoiceChannel, v8Colshape, v8Checkpoint; + if (!handle) return nullptr; switch (handle->GetType()) { case alt::IBaseObject::Type::PLAYER: - return V8Class::Get("Player"); + return &v8Player; case alt::IBaseObject::Type::VEHICLE: - return V8Class::Get("Vehicle"); - case alt::IBaseObject::Type::BLIP: - return V8Class::Get("Blip"); - case alt::IBaseObject::Type::WEBVIEW: - return V8Class::Get("WebView"); - case alt::IBaseObject::Type::VOICE_CHANNEL: - return V8Class::Get("VoiceChannel"); + return &v8Vehicle; +#ifdef ALT_SERVER_API case alt::IBaseObject::Type::COLSHAPE: - return V8Class::Get("Colshape"); + return &v8Colshape; case alt::IBaseObject::Type::CHECKPOINT: - return V8Class::Get("Checkpoint"); + return &v8Checkpoint; + case alt::IBaseObject::Type::VOICE_CHANNEL: + return &v8VoiceChannel; +#else + // case alt::IBaseObject::Type::BLIP: + // return &v8Blip; + case alt::IBaseObject::Type::WEBVIEW: + return &v8WebView; +#endif } return nullptr; diff --git a/V8Helpers.h b/V8Helpers.h index c220628d..aed8efd7 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -5,13 +5,19 @@ #include -#include "cpp-sdk/entities/IEntity.h" +#include "cpp-sdk/objects/IEntity.h" #include "cpp-sdk/types/MValue.h" #include "V8Entity.h" -class V8Helpers +namespace V8Helpers { -public: + inline void Throw(v8::Isolate *isolate, const std::string &msg) + { + isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(isolate, msg.data(), v8::NewStringType::kNormal, msg.size()).ToLocalChecked())); + } + + bool TryCatch(const std::function &fn); + struct HashFunc { size_t operator()(v8::Local fn) const @@ -33,12 +39,12 @@ class V8Helpers public: using Callback = std::function ctx, v8::Local exports)>; - Binding(Callback&& fn) + Binding(Callback &&fn) { All().push_back(std::move(fn)); } - static std::vector& All() + static std::vector &All() { static std::vector _All; return _All; @@ -46,19 +52,14 @@ class V8Helpers static void RegisterAll(v8::Local ctx, v8::Local exports) { - for (auto& binding : All()) + for (auto &binding : All()) binding(ctx, exports); } }; - static void Throw(v8::Isolate* isolate, const std::string& msg) + inline void RegisterFunc(v8::Local exports, const std::string &_name, v8::FunctionCallback cb, void *data = nullptr) { - isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(isolate, msg.data(), v8::NewStringType::kNormal, msg.size()).ToLocalChecked())); - } - - static void RegisterFunc(v8::Local exports, const std::string& _name, v8::FunctionCallback cb, void* data = nullptr) - { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local ctx = isolate->GetEnteredContext(); v8::Local name = v8::String::NewFromUtf8(isolate, _name.data(), v8::NewStringType::kNormal, _name.size()).ToLocalChecked(); @@ -69,27 +70,27 @@ class V8Helpers exports->Set(ctx, name, fn); } - static bool TryCatch(const std::function& fn); - - static void FunctionCallback(const v8::FunctionCallbackInfo& info); + void FunctionCallback(const v8::FunctionCallbackInfo &info); - static alt::MValue V8ToMValue(v8::Local val); + alt::MValue V8ToMValue(v8::Local val); - static v8::Local MValueToV8(alt::MValueConst val); + v8::Local MValueToV8(alt::MValueConst val); - static void MValueArgsToV8(alt::MValueArgs args, std::vector>& v8Args) + inline void MValueArgsToV8(alt::MValueArgs args, std::vector> &v8Args) { for (uint64_t i = 0; i < args.GetSize(); ++i) v8Args.push_back(MValueToV8(args[i])); } - static void SetAccessor(v8::Local tpl, v8::Isolate* isolate, const char* name, v8::AccessorGetterCallback getter, - v8::AccessorSetterCallback setter = nullptr) + inline void SetAccessor(v8::Local tpl, v8::Isolate *isolate, const char *name, v8::AccessorGetterCallback getter, + v8::AccessorSetterCallback setter = nullptr) { tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, name, - v8::NewStringType::kInternalized).ToLocalChecked(), getter, setter); + v8::NewStringType::kInternalized) + .ToLocalChecked(), + getter, setter); } -}; +}; // namespace V8Helpers class V8ResourceImpl; @@ -98,13 +99,13 @@ namespace V8 class SourceLocation { public: - SourceLocation(std::string&& fileName, int line); - SourceLocation() { }; + SourceLocation(std::string &&fileName, int line); + SourceLocation(){}; - const std::string& GetFileName() const { return fileName; } + const std::string &GetFileName() const { return fileName; } int GetLineNumber() const { return line; } - static SourceLocation GetCurrent(v8::Isolate* isolate); + static SourceLocation GetCurrent(v8::Isolate *isolate); private: std::string fileName; @@ -117,100 +118,97 @@ namespace V8 SourceLocation location; bool removed = false; - EventCallback(v8::Isolate* isolate, v8::Local _fn, SourceLocation&& location) : - fn(isolate, _fn), location(std::move(location)) { } + EventCallback(v8::Isolate *isolate, v8::Local _fn, SourceLocation &&location) : fn(isolate, _fn), location(std::move(location)) {} }; class EventHandler { public: - using CallbacksGetter = std::function(V8ResourceImpl* resource, const alt::CEvent*)>; - using ArgsGetter = std::function>& args)>; + using CallbacksGetter = std::function(V8ResourceImpl *resource, const alt::CEvent *)>; + using ArgsGetter = std::function> &args)>; - EventHandler(alt::CEvent::Type type, CallbacksGetter&& _handlersGetter, ArgsGetter&& _argsGetter) : - callbacksGetter(std::move(_handlersGetter)), argsGetter(std::move(_argsGetter)) + EventHandler(alt::CEvent::Type type, CallbacksGetter &&_handlersGetter, ArgsGetter &&_argsGetter) : callbacksGetter(std::move(_handlersGetter)), argsGetter(std::move(_argsGetter)) { Register(type, this); } - std::vector GetCallbacks(V8ResourceImpl* impl, const alt::CEvent* e); - std::vector> GetArgs(V8ResourceImpl* impl, const alt::CEvent* e); + std::vector GetCallbacks(V8ResourceImpl *impl, const alt::CEvent *e); + std::vector> GetArgs(V8ResourceImpl *impl, const alt::CEvent *e); - static EventHandler* Get(const alt::CEvent* e); + static EventHandler *Get(const alt::CEvent *e); private: CallbacksGetter callbacksGetter; ArgsGetter argsGetter; - static std::unordered_map& all() + static std::unordered_map &all() { - static std::unordered_map _all; + static std::unordered_map _all; return _all; } - static void Register(alt::CEvent::Type type, EventHandler* handler); + static void Register(alt::CEvent::Type type, EventHandler *handler); }; class LocalEventHandler : public EventHandler { public: - LocalEventHandler(alt::CEvent::Type type, const std::string& name, ArgsGetter&& argsGetter) : - EventHandler(type, std::move(GetCallbacksGetter(name)), std::move(argsGetter)) { } + LocalEventHandler(alt::CEvent::Type type, const std::string &name, ArgsGetter &&argsGetter) : EventHandler(type, std::move(GetCallbacksGetter(name)), std::move(argsGetter)) {} private: - static CallbacksGetter GetCallbacksGetter(const std::string& name); + static CallbacksGetter GetCallbacksGetter(const std::string &name); }; - void DefineOwnProperty(v8::Isolate* isolate, v8::Local ctx, v8::Local val, - const char* name, v8::Local value, v8::PropertyAttribute attributes = v8::PropertyAttribute::None); + void DefineOwnProperty(v8::Isolate *isolate, v8::Local ctx, v8::Local val, + const char *name, v8::Local value, v8::PropertyAttribute attributes = v8::PropertyAttribute::None); - void DefineOwnProperty(v8::Isolate* isolate, v8::Local ctx, v8::Local val, - v8::Local name, v8::Local value, v8::PropertyAttribute attributes = v8::PropertyAttribute::None); + void DefineOwnProperty(v8::Isolate *isolate, v8::Local ctx, v8::Local val, + v8::Local name, v8::Local value, v8::PropertyAttribute attributes = v8::PropertyAttribute::None); - void SetAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name, - v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter = nullptr); + void SetAccessor(v8::Isolate *isolate, v8::Local tpl, const char *name, + v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter = nullptr); - void SetMethod(v8::Isolate* isolate, v8::Local tpl, const char* name, - v8::FunctionCallback callback); + void SetMethod(v8::Isolate *isolate, v8::Local tpl, const char *name, + v8::FunctionCallback callback); - void SetStaticAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name, - v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter = nullptr); + void SetStaticAccessor(v8::Isolate *isolate, v8::Local tpl, const char *name, + v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter = nullptr); - void SetStaticMethod(v8::Isolate* isolate, v8::Local tpl, const char* name, - v8::FunctionCallback callback); + void SetStaticMethod(v8::Isolate *isolate, v8::Local tpl, const char *name, + v8::FunctionCallback callback); - void SetFunction(v8::Isolate* isolate, v8::Local ctx, v8::Local target, - const char* name, v8::FunctionCallback cb, void* userData = nullptr); + void SetFunction(v8::Isolate *isolate, v8::Local ctx, v8::Local target, + const char *name, v8::FunctionCallback cb, void *userData = nullptr); - v8::Local Get(v8::Local ctx, v8::Local obj, const char* name); + v8::Local Get(v8::Local ctx, v8::Local obj, const char *name); v8::Local Get(v8::Local ctx, v8::Local obj, v8::Local name); void RegisterSharedMain(v8::Local ctx, v8::Local exports); - v8::Local New(v8::Isolate* isolate, v8::Local ctx, v8::Local constructor, std::vector>& args); + v8::Local New(v8::Isolate *isolate, v8::Local ctx, v8::Local constructor, std::vector> &args); // TODO: create c++ classes for v8 classes and move there - v8::Local Vector3_XKey(v8::Isolate* isolate); - v8::Local Vector3_YKey(v8::Isolate* isolate); - v8::Local Vector3_ZKey(v8::Isolate* isolate); + v8::Local Vector3_XKey(v8::Isolate *isolate); + v8::Local Vector3_YKey(v8::Isolate *isolate); + v8::Local Vector3_ZKey(v8::Isolate *isolate); - v8::Local RGBA_RKey(v8::Isolate* isolate); - v8::Local RGBA_GKey(v8::Isolate* isolate); - v8::Local RGBA_BKey(v8::Isolate* isolate); - v8::Local RGBA_AKey(v8::Isolate* isolate); + v8::Local RGBA_RKey(v8::Isolate *isolate); + v8::Local RGBA_GKey(v8::Isolate *isolate); + v8::Local RGBA_BKey(v8::Isolate *isolate); + v8::Local RGBA_AKey(v8::Isolate *isolate); - v8::Local Fire_PosKey(v8::Isolate* isolate); - v8::Local Fire_WeaponKey(v8::Isolate* isolate); + v8::Local Fire_PosKey(v8::Isolate *isolate); + v8::Local Fire_WeaponKey(v8::Isolate *isolate); - bool SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool& out); - bool SafeToInteger(v8::Local val, v8::Local ctx, int64_t& out); - bool SafeToNumber(v8::Local val, v8::Local ctx, double& out); - bool SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String& out); + bool SafeToBoolean(v8::Local val, v8::Isolate *isolate, bool &out); + bool SafeToInteger(v8::Local val, v8::Local ctx, int64_t &out); + bool SafeToNumber(v8::Local val, v8::Local ctx, double &out); + bool SafeToString(v8::Local val, v8::Isolate *isolate, v8::Local ctx, alt::String &out); template - bool SafeToBaseObject(v8::Local val, v8::Isolate* isolate, alt::Ref& out) + bool SafeToBaseObject(v8::Local val, v8::Isolate *isolate, alt::Ref &out) { - V8Entity* v8BaseObject = V8Entity::Get(val); + V8Entity *v8BaseObject = V8Entity::Get(val); if (!v8BaseObject) return false; @@ -220,86 +218,90 @@ namespace V8 return true; } -} +} // namespace V8 -#define V8_GET_ISOLATE(info) v8::Isolate* isolate = (info).GetIsolate() +#define V8_GET_ISOLATE(info) v8::Isolate *isolate = (info).GetIsolate() #define V8_GET_CONTEXT(isolate) v8::Local ctx = (isolate)->GetEnteredContext() #define V8_GET_ISOLATE_CONTEXT() \ - V8_GET_ISOLATE(info); \ + V8_GET_ISOLATE(info); \ V8_GET_CONTEXT(isolate) -#define V8_GET_RESOURCE() \ - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); \ +#define V8_GET_RESOURCE() \ + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); \ V8_CHECK(resource, "invalid resource"); #define V8_GET_ISOLATE_CONTEXT_RESOURCE() \ - V8_GET_ISOLATE_CONTEXT(); \ + V8_GET_ISOLATE_CONTEXT(); \ V8_GET_RESOURCE() -#define V8_CHECK_RETN(a, b, c) if (!(a)) { V8Helpers::Throw(isolate, (b)); return c; } -#define V8_CHECK(a, b) V8_CHECK_RETN(a, b,) - -#define V8_GET_THIS_BASE_OBJECT(val, type) \ - ::alt::Ref val; \ - { \ - V8Entity* __val = V8Entity::Get(info.This()); \ - V8_CHECK(__val, "baseobject is invalid"); \ - val = __val->GetHandle().As(); \ +#define V8_CHECK_RETN(a, b, c) \ + if (!(a)) \ + { \ + V8Helpers::Throw(isolate, (b)); \ + return c; \ + } +#define V8_CHECK(a, b) V8_CHECK_RETN(a, b, ) + +#define V8_GET_THIS_BASE_OBJECT(val, type) \ + ::alt::Ref val; \ + { \ + V8Entity *__val = V8Entity::Get(info.This()); \ + V8_CHECK(__val, "baseobject is invalid"); \ + val = __val->GetHandle().As(); \ V8_CHECK(val, "baseobject is not of type " #type); \ } - #define V8_CHECK_CONSTRUCTOR() V8_CHECK(info.IsConstructCall(), "function can't be called without new") #define V8_CHECK_ARGS_LEN(count) V8_CHECK(info.Length() == (count), #count " arguments expected") #define V8_CHECK_ARGS_LEN2(count1, count2) V8_CHECK(info.Length() == (count1) || info.Length() == (count2), #count1 " or " #count2 " arguments expected") #define V8_TO_BOOLEAN(v8Val, val) \ - bool val; \ + bool val; \ V8_CHECK(V8::SafeToBoolean((v8Val), isolate, val), "Failed to convert value to boolean") #define V8_TO_NUMBER(v8Val, val) \ - double val; \ + double val; \ V8_CHECK(V8::SafeToNumber((v8Val), ctx, val), "Failed to convert value to number") // idx starts with 1 -#define V8_ARG_CHECK_NUMBER(idx) V8_CHECK(info[(idx) - 1]->IsNumber(), "Argument " #idx " must be a number") +#define V8_ARG_CHECK_NUMBER(idx) V8_CHECK(info[(idx)-1]->IsNumber(), "Argument " #idx " must be a number") // idx starts with 1 #define V8_ARG_TO_BOOLEAN(idx, val) \ - bool val; \ - V8_CHECK(V8::SafeToBoolean(info[(idx) - 1], isolate, val), "Failed to convert argument " #idx " to boolean") + bool val; \ + V8_CHECK(V8::SafeToBoolean(info[(idx)-1], isolate, val), "Failed to convert argument " #idx " to boolean") // idx starts with 1 -#define V8_ARG_TO_BOOLEAN_OPT(idx, val, defaultVal) \ - bool val; \ - if (info.Length() >= (idx)) \ - { \ - V8_CHECK(V8::SafeToBoolean(info[(idx) - 1], isolate, val), "Failed to convert argument " #idx " to boolean"); \ - } \ - else \ - { \ - val = defaultVal; \ +#define V8_ARG_TO_BOOLEAN_OPT(idx, val, defaultVal) \ + bool val; \ + if (info.Length() >= (idx)) \ + { \ + V8_CHECK(V8::SafeToBoolean(info[(idx)-1], isolate, val), "Failed to convert argument " #idx " to boolean"); \ + } \ + else \ + { \ + val = defaultVal; \ } // idx starts with 1 #define V8_ARG_TO_INTEGER(idx, val) \ - int64_t val; \ - V8_CHECK(V8::SafeToInteger(info[(idx) - 1], ctx, val), "Failed to convert argument " #idx " to integer") + int64_t val; \ + V8_CHECK(V8::SafeToInteger(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to integer") // idx starts with 1 #define V8_ARG_TO_NUMBER(idx, val) \ - double val; \ - V8_CHECK(V8::SafeToNumber(info[(idx) - 1], ctx, val), "Failed to convert argument " #idx " to number") + double val; \ + V8_CHECK(V8::SafeToNumber(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to number") // idx starts with 1 #define V8_ARG_TO_STRING(idx, val) \ - alt::String val; \ - V8_CHECK(V8::SafeToString(info[(idx) - 1], isolate, ctx, val), "Failed to convert argument " #idx " to string") + alt::String val; \ + V8_CHECK(V8::SafeToString(info[(idx)-1], isolate, ctx, val), "Failed to convert argument " #idx " to string") // idx starts with 1 #define V8_ARG_TO_BASE_OBJECT(idx, val, type, jsClassName) \ - alt::Ref val; \ + alt::Ref val; \ V8_CHECK(V8::SafeToBaseObject(info[(idx)-1], isolate, val), "Argument " #idx " must be a " jsClassName) #define V8_RETURN(val) info.GetReturnValue().Set(val) @@ -310,9 +312,9 @@ namespace V8 #define V8_RETURN_BASE_OBJECT(baseObjectRef) V8_RETURN(resource->GetBaseObjectOrNull(baseObjectRef)) -#define V8_BIND_BASE_OBJECT(baseObjectRef, error) \ - { \ - auto baseObject = (baseObjectRef); \ - V8_CHECK(!baseObject.IsEmpty(), error); \ +#define V8_BIND_BASE_OBJECT(baseObjectRef, error) \ + { \ + auto baseObject = (baseObjectRef); \ + V8_CHECK(!baseObject.IsEmpty(), error); \ resource->BindEntity(info.This(), baseObject.Get()); \ } diff --git a/V8Module.h b/V8Module.h index 98ca8532..0015b735 100644 --- a/V8Module.h +++ b/V8Module.h @@ -7,63 +7,67 @@ #include "V8Class.h" #include -class V8Module { +class V8Module +{ using Callback = std::function ctx, v8::Local exports)>; - -public: - static std::map& All() +public: + static std::map &All() { - static std::map all; + static std::map all; return all; } - static bool Exists(const std::string& name) + static void Add(V8Module &module) + { + All()[module.moduleName] = &module; + } + + static void Add(std::initializer_list> modules) + { + for (auto &m : modules) + All()[m.get().moduleName] = &m.get(); + } + + static bool Exists(const std::string &name) { if (All().find(name) == All().end()) - return false; - else - return true; + return false; + else + return true; } std::string moduleName; - std::unordered_set classes; + std::unordered_set classes; Callback creator; + template V8Module( std::string moduleName, - std::initializer_list _classes, - Callback fn - ) : moduleName(moduleName), classes(_classes), creator(fn) + std::initializer_list> _classes, + Callback fn) : moduleName(moduleName), creator(fn) { - All()[moduleName] = this; - } - - void Register(v8::Isolate* isolate, v8::Local context, v8::Local exports) - { - // Load all classes - for (auto& c : classes) - { - V8Class* v8class = V8Class::Get(c); - if (!v8class) - { - auto msg = "[V8] Module '" + moduleName - + "' is attempting to load non-existant class '" + c + "'"; + for (auto &c : _classes) + classes.insert(&c.get()); - Log::Error << msg << Log::Endl; - //throw std::runtime_error(msg); - } + // All()[moduleName] = this; + } - v8class->Register(isolate, context, exports); - } + void Register(v8::Isolate *isolate, v8::Local context, v8::Local exports) + { + // Load all classes + for (auto c : classes) + { + c->Register(isolate, context, exports); + } - creator(context, exports); - } + creator(context, exports); + } - v8::Local GetExports(v8::Isolate* isolate, v8::Local context) + v8::Local GetExports(v8::Isolate *isolate, v8::Local context) { v8::Local _exports = v8::Object::New(isolate); - Register(isolate, context, _exports); - return _exports; + Register(isolate, context, _exports); + return _exports; } }; diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 5b32f955..64179706 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -1,6 +1,6 @@ -#include "cpp-sdk/entities/IPlayer.h" -#include "cpp-sdk/entities/IVehicle.h" +#include "cpp-sdk/objects/IPlayer.h" +#include "cpp-sdk/objects/IVehicle.h" #include "V8ResourceImpl.h" @@ -11,11 +11,12 @@ using namespace alt; +extern V8Class v8Vector3, v8RGBA, v8BaseObject; bool V8ResourceImpl::Start() { - vector3Class.Reset(isolate, V8Class::Get("Vector3")->JSValue(isolate, GetContext())); - rgbaClass.Reset(isolate, V8Class::Get("RGBA")->JSValue(isolate, GetContext())); - baseObjectClass.Reset(isolate, V8Class::Get("BaseObject")->JSValue(isolate, GetContext())); + vector3Class.Reset(isolate, v8Vector3.JSValue(isolate, GetContext())); + rgbaClass.Reset(isolate, v8RGBA.JSValue(isolate, GetContext())); + baseObjectClass.Reset(isolate, v8BaseObject.JSValue(isolate, GetContext())); return true; } @@ -97,7 +98,7 @@ v8::Local V8ResourceImpl::CreateVector3(alt::Vector3f vec) v8::Number::New(isolate, vec[1]), v8::Number::New(isolate, vec[2])}; - return V8::New(isolate, GetContext(), vector3Class.Get(isolate), args); + return v8Vector3.CreateInstance(isolate, GetContext(), args); } v8::Local V8ResourceImpl::CreateRGBA(alt::RGBA rgba) diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index f8d2565a..c592a0cf 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -5,7 +5,7 @@ #include "cpp-sdk/types/MValue.h" #include "cpp-sdk/IResource.h" -#include "cpp-sdk/IBaseObject.h" +#include "cpp-sdk/objects/IBaseObject.h" #include "V8Entity.h" #include "V8Timer.h" diff --git a/V8Timer.h b/V8Timer.h index 16a1758c..8c317aa8 100644 --- a/V8Timer.h +++ b/V8Timer.h @@ -6,14 +6,13 @@ class V8Timer { public: - V8Timer(v8::Isolate* _isolate, v8::Local _context, int64_t curTime, v8::Local _callback, uint32_t _interval, bool _once, V8::SourceLocation&& _location) : - isolate(_isolate), - context(_isolate, _context), - lastRun(curTime), - callback(_isolate, _callback), - interval(_interval), - once(_once), - location(std::move(_location)) + V8Timer(v8::Isolate *_isolate, v8::Local _context, int64_t curTime, v8::Local _callback, uint32_t _interval, bool _once, V8::SourceLocation &&_location) : isolate(_isolate), + context(_isolate, _context), + lastRun(curTime), + callback(_isolate, _callback), + interval(_interval), + once(_once), + location(std::move(_location)) { //Log::Debug << "Create timer: " << curTime << " " << interval << Log::Endl; } @@ -24,7 +23,7 @@ class V8Timer { V8Helpers::TryCatch([&] { v8::MaybeLocal result = callback.Get(isolate)->CallAsFunction(context.Get(isolate), - v8::Undefined(isolate), 0, nullptr); + v8::Undefined(isolate), 0, nullptr); return !result.IsEmpty(); }); @@ -37,10 +36,10 @@ class V8Timer return true; } - const V8::SourceLocation& GetLocation() const { return location; } + const V8::SourceLocation &GetLocation() const { return location; } private: - v8::Isolate* isolate; + v8::Isolate *isolate; v8::Persistent context; v8::Persistent callback; int64_t interval; diff --git a/bindings/BaseObject.cpp b/bindings/BaseObject.cpp index 0af04d45..068d0f38 100644 --- a/bindings/BaseObject.cpp +++ b/bindings/BaseObject.cpp @@ -125,7 +125,7 @@ static void Destroy(const v8::FunctionCallbackInfo &info) alt::ICore::Instance().DestroyBaseObject(_this->GetHandle()); } -static V8Class v8baseObject("BaseObject", "", nullptr, [](v8::Local tpl) { +extern V8Class v8BaseObject("BaseObject", [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetAccessor(isolate, tpl, "type", &TypeGetter); diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index 89fb981a..0f08c6f6 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -3,7 +3,7 @@ #include "../V8ResourceImpl.h" #include "../V8Class.h" #include "../V8Entity.h" -#include "cpp-sdk/entities/IPlayer.h" +#include "cpp-sdk/objects/IPlayer.h" using namespace alt; @@ -345,7 +345,8 @@ static void StaticGetByID(const v8::FunctionCallbackInfo &info) V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id)); } -static V8Class v8entity("Entity", "WorldObject", nullptr, [](v8::Local tpl) { +extern V8Class v8WorldObject; +extern V8Class v8Entity("Entity", v8WorldObject, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); diff --git a/bindings/File.cpp b/bindings/File.cpp index 2a5e337d..5a56e3ac 100644 --- a/bindings/File.cpp +++ b/bindings/File.cpp @@ -79,7 +79,7 @@ static void StaticRead(const v8::FunctionCallbackInfo &info) } } -static V8Class v8File("File", "", nullptr, [](v8::Local tpl) { +extern V8Class v8File("File", [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetStaticMethod(isolate, tpl, "exists", StaticExists); diff --git a/bindings/RGBA.cpp b/bindings/RGBA.cpp index 083c6dbb..4b5cac14 100644 --- a/bindings/RGBA.cpp +++ b/bindings/RGBA.cpp @@ -19,8 +19,8 @@ static void ToString(const v8::FunctionCallbackInfo &info) info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, ss.str().c_str(), v8::NewStringType::kNormal).ToLocalChecked()); } -static V8Class v8RGBA( - "RGBA", "", [](const v8::FunctionCallbackInfo &info) { +extern V8Class v8RGBA( + "RGBA", [](const v8::FunctionCallbackInfo &info) { v8::Isolate* isolate = info.GetIsolate(); v8::Local ctx = isolate->GetEnteredContext(); @@ -39,4 +39,4 @@ static V8Class v8RGBA( V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_AKey(isolate), a, v8::PropertyAttribute::ReadOnly); }, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); - V8::SetMethod(isolate, tpl, "toString", ToString); }, false); + V8::SetMethod(isolate, tpl, "toString", ToString); }); diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index af673db1..5c333a1c 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -84,10 +84,9 @@ static void Constructor(const v8::FunctionCallbackInfo &info) V8::DefineOwnProperty(isolate, ctx, _this, V8::Vector3_ZKey(isolate), z, v8::PropertyAttribute::ReadOnly); } -static V8Class v8Vector3( - "Vector3", "", Constructor, [](v8::Local tpl) { +extern V8Class v8Vector3( + "Vector3", Constructor, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetMethod(isolate, tpl, "toString", ToString); - }, - false); + }); diff --git a/bindings/WorldObject.cpp b/bindings/WorldObject.cpp index 8674d2d7..09b7536c 100644 --- a/bindings/WorldObject.cpp +++ b/bindings/WorldObject.cpp @@ -78,7 +78,8 @@ static void DimensionSetter(v8::Local, v8::Local val, con } #endif // ALT_SERVER_API -static V8Class v8worldObject("WorldObject", "BaseObject", nullptr, [](v8::Local tpl) { +extern V8Class v8BaseObject; +extern V8Class v8WorldObject("WorldObject", v8BaseObject, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetAccessor(isolate, tpl, "pos", PositionGetter, PositionSetter); From 1713941b3fd576f7c79001a6282e666d9f7f27b3 Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 4 Nov 2020 04:53:58 +0100 Subject: [PATCH 027/564] Compressed pointers, adaptions for client --- .vscode/c_cpp_properties.json | 69 +-- .vscode/launch.json | 14 + .vscode/settings.json | 5 +- CMakeLists.txt | 46 +- deps/cpp-sdk | 2 +- src/CV8Resource.cpp | 5 +- src/CV8Resource.h | 5 +- src/CV8ScriptRuntime.cpp | 14 +- src/bindings/Blip.cpp | 774 +++++++++++++++++----------------- src/bindings/Discord.cpp | 2 +- src/bindings/Handling.cpp | 9 +- src/bindings/HandlingData.cpp | 11 +- src/bindings/LocalStorage.cpp | 7 +- src/bindings/Main.cpp | 185 ++++---- src/bindings/MapZoomData.cpp | 2 +- src/bindings/Player.cpp | 210 +++++---- src/bindings/V8Natives.cpp | 2 +- src/bindings/Vehicle.cpp | 10 +- src/bindings/Voice.cpp | 2 +- src/bindings/WebView.cpp | 19 +- src/helpers | 2 +- src/main.cpp | 21 + 22 files changed, 751 insertions(+), 665 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 46dbcb67..e135dc76 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,25 +1,46 @@ { - "configurations": [ - { - "name": "Win32", - "includePath": [ - "${workspaceFolder}/**", - "${workspaceFolder}/deps", - "${workspaceFolder}/deps/v8/include" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE", - "ALT_CLIENT_API", - "ALT_CLIENT" - ], - "windowsSdkVersion": "10.0.19041.0", - "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe", - "cStandard": "c11", - "cppStandard": "c++17", - "intelliSenseMode": "msvc-x64" - } - ], - "version": 4 -} \ No newline at end of file + "configurations": [ + { + "name": "Win32 Static", + "includePath": [ + "${workspaceFolder}/**", + "${workspaceFolder}/deps", + "${workspaceFolder}/deps/v8/include" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE", + "ALT_CLIENT_API", + "ALT_CLIENT" + ], + "windowsSdkVersion": "10.0.19041.0", + "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "msvc-x64" + }, + { + "name": "Win32 Shared", + "includePath": [ + "${workspaceFolder}/**", + "${workspaceFolder}/deps", + "${workspaceFolder}/deps/v8/include" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE", + "ALT_CLIENT_API", + "ALT_CLIENT", + "ALTV_JS_SHARED" + ], + "windowsSdkVersion": "10.0.19041.0", + "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "msvc-x64" + } + ], + "version": 4 +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..e1078fd0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Attach", + "type": "cppvsdbg", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 9e959e7c..2e8e1f56 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -62,6 +62,9 @@ "xstring": "cpp", "xtr1common": "cpp", "xtree": "cpp", - "xutility": "cpp" + "xutility": "cpp", + "deque": "cpp", + "queue": "cpp", + "sstream": "cpp" } } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f79a5fc..facb1d0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,15 @@ link_directories( ${ALTV_DEPS_DIR}/v8/lib/${CMAKE_BUILD_TYPE} ) -# Definitions +link_libraries( + # Platform binaries + Winmm.lib + DbgHelp.lib + + # V8 + v8_monolith.lib +) + add_definitions( # Compliation -DCXX_COMPILER_ID="${CMAKE_CXX_COMPILER_ID}" @@ -46,30 +54,36 @@ add_definitions( -DUNICODE -D_UNICODE + # alt:V -DALT_CLIENT -DALT_CLIENT_API -) -add_library( - ${PROJECT_NAME} SHARED - ${PROJECT_SOURCE_FILES} -) - -target_link_libraries(${PROJECT_NAME} - # Platform binaries - Winmm.lib - DbgHelp.lib - - # V8 - v8_monolith.lib + # v8 + -DV8_COMPRESS_POINTERS + -DV8_31BIT_SMIS_ON_64BIT_ARCH ) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /Zi /bigobj") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /bigobj") set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG:FULL /OPT:REF /OPT:ICF") +## SHARED +add_library( + ${PROJECT_NAME} SHARED + ${PROJECT_SOURCE_FILES} +) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 -# RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/BIN/Debug/client" -# RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/BIN/Release/client" +) +target_compile_definitions(${PROJECT_NAME} PRIVATE + -DALTV_JS_SHARED +) + +## STATIC +add_library( + ${PROJECT_NAME}-static STATIC + ${PROJECT_SOURCE_FILES} +) +set_target_properties(${PROJECT_NAME}-static PROPERTIES + CXX_STANDARD 17 ) \ No newline at end of file diff --git a/deps/cpp-sdk b/deps/cpp-sdk index 3c01a668..75b492f4 160000 --- a/deps/cpp-sdk +++ b/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 3c01a668938b23f5f32b0f6680f59225f0b62ee0 +Subproject commit 75b492f402b68b1417fc9534dd40a6b34705b76d diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 542c165f..6eb2659a 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -1,5 +1,5 @@ -#include "cpp-sdk/entities/IEntity.h" -#include "cpp-sdk/entities/IPlayer.h" +#include "cpp-sdk/objects/IEntity.h" +#include "cpp-sdk/objects/IPlayer.h" #include "cpp-sdk/events/CEvent.h" #include "cpp-sdk/events/CClientScriptEvent.h" @@ -22,6 +22,7 @@ #include "CV8ScriptRuntime.h" #include "CV8Resource.h" +#include "helpers/V8Helpers.h" #include "helpers/V8Module.h" static void StaticRequire(const v8::FunctionCallbackInfo &info) diff --git a/src/CV8Resource.h b/src/CV8Resource.h index 89817e60..33c217d2 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -1,7 +1,7 @@ #pragma once #include "cpp-sdk/IResource.h" -#include "cpp-sdk/entities/IEntity.h" +#include "cpp-sdk/objects/IEntity.h" #include "helpers/V8ResourceImpl.h" @@ -126,7 +126,8 @@ class CV8ResourceImpl : public V8ResourceImpl if (localStorage.IsEmpty()) { std::vector> args; - localStorage.Reset(isolate, V8Class::Get("LocalStorage")->New(GetContext(), args).As()); + extern V8Class v8LocalStorage; + localStorage.Reset(isolate, v8LocalStorage.New(GetContext(), args).As()); } return localStorage.Get(isolate); diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 7f424b6a..d83e12b9 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -1,14 +1,10 @@ -//#include "helpers/bindings/BaseObject.h" -//#include "helpers/bindings/WorldObject.h" -//#include "helpers/bindings/Entity.h" -//#include "bindings/Player.h" -//#include "bindings/Vehicle.h" -//#include "bindings/WebView.h" - #include "CV8ScriptRuntime.h" #include "inspector/CV8InspectorClient.h" #include "inspector/CV8InspectorChannel.h" +#include "helpers/V8Module.h" + +#include "Windows.h" CV8ScriptRuntime::CV8ScriptRuntime() { @@ -84,6 +80,10 @@ CV8ScriptRuntime::CV8ScriptRuntime() v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); + MessageBoxA(NULL, "", "", MB_OK); V8Class::LoadAll(isolate); + + extern V8Module altModule, nativesModule; + V8Module::Add({altModule, nativesModule}); } } diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index df3da283..dbd152b3 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -1,17 +1,17 @@ // #include "../CV8Resource.h" // #include "../helpers/V8Class.h" -// #include "script-objects/CBlip.h" +// #include "cpp-sdk/script-objects/IBlip.h" // static void Constructor(const v8::FunctionCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(info.IsConstructCall(), "Blip constructor is not a function"); +// V8_CHECK(info.IsConstructCall(), "Blip constructor is not a function"); -// // xyz as obj -// /* +// // xyz as obj +// /* // V8_CHECK(info.Length() == 2, "new Blip(...) expects 2 args"); // V8_CHECK(info[0]->IsObject(), "pos must be an object of {x, y, z}"); @@ -26,143 +26,143 @@ // V8_CHECK(info[1]->IsNumber(), "type must be an unsigned integer"); // */ -// /* +// /* // let blip = new alt.Blip(0, 0, 72, 11, 50, 50); // blip.rotation = 0; // */ -// // xyz as args +// // xyz as args -// V8_CHECK(false, "You can't use constructor of abstract class"); +// V8_CHECK(false, "You can't use constructor of abstract class"); // } // static void ConstructorAreaBlip(const v8::FunctionCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); -// V8_CHECK(info.IsConstructCall(), "AreaBlip constructor is not a function"); +// V8_CHECK(info.IsConstructCall(), "AreaBlip constructor is not a function"); -// V8_CHECK(info.Length() == 5, "new AreaBlip(...) expects 5 args"); -// V8_CHECK(info[0]->IsNumber(), "x must be a number"); -// V8_CHECK(info[1]->IsNumber(), "y must be a number"); -// V8_CHECK(info[2]->IsNumber(), "z must be a number"); -// V8_CHECK(info[3]->IsNumber(), "width must be a number"); -// V8_CHECK(info[4]->IsNumber(), "height must be a number"); +// V8_CHECK(info.Length() == 5, "new AreaBlip(...) expects 5 args"); +// V8_CHECK(info[0]->IsNumber(), "x must be a number"); +// V8_CHECK(info[1]->IsNumber(), "y must be a number"); +// V8_CHECK(info[2]->IsNumber(), "z must be a number"); +// V8_CHECK(info[3]->IsNumber(), "width must be a number"); +// V8_CHECK(info[4]->IsNumber(), "height must be a number"); -// v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); -// v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); -// v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); -// v8::Local width = info[3]->ToNumber(ctx).ToLocalChecked(); -// v8::Local height = info[4]->ToNumber(ctx).ToLocalChecked(); +// v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); +// v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); +// v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); +// v8::Local width = info[3]->ToNumber(ctx).ToLocalChecked(); +// v8::Local height = info[4]->ToNumber(ctx).ToLocalChecked(); -// alt::Ref blip = alt::CBlip::CreateBlipForArea({x->Value(), y->Value(), z->Value()}, width->Value(), height->Value()); +// alt::Ref blip = alt::IBlip::CreateBlipForArea({x->Value(), y->Value(), z->Value()}, width->Value(), height->Value()); -// V8_CHECK(blip, "Blip creation failed"); +// V8_CHECK(blip, "Blip creation failed"); -// static_cast(resource)->AddOwned(blip); -// resource->BindEntity(info.This(), blip.Get()); +// static_cast(resource)->AddOwned(blip); +// resource->BindEntity(info.This(), blip.Get()); // } // static void ConstructorRadiusBlip(const v8::FunctionCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); -// V8_CHECK(info.IsConstructCall(), "RadiusBlip constructor is not a function"); +// V8_CHECK(info.IsConstructCall(), "RadiusBlip constructor is not a function"); -// V8_CHECK(info.Length() == 4, "new RadiusBlip(...) expects 4 args"); -// V8_CHECK(info[0]->IsNumber(), "x must be a number"); -// V8_CHECK(info[1]->IsNumber(), "y must be a number"); -// V8_CHECK(info[2]->IsNumber(), "z must be a number"); -// V8_CHECK(info[3]->IsNumber(), "radius must be a number"); +// V8_CHECK(info.Length() == 4, "new RadiusBlip(...) expects 4 args"); +// V8_CHECK(info[0]->IsNumber(), "x must be a number"); +// V8_CHECK(info[1]->IsNumber(), "y must be a number"); +// V8_CHECK(info[2]->IsNumber(), "z must be a number"); +// V8_CHECK(info[3]->IsNumber(), "radius must be a number"); -// v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); -// v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); -// v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); -// v8::Local radius = info[3]->ToNumber(ctx).ToLocalChecked(); -// alt::Ref blip = alt::CBlip::CreateBlipForRadius({x->Value(), y->Value(), z->Value()}, radius->Value()); +// v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); +// v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); +// v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); +// v8::Local radius = info[3]->ToNumber(ctx).ToLocalChecked(); +// alt::Ref blip = alt::IBlip::CreateBlipForRadius({x->Value(), y->Value(), z->Value()}, radius->Value()); -// V8_CHECK(blip, "Blip creation failed"); +// V8_CHECK(blip, "Blip creation failed"); -// static_cast(resource)->AddOwned(blip); -// resource->BindEntity(info.This(), blip.Get()); +// static_cast(resource)->AddOwned(blip); +// resource->BindEntity(info.This(), blip.Get()); // } // static void ConstructorPointBlip(const v8::FunctionCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); -// V8_CHECK(info.IsConstructCall(), "PointBlip constructor is not a function"); +// V8_CHECK(info.IsConstructCall(), "PointBlip constructor is not a function"); -// V8_CHECK(info.Length() == 3, "new PointBlip(...) expects 3 args"); -// V8_CHECK(info[0]->IsNumber(), "x must be a number"); -// V8_CHECK(info[1]->IsNumber(), "y must be a number"); -// V8_CHECK(info[2]->IsNumber(), "z must be a number"); +// V8_CHECK(info.Length() == 3, "new PointBlip(...) expects 3 args"); +// V8_CHECK(info[0]->IsNumber(), "x must be a number"); +// V8_CHECK(info[1]->IsNumber(), "y must be a number"); +// V8_CHECK(info[2]->IsNumber(), "z must be a number"); -// v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); -// v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); -// v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); -// alt::Ref blip = alt::CBlip::Create(alt::IBlip::BlipType::DESTINATION, {x->Value(), y->Value(), z->Value()}); +// v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); +// v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); +// v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); +// alt::Ref blip = alt::IBlip::Create(alt::IBlip::BlipType::DESTINATION, {x->Value(), y->Value(), z->Value()}); -// V8_CHECK(blip, "Blip creation failed"); +// V8_CHECK(blip, "Blip creation failed"); -// static_cast(resource)->AddOwned(blip); -// resource->BindEntity(info.This(), blip.Get()); +// static_cast(resource)->AddOwned(blip); +// resource->BindEntity(info.This(), blip.Get()); // } // static void ConstructorPedBlip(const v8::FunctionCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); -// V8_CHECK(info.IsConstructCall(), "PedBlip constructor is not a function"); +// V8_CHECK(info.IsConstructCall(), "PedBlip constructor is not a function"); -// V8_CHECK(info.Length() == 1, "new PedBlip(...) expects 1 arg"); -// V8_CHECK(info[0]->IsNumber(), "pedId must be a number"); +// V8_CHECK(info.Length() == 1, "new PedBlip(...) expects 1 arg"); +// V8_CHECK(info[0]->IsNumber(), "pedId must be a number"); -// uint32_t pedId = info[0]->IntegerValue(ctx).ToChecked(); -// alt::Ref blip = alt::CBlip::CreateBlipForEntity(alt::IBlip::BlipType::PED, pedId); +// uint32_t pedId = info[0]->IntegerValue(ctx).ToChecked(); +// alt::Ref blip = alt::IBlip::CreateBlipForEntity(alt::IBlip::BlipType::PED, pedId); -// V8_CHECK(blip, "Blip creation failed"); +// V8_CHECK(blip, "Blip creation failed"); -// static_cast(resource)->AddOwned(blip); -// resource->BindEntity(info.This(), blip.Get()); +// static_cast(resource)->AddOwned(blip); +// resource->BindEntity(info.This(), blip.Get()); // } // static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); -// V8_CHECK(info.IsConstructCall(), "VehicleBlip constructor is not a function"); +// V8_CHECK(info.IsConstructCall(), "VehicleBlip constructor is not a function"); -// V8_CHECK(info.Length() == 1, "new VehicleBlip(...) expects 1 arg"); -// V8_CHECK(info[0]->IsNumber(), "vehicleId must be a number"); +// V8_CHECK(info.Length() == 1, "new VehicleBlip(...) expects 1 arg"); +// V8_CHECK(info[0]->IsNumber(), "vehicleId must be a number"); -// uint32_t vehicleId = info[0]->IntegerValue(ctx).ToChecked(); -// alt::Ref blip = alt::CBlip::CreateBlipForEntity(alt::IBlip::BlipType::VEHICLE, vehicleId); +// uint32_t vehicleId = info[0]->IntegerValue(ctx).ToChecked(); +// alt::Ref blip = alt::IBlip::CreateBlipForEntity(alt::IBlip::BlipType::VEHICLE, vehicleId); -// V8_CHECK(blip, "Blip creation failed"); +// V8_CHECK(blip, "Blip creation failed"); -// static_cast(resource)->AddOwned(blip); -// resource->BindEntity(info.This(), blip.Get()); +// static_cast(resource)->AddOwned(blip); +// resource->BindEntity(info.This(), blip.Get()); // } // //static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -170,25 +170,25 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetScale())); // //} // static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "scale must be a number"); -// double val = value->NumberValue(ctx).ToChecked(); +// V8_CHECK(value->IsNumber(), "scale must be a number"); +// double val = value->NumberValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); +// alt::Ref blip = _this->GetHandle().As(); -// blip->SetScale(val); +// blip->SetScale(val); // } // /** @@ -199,7 +199,7 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // auto scale = blip->GetScaleXY(); // // // // @@ -218,7 +218,7 @@ // // V8_CHECK(value->IsNumber(), "scale must be a number"); // // double val = value->NumberValue(ctx).ToChecked(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // blip->SetScale(val); // //} @@ -227,25 +227,25 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void SpriteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "sprite must be an integer"); -// int sprite = value->IntegerValue(ctx).ToChecked(); +// V8_CHECK(value->IsNumber(), "sprite must be an integer"); +// int sprite = value->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); +// alt::Ref blip = _this->GetHandle().As(); -// blip->SetSprite(sprite); +// blip->SetSprite(sprite); // } // //static void ColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -253,24 +253,24 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void ColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "color must be an integer"); -// int val = value->IntegerValue(ctx).ToChecked(); +// V8_CHECK(value->IsNumber(), "color must be an integer"); +// int val = value->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetColor(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetColor(val); // } // //static void SecondaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -278,24 +278,24 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void SecondaryColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "secondaryColor must be an unsigned integer"); -// int val = value->IntegerValue(ctx).ToChecked(); +// V8_CHECK(value->IsNumber(), "secondaryColor must be an unsigned integer"); +// int val = value->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetSecondaryColor(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetSecondaryColor(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -303,24 +303,24 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void AlphaSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "alpha must be an integer"); -// int val = value->IntegerValue(ctx).ToChecked(); +// V8_CHECK(value->IsNumber(), "alpha must be an integer"); +// int val = value->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetAlpha(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetAlpha(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -328,24 +328,24 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void FlashTimerSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "flashTimer must be an integer"); -// int val = value->IntegerValue(ctx).ToChecked(); +// V8_CHECK(value->IsNumber(), "flashTimer must be an integer"); +// int val = value->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetFlashTimer(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetFlashTimer(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -353,24 +353,24 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void FlashIntervalSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "flashInterval must be an integer"); -// int val = value->IntegerValue(ctx).ToChecked(); +// V8_CHECK(value->IsNumber(), "flashInterval must be an integer"); +// int val = value->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetFlashInterval(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetFlashInterval(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -378,23 +378,23 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void FriendlySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetAsFriendly(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetAsFriendly(val); // } // //static void RouteGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -402,23 +402,23 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void RouteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetRoute(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetRoute(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -426,23 +426,23 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void BrightSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetBright(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetBright(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -450,24 +450,24 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void NumberSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "number must be an integer"); -// auto val = value->IntegerValue(ctx).ToChecked(); +// V8_CHECK(value->IsNumber(), "number must be an integer"); +// auto val = value->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetNumber(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetNumber(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -475,23 +475,23 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void ShowConeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetShowCone(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetShowCone(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -499,23 +499,23 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void FlashesSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetFlashes(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetFlashes(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -523,23 +523,23 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void FlashesAlternateSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetFlashesAlternate(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetFlashesAlternate(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -547,23 +547,23 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void ShortRangeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetAsShortRange(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetAsShortRange(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -571,24 +571,24 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void PrioritySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "priority must be an integer"); -// auto val = value->IntegerValue(ctx).ToChecked(); +// V8_CHECK(value->IsNumber(), "priority must be an integer"); +// auto val = value->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetPriority(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetPriority(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -596,26 +596,26 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); // //} // static void RotationSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "rotation must be a number"); -// auto val = value->NumberValue(ctx).ToChecked(); +// V8_CHECK(value->IsNumber(), "rotation must be a number"); +// auto val = value->NumberValue(ctx).ToChecked(); -// Log::Debug << "nextRotation = " << val << Log::Endl; +// Log::Debug << "nextRotation = " << val << Log::Endl; -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetRotation(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetRotation(val); // } // //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -623,39 +623,39 @@ // // v8::Isolate* isolate = info.GetIsolate(); // // auto ctx = isolate->GetEnteredContext(); // // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // // // // info.GetReturnValue().Set(v8::Number::New(isolate, blip->())); // //} // static void GxtNameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsString(), "gxtName must be a string"); -// auto val = *v8::String::Utf8Value(info.GetIsolate(), value->ToString(ctx).ToLocalChecked()); +// V8_CHECK(value->IsString(), "gxtName must be a string"); +// auto val = *v8::String::Utf8Value(info.GetIsolate(), value->ToString(ctx).ToLocalChecked()); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetGxtName(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetGxtName(val); // } // static void NameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsString(), "name must be a string"); -// auto val = *v8::String::Utf8Value(info.GetIsolate(), value->ToString(ctx).ToLocalChecked()); +// V8_CHECK(value->IsString(), "name must be a string"); +// auto val = *v8::String::Utf8Value(info.GetIsolate(), value->ToString(ctx).ToLocalChecked()); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetName(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetName(val); // } // /* @@ -664,7 +664,7 @@ // v8::Isolate* isolate = info.GetIsolate(); // auto ctx = isolate->GetEnteredContext(); -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); // auto ret = v8::Number::New(isolate, blip->GETTER())); // info.GetReturnValue().Set(ret); @@ -673,185 +673,185 @@ // static void RouteColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "routeColor must be unsigned integer"); -// auto val = value->IntegerValue(ctx).ToChecked(); +// V8_CHECK(value->IsNumber(), "routeColor must be unsigned integer"); +// auto val = value->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetRouteColor(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetRouteColor(val); // } // static void PulseSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetPulse(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetPulse(val); // } // static void AsMissionCreatorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetAsMissionCreator(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetAsMissionCreator(val); // } // static void tickVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetTickVisible(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetTickVisible(val); // } // static void headingIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetHeadingIndicatorVisible(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetHeadingIndicatorVisible(val); // } // static void outlineIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetOutlineIndicatorVisible(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetOutlineIndicatorVisible(val); // } // static void friendIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetFriendIndicatorVisible(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetFriendIndicatorVisible(val); // } // static void crewIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetCrewIndicatorVisible(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetCrewIndicatorVisible(val); // } // static void categorySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "category must be integer"); -// auto val = value->IntegerValue(ctx).ToChecked(); +// V8_CHECK(value->IsNumber(), "category must be integer"); +// auto val = value->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetCategory(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetCategory(val); // } // static void highDetailSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetAsHighDetail(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetAsHighDetail(val); // } // static void shrinkedSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); +// auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetShrinked(val); +// alt::Ref blip = _this->GetHandle().As(); +// blip->SetShrinked(val); // } // static void Fade(const v8::FunctionCallbackInfo &info) // { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(info.Length() == 2, "2 args expected"); +// V8_CHECK(info.Length() == 2, "2 args expected"); -// V8_CHECK(info[0]->IsNumber(), "opacity must be an unsigned integer"); -// uint32_t opacity = info[0]->IntegerValue(ctx).ToChecked(); +// V8_CHECK(info[0]->IsNumber(), "opacity must be an unsigned integer"); +// uint32_t opacity = info[0]->IntegerValue(ctx).ToChecked(); -// V8_CHECK(info[1]->IsNumber(), "duration must be an unsigned integer"); -// uint32_t duration = info[1]->IntegerValue(ctx).ToChecked(); +// V8_CHECK(info[1]->IsNumber(), "duration must be an unsigned integer"); +// uint32_t duration = info[1]->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); +// alt::Ref blip = _this->GetHandle().As(); -// blip->Fade(opacity, duration); +// blip->Fade(opacity, duration); // } // static V8Class v8blip("Blip", "WorldObject", Constructor, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); -// /* +// /* // let ped = game.playerPedId(); // let coords = game.getEntityCoords(ped, true); @@ -860,65 +860,65 @@ // area.rotation = 0; // */ -// V8::SetAccessor(isolate, tpl, "sprite", nullptr, &SpriteSetter); -// V8::SetAccessor(isolate, tpl, "scale", nullptr, &ScaleSetter); -// V8::SetAccessor(isolate, tpl, "color", nullptr, &ColorSetter); -// V8::SetAccessor(isolate, tpl, "secondaryColor", nullptr, &SecondaryColorSetter); -// V8::SetAccessor(isolate, tpl, "alpha", nullptr, &AlphaSetter); -// V8::SetAccessor(isolate, tpl, "flashTimer", nullptr, &FlashTimerSetter); -// V8::SetAccessor(isolate, tpl, "flashInterval", nullptr, &FlashIntervalSetter); -// V8::SetAccessor(isolate, tpl, "route", nullptr, &RouteSetter); -// V8::SetAccessor(isolate, tpl, "bright", nullptr, &BrightSetter); -// V8::SetAccessor(isolate, tpl, "number", nullptr, &NumberSetter); -// V8::SetAccessor(isolate, tpl, "showCone", nullptr, &ShowConeSetter); -// V8::SetAccessor(isolate, tpl, "flashes", nullptr, &FlashesSetter); -// V8::SetAccessor(isolate, tpl, "flashesAlternate", nullptr, &FlashesAlternateSetter); -// V8::SetAccessor(isolate, tpl, "shortRange", nullptr, &ShortRangeSetter); -// V8::SetAccessor(isolate, tpl, "priority", nullptr, &PrioritySetter); -// V8::SetAccessor(isolate, tpl, "heading", nullptr, &RotationSetter); -// V8::SetAccessor(isolate, tpl, "gxtName", nullptr, &GxtNameSetter); -// V8::SetAccessor(isolate, tpl, "name", nullptr, &NameSetter); -// V8::SetAccessor(isolate, tpl, "routeColor", nullptr, &RouteColorSetter); -// V8::SetAccessor(isolate, tpl, "pulse", nullptr, &PulseSetter); -// V8::SetAccessor(isolate, tpl, "asMissionCreator", nullptr, &AsMissionCreatorSetter); -// V8::SetAccessor(isolate, tpl, "tickVisible", nullptr, &tickVisibleSetter); -// V8::SetAccessor(isolate, tpl, "headingIndicatorVisible", nullptr, &headingIndicatorVisibleSetter); -// V8::SetAccessor(isolate, tpl, "outlineIndicatorVisible", nullptr, &outlineIndicatorVisibleSetter); -// V8::SetAccessor(isolate, tpl, "friendIndicatorVisible", nullptr, &friendIndicatorVisibleSetter); -// V8::SetAccessor(isolate, tpl, "crewIndicatorVisible", nullptr, &crewIndicatorVisibleSetter); -// V8::SetAccessor(isolate, tpl, "category", nullptr, &categorySetter); -// V8::SetAccessor(isolate, tpl, "highDetail", nullptr, &highDetailSetter); -// V8::SetAccessor(isolate, tpl, "shrinked", nullptr, &shrinkedSetter); - -// V8::SetMethod(isolate, tpl, "fade", &Fade); +// V8::SetAccessor(isolate, tpl, "sprite", nullptr, &SpriteSetter); +// V8::SetAccessor(isolate, tpl, "scale", nullptr, &ScaleSetter); +// V8::SetAccessor(isolate, tpl, "color", nullptr, &ColorSetter); +// V8::SetAccessor(isolate, tpl, "secondaryColor", nullptr, &SecondaryColorSetter); +// V8::SetAccessor(isolate, tpl, "alpha", nullptr, &AlphaSetter); +// V8::SetAccessor(isolate, tpl, "flashTimer", nullptr, &FlashTimerSetter); +// V8::SetAccessor(isolate, tpl, "flashInterval", nullptr, &FlashIntervalSetter); +// V8::SetAccessor(isolate, tpl, "route", nullptr, &RouteSetter); +// V8::SetAccessor(isolate, tpl, "bright", nullptr, &BrightSetter); +// V8::SetAccessor(isolate, tpl, "number", nullptr, &NumberSetter); +// V8::SetAccessor(isolate, tpl, "showCone", nullptr, &ShowConeSetter); +// V8::SetAccessor(isolate, tpl, "flashes", nullptr, &FlashesSetter); +// V8::SetAccessor(isolate, tpl, "flashesAlternate", nullptr, &FlashesAlternateSetter); +// V8::SetAccessor(isolate, tpl, "shortRange", nullptr, &ShortRangeSetter); +// V8::SetAccessor(isolate, tpl, "priority", nullptr, &PrioritySetter); +// V8::SetAccessor(isolate, tpl, "heading", nullptr, &RotationSetter); +// V8::SetAccessor(isolate, tpl, "gxtName", nullptr, &GxtNameSetter); +// V8::SetAccessor(isolate, tpl, "name", nullptr, &NameSetter); +// V8::SetAccessor(isolate, tpl, "routeColor", nullptr, &RouteColorSetter); +// V8::SetAccessor(isolate, tpl, "pulse", nullptr, &PulseSetter); +// V8::SetAccessor(isolate, tpl, "asMissionCreator", nullptr, &AsMissionCreatorSetter); +// V8::SetAccessor(isolate, tpl, "tickVisible", nullptr, &tickVisibleSetter); +// V8::SetAccessor(isolate, tpl, "headingIndicatorVisible", nullptr, &headingIndicatorVisibleSetter); +// V8::SetAccessor(isolate, tpl, "outlineIndicatorVisible", nullptr, &outlineIndicatorVisibleSetter); +// V8::SetAccessor(isolate, tpl, "friendIndicatorVisible", nullptr, &friendIndicatorVisibleSetter); +// V8::SetAccessor(isolate, tpl, "crewIndicatorVisible", nullptr, &crewIndicatorVisibleSetter); +// V8::SetAccessor(isolate, tpl, "category", nullptr, &categorySetter); +// V8::SetAccessor(isolate, tpl, "highDetail", nullptr, &highDetailSetter); +// V8::SetAccessor(isolate, tpl, "shrinked", nullptr, &shrinkedSetter); + +// V8::SetMethod(isolate, tpl, "fade", &Fade); // }); // static V8Class v8AreaBlip("AreaBlip", "Blip", ConstructorAreaBlip, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); -// v8::Local proto = tpl->PrototypeTemplate(); +// v8::Local proto = tpl->PrototypeTemplate(); // }); // static V8Class v8RadiusBlip("RadiusBlip", "Blip", ConstructorRadiusBlip, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); -// v8::Local proto = tpl->PrototypeTemplate(); +// v8::Local proto = tpl->PrototypeTemplate(); // }); // static V8Class v8PointBlip("PointBlip", "Blip", ConstructorPointBlip, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); -// v8::Local proto = tpl->PrototypeTemplate(); +// v8::Local proto = tpl->PrototypeTemplate(); // }); // static V8Class v8PedBlip("PedBlip", "Blip", ConstructorPedBlip, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); -// v8::Local proto = tpl->PrototypeTemplate(); +// v8::Local proto = tpl->PrototypeTemplate(); // }); // static V8Class v8VehicleBlip("VehicleBlip", "Blip", ConstructorVehicleBlip, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); +// v8::Isolate *isolate = v8::Isolate::GetCurrent(); -// v8::Local proto = tpl->PrototypeTemplate(); +// v8::Local proto = tpl->PrototypeTemplate(); // }); diff --git a/src/bindings/Discord.cpp b/src/bindings/Discord.cpp index c5d07f9a..db159dff 100644 --- a/src/bindings/Discord.cpp +++ b/src/bindings/Discord.cpp @@ -47,7 +47,7 @@ static void CurrentUserGetter(v8::Local, const v8::PropertyCallbackI } } -static V8Class v8Discord("Discord", "", nullptr, [](v8::Local tpl) { +extern V8Class v8Discord("Discord", [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetStaticAccessor(isolate, tpl, "currentUser", &CurrentUserGetter); diff --git a/src/bindings/Handling.cpp b/src/bindings/Handling.cpp index 4c8d0883..2ba8f624 100644 --- a/src/bindings/Handling.cpp +++ b/src/bindings/Handling.cpp @@ -4,7 +4,7 @@ #include "../helpers/V8Class.h" #include "../helpers/V8Entity.h" #include "../helpers/V8ResourceImpl.h" -#include "cpp-sdk/entities/IVehicle.h" +#include "cpp-sdk/objects/IVehicle.h" static void Constructor(const v8::FunctionCallbackInfo &info) { @@ -1974,8 +1974,8 @@ static void DamageFlagsSetter(v8::Local, v8::Local val, c vehicle->GetHandling()->SetDamageFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); } -static V8Class v8HandlingData( - "Handling", "", Constructor, [](v8::Local tpl) { +extern V8Class v8Handling( + "Handling", Constructor, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local proto = tpl->PrototypeTemplate(); @@ -2051,5 +2051,4 @@ static V8Class v8HandlingData( proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modelFlags").ToLocalChecked(), &ModelFlagsGetter, &ModelFlagsSetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingFlags").ToLocalChecked(), &HandlingFlagsGetter, &HandlingFlagsSetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "damageFlags").ToLocalChecked(), &DamageFlagsGetter, &DamageFlagsSetter); - }, - false); \ No newline at end of file + }); \ No newline at end of file diff --git a/src/bindings/HandlingData.cpp b/src/bindings/HandlingData.cpp index 7a9150c8..34408e4f 100644 --- a/src/bindings/HandlingData.cpp +++ b/src/bindings/HandlingData.cpp @@ -27,12 +27,12 @@ static void GetForHandlingName(const v8::FunctionCallbackInfo &info) V8_CHECK(info[0]->IsNumber(), "modelHash must be a number"); uint32_t modelHash = info[0]->Uint32Value(isolate->GetEnteredContext()).ToChecked(); - static V8Class *handlingDataClass = V8Class::Get("HandlingData"); + extern V8Class v8HandlingData; std::vector> args{ v8::Number::New(isolate, modelHash)}; - info.GetReturnValue().Set(handlingDataClass->New(isolate->GetEnteredContext(), args)); + info.GetReturnValue().Set(v8HandlingData.New(isolate->GetEnteredContext(), args)); } static void HandlingNameHashGetter(v8::Local, const v8::PropertyCallbackInfo &info) @@ -1694,8 +1694,8 @@ static void DamageFlagsSetter(v8::Local, v8::Local val, c handling->SetDamageFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); } -static V8Class v8HandlingData( - "HandlingData", "", Constructor, [](v8::Local tpl) { +extern V8Class v8HandlingData( + "HandlingData", Constructor, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local proto = tpl->PrototypeTemplate(); @@ -1770,5 +1770,4 @@ static V8Class v8HandlingData( proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modelFlags").ToLocalChecked(), &ModelFlagsGetter, &ModelFlagsSetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingFlags").ToLocalChecked(), &HandlingFlagsGetter, &HandlingFlagsSetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "damageFlags").ToLocalChecked(), &DamageFlagsGetter, &DamageFlagsSetter); - }, - false); + }); diff --git a/src/bindings/LocalStorage.cpp b/src/bindings/LocalStorage.cpp index 6a9f9cb1..8710558f 100644 --- a/src/bindings/LocalStorage.cpp +++ b/src/bindings/LocalStorage.cpp @@ -79,8 +79,8 @@ static void Save(const v8::FunctionCallbackInfo &info) V8_CHECK(resource->GetLocalStorage()->Save(), "exceeded max local storage size (4MB)"); } -static V8Class v8LocalStorage( - "LocalStorage", "", nullptr, [](v8::Local tpl) { +extern V8Class v8LocalStorage( + "LocalStorage", nullptr, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); tpl->Set(isolate, "get", v8::FunctionTemplate::New(isolate, &StaticGet)); @@ -92,5 +92,4 @@ static V8Class v8LocalStorage( proto->Set(isolate, "delete", v8::FunctionTemplate::New(isolate, &Delete)); proto->Set(isolate, "deleteAll", v8::FunctionTemplate::New(isolate, &DeleteAll)); proto->Set(isolate, "save", v8::FunctionTemplate::New(isolate, &Save)); - }, - false); + }); diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 4de1bd50..c0e0bdb5 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -1,6 +1,6 @@ #include "../CV8ScriptRuntime.h" -#include "cpp-sdk/entities/IPlayer.h" +#include "cpp-sdk/objects/IPlayer.h" #include "../helpers/V8Module.h" #include "cpp-sdk/SDK.h" @@ -806,98 +806,117 @@ static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &in info.GetReturnValue().Set(persistent.Get(isolate)->GetPromise()); } -static V8Module altModule("alt", - { - "Vector3", - "RGBA", - "BaseObject", - "WorldObject", - "Entity", - "Player", - "Vehicle", - "WebView", - "Blip", - "AreaBlip", - "RadiusBlip", - "PointBlip", - "HandlingData", - "LocalStorage", - "MemoryBuffer", - "File", - "MapZoomData", - "Discord", - "Voice" - /*"PedBlip", - "VehicleBlip"*/ - }, - [](v8::Local ctx, v8::Local exports) { - V8::RegisterSharedMain(ctx, exports); - - V8Helpers::RegisterFunc(exports, "onServer", &OnServer); - V8Helpers::RegisterFunc(exports, "offServer", &OffServer); - V8Helpers::RegisterFunc(exports, "emitServer", &EmitServer); - V8Helpers::RegisterFunc(exports, "gameControlsEnabled", &GameControlsEnabled); - V8Helpers::RegisterFunc(exports, "toggleGameControls", &ToggleGameControls); - V8Helpers::RegisterFunc(exports, "toggleVoiceControls", &ToggleVoiceControls); - V8Helpers::RegisterFunc(exports, "showCursor", &ShowCursor); - V8Helpers::RegisterFunc(exports, "isMenuOpen", &IsMenuOpen); - V8Helpers::RegisterFunc(exports, "isConsoleOpen", &IsConsoleOpen); - //V8Helpers::RegisterFunc(exports, "drawRect2D", &DrawRect2D); - - V8Helpers::RegisterFunc(exports, "requestIpl", &RequestIPL); - V8Helpers::RegisterFunc(exports, "removeIpl", &RemoveIPL); - //V8Helpers::RegisterFunc(exports, "wait", &ScriptWait); - //V8Helpers::RegisterFunc(exports, "isInSandbox", &IsInSandbox); - V8Helpers::RegisterFunc(exports, "isInDebug", &IsInDebug); - V8Helpers::RegisterFunc(exports, "setCamFrozen", &SetCamFrozen); - - V8Helpers::RegisterFunc(exports, "getLicenseHash", &GetLicenseHash); - - //Gxt texts functions - V8Helpers::RegisterFunc(exports, "addGxtText", &AddGxtText); - V8Helpers::RegisterFunc(exports, "removeGxtText", &RemoveGxtText); - V8Helpers::RegisterFunc(exports, "getGxtText", &GetGxtText); - - //Voice functions - V8Helpers::RegisterFunc(exports, "isVoiceActivityInputEnabled", &IsVoiceActivityInputEnabled); - - //Time managements functions - V8Helpers::RegisterFunc(exports, "setMsPerGameMinute", &SetMsPerGameMinute); - V8Helpers::RegisterFunc(exports, "getMsPerGameMinute", &GetMsPerGameMinute); - - //CEF rendering on texture - V8Helpers::RegisterFunc(exports, "isTextureExistInArchetype", &IsTextureExistInArchetype); - - //Scaleform additionals - V8Helpers::RegisterFunc(exports, "beginScaleformMovieMethodMinimap", &BeginScaleformMovieMethodMinimap); +extern V8Class v8Vector3, + v8RGBA, + v8BaseObject, + v8WorldObject, + v8Entity, + v8Player, + v8Player, + v8Vehicle, + v8WebView, + v8Blip, + v8AreaBlip, + v8RadiusBlip, + v8PointBlip, + v8HandlingData, + v8LocalStorage, + v8MemoryBuffer, + v8File, + v8MapZoomData, + v8Discord, + v8Voice, + v8PedBlip, + v8VehicleBlip; +extern V8Module altModule( + "alt", + {v8Vector3, + v8RGBA, + v8BaseObject, + v8WorldObject, + v8Entity, + v8Player, + v8Vehicle, + v8WebView, + // v8Blip, + // v8AreaBlip, + // v8RadiusBlip, + // v8PointBlip, + v8HandlingData, + v8LocalStorage, + // v8MemoryBuffer, + v8File, + // v8MapZoomData, + v8Discord, + v8Voice}, + [](v8::Local ctx, v8::Local exports) { + V8::RegisterSharedMain(ctx, exports); + + V8Helpers::RegisterFunc(exports, "onServer", &OnServer); + V8Helpers::RegisterFunc(exports, "offServer", &OffServer); + V8Helpers::RegisterFunc(exports, "emitServer", &EmitServer); + V8Helpers::RegisterFunc(exports, "gameControlsEnabled", &GameControlsEnabled); + V8Helpers::RegisterFunc(exports, "toggleGameControls", &ToggleGameControls); + V8Helpers::RegisterFunc(exports, "toggleVoiceControls", &ToggleVoiceControls); + V8Helpers::RegisterFunc(exports, "showCursor", &ShowCursor); + V8Helpers::RegisterFunc(exports, "isMenuOpen", &IsMenuOpen); + V8Helpers::RegisterFunc(exports, "isConsoleOpen", &IsConsoleOpen); + //V8Helpers::RegisterFunc(exports, "drawRect2D", &DrawRect2D); + + V8Helpers::RegisterFunc(exports, "requestIpl", &RequestIPL); + V8Helpers::RegisterFunc(exports, "removeIpl", &RemoveIPL); + //V8Helpers::RegisterFunc(exports, "wait", &ScriptWait); + //V8Helpers::RegisterFunc(exports, "isInSandbox", &IsInSandbox); + V8Helpers::RegisterFunc(exports, "isInDebug", &IsInDebug); + V8Helpers::RegisterFunc(exports, "setCamFrozen", &SetCamFrozen); + + V8Helpers::RegisterFunc(exports, "getLicenseHash", &GetLicenseHash); + + //Gxt texts functions + V8Helpers::RegisterFunc(exports, "addGxtText", &AddGxtText); + V8Helpers::RegisterFunc(exports, "removeGxtText", &RemoveGxtText); + V8Helpers::RegisterFunc(exports, "getGxtText", &GetGxtText); + + //Voice functions + V8Helpers::RegisterFunc(exports, "isVoiceActivityInputEnabled", &IsVoiceActivityInputEnabled); + + //Time managements functions + V8Helpers::RegisterFunc(exports, "setMsPerGameMinute", &SetMsPerGameMinute); + V8Helpers::RegisterFunc(exports, "getMsPerGameMinute", &GetMsPerGameMinute); + + //CEF rendering on texture + V8Helpers::RegisterFunc(exports, "isTextureExistInArchetype", &IsTextureExistInArchetype); + + //Scaleform additionals + V8Helpers::RegisterFunc(exports, "beginScaleformMovieMethodMinimap", &BeginScaleformMovieMethodMinimap); #ifndef NDEBUG // V8Helpers::RegisterFunc(exports, "getVehWheels", &GetVehWheels); #endif - V8Helpers::RegisterFunc(exports, "getLocale", &GetLocale); + V8Helpers::RegisterFunc(exports, "getLocale", &GetLocale); - V8Helpers::RegisterFunc(exports, "setWeatherCycle", &SetWeatherCycle); - V8Helpers::RegisterFunc(exports, "setWeatherSyncActive", &SetWeatherSyncActive); + V8Helpers::RegisterFunc(exports, "setWeatherCycle", &SetWeatherCycle); + V8Helpers::RegisterFunc(exports, "setWeatherSyncActive", &SetWeatherSyncActive); - V8Helpers::RegisterFunc(exports, "setStat", &SetCharStat); - V8Helpers::RegisterFunc(exports, "getStat", &GetCharStat); - V8Helpers::RegisterFunc(exports, "resetStat", &ResetCharStat); + V8Helpers::RegisterFunc(exports, "setStat", &SetCharStat); + V8Helpers::RegisterFunc(exports, "getStat", &GetCharStat); + V8Helpers::RegisterFunc(exports, "resetStat", &ResetCharStat); - V8Helpers::RegisterFunc(exports, "isKeyDown", &IsKeyDown); - V8Helpers::RegisterFunc(exports, "isKeyToggled", &IsKeyToggled); + V8Helpers::RegisterFunc(exports, "isKeyDown", &IsKeyDown); + V8Helpers::RegisterFunc(exports, "isKeyToggled", &IsKeyToggled); - V8Helpers::RegisterFunc(exports, "setConfigFlag", &SetConfigFlag); - V8Helpers::RegisterFunc(exports, "getConfigFlag", &GetConfigFlag); - V8Helpers::RegisterFunc(exports, "doesConfigFlagExist", &DoesConfigFlagExist); + V8Helpers::RegisterFunc(exports, "setConfigFlag", &SetConfigFlag); + V8Helpers::RegisterFunc(exports, "getConfigFlag", &GetConfigFlag); + V8Helpers::RegisterFunc(exports, "doesConfigFlagExist", &DoesConfigFlagExist); - // V8Helpers::RegisterFunc(exports, "getEntityMemoryByID", &GetEntityMemoryByID); + // V8Helpers::RegisterFunc(exports, "getEntityMemoryByID", &GetEntityMemoryByID); - // V8Helpers::RegisterFunc(exports, "setRotationVelocity", &SetAngularVelocity); - // V8Helpers::RegisterFunc(exports, "setAngularVelocity", &SetAngularVelocity); + // V8Helpers::RegisterFunc(exports, "setRotationVelocity", &SetAngularVelocity); + // V8Helpers::RegisterFunc(exports, "setAngularVelocity", &SetAngularVelocity); - V8Helpers::RegisterFunc(exports, "isInStreamerMode", &IsInStreamerMode); + V8Helpers::RegisterFunc(exports, "isInStreamerMode", &IsInStreamerMode); - V8Helpers::RegisterFunc(exports, "takeScreenshot", &TakeScreenshot); - V8Helpers::RegisterFunc(exports, "takeScreenshotGameOnly", &TakeScreenshotGameOnly); - }); + V8Helpers::RegisterFunc(exports, "takeScreenshot", &TakeScreenshot); + V8Helpers::RegisterFunc(exports, "takeScreenshotGameOnly", &TakeScreenshotGameOnly); + }); diff --git a/src/bindings/MapZoomData.cpp b/src/bindings/MapZoomData.cpp index 87801ba4..1d246349 100644 --- a/src/bindings/MapZoomData.cpp +++ b/src/bindings/MapZoomData.cpp @@ -35,7 +35,7 @@ // V8_CHECK(info.Length() == 1, "MapZoomData.get expects 1 arg"); // V8_CHECK(info[0]->IsNumber() || info[0]->IsString(), "zoomDataId must be a number or string"); -// static V8Class *mapZoomDataClass = V8Class::Get("MapZoomData"); +// static V8Class *mapZoomDataClass = &v8MapZoomData; // std::vector> args{ // info[0]}; diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index da68b5de..9180a10c 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -4,8 +4,8 @@ #include "../helpers/V8Entity.h" #include "../helpers/V8ResourceImpl.h" -#include "cpp-sdk/entities/IPlayer.h" -#include "cpp-sdk/entities/IVehicle.h" +#include "cpp-sdk/objects/IPlayer.h" +#include "cpp-sdk/objects/IVehicle.h" static void NameGetter(v8::Local, const v8::PropertyCallbackInfo &info) { @@ -71,106 +71,106 @@ static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo info.GetReturnValue().Set(v8::Number::New(isolate, player->GetMicLevel())); } -static void GiveWeapon(const v8::FunctionCallbackInfo &info) -{ - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); +// static void GiveWeapon(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); - alt::Ref player = _this->GetHandle().As(); +// alt::Ref player = _this->GetHandle().As(); - V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); - uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - V8_CHECK(info[1]->IsNumber(), "ammoCount must be a number"); - uint32_t ammoCount = info[1]->NumberValue(ctx).ToChecked(); +// V8_CHECK(info[1]->IsNumber(), "ammoCount must be a number"); +// uint32_t ammoCount = info[1]->NumberValue(ctx).ToChecked(); - player->GiveWeapon(weaponHash, ammoCount, false); // todo: allow setter for selected -} +// player->GiveWeapon(weaponHash, ammoCount, false); // todo: allow setter for selected +// } -static void RemoveWeapon(const v8::FunctionCallbackInfo &info) -{ - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); +// static void RemoveWeapon(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); - alt::Ref player = _this->GetHandle().As(); +// alt::Ref player = _this->GetHandle().As(); - V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); - uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), player->RemoveWeapon(weaponHash))); -} +// info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), player->RemoveWeapon(weaponHash))); +// } -static void RemoveAllWeapons(const v8::FunctionCallbackInfo &info) -{ - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); +// static void RemoveAllWeapons(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); - alt::Ref player = _this->GetHandle().As(); +// alt::Ref player = _this->GetHandle().As(); - player->RemoveAllWeapons(); -} +// player->RemoveAllWeapons(); +// } -static void AddWeaponComponent(const v8::FunctionCallbackInfo &info) -{ - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); +// static void AddWeaponComponent(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); - alt::Ref player = _this->GetHandle().As(); +// alt::Ref player = _this->GetHandle().As(); - V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); - uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); - uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); +// V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); +// uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); - player->AddWeaponComponent(weaponHash, componentHash); -} +// player->AddWeaponComponent(weaponHash, componentHash); +// } -static void RemoveWeaponComponent(const v8::FunctionCallbackInfo &info) -{ - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); +// static void RemoveWeaponComponent(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); - alt::Ref player = _this->GetHandle().As(); +// alt::Ref player = _this->GetHandle().As(); - V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); - uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); - uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); +// V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); +// uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); - player->RemoveWeaponComponent(weaponHash, componentHash); -} +// player->RemoveWeaponComponent(weaponHash, componentHash); +// } static void WeaponHasComponent(const v8::FunctionCallbackInfo &info) { @@ -194,27 +194,27 @@ static void WeaponHasComponent(const v8::FunctionCallbackInfo &info) info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), player->HasWeaponComponent(weaponHash, componentHash))); } -static void SetWeaponTintIndex(const v8::FunctionCallbackInfo &info) -{ - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); +// static void SetWeaponTintIndex(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); - alt::Ref player = _this->GetHandle().As(); +// alt::Ref player = _this->GetHandle().As(); - V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); - uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - V8_CHECK(info[1]->IsNumber(), "tintIndex must be a number"); - uint8_t tintIndex = info[1]->NumberValue(ctx).ToChecked(); +// V8_CHECK(info[1]->IsNumber(), "tintIndex must be a number"); +// uint8_t tintIndex = info[1]->NumberValue(ctx).ToChecked(); - player->SetWeaponTintIndex(weaponHash, tintIndex); -} +// player->SetWeaponTintIndex(weaponHash, tintIndex); +// } static void GetWeaponTintIndex(const v8::FunctionCallbackInfo &info) { @@ -235,24 +235,24 @@ static void GetWeaponTintIndex(const v8::FunctionCallbackInfo &info) info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), player->GetWeaponTintIndex(weaponHash))); } -static void SetCurrentWeapon(const v8::FunctionCallbackInfo &info) -{ - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); +// static void SetCurrentWeapon(const v8::FunctionCallbackInfo &info) +// { +// v8::Isolate *isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); - alt::Ref player = _this->GetHandle().As(); +// alt::Ref player = _this->GetHandle().As(); - V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); - uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); +// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); +// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - player->SetCurrentWeapon(weaponHash); -} +// player->SetCurrentWeapon(weaponHash); +// } static void GetCurrentWeapon(const v8::FunctionCallbackInfo &info) { @@ -320,7 +320,8 @@ static void StaticGetByID(const v8::FunctionCallbackInfo &info) V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id).As()); } -static V8Class v8player("Player", "Entity", nullptr, [](v8::Local tpl) { +extern V8Class v8Entity; +extern V8Class v8Player("Player", v8Entity, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local proto = tpl->PrototypeTemplate(); @@ -338,17 +339,8 @@ static V8Class v8player("Player", "Entity", nullptr, [](v8::LocalSet(isolate, "giveWeapon", v8::FunctionTemplate::New(isolate, &GiveWeapon)); - proto->Set(isolate, "removeWeapon", v8::FunctionTemplate::New(isolate, &RemoveWeapon)); - proto->Set(isolate, "removeAllWeapons", v8::FunctionTemplate::New(isolate, &RemoveAllWeapons)); - proto->Set(isolate, "addWeaponComponent", v8::FunctionTemplate::New(isolate, &AddWeaponComponent)); - proto->Set(isolate, "removeWeaponComponent", v8::FunctionTemplate::New(isolate, &RemoveWeaponComponent)); proto->Set(isolate, "weaponHasComponent", v8::FunctionTemplate::New(isolate, &WeaponHasComponent)); - - proto->Set(isolate, "setWeaponTintIndex", v8::FunctionTemplate::New(isolate, &SetWeaponTintIndex)); proto->Set(isolate, "getWeaponTintIndex", v8::FunctionTemplate::New(isolate, &GetWeaponTintIndex)); - - proto->Set(isolate, "setCurrentWeapon", v8::FunctionTemplate::New(isolate, &SetCurrentWeapon)); proto->Set(isolate, "getCurrentWeapon", v8::FunctionTemplate::New(isolate, &GetCurrentWeapon)); } }); diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index aa12c592..02e5cc1c 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -251,4 +251,4 @@ static void RegisterNatives(v8::Local ctx, v8::Local ex } } -static V8Module nativesModule("natives", {}, RegisterNatives); +extern V8Module nativesModule("natives", {}, RegisterNatives); diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index e36fb7fa..b6e84f8a 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -3,7 +3,7 @@ #include "../helpers/V8Class.h" #include "../helpers/V8Entity.h" #include "../helpers/V8ResourceImpl.h" -#include "cpp-sdk/entities/IVehicle.h" +#include "cpp-sdk/objects/IVehicle.h" using namespace alt; @@ -14,12 +14,11 @@ static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); - static V8Class *handlingClass = V8Class::Get("Handling"); - std::vector> args{ info.This()}; - info.GetReturnValue().Set(handlingClass->New(isolate->GetEnteredContext(), args)); + extern V8Class v8Handling; + info.GetReturnValue().Set(v8Handling.New(isolate->GetEnteredContext(), args)); } static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) @@ -162,7 +161,8 @@ static void StaticGetByID(const v8::FunctionCallbackInfo &info) V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id).As()); } -static V8Class v8vehicle("Vehicle", "Entity", nullptr, [](v8::Local tpl) { +extern V8Class v8Entity; +extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local proto = tpl->PrototypeTemplate(); diff --git a/src/bindings/Voice.cpp b/src/bindings/Voice.cpp index 2464817b..82c4fd28 100644 --- a/src/bindings/Voice.cpp +++ b/src/bindings/Voice.cpp @@ -17,7 +17,7 @@ static void StaticSetInputMuted(v8::Local name, v8::Local alt::ICore::Instance().SetVoiceInputMuted(state); } -static V8Class v8Voice("Voice", "", nullptr, [](v8::Local tpl) { +extern V8Class v8Voice("Voice", [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetStaticAccessor(isolate, tpl, "muteInput", StaticGetInputMuted, StaticSetInputMuted); diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index d7b280aa..707b0c62 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -163,8 +163,10 @@ static void URLSetter(v8::Local property, v8::Local value view->SetUrl(*url); } -static V8Class v8webview( - "WebView", "BaseObject", [](const v8::FunctionCallbackInfo &info) { +extern V8Class v8BaseObject; +extern V8Class v8WebView( + "WebView", v8BaseObject, + [](const v8::FunctionCallbackInfo &info) { v8::Isolate *isolate = info.GetIsolate(); v8::Local ctx = isolate->GetCurrentContext(); @@ -172,7 +174,7 @@ static V8Class v8webview( V8_CHECK(info.Length() > 0 && info.Length() <= 3, "new WebView(...) expects 1, 2 or 3 args"); V8_CHECK(info[0]->IsString(), "url must be a string"); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); V8_CHECK(resource, "invalid resource"); v8::Local url = info[0].As(); @@ -190,7 +192,7 @@ static V8Class v8webview( auto texture = alt::ICore::Instance().GetTextureFromDrawable(drawableHash, targetTextureStr); V8_CHECK(texture != nullptr, "Texture not found"); - view = alt::ICore::Instance().CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), (uint32_t)drawableHash, targetTextureStr); + view = resource->CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), (uint32_t)drawableHash, targetTextureStr); V8_CHECK(!view.IsEmpty(), "Interactive WebView cannot be created"); } else if (info.Length() == 2) @@ -198,15 +200,16 @@ static V8Class v8webview( v8::Local isOverlay = info[1]->ToBoolean(isolate); bool isOverlayBool = isOverlay->Value(); - view = alt::ICore::Instance().CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), {0, 0}, {0, 0}, true, isOverlayBool); + view = resource->CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), {0, 0}, {0, 0}, true, isOverlayBool); } else { - view = alt::ICore::Instance().CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), {0, 0}, {0, 0}, true, false); + view = resource->CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), {0, 0}, {0, 0}, true, false); } - static_cast(resource)->AddOwned(view); - resource->BindEntity(info.This(), view.Get()); }, + // static_cast(resource)->AddOwned(view); + // resource->BindEntity(info.This(), view.Get()); + }, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); diff --git a/src/helpers b/src/helpers index 16c33b01..7549089c 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 16c33b01b86f76a774763cd4496966f8626b7498 +Subproject commit 7549089c0d0d82338fbc620ff36ff0af38d2adde diff --git a/src/main.cpp b/src/main.cpp index e69de29b..109a66d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -0,0 +1,21 @@ +#include "cpp-sdk/SDK.h" +#include "CV8ScriptRuntime.h" +#include "helpers/Log.h" + +#ifdef ALTV_JS_SHARED +#define ALTV_JS_EXPORT extern "C" __declspec(dllexport) +#else +#define ALTV_JS_EXPORT extern "C" +#endif + +void StaticInitialization() +{ + extern V8Class v8Vector3; +} + +ALTV_JS_EXPORT alt::IScriptRuntime *CreateJSScriptRuntime(alt::ICore *core) +{ + alt::ICore::SetInstance(core); + auto ret = new CV8ScriptRuntime(); + return ret; +} From 4d64883c72f1fe81617fc83e1a821a788dc666a0 Mon Sep 17 00:00:00 2001 From: Mark Cavalli Date: Wed, 4 Nov 2020 21:13:48 +0300 Subject: [PATCH 028/564] new Vector3 functions --- V8Helpers.cpp | 11 ++ V8Helpers.h | 7 + bindings/Vector3.cpp | 462 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 479 insertions(+), 1 deletion(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 98114051..7aab50f5 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -521,6 +521,17 @@ bool V8::SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local< return false; } +bool V8::SafeToObject(v8::Local val, v8::Local& out) +{ + if (val->IsObject()) + { + out = val.As(); + return true; + } + + return false; +} + std::vector V8::EventHandler::GetCallbacks(V8ResourceImpl* impl, const alt::CEvent* e) { return callbacksGetter(impl, e); diff --git a/V8Helpers.h b/V8Helpers.h index c220628d..c02fe2e0 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -206,6 +206,7 @@ namespace V8 bool SafeToInteger(v8::Local val, v8::Local ctx, int64_t& out); bool SafeToNumber(v8::Local val, v8::Local ctx, double& out); bool SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String& out); + bool SafeToObject(v8::Local val, v8::Local& out); template bool SafeToBaseObject(v8::Local val, v8::Isolate* isolate, alt::Ref& out) @@ -297,6 +298,11 @@ namespace V8 alt::String val; \ V8_CHECK(V8::SafeToString(info[(idx) - 1], isolate, ctx, val), "Failed to convert argument " #idx " to string") +// idx starts with 1 +#define V8_ARG_TO_OBJECT(idx, val) \ + v8::Local val; \ + V8_CHECK(V8::SafeToObject(info[(idx) - 1], val), "Failed to convert argument " #idx " to object") + // idx starts with 1 #define V8_ARG_TO_BASE_OBJECT(idx, val, type, jsClassName) \ alt::Ref val; \ @@ -306,6 +312,7 @@ namespace V8 #define V8_RETURN_NULL() V8_RETURN(v8::Null(isolate)) #define V8_RETURN_BOOLEAN(val) V8_RETURN(v8::Boolean::New(isolate, (val))) #define V8_RETURN_INTEGER(val) V8_RETURN(v8::Integer::New(isolate, (val))) +#define V8_RETURN_NUMBER(val) V8_RETURN(v8::Number::New(isolate, (val))) #define V8_RETURN_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val), v8::NewStringType::kNormal).ToLocalChecked()) #define V8_RETURN_BASE_OBJECT(baseObjectRef) V8_RETURN(resource->GetBaseObjectOrNull(baseObjectRef)) diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index 045f6fe2..ec239fe2 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -6,6 +6,8 @@ #include "../V8Helpers.h" #include "../V8ResourceImpl.h" +constexpr double PI = 3.141592653589793238463; + static void ToString(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -23,6 +25,450 @@ static void ToString(const v8::FunctionCallbackInfo& info) V8_RETURN_STRING(ss.str().c_str()); } +static void ToArray(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + v8::Local arr = v8::Array::New(isolate, 3); + arr->Set(ctx, 0, v8::Number::New(isolate, x)); + arr->Set(ctx, 1, v8::Number::New(isolate, y)); + arr->Set(ctx, 2, v8::Number::New(isolate, z)); + + V8_RETURN(arr); +} + + +static void Length(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + double length = sqrt(x * x + y * y + z * z); + + V8_RETURN_NUMBER(length); +} + + +static void Add(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN2(1, 3); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + if (info.Length() == 3) + { + V8_ARG_TO_NUMBER(1, x2); + V8_ARG_TO_NUMBER(2, y2); + V8_ARG_TO_NUMBER(3, z2); + + V8_RETURN(resource->CreateVector3({ x + x2, y + y2, z + z2 })); + } + else if (info.Length() == 1) + { + auto arg = info[0]; + if (arg->IsNumber()) + { + V8_ARG_TO_NUMBER(1, value); + V8_RETURN(resource->CreateVector3({ x + value, y + value, z + value })); + } + else if (arg->IsArray()) + { + v8::Local arr = arg.As(); + V8_CHECK(arr->Length() == 3, "Argument must be an array of 3 numbers"); + + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), y2); + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), z2); + V8_RETURN(resource->CreateVector3({ x + x2, y + y2, z + z2 })); + } + else if (arg->IsObject()) + { + v8::Local obj = arg.As(); + + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(), z2); + + V8_RETURN(resource->CreateVector3({ x + x2, y + y2, z + z2 })); + } + else + { + V8Helpers::Throw(isolate, "Argument must be a number, an array of 3 numbers or IVector3"); + } + } +} + +static void Sub(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN2(1, 3); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + if (info.Length() == 3) + { + V8_ARG_TO_NUMBER(1, x2); + V8_ARG_TO_NUMBER(2, y2); + V8_ARG_TO_NUMBER(3, z2); + + V8_RETURN(resource->CreateVector3({ x - x2, y - y2, z - z2 })); + } + else if (info.Length() == 1) + { + auto arg = info[0]; + if (arg->IsNumber()) + { + V8_ARG_TO_NUMBER(1, value); + V8_RETURN(resource->CreateVector3({ x - value, y - value, z - value })); + } + else if (arg->IsArray()) + { + v8::Local arr = arg.As(); + V8_CHECK(arr->Length() == 3, "Argument must be an array of 3 numbers"); + + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), y2); + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), z2); + V8_RETURN(resource->CreateVector3({ x - x2, y - y2, z - z2 })); + } + else if (arg->IsObject()) + { + v8::Local obj = arg.As(); + + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(), z2); + + V8_RETURN(resource->CreateVector3({ x - x2, y - y2, z - z2 })); + } + else + { + V8Helpers::Throw(isolate, "Argument must be a number, an array of 3 numbers or IVector3"); + } + } +} + +static void Divide(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN2(1, 3); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + if (info.Length() == 3) + { + V8_ARG_TO_NUMBER(1, x2); + V8_ARG_TO_NUMBER(2, y2); + V8_ARG_TO_NUMBER(3, z2); + + V8_CHECK(x2 != 0 && y2 != 0 && z2 != 0, "Division by zero"); + V8_RETURN(resource->CreateVector3({ x / x2, y / y2, z / z2 })); + } + else if (info.Length() == 1) + { + auto arg = info[0]; + if (arg->IsNumber()) + { + V8_ARG_TO_NUMBER(1, value); + V8_CHECK(value != 0, "Division by zero"); + V8_RETURN(resource->CreateVector3({ x / value, y / value, z / value })); + } + else if (arg->IsArray()) + { + v8::Local arr = arg.As(); + V8_CHECK(arr->Length() == 3, "Argument must be an array of 3 numbers"); + + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), y2); + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), z2); + V8_CHECK(x2 != 0 && y2 != 0 && z2 != 0, "Division by zero"); + V8_RETURN(resource->CreateVector3({ x / x2, y / y2, z / z2 })); + } + else if (arg->IsObject()) + { + v8::Local obj = arg.As(); + + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(), z2); + V8_CHECK(x2 != 0 && y2 != 0 && z2 != 0, "Division by zero"); + V8_RETURN(resource->CreateVector3({ x / x2, y / y2, z / z2 })); + } + else + { + V8Helpers::Throw(isolate, "Argument must be a number, an array of 3 numbers or IVector3"); + } + } +} + +static void Multiply(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN2(1, 3); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + if (info.Length() == 3) + { + V8_ARG_TO_NUMBER(1, x2); + V8_ARG_TO_NUMBER(2, y2); + V8_ARG_TO_NUMBER(3, z2); + + V8_RETURN(resource->CreateVector3({ x * x2, y * y2, z * z2 })); + } + else if (info.Length() == 1) + { + auto arg = info[0]; + if (arg->IsNumber()) + { + V8_ARG_TO_NUMBER(1, value); + V8_RETURN(resource->CreateVector3({ x * value, y * value, z * value })); + } + else if (arg->IsArray()) + { + v8::Local arr = arg.As(); + V8_CHECK(arr->Length() == 3, "Argument must be an array of 3 numbers"); + + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), y2); + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), z2); + V8_RETURN(resource->CreateVector3({ x * x2, y * y2, z * z2 })); + } + else if (arg->IsObject()) + { + v8::Local obj = arg.As(); + + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(), z2); + + V8_RETURN(resource->CreateVector3({ x * x2, y * y2, z * z2 })); + } + else + { + V8Helpers::Throw(isolate, "Argument must be a number, an array of 3 numbers or IVector3"); + } + } +} + +static void Negative(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + V8_RETURN(resource->CreateVector3({ -x, -y, -z })); +} + +static void Normalize(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + double length = sqrt(x * x + y * y + z * z); + + V8_RETURN(resource->CreateVector3({ x / length, y / length, z / length })); +} + + +static void DistanceTo(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + V8_ARG_TO_OBJECT(1, vec); + + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(), z2); + + double dist = sqrt(std::powf(x - x2, 2) + std::powf(y - y2, 2) + std::powf(z - z2, 2)); + + V8_RETURN_NUMBER(dist); +} + +static void AngleTo(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + V8_ARG_TO_OBJECT(1, vec); + + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(), z2); + + double xy = x * x2 + y * y2; + double posALength = sqrt(std::pow(x, 2) + std::pow(y, 2)); + double posBLength = sqrt(std::pow(x2, 2) + std::pow(y2, 2)); + + if (posALength == 0 || posBLength == 0) + { + V8Helpers::Throw(isolate, "Division by zero!"); + return; + } + + double cos = xy / (posALength * posBLength); + double radians = std::acos(cos); + // double angle = radians * (180 / PI); + + V8_RETURN_NUMBER(radians); +} + +static void AngleToDegrees(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + V8_ARG_TO_OBJECT(1, vec); + + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(), z2); + + double xy = x * x2 + y * y2; + double posALength = sqrt(std::pow(x, 2) + std::pow(y, 2)); + double posBLength = sqrt(std::pow(x2, 2) + std::pow(y2, 2)); + + if (posALength == 0 || posBLength == 0) + { + V8Helpers::Throw(isolate, "Division by zero!"); + return; + } + + double cos = xy / (posALength * posBLength); + double radians = std::acos(cos); + double angle = radians * (180 / PI); + + V8_RETURN_NUMBER(angle); +} + +static void ToDegrees(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + double x2 = (x * 180) / PI; + double y2 = (y * 180) / PI; + double z2 = (z * 180) / PI; + + V8_RETURN(resource->CreateVector3({ x2, y2, z2 })); +} + +static void ToRadians(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + double x2 = (x * PI) / 180; + double y2 = (y * PI) / 180; + double z2 = (z * PI) / 180; + + V8_RETURN(resource->CreateVector3({ x2, y2, z2 })); +} + +static void IsInRange(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN(2); + + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + V8_ARG_TO_OBJECT(1, vec); + V8_ARG_TO_NUMBER(2, range); + + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(), z2); + + double dx = abs(x - x2); + double dy = abs(y - y2); + double dz = abs(z - z2); + + boolean isInRange = + dx <= range && // perform fast check first + dy <= range && + dz <= range && + dx * dx + dy * dy + dz * dz <= range * range; // perform exact check + + V8_RETURN_BOOLEAN(isInRange); +} + static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -75,7 +521,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) } else { - V8Helpers::Throw(isolate, "Argument must be an array of 3 numbers or Vector3Like"); + V8Helpers::Throw(isolate, "Argument must be an array of 3 numbers or IVector3"); return; } } @@ -88,5 +534,19 @@ static void Constructor(const v8::FunctionCallbackInfo& info) static V8Class v8Vector3("Vector3", "", Constructor, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); + V8::SetAccessor(isolate, tpl, "length", Length); V8::SetMethod(isolate, tpl, "toString", ToString); + V8::SetMethod(isolate, tpl, "toArray", ToArray); + V8::SetMethod(isolate, tpl, "add", Add); + V8::SetMethod(isolate, tpl, "sub", Sub); + V8::SetMethod(isolate, tpl, "div", Divide); + V8::SetMethod(isolate, tpl, "mul", Multiply); + V8::SetMethod(isolate, tpl, "negative", Negative); + V8::SetMethod(isolate, tpl, "normalize", Normalize); + V8::SetMethod(isolate, tpl, "distanceTo", DistanceTo); + V8::SetMethod(isolate, tpl, "angleTo", AngleTo); + V8::SetMethod(isolate, tpl, "angleToDegrees", AngleToDegrees); + V8::SetMethod(isolate, tpl, "toRadians", ToRadians); + V8::SetMethod(isolate, tpl, "toDegrees", ToDegrees); + V8::SetMethod(isolate, tpl, "isInRange", IsInRange); }, false); From f48945bca621fed1ed28b9dccd5a812eb3c9281b Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 4 Nov 2020 22:23:17 +0100 Subject: [PATCH 029/564] Remove debug msgbox --- src/CV8ScriptRuntime.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index d83e12b9..d8dc5ee7 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -4,8 +4,6 @@ #include "inspector/CV8InspectorChannel.h" #include "helpers/V8Module.h" -#include "Windows.h" - CV8ScriptRuntime::CV8ScriptRuntime() { platform = v8::platform::NewDefaultPlatform(); @@ -80,7 +78,6 @@ CV8ScriptRuntime::CV8ScriptRuntime() v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); - MessageBoxA(NULL, "", "", MB_OK); V8Class::LoadAll(isolate); extern V8Module altModule, nativesModule; From 06f10317562463ee1b477a1fdadd48775f576239 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 5 Nov 2020 00:04:08 +0100 Subject: [PATCH 030/564] Reduce naming collisions in cmake --- CMakeLists.txt | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index facb1d0a..c7b3bf3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,14 +2,9 @@ cmake_minimum_required (VERSION 3.10) project(altv-client-js) -set(ALTV_DEPS_DIR ${CMAKE_SOURCE_DIR}/deps) +set(ALTV_JS_DEPS_DIR ${CMAKE_SOURCE_DIR}/deps) file(GLOB_RECURSE PROJECT_SOURCE_FILES "src/*.h" "src/*.hpp" "src/*.cpp" "src/*.c") -# file(GLOB_RECURSE SHARED_SOURCE_FILES -# "${ALTV_SHARED}/src/*.h" -# "${ALTV_SHARED}/src/*.hpp" -# "${ALTV_SHARED}/src/*.cpp" -# ) macro(GroupSources curdir groupindex) file(GLOB children RELATIVE ${curdir} ${curdir}/*) @@ -29,15 +24,15 @@ endmacro() GroupSources(${PROJECT_SOURCE_DIR}/src "Source Files") include_directories( - ${ALTV_DEPS_DIR} - ${ALTV_DEPS_DIR}/v8/include + ${ALTV_JS_DEPS_DIR} + ${ALTV_JS_DEPS_DIR}/v8/include ) link_directories( - ${ALTV_DEPS_DIR}/v8/lib/${CMAKE_BUILD_TYPE} + ${ALTV_JS_DEPS_DIR}/v8/lib/${CMAKE_BUILD_TYPE} ) -link_libraries( +set(ALTV_JS_LINKS # Platform binaries Winmm.lib DbgHelp.lib @@ -46,7 +41,7 @@ link_libraries( v8_monolith.lib ) -add_definitions( +set(ALTV_JS_DEFS # Compliation -DCXX_COMPILER_ID="${CMAKE_CXX_COMPILER_ID}" @@ -76,8 +71,12 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 ) target_compile_definitions(${PROJECT_NAME} PRIVATE + ${ALTV_JS_DEFS} -DALTV_JS_SHARED ) +target_link_libraries(${PROJECT_NAME} PRIVATE + ${ALTV_JS_LINKS} +) ## STATIC add_library( @@ -86,4 +85,10 @@ add_library( ) set_target_properties(${PROJECT_NAME}-static PROPERTIES CXX_STANDARD 17 -) \ No newline at end of file +) +target_compile_definitions(${PROJECT_NAME}-static PRIVATE + ${ALTV_JS_DEFS} +) +target_link_libraries(${PROJECT_NAME}-static PRIVATE + ${ALTV_JS_LINKS} +) From 8fdf2130107ac0afa39f407607c62dba3ca16364 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 5 Nov 2020 03:40:43 +0100 Subject: [PATCH 031/564] Fetch deps --- CMakeLists.txt | 33 ++++++- cmake/GitUtils.cmake | 228 +++++++++++++++++++++++++++++++++++++++++++ cmake/Utils.cmake | 32 ++++++ deps/cpp-sdk | 1 - 4 files changed, 289 insertions(+), 5 deletions(-) create mode 100644 cmake/GitUtils.cmake create mode 100644 cmake/Utils.cmake delete mode 160000 deps/cpp-sdk diff --git a/CMakeLists.txt b/CMakeLists.txt index c7b3bf3b..67a5d83a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,33 @@ cmake_minimum_required (VERSION 3.10) +include(cmake/GitUtils.cmake) +include(FetchContent) project(altv-client-js) -set(ALTV_JS_DEPS_DIR ${CMAKE_SOURCE_DIR}/deps) +# set(ALTV_JS_DEPS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps) + +# Fetch deps +# v8 +message("alt:V JS - Fetching v8 deps, can take a while") +FetchContent_Declare(altv-js-deps + URL https://github.com/altmp/altv-client-js/releases/download/deps/deps.zip +) +FetchContent_Populate(altv-js-deps) +set(ALTV_JS_DL_DEPS ${altv-js-deps_SOURCE_DIR}) + +# cpp-sdk +if(NOT ALTV_JS_CPP_SDK) + git_clone( + PROJECT_NAME cpp-sdk + GIT_URL https://github.com/altmp/cpp-sdk + GIT_BRANCH clientsdk + DIRECTORY ${ALTV_JS_DL_DEPS} + ) + set(ALTV_JS_CPP_SDK ${ALTV_JS_DL_DEPS}) +else() + message("alt:V JS - Skipping fetching cpp-sdk") +endif() +# Fetch deps file(GLOB_RECURSE PROJECT_SOURCE_FILES "src/*.h" "src/*.hpp" "src/*.cpp" "src/*.c") @@ -24,12 +49,12 @@ endmacro() GroupSources(${PROJECT_SOURCE_DIR}/src "Source Files") include_directories( - ${ALTV_JS_DEPS_DIR} - ${ALTV_JS_DEPS_DIR}/v8/include + ${ALTV_JS_CPP_SDK} + ${ALTV_JS_DL_DEPS}/include ) link_directories( - ${ALTV_JS_DEPS_DIR}/v8/lib/${CMAKE_BUILD_TYPE} + ${ALTV_JS_DL_DEPS}/lib/${CMAKE_BUILD_TYPE} ) set(ALTV_JS_LINKS diff --git a/cmake/GitUtils.cmake b/cmake/GitUtils.cmake new file mode 100644 index 00000000..25ba372c --- /dev/null +++ b/cmake/GitUtils.cmake @@ -0,0 +1,228 @@ +cmake_minimum_required(VERSION 2.8.7) + +include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake) +include(CMakeParseArguments) + +find_package(Git) +if(NOT GIT_FOUND) + message(FATAL_ERROR "git not found!") +endif() + + +# clone a git repo into a directory at configure time +# this can be useful for including cmake-library projects that contain *.cmake files +# the function will automatically init git submodules too +# +# ATTENTION: CMakeLists-files in the cloned repo will NOT be build automatically +# +# why not use ExternalProject_Add you ask? because we need to run this at configure time +# +# USAGE: +# git_clone( +# PROJECT_NAME +# GIT_URL +# [GIT_TAG|GIT_BRANCH|GIT_COMMIT ] +# [DIRECTORY ] +# [QUIET] +# ) +# +# +# ARGUMENTS: +# PROJECT_NAME +# name of the project that will be used in output variables. +# must be the same as the git directory/repo name +# +# GIT_URL +# url to the git repo +# +# GIT_TAG|GIT_BRANCH|GIT_COMMIT +# optional +# the tag/branch/commit to checkout +# default is master +# +# DIRECTORY +# optional +# the directory the project will be cloned into +# default is the build directory, similar to ExternalProject (${CMAKE_BINARY_DIR}) +# +# QUIET +# optional +# don't print status messages +# +# SOURCE_DIR_VARIABLE +# optional +# the variable will be set to contain the path to clonned directory. +# if not set path will be set in _SOURCE_DIR +# +# CLONE_RESULT_VARIABLE +# optional +# the variable will be set to contain the clone result. TRUE - success, FALSE - error +# if not set result will be set in _CLONE_RESULT +# +# +# +# OUTPUT VARIABLES: +# _SOURCE_DIR +# optional, exists when SOURCE_DIR_VARIABLE not set +# top level source directory of the cloned project +# +# _CLONE_RESULT +# optional, exists when CLONE_RESULT_VARIABLE not set +# Result of git_clone function. TRUE - success, FALSE - error +# +# +# EXAMPLE: +# git_clone( +# PROJECT_NAME testProj +# GIT_URL https://github.com/test/test.git +# GIT_COMMIT a1b2c3 +# DIRECTORY ${CMAKE_BINARY_DIR} +# QUIET +# ) +# +# include(${testProj_SOURCE_DIR}/cmake/myFancyLib.cmake) + +function(git_clone) + + cmake_parse_arguments( + PARGS # prefix of output variables + "QUIET" # list of names of the boolean arguments (only defined ones will be true) + "PROJECT_NAME;GIT_URL;GIT_TAG;GIT_BRANCH;GIT_COMMIT;DIRECTORY;SOURCE_DIR_VARIABLE;CLONE_RESULT_VARIABLE" # list of names of mono-valued arguments + "" # list of names of multi-valued arguments (output variables are lists) + ${ARGN} # arguments of the function to parse, here we take the all original ones + ) # remaining unparsed arguments can be found in PARGS_UNPARSED_ARGUMENTS + if(NOT PARGS_PROJECT_NAME) + message(FATAL_ERROR "You must provide a project name") + endif() + + if(NOT PARGS_GIT_URL) + message(FATAL_ERROR "You must provide a git url") + endif() + + if(NOT PARGS_DIRECTORY) + set(PARGS_DIRECTORY ${CMAKE_BINARY_DIR}) + endif() + + if(NOT PARGS_SOURCE_DIR_VARIABLE) + set(${PARGS_PROJECT_NAME}_SOURCE_DIR + ${PARGS_DIRECTORY}/${PARGS_PROJECT_NAME} + CACHE INTERNAL "" FORCE) # makes var visible everywhere because PARENT_SCOPE wouldn't include this scope + + set(SOURCE_DIR ${PARGS_PROJECT_NAME}_SOURCE_DIR) + else() + set(${PARGS_SOURCE_DIR_VARIABLE} + ${PARGS_DIRECTORY}/${PARGS_PROJECT_NAME} + CACHE INTERNAL "" FORCE) # makes var visible everywhere because PARENT_SCOPE wouldn't include this scope + + set(SOURCE_DIR ${PARGS_SOURCE_DIR_VARIABLE}) + endif() + + if(NOT PARGS_CLONE_RESULT_VARIABLE) + set(CLONE_RESULT ${PARGS_PROJECT_NAME}_CLONE_RESULT) + else() + set(CLONE_RESULT ${PARGS_CLONE_RESULT_VARIABLE}) + endif() + + # check that only one of GIT_TAG xor GIT_BRANCH xor GIT_COMMIT was passed + at_most_one(at_most_one_tag ${PARGS_GIT_TAG} ${PARGS_GIT_BRANCH} ${PARGS_GIT_COMMIT}) + + if(NOT at_most_one_tag) + message(FATAL_ERROR "you can only provide one of GIT_TAG, GIT_BRANCH or GIT_COMMIT") + endif() + + if(NOT PARGS_QUIET) + message(STATUS "downloading/updating ${PARGS_PROJECT_NAME}") + endif() + + # first clone the repo + if(EXISTS ${${SOURCE_DIR}}) + if(NOT PARGS_QUIET) + message(STATUS "${PARGS_PROJECT_NAME} directory found, pulling...") + endif() + + execute_process( + COMMAND ${GIT_EXECUTABLE} pull origin master + WORKING_DIRECTORY ${${SOURCE_DIR}} + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_output) + if(git_result EQUAL "0") + execute_process( + COMMAND ${GIT_EXECUTABLE} submodule update --remote + WORKING_DIRECTORY ${${SOURCE_DIR}} + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_output) + if(NOT git_result EQUAL "0") + set(${CLONE_RESULT} FALSE CACHE INTERNAL "" FORCE) + if(NOT PARGS_QUIET) + message(WARNING "${PARGS_PROJECT_NAME} submodule update error") #ToDo: maybe FATAL_ERROR? + endif() + return() + endif() + else() + set(${CLONE_RESULT} FALSE CACHE INTERNAL "" FORCE) + if(NOT PARGS_QUIET) + message(WARNING "${PARGS_PROJECT_NAME} pull error") #ToDo: maybe FATAL_ERROR? + endif() + return() + endif() + else() + if(NOT PARGS_QUIET) + message(STATUS "${PARGS_PROJECT_NAME} directory not found, cloning...") + endif() + + execute_process( + COMMAND ${GIT_EXECUTABLE} clone ${PARGS_GIT_URL} --recursive ${${SOURCE_DIR}} + WORKING_DIRECTORY ${PARGS_DIRECTORY} + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_output) + if(NOT git_result EQUAL "0") + set(${CLONE_RESULT} FALSE CACHE INTERNAL "" FORCE) + if(NOT PARGS_QUIET) + message(WARNING "${PARGS_PROJECT_NAME} clone error") #ToDo: maybe FATAL_ERROR? + endif() + return() + endif() + endif() + + + if(NOT PARGS_QUIET) + message(STATUS "${git_output}") + endif() + + # now checkout the right commit + if(PARGS_GIT_TAG) + execute_process( + COMMAND ${GIT_EXECUTABLE} fetch --all --tags --prune + COMMAND ${GIT_EXECUTABLE} checkout tags/${PARGS_GIT_TAG} -b tag_${PARGS_GIT_TAG} + WORKING_DIRECTORY ${${SOURCE_DIR}} + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_output) + elseif(PARGS_GIT_BRANCH OR PARGS_GIT_COMMIT) + execute_process( + COMMAND ${GIT_EXECUTABLE} checkout ${PARGS_GIT_BRANCH} ${PARGS_GIT_COMMIT} + WORKING_DIRECTORY ${${SOURCE_DIR}} + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_output) + else() + if(NOT PARGS_QUIET) + message(STATUS "no tag specified, defaulting to master") + endif() + execute_process( + COMMAND ${GIT_EXECUTABLE} checkout master + WORKING_DIRECTORY ${${SOURCE_DIR}} + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_output) + endif() + if(NOT git_result EQUAL "0") + set(${CLONE_RESULT} FALSE CACHE INTERNAL "" FORCE) + if(NOT PARGS_QUIET) + message(WARNING "${PARGS_PROJECT_NAME} some error happens. ${git_output}") #ToDo: maybe FATAL_ERROR? + endif() + return() + else() + set(${CLONE_RESULT} TRUE CACHE INTERNAL "" FORCE) + endif() + if(NOT PARGS_QUIET) + message(STATUS "${git_output}") + endif() +endfunction() diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake new file mode 100644 index 00000000..a76708ca --- /dev/null +++ b/cmake/Utils.cmake @@ -0,0 +1,32 @@ +# returns true if only a single one of its arguments is true +function(xor result) + set(true_args_count 0) + + foreach(foo ${ARGN}) + if(foo) + math(EXPR true_args_count "${true_args_count}+1") + endif() + endforeach() + + if(NOT (${true_args_count} EQUAL 1)) + set(${result} FALSE PARENT_SCOPE) + else() + set(${result} TRUE PARENT_SCOPE) + endif() +endfunction() + +function(at_most_one result) + set(true_args_count 0) + + foreach(foo ${ARGN}) + if(foo) + math(EXPR true_args_count "${true_args_count}+1") + endif() + endforeach() + + if(${true_args_count} GREATER 1) + set(${result} FALSE PARENT_SCOPE) + else() + set(${result} TRUE PARENT_SCOPE) + endif() +endfunction() diff --git a/deps/cpp-sdk b/deps/cpp-sdk deleted file mode 160000 index 75b492f4..00000000 --- a/deps/cpp-sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 75b492f402b68b1417fc9534dd40a6b34705b76d From baa886b918e802abec4a1d89325c4196f1092ca5 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 5 Nov 2020 04:30:29 +0100 Subject: [PATCH 032/564] Fix linking --- CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67a5d83a..3a4cc1b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,17 +53,13 @@ include_directories( ${ALTV_JS_DL_DEPS}/include ) -link_directories( - ${ALTV_JS_DL_DEPS}/lib/${CMAKE_BUILD_TYPE} -) - set(ALTV_JS_LINKS # Platform binaries Winmm.lib DbgHelp.lib # V8 - v8_monolith.lib + ${ALTV_JS_DL_DEPS}/lib/$,Debug,Release>/v8_monolith.lib ) set(ALTV_JS_DEFS From 660d23bb781e64aaea65d2051c19b2323c62c925 Mon Sep 17 00:00:00 2001 From: Hazard Date: Sat, 7 Nov 2020 00:38:48 +0100 Subject: [PATCH 033/564] Wrapped blips --- src/bindings/Blip.cpp | 1672 +++++++++++++++++++++-------------------- src/bindings/Main.cpp | 8 +- 2 files changed, 841 insertions(+), 839 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index dbd152b3..d316399f 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -1,924 +1,926 @@ -// #include "../CV8Resource.h" -// #include "../helpers/V8Class.h" -// #include "cpp-sdk/script-objects/IBlip.h" +#include "../CV8Resource.h" +#include "../helpers/V8Class.h" +#include "cpp-sdk/script-objects/IBlip.h" -// static void Constructor(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void Constructor(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(info.IsConstructCall(), "Blip constructor is not a function"); + V8_CHECK(info.IsConstructCall(), "Blip constructor is not a function"); -// // xyz as obj -// /* -// V8_CHECK(info.Length() == 2, "new Blip(...) expects 2 args"); + // xyz as obj + /* + V8_CHECK(info.Length() == 2, "new Blip(...) expects 2 args"); -// V8_CHECK(info[0]->IsObject(), "pos must be an object of {x, y, z}"); -// auto pos = info[1]->ToObject(isolate); -// double x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x")).ToLocalChecked() -// ->NumberValue(ctx).ToChecked(); -// double y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y")).ToLocalChecked() -// ->NumberValue(ctx).ToChecked(); -// double z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z")).ToLocalChecked() -// ->NumberValue(ctx).ToChecked(); + V8_CHECK(info[0]->IsObject(), "pos must be an object of {x, y, z}"); + auto pos = info[1]->ToObject(isolate); + double x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x")).ToLocalChecked() + ->NumberValue(ctx).ToChecked(); + double y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y")).ToLocalChecked() + ->NumberValue(ctx).ToChecked(); + double z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z")).ToLocalChecked() + ->NumberValue(ctx).ToChecked(); -// V8_CHECK(info[1]->IsNumber(), "type must be an unsigned integer"); -// */ + V8_CHECK(info[1]->IsNumber(), "type must be an unsigned integer"); + */ -// /* -// let blip = new alt.Blip(0, 0, 72, 11, 50, 50); -// blip.rotation = 0; -// */ + /* + let blip = new alt.Blip(0, 0, 72, 11, 50, 50); + blip.rotation = 0; + */ -// // xyz as args + // xyz as args -// V8_CHECK(false, "You can't use constructor of abstract class"); -// } + V8_CHECK(false, "You can't use constructor of abstract class"); +} -// static void ConstructorAreaBlip(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void ConstructorAreaBlip(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + auto resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8_CHECK(info.IsConstructCall(), "AreaBlip constructor is not a function"); + V8_CHECK(info.IsConstructCall(), "AreaBlip constructor is not a function"); -// V8_CHECK(info.Length() == 5, "new AreaBlip(...) expects 5 args"); -// V8_CHECK(info[0]->IsNumber(), "x must be a number"); -// V8_CHECK(info[1]->IsNumber(), "y must be a number"); -// V8_CHECK(info[2]->IsNumber(), "z must be a number"); -// V8_CHECK(info[3]->IsNumber(), "width must be a number"); -// V8_CHECK(info[4]->IsNumber(), "height must be a number"); + V8_CHECK(info.Length() == 5, "new AreaBlip(...) expects 5 args"); + V8_CHECK(info[0]->IsNumber(), "x must be a number"); + V8_CHECK(info[1]->IsNumber(), "y must be a number"); + V8_CHECK(info[2]->IsNumber(), "z must be a number"); + V8_CHECK(info[3]->IsNumber(), "width must be a number"); + V8_CHECK(info[4]->IsNumber(), "height must be a number"); -// v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); -// v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); -// v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); -// v8::Local width = info[3]->ToNumber(ctx).ToLocalChecked(); -// v8::Local height = info[4]->ToNumber(ctx).ToLocalChecked(); + v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); + v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); + v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); + v8::Local width = info[3]->ToNumber(ctx).ToLocalChecked(); + v8::Local height = info[4]->ToNumber(ctx).ToLocalChecked(); -// alt::Ref blip = alt::IBlip::CreateBlipForArea({x->Value(), y->Value(), z->Value()}, width->Value(), height->Value()); + alt::Ref blip = resource->CreateBlip({x->Value(), y->Value(), z->Value()}, width->Value(), height->Value()); -// V8_CHECK(blip, "Blip creation failed"); + V8_CHECK(blip, "Blip creation failed"); -// static_cast(resource)->AddOwned(blip); -// resource->BindEntity(info.This(), blip.Get()); -// } + // static_cast(resource)->AddOwned(blip); + // resource->BindEntity(info.This(), blip.Get()); +} -// static void ConstructorRadiusBlip(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void ConstructorRadiusBlip(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + auto resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8_CHECK(info.IsConstructCall(), "RadiusBlip constructor is not a function"); + V8_CHECK(info.IsConstructCall(), "RadiusBlip constructor is not a function"); -// V8_CHECK(info.Length() == 4, "new RadiusBlip(...) expects 4 args"); -// V8_CHECK(info[0]->IsNumber(), "x must be a number"); -// V8_CHECK(info[1]->IsNumber(), "y must be a number"); -// V8_CHECK(info[2]->IsNumber(), "z must be a number"); -// V8_CHECK(info[3]->IsNumber(), "radius must be a number"); + V8_CHECK(info.Length() == 4, "new RadiusBlip(...) expects 4 args"); + V8_CHECK(info[0]->IsNumber(), "x must be a number"); + V8_CHECK(info[1]->IsNumber(), "y must be a number"); + V8_CHECK(info[2]->IsNumber(), "z must be a number"); + V8_CHECK(info[3]->IsNumber(), "radius must be a number"); -// v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); -// v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); -// v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); -// v8::Local radius = info[3]->ToNumber(ctx).ToLocalChecked(); -// alt::Ref blip = alt::IBlip::CreateBlipForRadius({x->Value(), y->Value(), z->Value()}, radius->Value()); + v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); + v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); + v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); + v8::Local radius = info[3]->ToNumber(ctx).ToLocalChecked(); + alt::Ref blip = resource->CreateBlip({x->Value(), y->Value(), z->Value()}, radius->Value()); -// V8_CHECK(blip, "Blip creation failed"); + V8_CHECK(blip, "Blip creation failed"); -// static_cast(resource)->AddOwned(blip); -// resource->BindEntity(info.This(), blip.Get()); -// } + // static_cast(resource)->AddOwned(blip); + // resource->BindEntity(info.This(), blip.Get()); +} -// static void ConstructorPointBlip(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void ConstructorPointBlip(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); + auto resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); -// V8_CHECK(info.IsConstructCall(), "PointBlip constructor is not a function"); + V8_CHECK(info.IsConstructCall(), "PointBlip constructor is not a function"); -// V8_CHECK(info.Length() == 3, "new PointBlip(...) expects 3 args"); -// V8_CHECK(info[0]->IsNumber(), "x must be a number"); -// V8_CHECK(info[1]->IsNumber(), "y must be a number"); -// V8_CHECK(info[2]->IsNumber(), "z must be a number"); + V8_CHECK(info.Length() == 3, "new PointBlip(...) expects 3 args"); + V8_CHECK(info[0]->IsNumber(), "x must be a number"); + V8_CHECK(info[1]->IsNumber(), "y must be a number"); + V8_CHECK(info[2]->IsNumber(), "z must be a number"); -// v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); -// v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); -// v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); -// alt::Ref blip = alt::IBlip::Create(alt::IBlip::BlipType::DESTINATION, {x->Value(), y->Value(), z->Value()}); - -// V8_CHECK(blip, "Blip creation failed"); - -// static_cast(resource)->AddOwned(blip); -// resource->BindEntity(info.This(), blip.Get()); -// } - -// static void ConstructorPedBlip(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); - -// V8_CHECK(info.IsConstructCall(), "PedBlip constructor is not a function"); - -// V8_CHECK(info.Length() == 1, "new PedBlip(...) expects 1 arg"); -// V8_CHECK(info[0]->IsNumber(), "pedId must be a number"); - -// uint32_t pedId = info[0]->IntegerValue(ctx).ToChecked(); -// alt::Ref blip = alt::IBlip::CreateBlipForEntity(alt::IBlip::BlipType::PED, pedId); - -// V8_CHECK(blip, "Blip creation failed"); - -// static_cast(resource)->AddOwned(blip); -// resource->BindEntity(info.This(), blip.Get()); -// } - -// static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); - -// V8_CHECK(info.IsConstructCall(), "VehicleBlip constructor is not a function"); - -// V8_CHECK(info.Length() == 1, "new VehicleBlip(...) expects 1 arg"); -// V8_CHECK(info[0]->IsNumber(), "vehicleId must be a number"); - -// uint32_t vehicleId = info[0]->IntegerValue(ctx).ToChecked(); -// alt::Ref blip = alt::IBlip::CreateBlipForEntity(alt::IBlip::BlipType::VEHICLE, vehicleId); - -// V8_CHECK(blip, "Blip creation failed"); - -// static_cast(resource)->AddOwned(blip); -// resource->BindEntity(info.This(), blip.Get()); -// } - -// //static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetScale())); -// //} - -// static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(value->IsNumber(), "scale must be a number"); -// double val = value->NumberValue(ctx).ToChecked(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); - -// blip->SetScale(val); -// } - -// /** -// * Scale XY -// * */ -// //static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // auto scale = blip->GetScaleXY(); -// // -// // -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, )); -// //} - -// /** -// * Scale XY -// * */ -// //static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // V8_CHECK(value->IsNumber(), "scale must be a number"); -// // double val = value->NumberValue(ctx).ToChecked(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // blip->SetScale(val); -// //} - -// //static void SpriteGetter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void SpriteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(value->IsNumber(), "sprite must be an integer"); -// int sprite = value->IntegerValue(ctx).ToChecked(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); - -// blip->SetSprite(sprite); -// } - -// //static void ColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void ColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(value->IsNumber(), "color must be an integer"); -// int val = value->IntegerValue(ctx).ToChecked(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetColor(val); -// } - -// //static void SecondaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void SecondaryColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(value->IsNumber(), "secondaryColor must be an unsigned integer"); -// int val = value->IntegerValue(ctx).ToChecked(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetSecondaryColor(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void AlphaSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(value->IsNumber(), "alpha must be an integer"); -// int val = value->IntegerValue(ctx).ToChecked(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetAlpha(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void FlashTimerSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(value->IsNumber(), "flashTimer must be an integer"); -// int val = value->IntegerValue(ctx).ToChecked(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetFlashTimer(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void FlashIntervalSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(value->IsNumber(), "flashInterval must be an integer"); -// int val = value->IntegerValue(ctx).ToChecked(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetFlashInterval(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void FriendlySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// auto val = value->ToBoolean(isolate)->Value(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetAsFriendly(val); -// } - -// //static void RouteGetter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void RouteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// auto val = value->ToBoolean(isolate)->Value(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetRoute(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void BrightSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// auto val = value->ToBoolean(isolate)->Value(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetBright(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void NumberSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(value->IsNumber(), "number must be an integer"); -// auto val = value->IntegerValue(ctx).ToChecked(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetNumber(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void ShowConeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// auto val = value->ToBoolean(isolate)->Value(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetShowCone(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void FlashesSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// auto val = value->ToBoolean(isolate)->Value(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetFlashes(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void FlashesAlternateSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// auto val = value->ToBoolean(isolate)->Value(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetFlashesAlternate(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void ShortRangeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// auto val = value->ToBoolean(isolate)->Value(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetAsShortRange(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void PrioritySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(value->IsNumber(), "priority must be an integer"); -// auto val = value->IntegerValue(ctx).ToChecked(); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetPriority(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -// //} - -// static void RotationSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(value->IsNumber(), "rotation must be a number"); -// auto val = value->NumberValue(ctx).ToChecked(); - -// Log::Debug << "nextRotation = " << val << Log::Endl; - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetRotation(val); -// } - -// //static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// //{ -// // v8::Isolate* isolate = info.GetIsolate(); -// // auto ctx = isolate->GetEnteredContext(); -// // -// // alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// // -// // info.GetReturnValue().Set(v8::Number::New(isolate, blip->())); -// //} - -// static void GxtNameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(value->IsString(), "gxtName must be a string"); -// auto val = *v8::String::Utf8Value(info.GetIsolate(), value->ToString(ctx).ToLocalChecked()); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetGxtName(val); -// } - -// static void NameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(value->IsString(), "name must be a string"); -// auto val = *v8::String::Utf8Value(info.GetIsolate(), value->ToString(ctx).ToLocalChecked()); + v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); + v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); + v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); + alt::Ref blip = resource->CreateBlip(alt::IBlip::BlipType::DESTINATION, {x->Value(), y->Value(), z->Value()}); + + V8_CHECK(blip, "Blip creation failed"); + + // static_cast(resource)->AddOwned(blip); + // resource->BindEntity(info.This(), blip.Get()); +} + +static void ConstructorPedBlip(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + auto resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8_CHECK(info.IsConstructCall(), "PedBlip constructor is not a function"); + + V8_CHECK(info.Length() == 1, "new PedBlip(...) expects 1 arg"); + V8_CHECK(info[0]->IsNumber(), "pedId must be a number"); + + uint32_t pedId = info[0]->IntegerValue(ctx).ToChecked(); + alt::Ref blip = resource->CreateBlip(alt::IBlip::BlipType::PED, pedId); + + V8_CHECK(blip, "Blip creation failed"); + + // static_cast(resource)->AddOwned(blip); + // resource->BindEntity(info.This(), blip.Get()); +} + +static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + auto resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8_CHECK(info.IsConstructCall(), "VehicleBlip constructor is not a function"); + + V8_CHECK(info.Length() == 1, "new VehicleBlip(...) expects 1 arg"); + V8_CHECK(info[0]->IsNumber(), "vehicleId must be a number"); + + uint32_t vehicleId = info[0]->IntegerValue(ctx).ToChecked(); + alt::Ref blip = resource->CreateBlip(alt::IBlip::BlipType::VEHICLE, vehicleId); + + V8_CHECK(blip, "Blip creation failed"); + + // static_cast(resource)->AddOwned(blip); + // resource->BindEntity(info.This(), blip.Get()); +} + +//static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetScale())); +//} + +static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(value->IsNumber(), "scale must be a number"); + auto val = value->NumberValue(ctx).ToChecked(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + + blip->SetScale(val); +} + +/** + * Scale XY + * */ +//static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// auto scale = blip->GetScaleXY(); +// +// +// +// info.GetReturnValue().Set(v8::Number::New(isolate, )); +//} + +/** + * Scale XY + * */ +//static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// V8_CHECK(value->IsNumber(), "scale must be a number"); +// double val = value->NumberValue(ctx).ToChecked(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// blip->SetScale(val); +//} + +//static void SpriteGetter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void SpriteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(value->IsNumber(), "sprite must be an integer"); + int sprite = value->IntegerValue(ctx).ToChecked(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + + blip->SetSprite(sprite); +} + +//static void ColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void ColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(value->IsNumber(), "color must be an integer"); + int val = value->IntegerValue(ctx).ToChecked(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetColor(val); +} + +//static void SecondaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void SecondaryColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(value->IsNumber(), "secondaryColor must be an unsigned integer"); + auto val = value->IntegerValue(ctx).ToChecked(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetSecondaryColor(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void AlphaSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(value->IsNumber(), "alpha must be an integer"); + auto val = value->IntegerValue(ctx).ToChecked(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetAlpha(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void FlashTimerSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(value->IsNumber(), "flashTimer must be an integer"); + int val = value->IntegerValue(ctx).ToChecked(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetFlashTimer(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void FlashIntervalSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(value->IsNumber(), "flashInterval must be an integer"); + int val = value->IntegerValue(ctx).ToChecked(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetFlashInterval(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void FriendlySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + auto val = value->ToBoolean(isolate)->Value(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetAsFriendly(val); +} + +//static void RouteGetter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void RouteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + auto val = value->ToBoolean(isolate)->Value(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetRoute(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void BrightSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + auto val = value->ToBoolean(isolate)->Value(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetBright(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void NumberSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(value->IsNumber(), "number must be an integer"); + auto val = value->IntegerValue(ctx).ToChecked(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetNumber(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void ShowConeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + auto val = value->ToBoolean(isolate)->Value(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetShowCone(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void FlashesSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + auto val = value->ToBoolean(isolate)->Value(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetFlashes(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void FlashesAlternateSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + auto val = value->ToBoolean(isolate)->Value(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetFlashesAlternate(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void ShortRangeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + auto val = value->ToBoolean(isolate)->Value(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetAsShortRange(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void PrioritySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(value->IsNumber(), "priority must be an integer"); + auto val = value->IntegerValue(ctx).ToChecked(); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetPriority(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); +//} + +static void RotationSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(value->IsNumber(), "rotation must be a number"); + auto val = value->NumberValue(ctx).ToChecked(); + + Log::Debug << "nextRotation = " << val << Log::Endl; + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetRotation(val); +} + +//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +//{ +// v8::Isolate* isolate = info.GetIsolate(); +// auto ctx = isolate->GetEnteredContext(); +// +// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); +// +// info.GetReturnValue().Set(v8::Number::New(isolate, blip->())); +//} + +static void GxtNameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(value->IsString(), "gxtName must be a string"); + auto val = *v8::String::Utf8Value(info.GetIsolate(), value->ToString(ctx).ToLocalChecked()); + + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + alt::Ref blip = _this->GetHandle().As(); + blip->SetGxtName(val); +} + +static void NameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(value->IsString(), "name must be a string"); + auto val = *v8::String::Utf8Value(info.GetIsolate(), value->ToString(ctx).ToLocalChecked()); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetName(val); -// } + alt::Ref blip = _this->GetHandle().As(); + blip->SetName(val); +} -// /* -// static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -// { -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +/* +static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); + alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// auto ret = v8::Number::New(isolate, blip->GETTER())); -// info.GetReturnValue().Set(ret); -// } -// */ + auto ret = v8::Number::New(isolate, blip->GETTER())); + info.GetReturnValue().Set(ret); +} +*/ -// static void RouteColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void RouteColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "routeColor must be unsigned integer"); -// auto val = value->IntegerValue(ctx).ToChecked(); + V8_CHECK(value->IsNumber(), "routeColor must be unsigned integer"); + auto val = value->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetRouteColor(val); -// } + alt::Ref blip = _this->GetHandle().As(); + blip->SetRouteColor(val); +} -// static void PulseSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void PulseSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); + auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetPulse(val); -// } + alt::Ref blip = _this->GetHandle().As(); + blip->SetPulse(val); +} -// static void AsMissionCreatorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void AsMissionCreatorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); + auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetAsMissionCreator(val); -// } + alt::Ref blip = _this->GetHandle().As(); + blip->SetAsMissionCreator(val); +} -// static void tickVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void tickVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); + auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetTickVisible(val); -// } + alt::Ref blip = _this->GetHandle().As(); + blip->SetTickVisible(val); +} -// static void headingIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void headingIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); + auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetHeadingIndicatorVisible(val); -// } + alt::Ref blip = _this->GetHandle().As(); + blip->SetHeadingIndicatorVisible(val); +} -// static void outlineIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void outlineIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); + auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetOutlineIndicatorVisible(val); -// } + alt::Ref blip = _this->GetHandle().As(); + blip->SetOutlineIndicatorVisible(val); +} -// static void friendIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void friendIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); + auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetFriendIndicatorVisible(val); -// } + alt::Ref blip = _this->GetHandle().As(); + blip->SetFriendIndicatorVisible(val); +} -// static void crewIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void crewIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); + auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetCrewIndicatorVisible(val); -// } + alt::Ref blip = _this->GetHandle().As(); + blip->SetCrewIndicatorVisible(val); +} -// static void categorySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void categorySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(value->IsNumber(), "category must be integer"); -// auto val = value->IntegerValue(ctx).ToChecked(); + V8_CHECK(value->IsNumber(), "category must be integer"); + auto val = value->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetCategory(val); -// } + alt::Ref blip = _this->GetHandle().As(); + blip->SetCategory(val); +} -// static void highDetailSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void highDetailSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); + auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetAsHighDetail(val); -// } + alt::Ref blip = _this->GetHandle().As(); + blip->SetAsHighDetail(val); +} -// static void shrinkedSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void shrinkedSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// auto val = value->ToBoolean(isolate)->Value(); + auto val = value->ToBoolean(isolate)->Value(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); -// blip->SetShrinked(val); -// } + alt::Ref blip = _this->GetHandle().As(); + blip->SetShrinked(val); +} -// static void Fade(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +static void Fade(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(info.Length() == 2, "2 args expected"); + V8_CHECK(info.Length() == 2, "2 args expected"); -// V8_CHECK(info[0]->IsNumber(), "opacity must be an unsigned integer"); -// uint32_t opacity = info[0]->IntegerValue(ctx).ToChecked(); + V8_CHECK(info[0]->IsNumber(), "opacity must be an unsigned integer"); + uint32_t opacity = info[0]->IntegerValue(ctx).ToChecked(); -// V8_CHECK(info[1]->IsNumber(), "duration must be an unsigned integer"); -// uint32_t duration = info[1]->IntegerValue(ctx).ToChecked(); + V8_CHECK(info[1]->IsNumber(), "duration must be an unsigned integer"); + uint32_t duration = info[1]->IntegerValue(ctx).ToChecked(); -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); + V8Entity *_this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); -// alt::Ref blip = _this->GetHandle().As(); + alt::Ref blip = _this->GetHandle().As(); -// blip->Fade(opacity, duration); -// } + blip->Fade(opacity, duration); +} -// static V8Class v8blip("Blip", "WorldObject", Constructor, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); +extern V8Class v8WorldObject; +extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); -// /* -// let ped = game.playerPedId(); -// let coords = game.getEntityCoords(ped, true); + /* + let ped = game.playerPedId(); + let coords = game.getEntityCoords(ped, true); -// let area = new alt.AreaBlip(coords.x, coords.y, coords.z, 30, 30); -// area.color = 5; -// area.rotation = 0; -// */ + let area = new alt.AreaBlip(coords.x, coords.y, coords.z, 30, 30); + area.color = 5; + area.rotation = 0; + */ -// V8::SetAccessor(isolate, tpl, "sprite", nullptr, &SpriteSetter); -// V8::SetAccessor(isolate, tpl, "scale", nullptr, &ScaleSetter); -// V8::SetAccessor(isolate, tpl, "color", nullptr, &ColorSetter); -// V8::SetAccessor(isolate, tpl, "secondaryColor", nullptr, &SecondaryColorSetter); -// V8::SetAccessor(isolate, tpl, "alpha", nullptr, &AlphaSetter); -// V8::SetAccessor(isolate, tpl, "flashTimer", nullptr, &FlashTimerSetter); -// V8::SetAccessor(isolate, tpl, "flashInterval", nullptr, &FlashIntervalSetter); -// V8::SetAccessor(isolate, tpl, "route", nullptr, &RouteSetter); -// V8::SetAccessor(isolate, tpl, "bright", nullptr, &BrightSetter); -// V8::SetAccessor(isolate, tpl, "number", nullptr, &NumberSetter); -// V8::SetAccessor(isolate, tpl, "showCone", nullptr, &ShowConeSetter); -// V8::SetAccessor(isolate, tpl, "flashes", nullptr, &FlashesSetter); -// V8::SetAccessor(isolate, tpl, "flashesAlternate", nullptr, &FlashesAlternateSetter); -// V8::SetAccessor(isolate, tpl, "shortRange", nullptr, &ShortRangeSetter); -// V8::SetAccessor(isolate, tpl, "priority", nullptr, &PrioritySetter); -// V8::SetAccessor(isolate, tpl, "heading", nullptr, &RotationSetter); -// V8::SetAccessor(isolate, tpl, "gxtName", nullptr, &GxtNameSetter); -// V8::SetAccessor(isolate, tpl, "name", nullptr, &NameSetter); -// V8::SetAccessor(isolate, tpl, "routeColor", nullptr, &RouteColorSetter); -// V8::SetAccessor(isolate, tpl, "pulse", nullptr, &PulseSetter); -// V8::SetAccessor(isolate, tpl, "asMissionCreator", nullptr, &AsMissionCreatorSetter); -// V8::SetAccessor(isolate, tpl, "tickVisible", nullptr, &tickVisibleSetter); -// V8::SetAccessor(isolate, tpl, "headingIndicatorVisible", nullptr, &headingIndicatorVisibleSetter); -// V8::SetAccessor(isolate, tpl, "outlineIndicatorVisible", nullptr, &outlineIndicatorVisibleSetter); -// V8::SetAccessor(isolate, tpl, "friendIndicatorVisible", nullptr, &friendIndicatorVisibleSetter); -// V8::SetAccessor(isolate, tpl, "crewIndicatorVisible", nullptr, &crewIndicatorVisibleSetter); -// V8::SetAccessor(isolate, tpl, "category", nullptr, &categorySetter); -// V8::SetAccessor(isolate, tpl, "highDetail", nullptr, &highDetailSetter); -// V8::SetAccessor(isolate, tpl, "shrinked", nullptr, &shrinkedSetter); - -// V8::SetMethod(isolate, tpl, "fade", &Fade); -// }); - -// static V8Class v8AreaBlip("AreaBlip", "Blip", ConstructorAreaBlip, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); - -// v8::Local proto = tpl->PrototypeTemplate(); -// }); - -// static V8Class v8RadiusBlip("RadiusBlip", "Blip", ConstructorRadiusBlip, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); - -// v8::Local proto = tpl->PrototypeTemplate(); -// }); - -// static V8Class v8PointBlip("PointBlip", "Blip", ConstructorPointBlip, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); - -// v8::Local proto = tpl->PrototypeTemplate(); -// }); - -// static V8Class v8PedBlip("PedBlip", "Blip", ConstructorPedBlip, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); - -// v8::Local proto = tpl->PrototypeTemplate(); -// }); - -// static V8Class v8VehicleBlip("VehicleBlip", "Blip", ConstructorVehicleBlip, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); - -// v8::Local proto = tpl->PrototypeTemplate(); -// }); + V8::SetAccessor(isolate, tpl, "sprite", nullptr, &SpriteSetter); + V8::SetAccessor(isolate, tpl, "scale", nullptr, &ScaleSetter); + V8::SetAccessor(isolate, tpl, "color", nullptr, &ColorSetter); + V8::SetAccessor(isolate, tpl, "secondaryColor", nullptr, &SecondaryColorSetter); + V8::SetAccessor(isolate, tpl, "alpha", nullptr, &AlphaSetter); + V8::SetAccessor(isolate, tpl, "flashTimer", nullptr, &FlashTimerSetter); + V8::SetAccessor(isolate, tpl, "flashInterval", nullptr, &FlashIntervalSetter); + V8::SetAccessor(isolate, tpl, "route", nullptr, &RouteSetter); + V8::SetAccessor(isolate, tpl, "bright", nullptr, &BrightSetter); + V8::SetAccessor(isolate, tpl, "number", nullptr, &NumberSetter); + V8::SetAccessor(isolate, tpl, "showCone", nullptr, &ShowConeSetter); + V8::SetAccessor(isolate, tpl, "flashes", nullptr, &FlashesSetter); + V8::SetAccessor(isolate, tpl, "flashesAlternate", nullptr, &FlashesAlternateSetter); + V8::SetAccessor(isolate, tpl, "shortRange", nullptr, &ShortRangeSetter); + V8::SetAccessor(isolate, tpl, "priority", nullptr, &PrioritySetter); + V8::SetAccessor(isolate, tpl, "heading", nullptr, &RotationSetter); + V8::SetAccessor(isolate, tpl, "gxtName", nullptr, &GxtNameSetter); + V8::SetAccessor(isolate, tpl, "name", nullptr, &NameSetter); + V8::SetAccessor(isolate, tpl, "routeColor", nullptr, &RouteColorSetter); + V8::SetAccessor(isolate, tpl, "pulse", nullptr, &PulseSetter); + V8::SetAccessor(isolate, tpl, "asMissionCreator", nullptr, &AsMissionCreatorSetter); + V8::SetAccessor(isolate, tpl, "tickVisible", nullptr, &tickVisibleSetter); + V8::SetAccessor(isolate, tpl, "headingIndicatorVisible", nullptr, &headingIndicatorVisibleSetter); + V8::SetAccessor(isolate, tpl, "outlineIndicatorVisible", nullptr, &outlineIndicatorVisibleSetter); + V8::SetAccessor(isolate, tpl, "friendIndicatorVisible", nullptr, &friendIndicatorVisibleSetter); + V8::SetAccessor(isolate, tpl, "crewIndicatorVisible", nullptr, &crewIndicatorVisibleSetter); + V8::SetAccessor(isolate, tpl, "category", nullptr, &categorySetter); + V8::SetAccessor(isolate, tpl, "highDetail", nullptr, &highDetailSetter); + V8::SetAccessor(isolate, tpl, "shrinked", nullptr, &shrinkedSetter); + + V8::SetMethod(isolate, tpl, "fade", &Fade); +}); + +extern V8Class v8Blip; +extern V8Class v8AreaBlip("AreaBlip", v8Blip, ConstructorAreaBlip, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + v8::Local proto = tpl->PrototypeTemplate(); +}); + +extern V8Class v8RadiusBlip("RadiusBlip", v8Blip, ConstructorRadiusBlip, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + v8::Local proto = tpl->PrototypeTemplate(); +}); + +extern V8Class v8PointBlip("PointBlip", v8Blip, ConstructorPointBlip, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + v8::Local proto = tpl->PrototypeTemplate(); +}); + +extern V8Class v8PedBlip("PedBlip", v8Blip, ConstructorPedBlip, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + v8::Local proto = tpl->PrototypeTemplate(); +}); + +extern V8Class v8VehicleBlip("VehicleBlip", v8Blip, ConstructorVehicleBlip, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + v8::Local proto = tpl->PrototypeTemplate(); +}); diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index c0e0bdb5..3d534304 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -838,10 +838,10 @@ extern V8Module altModule( v8Player, v8Vehicle, v8WebView, - // v8Blip, - // v8AreaBlip, - // v8RadiusBlip, - // v8PointBlip, + v8Blip, + v8AreaBlip, + v8RadiusBlip, + v8PointBlip, v8HandlingData, v8LocalStorage, // v8MemoryBuffer, From b9e94a9eaaeedd751fdf85599100629ec111fd18 Mon Sep 17 00:00:00 2001 From: Hazard Date: Sat, 7 Nov 2020 04:02:05 +0100 Subject: [PATCH 034/564] Fix Player class --- .gitmodules | 5 +---- src/bindings/Player.cpp | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index de37459f..4ea3e8e6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "deps/cpp-sdk"] - path = deps/cpp-sdk - url = https://github.com/altmp/cpp-sdk.git [submodule "src/helpers"] path = src/helpers - url = https://github.com/altmp/v8-helpers.git + url = https://github.com/altmp/v8-helpers.git \ No newline at end of file diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 9180a10c..6eebac79 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -301,7 +301,7 @@ static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo if (!localPlayer) info.GetReturnValue().Set(v8::Null(isolate)); else - info.GetReturnValue().Set(resource->GetOrCreateEntity(localPlayer.Get(), "Player")->GetJSVal(isolate)); + info.GetReturnValue().Set(resource->GetOrCreateEntity(localPlayer.Get())->GetJSVal(isolate)); } static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) @@ -324,6 +324,7 @@ extern V8Class v8Entity; extern V8Class v8Player("Player", v8Entity, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); + tpl->InstanceTemplate()->SetInternalFieldCount(1); v8::Local proto = tpl->PrototypeTemplate(); V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); From 8b9b62cc8b0259e1eef8b9a3d1739f7bc3d5b43e Mon Sep 17 00:00:00 2001 From: Vektor Date: Sun, 8 Nov 2020 20:53:45 +0100 Subject: [PATCH 035/564] added helper macros --- V8Helpers.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index c220628d..2e846e89 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -262,6 +262,14 @@ namespace V8 double val; \ V8_CHECK(V8::SafeToNumber((v8Val), ctx, val), "Failed to convert value to number") +#define V8_TO_INTEGER(v8Val, val) \ + int64_t val; \ + V8_CHECK(V8::SafeToInteger((v8Val), ctx, val), "Failed to convert value to integer") + +#define V8_TO_STRING(v8Val, val) \ + alt::String val; \ + V8_CHECK(V8::SafeToString((v8Val), isolate, ctx, val), "Failed to convert value to integer") + // idx starts with 1 #define V8_ARG_CHECK_NUMBER(idx) V8_CHECK(info[(idx) - 1]->IsNumber(), "Argument " #idx " must be a number") @@ -306,13 +314,15 @@ namespace V8 #define V8_RETURN_NULL() V8_RETURN(v8::Null(isolate)) #define V8_RETURN_BOOLEAN(val) V8_RETURN(v8::Boolean::New(isolate, (val))) #define V8_RETURN_INTEGER(val) V8_RETURN(v8::Integer::New(isolate, (val))) +#define V8_RETURN_NUMBER(val) V8_RETURN(v8::Number::New(isolate, (val))) #define V8_RETURN_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val), v8::NewStringType::kNormal).ToLocalChecked()) #define V8_RETURN_BASE_OBJECT(baseObjectRef) V8_RETURN(resource->GetBaseObjectOrNull(baseObjectRef)) -#define V8_BIND_BASE_OBJECT(baseObjectRef, error) \ +#define V8_BIND_BASE_OBJECT(baseObjectRef) \ { \ + V8_CHECK(baseObjectRef, "Failed to create base object"); \ auto baseObject = (baseObjectRef); \ - V8_CHECK(!baseObject.IsEmpty(), error); \ + V8_CHECK(!baseObject.IsEmpty(), "Failed to bind base object"); \ resource->BindEntity(info.This(), baseObject.Get()); \ } From c7d69854c9af3b9fdb388235aa9af8c9a33ecd46 Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 11 Nov 2020 06:37:42 +0100 Subject: [PATCH 036/564] Update blips getters (vektor) --- src/bindings/Blip.cpp | 1146 ++++++++++++++++------------------------- src/helpers | 2 +- 2 files changed, 431 insertions(+), 717 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index d316399f..9bdcc462 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -1,926 +1,640 @@ - #include "../CV8Resource.h" -#include "../helpers/V8Class.h" +#include "../helpers/V8Helpers.h" #include "cpp-sdk/script-objects/IBlip.h" -static void Constructor(const v8::FunctionCallbackInfo &info) +static void Constructor(const v8::FunctionCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - + V8_GET_ISOLATE_CONTEXT(); V8_CHECK(info.IsConstructCall(), "Blip constructor is not a function"); - - // xyz as obj - /* - V8_CHECK(info.Length() == 2, "new Blip(...) expects 2 args"); - - V8_CHECK(info[0]->IsObject(), "pos must be an object of {x, y, z}"); - auto pos = info[1]->ToObject(isolate); - double x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x")).ToLocalChecked() - ->NumberValue(ctx).ToChecked(); - double y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y")).ToLocalChecked() - ->NumberValue(ctx).ToChecked(); - double z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z")).ToLocalChecked() - ->NumberValue(ctx).ToChecked(); - - V8_CHECK(info[1]->IsNumber(), "type must be an unsigned integer"); - */ - - /* - let blip = new alt.Blip(0, 0, 72, 11, 50, 50); - blip.rotation = 0; - */ - - // xyz as args - - V8_CHECK(false, "You can't use constructor of abstract class"); + V8_CHECK(false, "You can't use constructor of abstract class"); } -static void ConstructorAreaBlip(const v8::FunctionCallbackInfo &info) +static void ConstructorAreaBlip(const v8::FunctionCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8_CHECK(info.IsConstructCall(), "AreaBlip constructor is not a function"); - - V8_CHECK(info.Length() == 5, "new AreaBlip(...) expects 5 args"); - V8_CHECK(info[0]->IsNumber(), "x must be a number"); - V8_CHECK(info[1]->IsNumber(), "y must be a number"); - V8_CHECK(info[2]->IsNumber(), "z must be a number"); - V8_CHECK(info[3]->IsNumber(), "width must be a number"); - V8_CHECK(info[4]->IsNumber(), "height must be a number"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN(5); + V8_ARG_TO_NUMBER(1, x); + V8_ARG_TO_NUMBER(2, y); + V8_ARG_TO_NUMBER(3, z); + V8_ARG_TO_NUMBER(4, width); + V8_ARG_TO_NUMBER(5, height); - v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); - v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); - v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); - v8::Local width = info[3]->ToNumber(ctx).ToLocalChecked(); - v8::Local height = info[4]->ToNumber(ctx).ToLocalChecked(); - - alt::Ref blip = resource->CreateBlip({x->Value(), y->Value(), z->Value()}, width->Value(), height->Value()); - - V8_CHECK(blip, "Blip creation failed"); - - // static_cast(resource)->AddOwned(blip); - // resource->BindEntity(info.This(), blip.Get()); + alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::Ref blip = res->CreateBlip({ x, y, z }, width, height); + V8_BIND_BASE_OBJECT(blip); } -static void ConstructorRadiusBlip(const v8::FunctionCallbackInfo &info) +static void ConstructorRadiusBlip(const v8::FunctionCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8_CHECK(info.IsConstructCall(), "RadiusBlip constructor is not a function"); - - V8_CHECK(info.Length() == 4, "new RadiusBlip(...) expects 4 args"); - V8_CHECK(info[0]->IsNumber(), "x must be a number"); - V8_CHECK(info[1]->IsNumber(), "y must be a number"); - V8_CHECK(info[2]->IsNumber(), "z must be a number"); - V8_CHECK(info[3]->IsNumber(), "radius must be a number"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN(4); + V8_ARG_TO_NUMBER(1, x); + V8_ARG_TO_NUMBER(2, y); + V8_ARG_TO_NUMBER(3, z); + V8_ARG_TO_NUMBER(4, radius); - v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); - v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); - v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); - v8::Local radius = info[3]->ToNumber(ctx).ToLocalChecked(); - alt::Ref blip = resource->CreateBlip({x->Value(), y->Value(), z->Value()}, radius->Value()); - - V8_CHECK(blip, "Blip creation failed"); - - // static_cast(resource)->AddOwned(blip); - // resource->BindEntity(info.This(), blip.Get()); + alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::Ref blip = res->CreateBlip({ x, y, z }, radius); + V8_BIND_BASE_OBJECT(blip); } -static void ConstructorPointBlip(const v8::FunctionCallbackInfo &info) +static void ConstructorPointBlip(const v8::FunctionCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8_CHECK(info.IsConstructCall(), "PointBlip constructor is not a function"); - - V8_CHECK(info.Length() == 3, "new PointBlip(...) expects 3 args"); - V8_CHECK(info[0]->IsNumber(), "x must be a number"); - V8_CHECK(info[1]->IsNumber(), "y must be a number"); - V8_CHECK(info[2]->IsNumber(), "z must be a number"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN(3); + V8_ARG_TO_NUMBER(1, x); + V8_ARG_TO_NUMBER(2, y); + V8_ARG_TO_NUMBER(3, z); - v8::Local x = info[0]->ToNumber(ctx).ToLocalChecked(); - v8::Local y = info[1]->ToNumber(ctx).ToLocalChecked(); - v8::Local z = info[2]->ToNumber(ctx).ToLocalChecked(); - alt::Ref blip = resource->CreateBlip(alt::IBlip::BlipType::DESTINATION, {x->Value(), y->Value(), z->Value()}); - - V8_CHECK(blip, "Blip creation failed"); - - // static_cast(resource)->AddOwned(blip); - // resource->BindEntity(info.This(), blip.Get()); + alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::Ref blip = res->CreateBlip(alt::IBlip::BlipType::DESTINATION, { x, y, z }); + V8_BIND_BASE_OBJECT(blip); } -static void ConstructorPedBlip(const v8::FunctionCallbackInfo &info) +static void ConstructorPedBlip(const v8::FunctionCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, pedId); - V8_CHECK(info.IsConstructCall(), "PedBlip constructor is not a function"); - - V8_CHECK(info.Length() == 1, "new PedBlip(...) expects 1 arg"); - V8_CHECK(info[0]->IsNumber(), "pedId must be a number"); - - uint32_t pedId = info[0]->IntegerValue(ctx).ToChecked(); - alt::Ref blip = resource->CreateBlip(alt::IBlip::BlipType::PED, pedId); + alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::Ref blip = res->CreateBlip(alt::IBlip::BlipType::PED, pedId); + V8_BIND_BASE_OBJECT(blip); +} - V8_CHECK(blip, "Blip creation failed"); +static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, vehicleId); - // static_cast(resource)->AddOwned(blip); - // resource->BindEntity(info.This(), blip.Get()); + alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::Ref blip = res->CreateBlip(alt::IBlip::BlipType::VEHICLE, vehicleId); + V8_BIND_BASE_OBJECT(blip); } -static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo &info) +static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_NUMBER(blip->GetScale()); +} - auto resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); +static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_TO_NUMBER(value, val); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + blip->SetScale(val); +} - V8_CHECK(info.IsConstructCall(), "VehicleBlip constructor is not a function"); +static void SizeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_CHECK(info.Length() == 1, "new VehicleBlip(...) expects 1 arg"); - V8_CHECK(info[0]->IsNumber(), "vehicleId must be a number"); + V8_CHECK(value->IsObject(), "size must be an object"); - uint32_t vehicleId = info[0]->IntegerValue(ctx).ToChecked(); - alt::Ref blip = resource->CreateBlip(alt::IBlip::BlipType::VEHICLE, vehicleId); + v8::Local pos = value.As(); - V8_CHECK(blip, "Blip creation failed"); + v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked(); + v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked(); - // static_cast(resource)->AddOwned(blip); - // resource->BindEntity(info.This(), blip.Get()); + blip->SetScaleXY( + x->ToNumber(ctx).ToLocalChecked()->Value(), + y->ToNumber(ctx).ToLocalChecked()->Value() + ); } -//static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetScale())); -//} - -static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void SizeGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_CHECK(value->IsNumber(), "scale must be a number"); - auto val = value->NumberValue(ctx).ToChecked(); + alt::Vector2f pos = blip->GetScaleXY(); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + v8::Local obj = v8::Object::New(isolate); - alt::Ref blip = _this->GetHandle().As(); + obj->Set(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked(), v8::Number::New(isolate, pos[0])); + obj->Set(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked(), v8::Number::New(isolate, pos[1])); - blip->SetScale(val); + V8_RETURN(obj); } -/** - * Scale XY - * */ -//static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// auto scale = blip->GetScaleXY(); -// -// -// -// info.GetReturnValue().Set(v8::Number::New(isolate, )); -//} - -/** - * Scale XY - * */ -//static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// V8_CHECK(value->IsNumber(), "scale must be a number"); -// double val = value->NumberValue(ctx).ToChecked(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// blip->SetScale(val); -//} - -//static void SpriteGetter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void SpriteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void SpriteGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsNumber(), "sprite must be an integer"); - int sprite = value->IntegerValue(ctx).ToChecked(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_INTEGER(blip->GetSprite()); +} - alt::Ref blip = _this->GetHandle().As(); +static void SpriteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_INTEGER(value, val); + blip->SetSprite(val); +} - blip->SetSprite(sprite); +static void ColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_INTEGER(blip->GetColor()); } -//static void ColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void ColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) -{ - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsNumber(), "color must be an integer"); - int val = value->IntegerValue(ctx).ToChecked(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref blip = _this->GetHandle().As(); +static void ColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_INTEGER(value, val); blip->SetColor(val); } -//static void SecondaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void SecondaryColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void SecondaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsNumber(), "secondaryColor must be an unsigned integer"); - auto val = value->IntegerValue(ctx).ToChecked(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_INTEGER(blip->GetSecondaryColor()); +} - alt::Ref blip = _this->GetHandle().As(); +static void SecondaryColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_INTEGER(value, val); blip->SetSecondaryColor(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void AlphaSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void AlphaGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsNumber(), "alpha must be an integer"); - auto val = value->IntegerValue(ctx).ToChecked(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_INTEGER(blip->GetAlpha()); +} - alt::Ref blip = _this->GetHandle().As(); +static void AlphaSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_INTEGER(value, val); blip->SetAlpha(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void FlashTimerSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void FlashTimerGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsNumber(), "flashTimer must be an integer"); - int val = value->IntegerValue(ctx).ToChecked(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_INTEGER(blip->GetFlashTimer()); +} - alt::Ref blip = _this->GetHandle().As(); +static void FlashTimerSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_INTEGER(value, val); blip->SetFlashTimer(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void FlashIntervalSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void FlashIntervalGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsNumber(), "flashInterval must be an integer"); - int val = value->IntegerValue(ctx).ToChecked(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_INTEGER(blip->GetFlashInterval()); +} - alt::Ref blip = _this->GetHandle().As(); +static void FlashIntervalSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_INTEGER(value, val); blip->SetFlashInterval(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void FriendlySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void FriendlyGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetAsFriendly()); +} - alt::Ref blip = _this->GetHandle().As(); +static void FriendlySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetAsFriendly(val); } -//static void RouteGetter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void RouteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void RouteGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetRoute()); +} - alt::Ref blip = _this->GetHandle().As(); +static void RouteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetRoute(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void BrightSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void BrightGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetBright()); +} - alt::Ref blip = _this->GetHandle().As(); +static void BrightSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetBright(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void NumberSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void NumberGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsNumber(), "number must be an integer"); - auto val = value->IntegerValue(ctx).ToChecked(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_INTEGER(blip->GetNumber()); +} - alt::Ref blip = _this->GetHandle().As(); +static void NumberSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_INTEGER(value, val); blip->SetNumber(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void ShowConeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void ShowConeGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetShowCone()); +} - alt::Ref blip = _this->GetHandle().As(); +static void ShowConeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetShowCone(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void FlashesSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void FlashesGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetFlashes()); +} - alt::Ref blip = _this->GetHandle().As(); +static void FlashesSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetFlashes(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void FlashesAlternateSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void FlashesAlternateGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetFlashesAlternate()); +} - alt::Ref blip = _this->GetHandle().As(); +static void FlashesAlternateSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetFlashesAlternate(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void ShortRangeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void ShortRangeGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetAsShortRange()); +} - alt::Ref blip = _this->GetHandle().As(); +static void ShortRangeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetAsShortRange(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void PrioritySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void PriorityGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsNumber(), "priority must be an integer"); - auto val = value->IntegerValue(ctx).ToChecked(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_INTEGER(blip->GetPriority()); +} - alt::Ref blip = _this->GetHandle().As(); +static void PrioritySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_INTEGER(value, val); blip->SetPriority(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->GetSprite())); -//} - -static void RotationSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void RotationGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsNumber(), "rotation must be a number"); - auto val = value->NumberValue(ctx).ToChecked(); - - Log::Debug << "nextRotation = " << val << Log::Endl; - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_NUMBER(blip->GetRotation()); +} - alt::Ref blip = _this->GetHandle().As(); +static void RotationSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_NUMBER(value, val); blip->SetRotation(val); } -//static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) -//{ -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); -// -// alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); -// -// info.GetReturnValue().Set(v8::Number::New(isolate, blip->())); -//} - -static void GxtNameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void GxtNameGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsString(), "gxtName must be a string"); - auto val = *v8::String::Utf8Value(info.GetIsolate(), value->ToString(ctx).ToLocalChecked()); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref blip = _this->GetHandle().As(); - blip->SetGxtName(val); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_STRING(blip->GetGxtName()); } -static void NameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void GxtNameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsString(), "name must be a string"); - auto val = *v8::String::Utf8Value(info.GetIsolate(), value->ToString(ctx).ToLocalChecked()); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref blip = _this->GetHandle().As(); - blip->SetName(val); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_STRING(value, val); + blip->SetGxtName(val.CStr()); } -/* -static void Getter(v8::Local, const v8::PropertyCallbackInfo& info) +static void NameGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - alt::Ref blip = (alt::Ref)info.This()->GetInternalField(0).As()->Value(); - - auto ret = v8::Number::New(isolate, blip->GETTER())); - info.GetReturnValue().Set(ret); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_STRING(blip->GetName()); } -*/ -static void RouteColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void NameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsNumber(), "routeColor must be unsigned integer"); - auto val = value->IntegerValue(ctx).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_STRING(value, val); + blip->SetName(val.CStr()); +} - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); +static void RouteColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_INTEGER(blip->GetRouteColor()); +} - alt::Ref blip = _this->GetHandle().As(); +static void RouteColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_INTEGER(value, val); blip->SetRouteColor(val); } -static void PulseSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void PulseGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetPulse()); +} - alt::Ref blip = _this->GetHandle().As(); +static void PulseSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetPulse(val); } -static void AsMissionCreatorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void AsMissionCreatorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetAsMissionCreator()); +} - alt::Ref blip = _this->GetHandle().As(); +static void AsMissionCreatorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetAsMissionCreator(val); } -static void tickVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void TickVisibleGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetTickVisible()); +} - alt::Ref blip = _this->GetHandle().As(); +static void TickVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetTickVisible(val); } -static void headingIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void HeadingIndicatorVisibleGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetHeadingIndicatorVisible()); +} - alt::Ref blip = _this->GetHandle().As(); +static void HeadingIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetHeadingIndicatorVisible(val); } -static void outlineIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void OutlineIndicatorVisibleGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetOutlineIndicatorVisible()); +} - alt::Ref blip = _this->GetHandle().As(); +static void OutlineIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetOutlineIndicatorVisible(val); } -static void friendIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void FriendIndicatorVisibleGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetFriendIndicatorVisible()); +} - alt::Ref blip = _this->GetHandle().As(); +static void FriendIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetFriendIndicatorVisible(val); } -static void crewIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void CrewIndicatorVisibleGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetCrewIndicatorVisible()); +} - alt::Ref blip = _this->GetHandle().As(); +static void CrewIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetCrewIndicatorVisible(val); } -static void categorySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void CategoryGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(value->IsNumber(), "category must be integer"); - auto val = value->IntegerValue(ctx).ToChecked(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_INTEGER(blip->GetCategory()); +} - alt::Ref blip = _this->GetHandle().As(); +static void CategorySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_INTEGER(value, val); blip->SetCategory(val); } -static void highDetailSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void HighDetailGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetAsHighDetail()); +} - alt::Ref blip = _this->GetHandle().As(); +static void HighDetailSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetAsHighDetail(val); } -static void shrinkedSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void ShrinkedGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = value->ToBoolean(isolate)->Value(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_BOOLEAN(blip->GetShrinked()); +} - alt::Ref blip = _this->GetHandle().As(); +static void ShrinkedSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_BOOLEAN(value, val); blip->SetShrinked(val); } -static void Fade(const v8::FunctionCallbackInfo &info) +static void Fade(const v8::FunctionCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 2, "2 args expected"); - - V8_CHECK(info[0]->IsNumber(), "opacity must be an unsigned integer"); - uint32_t opacity = info[0]->IntegerValue(ctx).ToChecked(); - - V8_CHECK(info[1]->IsNumber(), "duration must be an unsigned integer"); - uint32_t duration = info[1]->IntegerValue(ctx).ToChecked(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref blip = _this->GetHandle().As(); - + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_INTEGER(1, opacity); + V8_ARG_TO_INTEGER(2, duration); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); blip->Fade(opacity, duration); } extern V8Class v8WorldObject; -extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - /* - let ped = game.playerPedId(); - let coords = game.getEntityCoords(ped, true); - - let area = new alt.AreaBlip(coords.x, coords.y, coords.z, 30, 30); - area.color = 5; - area.rotation = 0; - */ - - V8::SetAccessor(isolate, tpl, "sprite", nullptr, &SpriteSetter); - V8::SetAccessor(isolate, tpl, "scale", nullptr, &ScaleSetter); - V8::SetAccessor(isolate, tpl, "color", nullptr, &ColorSetter); - V8::SetAccessor(isolate, tpl, "secondaryColor", nullptr, &SecondaryColorSetter); - V8::SetAccessor(isolate, tpl, "alpha", nullptr, &AlphaSetter); - V8::SetAccessor(isolate, tpl, "flashTimer", nullptr, &FlashTimerSetter); - V8::SetAccessor(isolate, tpl, "flashInterval", nullptr, &FlashIntervalSetter); - V8::SetAccessor(isolate, tpl, "route", nullptr, &RouteSetter); - V8::SetAccessor(isolate, tpl, "bright", nullptr, &BrightSetter); - V8::SetAccessor(isolate, tpl, "number", nullptr, &NumberSetter); - V8::SetAccessor(isolate, tpl, "showCone", nullptr, &ShowConeSetter); - V8::SetAccessor(isolate, tpl, "flashes", nullptr, &FlashesSetter); - V8::SetAccessor(isolate, tpl, "flashesAlternate", nullptr, &FlashesAlternateSetter); - V8::SetAccessor(isolate, tpl, "shortRange", nullptr, &ShortRangeSetter); - V8::SetAccessor(isolate, tpl, "priority", nullptr, &PrioritySetter); - V8::SetAccessor(isolate, tpl, "heading", nullptr, &RotationSetter); - V8::SetAccessor(isolate, tpl, "gxtName", nullptr, &GxtNameSetter); - V8::SetAccessor(isolate, tpl, "name", nullptr, &NameSetter); - V8::SetAccessor(isolate, tpl, "routeColor", nullptr, &RouteColorSetter); - V8::SetAccessor(isolate, tpl, "pulse", nullptr, &PulseSetter); - V8::SetAccessor(isolate, tpl, "asMissionCreator", nullptr, &AsMissionCreatorSetter); - V8::SetAccessor(isolate, tpl, "tickVisible", nullptr, &tickVisibleSetter); - V8::SetAccessor(isolate, tpl, "headingIndicatorVisible", nullptr, &headingIndicatorVisibleSetter); - V8::SetAccessor(isolate, tpl, "outlineIndicatorVisible", nullptr, &outlineIndicatorVisibleSetter); - V8::SetAccessor(isolate, tpl, "friendIndicatorVisible", nullptr, &friendIndicatorVisibleSetter); - V8::SetAccessor(isolate, tpl, "crewIndicatorVisible", nullptr, &crewIndicatorVisibleSetter); - V8::SetAccessor(isolate, tpl, "category", nullptr, &categorySetter); - V8::SetAccessor(isolate, tpl, "highDetail", nullptr, &highDetailSetter); - V8::SetAccessor(isolate, tpl, "shrinked", nullptr, &shrinkedSetter); - - V8::SetMethod(isolate, tpl, "fade", &Fade); +extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local tpl){ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8::SetAccessor(isolate, tpl, "sprite", &SpriteGetter, &SpriteSetter); + V8::SetAccessor(isolate, tpl, "scale", &ScaleGetter, &ScaleSetter); + V8::SetAccessor(isolate, tpl, "size", &SizeGetter, &SizeSetter); + V8::SetAccessor(isolate, tpl, "color", &ColorGetter, &ColorSetter); + V8::SetAccessor(isolate, tpl, "secondaryColor", &SecondaryColorGetter, &SecondaryColorSetter); + V8::SetAccessor(isolate, tpl, "alpha", &AlphaGetter, &AlphaSetter); + V8::SetAccessor(isolate, tpl, "flashTimer", &FlashTimerGetter, &FlashTimerSetter); + V8::SetAccessor(isolate, tpl, "flashInterval", &FlashIntervalGetter, &FlashIntervalSetter); + V8::SetAccessor(isolate, tpl, "route", &RouteGetter, &RouteSetter); + V8::SetAccessor(isolate, tpl, "bright", &BrightGetter, &BrightSetter); + V8::SetAccessor(isolate, tpl, "number", &NumberGetter, &NumberSetter); + V8::SetAccessor(isolate, tpl, "showCone", &ShowConeGetter, &ShowConeSetter); + V8::SetAccessor(isolate, tpl, "flashes", &FlashesGetter, &FlashesSetter); + V8::SetAccessor(isolate, tpl, "flashesAlternate", &FlashesAlternateGetter, &FlashesAlternateSetter); + V8::SetAccessor(isolate, tpl, "shortRange", &ShortRangeGetter, &ShortRangeSetter); + V8::SetAccessor(isolate, tpl, "priority", &PriorityGetter, &PrioritySetter); + V8::SetAccessor(isolate, tpl, "heading", &RotationGetter, &RotationSetter); + V8::SetAccessor(isolate, tpl, "gxtName", &GxtNameGetter, &GxtNameSetter); + V8::SetAccessor(isolate, tpl, "name", &NameGetter, &NameSetter); + V8::SetAccessor(isolate, tpl, "routeColor", &RouteColorGetter, &RouteColorSetter); + V8::SetAccessor(isolate, tpl, "pulse", &PulseGetter, &PulseSetter); + V8::SetAccessor(isolate, tpl, "asMissionCreator", &AsMissionCreatorGetter, &AsMissionCreatorSetter); + V8::SetAccessor(isolate, tpl, "tickVisible", &TickVisibleGetter, &TickVisibleSetter); + V8::SetAccessor(isolate, tpl, "headingIndicatorVisible", &HeadingIndicatorVisibleGetter, &HeadingIndicatorVisibleSetter); + V8::SetAccessor(isolate, tpl, "outlineIndicatorVisible", &OutlineIndicatorVisibleGetter, &OutlineIndicatorVisibleSetter); + V8::SetAccessor(isolate, tpl, "friendIndicatorVisible", &FriendIndicatorVisibleGetter, &FriendIndicatorVisibleSetter); + V8::SetAccessor(isolate, tpl, "crewIndicatorVisible", &CrewIndicatorVisibleGetter, &CrewIndicatorVisibleSetter); + V8::SetAccessor(isolate, tpl, "category", &CategoryGetter, &CategorySetter); + V8::SetAccessor(isolate, tpl, "highDetail", &HighDetailGetter, &HighDetailSetter); + V8::SetAccessor(isolate, tpl, "shrinked", &ShrinkedGetter, &ShrinkedSetter); + + V8::SetMethod(isolate, tpl, "fade", &Fade); }); -extern V8Class v8Blip; extern V8Class v8AreaBlip("AreaBlip", v8Blip, ConstructorAreaBlip, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local proto = tpl->PrototypeTemplate(); + v8::Local proto = tpl->PrototypeTemplate(); }); extern V8Class v8RadiusBlip("RadiusBlip", v8Blip, ConstructorRadiusBlip, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local proto = tpl->PrototypeTemplate(); + v8::Local proto = tpl->PrototypeTemplate(); }); extern V8Class v8PointBlip("PointBlip", v8Blip, ConstructorPointBlip, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local proto = tpl->PrototypeTemplate(); + v8::Local proto = tpl->PrototypeTemplate(); }); extern V8Class v8PedBlip("PedBlip", v8Blip, ConstructorPedBlip, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local proto = tpl->PrototypeTemplate(); + v8::Local proto = tpl->PrototypeTemplate(); }); extern V8Class v8VehicleBlip("VehicleBlip", v8Blip, ConstructorVehicleBlip, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local proto = tpl->PrototypeTemplate(); + v8::Local proto = tpl->PrototypeTemplate(); }); diff --git a/src/helpers b/src/helpers index 7549089c..c951c317 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 7549089c0d0d82338fbc620ff36ff0af38d2adde +Subproject commit c951c317b0541dc4215aad88a51b7bab64116b15 From 7721cdaea5833502d55afb4b098845323cb6a2ea Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 11 Nov 2020 06:58:01 +0100 Subject: [PATCH 037/564] Set every base object's internal field count to 1 --- bindings/BaseObject.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bindings/BaseObject.cpp b/bindings/BaseObject.cpp index 068d0f38..39a56535 100644 --- a/bindings/BaseObject.cpp +++ b/bindings/BaseObject.cpp @@ -128,6 +128,8 @@ static void Destroy(const v8::FunctionCallbackInfo &info) extern V8Class v8BaseObject("BaseObject", [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + V8::SetAccessor(isolate, tpl, "type", &TypeGetter); V8::SetAccessor(isolate, tpl, "valid", &ValidGetter); From 3aad7907cbaf8930a3504e9e7ab6978872e1d8fa Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 11 Nov 2020 06:58:25 +0100 Subject: [PATCH 038/564] Set every base object's internal field count to 1 --- src/bindings/Player.cpp | 1 - src/helpers | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 6eebac79..4047ab7d 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -324,7 +324,6 @@ extern V8Class v8Entity; extern V8Class v8Player("Player", v8Entity, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); - tpl->InstanceTemplate()->SetInternalFieldCount(1); v8::Local proto = tpl->PrototypeTemplate(); V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); diff --git a/src/helpers b/src/helpers index c951c317..7721cdae 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit c951c317b0541dc4215aad88a51b7bab64116b15 +Subproject commit 7721cdaea5833502d55afb4b098845323cb6a2ea From 3d5ef8988ccf71145cfaf040b0ea9596b8cd4ead Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 11 Nov 2020 07:16:46 +0100 Subject: [PATCH 039/564] Inherit internal field count from parent classes --- V8Class.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/V8Class.h b/V8Class.h index c2bd5767..6e3331e4 100644 --- a/V8Class.h +++ b/V8Class.h @@ -109,7 +109,14 @@ class V8Class if (parent) { parent->Load(isolate); - _tpl->Inherit(parent->tpl.Get(isolate)); + auto parenttpl = parent->tpl.Get(isolate); + _tpl->Inherit(parenttpl); + + // if parent has more internal fields, + // set the current internal field count to the parent's count + auto parentInternalFieldCount = parenttpl->InstanceTemplate()->InternalFieldCount(); + if(parentInternalFieldCount > _tpl->InstanceTemplate()->InternalFieldCount()) + _tpl->InstanceTemplate()->SetInternalFieldCount(parentInternalFieldCount); } if (!tpl.IsEmpty()) From 60bfb50e9df00f24405f67d42c5b6fe7c4ff51a2 Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 11 Nov 2020 07:20:48 +0100 Subject: [PATCH 040/564] Update helpers --- src/CV8Resource.cpp | 2 +- src/helpers | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 6eb2659a..9212c0d1 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -84,7 +84,7 @@ bool CV8ResourceImpl::Start() pkg->ReadFile(file, src.GetData(), src.GetSize()); pkg->CloseFile(file); - Log::Info << "[V8] Starting script" << path; + Log::Info << "[V8] Starting script" << path << Log::Endl; v8::Local sourceCode = v8::String::NewFromUtf8(isolate, src.GetData(), v8::NewStringType::kNormal, src.GetSize()).ToLocalChecked(); diff --git a/src/helpers b/src/helpers index 7721cdae..3d5ef898 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 7721cdaea5833502d55afb4b098845323cb6a2ea +Subproject commit 3d5ef8988ccf71145cfaf040b0ea9596b8cd4ead From a5f143c06149c6c5456d2ea759f15a075fc3795c Mon Sep 17 00:00:00 2001 From: 7Hazard Date: Wed, 11 Nov 2020 07:28:08 +0100 Subject: [PATCH 041/564] Update README.md --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d206a899..13aceaf1 100644 --- a/README.md +++ b/README.md @@ -1 +1,12 @@ -altv-client-js +Official clientside JavaScript runtime for alt:V + +To generate: +`cmake . -BBUILD` + +To build: +`cmake --build BUILD` + +To test: +Place `altv-client-js.dll` into alt:V client folder (same folder as altv.exe and altv-client.dll) + +All contributions are appreciated. From 310430e078526fc655d1798fdc3f9912421317a3 Mon Sep 17 00:00:00 2001 From: 7Hazard Date: Wed, 11 Nov 2020 07:31:36 +0100 Subject: [PATCH 042/564] Update README.md --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 13aceaf1..b38b87a0 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ -Official clientside JavaScript runtime for alt:V +# Official clientside JavaScript runtime for alt:V -To generate: +## To generate: `cmake . -BBUILD` -To build: +## To build: `cmake --build BUILD` -To test: +## To test: +Get dev branch of alt:V client (download from https://altv.mp or change branch in `altv.cfg`) Place `altv-client-js.dll` into alt:V client folder (same folder as altv.exe and altv-client.dll) +Set `debug: true` in `altv.cfg` All contributions are appreciated. From c118acdbd847171e7a9329326d166dd87526a69c Mon Sep 17 00:00:00 2001 From: 7Hazard Date: Wed, 11 Nov 2020 07:34:09 +0100 Subject: [PATCH 043/564] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b38b87a0..b7386f68 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,12 @@ ## To build: `cmake --build BUILD` +Built `altv-client-js.dll` is now inside `BUILD/Debug` (if build is successful) ## To test: Get dev branch of alt:V client (download from https://altv.mp or change branch in `altv.cfg`) Place `altv-client-js.dll` into alt:V client folder (same folder as altv.exe and altv-client.dll) Set `debug: true` in `altv.cfg` -All contributions are appreciated. + +### All contributions are appreciated. From f6aa6c9c7091f7cd7187aede571dc9a0e8d998e5 Mon Sep 17 00:00:00 2001 From: Fabian Terhorst Date: Wed, 11 Nov 2020 18:28:05 +0100 Subject: [PATCH 044/564] Fix cursor funcs --- src/bindings/Main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 3d534304..66642eaf 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -859,6 +859,9 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "toggleGameControls", &ToggleGameControls); V8Helpers::RegisterFunc(exports, "toggleVoiceControls", &ToggleVoiceControls); V8Helpers::RegisterFunc(exports, "showCursor", &ShowCursor); + V8Helpers::RegisterFunc(exports, "getCursorPos", &CursorPosGetter); + V8Helpers::RegisterFunc(exports, "setCursorPos", &CursorPosSetter); + V8Helpers::RegisterFunc(exports, "toggleVoiceControls", &ToggleVoiceControls); V8Helpers::RegisterFunc(exports, "isMenuOpen", &IsMenuOpen); V8Helpers::RegisterFunc(exports, "isConsoleOpen", &IsConsoleOpen); //V8Helpers::RegisterFunc(exports, "drawRect2D", &DrawRect2D); From 5c233670edbdeef47ee6c5b97f2850c76fc69275 Mon Sep 17 00:00:00 2001 From: Fabian Terhorst Date: Wed, 11 Nov 2020 18:28:31 +0100 Subject: [PATCH 045/564] Update Main.cpp --- src/bindings/Main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 66642eaf..57a57fb3 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -861,7 +861,6 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "showCursor", &ShowCursor); V8Helpers::RegisterFunc(exports, "getCursorPos", &CursorPosGetter); V8Helpers::RegisterFunc(exports, "setCursorPos", &CursorPosSetter); - V8Helpers::RegisterFunc(exports, "toggleVoiceControls", &ToggleVoiceControls); V8Helpers::RegisterFunc(exports, "isMenuOpen", &IsMenuOpen); V8Helpers::RegisterFunc(exports, "isConsoleOpen", &IsConsoleOpen); //V8Helpers::RegisterFunc(exports, "drawRect2D", &DrawRect2D); From e0e7b2b8e1ee390b7537ffcd8b729f108077298e Mon Sep 17 00:00:00 2001 From: Fabian Terhorst Date: Wed, 11 Nov 2020 18:30:53 +0100 Subject: [PATCH 046/564] Update Main.cpp --- src/bindings/Main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 57a57fb3..c59d4e7e 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -143,7 +143,7 @@ static void ShowCursor(const v8::FunctionCallbackInfo &info) } } -static void CursorPosGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +static void CursorPosGetter(const v8::PropertyCallbackInfo &info) { v8::Isolate *isolate = info.GetIsolate(); auto ctx = isolate->GetEnteredContext(); @@ -158,7 +158,7 @@ static void CursorPosGetter(v8::Local name, const v8::PropertyCallback info.GetReturnValue().Set(obj); } -static void CursorPosSetter(v8::Local name, v8::Local val, const v8::PropertyCallbackInfo &info) +static void CursorPosSetter(v8::Local val, const v8::PropertyCallbackInfo &info) { v8::Isolate *isolate = info.GetIsolate(); auto ctx = isolate->GetEnteredContext(); From 6fdaffb01944af0f2616f86cc9a3d6d21f9ed379 Mon Sep 17 00:00:00 2001 From: 7Hazard Date: Wed, 11 Nov 2020 23:07:24 +0100 Subject: [PATCH 047/564] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b7386f68..23cefc77 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ `cmake . -BBUILD` ## To build: -`cmake --build BUILD` -Built `altv-client-js.dll` is now inside `BUILD/Debug` (if build is successful) +`cmake --build BUILD --config Release` +Built `altv-client-js.dll` is now inside `BUILD/Release` (if build is successful) ## To test: Get dev branch of alt:V client (download from https://altv.mp or change branch in `altv.cfg`) From dece4337b18e714e9c8aa65856b8af5db49626a1 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 12 Nov 2020 00:36:04 +0100 Subject: [PATCH 048/564] Fixed getCursorPos and setCursorPos --- src/bindings/Main.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index c59d4e7e..19ad130c 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -143,7 +143,7 @@ static void ShowCursor(const v8::FunctionCallbackInfo &info) } } -static void CursorPosGetter(const v8::PropertyCallbackInfo &info) +static void GetCursorPos(const v8::FunctionCallbackInfo &info) { v8::Isolate *isolate = info.GetIsolate(); auto ctx = isolate->GetEnteredContext(); @@ -158,11 +158,12 @@ static void CursorPosGetter(const v8::PropertyCallbackInfo &info) info.GetReturnValue().Set(obj); } -static void CursorPosSetter(v8::Local val, const v8::PropertyCallbackInfo &info) +static void SetCursorPos(const v8::FunctionCallbackInfo &info) { v8::Isolate *isolate = info.GetIsolate(); auto ctx = isolate->GetEnteredContext(); + auto val = info[0]; V8_CHECK(val->IsObject(), "cursorPos must be a object"); v8::Local x = val.As()->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked(); @@ -859,8 +860,9 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "toggleGameControls", &ToggleGameControls); V8Helpers::RegisterFunc(exports, "toggleVoiceControls", &ToggleVoiceControls); V8Helpers::RegisterFunc(exports, "showCursor", &ShowCursor); - V8Helpers::RegisterFunc(exports, "getCursorPos", &CursorPosGetter); - V8Helpers::RegisterFunc(exports, "setCursorPos", &CursorPosSetter); + + V8Helpers::RegisterFunc(exports, "getCursorPos", &GetCursorPos); + V8Helpers::RegisterFunc(exports, "setCursorPos", &SetCursorPos); V8Helpers::RegisterFunc(exports, "isMenuOpen", &IsMenuOpen); V8Helpers::RegisterFunc(exports, "isConsoleOpen", &IsConsoleOpen); //V8Helpers::RegisterFunc(exports, "drawRect2D", &DrawRect2D); From 30ff6455c96c6740e1733a0f69d52a5fb9ecdbeb Mon Sep 17 00:00:00 2001 From: Vektor Date: Thu, 12 Nov 2020 03:56:44 +0100 Subject: [PATCH 049/564] removed blip scale (it's same as size) added blip.display property --- src/bindings/Blip.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index 9bdcc462..8d233bde 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -78,21 +78,6 @@ static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo& in V8_BIND_BASE_OBJECT(blip); } -static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_NUMBER(blip->GetScale()); -} - -static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_TO_NUMBER(value, val); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - blip->SetScale(val); -} - static void SizeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -273,7 +258,22 @@ static void NumberSetter(v8::Local property, v8::Local va V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); V8_TO_INTEGER(value, val); - blip->SetNumber(val); + blip->SetNumber(val); +} + +static void DisplayGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_INTEGER(blip->GetDisplay()); +} + +static void DisplaySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_INTEGER(value, val); + blip->SetDisplay(val); } static void ShowConeGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -576,7 +576,6 @@ extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local Date: Thu, 12 Nov 2020 06:26:24 +0100 Subject: [PATCH 050/564] Fix client specific code --- V8Entity.h | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/V8Entity.h b/V8Entity.h index c10b624d..0b819b26 100644 --- a/V8Entity.h +++ b/V8Entity.h @@ -43,34 +43,39 @@ class V8Entity return static_cast(i.As()->Value()); } - static V8Class *GetClass(alt::Ref handle) - { - extern V8Class v8Player, v8Vehicle, v8Blip, v8WebView, v8VoiceChannel, v8Colshape, v8Checkpoint; + static V8Class* GetClass(alt::Ref handle) + { + extern V8Class v8Player, v8Vehicle, v8Blip; +#ifdef ALT_SERVER_API + extern V8Class v8VoiceChannel, v8Colshape, v8Checkpoint; +#else + extern V8Class v8WebView; +#endif - if (!handle) - return nullptr; + if (!handle) + return nullptr; - switch (handle->GetType()) - { - case alt::IBaseObject::Type::PLAYER: - return &v8Player; - case alt::IBaseObject::Type::VEHICLE: - return &v8Vehicle; + switch (handle->GetType()) + { + case alt::IBaseObject::Type::PLAYER: + return &v8Player; + case alt::IBaseObject::Type::VEHICLE: + return &v8Vehicle; #ifdef ALT_SERVER_API - case alt::IBaseObject::Type::COLSHAPE: - return &v8Colshape; - case alt::IBaseObject::Type::CHECKPOINT: - return &v8Checkpoint; - case alt::IBaseObject::Type::VOICE_CHANNEL: - return &v8VoiceChannel; + case alt::IBaseObject::Type::COLSHAPE: + return &v8Colshape; + case alt::IBaseObject::Type::CHECKPOINT: + return &v8Checkpoint; + case alt::IBaseObject::Type::VOICE_CHANNEL: + return &v8VoiceChannel; + case alt::IBaseObject::Type::BLIP: + return &v8Blip; #else - // case alt::IBaseObject::Type::BLIP: - // return &v8Blip; - case alt::IBaseObject::Type::WEBVIEW: - return &v8WebView; + case alt::IBaseObject::Type::WEBVIEW: + return &v8WebView; #endif - } + } - return nullptr; - } + return nullptr; + } }; \ No newline at end of file From a7544dbeb312e689e6cbf599cd8975038e5905a1 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 12 Nov 2020 06:26:59 +0100 Subject: [PATCH 051/564] Fix --- V8Entity.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/V8Entity.h b/V8Entity.h index 0b819b26..ec149758 100644 --- a/V8Entity.h +++ b/V8Entity.h @@ -61,6 +61,8 @@ class V8Entity return &v8Player; case alt::IBaseObject::Type::VEHICLE: return &v8Vehicle; + case alt::IBaseObject::Type::BLIP: + return &v8Blip; #ifdef ALT_SERVER_API case alt::IBaseObject::Type::COLSHAPE: return &v8Colshape; @@ -68,8 +70,6 @@ class V8Entity return &v8Checkpoint; case alt::IBaseObject::Type::VOICE_CHANNEL: return &v8VoiceChannel; - case alt::IBaseObject::Type::BLIP: - return &v8Blip; #else case alt::IBaseObject::Type::WEBVIEW: return &v8WebView; From 90de823f49f9d7f032af97545b3404809cd78880 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 12 Nov 2020 06:39:16 +0100 Subject: [PATCH 052/564] Fix --- V8Helpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/V8Helpers.h b/V8Helpers.h index 4526e196..42c954af 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -321,7 +321,7 @@ namespace V8 #define V8_RETURN_BASE_OBJECT(baseObjectRef) V8_RETURN(resource->GetBaseObjectOrNull(baseObjectRef)) -#define V8_BIND_BASE_OBJECT(baseObjectRef) \ +#define V8_BIND_BASE_OBJECT(baseObjectRef, msg) \ { \ V8_CHECK(baseObjectRef, "Failed to create base object"); \ auto baseObject = (baseObjectRef); \ From 9315826b5609a31e39ca42e0d8a5cc7383949e50 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 12 Nov 2020 06:43:53 +0100 Subject: [PATCH 053/564] Add missing include --- V8Helpers.h | 1 + 1 file changed, 1 insertion(+) diff --git a/V8Helpers.h b/V8Helpers.h index 42c954af..64f10bd5 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -4,6 +4,7 @@ #include #include +#include #include "cpp-sdk/objects/IEntity.h" #include "cpp-sdk/types/MValue.h" From df52cfa76ab649da48454cbd8cc7b6326d629d41 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 12 Nov 2020 06:47:33 +0100 Subject: [PATCH 054/564] Added missing include --- V8Helpers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 11215313..adf6cd6e 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -2,6 +2,7 @@ #include "cpp-sdk/ICore.h" #include "V8ResourceImpl.h" #include "V8Helpers.h" +#include bool V8Helpers::TryCatch(const std::function &fn) { From a5c3e55f0bd89466ef368aa2b4cb1bac7a7df771 Mon Sep 17 00:00:00 2001 From: Vektor Date: Thu, 12 Nov 2020 11:15:22 +0100 Subject: [PATCH 055/564] changed blip routecolor and secondary color to RGB --- src/bindings/Blip.cpp | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index 8d233bde..1174b6be 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -143,9 +143,10 @@ static void ColorSetter(v8::Local property, v8::Local val static void SecondaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE_CONTEXT(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INTEGER(blip->GetSecondaryColor()); + alt::RGBA color = blip->GetSecondaryColor(); + V8_RETURN(resource->CreateRGBA(color)); } static void SecondaryColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -153,7 +154,21 @@ static void SecondaryColorSetter(v8::Local property, v8::LocalSetSecondaryColor(val); + + V8_CHECK(value->IsObject(), "object expected"); + + v8::Local color = value.As(); + + v8::Local r = color->Get(ctx, v8::String::NewFromUtf8(isolate, "r").ToLocalChecked()).ToLocalChecked(); + v8::Local g = color->Get(ctx, v8::String::NewFromUtf8(isolate, "g").ToLocalChecked()).ToLocalChecked(); + v8::Local b = color->Get(ctx, v8::String::NewFromUtf8(isolate, "b").ToLocalChecked()).ToLocalChecked(); + + blip->SetSecondaryColor({ + (uint8_t)r->ToInteger(ctx).ToLocalChecked()->Value(), + (uint8_t)g->ToInteger(ctx).ToLocalChecked()->Value(), + (uint8_t)b->ToInteger(ctx).ToLocalChecked()->Value(), + 255 + }); } static void AlphaGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -398,17 +413,31 @@ static void NameSetter(v8::Local property, v8::Local valu static void RouteColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE_CONTEXT(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INTEGER(blip->GetRouteColor()); + alt::RGBA color = blip->GetRouteColor(); + V8_RETURN(resource->CreateRGBA(color)); } static void RouteColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); - blip->SetRouteColor(val); + + V8_CHECK(value->IsObject(), "object expected"); + + v8::Local color = value.As(); + + v8::Local r = color->Get(ctx, v8::String::NewFromUtf8(isolate, "r").ToLocalChecked()).ToLocalChecked(); + v8::Local g = color->Get(ctx, v8::String::NewFromUtf8(isolate, "g").ToLocalChecked()).ToLocalChecked(); + v8::Local b = color->Get(ctx, v8::String::NewFromUtf8(isolate, "b").ToLocalChecked()).ToLocalChecked(); + + blip->SetRouteColor({ + (uint8_t)r->ToInteger(ctx).ToLocalChecked()->Value(), + (uint8_t)g->ToInteger(ctx).ToLocalChecked()->Value(), + (uint8_t)b->ToInteger(ctx).ToLocalChecked()->Value(), + 255 + }); } static void PulseGetter(v8::Local, const v8::PropertyCallbackInfo& info) From 6555280f52a693d8deb5980281735e7922a6eae0 Mon Sep 17 00:00:00 2001 From: Vektor Date: Thu, 12 Nov 2020 11:17:24 +0100 Subject: [PATCH 056/564] update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 3d5ef898..df52cfa7 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 3d5ef8988ccf71145cfaf040b0ea9596b8cd4ead +Subproject commit df52cfa76ab649da48454cbd8cc7b6326d629d41 From bea5203900054d2cfcd710950ffb5cea99204cea Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 12 Nov 2020 13:55:39 +0100 Subject: [PATCH 057/564] Added IPlayer getters --- .gitignore | 2 + src/bindings/Player.cpp | 247 +++++++++++++++++++++++++++++++--------- 2 files changed, 194 insertions(+), 55 deletions(-) diff --git a/.gitignore b/.gitignore index 0b890095..1678a5b2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ BUILD/ deps/v8/ + +.vs/ \ No newline at end of file diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 4047ab7d..4f0e652c 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -7,70 +7,189 @@ #include "cpp-sdk/objects/IPlayer.h" #include "cpp-sdk/objects/IVehicle.h" -static void NameGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void NameGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_RETURN_STRING(player->GetName().CStr()); +} - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); +static void VehicleGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - alt::Ref player = _this->GetHandle().As(); + alt::Ref vehicle = player->GetVehicle(); - info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, player->GetName().CStr()).ToLocalChecked()); + if (vehicle) + V8_RETURN(resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); + else + V8_RETURN_NULL(); } -static void VehicleGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_RETURN_BOOLEAN(player->IsTalking()); +} - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); +static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - alt::Ref player = _this->GetHandle().As(); - alt::Ref vehicle = player->GetVehicle(); + V8_RETURN_NUMBER(player->GetMicLevel()); +} - if (vehicle) - info.GetReturnValue().Set(resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); - else - info.GetReturnValue().Set(v8::Null(info.GetIsolate())); +// My own shit + +static void CurrentWeaponComponentsGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + alt::Array comps = player->GetCurrentWeaponComponents(); + + v8::Local componentsArray = v8::Array::New(isolate, comps.GetSize()); + + for (uint32_t i = 0; i < comps.GetSize(); ++i) + componentsArray->Set(ctx, i, v8::Integer::NewFromUnsigned(isolate, comps[i])); + + V8_RETURN(componentsArray); } -static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void CurrentWeaponTintIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_RETURN_INTEGER(player->GetCurrentWeaponTintIndex()); +} - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); +static void CurrentWeaponGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - alt::Ref player = _this->GetHandle().As(); + V8_RETURN_INTEGER(player->GetCurrentWeapon()); +} + +static void IsJumpingGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - info.GetReturnValue().Set(v8::Boolean::New(isolate, player->IsTalking())); + V8_RETURN_BOOLEAN(player->IsJumping()); } -static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void IsInRagdollGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_RETURN_BOOLEAN(player->IsInRagdoll()); +} - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); +static void IsAimingGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - alt::Ref player = _this->GetHandle().As(); + V8_RETURN_BOOLEAN(player->IsAiming()); +} - info.GetReturnValue().Set(v8::Number::New(isolate, player->GetMicLevel())); +static void IsShootingGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BOOLEAN(player->IsShooting()); } +static void IsReloadingGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BOOLEAN(player->IsReloading()); +} + +static void ArmourGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_INTEGER(player->GetArmour()); +} + +static void MaxArmourGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_INTEGER(player->GetMaxArmour()); +} + +static void MoveSpeedGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_NUMBER(player->GetMoveSpeed()); +} + +static void AimPosGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN(resource->CreateVector3(player->GetAimPos())); +} + +static void HeadRotationGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN(resource->CreateVector3(player->GetHeadRotation())); +} + +static void SeatGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_INTEGER(player->GetSeat()); +} + +static void EntityAimingAtGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN(player->GetEntityAimingAt()); +} + +static void EntityAimOffsetGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN(resource->CreateVector3(player->GetEntityAimOffset())); +} + +static void FlashlightActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BOOLEAN(player->IsFlashlightActive()); +} + + // static void GiveWeapon(const v8::FunctionCallbackInfo &info) // { // v8::Isolate *isolate = info.GetIsolate(); @@ -172,6 +291,7 @@ static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo // player->RemoveWeaponComponent(weaponHash, componentHash); // } +/* static void WeaponHasComponent(const v8::FunctionCallbackInfo &info) { v8::Isolate *isolate = info.GetIsolate(); @@ -193,6 +313,7 @@ static void WeaponHasComponent(const v8::FunctionCallbackInfo &info) info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), player->HasWeaponComponent(weaponHash, componentHash))); } +*/ // static void SetWeaponTintIndex(const v8::FunctionCallbackInfo &info) // { @@ -216,6 +337,7 @@ static void WeaponHasComponent(const v8::FunctionCallbackInfo &info) // player->SetWeaponTintIndex(weaponHash, tintIndex); // } +/* static void GetWeaponTintIndex(const v8::FunctionCallbackInfo &info) { v8::Isolate *isolate = info.GetIsolate(); @@ -234,6 +356,7 @@ static void GetWeaponTintIndex(const v8::FunctionCallbackInfo &info) info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), player->GetWeaponTintIndex(weaponHash))); } +*/ // static void SetCurrentWeapon(const v8::FunctionCallbackInfo &info) // { @@ -254,6 +377,7 @@ static void GetWeaponTintIndex(const v8::FunctionCallbackInfo &info) // player->SetCurrentWeapon(weaponHash); // } +/* static void GetCurrentWeapon(const v8::FunctionCallbackInfo &info) { v8::Isolate *isolate = info.GetIsolate(); @@ -269,16 +393,13 @@ static void GetCurrentWeapon(const v8::FunctionCallbackInfo &info) info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), player->GetCurrentWeapon())); } +*/ -static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - v8::Local arr = v8::Array::New(info.GetIsolate()); + v8::Local arr = v8::Array::New(isolate); uint16_t i = 0; for (auto player : alt::ICore::Instance().GetPlayers()) @@ -287,24 +408,21 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfoSet(ctx, i++, resource->GetOrCreateEntity(player.Get(), "Player")->GetJSVal(isolate)); }; - info.GetReturnValue().Set(arr); + V8_RETURN(arr); } -static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); auto localPlayer = alt::ICore::Instance().GetLocalPlayer(); if (!localPlayer) - info.GetReturnValue().Set(v8::Null(isolate)); + V8_RETURN_NULL(); else - info.GetReturnValue().Set(resource->GetOrCreateEntity(localPlayer.Get())->GetJSVal(isolate)); + V8_RETURN(resource->GetOrCreateEntity(localPlayer.Get())->GetJSVal(isolate)); } -static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) +static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); @@ -312,7 +430,7 @@ static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid).As()); } -static void StaticGetByID(const v8::FunctionCallbackInfo &info) +static void StaticGetByID(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); @@ -322,7 +440,7 @@ static void StaticGetByID(const v8::FunctionCallbackInfo &info) extern V8Class v8Entity; extern V8Class v8Player("Player", v8Entity, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Local proto = tpl->PrototypeTemplate(); @@ -336,11 +454,30 @@ extern V8Class v8Player("Player", v8Entity, [](v8::Local t proto->SetAccessor(v8::String::NewFromUtf8(isolate, "vehicle").ToLocalChecked(), &VehicleGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isTalking").ToLocalChecked(), &TalkingGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "micLevel").ToLocalChecked(), &MicLevelGetter); - + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "currentWeaponComponents").ToLocalChecked(), &CurrentWeaponComponentsGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "currentWeaponTintIndex").ToLocalChecked(), &CurrentWeaponTintIndexGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "currentWeapon").ToLocalChecked(), &CurrentWeaponGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isJumping").ToLocalChecked(), &IsJumpingGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isInRagdoll").ToLocalChecked(), &IsInRagdollGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isAiming").ToLocalChecked(), &IsAimingGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isShooting").ToLocalChecked(), &IsShootingGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isReloading").ToLocalChecked(), &IsReloadingGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "armour").ToLocalChecked(), &ArmourGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "maxArmour").ToLocalChecked(), &MaxArmourGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "moveSpeed").ToLocalChecked(), &MoveSpeedGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "aimPos").ToLocalChecked(), &AimPosGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "headRot").ToLocalChecked(), &HeadRotationGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seat").ToLocalChecked(), &SeatGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "entityAimingAt").ToLocalChecked(), &EntityAimingAtGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "entityAimOffset").ToLocalChecked(), &EntityAimOffsetGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "flashlightActive").ToLocalChecked(), &FlashlightActiveGetter); + + /* if (alt::ICore::Instance().IsSandbox()) { proto->Set(isolate, "weaponHasComponent", v8::FunctionTemplate::New(isolate, &WeaponHasComponent)); proto->Set(isolate, "getWeaponTintIndex", v8::FunctionTemplate::New(isolate, &GetWeaponTintIndex)); proto->Set(isolate, "getCurrentWeapon", v8::FunctionTemplate::New(isolate, &GetCurrentWeapon)); } + */ }); From 31d215aa4568a8cd23bbe9a0549cfd345d9b4387 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 12 Nov 2020 14:17:38 +0100 Subject: [PATCH 058/564] Rewrote vehicle getters to use macros --- src/bindings/Vehicle.cpp | 67 ++++++++++++---------------------------- 1 file changed, 20 insertions(+), 47 deletions(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index b6e84f8a..300f6bfb 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -9,7 +9,7 @@ using namespace alt; static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); V8Entity *_this = V8Entity::Get(info.This()); V8_CHECK(_this, "entity is invalid"); @@ -18,70 +18,47 @@ static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo info.This()}; extern V8Class v8Handling; - info.GetReturnValue().Set(v8Handling.New(isolate->GetEnteredContext(), args)); + V8_RETURN(v8Handling.New(isolate->GetEnteredContext(), args)); } static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref vehicle = _this->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetWheelSpeed())); + V8_RETURN_NUMBER(vehicle->GetWheelSpeed()); } static void GearGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref vehicle = _this->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Integer::New(isolate, vehicle->GetCurrentGear())); + V8_RETURN_INTEGER(vehicle->GetCurrentGear()); } static void RPMGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref vehicle = _this->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetCurrentRPM())); + V8_RETURN_NUMBER(vehicle->GetCurrentRPM()); } static void WheelsCountGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref vehicle = _this->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetWheelsCount())); + V8_RETURN_NUMBER(vehicle->GetWheelsCount()); } static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref vehicle = _this->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - info.GetReturnValue().Set(resource->CreateVector3(vehicle->GetSpeedVector())); + V8_RETURN(resource->CreateVector3(vehicle->GetSpeedVector())); } // static void GravityGetter(v8::Local, const v8::PropertyCallbackInfo &info) @@ -127,13 +104,9 @@ static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackI static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - v8::Local arr = v8::Array::New(info.GetIsolate()); + v8::Local arr = v8::Array::New(isolate); uint16_t i = 0; for (auto vehicle : alt::ICore::Instance().GetVehicles()) @@ -142,7 +115,7 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo arr->Set(ctx, i++, resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); }; - info.GetReturnValue().Set(arr); + V8_RETURN(arr); } static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) From 212ee6a3c9a858ebc8a0ce15e524d2589c5d6ff5 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 12 Nov 2020 14:26:16 +0100 Subject: [PATCH 059/564] Fixed entity aiming at getter --- src/bindings/Player.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 4f0e652c..b179003a 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -167,10 +167,10 @@ static void SeatGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE_CONTEXT(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_RETURN(player->GetEntityAimingAt()); + V8_RETURN_BASE_OBJECT(player->GetEntityAimingAt()); } static void EntityAimOffsetGetter(v8::Local, const v8::PropertyCallbackInfo& info) From 31afaffc68298c56ed7604a5b08d00bb370dd7fa Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 12 Nov 2020 16:09:27 +0100 Subject: [PATCH 060/564] Added IVehicle getters --- src/bindings/Vehicle.cpp | 454 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 452 insertions(+), 2 deletions(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 300f6bfb..27e7600d 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -50,7 +50,7 @@ static void WheelsCountGetter(v8::Local, const v8::PropertyCallbackI V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_NUMBER(vehicle->GetWheelsCount()); + V8_RETURN_INTEGER(vehicle->GetWheelsCount()); } static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackInfo &info) @@ -61,6 +61,408 @@ static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackI V8_RETURN(resource->CreateVector3(vehicle->GetSpeedVector())); } +static void DriverGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BASE_OBJECT(vehicle->GetDriver()); +} + +static void IsDestroyedGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsDestroyed()); +} + +static void ModKitsCountGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetModKitsCount()); +} + +static void ModKitGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetModKit()); +} + +static void IsPrimaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsPrimaryColorRGB()); +} + +static void PrimaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetPrimaryColor()); +} + +static void PrimaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN(resource->CreateRGBA(vehicle->GetPrimaryColorRGB())); +} + +static void IsSecondaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsSecondaryColorRGB()); +} + +static void SecondaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetSecondaryColor()); +} + +static void SecondaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN(resource->CreateRGBA(vehicle->GetSecondaryColorRGB())); +} + +static void PearlColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetPearlColor()); +} + +static void WheelColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetWheelColor()); +} + +static void InteriorColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetInteriorColor()); +} + +static void DashboardColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetDashboardColor()); +} + +static void IsTireSmokeColorCustomGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsTireSmokeColorCustom()); +} + +static void TireSmokeColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN(resource->CreateRGBA(vehicle->GetTireSmokeColor())); +} + +static void WheelTypeGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetWheelType()); +} + +static void WheelVariationGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetWheelVariation()); +} + +static void RearWheelVariationGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetRearWheelVariation()); +} + +static void IsCustomTiresGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->GetCustomTires()); +} + +static void SpecialDarknessGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetSpecialDarkness()); +} + +static void NumberplateIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetNumberplateIndex()); +} + +static void NumberplateTextGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_STRING(vehicle->GetNumberplateText().CStr()); +} + +static void WindowTintGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetWindowTint()); +} + +static void DirtLevelGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetDirtLevel()); +} + +static void IsNeonActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsNeonActive()); +} + +static void NeonColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN(resource->CreateRGBA(vehicle->GetNeonColor())); +} + +static void NeonGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + v8::Local neonActive = v8::Object::New(isolate); + + bool left, right, front, back; + vehicle->GetNeonActive(&left, &right, &front, &back); + + neonActive->Set(ctx, v8::String::NewFromUtf8(isolate, "left").ToLocalChecked(), v8::Boolean::New(isolate, left)); + neonActive->Set(ctx, v8::String::NewFromUtf8(isolate, "right").ToLocalChecked(), v8::Boolean::New(isolate, right)); + neonActive->Set(ctx, v8::String::NewFromUtf8(isolate, "front").ToLocalChecked(), v8::Boolean::New(isolate, front)); + neonActive->Set(ctx, v8::String::NewFromUtf8(isolate, "back").ToLocalChecked(), v8::Boolean::New(isolate, back)); + + V8_RETURN(neonActive); +} + +static void LiveryGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetLivery()); +} + +static void RoofLiveryGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetRoofLivery()); +} + +static void EngineOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsEngineOn()); +} + +static void HandbrakeActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsHandbrakeActive()); +} + +static void HeadlightColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetHeadlightColor()); +} + +static void RadioStationIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetRadioStationIndex()); +} + +static void IsSirenActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsSirenActive()); +} + +static void LockStateGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetLockState()); +} + +static void IsDaylightOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsDaylightOn()); +} + +static void IsNightlightOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsNightlightOn()); +} + +static void RoofStateGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetRoofState()); +} + +static void IsFlamethrowerActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsFlamethrowerActive()); +} + +static void LightsMultiplierGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_NUMBER(vehicle->GetLightsMultiplier()); +} + +static void EngineHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetEngineHealth()); +} + +static void PetrolTankHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetPetrolTankHealth()); +} + +static void RepairsCountGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetRepairsCount()); +} + +static void BodyHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetBodyHealth()); +} + +static void BodyAdditionalHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetBodyAdditionalHealth()); +} + +static void HasArmoredWindowsGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->HasArmoredWindows()); +} + +static void IsManualEngineControlGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsManualEngineControl()); +} + +static void IsHandlingModifiedGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsHandlingModified()); +} + // static void GravityGetter(v8::Local, const v8::PropertyCallbackInfo &info) // { // V8_GET_ISOLATE_CONTEXT(); @@ -102,7 +504,7 @@ static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackI // vehicle->gravity = newval; // } -static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -152,4 +554,52 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); // V8::SetAccessor(isolate, tpl, "gravity", &GravityGetter, &GravitySetter); V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); + V8::SetAccessor(isolate, tpl, "destroyed", &IsDestroyedGetter); + V8::SetAccessor(isolate, tpl, "modKitsCount", &ModKitsCountGetter); + V8::SetAccessor(isolate, tpl, "modKit", &ModKitGetter); + //V8::SetAccessor(isolate, tpl, "hasCustomPrimaryColor", &IsPrimaryColorRGBGetter); + V8::SetAccessor(isolate, tpl, "primaryColor", &PrimaryColorGetter); + V8::SetAccessor(isolate, tpl, "customPrimaryColor", &PrimaryColorRGBGetter); + //V8::SetAccessor(isolate, tpl, "hasCustomSecondaryColor", &IsSecondaryColorRGBGetter); + V8::SetAccessor(isolate, tpl, "secondaryColor", &SecondaryColorGetter); + V8::SetAccessor(isolate, tpl, "customSecondaryColor", &SecondaryColorRGBGetter); + V8::SetAccessor(isolate, tpl, "pearlColor", &PearlColorGetter); + V8::SetAccessor(isolate, tpl, "wheelColor", &WheelColorGetter); + V8::SetAccessor(isolate, tpl, "interiorColor", &InteriorColorGetter); + V8::SetAccessor(isolate, tpl, "dashboardColor", &DashboardColorGetter); + //V8::SetAccessor(isolate, tpl, "hasCustomTireSmokeColor", &IsTireSmokeColorCustomGetter); + V8::SetAccessor(isolate, tpl, "tireSmokeColor", &TireSmokeColorGetter); + V8::SetAccessor(isolate, tpl, "wheelType", &WheelTypeGetter); + V8::SetAccessor(isolate, tpl, "frontWheels", &WheelVariationGetter); + V8::SetAccessor(isolate, tpl, "rearWheels", &RearWheelVariationGetter); + V8::SetAccessor(isolate, tpl, "customTires", &IsCustomTiresGetter); + V8::SetAccessor(isolate, tpl, "darkness", &SpecialDarknessGetter); + V8::SetAccessor(isolate, tpl, "numberPlateIndex", &NumberplateIndexGetter); + V8::SetAccessor(isolate, tpl, "numberPlateText", &NumberplateTextGetter); + V8::SetAccessor(isolate, tpl, "windowTint", &WindowTintGetter); + V8::SetAccessor(isolate, tpl, "dirtLevel", &DirtLevelGetter); + //V8::SetAccessor(isolate, tpl, "neonActive", &IsNeonActiveGetter); + V8::SetAccessor(isolate, tpl, "neon", &NeonGetter); + V8::SetAccessor(isolate, tpl, "neonColor", &NeonColorGetter); + V8::SetAccessor(isolate, tpl, "livery", &LiveryGetter); + V8::SetAccessor(isolate, tpl, "roofLivery", &RoofLiveryGetter); + V8::SetAccessor(isolate, tpl, "engineOn", &EngineOnGetter); + V8::SetAccessor(isolate, tpl, "handbrakeActive", &HandbrakeActiveGetter); + V8::SetAccessor(isolate, tpl, "headlightColor", &HeadlightColorGetter); + V8::SetAccessor(isolate, tpl, "activeRadioStation", &RadioStationIndexGetter); + V8::SetAccessor(isolate, tpl, "sirenActive", &IsSirenActiveGetter); + V8::SetAccessor(isolate, tpl, "lockState", &LockStateGetter); + V8::SetAccessor(isolate, tpl, "daylightOn", &IsDaylightOnGetter); + V8::SetAccessor(isolate, tpl, "nightlightOn", &IsNightlightOnGetter); + V8::SetAccessor(isolate, tpl, "roofState", &RoofStateGetter); + V8::SetAccessor(isolate, tpl, "flamethrowerActive", &IsFlamethrowerActiveGetter); + V8::SetAccessor(isolate, tpl, "lightsMultiplier", &LightsMultiplierGetter); + V8::SetAccessor(isolate, tpl, "engineHealth", &EngineHealthGetter); + V8::SetAccessor(isolate, tpl, "petrolTankHealth", &PetrolTankHealthGetter); + V8::SetAccessor(isolate, tpl, "repairsCount", &RepairsCountGetter); + V8::SetAccessor(isolate, tpl, "bodyHealth", &BodyHealthGetter); + V8::SetAccessor(isolate, tpl, "bodyAdditionalHealth", &BodyAdditionalHealthGetter); + V8::SetAccessor(isolate, tpl, "hasArmoredWindows", &HasArmoredWindowsGetter); + V8::SetAccessor(isolate, tpl, "manualEngineControl", &IsManualEngineControlGetter); + //V8::SetAccessor(isolate, tpl, "handlingModified", &IsHandlingModifiedGetter); }); From 55be4f50538b4109c0b6dcae8dc2e881190dd5e2 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 12 Nov 2020 16:25:27 +0100 Subject: [PATCH 061/564] Fixed missing include --- src/bindings/Player.cpp | 2 ++ src/bindings/Vehicle.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index b179003a..0f9aee3b 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -7,6 +7,8 @@ #include "cpp-sdk/objects/IPlayer.h" #include "cpp-sdk/objects/IVehicle.h" +using namespace alt; + static void NameGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 27e7600d..39b3b928 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -3,6 +3,8 @@ #include "../helpers/V8Class.h" #include "../helpers/V8Entity.h" #include "../helpers/V8ResourceImpl.h" + +#include "cpp-sdk/objects/IPlayer.h" #include "cpp-sdk/objects/IVehicle.h" using namespace alt; From 0b7db5235d1b13e0359f8efd87a1bf217f8b28f5 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 12 Nov 2020 18:39:17 +0100 Subject: [PATCH 062/564] Fix some bad logging --- src/CV8Resource.cpp | 2 +- src/CV8Resource.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 9212c0d1..83fe7816 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -84,7 +84,7 @@ bool CV8ResourceImpl::Start() pkg->ReadFile(file, src.GetData(), src.GetSize()); pkg->CloseFile(file); - Log::Info << "[V8] Starting script" << path << Log::Endl; + Log::Info << "[V8] Starting script " << path << Log::Endl; v8::Local sourceCode = v8::String::NewFromUtf8(isolate, src.GetData(), v8::NewStringType::kNormal, src.GetSize()).ToLocalChecked(); diff --git a/src/CV8Resource.h b/src/CV8Resource.h index 33c217d2..5b42f263 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -20,7 +20,7 @@ class CV8ResourceImpl : public V8ResourceImpl ~CV8ResourceImpl() { - Log::Debug << __FUNCTION__; + Log::Debug << __FUNCTION__ << Log::Endl; } bool Start() override; From 4ae02d3552fca60dc86d2fc04b49e8ffc83948e0 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 12 Nov 2020 18:39:42 +0100 Subject: [PATCH 063/564] Bind webviews to js object --- src/bindings/WebView.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index 707b0c62..b42c88ed 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -167,15 +167,14 @@ extern V8Class v8BaseObject; extern V8Class v8WebView( "WebView", v8BaseObject, [](const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetCurrentContext(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK(info.IsConstructCall(), "WebView is not a function"); V8_CHECK(info.Length() > 0 && info.Length() <= 3, "new WebView(...) expects 1, 2 or 3 args"); V8_CHECK(info[0]->IsString(), "url must be a string"); - alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + alt::IResource *altres = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(altres, "invalid resource"); v8::Local url = info[0].As(); @@ -192,7 +191,7 @@ extern V8Class v8WebView( auto texture = alt::ICore::Instance().GetTextureFromDrawable(drawableHash, targetTextureStr); V8_CHECK(texture != nullptr, "Texture not found"); - view = resource->CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), (uint32_t)drawableHash, targetTextureStr); + view = altres->CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), (uint32_t)drawableHash, targetTextureStr); V8_CHECK(!view.IsEmpty(), "Interactive WebView cannot be created"); } else if (info.Length() == 2) @@ -200,15 +199,14 @@ extern V8Class v8WebView( v8::Local isOverlay = info[1]->ToBoolean(isolate); bool isOverlayBool = isOverlay->Value(); - view = resource->CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), {0, 0}, {0, 0}, true, isOverlayBool); + view = altres->CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), {0, 0}, {0, 0}, true, isOverlayBool); } else { - view = resource->CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), {0, 0}, {0, 0}, true, false); + view = altres->CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), {0, 0}, {0, 0}, true, false); } - // static_cast(resource)->AddOwned(view); - // resource->BindEntity(info.This(), view.Get()); + V8_BIND_BASE_OBJECT(view); }, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); From fdc5ee1e334085e12f9b6b91355be3cc0daaec0d Mon Sep 17 00:00:00 2001 From: Hazard Date: Fri, 13 Nov 2020 05:34:09 +0100 Subject: [PATCH 064/564] Fix memory leak for v8 entities --- V8ResourceImpl.cpp | 8 ++++++++ V8ResourceImpl.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 64179706..fa3723cc 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -11,6 +11,14 @@ using namespace alt; +V8ResourceImpl::~V8ResourceImpl() { + for(auto& [obj, ent] : entities) { + delete ent; + } + + entities.clear(); +} + extern V8Class v8Vector3, v8RGBA, v8BaseObject; bool V8ResourceImpl::Start() { diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index c592a0cf..6fbd4a04 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -34,6 +34,8 @@ class V8ResourceImpl : public alt::IResource::Impl { } + ~V8ResourceImpl(); + struct PathInfo { alt::IPackage *pkg = nullptr; From daa6f26bd03de8631de86470f318ee0492a8552a Mon Sep 17 00:00:00 2001 From: Hazard Date: Fri, 13 Nov 2020 05:34:41 +0100 Subject: [PATCH 065/564] Update helpers --- src/CV8Resource.cpp | 2 +- src/helpers | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 83fe7816..cc3dd171 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -125,7 +125,7 @@ bool CV8ResourceImpl::Start() alt::MValue _exports = V8Helpers::V8ToMValue(curModule->GetModuleNamespace()); resource->SetExports(_exports.As()); - Log::Info << "[V8] Started script" << path; + Log::Info << "[V8] Started script " << path << Log::Endl; return true; }); diff --git a/src/helpers b/src/helpers index df52cfa7..fdc5ee1e 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit df52cfa76ab649da48454cbd8cc7b6326d629d41 +Subproject commit fdc5ee1e334085e12f9b6b91355be3cc0daaec0d From 385bed325b41f8144ee127e84c8c9d35adc75aea Mon Sep 17 00:00:00 2001 From: Hazard Date: Fri, 13 Nov 2020 05:34:49 +0100 Subject: [PATCH 066/564] Get cpp-sdk from master branch --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a4cc1b3..d5765216 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ if(NOT ALTV_JS_CPP_SDK) git_clone( PROJECT_NAME cpp-sdk GIT_URL https://github.com/altmp/cpp-sdk - GIT_BRANCH clientsdk + GIT_BRANCH master DIRECTORY ${ALTV_JS_DL_DEPS} ) set(ALTV_JS_CPP_SDK ${ALTV_JS_DL_DEPS}) From 7602acab3518549fed1ab924dde393016f26f12b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 13 Nov 2020 16:20:03 +0100 Subject: [PATCH 067/564] Added missing health getters for player class --- src/bindings/Player.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 0f9aee3b..23adf8f2 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -46,8 +46,6 @@ static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo V8_RETURN_NUMBER(player->GetMicLevel()); } -// My own shit - static void CurrentWeaponComponentsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -191,6 +189,21 @@ static void FlashlightActiveGetter(v8::Local, const v8::PropertyCall V8_RETURN_BOOLEAN(player->IsFlashlightActive()); } +static void HealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_INTEGER(player->GetHealth()); +} + +static void MaxHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_INTEGER(player->GetMaxHealth()); +} // static void GiveWeapon(const v8::FunctionCallbackInfo &info) // { @@ -473,6 +486,8 @@ extern V8Class v8Player("Player", v8Entity, [](v8::Local t proto->SetAccessor(v8::String::NewFromUtf8(isolate, "entityAimingAt").ToLocalChecked(), &EntityAimingAtGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "entityAimOffset").ToLocalChecked(), &EntityAimOffsetGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "flashlightActive").ToLocalChecked(), &FlashlightActiveGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "health").ToLocalChecked(), &HealthGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "maxHealth").ToLocalChecked(), &MaxHealthGetter); /* if (alt::ICore::Instance().IsSandbox()) From 4872a59df8ca09e258149051550cc0460939fe7a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 13 Nov 2020 19:38:35 +0100 Subject: [PATCH 068/564] Added missing isDead getter to player --- src/bindings/Player.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 23adf8f2..f0408985 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -205,6 +205,15 @@ static void MaxHealthGetter(v8::Local, const v8::PropertyCallbackInf V8_RETURN_INTEGER(player->GetMaxHealth()); } +static void IsDeadGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BOOLEAN(player->IsDead()); +} + + // static void GiveWeapon(const v8::FunctionCallbackInfo &info) // { // v8::Isolate *isolate = info.GetIsolate(); @@ -488,6 +497,7 @@ extern V8Class v8Player("Player", v8Entity, [](v8::Local t proto->SetAccessor(v8::String::NewFromUtf8(isolate, "flashlightActive").ToLocalChecked(), &FlashlightActiveGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "health").ToLocalChecked(), &HealthGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "maxHealth").ToLocalChecked(), &MaxHealthGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isDead").ToLocalChecked(), &IsDeadGetter); /* if (alt::ICore::Instance().IsSandbox()) From 4754fc95e720b5890353fe04add2764ddaaf5911 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 13 Nov 2020 19:50:36 +0100 Subject: [PATCH 069/564] Added missing driver getter to vehicle class --- src/bindings/Vehicle.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 39b3b928..1182be74 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -604,4 +604,5 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetAccessor(isolate, tpl, "hasArmoredWindows", &HasArmoredWindowsGetter); V8::SetAccessor(isolate, tpl, "manualEngineControl", &IsManualEngineControlGetter); //V8::SetAccessor(isolate, tpl, "handlingModified", &IsHandlingModifiedGetter); + V8::SetAccessor(isolate, tpl, "driver", &DriverGetter); }); From 77f7893a7c88b4b4eaeeb85034ead4990cc5393b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 13 Nov 2020 20:02:23 +0100 Subject: [PATCH 070/564] Changed some functions to use macros --- src/bindings/Player.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index f0408985..8fc40f2b 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -22,12 +22,7 @@ static void VehicleGetter(v8::Local, const v8::PropertyCallbackInfo< V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - alt::Ref vehicle = player->GetVehicle(); - - if (vehicle) - V8_RETURN(resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); - else - V8_RETURN_NULL(); + V8_RETURN_BASE_OBJECT(player->GetVehicle()); } static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -439,11 +434,7 @@ static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - auto localPlayer = alt::ICore::Instance().GetLocalPlayer(); - if (!localPlayer) - V8_RETURN_NULL(); - else - V8_RETURN(resource->GetOrCreateEntity(localPlayer.Get())->GetJSVal(isolate)); + V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetLocalPlayer()); } static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) From e001f9016d6534deafc30bf7caa16cad624e3942 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 13 Nov 2020 20:42:38 +0100 Subject: [PATCH 071/564] Organized vehicle and player getters --- src/bindings/Player.cpp | 25 +++++++++++++++---------- src/bindings/Vehicle.cpp | 13 ++++++++++++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 8fc40f2b..faa5ab0c 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -465,30 +465,35 @@ extern V8Class v8Player("Player", v8Entity, [](v8::Local t tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, "all").ToLocalChecked(), &AllGetter); tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, "local").ToLocalChecked(), &LocalGetter); + // Common getters proto->SetAccessor(v8::String::NewFromUtf8(isolate, "name").ToLocalChecked(), &NameGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "vehicle").ToLocalChecked(), &VehicleGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seat").ToLocalChecked(), &SeatGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isTalking").ToLocalChecked(), &TalkingGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "micLevel").ToLocalChecked(), &MicLevelGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "health").ToLocalChecked(), &HealthGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "maxHealth").ToLocalChecked(), &MaxHealthGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "armour").ToLocalChecked(), &ArmourGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "maxArmour").ToLocalChecked(), &MaxArmourGetter); + + // Weapon getters proto->SetAccessor(v8::String::NewFromUtf8(isolate, "currentWeaponComponents").ToLocalChecked(), &CurrentWeaponComponentsGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "currentWeaponTintIndex").ToLocalChecked(), &CurrentWeaponTintIndexGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "currentWeapon").ToLocalChecked(), &CurrentWeaponGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "entityAimingAt").ToLocalChecked(), &EntityAimingAtGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "entityAimOffset").ToLocalChecked(), &EntityAimOffsetGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "flashlightActive").ToLocalChecked(), &FlashlightActiveGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "aimPos").ToLocalChecked(), &AimPosGetter); + + // Gamestate getters proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isJumping").ToLocalChecked(), &IsJumpingGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isInRagdoll").ToLocalChecked(), &IsInRagdollGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isAiming").ToLocalChecked(), &IsAimingGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isShooting").ToLocalChecked(), &IsShootingGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isReloading").ToLocalChecked(), &IsReloadingGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "armour").ToLocalChecked(), &ArmourGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "maxArmour").ToLocalChecked(), &MaxArmourGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isDead").ToLocalChecked(), &IsDeadGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "moveSpeed").ToLocalChecked(), &MoveSpeedGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "aimPos").ToLocalChecked(), &AimPosGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "headRot").ToLocalChecked(), &HeadRotationGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seat").ToLocalChecked(), &SeatGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "entityAimingAt").ToLocalChecked(), &EntityAimingAtGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "entityAimOffset").ToLocalChecked(), &EntityAimOffsetGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "flashlightActive").ToLocalChecked(), &FlashlightActiveGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "health").ToLocalChecked(), &HealthGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "maxHealth").ToLocalChecked(), &MaxHealthGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isDead").ToLocalChecked(), &IsDeadGetter); /* if (alt::ICore::Instance().IsSandbox()) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 1182be74..aa6a52be 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -549,6 +549,7 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetStaticAccessor(isolate, tpl, "all", &AllGetter); + // Common getters V8::SetAccessor(isolate, tpl, "speed", &SpeedGetter); V8::SetAccessor(isolate, tpl, "gear", &GearGetter); V8::SetAccessor(isolate, tpl, "rpm", &RPMGetter); @@ -557,6 +558,9 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local // V8::SetAccessor(isolate, tpl, "gravity", &GravityGetter, &GravitySetter); V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); V8::SetAccessor(isolate, tpl, "destroyed", &IsDestroyedGetter); + V8::SetAccessor(isolate, tpl, "driver", &DriverGetter); + + // Appearance getters V8::SetAccessor(isolate, tpl, "modKitsCount", &ModKitsCountGetter); V8::SetAccessor(isolate, tpl, "modKit", &ModKitGetter); //V8::SetAccessor(isolate, tpl, "hasCustomPrimaryColor", &IsPrimaryColorRGBGetter); @@ -585,6 +589,8 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetAccessor(isolate, tpl, "neonColor", &NeonColorGetter); V8::SetAccessor(isolate, tpl, "livery", &LiveryGetter); V8::SetAccessor(isolate, tpl, "roofLivery", &RoofLiveryGetter); + + // Gamestate getters V8::SetAccessor(isolate, tpl, "engineOn", &EngineOnGetter); V8::SetAccessor(isolate, tpl, "handbrakeActive", &HandbrakeActiveGetter); V8::SetAccessor(isolate, tpl, "headlightColor", &HeadlightColorGetter); @@ -596,13 +602,18 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetAccessor(isolate, tpl, "roofState", &RoofStateGetter); V8::SetAccessor(isolate, tpl, "flamethrowerActive", &IsFlamethrowerActiveGetter); V8::SetAccessor(isolate, tpl, "lightsMultiplier", &LightsMultiplierGetter); + + // Health getters V8::SetAccessor(isolate, tpl, "engineHealth", &EngineHealthGetter); V8::SetAccessor(isolate, tpl, "petrolTankHealth", &PetrolTankHealthGetter); V8::SetAccessor(isolate, tpl, "repairsCount", &RepairsCountGetter); V8::SetAccessor(isolate, tpl, "bodyHealth", &BodyHealthGetter); V8::SetAccessor(isolate, tpl, "bodyAdditionalHealth", &BodyAdditionalHealthGetter); + + // Damage getters V8::SetAccessor(isolate, tpl, "hasArmoredWindows", &HasArmoredWindowsGetter); + + // Script getters V8::SetAccessor(isolate, tpl, "manualEngineControl", &IsManualEngineControlGetter); //V8::SetAccessor(isolate, tpl, "handlingModified", &IsHandlingModifiedGetter); - V8::SetAccessor(isolate, tpl, "driver", &DriverGetter); }); From bd3309353d07e71804c34354366422a97ede9338 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 13 Nov 2020 21:16:46 +0100 Subject: [PATCH 072/564] Changed vehicle destroyed property to isDestroyed --- src/bindings/Vehicle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index aa6a52be..1d6f1fd0 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -557,7 +557,7 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); // V8::SetAccessor(isolate, tpl, "gravity", &GravityGetter, &GravitySetter); V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); - V8::SetAccessor(isolate, tpl, "destroyed", &IsDestroyedGetter); + V8::SetAccessor(isolate, tpl, "isDestroyed", &IsDestroyedGetter); V8::SetAccessor(isolate, tpl, "driver", &DriverGetter); // Appearance getters From 55e27f13686a893185e9ff8f104e61e3f8fbc8d0 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 14 Nov 2020 11:39:48 +0100 Subject: [PATCH 073/564] retard --- bindings/RGBA.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/RGBA.cpp b/bindings/RGBA.cpp index 4b5cac14..7281272e 100644 --- a/bindings/RGBA.cpp +++ b/bindings/RGBA.cpp @@ -14,7 +14,7 @@ static void ToString(const v8::FunctionCallbackInfo &info) v8::Local a = info.This()->Get(ctx, V8::RGBA_AKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); std::ostringstream ss; - ss << "RGBA{ r: " << r->Value() << ", g: " << r->Value() << ", b: " << b->Value() << ", a: " << a->Value() << " }"; + ss << "RGBA{ r: " << r->Value() << ", g: " << g->Value() << ", b: " << b->Value() << ", a: " << a->Value() << " }"; info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, ss.str().c_str(), v8::NewStringType::kNormal).ToLocalChecked()); } From d71867f4728a7f794010a052d2ed628fffd3600e Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 14 Nov 2020 11:39:32 +0100 Subject: [PATCH 074/564] add alpha to blip route color --- src/bindings/Blip.cpp | 6 +++--- src/helpers | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index 1174b6be..e26084b2 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -415,8 +415,7 @@ static void RouteColorGetter(v8::Local, const v8::PropertyCallbackIn { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - alt::RGBA color = blip->GetRouteColor(); - V8_RETURN(resource->CreateRGBA(color)); + V8_RETURN(resource->CreateRGBA(blip->GetRouteColor())); } static void RouteColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -431,12 +430,13 @@ static void RouteColorSetter(v8::Local property, v8::Local r = color->Get(ctx, v8::String::NewFromUtf8(isolate, "r").ToLocalChecked()).ToLocalChecked(); v8::Local g = color->Get(ctx, v8::String::NewFromUtf8(isolate, "g").ToLocalChecked()).ToLocalChecked(); v8::Local b = color->Get(ctx, v8::String::NewFromUtf8(isolate, "b").ToLocalChecked()).ToLocalChecked(); + v8::Local a = color->Get(ctx, v8::String::NewFromUtf8(isolate, "a").ToLocalChecked()).ToLocalChecked(); blip->SetRouteColor({ (uint8_t)r->ToInteger(ctx).ToLocalChecked()->Value(), (uint8_t)g->ToInteger(ctx).ToLocalChecked()->Value(), (uint8_t)b->ToInteger(ctx).ToLocalChecked()->Value(), - 255 + (uint8_t)a->ToInteger(ctx).ToLocalChecked()->Value() }); } diff --git a/src/helpers b/src/helpers index fdc5ee1e..55e27f13 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit fdc5ee1e334085e12f9b6b91355be3cc0daaec0d +Subproject commit 55e27f13686a893185e9ff8f104e61e3f8fbc8d0 From cb0dc5cd34577c2067d37acae0e444c8d3fe525b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 14 Nov 2020 14:13:38 +0100 Subject: [PATCH 075/564] Made vehicle class code more consistent with other classes --- src/bindings/Vehicle.cpp | 114 +++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 1d6f1fd0..2991bd99 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -20,7 +20,7 @@ static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo info.This()}; extern V8Class v8Handling; - V8_RETURN(v8Handling.New(isolate->GetEnteredContext(), args)); + V8_RETURN(v8Handling.New(ctx, args)); } static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) @@ -550,70 +550,70 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetStaticAccessor(isolate, tpl, "all", &AllGetter); // Common getters - V8::SetAccessor(isolate, tpl, "speed", &SpeedGetter); - V8::SetAccessor(isolate, tpl, "gear", &GearGetter); - V8::SetAccessor(isolate, tpl, "rpm", &RPMGetter); - V8::SetAccessor(isolate, tpl, "wheelsCount", &WheelsCountGetter); - V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); - // V8::SetAccessor(isolate, tpl, "gravity", &GravityGetter, &GravitySetter); - V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); - V8::SetAccessor(isolate, tpl, "isDestroyed", &IsDestroyedGetter); - V8::SetAccessor(isolate, tpl, "driver", &DriverGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "speed").ToLocalChecked(), &SpeedGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "gear").ToLocalChecked(), &GearGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rpm").ToLocalChecked(), &RPMGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "wheelsCount").ToLocalChecked(), &WheelsCountGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "speedVector").ToLocalChecked(), &SpeedVectorGetter); + // proto->SetAccessor(v8::String::NewFromUtf8(isolate, "gravity", &GravityGetter).ToLocalChecked(), &GravitySetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handling").ToLocalChecked(), &HandlingGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isDestroyed").ToLocalChecked(), &IsDestroyedGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driver").ToLocalChecked(), &DriverGetter); // Appearance getters - V8::SetAccessor(isolate, tpl, "modKitsCount", &ModKitsCountGetter); - V8::SetAccessor(isolate, tpl, "modKit", &ModKitGetter); - //V8::SetAccessor(isolate, tpl, "hasCustomPrimaryColor", &IsPrimaryColorRGBGetter); - V8::SetAccessor(isolate, tpl, "primaryColor", &PrimaryColorGetter); - V8::SetAccessor(isolate, tpl, "customPrimaryColor", &PrimaryColorRGBGetter); - //V8::SetAccessor(isolate, tpl, "hasCustomSecondaryColor", &IsSecondaryColorRGBGetter); - V8::SetAccessor(isolate, tpl, "secondaryColor", &SecondaryColorGetter); - V8::SetAccessor(isolate, tpl, "customSecondaryColor", &SecondaryColorRGBGetter); - V8::SetAccessor(isolate, tpl, "pearlColor", &PearlColorGetter); - V8::SetAccessor(isolate, tpl, "wheelColor", &WheelColorGetter); - V8::SetAccessor(isolate, tpl, "interiorColor", &InteriorColorGetter); - V8::SetAccessor(isolate, tpl, "dashboardColor", &DashboardColorGetter); - //V8::SetAccessor(isolate, tpl, "hasCustomTireSmokeColor", &IsTireSmokeColorCustomGetter); - V8::SetAccessor(isolate, tpl, "tireSmokeColor", &TireSmokeColorGetter); - V8::SetAccessor(isolate, tpl, "wheelType", &WheelTypeGetter); - V8::SetAccessor(isolate, tpl, "frontWheels", &WheelVariationGetter); - V8::SetAccessor(isolate, tpl, "rearWheels", &RearWheelVariationGetter); - V8::SetAccessor(isolate, tpl, "customTires", &IsCustomTiresGetter); - V8::SetAccessor(isolate, tpl, "darkness", &SpecialDarknessGetter); - V8::SetAccessor(isolate, tpl, "numberPlateIndex", &NumberplateIndexGetter); - V8::SetAccessor(isolate, tpl, "numberPlateText", &NumberplateTextGetter); - V8::SetAccessor(isolate, tpl, "windowTint", &WindowTintGetter); - V8::SetAccessor(isolate, tpl, "dirtLevel", &DirtLevelGetter); - //V8::SetAccessor(isolate, tpl, "neonActive", &IsNeonActiveGetter); - V8::SetAccessor(isolate, tpl, "neon", &NeonGetter); - V8::SetAccessor(isolate, tpl, "neonColor", &NeonColorGetter); - V8::SetAccessor(isolate, tpl, "livery", &LiveryGetter); - V8::SetAccessor(isolate, tpl, "roofLivery", &RoofLiveryGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modKitsCount").ToLocalChecked(), &ModKitsCountGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modKit").ToLocalChecked(), &ModKitGetter); + //proto->SetAccessor(v8::String::NewFromUtf8(isolate, "hasCustomPrimaryColor").ToLocalChecked(), &IsPrimaryColorRGBGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "primaryColor").ToLocalChecked(), &PrimaryColorGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "customPrimaryColor").ToLocalChecked(), &PrimaryColorRGBGetter); + //proto->SetAccessor(v8::String::NewFromUtf8(isolate, "hasCustomSecondaryColor").ToLocalChecked(), &IsSecondaryColorRGBGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "secondaryColor").ToLocalChecked(), &SecondaryColorGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "customSecondaryColor").ToLocalChecked(), &SecondaryColorRGBGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "pearlColor").ToLocalChecked(), &PearlColorGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "wheelColor").ToLocalChecked(), &WheelColorGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "interiorColor").ToLocalChecked(), &InteriorColorGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "dashboardColor").ToLocalChecked(), &DashboardColorGetter); + //proto->SetAccessor(v8::String::NewFromUtf8(isolate, "hasCustomTireSmokeColor").ToLocalChecked(), &IsTireSmokeColorCustomGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tireSmokeColor").ToLocalChecked(), &TireSmokeColorGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "wheelType").ToLocalChecked(), &WheelTypeGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "frontWheels").ToLocalChecked(), &WheelVariationGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rearWheels").ToLocalChecked(), &RearWheelVariationGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "customTires").ToLocalChecked(), &IsCustomTiresGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "darkness").ToLocalChecked(), &SpecialDarknessGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "numberPlateIndex").ToLocalChecked(), &NumberplateIndexGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "numberPlateText").ToLocalChecked(), &NumberplateTextGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "windowTint").ToLocalChecked(), &WindowTintGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "dirtLevel").ToLocalChecked(), &DirtLevelGetter); + //proto->SetAccessor(v8::String::NewFromUtf8(isolate, "neonActive").ToLocalChecked(), &IsNeonActiveGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "neon").ToLocalChecked(), &NeonGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "neonColor").ToLocalChecked(), &NeonColorGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "livery").ToLocalChecked(), &LiveryGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "roofLivery").ToLocalChecked(), &RoofLiveryGetter); // Gamestate getters - V8::SetAccessor(isolate, tpl, "engineOn", &EngineOnGetter); - V8::SetAccessor(isolate, tpl, "handbrakeActive", &HandbrakeActiveGetter); - V8::SetAccessor(isolate, tpl, "headlightColor", &HeadlightColorGetter); - V8::SetAccessor(isolate, tpl, "activeRadioStation", &RadioStationIndexGetter); - V8::SetAccessor(isolate, tpl, "sirenActive", &IsSirenActiveGetter); - V8::SetAccessor(isolate, tpl, "lockState", &LockStateGetter); - V8::SetAccessor(isolate, tpl, "daylightOn", &IsDaylightOnGetter); - V8::SetAccessor(isolate, tpl, "nightlightOn", &IsNightlightOnGetter); - V8::SetAccessor(isolate, tpl, "roofState", &RoofStateGetter); - V8::SetAccessor(isolate, tpl, "flamethrowerActive", &IsFlamethrowerActiveGetter); - V8::SetAccessor(isolate, tpl, "lightsMultiplier", &LightsMultiplierGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "engineOn").ToLocalChecked(), &EngineOnGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handbrakeActive").ToLocalChecked(), &HandbrakeActiveGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "headlightColor").ToLocalChecked(), &HeadlightColorGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "activeRadioStation").ToLocalChecked(), &RadioStationIndexGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "sirenActive").ToLocalChecked(), &IsSirenActiveGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lockState").ToLocalChecked(), &LockStateGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "daylightOn").ToLocalChecked(), &IsDaylightOnGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "nightlightOn").ToLocalChecked(), &IsNightlightOnGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "roofState").ToLocalChecked(), &RoofStateGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "flamethrowerActive").ToLocalChecked(), &IsFlamethrowerActiveGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lightsMultiplier").ToLocalChecked(), &LightsMultiplierGetter); // Health getters - V8::SetAccessor(isolate, tpl, "engineHealth", &EngineHealthGetter); - V8::SetAccessor(isolate, tpl, "petrolTankHealth", &PetrolTankHealthGetter); - V8::SetAccessor(isolate, tpl, "repairsCount", &RepairsCountGetter); - V8::SetAccessor(isolate, tpl, "bodyHealth", &BodyHealthGetter); - V8::SetAccessor(isolate, tpl, "bodyAdditionalHealth", &BodyAdditionalHealthGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "engineHealth").ToLocalChecked(), &EngineHealthGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "petrolTankHealth").ToLocalChecked(), &PetrolTankHealthGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "repairsCount").ToLocalChecked(), &RepairsCountGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "bodyHealth").ToLocalChecked(), &BodyHealthGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "bodyAdditionalHealth").ToLocalChecked(), &BodyAdditionalHealthGetter); // Damage getters - V8::SetAccessor(isolate, tpl, "hasArmoredWindows", &HasArmoredWindowsGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "hasArmoredWindows").ToLocalChecked(), &HasArmoredWindowsGetter); // Script getters - V8::SetAccessor(isolate, tpl, "manualEngineControl", &IsManualEngineControlGetter); - //V8::SetAccessor(isolate, tpl, "handlingModified", &IsHandlingModifiedGetter); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "manualEngineControl").ToLocalChecked(), &IsManualEngineControlGetter); + //proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingModified").ToLocalChecked(), &IsHandlingModifiedGetter); }); From fff72b2942661119299b7f5ea4defb885ef90fe7 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 14 Nov 2020 15:01:08 +0100 Subject: [PATCH 076/564] Updated classes to use better V8::SetAccessor method --- src/bindings/Handling.cpp | 132 +++++++++++++++++----------------- src/bindings/HandlingData.cpp | 132 +++++++++++++++++----------------- src/bindings/Player.cpp | 48 ++++++------- src/bindings/Vehicle.cpp | 110 ++++++++++++++-------------- 4 files changed, 211 insertions(+), 211 deletions(-) diff --git a/src/bindings/Handling.cpp b/src/bindings/Handling.cpp index 2ba8f624..7e8b09d4 100644 --- a/src/bindings/Handling.cpp +++ b/src/bindings/Handling.cpp @@ -1985,70 +1985,70 @@ extern V8Class v8Handling( proto->Set(isolate, "isModified", v8::FunctionTemplate::New(isolate, &IsModified)); proto->Set(isolate, "reset", v8::FunctionTemplate::New(isolate, &Reset)); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingNameHash").ToLocalChecked(), &HandlingNameHashGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "mass").ToLocalChecked(), &MassGetter, &MassSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDragCoeff").ToLocalChecked(), &InitialDragCoeffGetter, &InitialDragCoeffSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "downforceModifier").ToLocalChecked(), &DownforceModifierGetter, &DownforceModifierSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat1").ToLocalChecked(), &unkFloat1Getter, &unkFloat1Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat2").ToLocalChecked(), &unkFloat2Getter, &unkFloat2Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "centreOfMassOffset").ToLocalChecked(), &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "inertiaMultiplier").ToLocalChecked(), &InertiaMultiplierGetter, &InertiaMultiplierSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmerged").ToLocalChecked(), &PercentSubmergedGetter, &PercentSubmergedSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmergedRatio").ToLocalChecked(), &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveBiasFront").ToLocalChecked(), &DriveBiasFrontGetter, &DriveBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "acceleration").ToLocalChecked(), &AccelerationGetter, &AccelerationSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveGears").ToLocalChecked(), &InitialDriveGearsGetter, &InitialDriveGearsSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveInertia").ToLocalChecked(), &DriveInertiaGetter, &DriveInertiaSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleUpShift").ToLocalChecked(), &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleDownShift").ToLocalChecked(), &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveForce").ToLocalChecked(), &InitialDriveForceGetter, &InitialDriveForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveMaxFlatVel").ToLocalChecked(), &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveMaxFlatVel").ToLocalChecked(), &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeForce").ToLocalChecked(), &BrakeForceGetter, &BrakeForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat4").ToLocalChecked(), &unkFloat4Getter, &unkFloat4Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasFront").ToLocalChecked(), &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasRear").ToLocalChecked(), &BrakeBiasRearGetter, &BrakeBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handBrakeForce").ToLocalChecked(), &HandBrakeForceGetter, &HandBrakeForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLock").ToLocalChecked(), &SteeringLockGetter, &SteeringLockSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLockRatio").ToLocalChecked(), &SteeringLockRatioGetter, &SteeringLockRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMax").ToLocalChecked(), &TractionCurveMaxGetter, &TractionCurveMaxSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMaxRatio").ToLocalChecked(), &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMin").ToLocalChecked(), &TractionCurveMinGetter, &TractionCurveMinSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMinRatio").ToLocalChecked(), &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateral").ToLocalChecked(), &TractionCurveLateralGetter, &TractionCurveLateralSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateralRatio").ToLocalChecked(), &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMax").ToLocalChecked(), &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMaxRatio").ToLocalChecked(), &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lowSpeedTractionLossMult").ToLocalChecked(), &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "camberStiffnesss").ToLocalChecked(), &CamberStiffnesssGetter, &CamberStiffnesssSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasFront").ToLocalChecked(), &TractionBiasFrontGetter, &TractionBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasRear").ToLocalChecked(), &TractionBiasRearGetter, &TractionBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionLossMult").ToLocalChecked(), &TractionLossMultGetter, &TractionLossMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionForce").ToLocalChecked(), &SuspensionForceGetter, &SuspensionForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionCompDamp").ToLocalChecked(), &SuspensionCompDampGetter, &SuspensionCompDampSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionReboundDamp").ToLocalChecked(), &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionUpperLimit").ToLocalChecked(), &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionLowerLimit").ToLocalChecked(), &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionRaise").ToLocalChecked(), &SuspensionRaiseGetter, &SuspensionRaiseSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasFront").ToLocalChecked(), &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasRear").ToLocalChecked(), &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarForce").ToLocalChecked(), &AntiRollBarForceGetter, &AntiRollBarForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasFront").ToLocalChecked(), &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasRear").ToLocalChecked(), &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightFront").ToLocalChecked(), &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightRear").ToLocalChecked(), &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "collisionDamageMult").ToLocalChecked(), &CollisionDamageMultGetter, &CollisionDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "weaponDamageMult").ToLocalChecked(), &WeaponDamageMultGetter, &WeaponDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "deformationDamageMult").ToLocalChecked(), &DeformationDamageMultGetter, &DeformationDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "engineDamageMult").ToLocalChecked(), &EngineDamageMultGetter, &EngineDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "petrolTankVolume").ToLocalChecked(), &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "oilVolume").ToLocalChecked(), &OilVolumeGetter, &OilVolumeSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat5").ToLocalChecked(), &unkFloat5Getter, &unkFloat5Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistX").ToLocalChecked(), &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistY").ToLocalChecked(), &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistZ").ToLocalChecked(), &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "monetaryValue").ToLocalChecked(), &MonetaryValueGetter, &MonetaryValueSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modelFlags").ToLocalChecked(), &ModelFlagsGetter, &ModelFlagsSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingFlags").ToLocalChecked(), &HandlingFlagsGetter, &HandlingFlagsSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "damageFlags").ToLocalChecked(), &DamageFlagsGetter, &DamageFlagsSetter); + V8::SetAccessor(isolate, tpl, "handlingNameHash", &HandlingNameHashGetter); + V8::SetAccessor(isolate, tpl, "mass", &MassGetter, &MassSetter); + V8::SetAccessor(isolate, tpl, "initialDragCoeff", &InitialDragCoeffGetter, &InitialDragCoeffSetter); + V8::SetAccessor(isolate, tpl, "downforceModifier", &DownforceModifierGetter, &DownforceModifierSetter); + V8::SetAccessor(isolate, tpl, "unkFloat1", &unkFloat1Getter, &unkFloat1Setter); + V8::SetAccessor(isolate, tpl, "unkFloat2", &unkFloat2Getter, &unkFloat2Setter); + V8::SetAccessor(isolate, tpl, "centreOfMassOffset", &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); + V8::SetAccessor(isolate, tpl, "inertiaMultiplier", &InertiaMultiplierGetter, &InertiaMultiplierSetter); + V8::SetAccessor(isolate, tpl, "percentSubmerged", &PercentSubmergedGetter, &PercentSubmergedSetter); + V8::SetAccessor(isolate, tpl, "percentSubmergedRatio", &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); + V8::SetAccessor(isolate, tpl, "driveBiasFront", &DriveBiasFrontGetter, &DriveBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "acceleration", &AccelerationGetter, &AccelerationSetter); + V8::SetAccessor(isolate, tpl, "initialDriveGears", &InitialDriveGearsGetter, &InitialDriveGearsSetter); + V8::SetAccessor(isolate, tpl, "driveInertia", &DriveInertiaGetter, &DriveInertiaSetter); + V8::SetAccessor(isolate, tpl, "clutchChangeRateScaleUpShift", &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); + V8::SetAccessor(isolate, tpl, "clutchChangeRateScaleDownShift", &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); + V8::SetAccessor(isolate, tpl, "initialDriveForce", &InitialDriveForceGetter, &InitialDriveForceSetter); + V8::SetAccessor(isolate, tpl, "driveMaxFlatVel", &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); + V8::SetAccessor(isolate, tpl, "initialDriveMaxFlatVel", &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); + V8::SetAccessor(isolate, tpl, "brakeForce", &BrakeForceGetter, &BrakeForceSetter); + V8::SetAccessor(isolate, tpl, "unkFloat4", &unkFloat4Getter, &unkFloat4Setter); + V8::SetAccessor(isolate, tpl, "brakeBiasFront", &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "brakeBiasRear", &BrakeBiasRearGetter, &BrakeBiasRearSetter); + V8::SetAccessor(isolate, tpl, "handBrakeForce", &HandBrakeForceGetter, &HandBrakeForceSetter); + V8::SetAccessor(isolate, tpl, "steeringLock", &SteeringLockGetter, &SteeringLockSetter); + V8::SetAccessor(isolate, tpl, "steeringLockRatio", &SteeringLockRatioGetter, &SteeringLockRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMax", &TractionCurveMaxGetter, &TractionCurveMaxSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMaxRatio", &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMin", &TractionCurveMinGetter, &TractionCurveMinSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMinRatio", &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveLateral", &TractionCurveLateralGetter, &TractionCurveLateralSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveLateralRatio", &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionSpringDeltaMax", &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); + V8::SetAccessor(isolate, tpl, "tractionSpringDeltaMaxRatio", &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); + V8::SetAccessor(isolate, tpl, "lowSpeedTractionLossMult", &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); + V8::SetAccessor(isolate, tpl, "camberStiffnesss", &CamberStiffnesssGetter, &CamberStiffnesssSetter); + V8::SetAccessor(isolate, tpl, "tractionBiasFront", &TractionBiasFrontGetter, &TractionBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "tractionBiasRear", &TractionBiasRearGetter, &TractionBiasRearSetter); + V8::SetAccessor(isolate, tpl, "tractionLossMult", &TractionLossMultGetter, &TractionLossMultSetter); + V8::SetAccessor(isolate, tpl, "suspensionForce", &SuspensionForceGetter, &SuspensionForceSetter); + V8::SetAccessor(isolate, tpl, "suspensionCompDamp", &SuspensionCompDampGetter, &SuspensionCompDampSetter); + V8::SetAccessor(isolate, tpl, "suspensionReboundDamp", &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); + V8::SetAccessor(isolate, tpl, "suspensionUpperLimit", &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); + V8::SetAccessor(isolate, tpl, "suspensionLowerLimit", &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); + V8::SetAccessor(isolate, tpl, "suspensionRaise", &SuspensionRaiseGetter, &SuspensionRaiseSetter); + V8::SetAccessor(isolate, tpl, "suspensionBiasFront", &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "suspensionBiasRear", &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarForce", &AntiRollBarForceGetter, &AntiRollBarForceSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarBiasFront", &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarBiasRear", &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); + V8::SetAccessor(isolate, tpl, "rollCentreHeightFront", &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); + V8::SetAccessor(isolate, tpl, "rollCentreHeightRear", &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); + V8::SetAccessor(isolate, tpl, "collisionDamageMult", &CollisionDamageMultGetter, &CollisionDamageMultSetter); + V8::SetAccessor(isolate, tpl, "weaponDamageMult", &WeaponDamageMultGetter, &WeaponDamageMultSetter); + V8::SetAccessor(isolate, tpl, "deformationDamageMult", &DeformationDamageMultGetter, &DeformationDamageMultSetter); + V8::SetAccessor(isolate, tpl, "engineDamageMult", &EngineDamageMultGetter, &EngineDamageMultSetter); + V8::SetAccessor(isolate, tpl, "petrolTankVolume", &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); + V8::SetAccessor(isolate, tpl, "oilVolume", &OilVolumeGetter, &OilVolumeSetter); + V8::SetAccessor(isolate, tpl, "unkFloat5", &unkFloat5Getter, &unkFloat5Setter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistX", &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistY", &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistZ", &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); + V8::SetAccessor(isolate, tpl, "monetaryValue", &MonetaryValueGetter, &MonetaryValueSetter); + V8::SetAccessor(isolate, tpl, "modelFlags", &ModelFlagsGetter, &ModelFlagsSetter); + V8::SetAccessor(isolate, tpl, "handlingFlags", &HandlingFlagsGetter, &HandlingFlagsSetter); + V8::SetAccessor(isolate, tpl, "damageFlags", &DamageFlagsGetter, &DamageFlagsSetter); }); \ No newline at end of file diff --git a/src/bindings/HandlingData.cpp b/src/bindings/HandlingData.cpp index 34408e4f..415aaf11 100644 --- a/src/bindings/HandlingData.cpp +++ b/src/bindings/HandlingData.cpp @@ -1704,70 +1704,70 @@ extern V8Class v8HandlingData( tpl->Set(isolate, "getForHandlingName", v8::FunctionTemplate::New(isolate, &GetForHandlingName)); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingNameHash").ToLocalChecked(), &HandlingNameHashGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "mass").ToLocalChecked(), &MassGetter, &MassSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDragCoeff").ToLocalChecked(), &InitialDragCoeffGetter, &InitialDragCoeffSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "downforceModifier").ToLocalChecked(), &DownforceModifierGetter, &DownforceModifierSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat1").ToLocalChecked(), &unkFloat1Getter, &unkFloat1Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat2").ToLocalChecked(), &unkFloat2Getter, &unkFloat2Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "centreOfMassOffset").ToLocalChecked(), &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "inertiaMultiplier").ToLocalChecked(), &InertiaMultiplierGetter, &InertiaMultiplierSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmerged").ToLocalChecked(), &PercentSubmergedGetter, &PercentSubmergedSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmergedRatio").ToLocalChecked(), &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveBiasFront").ToLocalChecked(), &DriveBiasFrontGetter, &DriveBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "acceleration").ToLocalChecked(), &AccelerationGetter, &AccelerationSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveGears").ToLocalChecked(), &InitialDriveGearsGetter, &InitialDriveGearsSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveInertia").ToLocalChecked(), &DriveInertiaGetter, &DriveInertiaSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleUpShift").ToLocalChecked(), &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleDownShift").ToLocalChecked(), &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveForce").ToLocalChecked(), &InitialDriveForceGetter, &InitialDriveForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveMaxFlatVel").ToLocalChecked(), &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveMaxFlatVel").ToLocalChecked(), &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeForce").ToLocalChecked(), &BrakeForceGetter, &BrakeForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat4").ToLocalChecked(), &unkFloat4Getter, &unkFloat4Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasFront").ToLocalChecked(), &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasRear").ToLocalChecked(), &BrakeBiasRearGetter, &BrakeBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handBrakeForce").ToLocalChecked(), &HandBrakeForceGetter, &HandBrakeForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLock").ToLocalChecked(), &SteeringLockGetter, &SteeringLockSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLockRatio").ToLocalChecked(), &SteeringLockRatioGetter, &SteeringLockRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMax").ToLocalChecked(), &TractionCurveMaxGetter, &TractionCurveMaxSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMaxRatio").ToLocalChecked(), &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMin").ToLocalChecked(), &TractionCurveMinGetter, &TractionCurveMinSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMinRatio").ToLocalChecked(), &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateral").ToLocalChecked(), &TractionCurveLateralGetter, &TractionCurveLateralSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateralRatio").ToLocalChecked(), &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMax").ToLocalChecked(), &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMaxRatio").ToLocalChecked(), &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lowSpeedTractionLossMult").ToLocalChecked(), &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "camberStiffnesss").ToLocalChecked(), &CamberStiffnesssGetter, &CamberStiffnesssSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasFront").ToLocalChecked(), &TractionBiasFrontGetter, &TractionBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasRear").ToLocalChecked(), &TractionBiasRearGetter, &TractionBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionLossMult").ToLocalChecked(), &TractionLossMultGetter, &TractionLossMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionForce").ToLocalChecked(), &SuspensionForceGetter, &SuspensionForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionCompDamp").ToLocalChecked(), &SuspensionCompDampGetter, &SuspensionCompDampSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionReboundDamp").ToLocalChecked(), &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionUpperLimit").ToLocalChecked(), &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionLowerLimit").ToLocalChecked(), &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionRaise").ToLocalChecked(), &SuspensionRaiseGetter, &SuspensionRaiseSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasFront").ToLocalChecked(), &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasRear").ToLocalChecked(), &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarForce").ToLocalChecked(), &AntiRollBarForceGetter, &AntiRollBarForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasFront").ToLocalChecked(), &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasRear").ToLocalChecked(), &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightFront").ToLocalChecked(), &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightRear").ToLocalChecked(), &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "collisionDamageMult").ToLocalChecked(), &CollisionDamageMultGetter, &CollisionDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "weaponDamageMult").ToLocalChecked(), &WeaponDamageMultGetter, &WeaponDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "deformationDamageMult").ToLocalChecked(), &DeformationDamageMultGetter, &DeformationDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "engineDamageMult").ToLocalChecked(), &EngineDamageMultGetter, &EngineDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "petrolTankVolume").ToLocalChecked(), &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "oilVolume").ToLocalChecked(), &OilVolumeGetter, &OilVolumeSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat5").ToLocalChecked(), &unkFloat5Getter, &unkFloat5Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistX").ToLocalChecked(), &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistY").ToLocalChecked(), &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistZ").ToLocalChecked(), &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "monetaryValue").ToLocalChecked(), &MonetaryValueGetter, &MonetaryValueSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modelFlags").ToLocalChecked(), &ModelFlagsGetter, &ModelFlagsSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingFlags").ToLocalChecked(), &HandlingFlagsGetter, &HandlingFlagsSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "damageFlags").ToLocalChecked(), &DamageFlagsGetter, &DamageFlagsSetter); + V8::SetAccessor(isolate, tpl, "handlingNameHash", &HandlingNameHashGetter); + V8::SetAccessor(isolate, tpl, "mass", &MassGetter, &MassSetter); + V8::SetAccessor(isolate, tpl, "initialDragCoeff", &InitialDragCoeffGetter, &InitialDragCoeffSetter); + V8::SetAccessor(isolate, tpl, "downforceModifier", &DownforceModifierGetter, &DownforceModifierSetter); + V8::SetAccessor(isolate, tpl, "unkFloat1", &unkFloat1Getter, &unkFloat1Setter); + V8::SetAccessor(isolate, tpl, "unkFloat2", &unkFloat2Getter, &unkFloat2Setter); + V8::SetAccessor(isolate, tpl, "centreOfMassOffset", &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); + V8::SetAccessor(isolate, tpl, "inertiaMultiplier", &InertiaMultiplierGetter, &InertiaMultiplierSetter); + V8::SetAccessor(isolate, tpl, "percentSubmerged", &PercentSubmergedGetter, &PercentSubmergedSetter); + V8::SetAccessor(isolate, tpl, "percentSubmergedRatio", &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); + V8::SetAccessor(isolate, tpl, "driveBiasFront", &DriveBiasFrontGetter, &DriveBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "acceleration", &AccelerationGetter, &AccelerationSetter); + V8::SetAccessor(isolate, tpl, "initialDriveGears", &InitialDriveGearsGetter, &InitialDriveGearsSetter); + V8::SetAccessor(isolate, tpl, "driveInertia", &DriveInertiaGetter, &DriveInertiaSetter); + V8::SetAccessor(isolate, tpl, "clutchChangeRateScaleUpShift", &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); + V8::SetAccessor(isolate, tpl, "clutchChangeRateScaleDownShift", &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); + V8::SetAccessor(isolate, tpl, "initialDriveForce", &InitialDriveForceGetter, &InitialDriveForceSetter); + V8::SetAccessor(isolate, tpl, "driveMaxFlatVel", &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); + V8::SetAccessor(isolate, tpl, "initialDriveMaxFlatVel", &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); + V8::SetAccessor(isolate, tpl, "brakeForce", &BrakeForceGetter, &BrakeForceSetter); + V8::SetAccessor(isolate, tpl, "unkFloat4", &unkFloat4Getter, &unkFloat4Setter); + V8::SetAccessor(isolate, tpl, "brakeBiasFront", &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "brakeBiasRear", &BrakeBiasRearGetter, &BrakeBiasRearSetter); + V8::SetAccessor(isolate, tpl, "handBrakeForce", &HandBrakeForceGetter, &HandBrakeForceSetter); + V8::SetAccessor(isolate, tpl, "steeringLock", &SteeringLockGetter, &SteeringLockSetter); + V8::SetAccessor(isolate, tpl, "steeringLockRatio", &SteeringLockRatioGetter, &SteeringLockRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMax", &TractionCurveMaxGetter, &TractionCurveMaxSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMaxRatio", &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMin", &TractionCurveMinGetter, &TractionCurveMinSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMinRatio", &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveLateral", &TractionCurveLateralGetter, &TractionCurveLateralSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveLateralRatio", &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionSpringDeltaMax", &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); + V8::SetAccessor(isolate, tpl, "tractionSpringDeltaMaxRatio", &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); + V8::SetAccessor(isolate, tpl, "lowSpeedTractionLossMult", &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); + V8::SetAccessor(isolate, tpl, "camberStiffnesss", &CamberStiffnesssGetter, &CamberStiffnesssSetter); + V8::SetAccessor(isolate, tpl, "tractionBiasFront", &TractionBiasFrontGetter, &TractionBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "tractionBiasRear", &TractionBiasRearGetter, &TractionBiasRearSetter); + V8::SetAccessor(isolate, tpl, "tractionLossMult", &TractionLossMultGetter, &TractionLossMultSetter); + V8::SetAccessor(isolate, tpl, "suspensionForce", &SuspensionForceGetter, &SuspensionForceSetter); + V8::SetAccessor(isolate, tpl, "suspensionCompDamp", &SuspensionCompDampGetter, &SuspensionCompDampSetter); + V8::SetAccessor(isolate, tpl, "suspensionReboundDamp", &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); + V8::SetAccessor(isolate, tpl, "suspensionUpperLimit", &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); + V8::SetAccessor(isolate, tpl, "suspensionLowerLimit", &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); + V8::SetAccessor(isolate, tpl, "suspensionRaise", &SuspensionRaiseGetter, &SuspensionRaiseSetter); + V8::SetAccessor(isolate, tpl, "suspensionBiasFront", &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "suspensionBiasRear", &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarForce", &AntiRollBarForceGetter, &AntiRollBarForceSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarBiasFront", &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarBiasRear", &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); + V8::SetAccessor(isolate, tpl, "rollCentreHeightFront", &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); + V8::SetAccessor(isolate, tpl, "rollCentreHeightRear", &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); + V8::SetAccessor(isolate, tpl, "collisionDamageMult", &CollisionDamageMultGetter, &CollisionDamageMultSetter); + V8::SetAccessor(isolate, tpl, "weaponDamageMult", &WeaponDamageMultGetter, &WeaponDamageMultSetter); + V8::SetAccessor(isolate, tpl, "deformationDamageMult", &DeformationDamageMultGetter, &DeformationDamageMultSetter); + V8::SetAccessor(isolate, tpl, "engineDamageMult", &EngineDamageMultGetter, &EngineDamageMultSetter); + V8::SetAccessor(isolate, tpl, "petrolTankVolume", &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); + V8::SetAccessor(isolate, tpl, "oilVolume", &OilVolumeGetter, &OilVolumeSetter); + V8::SetAccessor(isolate, tpl, "unkFloat5", &unkFloat5Getter, &unkFloat5Setter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistX", &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistY", &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistZ", &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); + V8::SetAccessor(isolate, tpl, "monetaryValue", &MonetaryValueGetter, &MonetaryValueSetter); + V8::SetAccessor(isolate, tpl, "modelFlags", &ModelFlagsGetter, &ModelFlagsSetter); + V8::SetAccessor(isolate, tpl, "handlingFlags", &HandlingFlagsGetter, &HandlingFlagsSetter); + V8::SetAccessor(isolate, tpl, "damageFlags", &DamageFlagsGetter, &DamageFlagsSetter); }); diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index faa5ab0c..e457f211 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -466,34 +466,34 @@ extern V8Class v8Player("Player", v8Entity, [](v8::Local t tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, "local").ToLocalChecked(), &LocalGetter); // Common getters - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "name").ToLocalChecked(), &NameGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "vehicle").ToLocalChecked(), &VehicleGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seat").ToLocalChecked(), &SeatGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isTalking").ToLocalChecked(), &TalkingGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "micLevel").ToLocalChecked(), &MicLevelGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "health").ToLocalChecked(), &HealthGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "maxHealth").ToLocalChecked(), &MaxHealthGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "armour").ToLocalChecked(), &ArmourGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "maxArmour").ToLocalChecked(), &MaxArmourGetter); + V8::SetAccessor(isolate, tpl, "name", &NameGetter); + V8::SetAccessor(isolate, tpl, "vehicle", &VehicleGetter); + V8::SetAccessor(isolate, tpl, "seat", &SeatGetter); + V8::SetAccessor(isolate, tpl, "isTalking", &TalkingGetter); + V8::SetAccessor(isolate, tpl, "micLevel", &MicLevelGetter); + V8::SetAccessor(isolate, tpl, "health", &HealthGetter); + V8::SetAccessor(isolate, tpl, "maxHealth", &MaxHealthGetter); + V8::SetAccessor(isolate, tpl, "armour", &ArmourGetter); + V8::SetAccessor(isolate, tpl, "maxArmour", &MaxArmourGetter); // Weapon getters - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "currentWeaponComponents").ToLocalChecked(), &CurrentWeaponComponentsGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "currentWeaponTintIndex").ToLocalChecked(), &CurrentWeaponTintIndexGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "currentWeapon").ToLocalChecked(), &CurrentWeaponGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "entityAimingAt").ToLocalChecked(), &EntityAimingAtGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "entityAimOffset").ToLocalChecked(), &EntityAimOffsetGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "flashlightActive").ToLocalChecked(), &FlashlightActiveGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "aimPos").ToLocalChecked(), &AimPosGetter); + V8::SetAccessor(isolate, tpl, "currentWeaponComponents", &CurrentWeaponComponentsGetter); + V8::SetAccessor(isolate, tpl, "currentWeaponTintIndex", &CurrentWeaponTintIndexGetter); + V8::SetAccessor(isolate, tpl, "currentWeapon", &CurrentWeaponGetter); + V8::SetAccessor(isolate, tpl, "entityAimingAt", &EntityAimingAtGetter); + V8::SetAccessor(isolate, tpl, "entityAimOffset", &EntityAimOffsetGetter); + V8::SetAccessor(isolate, tpl, "flashlightActive", &FlashlightActiveGetter); + V8::SetAccessor(isolate, tpl, "aimPos", &AimPosGetter); // Gamestate getters - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isJumping").ToLocalChecked(), &IsJumpingGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isInRagdoll").ToLocalChecked(), &IsInRagdollGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isAiming").ToLocalChecked(), &IsAimingGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isShooting").ToLocalChecked(), &IsShootingGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isReloading").ToLocalChecked(), &IsReloadingGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isDead").ToLocalChecked(), &IsDeadGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "moveSpeed").ToLocalChecked(), &MoveSpeedGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "headRot").ToLocalChecked(), &HeadRotationGetter); + V8::SetAccessor(isolate, tpl, "isJumping", &IsJumpingGetter); + V8::SetAccessor(isolate, tpl, "isInRagdoll", &IsInRagdollGetter); + V8::SetAccessor(isolate, tpl, "isAiming", &IsAimingGetter); + V8::SetAccessor(isolate, tpl, "isShooting", &IsShootingGetter); + V8::SetAccessor(isolate, tpl, "isReloading", &IsReloadingGetter); + V8::SetAccessor(isolate, tpl, "isDead", &IsDeadGetter); + V8::SetAccessor(isolate, tpl, "moveSpeed", &MoveSpeedGetter); + V8::SetAccessor(isolate, tpl, "headRot", &HeadRotationGetter); /* if (alt::ICore::Instance().IsSandbox()) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 2991bd99..9ed2d6b7 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -550,70 +550,70 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetStaticAccessor(isolate, tpl, "all", &AllGetter); // Common getters - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "speed").ToLocalChecked(), &SpeedGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "gear").ToLocalChecked(), &GearGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rpm").ToLocalChecked(), &RPMGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "wheelsCount").ToLocalChecked(), &WheelsCountGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "speedVector").ToLocalChecked(), &SpeedVectorGetter); + V8::SetAccessor(isolate, tpl, "speed", &SpeedGetter); + V8::SetAccessor(isolate, tpl, "gear", &GearGetter); + V8::SetAccessor(isolate, tpl, "rpm", &RPMGetter); + V8::SetAccessor(isolate, tpl, "wheelsCount", &WheelsCountGetter); + V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); // proto->SetAccessor(v8::String::NewFromUtf8(isolate, "gravity", &GravityGetter).ToLocalChecked(), &GravitySetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handling").ToLocalChecked(), &HandlingGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isDestroyed").ToLocalChecked(), &IsDestroyedGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driver").ToLocalChecked(), &DriverGetter); + V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); + V8::SetAccessor(isolate, tpl, "isDestroyed", &IsDestroyedGetter); + V8::SetAccessor(isolate, tpl, "driver", &DriverGetter); // Appearance getters - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modKitsCount").ToLocalChecked(), &ModKitsCountGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modKit").ToLocalChecked(), &ModKitGetter); - //proto->SetAccessor(v8::String::NewFromUtf8(isolate, "hasCustomPrimaryColor").ToLocalChecked(), &IsPrimaryColorRGBGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "primaryColor").ToLocalChecked(), &PrimaryColorGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "customPrimaryColor").ToLocalChecked(), &PrimaryColorRGBGetter); - //proto->SetAccessor(v8::String::NewFromUtf8(isolate, "hasCustomSecondaryColor").ToLocalChecked(), &IsSecondaryColorRGBGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "secondaryColor").ToLocalChecked(), &SecondaryColorGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "customSecondaryColor").ToLocalChecked(), &SecondaryColorRGBGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "pearlColor").ToLocalChecked(), &PearlColorGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "wheelColor").ToLocalChecked(), &WheelColorGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "interiorColor").ToLocalChecked(), &InteriorColorGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "dashboardColor").ToLocalChecked(), &DashboardColorGetter); - //proto->SetAccessor(v8::String::NewFromUtf8(isolate, "hasCustomTireSmokeColor").ToLocalChecked(), &IsTireSmokeColorCustomGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tireSmokeColor").ToLocalChecked(), &TireSmokeColorGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "wheelType").ToLocalChecked(), &WheelTypeGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "frontWheels").ToLocalChecked(), &WheelVariationGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rearWheels").ToLocalChecked(), &RearWheelVariationGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "customTires").ToLocalChecked(), &IsCustomTiresGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "darkness").ToLocalChecked(), &SpecialDarknessGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "numberPlateIndex").ToLocalChecked(), &NumberplateIndexGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "numberPlateText").ToLocalChecked(), &NumberplateTextGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "windowTint").ToLocalChecked(), &WindowTintGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "dirtLevel").ToLocalChecked(), &DirtLevelGetter); - //proto->SetAccessor(v8::String::NewFromUtf8(isolate, "neonActive").ToLocalChecked(), &IsNeonActiveGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "neon").ToLocalChecked(), &NeonGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "neonColor").ToLocalChecked(), &NeonColorGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "livery").ToLocalChecked(), &LiveryGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "roofLivery").ToLocalChecked(), &RoofLiveryGetter); + V8::SetAccessor(isolate, tpl, "modKitsCount", &ModKitsCountGetter); + V8::SetAccessor(isolate, tpl, "modKit", &ModKitGetter); + //V8::SetAccessor(isolate, tpl, "hasCustomPrimaryColor", &IsPrimaryColorRGBGetter); + V8::SetAccessor(isolate, tpl, "primaryColor", &PrimaryColorGetter); + V8::SetAccessor(isolate, tpl, "customPrimaryColor", &PrimaryColorRGBGetter); + //V8::SetAccessor(isolate, tpl, "hasCustomSecondaryColor", &IsSecondaryColorRGBGetter); + V8::SetAccessor(isolate, tpl, "secondaryColor", &SecondaryColorGetter); + V8::SetAccessor(isolate, tpl, "customSecondaryColor", &SecondaryColorRGBGetter); + V8::SetAccessor(isolate, tpl, "pearlColor", &PearlColorGetter); + V8::SetAccessor(isolate, tpl, "wheelColor", &WheelColorGetter); + V8::SetAccessor(isolate, tpl, "interiorColor", &InteriorColorGetter); + V8::SetAccessor(isolate, tpl, "dashboardColor", &DashboardColorGetter); + //V8::SetAccessor(isolate, tpl, "hasCustomTireSmokeColor", &IsTireSmokeColorCustomGetter); + V8::SetAccessor(isolate, tpl, "tireSmokeColor", &TireSmokeColorGetter); + V8::SetAccessor(isolate, tpl, "wheelType", &WheelTypeGetter); + V8::SetAccessor(isolate, tpl, "frontWheels", &WheelVariationGetter); + V8::SetAccessor(isolate, tpl, "rearWheels", &RearWheelVariationGetter); + V8::SetAccessor(isolate, tpl, "customTires", &IsCustomTiresGetter); + V8::SetAccessor(isolate, tpl, "darkness", &SpecialDarknessGetter); + V8::SetAccessor(isolate, tpl, "numberPlateIndex", &NumberplateIndexGetter); + V8::SetAccessor(isolate, tpl, "numberPlateText", &NumberplateTextGetter); + V8::SetAccessor(isolate, tpl, "windowTint", &WindowTintGetter); + V8::SetAccessor(isolate, tpl, "dirtLevel", &DirtLevelGetter); + //V8::SetAccessor(isolate, tpl, "neonActive", &IsNeonActiveGetter); + V8::SetAccessor(isolate, tpl, "neon", &NeonGetter); + V8::SetAccessor(isolate, tpl, "neonColor", &NeonColorGetter); + V8::SetAccessor(isolate, tpl, "livery", &LiveryGetter); + V8::SetAccessor(isolate, tpl, "roofLivery", &RoofLiveryGetter); // Gamestate getters - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "engineOn").ToLocalChecked(), &EngineOnGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handbrakeActive").ToLocalChecked(), &HandbrakeActiveGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "headlightColor").ToLocalChecked(), &HeadlightColorGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "activeRadioStation").ToLocalChecked(), &RadioStationIndexGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "sirenActive").ToLocalChecked(), &IsSirenActiveGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lockState").ToLocalChecked(), &LockStateGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "daylightOn").ToLocalChecked(), &IsDaylightOnGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "nightlightOn").ToLocalChecked(), &IsNightlightOnGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "roofState").ToLocalChecked(), &RoofStateGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "flamethrowerActive").ToLocalChecked(), &IsFlamethrowerActiveGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lightsMultiplier").ToLocalChecked(), &LightsMultiplierGetter); + V8::SetAccessor(isolate, tpl, "engineOn", &EngineOnGetter); + V8::SetAccessor(isolate, tpl, "handbrakeActive", &HandbrakeActiveGetter); + V8::SetAccessor(isolate, tpl, "headlightColor", &HeadlightColorGetter); + V8::SetAccessor(isolate, tpl, "activeRadioStation", &RadioStationIndexGetter); + V8::SetAccessor(isolate, tpl, "sirenActive", &IsSirenActiveGetter); + V8::SetAccessor(isolate, tpl, "lockState", &LockStateGetter); + V8::SetAccessor(isolate, tpl, "daylightOn", &IsDaylightOnGetter); + V8::SetAccessor(isolate, tpl, "nightlightOn", &IsNightlightOnGetter); + V8::SetAccessor(isolate, tpl, "roofState", &RoofStateGetter); + V8::SetAccessor(isolate, tpl, "flamethrowerActive", &IsFlamethrowerActiveGetter); + V8::SetAccessor(isolate, tpl, "lightsMultiplier", &LightsMultiplierGetter); // Health getters - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "engineHealth").ToLocalChecked(), &EngineHealthGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "petrolTankHealth").ToLocalChecked(), &PetrolTankHealthGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "repairsCount").ToLocalChecked(), &RepairsCountGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "bodyHealth").ToLocalChecked(), &BodyHealthGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "bodyAdditionalHealth").ToLocalChecked(), &BodyAdditionalHealthGetter); + V8::SetAccessor(isolate, tpl, "engineHealth", &EngineHealthGetter); + V8::SetAccessor(isolate, tpl, "petrolTankHealth", &PetrolTankHealthGetter); + V8::SetAccessor(isolate, tpl, "repairsCount", &RepairsCountGetter); + V8::SetAccessor(isolate, tpl, "bodyHealth", &BodyHealthGetter); + V8::SetAccessor(isolate, tpl, "bodyAdditionalHealth", &BodyAdditionalHealthGetter); // Damage getters - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "hasArmoredWindows").ToLocalChecked(), &HasArmoredWindowsGetter); + V8::SetAccessor(isolate, tpl, "hasArmoredWindows", &HasArmoredWindowsGetter); // Script getters - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "manualEngineControl").ToLocalChecked(), &IsManualEngineControlGetter); - //proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingModified").ToLocalChecked(), &IsHandlingModifiedGetter); + V8::SetAccessor(isolate, tpl, "manualEngineControl", &IsManualEngineControlGetter); + //V8::SetAccessor(isolate, tpl, "handlingModified", &IsHandlingModifiedGetter); }); From 074dbd5bdf185cf185a32dc980eb2cf06215c0d1 Mon Sep 17 00:00:00 2001 From: Hazard Date: Sat, 14 Nov 2020 20:00:58 +0100 Subject: [PATCH 077/564] refs INative::Context --- src/bindings/V8Natives.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 02e5cc1c..0661c24e 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -59,7 +59,7 @@ static void *ToMemoryBuffer(v8::Local val, v8::Local ctx return nullptr; } -static void PushArg(alt::INative::Context *scrCtx, alt::INative::Type argType, v8::Isolate *isolate, v8::Local val) +static void PushArg(alt::Ref scrCtx, alt::INative::Type argType, v8::Isolate *isolate, v8::Local val) { using ArgType = alt::INative::Type; @@ -149,7 +149,7 @@ static void PushPointerReturn(alt::INative::Type argType, v8::Local r } } -static v8::Local GetReturn(alt::INative::Context *scrCtx, alt::INative::Type retnType, v8::Isolate *isolate) +static v8::Local GetReturn(alt::Ref scrCtx, alt::INative::Type retnType, v8::Isolate *isolate) { using ArgType = alt::INative::Type; @@ -193,7 +193,7 @@ static v8::Local GetReturn(alt::INative::Context *scrCtx, alt::INativ static void InvokeNative(const v8::FunctionCallbackInfo &info) { - static alt::INative::Context *ctx = alt::ICore::Instance().GetNativesContext(); + static auto ctx = alt::ICore::Instance().CreateNativesContext(); v8::Isolate *isolate = info.GetIsolate(); v8::Local v8Ctx = isolate->GetCurrentContext(); From 11b3017031ccc2633610418fcc98f67ed78f700c Mon Sep 17 00:00:00 2001 From: Hazard Date: Sun, 15 Nov 2020 11:14:15 +0100 Subject: [PATCH 078/564] Link to dynamic CRT (/MD) --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5765216..22d5aac0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ project(altv-client-js) # v8 message("alt:V JS - Fetching v8 deps, can take a while") FetchContent_Declare(altv-js-deps - URL https://github.com/altmp/altv-client-js/releases/download/deps/deps.zip + URL https://github.com/altmp/altv-client-js/releases/download/deps2/deps.zip ) FetchContent_Populate(altv-js-deps) set(ALTV_JS_DL_DEPS ${altv-js-deps_SOURCE_DIR}) @@ -79,8 +79,8 @@ set(ALTV_JS_DEFS -DV8_31BIT_SMIS_ON_64BIT_ARCH ) -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /Zi /bigobj") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /bigobj") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /Zi /bigobj") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /bigobj") set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG:FULL /OPT:REF /OPT:ICF") ## SHARED From 4d6d8a4990a65114054c4fb990a1a055adac9285 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 14 Nov 2020 17:44:22 +0100 Subject: [PATCH 079/564] turn into macro --- src/bindings/Blip.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index e26084b2..acaff3f6 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -5,7 +5,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.IsConstructCall(), "Blip constructor is not a function"); + V8_CHECK_CONSTRUCTOR(); V8_CHECK(false, "You can't use constructor of abstract class"); } From 7a0812d2c21512d71cd1c3e4951d5d26affa47a0 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sun, 15 Nov 2020 13:34:08 +0100 Subject: [PATCH 080/564] pass impl to natives --- src/CV8Resource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index cc3dd171..c6c0d43c 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -50,7 +50,7 @@ bool CV8ResourceImpl::Start() if (resource->GetMain().IsEmpty()) return false; - resource->EnableNatives(); + resource->EnableNatives(this); v8::Locker locker(isolate); v8::Isolate::Scope isolate_scope(isolate); From d1c2d4d1f8578987d9466d6480f5adfdd94d27ef Mon Sep 17 00:00:00 2001 From: Hazard Date: Mon, 16 Nov 2020 00:52:25 +0100 Subject: [PATCH 081/564] Fixed natives --- src/CV8Resource.cpp | 7 ++++--- src/bindings/V8Natives.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index c6c0d43c..a3a1e61b 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -50,7 +50,8 @@ bool CV8ResourceImpl::Start() if (resource->GetMain().IsEmpty()) return false; - resource->EnableNatives(this); + resource->EnableNatives(); + auto nscope = resource->PushNativesScope(); v8::Locker locker(isolate); v8::Isolate::Scope isolate_scope(isolate); @@ -158,7 +159,7 @@ bool CV8ResourceImpl::Stop() if (!context.IsEmpty()) { - resource->PushNativeUpdate(); + auto nscope = resource->PushNativesScope(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); @@ -174,7 +175,7 @@ bool CV8ResourceImpl::Stop() bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) { - resource->PushNativeUpdate(); + auto nscope = resource->PushNativesScope(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 0661c24e..1dd4f353 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -64,7 +64,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a using ArgType = alt::INative::Type; v8::Local v8Ctx = isolate->GetEnteredContext(); - + switch (argType) { case alt::INative::Type::ARG_BOOL: From 96c62031c33bd029bb565609caadc176af2708fa Mon Sep 17 00:00:00 2001 From: Hazard Date: Mon, 16 Nov 2020 03:52:27 +0100 Subject: [PATCH 082/564] Add LocalStorage.clear --- src/bindings/LocalStorage.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bindings/LocalStorage.cpp b/src/bindings/LocalStorage.cpp index 8710558f..4088975a 100644 --- a/src/bindings/LocalStorage.cpp +++ b/src/bindings/LocalStorage.cpp @@ -58,7 +58,7 @@ static void Delete(const v8::FunctionCallbackInfo &info) resource->GetLocalStorage()->Delete(key); } -static void DeleteAll(const v8::FunctionCallbackInfo &info) +static void Clear(const v8::FunctionCallbackInfo &info) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); @@ -90,6 +90,7 @@ extern V8Class v8LocalStorage( proto->Set(isolate, "get", v8::FunctionTemplate::New(isolate, &Get)); proto->Set(isolate, "set", v8::FunctionTemplate::New(isolate, &Set)); proto->Set(isolate, "delete", v8::FunctionTemplate::New(isolate, &Delete)); - proto->Set(isolate, "deleteAll", v8::FunctionTemplate::New(isolate, &DeleteAll)); + proto->Set(isolate, "deleteAll", v8::FunctionTemplate::New(isolate, &Clear)); + proto->Set(isolate, "clear", v8::FunctionTemplate::New(isolate, &Clear)); proto->Set(isolate, "save", v8::FunctionTemplate::New(isolate, &Save)); }); From 9f6c00e50423a07205b2b799d6ed66a4eb1fa38f Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 16 Nov 2020 17:16:39 +0100 Subject: [PATCH 083/564] new macros --- V8Helpers.cpp | 23 ++++++++++++++++++++ V8Helpers.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index adf6cd6e..2465fbe1 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -529,6 +529,29 @@ bool V8::SafeToString(v8::Local val, v8::Isolate *isolate, v8::Local< return false; } +bool V8::SafeToFunction(v8::Local val, v8::Local ctx, v8::Local& out) +{ + if (val->IsFunction()) + { + out = val.As(); + return true; + } + + return false; +} + +bool V8::SafeToObject(v8::Local val, v8::Local ctx, v8::Local& out) +{ + v8::MaybeLocal maybeVal = val->ToObject(ctx); + if (!maybeVal.IsEmpty()) + { + out = maybeVal.ToLocalChecked(); + return true; + } + + return false; +} + std::vector V8::EventHandler::GetCallbacks(V8ResourceImpl *impl, const alt::CEvent *e) { return callbacksGetter(impl, e); diff --git a/V8Helpers.h b/V8Helpers.h index 64f10bd5..b44c8528 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -205,6 +205,8 @@ namespace V8 bool SafeToInteger(v8::Local val, v8::Local ctx, int64_t &out); bool SafeToNumber(v8::Local val, v8::Local ctx, double &out); bool SafeToString(v8::Local val, v8::Isolate *isolate, v8::Local ctx, alt::String &out); + bool SafeToFunction(v8::Local val, v8::Local ctx, v8::Local& out); + bool SafeToObject(v8::Local val, v8::Local ctx, v8::Local& out); template bool SafeToBaseObject(v8::Local val, v8::Isolate *isolate, alt::Ref &out) @@ -252,10 +254,23 @@ namespace V8 V8_CHECK(val, "baseobject is not of type " #type); \ } +// idx starts with 1 +#define V8_GET_THIS_INTERNAL_FIELD_OBJECT(idx, val) \ + auto val = info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + +// idx starts with 1 +#define V8_GET_THIS_INTERNAL_FIELD_V8ENTITY(idx, val) \ + auto val = V8Entity::Get(info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredContext()).ToLocalChecked()); + +// idx starts with 1 +#define V8_GET_THIS_INTERNAL_FIELD_ENTITY(idx, val, type) \ + auto val = V8Entity::Get(info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredContext()).ToLocalChecked())->GetHandle().As(); + #define V8_CHECK_CONSTRUCTOR() V8_CHECK(info.IsConstructCall(), "function can't be called without new") #define V8_CHECK_ARGS_LEN(count) V8_CHECK(info.Length() == (count), #count " arguments expected") #define V8_CHECK_ARGS_LEN2(count1, count2) V8_CHECK(info.Length() == (count1) || info.Length() == (count2), #count1 " or " #count2 " arguments expected") +#define V8_CHECK_ARGS_LEN3(count) V8_CHECK(info.Length() == (count), "Atleast " #count " arguments expected") #define V8_TO_BOOLEAN(v8Val, val) \ bool val; \ @@ -271,7 +286,38 @@ namespace V8 #define V8_TO_STRING(v8Val, val) \ alt::String val; \ - V8_CHECK(V8::SafeToString((v8Val), isolate, ctx, val), "Failed to convert value to integer") + V8_CHECK(V8::SafeToString((v8Val), isolate, ctx, val), "Failed to convert value to string") + +#define V8_TO_OBJECT(v8Val, val) \ + v8::Local val; \ + V8_CHECK(V8::SafeToObject((v8Val), ctx, val), "Failed to convert value to object") + +#define V8_OBJECT_GET_NUMBER(v8Val, prop, val) \ + V8_TO_NUMBER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) + +#define V8_OBJECT_SET_NUMBER(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Number::New(isolate, val)); + +#define V8_OBJECT_GET_INTEGER(v8Val, prop, val) \ + V8_TO_INTEGER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) + +#define V8_OBJECT_SET_INTEGER(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Integer::New(isolate, val)); + +#define V8_OBJECT_GET_STRING(v8Val, prop, val) \ + V8_TO_STRING((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) + +#define V8_OBJECT_SET_STRING(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::String::NewFromUtf8(isolate, val.CStr()).ToLocalChecked()); + +#define V8_NEW_OBJECT(val) \ + v8::Local val = v8::Object::New(isolate); + +#define V8_NEW_ARGS(val) \ + std::vector> val; + +#define V8_ADD_ARG(args, val) \ + (args).push_back(val); // idx starts with 1 #define V8_ARG_CHECK_NUMBER(idx) V8_CHECK(info[(idx)-1]->IsNumber(), "Argument " #idx " must be a number") @@ -308,6 +354,16 @@ namespace V8 alt::String val; \ V8_CHECK(V8::SafeToString(info[(idx)-1], isolate, ctx, val), "Failed to convert argument " #idx " to string") +// idx starts with 1 +#define V8_ARG_TO_FUNCTION(idx, val) \ + v8::Local val; \ + V8_CHECK(V8::SafeToFunction(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to function") + +// idx starts with 1 +#define V8_ARG_TO_OBJECT(idx, val) \ + v8::Local val; \ + V8_CHECK(V8::SafeToObject(info[(idx) - 1], ctx, val), "Failed to convert argument " #idx " to object") + // idx starts with 1 #define V8_ARG_TO_BASE_OBJECT(idx, val, type, jsClassName) \ alt::Ref val; \ From 54c49e37ed05ae72e342a04b288642f0cbb91261 Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 16 Nov 2020 17:20:57 +0100 Subject: [PATCH 084/564] redo bindings with macros WIP --- src/bindings/Blip.cpp | 69 +- src/bindings/Discord.cpp | 32 +- src/bindings/Handling.cpp | 2194 ++++++++++++------------------------- src/bindings/Main.cpp | 355 +++--- src/bindings/Player.cpp | 274 +---- src/bindings/Vehicle.cpp | 116 +- src/helpers | 2 +- 7 files changed, 895 insertions(+), 2147 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index acaff3f6..4c7e9eba 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -75,6 +75,8 @@ static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo& in alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); alt::Ref blip = res->CreateBlip(alt::IBlip::BlipType::VEHICLE, vehicleId); + + V8_BIND_BASE_OBJECT(blip); } @@ -83,17 +85,11 @@ static void SizeSetter(v8::Local property, v8::Local valu V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_CHECK(value->IsObject(), "size must be an object"); - - v8::Local pos = value.As(); + V8_TO_OBJECT(value, pos); + V8_OBJECT_GET_NUMBER(pos, "x", x); + V8_OBJECT_GET_NUMBER(pos, "y", y); - v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked(); - v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked(); - - blip->SetScaleXY( - x->ToNumber(ctx).ToLocalChecked()->Value(), - y->ToNumber(ctx).ToLocalChecked()->Value() - ); + blip->SetScaleXY(x, y); } static void SizeGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -101,14 +97,13 @@ static void SizeGetter(v8::Local, const v8::PropertyCallbackInfoGetScaleXY(); - - v8::Local obj = v8::Object::New(isolate); + alt::Vector2f blipPos = blip->GetScaleXY(); - obj->Set(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked(), v8::Number::New(isolate, pos[0])); - obj->Set(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked(), v8::Number::New(isolate, pos[1])); + V8_NEW_OBJECT(pos); + V8_OBJECT_SET_NUMBER(pos, "x", blipPos[0]); + V8_OBJECT_SET_NUMBER(pos, "y", blipPos[1]); - V8_RETURN(obj); + V8_RETURN(pos); } static void SpriteGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -145,30 +140,20 @@ static void SecondaryColorGetter(v8::Local, const v8::PropertyCallba { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - alt::RGBA color = blip->GetSecondaryColor(); - V8_RETURN(resource->CreateRGBA(color)); + V8_RETURN(resource->CreateRGBA(blip->GetSecondaryColor())); } static void SecondaryColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); - - V8_CHECK(value->IsObject(), "object expected"); - - v8::Local color = value.As(); - v8::Local r = color->Get(ctx, v8::String::NewFromUtf8(isolate, "r").ToLocalChecked()).ToLocalChecked(); - v8::Local g = color->Get(ctx, v8::String::NewFromUtf8(isolate, "g").ToLocalChecked()).ToLocalChecked(); - v8::Local b = color->Get(ctx, v8::String::NewFromUtf8(isolate, "b").ToLocalChecked()).ToLocalChecked(); + V8_TO_OBJECT(value, color); + V8_OBJECT_GET_INTEGER(color, "r", r); + V8_OBJECT_GET_INTEGER(color, "g", g); + V8_OBJECT_GET_INTEGER(color, "b", b); - blip->SetSecondaryColor({ - (uint8_t)r->ToInteger(ctx).ToLocalChecked()->Value(), - (uint8_t)g->ToInteger(ctx).ToLocalChecked()->Value(), - (uint8_t)b->ToInteger(ctx).ToLocalChecked()->Value(), - 255 - }); + blip->SetSecondaryColor({ (uint8_t)r, (uint8_t)g, (uint8_t)b, 255 }); } static void AlphaGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -423,21 +408,13 @@ static void RouteColorSetter(v8::Local property, v8::LocalIsObject(), "object expected"); - - v8::Local color = value.As(); - - v8::Local r = color->Get(ctx, v8::String::NewFromUtf8(isolate, "r").ToLocalChecked()).ToLocalChecked(); - v8::Local g = color->Get(ctx, v8::String::NewFromUtf8(isolate, "g").ToLocalChecked()).ToLocalChecked(); - v8::Local b = color->Get(ctx, v8::String::NewFromUtf8(isolate, "b").ToLocalChecked()).ToLocalChecked(); - v8::Local a = color->Get(ctx, v8::String::NewFromUtf8(isolate, "a").ToLocalChecked()).ToLocalChecked(); + V8_TO_OBJECT(value, color); + V8_OBJECT_GET_INTEGER(color, "r", r); + V8_OBJECT_GET_INTEGER(color, "g", g); + V8_OBJECT_GET_INTEGER(color, "b", b); + V8_OBJECT_GET_INTEGER(color, "a", a); - blip->SetRouteColor({ - (uint8_t)r->ToInteger(ctx).ToLocalChecked()->Value(), - (uint8_t)g->ToInteger(ctx).ToLocalChecked()->Value(), - (uint8_t)b->ToInteger(ctx).ToLocalChecked()->Value(), - (uint8_t)a->ToInteger(ctx).ToLocalChecked()->Value() - }); + blip->SetRouteColor({ (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); } static void PulseGetter(v8::Local, const v8::PropertyCallbackInfo& info) diff --git a/src/bindings/Discord.cpp b/src/bindings/Discord.cpp index db159dff..775311a3 100644 --- a/src/bindings/Discord.cpp +++ b/src/bindings/Discord.cpp @@ -11,39 +11,23 @@ struct DiscordRequestOAuth2TokenCallbackData static void CurrentUserGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); auto discord = alt::ICore::Instance().GetDiscordManager(); if (discord->IsUserDataReady()) { - v8::Local discordInfo = v8::Object::New(isolate); - - discordInfo->Set( - ctx, - v8::String::NewFromUtf8(isolate, "id").ToLocalChecked(), - v8::String::NewFromUtf8(isolate, discord->GetUserID().CStr()).ToLocalChecked()); - - discordInfo->Set( - ctx, - v8::String::NewFromUtf8(isolate, "name").ToLocalChecked(), - v8::String::NewFromUtf8(isolate, discord->GetUsername().CStr()).ToLocalChecked()); - - discordInfo->Set( - ctx, - v8::String::NewFromUtf8(isolate, "discriminator").ToLocalChecked(), - v8::String::NewFromUtf8(isolate, discord->GetDiscriminator().CStr()).ToLocalChecked()); + V8_NEW_OBJECT(discordInfo); - discordInfo->Set( - ctx, - v8::String::NewFromUtf8(isolate, "avatar").ToLocalChecked(), - v8::String::NewFromUtf8(isolate, discord->GetAvatar().CStr()).ToLocalChecked()); + V8_OBJECT_SET_STRING(discordInfo, "id", discord->GetUserID()); + V8_OBJECT_SET_STRING(discordInfo, "name", discord->GetUsername()); + V8_OBJECT_SET_STRING(discordInfo, "discriminator", discord->GetDiscriminator()); + V8_OBJECT_SET_STRING(discordInfo, "avatar", discord->GetAvatar()); - info.GetReturnValue().Set(discordInfo); + V8_RETURN(discordInfo); } else { - info.GetReturnValue().Set(v8::Null(isolate)); + V8_RETURN_NULL(); } } diff --git a/src/bindings/Handling.cpp b/src/bindings/Handling.cpp index 2ba8f624..b00e18dc 100644 --- a/src/bindings/Handling.cpp +++ b/src/bindings/Handling.cpp @@ -6,2049 +6,1219 @@ #include "../helpers/V8ResourceImpl.h" #include "cpp-sdk/objects/IVehicle.h" -static void Constructor(const v8::FunctionCallbackInfo &info) +static void Constructor(const v8::FunctionCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_OBJECT(1, vehicle); - V8_CHECK(info.IsConstructCall(), "Handling constructor is not a function"); - V8_CHECK(info.Length() == 1, "new Handling(...) expects 1 arg"); - - V8_CHECK(info[0]->IsObject(), "vehicle must be an object"); - auto objVehicle = info[0]->ToObject(ctx).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - info.This()->SetInternalField(0, info[0]); + info.This()->SetInternalField(0, vehicle); } -static void IsModified(const v8::FunctionCallbackInfo &info) +static void IsModified(const v8::FunctionCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto netVehicle = v8vehicle->GetHandle().As().Get(); - - V8_RETURN_BOOLEAN(netVehicle->IsHandlingModified()); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + V8_RETURN_BOOLEAN(vehicle->IsHandlingModified()); } -static void Reset(const v8::FunctionCallbackInfo &info) +static void Reset(const v8::FunctionCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto refVehicle = v8vehicle->GetHandle().As(); - - refVehicle->ResetHandling(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + vehicle->ResetHandling(); } -static void HandlingNameHashGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void HandlingNameHashGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, (vehicle->GetHandling())->GetHandlingNameHash())); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + V8_RETURN_INTEGER(vehicle->GetHandling()->GetHandlingNameHash()); } -static void MassGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void MassGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetMass())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetMass()); } -static void MassSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void MassSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "mass must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetMass((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetMass(fvalue); } -static void InitialDragCoeffGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void InitialDragCoeffGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetInitialDragCoeff())); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetInitialDragCoeff()); } -static void InitialDragCoeffSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void InitialDragCoeffSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "initialDragCoeff must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetInitialDragCoeff((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetInitialDragCoeff(fvalue); } -static void DownforceModifierGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void DownforceModifierGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetDownforceModifier())); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetDownforceModifier()); } -static void DownforceModifierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void DownforceModifierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "downforceModifier must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetDownforceModifier((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetDownforceModifier(fvalue); } -static void unkFloat1Getter(v8::Local, const v8::PropertyCallbackInfo &info) +static void unkFloat1Getter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetunkFloat1())); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetunkFloat1()); } -static void unkFloat1Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void unkFloat1Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "unkFloat1 must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetunkFloat1((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetunkFloat1(fvalue); } -static void unkFloat2Getter(v8::Local, const v8::PropertyCallbackInfo &info) +static void unkFloat2Getter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetunkFloat2())); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetunkFloat2()); } -static void unkFloat2Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void unkFloat2Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "unkFloat2 must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetunkFloat2((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetunkFloat2(fvalue); } -static void CentreOfMassOffsetGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void CentreOfMassOffsetGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(resource->CreateVector3((vehicle->GetHandling()->GetCentreOfMassOffset()))); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + V8_RETURN(resource->CreateVector3(vehicle->GetHandling()->GetCentreOfMassOffset())); } -static void CentreOfMassOffsetSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void CentreOfMassOffsetSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - V8_CHECK(val->IsObject(), "centreOfMassOffset must be a Vector3"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - v8::Local pos = val.As(); + V8_TO_OBJECT(val, pos); + V8_OBJECT_GET_NUMBER(pos, "x", x); + V8_OBJECT_GET_NUMBER(pos, "y", y); + V8_OBJECT_GET_NUMBER(pos, "z", z); - v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - - vehicle->GetHandling()->SetCentreOfMassOffset({(float)x->Value(), (float)y->Value(), (float)z->Value()}); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetCentreOfMassOffset({ x, y, z }); } -static void InertiaMultiplierGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void InertiaMultiplierGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(resource->CreateVector3((vehicle->GetHandling()->GetInertiaMultiplier()))); + V8_RETURN(resource->CreateVector3(vehicle->GetHandling()->GetInertiaMultiplier())); } -static void InertiaMultiplierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void InertiaMultiplierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8_CHECK(val->IsObject(), "inertiaMultiplier must be a Vector3"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); + V8_TO_OBJECT(val, pos); + V8_OBJECT_GET_NUMBER(pos, "x", x); + V8_OBJECT_GET_NUMBER(pos, "y", y); + V8_OBJECT_GET_NUMBER(pos, "z", z); - v8::Local pos = val.As(); - - v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - - vehicle->GetHandling()->SetInertiaMultiplier({(float)x->Value(), (float)y->Value(), (float)z->Value()}); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetInertiaMultiplier({ x, y, z }); } -static void PercentSubmergedGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void PercentSubmergedGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetPercentSubmerged())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetPercentSubmerged()); } -static void PercentSubmergedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void PercentSubmergedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "percentSubmerged must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetPercentSubmerged((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetPercentSubmerged(fvalue); } -static void PercentSubmergedRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void PercentSubmergedRatioGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetPercentSubmergedRatio())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetPercentSubmergedRatio()); } -static void PercentSubmergedRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void PercentSubmergedRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "percentSubmergedRatio must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetPercentSubmergedRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetPercentSubmergedRatio(fvalue); } -static void DriveBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void DriveBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetDriveBiasFront())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetDriveBiasFront()); } -static void DriveBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void DriveBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "driveBiasFront must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetDriveBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetDriveBiasFront(fvalue); } -static void AccelerationGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void AccelerationGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetAcceleration())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetAcceleration()); } -static void AccelerationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void AccelerationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "acceleration must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetAcceleration((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetAcceleration(fvalue); } -static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetInitialDriveGears())); + V8_RETURN_INTEGER(vehicle->GetHandling()->GetInitialDriveGears()); } -static void InitialDriveGearsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void InitialDriveGearsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "initialDriveGears must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetInitialDriveGears(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); + V8_TO_INTEGER(val, ivalue); + vehicle->GetHandling()->SetInitialDriveGears(ivalue); } -static void DriveInertiaGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void DriveInertiaGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetDriveInertia())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetDriveInertia()); } -static void DriveInertiaSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void DriveInertiaSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "driveInertia must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetDriveInertia((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetDriveInertia(fvalue); } -static void ClutchChangeRateScaleUpShiftGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void ClutchChangeRateScaleUpShiftGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetClutchChangeRateScaleUpShift())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetClutchChangeRateScaleUpShift()); } -static void ClutchChangeRateScaleUpShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void ClutchChangeRateScaleUpShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "clutchChangeRateScaleUpShift must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetClutchChangeRateScaleUpShift((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetClutchChangeRateScaleUpShift(fvalue); } -static void ClutchChangeRateScaleDownShiftGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void ClutchChangeRateScaleDownShiftGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetClutchChangeRateScaleDownShift())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetClutchChangeRateScaleDownShift()); } -static void ClutchChangeRateScaleDownShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void ClutchChangeRateScaleDownShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "clutchChangeRateScaleDownShift must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetClutchChangeRateScaleDownShift((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetClutchChangeRateScaleDownShift(fvalue); } -static void InitialDriveForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void InitialDriveForceGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetInitialDriveForce())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetInitialDriveForce()); } -static void InitialDriveForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void InitialDriveForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "initialDriveForce must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetInitialDriveForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetInitialDriveForce(fvalue); } -static void DriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void DriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetDriveMaxFlatVel())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetDriveMaxFlatVel()); } -static void DriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void DriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "driveMaxFlatVel must be a number"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetDriveMaxFlatVel((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetDriveMaxFlatVel(fvalue); } -static void InitialDriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void InitialDriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetInitialDriveMaxFlatVel())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetInitialDriveMaxFlatVel()); } -static void InitialDriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void InitialDriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "initialDriveMaxFlatVel must be a number"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetInitialDriveMaxFlatVel((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetInitialDriveMaxFlatVel(fvalue); } -static void BrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void BrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetBrakeForce())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetBrakeForce()); } -static void BrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void BrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "brakeForce must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetBrakeForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetBrakeForce(fvalue); } -static void unkFloat4Getter(v8::Local, const v8::PropertyCallbackInfo &info) +static void unkFloat4Getter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetunkFloat4())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetunkFloat4()); } -static void unkFloat4Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void unkFloat4Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "unkFloat4 must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetunkFloat4((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetunkFloat4(fvalue); } -static void BrakeBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void BrakeBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetBrakeBiasFront())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetBrakeBiasFront()); } -static void BrakeBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void BrakeBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "brakeBiasFront must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetBrakeBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetBrakeBiasFront(fvalue); } -static void BrakeBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void BrakeBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetBrakeBiasRear())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetBrakeBiasRear()); } -static void BrakeBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void BrakeBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "brakeBiasRear must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetBrakeBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetBrakeBiasRear(fvalue); } -static void HandBrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void HandBrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetHandBrakeForce())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetHandBrakeForce()); } -static void HandBrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void HandBrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "handBrakeForce must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetHandBrakeForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetHandBrakeForce(fvalue); } -static void SteeringLockGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SteeringLockGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSteeringLock())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSteeringLock()); } -static void SteeringLockSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SteeringLockSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "steeringLock must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetSteeringLock((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSteeringLock(fvalue); } -static void SteeringLockRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SteeringLockRatioGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSteeringLockRatio())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSteeringLockRatio()); } -static void SteeringLockRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SteeringLockRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "steeringLockRatio must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetSteeringLockRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSteeringLockRatio(fvalue); } -static void TractionCurveMaxGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionCurveMaxGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionCurveMax())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetTractionCurveMax()); } -static void TractionCurveMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionCurveMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionCurveMax must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetTractionCurveMax((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetTractionCurveMax(fvalue); } -static void TractionCurveMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionCurveMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionCurveMaxRatio())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetTractionCurveMaxRatio()); } -static void TractionCurveMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionCurveMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionCurveMaxRatio must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetTractionCurveMaxRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetTractionCurveMaxRatio(fvalue); } -static void TractionCurveMinGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionCurveMinGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionCurveMin())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetTractionCurveMin()); } -static void TractionCurveMinSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionCurveMinSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionCurveMin must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetTractionCurveMin((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetTractionCurveMin(fvalue); } -static void TractionCurveMinRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionCurveMinRatioGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionCurveMinRatio())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetTractionCurveMinRatio()); } -static void TractionCurveMinRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionCurveMinRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionCurveMinRatio must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetTractionCurveMinRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetTractionCurveMinRatio(fvalue); } -static void TractionCurveLateralGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionCurveLateralGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionCurveLateral())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetTractionCurveLateral()); } -static void TractionCurveLateralSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionCurveLateralSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionCurveLateral must be a number"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetTractionCurveLateral((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetTractionCurveLateral(fvalue); } -static void TractionCurveLateralRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionCurveLateralRatioGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionCurveLateralRatio())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetTractionCurveLateralRatio()); } -static void TractionCurveLateralRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionCurveLateralRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionCurveLateralRatio must be a number"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetTractionCurveLateralRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetTractionCurveLateralRatio(fvalue); } -static void TractionSpringDeltaMaxGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionSpringDeltaMaxGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionSpringDeltaMax())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetTractionSpringDeltaMax()); } -static void TractionSpringDeltaMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionSpringDeltaMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionSpringDeltaMax must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetTractionSpringDeltaMax((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetTractionSpringDeltaMax(fvalue); } -static void TractionSpringDeltaMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionSpringDeltaMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionSpringDeltaMaxRatio())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetTractionSpringDeltaMaxRatio()); } -static void TractionSpringDeltaMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionSpringDeltaMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionSpringDeltaMaxRatio must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetTractionSpringDeltaMaxRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetTractionSpringDeltaMaxRatio(fvalue); } -static void LowSpeedTractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void LowSpeedTractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetLowSpeedTractionLossMult())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetLowSpeedTractionLossMult()); } -static void LowSpeedTractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void LowSpeedTractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "lowSpeedTractionLossMult must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetLowSpeedTractionLossMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetLowSpeedTractionLossMult(fvalue); } -static void CamberStiffnesssGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void CamberStiffnesssGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetCamberStiffnesss())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetCamberStiffnesss()); } -static void CamberStiffnesssSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void CamberStiffnesssSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "camberStiffnesss must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetCamberStiffnesss((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetCamberStiffnesss(fvalue); } -static void TractionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionBiasFront())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetTractionBiasFront()); } -static void TractionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionBiasFront must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetTractionBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetTractionBiasFront(fvalue); } -static void TractionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionBiasRear())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetTractionBiasRear()); } -static void TractionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionBiasRear must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetTractionBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetTractionBiasRear(fvalue); } -static void TractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetTractionLossMult())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetTractionLossMult()); } -static void TractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionLossMult must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetTractionLossMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetTractionLossMult(fvalue); } -static void SuspensionForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionForceGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionForce())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSuspensionForce()); } -static void SuspensionForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionForce must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetSuspensionForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSuspensionForce(fvalue); } -static void SuspensionCompDampGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionCompDampGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionCompDamp())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSuspensionCompDamp()); } -static void SuspensionCompDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionCompDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionCompDamp must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetSuspensionCompDamp((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSuspensionCompDamp(fvalue); } -static void SuspensionReboundDampGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionReboundDampGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionReboundDamp())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSuspensionReboundDamp()); } -static void SuspensionReboundDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionReboundDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionReboundDamp must be a number"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetSuspensionReboundDamp((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSuspensionReboundDamp(fvalue); } -static void SuspensionUpperLimitGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionUpperLimitGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionUpperLimit())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSuspensionUpperLimit()); } -static void SuspensionUpperLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionUpperLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionUpperLimit must be a number"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetSuspensionUpperLimit((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSuspensionUpperLimit(fvalue); } -static void SuspensionLowerLimitGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionLowerLimitGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionLowerLimit())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSuspensionLowerLimit()); } -static void SuspensionLowerLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionLowerLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionLowerLimit must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetSuspensionLowerLimit((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSuspensionLowerLimit(fvalue); } -static void SuspensionRaiseGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionRaiseGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionRaise())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSuspensionRaise()); } -static void SuspensionRaiseSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionRaiseSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionRaise must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetSuspensionRaise((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSuspensionRaise(fvalue); } -static void SuspensionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionBiasFront())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSuspensionBiasFront()); } -static void SuspensionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionBiasFront must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetSuspensionBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSuspensionBiasFront(fvalue); } -static void SuspensionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSuspensionBiasRear())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSuspensionBiasRear()); } -static void SuspensionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionBiasRear must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetSuspensionBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSuspensionBiasRear(fvalue); } -static void AntiRollBarForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void AntiRollBarForceGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetAntiRollBarForce())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetAntiRollBarForce()); } -static void AntiRollBarForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void AntiRollBarForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "antiRollBarForce must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetAntiRollBarForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetAntiRollBarForce(fvalue); } -static void AntiRollBarBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void AntiRollBarBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetAntiRollBarBiasFront())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetAntiRollBarBiasFront()); } -static void AntiRollBarBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void AntiRollBarBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "antiRollBarBiasFront must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetAntiRollBarBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetAntiRollBarBiasFront(fvalue); } -static void AntiRollBarBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void AntiRollBarBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetAntiRollBarBiasRear())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetAntiRollBarBiasRear()); } -static void AntiRollBarBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void AntiRollBarBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "antiRollBarBiasRear must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetAntiRollBarBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetAntiRollBarBiasRear(fvalue); } -static void RollCentreHeightFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void RollCentreHeightFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetRollCentreHeightFront())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetRollCentreHeightFront()); } -static void RollCentreHeightFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void RollCentreHeightFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "rollCentreHeightFront must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetRollCentreHeightFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetRollCentreHeightFront(fvalue); } -static void RollCentreHeightRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void RollCentreHeightRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetRollCentreHeightRear())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetRollCentreHeightRear()); } -static void RollCentreHeightRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void RollCentreHeightRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "rollCentreHeightRear must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetRollCentreHeightRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetRollCentreHeightRear(fvalue); } -static void CollisionDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void CollisionDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetCollisionDamageMult())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetCollisionDamageMult()); } -static void CollisionDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void CollisionDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "collisionDamageMult must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetCollisionDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetCollisionDamageMult(fvalue); } -static void WeaponDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void WeaponDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetWeaponDamageMult())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetWeaponDamageMult()); } -static void WeaponDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void WeaponDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "weaponDamageMult must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetWeaponDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetWeaponDamageMult(fvalue); } -static void DeformationDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void DeformationDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetDeformationDamageMult())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetDeformationDamageMult()); } -static void DeformationDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void DeformationDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "deformationDamageMult must be a number"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetDeformationDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetDeformationDamageMult(fvalue); } -static void EngineDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void EngineDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetEngineDamageMult())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetEngineDamageMult()); } -static void EngineDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void EngineDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "engineDamageMult must be a number"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetEngineDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetEngineDamageMult(fvalue); } -static void PetrolTankVolumeGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void PetrolTankVolumeGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetPetrolTankVolume())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetPetrolTankVolume()); } -static void PetrolTankVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void PetrolTankVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "petrolTankVolume must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetPetrolTankVolume((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetPetrolTankVolume(fvalue); } -static void OilVolumeGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void OilVolumeGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetOilVolume())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetOilVolume()); } -static void OilVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void OilVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "oilVolume must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetOilVolume((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetOilVolume(fvalue); } -static void unkFloat5Getter(v8::Local, const v8::PropertyCallbackInfo &info) +static void unkFloat5Getter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetunkFloat5())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetunkFloat5()); } -static void unkFloat5Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void unkFloat5Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "unkFloat5 must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetunkFloat5((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetunkFloat5(fvalue); } -static void SeatOffsetDistXGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SeatOffsetDistXGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSeatOffsetDistX())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSeatOffsetDistX()); } -static void SeatOffsetDistXSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SeatOffsetDistXSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "seatOffsetDistX must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetSeatOffsetDistX((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSeatOffsetDistX(fvalue); } -static void SeatOffsetDistYGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SeatOffsetDistYGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSeatOffsetDistY())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSeatOffsetDistY()); } -static void SeatOffsetDistYSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SeatOffsetDistYSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "seatOffsetDistY must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetSeatOffsetDistY((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSeatOffsetDistY(fvalue); } -static void SeatOffsetDistZGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SeatOffsetDistZGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetSeatOffsetDistZ())); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetSeatOffsetDistZ()); } -static void SeatOffsetDistZSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SeatOffsetDistZSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "seatOffsetDistZ must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetSeatOffsetDistZ((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + vehicle->GetHandling()->SetSeatOffsetDistZ(fvalue); } -static void MonetaryValueGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void MonetaryValueGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetMonetaryValue())); + V8_RETURN_INTEGER(vehicle->GetHandling()->GetMonetaryValue()); } -static void MonetaryValueSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void MonetaryValueSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "monetaryValue must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetMonetaryValue(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); + V8_TO_INTEGER(val, ivalue); + vehicle->GetHandling()->SetMonetaryValue(ivalue); } -static void ModelFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void ModelFlagsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetModelFlags())); + V8_RETURN_INTEGER(vehicle->GetHandling()->GetModelFlags()); } -static void ModelFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void ModelFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "modelFlags must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetModelFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); + V8_TO_INTEGER(val, ivalue); + vehicle->GetHandling()->SetModelFlags(ivalue); } -static void HandlingFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void HandlingFlagsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetHandlingFlags())); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + V8_RETURN_INTEGER(vehicle->GetHandling()->GetHandlingFlags()); } -static void HandlingFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void HandlingFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "handlingFlags must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - vehicle->GetHandling()->SetHandlingFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); + V8_TO_INTEGER(val, ivalue); + vehicle->GetHandling()->SetHandlingFlags(ivalue); } -static void DamageFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void DamageFlagsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetHandling()->GetDamageFlags())); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + V8_RETURN_INTEGER(vehicle->GetHandling()->GetDamageFlags()); } -static void DamageFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void DamageFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "damageFlags must be a number"); - - auto objVehicle = info.This()->GetInternalField(0)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); - - auto v8vehicle = V8Entity::Get(objVehicle); - V8_CHECK(v8vehicle, "entity is invalid"); - - auto vehicle = v8vehicle->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - vehicle->GetHandling()->SetDamageFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); + V8_TO_INTEGER(val, ivalue); + vehicle->GetHandling()->SetDamageFlags(ivalue); } -extern V8Class v8Handling( - "Handling", Constructor, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); +extern V8Class v8Handling("Handling", Constructor, [](v8::Local tpl) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Local proto = tpl->PrototypeTemplate(); tpl->InstanceTemplate()->SetInternalFieldCount(1); - proto->Set(isolate, "isModified", v8::FunctionTemplate::New(isolate, &IsModified)); - proto->Set(isolate, "reset", v8::FunctionTemplate::New(isolate, &Reset)); - - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingNameHash").ToLocalChecked(), &HandlingNameHashGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "mass").ToLocalChecked(), &MassGetter, &MassSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDragCoeff").ToLocalChecked(), &InitialDragCoeffGetter, &InitialDragCoeffSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "downforceModifier").ToLocalChecked(), &DownforceModifierGetter, &DownforceModifierSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat1").ToLocalChecked(), &unkFloat1Getter, &unkFloat1Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat2").ToLocalChecked(), &unkFloat2Getter, &unkFloat2Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "centreOfMassOffset").ToLocalChecked(), &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "inertiaMultiplier").ToLocalChecked(), &InertiaMultiplierGetter, &InertiaMultiplierSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmerged").ToLocalChecked(), &PercentSubmergedGetter, &PercentSubmergedSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmergedRatio").ToLocalChecked(), &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveBiasFront").ToLocalChecked(), &DriveBiasFrontGetter, &DriveBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "acceleration").ToLocalChecked(), &AccelerationGetter, &AccelerationSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveGears").ToLocalChecked(), &InitialDriveGearsGetter, &InitialDriveGearsSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveInertia").ToLocalChecked(), &DriveInertiaGetter, &DriveInertiaSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleUpShift").ToLocalChecked(), &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleDownShift").ToLocalChecked(), &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveForce").ToLocalChecked(), &InitialDriveForceGetter, &InitialDriveForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveMaxFlatVel").ToLocalChecked(), &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveMaxFlatVel").ToLocalChecked(), &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeForce").ToLocalChecked(), &BrakeForceGetter, &BrakeForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat4").ToLocalChecked(), &unkFloat4Getter, &unkFloat4Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasFront").ToLocalChecked(), &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasRear").ToLocalChecked(), &BrakeBiasRearGetter, &BrakeBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handBrakeForce").ToLocalChecked(), &HandBrakeForceGetter, &HandBrakeForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLock").ToLocalChecked(), &SteeringLockGetter, &SteeringLockSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLockRatio").ToLocalChecked(), &SteeringLockRatioGetter, &SteeringLockRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMax").ToLocalChecked(), &TractionCurveMaxGetter, &TractionCurveMaxSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMaxRatio").ToLocalChecked(), &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMin").ToLocalChecked(), &TractionCurveMinGetter, &TractionCurveMinSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMinRatio").ToLocalChecked(), &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateral").ToLocalChecked(), &TractionCurveLateralGetter, &TractionCurveLateralSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateralRatio").ToLocalChecked(), &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMax").ToLocalChecked(), &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMaxRatio").ToLocalChecked(), &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lowSpeedTractionLossMult").ToLocalChecked(), &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "camberStiffnesss").ToLocalChecked(), &CamberStiffnesssGetter, &CamberStiffnesssSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasFront").ToLocalChecked(), &TractionBiasFrontGetter, &TractionBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasRear").ToLocalChecked(), &TractionBiasRearGetter, &TractionBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionLossMult").ToLocalChecked(), &TractionLossMultGetter, &TractionLossMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionForce").ToLocalChecked(), &SuspensionForceGetter, &SuspensionForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionCompDamp").ToLocalChecked(), &SuspensionCompDampGetter, &SuspensionCompDampSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionReboundDamp").ToLocalChecked(), &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionUpperLimit").ToLocalChecked(), &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionLowerLimit").ToLocalChecked(), &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionRaise").ToLocalChecked(), &SuspensionRaiseGetter, &SuspensionRaiseSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasFront").ToLocalChecked(), &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasRear").ToLocalChecked(), &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarForce").ToLocalChecked(), &AntiRollBarForceGetter, &AntiRollBarForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasFront").ToLocalChecked(), &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasRear").ToLocalChecked(), &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightFront").ToLocalChecked(), &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightRear").ToLocalChecked(), &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "collisionDamageMult").ToLocalChecked(), &CollisionDamageMultGetter, &CollisionDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "weaponDamageMult").ToLocalChecked(), &WeaponDamageMultGetter, &WeaponDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "deformationDamageMult").ToLocalChecked(), &DeformationDamageMultGetter, &DeformationDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "engineDamageMult").ToLocalChecked(), &EngineDamageMultGetter, &EngineDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "petrolTankVolume").ToLocalChecked(), &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "oilVolume").ToLocalChecked(), &OilVolumeGetter, &OilVolumeSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat5").ToLocalChecked(), &unkFloat5Getter, &unkFloat5Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistX").ToLocalChecked(), &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistY").ToLocalChecked(), &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistZ").ToLocalChecked(), &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "monetaryValue").ToLocalChecked(), &MonetaryValueGetter, &MonetaryValueSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modelFlags").ToLocalChecked(), &ModelFlagsGetter, &ModelFlagsSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingFlags").ToLocalChecked(), &HandlingFlagsGetter, &HandlingFlagsSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "damageFlags").ToLocalChecked(), &DamageFlagsGetter, &DamageFlagsSetter); + V8::SetMethod(isolate, tpl, "isModified", &IsModified); + V8::SetMethod(isolate, tpl, "reset", &Reset); + + V8::SetAccessor(isolate, tpl, "handlingNameHash", &HandlingNameHashGetter); + V8::SetAccessor(isolate, tpl, "mass", &MassGetter, &MassSetter); + V8::SetAccessor(isolate, tpl, "initialDragCoeff", &InitialDragCoeffGetter, &InitialDragCoeffSetter); + V8::SetAccessor(isolate, tpl, "downforceModifier", &DownforceModifierGetter, &DownforceModifierSetter); + V8::SetAccessor(isolate, tpl, "unkFloat1", &unkFloat1Getter, &unkFloat1Setter); + V8::SetAccessor(isolate, tpl, "unkFloat2", &unkFloat2Getter, &unkFloat2Setter); + V8::SetAccessor(isolate, tpl, "centreOfMassOffset", &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); + V8::SetAccessor(isolate, tpl, "inertiaMultiplier", &InertiaMultiplierGetter, &InertiaMultiplierSetter); + V8::SetAccessor(isolate, tpl, "percentSubmerged", &PercentSubmergedGetter, &PercentSubmergedSetter); + V8::SetAccessor(isolate, tpl, "percentSubmergedRatio", &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); + V8::SetAccessor(isolate, tpl, "driveBiasFront", &DriveBiasFrontGetter, &DriveBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "acceleration", &AccelerationGetter, &AccelerationSetter); + V8::SetAccessor(isolate, tpl, "initialDriveGears", &InitialDriveGearsGetter, &InitialDriveGearsSetter); + V8::SetAccessor(isolate, tpl, "driveInertia", &DriveInertiaGetter, &DriveInertiaSetter); + V8::SetAccessor(isolate, tpl, "clutchChangeRateScaleUpShift", &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); + V8::SetAccessor(isolate, tpl, "clutchChangeRateScaleDownShift", &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); + V8::SetAccessor(isolate, tpl, "initialDriveForce", &InitialDriveForceGetter, &InitialDriveForceSetter); + V8::SetAccessor(isolate, tpl, "driveMaxFlatVel", &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); + V8::SetAccessor(isolate, tpl, "initialDriveMaxFlatVel", &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); + V8::SetAccessor(isolate, tpl, "brakeForce", &BrakeForceGetter, &BrakeForceSetter); + V8::SetAccessor(isolate, tpl, "unkFloat4", &unkFloat4Getter, &unkFloat4Setter); + V8::SetAccessor(isolate, tpl, "brakeBiasFront", &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "brakeBiasRear", &BrakeBiasRearGetter, &BrakeBiasRearSetter); + V8::SetAccessor(isolate, tpl, "handBrakeForce", &HandBrakeForceGetter, &HandBrakeForceSetter); + V8::SetAccessor(isolate, tpl, "steeringLock", &SteeringLockGetter, &SteeringLockSetter); + V8::SetAccessor(isolate, tpl, "steeringLockRatio", &SteeringLockRatioGetter, &SteeringLockRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMax", &TractionCurveMaxGetter, &TractionCurveMaxSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMaxRatio", &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMin", &TractionCurveMinGetter, &TractionCurveMinSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMinRatio", &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveLateral", &TractionCurveLateralGetter, &TractionCurveLateralSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveLateralRatio", &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionSpringDeltaMax", &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); + V8::SetAccessor(isolate, tpl, "tractionSpringDeltaMaxRatio", &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); + V8::SetAccessor(isolate, tpl, "lowSpeedTractionLossMult", &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); + V8::SetAccessor(isolate, tpl, "camberStiffnesss", &CamberStiffnesssGetter, &CamberStiffnesssSetter); + V8::SetAccessor(isolate, tpl, "tractionBiasFront", &TractionBiasFrontGetter, &TractionBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "tractionBiasRear", &TractionBiasRearGetter, &TractionBiasRearSetter); + V8::SetAccessor(isolate, tpl, "tractionLossMult", &TractionLossMultGetter, &TractionLossMultSetter); + V8::SetAccessor(isolate, tpl, "suspensionForce", &SuspensionForceGetter, &SuspensionForceSetter); + V8::SetAccessor(isolate, tpl, "suspensionCompDamp", &SuspensionCompDampGetter, &SuspensionCompDampSetter); + V8::SetAccessor(isolate, tpl, "suspensionReboundDamp", &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); + V8::SetAccessor(isolate, tpl, "suspensionUpperLimit", &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); + V8::SetAccessor(isolate, tpl, "suspensionLowerLimit", &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); + V8::SetAccessor(isolate, tpl, "suspensionRaise", &SuspensionRaiseGetter, &SuspensionRaiseSetter); + V8::SetAccessor(isolate, tpl, "suspensionBiasFront", &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "suspensionBiasRear", &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarForce", &AntiRollBarForceGetter, &AntiRollBarForceSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarBiasFront", &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarBiasRear", &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); + V8::SetAccessor(isolate, tpl, "rollCentreHeightFront", &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); + V8::SetAccessor(isolate, tpl, "rollCentreHeightRear", &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); + V8::SetAccessor(isolate, tpl, "collisionDamageMult", &CollisionDamageMultGetter, &CollisionDamageMultSetter); + V8::SetAccessor(isolate, tpl, "weaponDamageMult", &WeaponDamageMultGetter, &WeaponDamageMultSetter); + V8::SetAccessor(isolate, tpl, "deformationDamageMult", &DeformationDamageMultGetter, &DeformationDamageMultSetter); + V8::SetAccessor(isolate, tpl, "engineDamageMult", &EngineDamageMultGetter, &EngineDamageMultSetter); + V8::SetAccessor(isolate, tpl, "petrolTankVolume", &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); + V8::SetAccessor(isolate, tpl, "oilVolume", &OilVolumeGetter, &OilVolumeSetter); + V8::SetAccessor(isolate, tpl, "unkFloat5", &unkFloat5Getter, &unkFloat5Setter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistX", &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistY", &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistZ", &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); + V8::SetAccessor(isolate, tpl, "monetaryValue", &MonetaryValueGetter, &MonetaryValueSetter); + V8::SetAccessor(isolate, tpl, "modelFlags", &ModelFlagsGetter, &ModelFlagsSetter); + V8::SetAccessor(isolate, tpl, "handlingFlags", &HandlingFlagsGetter, &HandlingFlagsSetter); + V8::SetAccessor(isolate, tpl, "damageFlags", &DamageFlagsGetter, &DamageFlagsSetter); }); \ No newline at end of file diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 19ad130c..04f47e9f 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -11,124 +11,78 @@ using namespace alt; static void OnServer(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() == 2, "onServer expects 2 args"); - V8_CHECK(info[0]->IsString(), "eventName must be a string"); - V8_CHECK(info[1]->IsFunction(), "callback must be a function"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); - v8::Local callback = info[1].As(); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, eventName); + V8_ARG_TO_FUNCTION(2, callback); - resource->SubscribeRemote(evName, callback, V8::SourceLocation::GetCurrent(isolate)); + resource->SubscribeRemote(eventName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate)); } static void OffServer(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() == 2, "onServer expects 2 args"); - V8_CHECK(info[0]->IsString(), "eventName must be a string"); - V8_CHECK(info[1]->IsFunction(), "callback must be a function"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); - - std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); - v8::Local callback = info[1].As(); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, eventName); + V8_ARG_TO_FUNCTION(2, callback); - resource->UnsubscribeRemote(evName, callback); + resource->UnsubscribeRemote(eventName.ToString(), callback); } static void EmitServer(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() >= 1, "emitServer expects at least 1 arg"); - V8_CHECK(info[0]->IsString(), "eventName must be a string"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - std::string name = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + V8_CHECK_ARGS_LEN3(1); + V8_ARG_TO_STRING(1, eventName); + alt::MValueArgs args; for (int i = 1; i < info.Length(); ++i) args.Push(V8Helpers::V8ToMValue(info[i])); - alt::ICore::Instance().TriggerServerEvent(name, args); + alt::ICore::Instance().TriggerServerEvent(eventName.ToString(), args); } -/** -type: 'function', -name: 'gameControlsEnabled', -description: 'Returns a bool if is game controls enabled', -returns: { - dataType: 'bool', - description: 'If is game controls enabled' -} -*/ static void GameControlsEnabled(const v8::FunctionCallbackInfo &info) { - info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), alt::ICore::Instance().AreControlsEnabled())); + V8_GET_ISOLATE(info); + V8_RETURN_BOOLEAN(alt::ICore::Instance().AreControlsEnabled()); } -/** -type: 'function', -name: 'toggleGameControls', -description: 'Toggles a game controls', -parameters: [ - { - name: 'state', - dataType: 'bool', - description: '`true` for enable controls, `false` to disable controls' - } -] -*/ static void ToggleGameControls(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK(info.Length() == 1, "toggleGameControls expects 1 arg"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_BOOLEAN(1, state); CV8ResourceImpl *jsResource = static_cast(resource); - bool state = info[0]->ToBoolean(isolate)->Value(); - jsResource->ToggleGameControls(state); } static void ToggleVoiceControls(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() == 1, "toggleVoiceControls expects 1 arg"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - /*V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - CV8ResourceImpl* jsResource = static_cast(resource);*/ - - bool state = info[0]->ToBoolean(isolate)->Value(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_BOOLEAN(1, state); // TODO: make it resource-bound - //jsResource->ToggleGameControls(state); + //jsResource->ToggleVoiceControls(state); alt::ICore::Instance().ToggleVoiceControls(state); } static void ShowCursor(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK(info.Length() >= 1, "showCursor expects 1 or 2 args"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_BOOLEAN(1, state); CV8ResourceImpl *jsResource = static_cast(resource); - bool state = info[0]->ToBoolean(isolate)->Value(); if (!jsResource->ToggleCursor(state)) { @@ -145,32 +99,27 @@ static void ShowCursor(const v8::FunctionCallbackInfo &info) static void GetCursorPos(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - alt::Vector2i pos = alt::ICore::Instance().GetCursorPosition(); - - v8::Local obj = v8::Object::New(isolate); + V8_GET_ISOLATE_CONTEXT(); - obj->Set(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked(), v8::Integer::New(isolate, pos[0])); - obj->Set(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked(), v8::Integer::New(isolate, pos[1])); + alt::Vector2i cursorPos = alt::ICore::Instance().GetCursorPosition(); - info.GetReturnValue().Set(obj); + V8_NEW_OBJECT(pos); + V8_OBJECT_SET_INTEGER(pos, "x", cursorPos[0]); + V8_OBJECT_SET_INTEGER(pos, "y", cursorPos[1]); + + V8_RETURN(pos); } static void SetCursorPos(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto val = info[0]; - V8_CHECK(val->IsObject(), "cursorPos must be a object"); + V8_GET_ISOLATE_CONTEXT(); - v8::Local x = val.As()->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked(); - v8::Local y = val.As()->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_OBJECT(1, pos); + V8_OBJECT_GET_INTEGER(pos, "x", x); + V8_OBJECT_GET_INTEGER(pos, "y", y); - ICore::Instance().SetCursorPosition({x->ToInteger(ctx).ToLocalChecked()->Value(), - y->ToInteger(ctx).ToLocalChecked()->Value()}); + ICore::Instance().SetCursorPosition({ x, y }); } static void LoadModel(const v8::FunctionCallbackInfo &info) @@ -185,167 +134,134 @@ static void LoadModelAsync(const v8::FunctionCallbackInfo &info) static void IsTextureExistInArchetype(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 2, "2 args expected"); - - v8::Local modelHash = info[0]->ToInteger(ctx).ToLocalChecked(); - std::string modelName = *v8::String::Utf8Value(info.GetIsolate(), info[1].As()); + V8_GET_ISOLATE_CONTEXT(); - void *texture = ICore::Instance().GetTextureFromDrawable(modelHash->Value(), modelName); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_INTEGER(1, modelHash); + V8_ARG_TO_STRING(2, modelName); - info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), texture != nullptr)); + V8_RETURN_BOOLEAN(nullptr != ICore::Instance().GetTextureFromDrawable(modelHash, modelName)); } static void RequestIPL(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_GET_ISOLATE_CONTEXT(); - std::string iplName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, iplName); - ICore::Instance().RequestIPL(iplName.c_str()); + ICore::Instance().RequestIPL(iplName); } static void RemoveIPL(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_GET_ISOLATE_CONTEXT(); - std::string iplName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, iplName); - ICore::Instance().RemoveIPL(iplName.c_str()); + ICore::Instance().RemoveIPL(iplName); } static void GetLicenseHash(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - auto ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - auto licenseHash = ICore::Instance().GetLicenseHash(); - info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, licenseHash.CStr()).ToLocalChecked()); + V8_RETURN_STRING(ICore::Instance().GetLicenseHash().CStr()); } static void SetCamFrozen(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_GET_ISOLATE_CONTEXT(); - v8::Local state = info[0]->ToBoolean(isolate); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_BOOLEAN(1, state); - ICore::Instance().SetCamFrozen(state->Value()); + ICore::Instance().SetCamFrozen(state); } -// static void IsInSandbox(const v8::FunctionCallbackInfo &info) -// { -// info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), CGame::Instance().IsSandbox())); -// } - static void IsInDebug(const v8::FunctionCallbackInfo &info) { - info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), alt::ICore::Instance().IsDebug())); + V8_GET_ISOLATE_CONTEXT(); + + V8_RETURN_BOOLEAN(alt::ICore::Instance().IsDebug()); } static void IsVoiceActivityInputEnabled(const v8::FunctionCallbackInfo &info) { - info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), ICore::Instance().IsVoiceActivationEnabled())); + V8_GET_ISOLATE_CONTEXT(); + + V8_RETURN_BOOLEAN(ICore::Instance().IsVoiceActivationEnabled()); } static void AddGxtText(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK(info.Length() == 2, "2 args expected"); - - std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); - std::string textValue = *v8::String::Utf8Value(info.GetIsolate(), info[1].As()); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, key); + V8_ARG_TO_STRING(2, textValue); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); - static_cast(resource)->AddGxtText(ICore::Instance().Hash(key), textValue); + static_cast(resource)->AddGxtText(ICore::Instance().Hash(key), textValue.ToString()); } static void RemoveGxtText(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); - V8_CHECK(resource, "Invalid resource"); static_cast(resource)->RemoveGxtText(ICore::Instance().Hash(key)); } static void GetGxtText(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); - std::string text = static_cast(resource)->GetGxtText(ICore::Instance().Hash(key)); - info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, text.c_str()).ToLocalChecked()); + V8_RETURN_STRING(static_cast(resource)->GetGxtText(ICore::Instance().Hash(key)).c_str()); } static void GetMsPerGameMinute(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8_GET_ISOLATE(info); - int32_t ms = ICore::Instance().GetMsPerGameMinute(); - info.GetReturnValue().Set(v8::Integer::New(isolate, ms)); + V8_RETURN_INTEGER(ICore::Instance().GetMsPerGameMinute()); } static void SetMsPerGameMinute(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, ms); - v8::Local ms = info[0]->ToInteger(ctx).ToLocalChecked(); - ICore::Instance().SetMsPerGameMinute(ms->Value()); + ICore::Instance().SetMsPerGameMinute(ms); } static void BeginScaleformMovieMethodMinimap(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - std::string methodName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, methodName); - bool result = ICore::Instance().BeginScaleformMovieMethodMinimap(methodName.c_str()); - info.GetReturnValue().Set(v8::Boolean::New(isolate, result)); + V8_RETURN_BOOLEAN(ICore::Instance().BeginScaleformMovieMethodMinimap(methodName.CStr())); } static void GetLocale(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - auto locale = ICore::Instance().GetLocale(); + V8_GET_ISOLATE_CONTEXT(); - info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, locale.CStr()).ToLocalChecked()); + V8_RETURN_STRING(ICore::Instance().GetLocale().CStr()); } static void SetWeatherCycle(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); V8_CHECK(info.Length() == 2, "2 args expected"); V8_CHECK(info[0]->IsArray(), "weathers must be an array"); @@ -379,101 +295,87 @@ static void SetWeatherCycle(const v8::FunctionCallbackInfo &info) static void SetWeatherSyncActive(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE(info); - V8_CHECK(info.Length() == 1, "1 arg expected"); - V8_CHECK(info[0]->IsBoolean(), "activeState must be boolean"); - - v8::Local isActive = info[0].As(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_BOOLEAN(1, isActive); - ICore::Instance().SetWeatherSyncActive(isActive->Value()); + ICore::Instance().SetWeatherSyncActive(isActive); } static void SetCharStat(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 2, "2 args expected"); - V8_CHECK(info[0]->IsString(), "statName must be string"); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, statName); - std::string statName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); IStatData *targetStat = alt::ICore::Instance().GetStatData(statName); V8_CHECK(targetStat != nullptr, "stat with this name not found"); - v8::Local ctx = isolate->GetEnteredContext(); - V8_CHECK(strcmp(targetStat->GetStatType(), "NONE") != 0 && strcmp(targetStat->GetStatType(), "PROFILE_SETTING") != 0, "target stat can't be edited"); if (!strcmp(targetStat->GetStatType(), "INT")) { - V8_CHECK(info[1]->IsNumber(), "value must be number"); - int32_t intValue = info[1]->ToInt32(ctx).ToLocalChecked()->Value(); - targetStat->SetInt32Value(intValue); - info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + V8_ARG_TO_INTEGER(2, value); + targetStat->SetInt32Value(value); + V8_RETURN_BOOLEAN(true); return; } else if (!strcmp(targetStat->GetStatType(), "INT64")) { - V8_CHECK(info[1]->IsNumber(), "value must be number"); - int64_t intValue = info[1]->ToBigInt(ctx).ToLocalChecked()->Int64Value(); - targetStat->SetInt64Value(intValue); - info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + V8_ARG_TO_INTEGER(2, value); + targetStat->SetInt64Value(value); + V8_RETURN_BOOLEAN(true); return; } else if (!strcmp(targetStat->GetStatType(), "TEXTLABEL")) { - V8_CHECK(info[1]->IsNumber(), "value must be number"); - int32_t intValue = info[1]->ToInt32(ctx).ToLocalChecked()->Value(); - targetStat->SetInt32Value(intValue); - info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + V8_ARG_TO_INTEGER(2, value); + targetStat->SetInt32Value(value); + V8_RETURN_BOOLEAN(true); return; } else if (!strcmp(targetStat->GetStatType(), "FLOAT")) { - V8_CHECK(info[1]->IsNumber(), "value must be number"); - float floatValue = info[1]->ToNumber(ctx).ToLocalChecked()->Value(); - targetStat->SetFloatValue(floatValue); - info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + V8_ARG_TO_NUMBER(2, value); + targetStat->SetFloatValue(value); + V8_RETURN_BOOLEAN(true); return; } else if (!strcmp(targetStat->GetStatType(), "BOOL")) { - V8_CHECK(info[1]->IsBoolean(), "value must be boolean"); - bool boolValue = info[1]->ToBoolean(isolate)->Value(); - targetStat->SetBoolValue(boolValue); - info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + V8_ARG_TO_BOOLEAN(2, value); + targetStat->SetBoolValue(value); + V8_RETURN_BOOLEAN(true); return; } else if (!strcmp(targetStat->GetStatType(), "STRING")) { - V8_CHECK(info[1]->IsString(), "value must be string"); - std::string stringValue = *v8::String::Utf8Value(info.GetIsolate(), info[1].As()); - targetStat->SetStringValue(stringValue.c_str()); - info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + V8_ARG_TO_STRING(2, value); + targetStat->SetStringValue(value.CStr()); + V8_RETURN_BOOLEAN(true); return; } else if (!strcmp(targetStat->GetStatType(), "UINT8")) { - V8_CHECK(info[1]->IsNumber(), "value must be number"); - uint8_t intValue = info[1]->ToUint32(ctx).ToLocalChecked()->Value(); - targetStat->SetUInt8Value(intValue); - info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + V8_ARG_TO_INTEGER(2, value); + targetStat->SetUInt8Value(value); + V8_RETURN_BOOLEAN(true); return; } else if (!strcmp(targetStat->GetStatType(), "UINT16")) { - V8_CHECK(info[1]->IsNumber(), "value must be number"); - uint16_t intValue = info[1]->ToUint32(ctx).ToLocalChecked()->Value(); - targetStat->SetUInt16Value(intValue); - info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + V8_ARG_TO_INTEGER(2, value); + targetStat->SetUInt16Value(value); + V8_RETURN_BOOLEAN(true); return; } else if (!strcmp(targetStat->GetStatType(), "UINT32")) { - V8_CHECK(info[1]->IsNumber(), "value must be number"); - uint32_t intValue = info[1]->ToUint32(ctx).ToLocalChecked()->Value(); - targetStat->SetUInt32Value(intValue); - info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + V8_ARG_TO_INTEGER(2, value); + targetStat->SetUInt32Value(value); + V8_RETURN_BOOLEAN(true); return; } else if ( @@ -483,14 +385,13 @@ static void SetCharStat(const v8::FunctionCallbackInfo &info) !strcmp(targetStat->GetStatType(), "PACKED") || !strcmp(targetStat->GetStatType(), "USERID")) { - V8_CHECK(info[1]->IsNumber(), "value must be number"); - uint64_t intValue = info[1]->ToBigInt(ctx).ToLocalChecked()->Uint64Value(); - targetStat->SetUInt64Value(intValue); - info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + V8_ARG_TO_INTEGER(2, value); + targetStat->SetUInt64Value(value); + V8_RETURN_BOOLEAN(true); return; } - info.GetReturnValue().Set(v8::Boolean::New(isolate, false)); + V8_RETURN_BOOLEAN(false); } static void GetCharStat(const v8::FunctionCallbackInfo &info) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 4047ab7d..80f357eb 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -9,274 +9,70 @@ static void NameGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref player = _this->GetHandle().As(); + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, player->GetName().CStr()).ToLocalChecked()); } static void VehicleGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref player = _this->GetHandle().As(); - alt::Ref vehicle = player->GetVehicle(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - if (vehicle) - info.GetReturnValue().Set(resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); - else - info.GetReturnValue().Set(v8::Null(info.GetIsolate())); + V8_RETURN_BASE_OBJECT(player->GetVehicle()); } static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref player = _this->GetHandle().As(); + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - info.GetReturnValue().Set(v8::Boolean::New(isolate, player->IsTalking())); + V8_RETURN_BOOLEAN(player->IsTalking()); } static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref player = _this->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, player->GetMicLevel())); + V8_RETURN_INTEGER(player->GetMicLevel()); } -// static void GiveWeapon(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref player = _this->GetHandle().As(); - -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - -// V8_CHECK(info[1]->IsNumber(), "ammoCount must be a number"); -// uint32_t ammoCount = info[1]->NumberValue(ctx).ToChecked(); - -// player->GiveWeapon(weaponHash, ammoCount, false); // todo: allow setter for selected -// } - -// static void RemoveWeapon(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref player = _this->GetHandle().As(); - -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - -// info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), player->RemoveWeapon(weaponHash))); -// } - -// static void RemoveAllWeapons(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref player = _this->GetHandle().As(); - -// player->RemoveAllWeapons(); -// } - -// static void AddWeaponComponent(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref player = _this->GetHandle().As(); - -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - -// V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); -// uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); - -// player->AddWeaponComponent(weaponHash, componentHash); -// } - -// static void RemoveWeaponComponent(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref player = _this->GetHandle().As(); - -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - -// V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); -// uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); - -// player->RemoveWeaponComponent(weaponHash, componentHash); -// } - static void WeaponHasComponent(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref player = _this->GetHandle().As(); - - V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); - uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - - V8_CHECK(info[1]->IsNumber(), "componentHash must be a number"); - uint32_t componentHash = info[1]->NumberValue(ctx).ToChecked(); - - info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), player->HasWeaponComponent(weaponHash, componentHash))); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_INTEGER(1, weaponHash); + V8_ARG_TO_INTEGER(2, componentHash); + + V8_RETURN_BOOLEAN(player->HasWeaponComponent(weaponHash, componentHash)); } -// static void SetWeaponTintIndex(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref player = _this->GetHandle().As(); - -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - -// V8_CHECK(info[1]->IsNumber(), "tintIndex must be a number"); -// uint8_t tintIndex = info[1]->NumberValue(ctx).ToChecked(); - -// player->SetWeaponTintIndex(weaponHash, tintIndex); -// } - static void GetWeaponTintIndex(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - alt::Ref player = _this->GetHandle().As(); - - V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); - uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, weaponHash); - info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), player->GetWeaponTintIndex(weaponHash))); + V8_RETURN_INTEGER(player->GetWeaponTintIndex(weaponHash)); } -// static void SetCurrentWeapon(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// alt::Ref player = _this->GetHandle().As(); - -// V8_CHECK(info[0]->IsNumber(), "weaponHash must be a number"); -// uint32_t weaponHash = info[0]->NumberValue(ctx).ToChecked(); - -// player->SetCurrentWeapon(weaponHash); -// } - static void GetCurrentWeapon(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - alt::Ref player = _this->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(info.GetIsolate(), player->GetCurrentWeapon())); + V8_RETURN_INTEGER(player->GetCurrentWeapon()); } static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); v8::Local arr = v8::Array::New(info.GetIsolate()); @@ -287,21 +83,13 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfoSet(ctx, i++, resource->GetOrCreateEntity(player.Get(), "Player")->GetJSVal(isolate)); }; - info.GetReturnValue().Set(arr); + V8_RETURN(arr); } static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); - - auto localPlayer = alt::ICore::Instance().GetLocalPlayer(); - if (!localPlayer) - info.GetReturnValue().Set(v8::Null(isolate)); - else - info.GetReturnValue().Set(resource->GetOrCreateEntity(localPlayer.Get())->GetJSVal(isolate)); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetLocalPlayer()); } static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index b6e84f8a..c5acb311 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -9,129 +9,58 @@ using namespace alt; static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - std::vector> args{ - info.This()}; + V8_GET_ISOLATE_CONTEXT(); + V8_NEW_ARGS(args); + V8_ADD_ARG(args, info.This()); + extern V8Class v8Handling; - info.GetReturnValue().Set(v8Handling.New(isolate->GetEnteredContext(), args)); + V8_RETURN(v8Handling.New(isolate->GetEnteredContext(), args)); } static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref vehicle = _this->GetHandle().As(); + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetWheelSpeed())); + V8_RETURN_NUMBER(vehicle->GetWheelSpeed()); } static void GearGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref vehicle = _this->GetHandle().As(); - - info.GetReturnValue().Set(v8::Integer::New(isolate, vehicle->GetCurrentGear())); + V8_RETURN_INTEGER(vehicle->GetCurrentGear()); } static void RPMGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - alt::Ref vehicle = _this->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetCurrentRPM())); + V8_RETURN_NUMBER(vehicle->GetCurrentRPM()); } static void WheelsCountGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - alt::Ref vehicle = _this->GetHandle().As(); - - info.GetReturnValue().Set(v8::Number::New(isolate, vehicle->GetWheelsCount())); + V8_RETURN_INTEGER(vehicle->GetWheelsCount()); } static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref vehicle = _this->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - info.GetReturnValue().Set(resource->CreateVector3(vehicle->GetSpeedVector())); + V8_RETURN(resource->CreateVector3(vehicle->GetSpeedVector())); } -// static void GravityGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// V8_GET_ISOLATE_CONTEXT(); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); -// V8_CHECK(resource, "invalid resource"); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// auto vehicle = _this->GetHandle().As()->GetGameVehicle(); -// V8_CHECK(vehicle, "Could not retrieve game vehicle"); - -// Log::Debug("GRAVITY", vehicle->gravity); -// auto ret = v8::Number::New(isolate, vehicle->gravity); -// Log::Debug("RET GRAVITY", ret->NumberValue(ctx).ToChecked()); -// info.GetReturnValue().Set(ret); -// } - -// static void GravitySetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// V8_GET_ISOLATE_CONTEXT(); -// V8_CHECK(val->IsNumber(), "val must be a number"); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "invalid resource"); - -// V8_CHECK(val->IsNumber(), "val needs to be a nummber (float)"); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// auto vehicle = _this->GetHandle().As()->GetGameVehicle(); -// V8_CHECK(vehicle, "Could not retrieve game vehicle"); - -// Log::Debug("GRAVITY", vehicle->gravity); -// auto newval = val->NumberValue(ctx).ToChecked(); -// Log::Debug("NEW GRAVITY", newval); -// vehicle->gravity = newval; -// } - static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); v8::Local arr = v8::Array::New(info.GetIsolate()); @@ -142,7 +71,7 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo arr->Set(ctx, i++, resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); }; - info.GetReturnValue().Set(arr); + V8_RETURN(arr); } static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) @@ -177,6 +106,5 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetAccessor(isolate, tpl, "rpm", &RPMGetter); V8::SetAccessor(isolate, tpl, "wheelsCount", &WheelsCountGetter); V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); - // V8::SetAccessor(isolate, tpl, "gravity", &GravityGetter, &GravitySetter); V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); }); diff --git a/src/helpers b/src/helpers index 55e27f13..9f6c00e5 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 55e27f13686a893185e9ff8f104e61e3f8fbc8d0 +Subproject commit 9f6c00e50423a07205b2b799d6ed66a4eb1fa38f From df8b3e0de536960a83abfa83a6db1c3188ebbce3 Mon Sep 17 00:00:00 2001 From: Vektor Date: Tue, 17 Nov 2020 13:11:36 +0100 Subject: [PATCH 085/564] add more macros --- V8Helpers.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/V8Helpers.h b/V8Helpers.h index b44c8528..06bf0ccb 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -270,7 +270,8 @@ namespace V8 #define V8_CHECK_ARGS_LEN(count) V8_CHECK(info.Length() == (count), #count " arguments expected") #define V8_CHECK_ARGS_LEN2(count1, count2) V8_CHECK(info.Length() == (count1) || info.Length() == (count2), #count1 " or " #count2 " arguments expected") -#define V8_CHECK_ARGS_LEN3(count) V8_CHECK(info.Length() == (count), "Atleast " #count " arguments expected") +#define V8_CHECK_ARGS_LEN_MIN_MAX(count1, count2) V8_CHECK(info.Length() >= (count1) && info.Length() <= (count2), "Minimum " #count1 ", maximum " #count2 " arguments expected") +#define V8_CHECK_ARGS_LEN_MIN(count) V8_CHECK(info.Length() <= (count), "Minimum " #count " arguments expected") #define V8_TO_BOOLEAN(v8Val, val) \ bool val; \ @@ -339,6 +340,10 @@ namespace V8 val = defaultVal; \ } +// idx starts with 1 +#define V8_ARG_TO_MVALUE(idx, val) \ + alt::MValue val = V8Helpers::V8ToMValue(info[(idx)-1]); + // idx starts with 1 #define V8_ARG_TO_INTEGER(idx, val) \ int64_t val; \ From 8f1f6c2982d7976664b4743ff6a72dae36bfbce2 Mon Sep 17 00:00:00 2001 From: Vektor Date: Tue, 17 Nov 2020 13:13:33 +0100 Subject: [PATCH 086/564] redo bindings 2 --- src/bindings/LocalStorage.cpp | 70 +++++------ src/bindings/Main.cpp | 133 +++++++------------- src/bindings/Player.cpp | 16 +-- src/bindings/WebView.cpp | 229 +++++++++++++--------------------- src/helpers | 2 +- 5 files changed, 174 insertions(+), 276 deletions(-) diff --git a/src/bindings/LocalStorage.cpp b/src/bindings/LocalStorage.cpp index 4088975a..2bcfa884 100644 --- a/src/bindings/LocalStorage.cpp +++ b/src/bindings/LocalStorage.cpp @@ -7,62 +7,57 @@ static void StaticGet(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); - - info.GetReturnValue().Set(static_cast(resource)->GetLocalStorage()); + V8_RETURN(static_cast(resource)->GetLocalStorage()); } static void Get(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::IResource *resource = V8ResourceImpl::GetResource(ctx); V8_CHECK(resource, "Invalid resource"); - std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); - alt::MValueConst val = resource->GetLocalStorage()->Get(key); - - info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); + V8_RETURN(V8Helpers::MValueToV8(resource->GetLocalStorage()->Get(key))); } static void Set(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 2, "2 args expected"); + V8_CHECK_ARGS_LEN(2); - alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_ARG_TO_STRING(1, key); + V8_ARG_TO_MVALUE(2, val); + + alt::IResource *resource = V8ResourceImpl::GetResource(ctx); V8_CHECK(resource, "Invalid resource"); - std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); - alt::MValue val = V8Helpers::V8ToMValue(info[1]); - resource->GetLocalStorage()->Set(key, val); } static void Delete(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::IResource *resource = V8ResourceImpl::GetResource(ctx); V8_CHECK(resource, "Invalid resource"); - std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); resource->GetLocalStorage()->Delete(key); } static void Clear(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8_GET_ISOLATE_CONTEXT(); - alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::IResource *resource = V8ResourceImpl::GetResource(ctx); V8_CHECK(resource, "Invalid resource"); resource->GetLocalStorage()->Clear(); @@ -70,27 +65,26 @@ static void Clear(const v8::FunctionCallbackInfo &info) static void Save(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::IResource *resource = V8ResourceImpl::GetResource(ctx); V8_CHECK(resource, "Invalid resource"); - std::string key = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); V8_CHECK(resource->GetLocalStorage()->Save(), "exceeded max local storage size (4MB)"); } -extern V8Class v8LocalStorage( - "LocalStorage", nullptr, [](v8::Local tpl) { +extern V8Class v8LocalStorage("LocalStorage", nullptr, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); - tpl->Set(isolate, "get", v8::FunctionTemplate::New(isolate, &StaticGet)); - - v8::Local proto = tpl->PrototypeTemplate(); + V8::SetStaticMethod(isolate, tpl, "get", &StaticGet); - proto->Set(isolate, "get", v8::FunctionTemplate::New(isolate, &Get)); - proto->Set(isolate, "set", v8::FunctionTemplate::New(isolate, &Set)); - proto->Set(isolate, "delete", v8::FunctionTemplate::New(isolate, &Delete)); - proto->Set(isolate, "deleteAll", v8::FunctionTemplate::New(isolate, &Clear)); - proto->Set(isolate, "clear", v8::FunctionTemplate::New(isolate, &Clear)); - proto->Set(isolate, "save", v8::FunctionTemplate::New(isolate, &Save)); + V8::SetMethod(isolate, tpl, "get", &Get); + V8::SetMethod(isolate, tpl, "set", &Set); + V8::SetMethod(isolate, tpl, "delete", &Delete); + V8::SetMethod(isolate, tpl, "deleteAll", &Clear); + V8::SetMethod(isolate, tpl, "clear", &Clear); + V8::SetMethod(isolate, tpl, "save", &Save); }); diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 04f47e9f..5d42cc77 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -35,7 +35,7 @@ static void EmitServer(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK_ARGS_LEN3(1); + V8_CHECK_ARGS_LEN_MIN(1); V8_ARG_TO_STRING(1, eventName); alt::MValueArgs args; @@ -396,13 +396,11 @@ static void SetCharStat(const v8::FunctionCallbackInfo &info) static void GetCharStat(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 1, "1 arg expected"); - V8_CHECK(info[0]->IsString(), "statName must be string"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, statName); - std::string statName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); IStatData *targetStat = alt::ICore::Instance().GetStatData(statName); V8_CHECK(targetStat != nullptr, "stat with this name not found"); @@ -410,56 +408,47 @@ static void GetCharStat(const v8::FunctionCallbackInfo &info) if (!strcmp(targetStat->GetStatType(), "INT")) { - int32_t intValue = targetStat->GetInt32Value(); - info.GetReturnValue().Set(v8::Integer::New(isolate, intValue)); + V8_RETURN_INTEGER(targetStat->GetInt32Value()); return; } else if (!strcmp(targetStat->GetStatType(), "INT64")) { - int64_t intValue = targetStat->GetInt64Value(); - info.GetReturnValue().Set(v8::BigInt::New(isolate, intValue)); + V8_RETURN_INTEGER(targetStat->GetInt64Value()); return; } else if (!strcmp(targetStat->GetStatType(), "TEXTLABEL")) { - int32_t intValue = targetStat->GetInt32Value(); - info.GetReturnValue().Set(v8::Integer::New(isolate, intValue)); + V8_RETURN_INTEGER(targetStat->GetInt32Value()); return; } else if (!strcmp(targetStat->GetStatType(), "FLOAT")) { - float floatValue = targetStat->GetFloatValue(); - info.GetReturnValue().Set(v8::Number::New(isolate, floatValue)); + V8_RETURN_NUMBER(targetStat->GetFloatValue()); return; } else if (!strcmp(targetStat->GetStatType(), "BOOL")) { - bool boolValue = targetStat->GetBoolValue(); - info.GetReturnValue().Set(v8::Boolean::New(isolate, boolValue)); + V8_RETURN_BOOLEAN(targetStat->GetBoolValue()); return; } else if (!strcmp(targetStat->GetStatType(), "STRING")) { - const char *stringValue = targetStat->GetStringValue(); - info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, stringValue).ToLocalChecked()); + V8_RETURN_STRING(targetStat->GetStringValue()); return; } else if (!strcmp(targetStat->GetStatType(), "UINT8")) { - uint8_t intValue = targetStat->GetUInt8Value(); - info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, intValue)); + V8_RETURN_INTEGER(targetStat->GetUInt8Value()); return; } else if (!strcmp(targetStat->GetStatType(), "UINT16")) { - uint16_t intValue = targetStat->GetUInt16Value(); - info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, intValue)); + V8_RETURN_INTEGER(targetStat->GetUInt16Value()); return; } else if (!strcmp(targetStat->GetStatType(), "UINT32")) { - uint32_t intValue = targetStat->GetUInt32Value(); - info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, intValue)); + V8_RETURN_INTEGER(targetStat->GetUInt32Value()); return; } else if ( @@ -469,64 +458,58 @@ static void GetCharStat(const v8::FunctionCallbackInfo &info) !strcmp(targetStat->GetStatType(), "PACKED") || !strcmp(targetStat->GetStatType(), "USERID")) { - uint64_t intValue = targetStat->GetUInt64Value(); - info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(isolate, intValue)); + V8_RETURN_INTEGER(targetStat->GetUInt64Value()); return; } - info.GetReturnValue().Set(v8::Null(isolate)); + V8_RETURN_NULL(); } static void ResetCharStat(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 1, "1 arg expected"); - V8_CHECK(info[0]->IsString(), "statName must be string"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, statName); - std::string statName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); IStatData *targetStat = alt::ICore::Instance().GetStatData(statName); V8_CHECK(targetStat != nullptr, "stat with this name not found"); - v8::Local ctx = isolate->GetEnteredContext(); - V8_CHECK(strcmp(targetStat->GetStatType(), "NONE") != 0 && strcmp(targetStat->GetStatType(), "PROFILE_SETTING") != 0, "target stat can't be reseted"); targetStat->Reset(); - info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + V8_RETURN_BOOLEAN(true); } static void IsMenuOpen(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - info.GetReturnValue().Set(v8::Boolean::New(isolate, ICore::Instance().IsMenuOpen())); + V8_GET_ISOLATE(info); + V8_RETURN_BOOLEAN(ICore::Instance().IsMenuOpen()); } static void IsConsoleOpen(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - info.GetReturnValue().Set(v8::Boolean::New(isolate, ICore::Instance().IsConsoleOpen())); + V8_GET_ISOLATE(info); + V8_RETURN_BOOLEAN(ICore::Instance().IsConsoleOpen()); } static void IsKeyDown(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 1, "1 arg expected"); - uint32_t keycode = info[0]->ToUint32(ctx).ToLocalChecked()->Value(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, keycode); - info.GetReturnValue().Set(v8::Boolean::New(isolate, alt::ICore::Instance().GetKeyState(keycode).IsDown())); + V8_RETURN_BOOLEAN(alt::ICore::Instance().GetKeyState(keycode).IsDown()); } static void IsKeyToggled(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 1, "1 arg expected"); - uint32_t keycode = info[0]->ToUint32(ctx).ToLocalChecked()->Value(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, keycode); - info.GetReturnValue().Set(v8::Boolean::New(isolate, alt::ICore::Instance().GetKeyState(keycode).IsToggled())); + V8_RETURN_BOOLEAN(alt::ICore::Instance().GetKeyState(keycode).IsToggled()); } static void SetConfigFlag(const v8::FunctionCallbackInfo &info) @@ -599,44 +582,26 @@ static void DoesConfigFlagExist(const v8::FunctionCallbackInfo &info) static void GetPermissionState(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - V8_CHECK(info[0]->IsUint32(), "1st arg must be permission id"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT(); - auto permnum = info[0].As()->Value(); - V8_CHECK(permnum < (uint32_t)alt::Permission::All, "Invalid permission"); - auto perm = (alt::Permission)permnum; + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, permnum); - auto state = alt::ICore::Instance().GetPermissionState(perm); - info.GetReturnValue().Set(v8::Uint32::NewFromUnsigned(isolate, (uint8_t)state)); + V8_RETURN_INTEGER((uint8_t)alt::ICore::Instance().GetPermissionState((alt::Permission)permnum)); } static void IsInStreamerMode(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE(info); - info.GetReturnValue().Set(v8::Boolean::New(isolate, alt::ICore::Instance().IsInStreamerMode())); + V8_RETURN_BOOLEAN(alt::ICore::Instance().IsInStreamerMode()); } static void TakeScreenshot(const v8::FunctionCallbackInfo &info) { static std::list> promises; - static v8::Isolate *_isolate = v8::Isolate::GetCurrent(); - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(ICore::Instance().IsDebug(), "Must be in debug mode"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT(); auto &api = alt::ICore::Instance(); auto state = api.GetPermissionState(alt::Permission::ScreenCapture); @@ -646,7 +611,7 @@ static void TakeScreenshot(const v8::FunctionCallbackInfo &info) auto &persistent = promises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); api.TakeScreenshot([](alt::StringView base64, const void *userData) { - v8::Isolate *isolate = _isolate; + v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -660,24 +625,15 @@ static void TakeScreenshot(const v8::FunctionCallbackInfo &info) } promises.remove(*persistent); - }, - &persistent); + }, &persistent); - info.GetReturnValue().Set(persistent.Get(isolate)->GetPromise()); } static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &info) { static std::list> promises; - static v8::Isolate *_isolate = v8::Isolate::GetCurrent(); - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(ICore::Instance().IsDebug(), "Must be in debug mode"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT(); auto &api = alt::ICore::Instance(); auto state = api.GetPermissionState(alt::Permission::ScreenCapture); @@ -687,7 +643,7 @@ static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &in auto &persistent = promises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); api.TakeScreenshotGameOnly([](alt::StringView base64, const void *userData) { - v8::Isolate *isolate = _isolate; + v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -702,10 +658,9 @@ static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &in promises.remove(*persistent); ctx->Exit(); - }, - &persistent); + }, &persistent); - info.GetReturnValue().Set(persistent.Get(isolate)->GetPromise()); + V8_RETURN(persistent.Get(isolate)->GetPromise()); } extern V8Class v8Vector3, diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 80f357eb..23fedc4b 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -70,7 +70,7 @@ static void GetCurrentWeapon(const v8::FunctionCallbackInfo &info) V8_RETURN_INTEGER(player->GetCurrentWeapon()); } -static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -86,7 +86,7 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo name, const v8::PropertyCallbackInfo &info) +static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetLocalPlayer()); @@ -117,13 +117,13 @@ extern V8Class v8Player("Player", v8Entity, [](v8::Local t V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); - tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, "all").ToLocalChecked(), &AllGetter); - tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, "local").ToLocalChecked(), &LocalGetter); + V8::SetStaticAccessor(isolate, tpl, "all", &AllGetter); + V8::SetStaticAccessor(isolate, tpl, "local", &LocalGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "name").ToLocalChecked(), &NameGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "vehicle").ToLocalChecked(), &VehicleGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "isTalking").ToLocalChecked(), &TalkingGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "micLevel").ToLocalChecked(), &MicLevelGetter); + V8::SetAccessor(isolate, tpl, "name", &NameGetter); + V8::SetAccessor(isolate, tpl, "vehicle", &VehicleGetter); + V8::SetAccessor(isolate, tpl, "isTalking", &TalkingGetter); + V8::SetAccessor(isolate, tpl, "micLevel", &MicLevelGetter); if (alt::ICore::Instance().IsSandbox()) { diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index b42c88ed..e552f6f8 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -10,59 +10,38 @@ using namespace alt; static void On(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK(info.Length() == 2, "2 args expected"); - V8_CHECK(info[0]->IsString(), "eventName must be a string"); - V8_CHECK(info[1]->IsFunction(), "callback must be a function"); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, fun); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref view = _this->GetHandle().As(); - std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); - - static_cast(resource)->SubscribeWebView(view, evName, info[1].As(), V8::SourceLocation::GetCurrent(isolate)); + static_cast(resource)->SubscribeWebView(view, evName.ToString(), fun, V8::SourceLocation::GetCurrent(isolate)); } static void Off(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() == 2, "2 args expected"); - V8_CHECK(info[0]->IsString(), "eventName must be a string"); - V8_CHECK(info[1]->IsFunction(), "callback must be a function"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, fun); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - alt::Ref view = _this->GetHandle().As(); - std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); - - static_cast(resource)->UnsubscribeWebView(view, evName, info[1].As()); + static_cast(resource)->UnsubscribeWebView(view, evName.ToString(), fun); } static void Emit(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() >= 1, "WebView.emit expects atleast 1 arg"); - V8_CHECK(info[0]->IsString(), "eventName must be a string"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, evName); - alt::Ref view = _this->GetHandle().As(); - std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); alt::MValueArgs mvArgs; @@ -74,151 +53,121 @@ static void Emit(const v8::FunctionCallbackInfo &info) static void Focus(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE(info); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref view = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); view->Focus(); } static void Unfocus(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE(info); - alt::Ref view = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); view->Unfocus(); } static void SetURL(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - V8_CHECK(info[0]->IsString(), "string expected"); + V8_GET_ISOLATE_CONTEXT(); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, url); - alt::Ref view = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - v8::String::Utf8Value url(info.GetIsolate(), info[0].As()); - - view->SetUrl(*url); + view->SetUrl(url); } static void IsVisibleGetter(v8::Local property, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE(info); - alt::Ref view = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - info.GetReturnValue().Set(v8::Boolean::New(isolate, view->IsVisible())); + V8_RETURN_BOOLEAN(view->IsVisible()); } static void IsVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE(info); - alt::Ref view = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - view->SetVisible(value->BooleanValue(isolate)); + V8_TO_BOOLEAN(value, state); + view->SetVisible(state); } static void URLGetter(v8::Local property, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE(info); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - alt::Ref view = _this->GetHandle().As(); - - info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, view->GetUrl().CStr()).ToLocalChecked()); + V8_RETURN_STRING(view->GetUrl().CStr()); } static void URLSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetCurrentContext(); + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); + + V8_TO_STRING(value, url); + + view->SetUrl(url); +} + +static void Constructor(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN_MIN_MAX(1, 3); + + V8_ARG_TO_STRING(1, url); + + alt::IResource* altres = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(altres, "invalid resource"); + + alt::Ref view = nullptr; + + if (info.Length() == 3) + { + V8_ARG_TO_INTEGER(2, drawableHash); + V8_ARG_TO_STRING(3, targetTextureStr); + + auto texture = alt::ICore::Instance().GetTextureFromDrawable(drawableHash, targetTextureStr); + V8_CHECK(texture != nullptr, "Texture not found"); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + view = altres->CreateWebView(url, (uint32_t)drawableHash, targetTextureStr); + V8_CHECK(!view.IsEmpty(), "Interactive WebView cannot be created"); + } + else if (info.Length() == 2) + { + V8_ARG_TO_BOOLEAN(2, isOverlayBool); - alt::Ref view = _this->GetHandle().As(); + view = altres->CreateWebView(url, { 0, 0 }, { 0, 0 }, true, isOverlayBool); + } + else + { + view = altres->CreateWebView(url, { 0, 0 }, { 0, 0 }, true, false); + } - v8::String::Utf8Value url{isolate, value->ToString(ctx).ToLocalChecked()}; - view->SetUrl(*url); + V8_BIND_BASE_OBJECT(view); } extern V8Class v8BaseObject; -extern V8Class v8WebView( - "WebView", v8BaseObject, - [](const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - - V8_CHECK(info.IsConstructCall(), "WebView is not a function"); - V8_CHECK(info.Length() > 0 && info.Length() <= 3, "new WebView(...) expects 1, 2 or 3 args"); - V8_CHECK(info[0]->IsString(), "url must be a string"); - - alt::IResource *altres = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - V8_CHECK(altres, "invalid resource"); - - v8::Local url = info[0].As(); - - alt::Ref view = nullptr; - - if (info.Length() == 3) - { - v8::Local modelHash = info[1]->ToInteger(ctx).ToLocalChecked(); - v8::Local targetTexture = info[2]->ToString(ctx).ToLocalChecked(); - - uint32_t drawableHash = modelHash->Value(); - std::string targetTextureStr = *v8::String::Utf8Value(info.GetIsolate(), targetTexture); - - auto texture = alt::ICore::Instance().GetTextureFromDrawable(drawableHash, targetTextureStr); - V8_CHECK(texture != nullptr, "Texture not found"); - - view = altres->CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), (uint32_t)drawableHash, targetTextureStr); - V8_CHECK(!view.IsEmpty(), "Interactive WebView cannot be created"); - } - else if (info.Length() == 2) - { - v8::Local isOverlay = info[1]->ToBoolean(isolate); - bool isOverlayBool = isOverlay->Value(); - - view = altres->CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), {0, 0}, {0, 0}, true, isOverlayBool); - } - else - { - view = altres->CreateWebView(*v8::String::Utf8Value(info.GetIsolate(), url), {0, 0}, {0, 0}, true, false); - } - - V8_BIND_BASE_OBJECT(view); - }, - [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8::SetAccessor(isolate, tpl, "isVisible", &IsVisibleGetter, &IsVisibleSetter); - V8::SetAccessor(isolate, tpl, "url", &URLGetter, &URLSetter); - - v8::Local proto = tpl->PrototypeTemplate(); - - proto->Set(isolate, "on", v8::FunctionTemplate::New(isolate, &On)); - proto->Set(isolate, "off", v8::FunctionTemplate::New(isolate, &Off)); - proto->Set(isolate, "emit", v8::FunctionTemplate::New(isolate, &Emit)); - proto->Set(isolate, "focus", v8::FunctionTemplate::New(isolate, &Focus)); - proto->Set(isolate, "unfocus", v8::FunctionTemplate::New(isolate, &Unfocus)); - }); +extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8::SetAccessor(isolate, tpl, "isVisible", &IsVisibleGetter, &IsVisibleSetter); + V8::SetAccessor(isolate, tpl, "url", &URLGetter, &URLSetter); + + V8::SetMethod(isolate, tpl, "on", &On); + V8::SetMethod(isolate, tpl, "off", &Off); + V8::SetMethod(isolate, tpl, "emit", &Emit); + V8::SetMethod(isolate, tpl, "focus", &Focus); + V8::SetMethod(isolate, tpl, "unfocus", &Unfocus); +}); diff --git a/src/helpers b/src/helpers index 9f6c00e5..df8b3e0d 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 9f6c00e50423a07205b2b799d6ed66a4eb1fa38f +Subproject commit df8b3e0de536960a83abfa83a6db1c3188ebbce3 From 30b83032804337febc641bfca82240ee0f1f4970 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 06:49:03 +0100 Subject: [PATCH 087/564] daily macro madness --- V8Helpers.h | 13 ++ bindings/BaseObject.cpp | 107 +++++------------ bindings/Entity.cpp | 252 ++++++++++++--------------------------- bindings/File.cpp | 36 ++---- bindings/Main.cpp | 214 ++++++++++++--------------------- bindings/RGBA.cpp | 46 +++---- bindings/Vector3.cpp | 9 +- bindings/WorldObject.cpp | 61 +++------- 8 files changed, 250 insertions(+), 488 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index 06bf0ccb..8e22d95f 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -233,10 +233,18 @@ namespace V8 V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); \ V8_CHECK(resource, "invalid resource"); +#define V8_GET_IRESOURCE() \ + alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); \ + V8_CHECK(resource, "invalid resource"); + #define V8_GET_ISOLATE_CONTEXT_RESOURCE() \ V8_GET_ISOLATE_CONTEXT(); \ V8_GET_RESOURCE() +#define V8_GET_ISOLATE_CONTEXT_IRESOURCE() \ + V8_GET_ISOLATE_CONTEXT(); \ + V8_GET_IRESOURCE() + #define V8_CHECK_RETN(a, b, c) \ if (!(a)) \ { \ @@ -266,6 +274,10 @@ namespace V8 #define V8_GET_THIS_INTERNAL_FIELD_ENTITY(idx, val, type) \ auto val = V8Entity::Get(info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredContext()).ToLocalChecked())->GetHandle().As(); +// idx starts with 1 +#define V8_GET_THIS_INTERNAL_FIELD_INTEGER(idx, val) \ + auto val = info.This()->GetInternalField((idx)-1)->IntegerValue(ctx).ToChecked(); + #define V8_CHECK_CONSTRUCTOR() V8_CHECK(info.IsConstructCall(), "function can't be called without new") #define V8_CHECK_ARGS_LEN(count) V8_CHECK(info.Length() == (count), #count " arguments expected") @@ -380,6 +392,7 @@ namespace V8 #define V8_RETURN_INTEGER(val) V8_RETURN(v8::Integer::New(isolate, (val))) #define V8_RETURN_NUMBER(val) V8_RETURN(v8::Number::New(isolate, (val))) #define V8_RETURN_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val), v8::NewStringType::kNormal).ToLocalChecked()) +#define V8_RETURN_MVALUE(val) V8_RETURN(V8Helpers::MValueToV8(val)) #define V8_RETURN_BASE_OBJECT(baseObjectRef) V8_RETURN(resource->GetBaseObjectOrNull(baseObjectRef)) diff --git a/bindings/BaseObject.cpp b/bindings/BaseObject.cpp index 39a56535..b1e96689 100644 --- a/bindings/BaseObject.cpp +++ b/bindings/BaseObject.cpp @@ -6,123 +6,78 @@ static void TypeGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE(info); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_THIS_BASE_OBJECT(obj, alt::IBaseObject); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref obj = _this->GetHandle(); - uint32_t type = static_cast(obj->GetType()); - - info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(info.GetIsolate(), type)); + V8_RETURN_INTEGER((uint32_t)obj->GetType()); } static void ValidGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE(info); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_THIS_BASE_OBJECT(obj, alt::IBaseObject); - V8Entity *_this = V8Entity::Get(info.This()); - info.GetReturnValue().Set(v8::Boolean::New(isolate, _this != nullptr)); + V8_RETURN_BOOLEAN(true); } static void HasMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_THIS_BASE_OBJECT(obj, alt::IBaseObject); - alt::Ref obj = _this->GetHandle(); - - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); - info.GetReturnValue().Set(v8::Boolean::New(isolate, obj->HasMetaData(*v8::String::Utf8Value(isolate, key)))); + V8_RETURN_BOOLEAN(obj->HasMetaData(key)); } static void GetMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); - alt::Ref obj = _this->GetHandle(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + V8_GET_THIS_BASE_OBJECT(obj, alt::IBaseObject); - alt::MValueConst val = obj->GetMetaData(*v8::String::Utf8Value(isolate, key)); - info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); + V8_RETURN_MVALUE(obj->GetMetaData(key)); } static void SetMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 2, "2 args expected"); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, key); + V8_ARG_TO_MVALUE(2, value); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_THIS_BASE_OBJECT(obj, alt::IBaseObject); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref obj = _this->GetHandle(); - - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); - v8::Local value = info[1]; - - obj->SetMetaData(*v8::String::Utf8Value(isolate, key), V8Helpers::V8ToMValue(value)); + obj->SetMetaData(key, value); } static void DeleteMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_GET_ISOLATE_CONTEXT(); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_THIS_BASE_OBJECT(obj, alt::IBaseObject); - alt::Ref obj = _this->GetHandle(); - - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); - - obj->DeleteMetaData(*v8::String::Utf8Value(isolate, key)); + obj->DeleteMetaData(key); } static void Destroy(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT(); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_THIS_BASE_OBJECT(obj, alt::IBaseObject); - alt::ICore::Instance().DestroyBaseObject(_this->GetHandle()); + alt::ICore::Instance().DestroyBaseObject(obj); } extern V8Class v8BaseObject("BaseObject", [](v8::Local tpl) { diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index 0f08c6f6..3cef16c9 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -9,290 +9,188 @@ using namespace alt; static void IDGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - Ref ent = _this->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); - info.GetReturnValue().Set(v8::Integer::New(isolate, ent->GetID())); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); + + V8_RETURN_INTEGER(ent->GetID()); } static void OwnerGetter(v8::Local, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(_this, IEntity); - V8_RETURN_BASE_OBJECT(_this->GetNetworkOwner()); + + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); + + V8_RETURN_BASE_OBJECT(ent->GetNetworkOwner()); } static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - Ref ent = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - alt::Position _pos = ent->GetPosition(); - info.GetReturnValue().Set(resource->CreateVector3(_pos)); + V8_RETURN(resource->CreateVector3(ent->GetPosition())); } static void DimensionGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); - Ref ent = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - info.GetReturnValue().Set(v8::Integer::New(isolate, ent->GetDimension())); + V8_RETURN_INTEGER(ent->GetDimension()); } static void RotationGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - alt::Ref ent = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - alt::Rotation _rot = ent->GetRotation(); - info.GetReturnValue().Set(resource->CreateVector3(_rot)); + V8_RETURN(resource->CreateVector3(ent->GetRotation())); } static void ModelGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT(); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - alt::Ref ent = _this->GetHandle().As(); - info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, ent->GetModel())); + V8_RETURN_INTEGER(ent->GetModel()); } static void HasSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT(); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - alt::Ref ent = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); - info.GetReturnValue().Set(v8::Boolean::New(isolate, ent->HasSyncedMetaData(*v8::String::Utf8Value(isolate, key)))); + V8_RETURN_BOOLEAN(ent->HasSyncedMetaData(key)); } static void GetSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); - alt::Ref ent = _this->GetHandle().As(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - alt::MValueConst val = ent->GetSyncedMetaData(*v8::String::Utf8Value(isolate, key)); - info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); + V8_RETURN_MVALUE(ent->GetSyncedMetaData(key)); } static void HasStreamSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT(); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - alt::Ref ent = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); - info.GetReturnValue().Set(v8::Boolean::New(isolate, ent->HasStreamSyncedMetaData(*v8::String::Utf8Value(isolate, key)))); + V8_RETURN_BOOLEAN(ent->HasStreamSyncedMetaData(key)); } static void GetStreamSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); - alt::Ref ent = _this->GetHandle().As(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - alt::MValueConst val = ent->GetStreamSyncedMetaData(*v8::String::Utf8Value(isolate, key)); - info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); + V8_RETURN_MVALUE(ent->GetStreamSyncedMetaData(key)); } #ifdef ALT_SERVER_API static void RotationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(val->IsObject(), "object expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - alt::Ref obj = _this->GetHandle().As(); + V8_GET_ISOLATE_CONTEXT(); - v8::Local pos = val.As(); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - v8::Local x = pos->Get(v8::String::NewFromUtf8(isolate, "x"))->ToNumber(isolate); - v8::Local y = pos->Get(v8::String::NewFromUtf8(isolate, "y"))->ToNumber(isolate); - v8::Local z = pos->Get(v8::String::NewFromUtf8(isolate, "z"))->ToNumber(isolate); + V8_TO_OBJECT(val, pos); + V8_OBJECT_GET_NUMBER(pos, "x", x); + V8_OBJECT_GET_NUMBER(pos, "y", y); + V8_OBJECT_GET_NUMBER(pos, "z", z); - obj->SetRotation({float(x->Value()), float(y->Value()), float(z->Value())}); + ent->SetRotation({ x, y, z }); } static void ModelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8_CHECK(val->IsNumber() || val->IsString(), "model can be number or string"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); - alt::Ref player = _this->GetHandle().As(); - V8_CHECK(player, "model can be set only for player"); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); if (val->IsNumber()) { - player->SetModel(val->ToInteger(isolate)->Value()); + V8_TO_INTEGER(val, model); + player->SetModel(model); } else { - v8::String::Utf8Value strVal{isolate, val}; - player->SetModel(alt::ICore::Instance().Hash(*strVal)); + V8_TO_STRING(val, model); + player->SetModel(alt::ICore::Instance().Hash(model)); } } static void SetSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() == 2, "2 args expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); - alt::Ref ent = _this->GetHandle().As(); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, key); + V8_ARG_TO_MVALUE(2, value); - v8::Local key = info[0]->ToString(isolate); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - ent->SetSyncedMetaData(*v8::String::Utf8Value(isolate, key), V8Helpers::V8ToMValue(info[1])); + ent->SetSyncedMetaData(key, value); } static void DeleteSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT(); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - alt::Ref ent = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - v8::Local key = info[0]->ToString(isolate); - ent->DeleteSyncedMetaData(*v8::String::Utf8Value(isolate, key)); + ent->DeleteSyncedMetaData(key); } static void SetStreamSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() == 2, "2 args expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT(); - alt::Ref ent = _this->GetHandle().As(); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, key); + V8_ARG_TO_MVALUE(2, value); - v8::Local key = info[0]->ToString(isolate); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - ent->SetStreamSyncedMetaData(*v8::String::Utf8Value(isolate, key), V8Helpers::V8ToMValue(info[1])); + ent->SetStreamSyncedMetaData(key, value); } static void DeleteStreamSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT(); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); - alt::Ref ent = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - v8::Local key = info[0]->ToString(isolate); - ent->DeleteStreamSyncedMetaData(*v8::String::Utf8Value(isolate, key)); + ent->DeleteStreamSyncedMetaData(key); } static void SetNetOwner(const v8::FunctionCallbackInfo &info) diff --git a/bindings/File.cpp b/bindings/File.cpp index 5a56e3ac..4c5d4b5f 100644 --- a/bindings/File.cpp +++ b/bindings/File.cpp @@ -5,15 +5,10 @@ static void StaticExists(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - V8_CHECK(info[0]->IsString(), "fileName must be a string"); - - alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); - std::string _path = *v8::String::Utf8Value(isolate, info[0].As()); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, _path); #ifdef ALT_CLIENT auto path = alt::ICore::Instance().Resolve(resource, _path, ""); @@ -23,27 +18,22 @@ static void StaticExists(const v8::FunctionCallbackInfo &info) bool exists = alt::ICore::Instance().FileExists(_path); #endif - info.GetReturnValue().Set(v8::Boolean::New(isolate, exists)); + V8_RETURN_BOOLEAN(exists); } static void StaticRead(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8_CHECK(info.Length() >= 1, "at least 1 arg expected"); - V8_CHECK(info[0]->IsString(), "fileName must be a string"); - - alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); - std::string name = *v8::String::Utf8Value(isolate, info[0].As()); + V8_CHECK_ARGS_LEN_MIN(1); + V8_ARG_TO_STRING(1, name); - std::string encoding = "utf-8"; + alt::String encoding = "utf-8"; if (info.Length() >= 2) { - V8_CHECK(info[1]->IsString(), "encoding must be a string"); - encoding = *v8::String::Utf8Value(isolate, info[1].As()); + V8_ARG_TO_STRING(2, _encoding); + encoding = _encoding; } #ifdef ALT_CLIENT @@ -62,11 +52,11 @@ static void StaticRead(const v8::FunctionCallbackInfo &info) if (encoding == "utf-8") { - info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, data.GetData(), v8::NewStringType::kNormal, data.GetSize()).ToLocalChecked()); + V8_RETURN(v8::String::NewFromUtf8(isolate, data.GetData(), v8::NewStringType::kNormal, data.GetSize()).ToLocalChecked()); } else if (encoding == "utf-16") { - info.GetReturnValue().Set(v8::String::NewFromTwoByte(isolate, (uint16_t *)data.GetData(), v8::NewStringType::kNormal, data.GetSize() / 2).ToLocalChecked()); + V8_RETURN(v8::String::NewFromTwoByte(isolate, (uint16_t *)data.GetData(), v8::NewStringType::kNormal, data.GetSize() / 2).ToLocalChecked()); } else if (encoding == "binary") { @@ -75,7 +65,7 @@ static void StaticRead(const v8::FunctionCallbackInfo &info) std::memcpy(contents.Data(), data.GetData(), data.GetSize()); - info.GetReturnValue().Set(buffer); + V8_RETURN(buffer); } } diff --git a/bindings/Main.cpp b/bindings/Main.cpp index e896ab87..4f723d0d 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -4,60 +4,43 @@ static void HashCb(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 1, "1 arg expected"); - V8_CHECK(info[0]->IsString(), "string expected"); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, str); - v8::String::Utf8Value str(isolate, info[0]); - uint32_t hash = alt::ICore::Instance().Hash(*str); - - info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(info.GetIsolate(), hash)); + V8_RETURN_INTEGER(alt::ICore::Instance().Hash(str)); } static void On(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 2, "on expects 2 args"); - V8_CHECK(info[0]->IsString(), "eventName must be a string"); - V8_CHECK(info[1]->IsFunction(), "callback must be a function"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); - v8::Local callback = info[1].As(); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, callback); - resource->SubscribeLocal(evName, callback, V8::SourceLocation::GetCurrent(isolate)); + resource->SubscribeLocal(evName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate)); } static void Off(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK(info.Length() == 2, "on expects 2 args"); - V8_CHECK(info[0]->IsString(), "eventName must be a string"); - V8_CHECK(info[1]->IsFunction(), "callback must be a function"); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, callback); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); - - std::string evName = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); - v8::Local callback = info[1].As(); - - resource->UnsubscribeLocal(evName, callback); + resource->UnsubscribeLocal(evName.ToString(), callback); } static void Emit(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK(info.Length() >= 1, "emitClient expects at least 1 arg"); - V8_CHECK(info[0]->IsString(), "eventName must be a string"); + V8_CHECK_ARGS_LEN_MIN(1); + V8_ARG_TO_STRING(1, name); - std::string name = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); alt::MValueArgs args; for (int i = 1; i < info.Length(); ++i) @@ -68,80 +51,70 @@ static void Emit(const v8::FunctionCallbackInfo &info) static void HasMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK_ARGS_LEN_MIN(1); + V8_ARG_TO_STRING(1, key); - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); - info.GetReturnValue().Set(v8::Boolean::New(isolate, alt::ICore::Instance().HasMetaData(*v8::String::Utf8Value(isolate, key)))); + V8_RETURN(alt::ICore::Instance().HasMetaData(key)); } static void GetMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_GET_ISOLATE_CONTEXT(); - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + V8_CHECK_ARGS_LEN_MIN(1); + V8_ARG_TO_STRING(1, key); - alt::MValueConst val = alt::ICore::Instance().GetMetaData(*v8::String::Utf8Value(isolate, key)); - info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); + V8_RETURN_MVALUE(alt::ICore::Instance().GetMetaData(key)); } static void SetMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 2, "2 args expected"); + V8_CHECK_ARGS_LEN_MIN(2); + V8_ARG_TO_STRING(1, key); + V8_ARG_TO_MVALUE(2, value); - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); - v8::Local value = info[1]; - - alt::ICore::Instance().SetMetaData(*v8::String::Utf8Value(isolate, key), V8Helpers::V8ToMValue(value)); + alt::ICore::Instance().SetMetaData(key, value); } static void DeleteMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK_ARGS_LEN_MIN(1); + V8_ARG_TO_STRING(1, key); - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); - alt::ICore::Instance().DeleteMetaData(*v8::String::Utf8Value(isolate, key)); + alt::ICore::Instance().DeleteMetaData(key); } static void HasSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK_ARGS_LEN_MIN(1); + V8_ARG_TO_STRING(1, key); - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); - info.GetReturnValue().Set(v8::Boolean::New(isolate, alt::ICore::Instance().HasSyncedMetaData(*v8::String::Utf8Value(isolate, key)))); + V8_RETURN(alt::ICore::Instance().HasSyncedMetaData(key)); } static void GetSyncedMeta(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_GET_ISOLATE_CONTEXT(); - v8::Local key = info[0]->ToString(ctx).ToLocalChecked(); + V8_CHECK_ARGS_LEN_MIN(1); + V8_ARG_TO_STRING(1, key); - alt::MValueConst val = alt::ICore::Instance().GetSyncedMetaData(*v8::String::Utf8Value(isolate, key)); - info.GetReturnValue().Set(V8Helpers::MValueToV8(val)); + V8_RETURN_MVALUE(alt::ICore::Instance().GetSyncedMetaData(key)); } static void Log(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN_MIN(1); std::stringstream ss; @@ -160,8 +133,9 @@ static void Log(const v8::FunctionCallbackInfo &info) static void LogWarning(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN_MIN(1); std::stringstream ss; @@ -180,8 +154,9 @@ static void LogWarning(const v8::FunctionCallbackInfo &info) static void LogError(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN_MIN(1); std::stringstream ss; @@ -200,99 +175,59 @@ static void LogError(const v8::FunctionCallbackInfo &info) static void SetTimeout(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8_CHECK(info.Length() == 2, "2 args expected"); - V8_CHECK(info[0]->IsFunction(), "function expected"); - V8_CHECK(info[1]->IsNumber(), "number expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_CHECK_ARGS_LEN(2); - v8::Local callback = info[0].As(); - v8::Local time = info[1]->ToUint32(ctx).ToLocalChecked(); + V8_ARG_TO_FUNCTION(1, callback); + V8_ARG_TO_INTEGER(2, time); - uint32_t id = resource->CreateTimer(ctx, callback, time->Value(), true, V8::SourceLocation::GetCurrent(isolate)); - - info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, id)); + V8_RETURN_INTEGER(resource->CreateTimer(ctx, callback, time, true, V8::SourceLocation::GetCurrent(isolate))); } static void SetInterval(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8_CHECK(info.Length() == 2, "2 args expected"); - V8_CHECK(info[0]->IsFunction(), "function expected"); - V8_CHECK(info[1]->IsNumber(), "number expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_CHECK_ARGS_LEN(2); - v8::Local callback = info[0].As(); - v8::Local time = info[1]->ToUint32(ctx).ToLocalChecked(); + V8_ARG_TO_FUNCTION(1, callback); + V8_ARG_TO_INTEGER(2, time); - uint32_t id = resource->CreateTimer(ctx, callback, time->Value(), false, V8::SourceLocation::GetCurrent(isolate)); - - info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, id)); + V8_RETURN_INTEGER(resource->CreateTimer(ctx, callback, time, false, V8::SourceLocation::GetCurrent(isolate))); } static void NextTick(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - V8_CHECK(info[0]->IsFunction(), "function expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_CHECK_ARGS_LEN(1); - v8::Local callback = info[0].As(); + V8_ARG_TO_FUNCTION(1, callback); - uint32_t id = resource->CreateTimer(ctx, callback, 0, true, V8::SourceLocation::GetCurrent(isolate)); - - info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, id)); + V8_RETURN_INTEGER(resource->CreateTimer(ctx, callback, 0, true, V8::SourceLocation::GetCurrent(isolate))); } static void EveryTick(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - V8_CHECK(info[0]->IsFunction(), "function expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_CHECK_ARGS_LEN(1); - v8::Local callback = info[0].As(); + V8_ARG_TO_FUNCTION(1, callback); - uint32_t id = resource->CreateTimer(ctx, callback, 0, false, V8::SourceLocation::GetCurrent(isolate)); - - info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, id)); + V8_RETURN_INTEGER(resource->CreateTimer(ctx, callback, 0, false, V8::SourceLocation::GetCurrent(isolate))); } static void ClearTimer(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8_CHECK(info.Length() == 1, "1 arg expected"); - V8_CHECK(info[0]->IsNumber(), "number expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_CHECK_ARGS_LEN(1); - v8::Local time = info[0]->ToUint32(ctx).ToLocalChecked(); + V8_ARG_TO_INTEGER(1, timer); - resource->RemoveTimer(time->Value()); + resource->RemoveTimer(timer); } void V8::RegisterSharedMain(v8::Local ctx, v8::Local exports) @@ -330,8 +265,7 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8::DefineOwnProperty(isolate, ctx, exports, "DefaultDimension", v8::Integer::New(isolate, alt::DEFAULT_DIMENSION)); V8::DefineOwnProperty(isolate, ctx, exports, "GlobalDimension", v8::Integer::New(isolate, alt::GLOBAL_DIMENSION)); -#ifdef ALT_CLIENT V8::DefineOwnProperty(isolate, ctx, exports, "Version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); V8::DefineOwnProperty(isolate, ctx, exports, "Branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); -#endif + V8::DefineOwnProperty(isolate, ctx, exports, "sdkVersion", v8::Integer::New(isolate, alt::ICore::Instance().SDK_VERSION)); } diff --git a/bindings/RGBA.cpp b/bindings/RGBA.cpp index 7281272e..d5ef9bfc 100644 --- a/bindings/RGBA.cpp +++ b/bindings/RGBA.cpp @@ -5,38 +5,38 @@ static void ToString(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - v8::Local r = info.This()->Get(ctx, V8::RGBA_RKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local g = info.This()->Get(ctx, V8::RGBA_GKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local b = info.This()->Get(ctx, V8::RGBA_BKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local a = info.This()->Get(ctx, V8::RGBA_AKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + V8_TO_NUMBER(info.This()->Get(ctx, V8::RGBA_RKey(isolate)).ToLocalChecked(), r); + V8_TO_NUMBER(info.This()->Get(ctx, V8::RGBA_GKey(isolate)).ToLocalChecked(), g); + V8_TO_NUMBER(info.This()->Get(ctx, V8::RGBA_BKey(isolate)).ToLocalChecked(), b); + V8_TO_NUMBER(info.This()->Get(ctx, V8::RGBA_AKey(isolate)).ToLocalChecked(), a); std::ostringstream ss; - ss << "RGBA{ r: " << r->Value() << ", g: " << g->Value() << ", b: " << b->Value() << ", a: " << a->Value() << " }"; + ss << "RGBA{ r: " << r << ", g: " << g << ", b: " << b << ", a: " << a << " }"; - info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, ss.str().c_str(), v8::NewStringType::kNormal).ToLocalChecked()); + V8_RETURN_STRING(ss.str().c_str()); } -extern V8Class v8RGBA( - "RGBA", [](const v8::FunctionCallbackInfo &info) { - v8::Isolate* isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); +static void Constructor(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.Length() == 4, "4 args expected"); + V8_CHECK_ARGS_LEN(4); - v8::Local _this = info.This(); + V8_ARG_TO_INTEGER(1, r); + V8_ARG_TO_INTEGER(2, g); + V8_ARG_TO_INTEGER(3, b); + V8_ARG_TO_INTEGER(4, a); - v8::Local r = info[0]->ToNumber(ctx).ToLocalChecked(); - v8::Local g = info[1]->ToNumber(ctx).ToLocalChecked(); - v8::Local b = info[2]->ToNumber(ctx).ToLocalChecked(); - v8::Local a = info[3]->ToNumber(ctx).ToLocalChecked(); + V8::DefineOwnProperty(isolate, ctx, info.This(), V8::RGBA_RKey(isolate), v8::Integer::New(isolate, r), v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, ctx, info.This(), V8::RGBA_GKey(isolate), v8::Integer::New(isolate, g), v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, ctx, info.This(), V8::RGBA_BKey(isolate), v8::Integer::New(isolate, b), v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, ctx, info.This(), V8::RGBA_AKey(isolate), v8::Integer::New(isolate, a), v8::PropertyAttribute::ReadOnly); +} - V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_RKey(isolate), r, v8::PropertyAttribute::ReadOnly); - V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_GKey(isolate), g, v8::PropertyAttribute::ReadOnly); - V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_BKey(isolate), b, v8::PropertyAttribute::ReadOnly); - V8::DefineOwnProperty(isolate, ctx, _this, V8::RGBA_AKey(isolate), a, v8::PropertyAttribute::ReadOnly); }, [](v8::Local tpl) { +extern V8Class v8RGBA("RGBA", &Constructor, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); - V8::SetMethod(isolate, tpl, "toString", ToString); }); + V8::SetMethod(isolate, tpl, "toString", ToString); +}); diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index 5c333a1c..315e2607 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -84,9 +84,8 @@ static void Constructor(const v8::FunctionCallbackInfo &info) V8::DefineOwnProperty(isolate, ctx, _this, V8::Vector3_ZKey(isolate), z, v8::PropertyAttribute::ReadOnly); } -extern V8Class v8Vector3( - "Vector3", Constructor, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); +extern V8Class v8Vector3("Vector3", Constructor, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); - V8::SetMethod(isolate, tpl, "toString", ToString); - }); + V8::SetMethod(isolate, tpl, "toString", ToString); +}); diff --git a/bindings/WorldObject.cpp b/bindings/WorldObject.cpp index 09b7536c..1ec437c2 100644 --- a/bindings/WorldObject.cpp +++ b/bindings/WorldObject.cpp @@ -8,73 +8,46 @@ using namespace alt; static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_THIS_BASE_OBJECT(obj, alt::IWorldObject); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); - - Ref obj = _this->GetHandle().As(); - - alt::Position _pos = obj->GetPosition(); - info.GetReturnValue().Set(resource->CreateVector3(_pos)); + V8_RETURN(resource->CreateVector3(obj->GetPosition())); } static void PositionSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); - - V8_CHECK(val->IsObject(), "object expected"); - - V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); - V8_CHECK(resource, "invalid resource"); - - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - Ref obj = _this->GetHandle().As(); + V8_GET_THIS_BASE_OBJECT(obj, alt::IWorldObject); - v8::Local pos = val.As(); + V8_TO_OBJECT(val, pos); + V8_OBJECT_GET_NUMBER(pos, "x", x); + V8_OBJECT_GET_NUMBER(pos, "y", y); + V8_OBJECT_GET_NUMBER(pos, "z", z); - v8::Local x = V8::Get(ctx, pos, "x")->ToNumber(ctx).ToLocalChecked(); - v8::Local y = V8::Get(ctx, pos, "y")->ToNumber(ctx).ToLocalChecked(); - v8::Local z = V8::Get(ctx, pos, "z")->ToNumber(ctx).ToLocalChecked(); - - obj->SetPosition({float(x->Value()), float(y->Value()), float(z->Value())}); + obj->SetPosition({ x, y, z }); } #ifdef ALT_SERVER_API static void DimensionGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT(); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_THIS_BASE_OBJECT(obj, alt::IWorldObject); - Ref obj = _this->GetHandle().As(); - - info.GetReturnValue().Set(v8::Integer::New(isolate, obj->GetDimension())); + V8_RETURN_INTEGER(obj->GetDimension()); } static void DimensionSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT(); - V8Entity *_this = V8Entity::Get(info.This()); - V8_CHECK(_this, "entity is invalid"); + V8_GET_THIS_BASE_OBJECT(obj, alt::IWorldObject); - Ref obj = _this->GetHandle().As(); + V8_TO_INTEGER(val, dim); - obj->SetDimension(val->ToInteger(isolate)->Value()); + obj->SetDimension(dim); } #endif // ALT_SERVER_API From 47f336e3b6d0f614760b70fd28a2d86deedbe6cf Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 06:49:17 +0100 Subject: [PATCH 088/564] daily macro madness --- src/bindings/HandlingData.cpp | 1422 +++++++++++++++++---------------- src/helpers | 2 +- 2 files changed, 729 insertions(+), 695 deletions(-) diff --git a/src/bindings/HandlingData.cpp b/src/bindings/HandlingData.cpp index 34408e4f..b3967dfe 100644 --- a/src/bindings/HandlingData.cpp +++ b/src/bindings/HandlingData.cpp @@ -2,16 +2,13 @@ #include "../CV8Resource.h" #include "../helpers/V8Class.h" -static void Constructor(const v8::FunctionCallbackInfo &info) +static void Constructor(const v8::FunctionCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_CONSTRUCTOR(); - V8_CHECK(info.IsConstructCall(), "HandlingData constructor is not a function"); - V8_CHECK(info.Length() == 1, "new HandlingData(...) expects 1 arg"); - - V8_CHECK(info[0]->IsNumber(), "modelHash must be a number"); - uint32_t modelHash = info[0]->Uint32Value(ctx).ToChecked(); + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "model doesn't exist"); @@ -19,348 +16,344 @@ static void Constructor(const v8::FunctionCallbackInfo &info) info.This()->SetInternalField(0, info[0]); } -static void GetForHandlingName(const v8::FunctionCallbackInfo &info) +static void GetForHandlingName(const v8::FunctionCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() == 1, "HandlingData.getForHandlingName expects 1 arg"); - V8_CHECK(info[0]->IsNumber(), "modelHash must be a number"); - uint32_t modelHash = info[0]->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); - extern V8Class v8HandlingData; + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, modelHash); std::vector> args{ - v8::Number::New(isolate, modelHash)}; + v8::Number::New(isolate, modelHash) + }; - info.GetReturnValue().Set(v8HandlingData.New(isolate->GetEnteredContext(), args)); + extern V8Class v8HandlingData; + V8_RETURN(v8HandlingData.New(isolate->GetEnteredContext(), args)); } -static void HandlingNameHashGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void HandlingNameHashGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + uint32_t modelHash2 = info.This()->GetInternalField(0)->IntegerValue(ctx).ToChecked(); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetHandlingNameHash())); + V8_RETURN_NUMBER(handling->GetHandlingNameHash()); } -static void MassGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void MassGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetMass())); + V8_RETURN_NUMBER(handling->GetMass()); } -static void MassSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void MassSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "mass must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetMass((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetMass(fvalue); } -static void InitialDragCoeffGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void InitialDragCoeffGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetInitialDragCoeff())); + V8_RETURN_NUMBER(handling->GetInitialDragCoeff()); } -static void InitialDragCoeffSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void InitialDragCoeffSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "initialDragCoeff must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetInitialDragCoeff((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetInitialDragCoeff(fvalue); } -static void DownforceModifierGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void DownforceModifierGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetDownforceModifier())); + V8_RETURN_NUMBER(handling->GetDownforceModifier()); } -static void DownforceModifierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void DownforceModifierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "downforceModifier must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetDownforceModifier((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetDownforceModifier(fvalue); } -static void unkFloat1Getter(v8::Local, const v8::PropertyCallbackInfo &info) +static void unkFloat1Getter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetunkFloat1())); + V8_RETURN_NUMBER(handling->GetunkFloat1()); } -static void unkFloat1Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void unkFloat1Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "unkFloat1 must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetunkFloat1((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetunkFloat1(fvalue); } -static void unkFloat2Getter(v8::Local, const v8::PropertyCallbackInfo &info) +static void unkFloat2Getter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetunkFloat2())); + V8_RETURN_NUMBER(handling->GetunkFloat2()); } -static void unkFloat2Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void unkFloat2Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "unkFloat2 must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetunkFloat2((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetunkFloat2(fvalue); } -static void CentreOfMassOffsetGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void CentreOfMassOffsetGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(resource->CreateVector3(handling->GetCentreOfMassOffset())); + V8_RETURN(resource->CreateVector3(handling->GetCentreOfMassOffset())); } -static void CentreOfMassOffsetSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void CentreOfMassOffsetSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - V8_CHECK(val->IsObject(), "centreOfMassOffset must be a Vector3"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - v8::Local pos = val.As(); + V8_TO_OBJECT(val, pos); + V8_OBJECT_GET_NUMBER(pos, "x", x); + V8_OBJECT_GET_NUMBER(pos, "y", y); + V8_OBJECT_GET_NUMBER(pos, "z", z); - v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - - handling->SetCentreOfMassOffset({(float)x->Value(), (float)y->Value(), (float)z->Value()}); + handling->SetCentreOfMassOffset({ x, y, z }); } -static void InertiaMultiplierGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void InertiaMultiplierGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(resource->CreateVector3(handling->GetInertiaMultiplier())); + V8_RETURN(resource->CreateVector3(handling->GetInertiaMultiplier())); } -static void InertiaMultiplierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void InertiaMultiplierSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - V8_CHECK(val->IsObject(), "inertiaMultiplier must be a Vector3"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - v8::Local pos = val.As(); + V8_TO_OBJECT(val, pos); + V8_OBJECT_GET_NUMBER(pos, "x", x); + V8_OBJECT_GET_NUMBER(pos, "y", y); + V8_OBJECT_GET_NUMBER(pos, "z", z); - v8::Local x = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local y = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local z = pos->Get(ctx, v8::String::NewFromUtf8(isolate, "z").ToLocalChecked()).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - - handling->SetInertiaMultiplier({(float)x->Value(), (float)y->Value(), (float)z->Value()}); + handling->SetInertiaMultiplier({ x, y, z }); } -static void PercentSubmergedGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void PercentSubmergedGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetPercentSubmerged())); + V8_RETURN_NUMBER(handling->GetPercentSubmerged()); } -static void PercentSubmergedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void PercentSubmergedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "percentSubmerged must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetPercentSubmerged((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetPercentSubmerged(fvalue); } -static void PercentSubmergedRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void PercentSubmergedRatioGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetPercentSubmergedRatio())); + V8_RETURN_NUMBER(handling->GetPercentSubmergedRatio()); } -static void PercentSubmergedRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void PercentSubmergedRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "percentSubmergedRatio must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetPercentSubmergedRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetPercentSubmergedRatio(fvalue); } -static void DriveBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void DriveBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetDriveBiasFront())); + V8_RETURN_NUMBER(handling->GetDriveBiasFront()); } -static void DriveBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void DriveBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "driveBiasFront must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetDriveBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetDriveBiasFront(fvalue); } -static void AccelerationGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void AccelerationGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetAcceleration())); + V8_RETURN_NUMBER(handling->GetAcceleration()); } -static void AccelerationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void AccelerationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "acceleration must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetAcceleration((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetAcceleration(fvalue); } -static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetInitialDriveGears())); + V8_RETURN_NUMBER(handling->GetInitialDriveGears()); } -static void InitialDriveGearsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void InitialDriveGearsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "initialDriveGears must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); @@ -368,1250 +361,1297 @@ static void InitialDriveGearsSetter(v8::Local, v8::Local handling->SetInitialDriveGears(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); } -static void DriveInertiaGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void DriveInertiaGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetDriveInertia())); + V8_RETURN_NUMBER(handling->GetDriveInertia()); } -static void DriveInertiaSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void DriveInertiaSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "driveInertia must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetDriveInertia((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetDriveInertia(fvalue); } -static void ClutchChangeRateScaleUpShiftGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void ClutchChangeRateScaleUpShiftGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetClutchChangeRateScaleUpShift())); + V8_RETURN_NUMBER(handling->GetClutchChangeRateScaleUpShift()); } -static void ClutchChangeRateScaleUpShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void ClutchChangeRateScaleUpShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "clutchChangeRateScaleUpShift must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetClutchChangeRateScaleUpShift((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetClutchChangeRateScaleUpShift(fvalue); } -static void ClutchChangeRateScaleDownShiftGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void ClutchChangeRateScaleDownShiftGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetClutchChangeRateScaleDownShift())); + V8_RETURN_NUMBER(handling->GetClutchChangeRateScaleDownShift()); } -static void ClutchChangeRateScaleDownShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void ClutchChangeRateScaleDownShiftSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "clutchChangeRateScaleDownShift must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetClutchChangeRateScaleDownShift((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetClutchChangeRateScaleDownShift(fvalue); } -static void InitialDriveForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void InitialDriveForceGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetInitialDriveForce())); + V8_RETURN_NUMBER(handling->GetInitialDriveForce()); } -static void InitialDriveForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void InitialDriveForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "initialDriveForce must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetInitialDriveForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetInitialDriveForce(fvalue); } -static void DriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void DriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetDriveMaxFlatVel())); + V8_RETURN_NUMBER(handling->GetDriveMaxFlatVel()); } -static void DriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void DriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "driveMaxFlatVel must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetDriveMaxFlatVel((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetDriveMaxFlatVel(fvalue); } -static void InitialDriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void InitialDriveMaxFlatVelGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetInitialDriveMaxFlatVel())); + V8_RETURN_NUMBER(handling->GetInitialDriveMaxFlatVel()); } -static void InitialDriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void InitialDriveMaxFlatVelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "initialDriveMaxFlatVel must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetInitialDriveMaxFlatVel((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetInitialDriveMaxFlatVel(fvalue); } -static void BrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void BrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetBrakeForce())); + V8_RETURN_NUMBER(handling->GetBrakeForce()); } -static void BrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void BrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "brakeForce must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetBrakeForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetBrakeForce(fvalue); } -static void unkFloat4Getter(v8::Local, const v8::PropertyCallbackInfo &info) +static void unkFloat4Getter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetunkFloat4())); + V8_RETURN_NUMBER(handling->GetunkFloat4()); } -static void unkFloat4Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void unkFloat4Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "unkFloat4 must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetunkFloat4((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetunkFloat4(fvalue); } -static void BrakeBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void BrakeBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetBrakeBiasFront())); + V8_RETURN_NUMBER(handling->GetBrakeBiasFront()); } -static void BrakeBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void BrakeBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "brakeBiasFront must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetBrakeBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetBrakeBiasFront(fvalue); } -static void BrakeBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void BrakeBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetBrakeBiasRear())); + V8_RETURN_NUMBER(handling->GetBrakeBiasRear()); } -static void BrakeBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void BrakeBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "brakeBiasRear must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetBrakeBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetBrakeBiasRear(fvalue); } -static void HandBrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void HandBrakeForceGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetHandBrakeForce())); + V8_RETURN_NUMBER(handling->GetHandBrakeForce()); } -static void HandBrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void HandBrakeForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "handBrakeForce must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetHandBrakeForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetHandBrakeForce(fvalue); } -static void SteeringLockGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SteeringLockGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSteeringLock())); + V8_RETURN_NUMBER(handling->GetSteeringLock()); } -static void SteeringLockSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SteeringLockSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "steeringLock must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSteeringLock((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSteeringLock(fvalue); } -static void SteeringLockRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SteeringLockRatioGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSteeringLockRatio())); + V8_RETURN_NUMBER(handling->GetSteeringLockRatio()); } -static void SteeringLockRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SteeringLockRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "steeringLockRatio must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSteeringLockRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSteeringLockRatio(fvalue); } -static void TractionCurveMaxGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionCurveMaxGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionCurveMax())); + V8_RETURN_NUMBER(handling->GetTractionCurveMax()); } -static void TractionCurveMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionCurveMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionCurveMax must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetTractionCurveMax((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetTractionCurveMax(fvalue); } -static void TractionCurveMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionCurveMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionCurveMaxRatio())); + V8_RETURN_NUMBER(handling->GetTractionCurveMaxRatio()); } -static void TractionCurveMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionCurveMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionCurveMaxRatio must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetTractionCurveMaxRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetTractionCurveMaxRatio(fvalue); } -static void TractionCurveMinGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionCurveMinGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionCurveMin())); + V8_RETURN_NUMBER(handling->GetTractionCurveMin()); } -static void TractionCurveMinSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionCurveMinSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionCurveMin must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetTractionCurveMin((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetTractionCurveMin(fvalue); } -static void TractionCurveMinRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionCurveMinRatioGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionCurveMinRatio())); + V8_RETURN_NUMBER(handling->GetTractionCurveMinRatio()); } -static void TractionCurveMinRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionCurveMinRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionCurveMinRatio must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetTractionCurveMinRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetTractionCurveMinRatio(fvalue); } -static void TractionCurveLateralGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionCurveLateralGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionCurveLateral())); + V8_RETURN_NUMBER(handling->GetTractionCurveLateral()); } -static void TractionCurveLateralSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionCurveLateralSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionCurveLateral must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetTractionCurveLateral((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetTractionCurveLateral(fvalue); } -static void TractionCurveLateralRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionCurveLateralRatioGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionCurveLateralRatio())); + V8_RETURN_NUMBER(handling->GetTractionCurveLateralRatio()); } -static void TractionCurveLateralRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionCurveLateralRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionCurveLateralRatio must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetTractionCurveLateralRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetTractionCurveLateralRatio(fvalue); } -static void TractionSpringDeltaMaxGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionSpringDeltaMaxGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionSpringDeltaMax())); + V8_RETURN_NUMBER(handling->GetTractionSpringDeltaMax()); } -static void TractionSpringDeltaMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionSpringDeltaMaxSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionSpringDeltaMax must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetTractionSpringDeltaMax((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetTractionSpringDeltaMax(fvalue); } -static void TractionSpringDeltaMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionSpringDeltaMaxRatioGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionSpringDeltaMaxRatio())); + V8_RETURN_NUMBER(handling->GetTractionSpringDeltaMaxRatio()); } -static void TractionSpringDeltaMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionSpringDeltaMaxRatioSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionSpringDeltaMaxRatio must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetTractionSpringDeltaMaxRatio((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetTractionSpringDeltaMaxRatio(fvalue); } -static void LowSpeedTractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void LowSpeedTractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetLowSpeedTractionLossMult())); + V8_RETURN_NUMBER(handling->GetLowSpeedTractionLossMult()); } -static void LowSpeedTractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void LowSpeedTractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "lowSpeedTractionLossMult must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetLowSpeedTractionLossMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetLowSpeedTractionLossMult(fvalue); } -static void CamberStiffnesssGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void CamberStiffnesssGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetCamberStiffnesss())); + V8_RETURN_NUMBER(handling->GetCamberStiffnesss()); } -static void CamberStiffnesssSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void CamberStiffnesssSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "camberStiffnesss must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetCamberStiffnesss((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetCamberStiffnesss(fvalue); } -static void TractionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionBiasFront())); + V8_RETURN_NUMBER(handling->GetTractionBiasFront()); } -static void TractionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionBiasFront must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetTractionBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetTractionBiasFront(fvalue); } -static void TractionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionBiasRear())); + V8_RETURN_NUMBER(handling->GetTractionBiasRear()); } -static void TractionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionBiasRear must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetTractionBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetTractionBiasRear(fvalue); } -static void TractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TractionLossMultGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetTractionLossMult())); + V8_RETURN_NUMBER(handling->GetTractionLossMult()); } -static void TractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void TractionLossMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "tractionLossMult must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetTractionLossMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetTractionLossMult(fvalue); } -static void SuspensionForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionForceGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionForce())); + V8_RETURN_NUMBER(handling->GetSuspensionForce()); } -static void SuspensionForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionForce must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSuspensionForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSuspensionForce(fvalue); } -static void SuspensionCompDampGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionCompDampGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionCompDamp())); + V8_RETURN_NUMBER(handling->GetSuspensionCompDamp()); } -static void SuspensionCompDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionCompDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionCompDamp must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSuspensionCompDamp((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSuspensionCompDamp(fvalue); } -static void SuspensionReboundDampGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionReboundDampGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionReboundDamp())); + V8_RETURN_NUMBER(handling->GetSuspensionReboundDamp()); } -static void SuspensionReboundDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionReboundDampSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionReboundDamp must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSuspensionReboundDamp((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSuspensionReboundDamp(fvalue); } -static void SuspensionUpperLimitGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionUpperLimitGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionUpperLimit())); + V8_RETURN_NUMBER(handling->GetSuspensionUpperLimit()); } -static void SuspensionUpperLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionUpperLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionUpperLimit must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSuspensionUpperLimit((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSuspensionUpperLimit(fvalue); } -static void SuspensionLowerLimitGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionLowerLimitGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionLowerLimit())); + V8_RETURN_NUMBER(handling->GetSuspensionLowerLimit()); } -static void SuspensionLowerLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionLowerLimitSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionLowerLimit must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSuspensionLowerLimit((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSuspensionLowerLimit(fvalue); } -static void SuspensionRaiseGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionRaiseGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionRaise())); + V8_RETURN_NUMBER(handling->GetSuspensionRaise()); } -static void SuspensionRaiseSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionRaiseSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionRaise must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSuspensionRaise((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSuspensionRaise(fvalue); } -static void SuspensionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionBiasFront())); + V8_RETURN_NUMBER(handling->GetSuspensionBiasFront()); } -static void SuspensionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionBiasFront must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSuspensionBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSuspensionBiasFront(fvalue); } -static void SuspensionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SuspensionBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSuspensionBiasRear())); + V8_RETURN_NUMBER(handling->GetSuspensionBiasRear()); } -static void SuspensionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SuspensionBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "suspensionBiasRear must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSuspensionBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSuspensionBiasRear(fvalue); } -static void AntiRollBarForceGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void AntiRollBarForceGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetAntiRollBarForce())); + V8_RETURN_NUMBER(handling->GetAntiRollBarForce()); } -static void AntiRollBarForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void AntiRollBarForceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "antiRollBarForce must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetAntiRollBarForce((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetAntiRollBarForce(fvalue); } -static void AntiRollBarBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void AntiRollBarBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetAntiRollBarBiasFront())); + V8_RETURN_NUMBER(handling->GetAntiRollBarBiasFront()); } -static void AntiRollBarBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void AntiRollBarBiasFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "antiRollBarBiasFront must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetAntiRollBarBiasFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetAntiRollBarBiasFront(fvalue); } -static void AntiRollBarBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void AntiRollBarBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetAntiRollBarBiasRear())); + V8_RETURN_NUMBER(handling->GetAntiRollBarBiasRear()); } -static void AntiRollBarBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void AntiRollBarBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "antiRollBarBiasRear must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetAntiRollBarBiasRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetAntiRollBarBiasRear(fvalue); } -static void RollCentreHeightFrontGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void RollCentreHeightFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetRollCentreHeightFront())); + V8_RETURN_NUMBER(handling->GetRollCentreHeightFront()); } -static void RollCentreHeightFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void RollCentreHeightFrontSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "rollCentreHeightFront must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetRollCentreHeightFront((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetRollCentreHeightFront(fvalue); } -static void RollCentreHeightRearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void RollCentreHeightRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetRollCentreHeightRear())); + V8_RETURN_NUMBER(handling->GetRollCentreHeightRear()); } -static void RollCentreHeightRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void RollCentreHeightRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "rollCentreHeightRear must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetRollCentreHeightRear((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetRollCentreHeightRear(fvalue); } -static void CollisionDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void CollisionDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetCollisionDamageMult())); + V8_RETURN_NUMBER(handling->GetCollisionDamageMult()); } -static void CollisionDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void CollisionDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "collisionDamageMult must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetCollisionDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetCollisionDamageMult(fvalue); } -static void WeaponDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void WeaponDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetWeaponDamageMult())); + V8_RETURN_NUMBER(handling->GetWeaponDamageMult()); } -static void WeaponDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void WeaponDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "weaponDamageMult must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetWeaponDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetWeaponDamageMult(fvalue); } -static void DeformationDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void DeformationDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetDeformationDamageMult())); + V8_RETURN_NUMBER(handling->GetDeformationDamageMult()); } -static void DeformationDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void DeformationDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "deformationDamageMult must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetDeformationDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetDeformationDamageMult(fvalue); } -static void EngineDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void EngineDamageMultGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetEngineDamageMult())); + V8_RETURN_NUMBER(handling->GetEngineDamageMult()); } -static void EngineDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void EngineDamageMultSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "engineDamageMult must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetEngineDamageMult((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetEngineDamageMult(fvalue); } -static void PetrolTankVolumeGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void PetrolTankVolumeGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetPetrolTankVolume())); + V8_RETURN_NUMBER(handling->GetPetrolTankVolume()); } -static void PetrolTankVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void PetrolTankVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "petrolTankVolume must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetPetrolTankVolume((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetPetrolTankVolume(fvalue); } -static void OilVolumeGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void OilVolumeGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetOilVolume())); + V8_RETURN_NUMBER(handling->GetOilVolume()); } -static void OilVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void OilVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "oilVolume must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetOilVolume((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetOilVolume(fvalue); } -static void unkFloat5Getter(v8::Local, const v8::PropertyCallbackInfo &info) +static void unkFloat5Getter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetunkFloat5())); + V8_RETURN_NUMBER(handling->GetunkFloat5()); } -static void unkFloat5Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void unkFloat5Setter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "unkFloat5 must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetunkFloat5((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetunkFloat5(fvalue); } -static void SeatOffsetDistXGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SeatOffsetDistXGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSeatOffsetDistX())); + V8_RETURN_NUMBER(handling->GetSeatOffsetDistX()); } -static void SeatOffsetDistXSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SeatOffsetDistXSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "seatOffsetDistX must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSeatOffsetDistX((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSeatOffsetDistX(fvalue); } -static void SeatOffsetDistYGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SeatOffsetDistYGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSeatOffsetDistY())); + V8_RETURN_NUMBER(handling->GetSeatOffsetDistY()); } -static void SeatOffsetDistYSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SeatOffsetDistYSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "seatOffsetDistY must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSeatOffsetDistY((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSeatOffsetDistY(fvalue); } -static void SeatOffsetDistZGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SeatOffsetDistZGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetSeatOffsetDistZ())); + V8_RETURN_NUMBER(handling->GetSeatOffsetDistZ()); } -static void SeatOffsetDistZSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void SeatOffsetDistZSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "seatOffsetDistZ must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetSeatOffsetDistZ((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + V8_TO_NUMBER(val, fvalue); + + handling->SetSeatOffsetDistZ(fvalue); } -static void MonetaryValueGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void MonetaryValueGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetMonetaryValue())); + V8_RETURN_NUMBER(handling->GetMonetaryValue()); } -static void MonetaryValueSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void MonetaryValueSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "monetaryValue must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); @@ -1619,24 +1659,23 @@ static void MonetaryValueSetter(v8::Local, v8::Local val, handling->SetMonetaryValue(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); } -static void ModelFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void ModelFlagsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetModelFlags())); + V8_RETURN_NUMBER(handling->GetModelFlags()); } -static void ModelFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void ModelFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "modelFlags must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); @@ -1644,24 +1683,23 @@ static void ModelFlagsSetter(v8::Local, v8::Local val, co handling->SetModelFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); } -static void HandlingFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void HandlingFlagsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetHandlingFlags())); + V8_RETURN_NUMBER(handling->GetHandlingFlags()); } -static void HandlingFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void HandlingFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "handlingFlags must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); @@ -1669,24 +1707,23 @@ static void HandlingFlagsSetter(v8::Local, v8::Local val, handling->SetHandlingFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); } -static void DamageFlagsGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void DamageFlagsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, handling->GetDamageFlags())); + V8_RETURN_NUMBER(handling->GetDamageFlags()); } -static void DamageFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +static void DamageFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "damageFlags must be a number"); + V8_GET_ISOLATE_CONTEXT(); - uint32_t modelHash = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); @@ -1694,80 +1731,77 @@ static void DamageFlagsSetter(v8::Local, v8::Local val, c handling->SetDamageFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); } -extern V8Class v8HandlingData( - "HandlingData", Constructor, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - v8::Local proto = tpl->PrototypeTemplate(); +extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::Local tpl) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->Set(isolate, "getForHandlingName", v8::FunctionTemplate::New(isolate, &GetForHandlingName)); - - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingNameHash").ToLocalChecked(), &HandlingNameHashGetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "mass").ToLocalChecked(), &MassGetter, &MassSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDragCoeff").ToLocalChecked(), &InitialDragCoeffGetter, &InitialDragCoeffSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "downforceModifier").ToLocalChecked(), &DownforceModifierGetter, &DownforceModifierSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat1").ToLocalChecked(), &unkFloat1Getter, &unkFloat1Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat2").ToLocalChecked(), &unkFloat2Getter, &unkFloat2Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "centreOfMassOffset").ToLocalChecked(), &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "inertiaMultiplier").ToLocalChecked(), &InertiaMultiplierGetter, &InertiaMultiplierSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmerged").ToLocalChecked(), &PercentSubmergedGetter, &PercentSubmergedSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "percentSubmergedRatio").ToLocalChecked(), &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveBiasFront").ToLocalChecked(), &DriveBiasFrontGetter, &DriveBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "acceleration").ToLocalChecked(), &AccelerationGetter, &AccelerationSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveGears").ToLocalChecked(), &InitialDriveGearsGetter, &InitialDriveGearsSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveInertia").ToLocalChecked(), &DriveInertiaGetter, &DriveInertiaSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleUpShift").ToLocalChecked(), &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "clutchChangeRateScaleDownShift").ToLocalChecked(), &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveForce").ToLocalChecked(), &InitialDriveForceGetter, &InitialDriveForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "driveMaxFlatVel").ToLocalChecked(), &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "initialDriveMaxFlatVel").ToLocalChecked(), &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeForce").ToLocalChecked(), &BrakeForceGetter, &BrakeForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat4").ToLocalChecked(), &unkFloat4Getter, &unkFloat4Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasFront").ToLocalChecked(), &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "brakeBiasRear").ToLocalChecked(), &BrakeBiasRearGetter, &BrakeBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handBrakeForce").ToLocalChecked(), &HandBrakeForceGetter, &HandBrakeForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLock").ToLocalChecked(), &SteeringLockGetter, &SteeringLockSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "steeringLockRatio").ToLocalChecked(), &SteeringLockRatioGetter, &SteeringLockRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMax").ToLocalChecked(), &TractionCurveMaxGetter, &TractionCurveMaxSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMaxRatio").ToLocalChecked(), &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMin").ToLocalChecked(), &TractionCurveMinGetter, &TractionCurveMinSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveMinRatio").ToLocalChecked(), &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateral").ToLocalChecked(), &TractionCurveLateralGetter, &TractionCurveLateralSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionCurveLateralRatio").ToLocalChecked(), &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMax").ToLocalChecked(), &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionSpringDeltaMaxRatio").ToLocalChecked(), &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lowSpeedTractionLossMult").ToLocalChecked(), &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "camberStiffnesss").ToLocalChecked(), &CamberStiffnesssGetter, &CamberStiffnesssSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasFront").ToLocalChecked(), &TractionBiasFrontGetter, &TractionBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionBiasRear").ToLocalChecked(), &TractionBiasRearGetter, &TractionBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "tractionLossMult").ToLocalChecked(), &TractionLossMultGetter, &TractionLossMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionForce").ToLocalChecked(), &SuspensionForceGetter, &SuspensionForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionCompDamp").ToLocalChecked(), &SuspensionCompDampGetter, &SuspensionCompDampSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionReboundDamp").ToLocalChecked(), &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionUpperLimit").ToLocalChecked(), &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionLowerLimit").ToLocalChecked(), &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionRaise").ToLocalChecked(), &SuspensionRaiseGetter, &SuspensionRaiseSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasFront").ToLocalChecked(), &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "suspensionBiasRear").ToLocalChecked(), &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarForce").ToLocalChecked(), &AntiRollBarForceGetter, &AntiRollBarForceSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasFront").ToLocalChecked(), &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "antiRollBarBiasRear").ToLocalChecked(), &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightFront").ToLocalChecked(), &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "rollCentreHeightRear").ToLocalChecked(), &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "collisionDamageMult").ToLocalChecked(), &CollisionDamageMultGetter, &CollisionDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "weaponDamageMult").ToLocalChecked(), &WeaponDamageMultGetter, &WeaponDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "deformationDamageMult").ToLocalChecked(), &DeformationDamageMultGetter, &DeformationDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "engineDamageMult").ToLocalChecked(), &EngineDamageMultGetter, &EngineDamageMultSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "petrolTankVolume").ToLocalChecked(), &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "oilVolume").ToLocalChecked(), &OilVolumeGetter, &OilVolumeSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "unkFloat5").ToLocalChecked(), &unkFloat5Getter, &unkFloat5Setter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistX").ToLocalChecked(), &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistY").ToLocalChecked(), &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "seatOffsetDistZ").ToLocalChecked(), &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "monetaryValue").ToLocalChecked(), &MonetaryValueGetter, &MonetaryValueSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "modelFlags").ToLocalChecked(), &ModelFlagsGetter, &ModelFlagsSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "handlingFlags").ToLocalChecked(), &HandlingFlagsGetter, &HandlingFlagsSetter); - proto->SetAccessor(v8::String::NewFromUtf8(isolate, "damageFlags").ToLocalChecked(), &DamageFlagsGetter, &DamageFlagsSetter); + V8::SetMethod(isolate, tpl, "getForHandlingName", &GetForHandlingName); + + V8::SetAccessor(isolate, tpl, "handlingNameHash", &HandlingNameHashGetter); + V8::SetAccessor(isolate, tpl, "mass", &MassGetter, &MassSetter); + V8::SetAccessor(isolate, tpl, "initialDragCoeff", &InitialDragCoeffGetter, &InitialDragCoeffSetter); + V8::SetAccessor(isolate, tpl, "downforceModifier", &DownforceModifierGetter, &DownforceModifierSetter); + V8::SetAccessor(isolate, tpl, "unkFloat1", &unkFloat1Getter, &unkFloat1Setter); + V8::SetAccessor(isolate, tpl, "unkFloat2", &unkFloat2Getter, &unkFloat2Setter); + V8::SetAccessor(isolate, tpl, "centreOfMassOffset", &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); + V8::SetAccessor(isolate, tpl, "inertiaMultiplier", &InertiaMultiplierGetter, &InertiaMultiplierSetter); + V8::SetAccessor(isolate, tpl, "percentSubmerged", &PercentSubmergedGetter, &PercentSubmergedSetter); + V8::SetAccessor(isolate, tpl, "percentSubmergedRatio", &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); + V8::SetAccessor(isolate, tpl, "driveBiasFront", &DriveBiasFrontGetter, &DriveBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "acceleration", &AccelerationGetter, &AccelerationSetter); + V8::SetAccessor(isolate, tpl, "initialDriveGears", &InitialDriveGearsGetter, &InitialDriveGearsSetter); + V8::SetAccessor(isolate, tpl, "driveInertia", &DriveInertiaGetter, &DriveInertiaSetter); + V8::SetAccessor(isolate, tpl, "clutchChangeRateScaleUpShift", &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); + V8::SetAccessor(isolate, tpl, "clutchChangeRateScaleDownShift", &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); + V8::SetAccessor(isolate, tpl, "initialDriveForce", &InitialDriveForceGetter, &InitialDriveForceSetter); + V8::SetAccessor(isolate, tpl, "driveMaxFlatVel", &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); + V8::SetAccessor(isolate, tpl, "initialDriveMaxFlatVel", &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); + V8::SetAccessor(isolate, tpl, "brakeForce", &BrakeForceGetter, &BrakeForceSetter); + V8::SetAccessor(isolate, tpl, "unkFloat4", &unkFloat4Getter, &unkFloat4Setter); + V8::SetAccessor(isolate, tpl, "brakeBiasFront", &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "brakeBiasRear", &BrakeBiasRearGetter, &BrakeBiasRearSetter); + V8::SetAccessor(isolate, tpl, "handBrakeForce", &HandBrakeForceGetter, &HandBrakeForceSetter); + V8::SetAccessor(isolate, tpl, "steeringLock", &SteeringLockGetter, &SteeringLockSetter); + V8::SetAccessor(isolate, tpl, "steeringLockRatio", &SteeringLockRatioGetter, &SteeringLockRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMax", &TractionCurveMaxGetter, &TractionCurveMaxSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMaxRatio", &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMin", &TractionCurveMinGetter, &TractionCurveMinSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMinRatio", &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveLateral", &TractionCurveLateralGetter, &TractionCurveLateralSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveLateralRatio", &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionSpringDeltaMax", &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); + V8::SetAccessor(isolate, tpl, "tractionSpringDeltaMaxRatio", &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); + V8::SetAccessor(isolate, tpl, "lowSpeedTractionLossMult", &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); + V8::SetAccessor(isolate, tpl, "camberStiffnesss", &CamberStiffnesssGetter, &CamberStiffnesssSetter); + V8::SetAccessor(isolate, tpl, "tractionBiasFront", &TractionBiasFrontGetter, &TractionBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "tractionBiasRear", &TractionBiasRearGetter, &TractionBiasRearSetter); + V8::SetAccessor(isolate, tpl, "tractionLossMult", &TractionLossMultGetter, &TractionLossMultSetter); + V8::SetAccessor(isolate, tpl, "suspensionForce", &SuspensionForceGetter, &SuspensionForceSetter); + V8::SetAccessor(isolate, tpl, "suspensionCompDamp", &SuspensionCompDampGetter, &SuspensionCompDampSetter); + V8::SetAccessor(isolate, tpl, "suspensionReboundDamp", &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); + V8::SetAccessor(isolate, tpl, "suspensionUpperLimit", &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); + V8::SetAccessor(isolate, tpl, "suspensionLowerLimit", &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); + V8::SetAccessor(isolate, tpl, "suspensionRaise", &SuspensionRaiseGetter, &SuspensionRaiseSetter); + V8::SetAccessor(isolate, tpl, "suspensionBiasFront", &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "suspensionBiasRear", &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarForce", &AntiRollBarForceGetter, &AntiRollBarForceSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarBiasFront", &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarBiasRear", &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); + V8::SetAccessor(isolate, tpl, "rollCentreHeightFront", &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); + V8::SetAccessor(isolate, tpl, "rollCentreHeightRear", &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); + V8::SetAccessor(isolate, tpl, "collisionDamageMult", &CollisionDamageMultGetter, &CollisionDamageMultSetter); + V8::SetAccessor(isolate, tpl, "weaponDamageMult", &WeaponDamageMultGetter, &WeaponDamageMultSetter); + V8::SetAccessor(isolate, tpl, "deformationDamageMult", &DeformationDamageMultGetter, &DeformationDamageMultSetter); + V8::SetAccessor(isolate, tpl, "engineDamageMult", &EngineDamageMultGetter, &EngineDamageMultSetter); + V8::SetAccessor(isolate, tpl, "petrolTankVolume", &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); + V8::SetAccessor(isolate, tpl, "oilVolume", &OilVolumeGetter, &OilVolumeSetter); + V8::SetAccessor(isolate, tpl, "unkFloat5", &unkFloat5Getter, &unkFloat5Setter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistX", &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistY", &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistZ", &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); + V8::SetAccessor(isolate, tpl, "monetaryValue", &MonetaryValueGetter, &MonetaryValueSetter); + V8::SetAccessor(isolate, tpl, "modelFlags", &ModelFlagsGetter, &ModelFlagsSetter); + V8::SetAccessor(isolate, tpl, "handlingFlags", &HandlingFlagsGetter, &HandlingFlagsSetter); + V8::SetAccessor(isolate, tpl, "damageFlags", &DamageFlagsGetter, &DamageFlagsSetter); }); diff --git a/src/helpers b/src/helpers index df8b3e0d..30b83032 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit df8b3e0de536960a83abfa83a6db1c3188ebbce3 +Subproject commit 30b83032804337febc641bfca82240ee0f1f4970 From 5957cb8ca0cee3a63de16bde7935f13809c1f545 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 07:30:47 +0100 Subject: [PATCH 089/564] change blip routeColor to static --- src/bindings/Blip.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index 4c7e9eba..ac5d74cc 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -581,6 +581,8 @@ extern V8Class v8WorldObject; extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local tpl){ v8::Isolate* isolate = v8::Isolate::GetCurrent(); + V8::SetStaticAccessor(isolate, tpl, "routeColor", &RouteColorGetter, &RouteColorSetter); + V8::SetAccessor(isolate, tpl, "sprite", &SpriteGetter, &SpriteSetter); V8::SetAccessor(isolate, tpl, "size", &SizeGetter, &SizeSetter); V8::SetAccessor(isolate, tpl, "color", &ColorGetter, &ColorSetter); @@ -600,7 +602,6 @@ extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local Date: Wed, 18 Nov 2020 07:39:21 +0100 Subject: [PATCH 090/564] add vector3 functions --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 30b83032..83883bf7 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 30b83032804337febc641bfca82240ee0f1f4970 +Subproject commit 83883bf797eac97870358543d1db48ef9f5ad1e7 From 2fc2d8bb485f001d6d8ac2f0bf92814280814737 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 10:13:22 +0100 Subject: [PATCH 091/564] fix merge --- V8Helpers.cpp | 12 ------------ V8Helpers.h | 13 ------------- 2 files changed, 25 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 304459fe..2465fbe1 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -529,26 +529,17 @@ bool V8::SafeToString(v8::Local val, v8::Isolate *isolate, v8::Local< return false; } -<<<<<<< HEAD bool V8::SafeToFunction(v8::Local val, v8::Local ctx, v8::Local& out) { if (val->IsFunction()) { out = val.As(); -======= -bool V8::SafeToObject(v8::Local val, v8::Local& out) -{ - if (val->IsObject()) - { - out = val.As(); ->>>>>>> 4d64883c72f1fe81617fc83e1a821a788dc666a0 return true; } return false; } -<<<<<<< HEAD bool V8::SafeToObject(v8::Local val, v8::Local ctx, v8::Local& out) { v8::MaybeLocal maybeVal = val->ToObject(ctx); @@ -562,9 +553,6 @@ bool V8::SafeToObject(v8::Local val, v8::Local ctx, v8:: } std::vector V8::EventHandler::GetCallbacks(V8ResourceImpl *impl, const alt::CEvent *e) -======= -std::vector V8::EventHandler::GetCallbacks(V8ResourceImpl* impl, const alt::CEvent* e) ->>>>>>> 4d64883c72f1fe81617fc83e1a821a788dc666a0 { return callbacksGetter(impl, e); } diff --git a/V8Helpers.h b/V8Helpers.h index 95acd7ba..8e22d95f 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -201,20 +201,12 @@ namespace V8 v8::Local Fire_PosKey(v8::Isolate *isolate); v8::Local Fire_WeaponKey(v8::Isolate *isolate); -<<<<<<< HEAD bool SafeToBoolean(v8::Local val, v8::Isolate *isolate, bool &out); bool SafeToInteger(v8::Local val, v8::Local ctx, int64_t &out); bool SafeToNumber(v8::Local val, v8::Local ctx, double &out); bool SafeToString(v8::Local val, v8::Isolate *isolate, v8::Local ctx, alt::String &out); bool SafeToFunction(v8::Local val, v8::Local ctx, v8::Local& out); bool SafeToObject(v8::Local val, v8::Local ctx, v8::Local& out); -======= - bool SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool& out); - bool SafeToInteger(v8::Local val, v8::Local ctx, int64_t& out); - bool SafeToNumber(v8::Local val, v8::Local ctx, double& out); - bool SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String& out); - bool SafeToObject(v8::Local val, v8::Local& out); ->>>>>>> 4d64883c72f1fe81617fc83e1a821a788dc666a0 template bool SafeToBaseObject(v8::Local val, v8::Isolate *isolate, alt::Ref &out) @@ -389,11 +381,6 @@ namespace V8 v8::Local val; \ V8_CHECK(V8::SafeToObject(info[(idx) - 1], ctx, val), "Failed to convert argument " #idx " to object") -// idx starts with 1 -#define V8_ARG_TO_OBJECT(idx, val) \ - v8::Local val; \ - V8_CHECK(V8::SafeToObject(info[(idx) - 1], val), "Failed to convert argument " #idx " to object") - // idx starts with 1 #define V8_ARG_TO_BASE_OBJECT(idx, val, type, jsClassName) \ alt::Ref val; \ From 7dbedf060131d02cfb9a12476abcfd721c1261d1 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 10:13:38 +0100 Subject: [PATCH 092/564] fix vector3 merge --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 83883bf7..2fc2d8bb 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 83883bf797eac97870358543d1db48ef9f5ad1e7 +Subproject commit 2fc2d8bb485f001d6d8ac2f0bf92814280814737 From 8dbdb3451f0ef1f1a69320c70994c17e8d387d80 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 10:40:49 +0100 Subject: [PATCH 093/564] add proper int types --- V8Helpers.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- V8Helpers.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 2465fbe1..32205fdb 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -493,7 +493,7 @@ bool V8::SafeToBoolean(v8::Local val, v8::Isolate *isolate, bool &out return true; } -bool V8::SafeToInteger(v8::Local val, v8::Local ctx, int64_t &out) +bool V8::SafeToInteger(v8::Local val, v8::Local ctx, int64_t& out) { v8::MaybeLocal maybeVal = val->ToInteger(ctx); if (!maybeVal.IsEmpty()) @@ -505,6 +505,54 @@ bool V8::SafeToInteger(v8::Local val, v8::Local ctx, int return false; } +bool V8::SafeToUInt64(v8::Local val, v8::Local ctx, uint64_t& out) +{ + v8::MaybeLocal maybeVal = val->ToBigInt(ctx); + if (!maybeVal.IsEmpty()) + { + out = maybeVal.ToLocalChecked()->Uint64Value(); + return true; + } + + return false; +} + +bool V8::SafeToInt64(v8::Local val, v8::Local ctx, int64_t& out) +{ + v8::MaybeLocal maybeVal = val->ToBigInt(ctx); + if (!maybeVal.IsEmpty()) + { + out = maybeVal.ToLocalChecked()->Int64Value(); + return true; + } + + return false; +} + +bool V8::SafeToUInt32(v8::Local val, v8::Local ctx, uint32_t& out) +{ + v8::MaybeLocal maybeVal = val->ToUint32(ctx); + if (!maybeVal.IsEmpty()) + { + out = maybeVal.ToLocalChecked()->Value(); + return true; + } + + return false; +} + +bool V8::SafeToInt32(v8::Local val, v8::Local ctx, int32_t& out) +{ + v8::MaybeLocal maybeVal = val->ToInt32(ctx); + if (!maybeVal.IsEmpty()) + { + out = maybeVal.ToLocalChecked()->Value(); + return true; + } + + return false; +} + bool V8::SafeToNumber(v8::Local val, v8::Local ctx, double &out) { v8::MaybeLocal maybeVal = val->ToNumber(ctx); diff --git a/V8Helpers.h b/V8Helpers.h index 8e22d95f..86e07e4e 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -208,6 +208,11 @@ namespace V8 bool SafeToFunction(v8::Local val, v8::Local ctx, v8::Local& out); bool SafeToObject(v8::Local val, v8::Local ctx, v8::Local& out); + bool SafeToUInt64(v8::Local val, v8::Local ctx, uint64_t& out); + bool SafeToInt64(v8::Local val, v8::Local ctx, int64_t& out); + bool SafeToUInt32(v8::Local val, v8::Local ctx, uint32_t& out); + bool SafeToInt32(v8::Local val, v8::Local ctx, int32_t& out); + template bool SafeToBaseObject(v8::Local val, v8::Isolate *isolate, alt::Ref &out) { @@ -386,6 +391,27 @@ namespace V8 alt::Ref val; \ V8_CHECK(V8::SafeToBaseObject(info[(idx)-1], isolate, val), "Argument " #idx " must be a " jsClassName) + +// idx starts with 1 +#define V8_ARG_TO_UINT64(idx, val) \ + uint64_t val; \ + V8_CHECK(V8::SafeToUInt64(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to integer") + +// idx starts with 1 +#define V8_ARG_TO_INT64(idx, val) \ + int64_t val; \ + V8_CHECK(V8::SafeToInt64(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to integer") + +// idx starts with 1 +#define V8_ARG_TO_UINT32(idx, val) \ + uint32_t val; \ + V8_CHECK(V8::SafeToUInt32(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to integer") + +// idx starts with 1 +#define V8_ARG_TO_INT32(idx, val) \ + int32_t val; \ + V8_CHECK(V8::SafeToInt32(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to integer") + #define V8_RETURN(val) info.GetReturnValue().Set(val) #define V8_RETURN_NULL() V8_RETURN(v8::Null(isolate)) #define V8_RETURN_BOOLEAN(val) V8_RETURN(v8::Boolean::New(isolate, (val))) @@ -394,6 +420,11 @@ namespace V8 #define V8_RETURN_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val), v8::NewStringType::kNormal).ToLocalChecked()) #define V8_RETURN_MVALUE(val) V8_RETURN(V8Helpers::MValueToV8(val)) +#define V8_RETURN_UINT64(val) V8_RETURN(v8::BigInt::NewFromUnsigned(isolate, (val))) +#define V8_RETURN_INT64(val) V8_RETURN(v8::BigInt::New(isolate, (val))) +#define V8_RETURN_UINT32(val) V8_RETURN(v8::Integer::NewFromUnsigned(isolate, (val))) +#define V8_RETURN_INT32(val) V8_RETURN(v8::Integer::New(isolate, (val))) + #define V8_RETURN_BASE_OBJECT(baseObjectRef) V8_RETURN(resource->GetBaseObjectOrNull(baseObjectRef)) #define V8_BIND_BASE_OBJECT(baseObjectRef, msg) \ From 8a628ea9cbb5997b547abe76638892f9cc754a1d Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 10:42:15 +0100 Subject: [PATCH 094/564] use proper types at char stats --- src/bindings/Main.cpp | 26 +++++++++++++------------- src/helpers | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 5d42cc77..3865bdcb 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -324,14 +324,14 @@ static void SetCharStat(const v8::FunctionCallbackInfo &info) } else if (!strcmp(targetStat->GetStatType(), "INT64")) { - V8_ARG_TO_INTEGER(2, value); + V8_ARG_TO_INT64(2, value); targetStat->SetInt64Value(value); V8_RETURN_BOOLEAN(true); return; } else if (!strcmp(targetStat->GetStatType(), "TEXTLABEL")) { - V8_ARG_TO_INTEGER(2, value); + V8_ARG_TO_INT32(2, value); targetStat->SetInt32Value(value); V8_RETURN_BOOLEAN(true); return; @@ -359,21 +359,21 @@ static void SetCharStat(const v8::FunctionCallbackInfo &info) } else if (!strcmp(targetStat->GetStatType(), "UINT8")) { - V8_ARG_TO_INTEGER(2, value); + V8_ARG_TO_UINT32(2, value); targetStat->SetUInt8Value(value); V8_RETURN_BOOLEAN(true); return; } else if (!strcmp(targetStat->GetStatType(), "UINT16")) { - V8_ARG_TO_INTEGER(2, value); + V8_ARG_TO_UINT32(2, value); targetStat->SetUInt16Value(value); V8_RETURN_BOOLEAN(true); return; } else if (!strcmp(targetStat->GetStatType(), "UINT32")) { - V8_ARG_TO_INTEGER(2, value); + V8_ARG_TO_UINT32(2, value); targetStat->SetUInt32Value(value); V8_RETURN_BOOLEAN(true); return; @@ -385,7 +385,7 @@ static void SetCharStat(const v8::FunctionCallbackInfo &info) !strcmp(targetStat->GetStatType(), "PACKED") || !strcmp(targetStat->GetStatType(), "USERID")) { - V8_ARG_TO_INTEGER(2, value); + V8_ARG_TO_UINT64(2, value); targetStat->SetUInt64Value(value); V8_RETURN_BOOLEAN(true); return; @@ -408,17 +408,17 @@ static void GetCharStat(const v8::FunctionCallbackInfo &info) if (!strcmp(targetStat->GetStatType(), "INT")) { - V8_RETURN_INTEGER(targetStat->GetInt32Value()); + V8_RETURN_INT32(targetStat->GetInt32Value()); return; } else if (!strcmp(targetStat->GetStatType(), "INT64")) { - V8_RETURN_INTEGER(targetStat->GetInt64Value()); + V8_RETURN_INT64(targetStat->GetInt64Value()); return; } else if (!strcmp(targetStat->GetStatType(), "TEXTLABEL")) { - V8_RETURN_INTEGER(targetStat->GetInt32Value()); + V8_RETURN_INT32(targetStat->GetInt32Value()); return; } else if (!strcmp(targetStat->GetStatType(), "FLOAT")) @@ -438,17 +438,17 @@ static void GetCharStat(const v8::FunctionCallbackInfo &info) } else if (!strcmp(targetStat->GetStatType(), "UINT8")) { - V8_RETURN_INTEGER(targetStat->GetUInt8Value()); + V8_RETURN_UINT32(targetStat->GetUInt8Value()); return; } else if (!strcmp(targetStat->GetStatType(), "UINT16")) { - V8_RETURN_INTEGER(targetStat->GetUInt16Value()); + V8_RETURN_UINT32(targetStat->GetUInt16Value()); return; } else if (!strcmp(targetStat->GetStatType(), "UINT32")) { - V8_RETURN_INTEGER(targetStat->GetUInt32Value()); + V8_RETURN_UINT32(targetStat->GetUInt32Value()); return; } else if ( @@ -458,7 +458,7 @@ static void GetCharStat(const v8::FunctionCallbackInfo &info) !strcmp(targetStat->GetStatType(), "PACKED") || !strcmp(targetStat->GetStatType(), "USERID")) { - V8_RETURN_INTEGER(targetStat->GetUInt64Value()); + V8_RETURN_UINT64(targetStat->GetUInt64Value()); return; } diff --git a/src/helpers b/src/helpers index 2fc2d8bb..8dbdb345 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 2fc2d8bb485f001d6d8ac2f0bf92814280814737 +Subproject commit 8dbdb3451f0ef1f1a69320c70994c17e8d387d80 From ee9038e05e6a5149a475e2a5632568d49f5d5ebe Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 18 Nov 2020 13:38:32 +0100 Subject: [PATCH 095/564] Fix merge conflict --- src/bindings/HandlingData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/HandlingData.cpp b/src/bindings/HandlingData.cpp index 415aaf11..fb8e8f41 100644 --- a/src/bindings/HandlingData.cpp +++ b/src/bindings/HandlingData.cpp @@ -1702,7 +1702,7 @@ extern V8Class v8HandlingData( tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->Set(isolate, "getForHandlingName", v8::FunctionTemplate::New(isolate, &GetForHandlingName)); + V8::SetMethod(isolate, tpl, "getForHandlingName", &GetForHandlingName); V8::SetAccessor(isolate, tpl, "handlingNameHash", &HandlingNameHashGetter); V8::SetAccessor(isolate, tpl, "mass", &MassGetter, &MassSetter); From 43d68e8d6eb13c812b9a02c3e58b335dba5ca1a1 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 18 Nov 2020 13:59:32 +0100 Subject: [PATCH 096/564] Fix merge --- src/bindings/Player.cpp | 232 +++++++++++++++-- src/bindings/Vehicle.cpp | 532 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 729 insertions(+), 35 deletions(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 23fedc4b..6d571983 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -7,15 +7,17 @@ #include "cpp-sdk/objects/IPlayer.h" #include "cpp-sdk/objects/IVehicle.h" -static void NameGetter(v8::Local, const v8::PropertyCallbackInfo &info) +using namespace alt; + +static void NameGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, player->GetName().CStr()).ToLocalChecked()); + V8_RETURN_STRING(player->GetName().CStr()); } -static void VehicleGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void VehicleGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); @@ -23,7 +25,7 @@ static void VehicleGetter(v8::Local, const v8::PropertyCallbackInfo< V8_RETURN_BASE_OBJECT(player->GetVehicle()); } -static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); @@ -31,19 +33,186 @@ static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo< V8_RETURN_BOOLEAN(player->IsTalking()); } -static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_RETURN_INTEGER(player->GetMicLevel()); + V8_RETURN_NUMBER(player->GetMicLevel()); } -static void WeaponHasComponent(const v8::FunctionCallbackInfo &info) +static void CurrentWeaponComponentsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - + + alt::Array comps = player->GetCurrentWeaponComponents(); + + v8::Local componentsArray = v8::Array::New(isolate, comps.GetSize()); + + for (uint32_t i = 0; i < comps.GetSize(); ++i) + componentsArray->Set(ctx, i, v8::Integer::NewFromUnsigned(isolate, comps[i])); + + V8_RETURN(componentsArray); +} + +static void CurrentWeaponTintIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_INTEGER(player->GetCurrentWeaponTintIndex()); +} + +static void CurrentWeaponGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_INTEGER(player->GetCurrentWeapon()); +} + +static void IsJumpingGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BOOLEAN(player->IsJumping()); +} + +static void IsInRagdollGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BOOLEAN(player->IsInRagdoll()); +} + +static void IsAimingGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BOOLEAN(player->IsAiming()); +} + +static void IsShootingGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BOOLEAN(player->IsShooting()); +} + +static void IsReloadingGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BOOLEAN(player->IsReloading()); +} + +static void ArmourGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_INTEGER(player->GetArmour()); +} + +static void MaxArmourGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_INTEGER(player->GetMaxArmour()); +} + +static void MoveSpeedGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_NUMBER(player->GetMoveSpeed()); +} + +static void AimPosGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN(resource->CreateVector3(player->GetAimPos())); +} + +static void HeadRotationGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN(resource->CreateVector3(player->GetHeadRotation())); +} + +static void SeatGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_INTEGER(player->GetSeat()); +} + +static void EntityAimingAtGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BASE_OBJECT(player->GetEntityAimingAt()); +} + +static void EntityAimOffsetGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN(resource->CreateVector3(player->GetEntityAimOffset())); +} + +static void FlashlightActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BOOLEAN(player->IsFlashlightActive()); +} + +static void HealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_INTEGER(player->GetHealth()); +} + +static void MaxHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_INTEGER(player->GetMaxHealth()); +} + +static void IsDeadGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BOOLEAN(player->IsDead()); +} + +static void WeaponHasComponent(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + V8_CHECK_ARGS_LEN(2); V8_ARG_TO_INTEGER(1, weaponHash); V8_ARG_TO_INTEGER(2, componentHash); @@ -51,7 +220,7 @@ static void WeaponHasComponent(const v8::FunctionCallbackInfo &info) V8_RETURN_BOOLEAN(player->HasWeaponComponent(weaponHash, componentHash)); } -static void GetWeaponTintIndex(const v8::FunctionCallbackInfo &info) +static void GetWeaponTintIndex(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); @@ -62,7 +231,7 @@ static void GetWeaponTintIndex(const v8::FunctionCallbackInfo &info) V8_RETURN_INTEGER(player->GetWeaponTintIndex(weaponHash)); } -static void GetCurrentWeapon(const v8::FunctionCallbackInfo &info) +static void GetCurrentWeapon(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); @@ -70,11 +239,11 @@ static void GetCurrentWeapon(const v8::FunctionCallbackInfo &info) V8_RETURN_INTEGER(player->GetCurrentWeapon()); } -static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - v8::Local arr = v8::Array::New(info.GetIsolate()); + v8::Local arr = v8::Array::New(isolate); uint16_t i = 0; for (auto player : alt::ICore::Instance().GetPlayers()) @@ -86,13 +255,14 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo V8_RETURN(arr); } -static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetLocalPlayer()); } -static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) +static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); @@ -100,7 +270,7 @@ static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid).As()); } -static void StaticGetByID(const v8::FunctionCallbackInfo &info) +static void StaticGetByID(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); @@ -110,7 +280,7 @@ static void StaticGetByID(const v8::FunctionCallbackInfo &info) extern V8Class v8Entity; extern V8Class v8Player("Player", v8Entity, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Local proto = tpl->PrototypeTemplate(); @@ -120,15 +290,33 @@ extern V8Class v8Player("Player", v8Entity, [](v8::Local t V8::SetStaticAccessor(isolate, tpl, "all", &AllGetter); V8::SetStaticAccessor(isolate, tpl, "local", &LocalGetter); + // Common getters V8::SetAccessor(isolate, tpl, "name", &NameGetter); V8::SetAccessor(isolate, tpl, "vehicle", &VehicleGetter); + V8::SetAccessor(isolate, tpl, "seat", &SeatGetter); V8::SetAccessor(isolate, tpl, "isTalking", &TalkingGetter); V8::SetAccessor(isolate, tpl, "micLevel", &MicLevelGetter); + V8::SetAccessor(isolate, tpl, "health", &HealthGetter); + V8::SetAccessor(isolate, tpl, "maxHealth", &MaxHealthGetter); + V8::SetAccessor(isolate, tpl, "armour", &ArmourGetter); + V8::SetAccessor(isolate, tpl, "maxArmour", &MaxArmourGetter); - if (alt::ICore::Instance().IsSandbox()) - { - proto->Set(isolate, "weaponHasComponent", v8::FunctionTemplate::New(isolate, &WeaponHasComponent)); - proto->Set(isolate, "getWeaponTintIndex", v8::FunctionTemplate::New(isolate, &GetWeaponTintIndex)); - proto->Set(isolate, "getCurrentWeapon", v8::FunctionTemplate::New(isolate, &GetCurrentWeapon)); - } + // Weapon getters + V8::SetAccessor(isolate, tpl, "currentWeaponComponents", &CurrentWeaponComponentsGetter); + V8::SetAccessor(isolate, tpl, "currentWeaponTintIndex", &CurrentWeaponTintIndexGetter); + V8::SetAccessor(isolate, tpl, "currentWeapon", &CurrentWeaponGetter); + V8::SetAccessor(isolate, tpl, "entityAimingAt", &EntityAimingAtGetter); + V8::SetAccessor(isolate, tpl, "entityAimOffset", &EntityAimOffsetGetter); + V8::SetAccessor(isolate, tpl, "flashlightActive", &FlashlightActiveGetter); + V8::SetAccessor(isolate, tpl, "aimPos", &AimPosGetter); + + // Gamestate getters + V8::SetAccessor(isolate, tpl, "isJumping", &IsJumpingGetter); + V8::SetAccessor(isolate, tpl, "isInRagdoll", &IsInRagdollGetter); + V8::SetAccessor(isolate, tpl, "isAiming", &IsAimingGetter); + V8::SetAccessor(isolate, tpl, "isShooting", &IsShootingGetter); + V8::SetAccessor(isolate, tpl, "isReloading", &IsReloadingGetter); + V8::SetAccessor(isolate, tpl, "isDead", &IsDeadGetter); + V8::SetAccessor(isolate, tpl, "moveSpeed", &MoveSpeedGetter); + V8::SetAccessor(isolate, tpl, "headRot", &HeadRotationGetter); }); diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index c5acb311..f8bd3b6a 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -3,22 +3,24 @@ #include "../helpers/V8Class.h" #include "../helpers/V8Entity.h" #include "../helpers/V8ResourceImpl.h" + +#include "cpp-sdk/objects/IPlayer.h" #include "cpp-sdk/objects/IVehicle.h" using namespace alt; -static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); V8_NEW_ARGS(args); V8_ADD_ARG(args, info.This()); - + extern V8Class v8Handling; - V8_RETURN(v8Handling.New(isolate->GetEnteredContext(), args)); + V8_RETURN(v8Handling.New(ctx, args)); } -static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); @@ -26,7 +28,7 @@ static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfoGetWheelSpeed()); } -static void GearGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void GearGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); @@ -34,7 +36,7 @@ static void GearGetter(v8::Local, const v8::PropertyCallbackInfoGetCurrentGear()); } -static void RPMGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void RPMGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); @@ -42,7 +44,7 @@ static void RPMGetter(v8::Local, const v8::PropertyCallbackInfoGetCurrentRPM()); } -static void WheelsCountGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void WheelsCountGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); @@ -50,7 +52,7 @@ static void WheelsCountGetter(v8::Local, const v8::PropertyCallbackI V8_RETURN_INTEGER(vehicle->GetWheelsCount()); } -static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); @@ -58,11 +60,454 @@ static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackI V8_RETURN(resource->CreateVector3(vehicle->GetSpeedVector())); } -static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo &info) +static void DriverGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BASE_OBJECT(vehicle->GetDriver()); +} + +static void IsDestroyedGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsDestroyed()); +} + +static void ModKitsCountGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetModKitsCount()); +} + +static void ModKitGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetModKit()); +} + +static void IsPrimaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsPrimaryColorRGB()); +} + +static void PrimaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetPrimaryColor()); +} + +static void PrimaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN(resource->CreateRGBA(vehicle->GetPrimaryColorRGB())); +} + +static void IsSecondaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsSecondaryColorRGB()); +} + +static void SecondaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetSecondaryColor()); +} + +static void SecondaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN(resource->CreateRGBA(vehicle->GetSecondaryColorRGB())); +} + +static void PearlColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetPearlColor()); +} + +static void WheelColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetWheelColor()); +} + +static void InteriorColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetInteriorColor()); +} + +static void DashboardColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetDashboardColor()); +} + +static void IsTireSmokeColorCustomGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsTireSmokeColorCustom()); +} + +static void TireSmokeColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN(resource->CreateRGBA(vehicle->GetTireSmokeColor())); +} + +static void WheelTypeGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetWheelType()); +} + +static void WheelVariationGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetWheelVariation()); +} + +static void RearWheelVariationGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetRearWheelVariation()); +} + +static void IsCustomTiresGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->GetCustomTires()); +} - v8::Local arr = v8::Array::New(info.GetIsolate()); +static void SpecialDarknessGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetSpecialDarkness()); +} + +static void NumberplateIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetNumberplateIndex()); +} + +static void NumberplateTextGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_STRING(vehicle->GetNumberplateText().CStr()); +} + +static void WindowTintGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetWindowTint()); +} + +static void DirtLevelGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetDirtLevel()); +} + +static void IsNeonActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsNeonActive()); +} + +static void NeonColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN(resource->CreateRGBA(vehicle->GetNeonColor())); +} + +static void NeonGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + v8::Local neonActive = v8::Object::New(isolate); + + bool left, right, front, back; + vehicle->GetNeonActive(&left, &right, &front, &back); + + neonActive->Set(ctx, v8::String::NewFromUtf8(isolate, "left").ToLocalChecked(), v8::Boolean::New(isolate, left)); + neonActive->Set(ctx, v8::String::NewFromUtf8(isolate, "right").ToLocalChecked(), v8::Boolean::New(isolate, right)); + neonActive->Set(ctx, v8::String::NewFromUtf8(isolate, "front").ToLocalChecked(), v8::Boolean::New(isolate, front)); + neonActive->Set(ctx, v8::String::NewFromUtf8(isolate, "back").ToLocalChecked(), v8::Boolean::New(isolate, back)); + + V8_RETURN(neonActive); +} + +static void LiveryGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetLivery()); +} + +static void RoofLiveryGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetRoofLivery()); +} + +static void EngineOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsEngineOn()); +} + +static void HandbrakeActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsHandbrakeActive()); +} + +static void HeadlightColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetHeadlightColor()); +} + +static void RadioStationIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetRadioStationIndex()); +} + +static void IsSirenActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsSirenActive()); +} + +static void LockStateGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetLockState()); +} + +static void IsDaylightOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsDaylightOn()); +} + +static void IsNightlightOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsNightlightOn()); +} + +static void RoofStateGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetRoofState()); +} + +static void IsFlamethrowerActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsFlamethrowerActive()); +} + +static void LightsMultiplierGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_NUMBER(vehicle->GetLightsMultiplier()); +} + +static void EngineHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetEngineHealth()); +} + +static void PetrolTankHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetPetrolTankHealth()); +} + +static void RepairsCountGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetRepairsCount()); +} + +static void BodyHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetBodyHealth()); +} + +static void BodyAdditionalHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetBodyAdditionalHealth()); +} + +static void HasArmoredWindowsGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->HasArmoredWindows()); +} + +static void IsManualEngineControlGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsManualEngineControl()); +} + +static void IsHandlingModifiedGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_BOOLEAN(vehicle->IsHandlingModified()); +} + +// static void GravityGetter(v8::Local, const v8::PropertyCallbackInfo &info) +// { +// V8_GET_ISOLATE(info); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); +// V8_CHECK(resource, "invalid resource"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// auto vehicle = _this->GetHandle().As()->GetGameVehicle(); +// V8_CHECK(vehicle, "Could not retrieve game vehicle"); + +// Log::Debug("GRAVITY", vehicle->gravity); +// auto ret = v8::Number::New(isolate, vehicle->gravity); +// Log::Debug("RET GRAVITY", ret->NumberValue(ctx).ToChecked()); +// info.GetReturnValue().Set(ret); +// } + +// static void GravitySetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +// { +// V8_GET_ISOLATE(info); +// V8_CHECK(val->IsNumber(), "val must be a number"); + +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8_CHECK(resource, "invalid resource"); + +// V8_CHECK(val->IsNumber(), "val needs to be a nummber (float)"); + +// V8Entity *_this = V8Entity::Get(info.This()); +// V8_CHECK(_this, "entity is invalid"); + +// auto vehicle = _this->GetHandle().As()->GetGameVehicle(); +// V8_CHECK(vehicle, "Could not retrieve game vehicle"); + +// Log::Debug("GRAVITY", vehicle->gravity); +// auto newval = val->NumberValue(ctx).ToChecked(); +// Log::Debug("NEW GRAVITY", newval); +// vehicle->gravity = newval; +// } + +static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + v8::Local arr = v8::Array::New(isolate); uint16_t i = 0; for (auto vehicle : alt::ICore::Instance().GetVehicles()) @@ -74,7 +519,7 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo V8_RETURN(arr); } -static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) +static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); @@ -82,7 +527,7 @@ static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid).As()); } -static void StaticGetByID(const v8::FunctionCallbackInfo &info) +static void StaticGetByID(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); @@ -92,7 +537,7 @@ static void StaticGetByID(const v8::FunctionCallbackInfo &info) extern V8Class v8Entity; extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Local proto = tpl->PrototypeTemplate(); @@ -101,10 +546,71 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetStaticAccessor(isolate, tpl, "all", &AllGetter); + // Common getters V8::SetAccessor(isolate, tpl, "speed", &SpeedGetter); V8::SetAccessor(isolate, tpl, "gear", &GearGetter); V8::SetAccessor(isolate, tpl, "rpm", &RPMGetter); V8::SetAccessor(isolate, tpl, "wheelsCount", &WheelsCountGetter); V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); + // proto->SetAccessor(v8::String::NewFromUtf8(isolate, "gravity", &GravityGetter).ToLocalChecked(), &GravitySetter); V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); + V8::SetAccessor(isolate, tpl, "isDestroyed", &IsDestroyedGetter); + V8::SetAccessor(isolate, tpl, "driver", &DriverGetter); + + // Appearance getters + V8::SetAccessor(isolate, tpl, "modKitsCount", &ModKitsCountGetter); + V8::SetAccessor(isolate, tpl, "modKit", &ModKitGetter); + //V8::SetAccessor(isolate, tpl, "hasCustomPrimaryColor", &IsPrimaryColorRGBGetter); + V8::SetAccessor(isolate, tpl, "primaryColor", &PrimaryColorGetter); + V8::SetAccessor(isolate, tpl, "customPrimaryColor", &PrimaryColorRGBGetter); + //V8::SetAccessor(isolate, tpl, "hasCustomSecondaryColor", &IsSecondaryColorRGBGetter); + V8::SetAccessor(isolate, tpl, "secondaryColor", &SecondaryColorGetter); + V8::SetAccessor(isolate, tpl, "customSecondaryColor", &SecondaryColorRGBGetter); + V8::SetAccessor(isolate, tpl, "pearlColor", &PearlColorGetter); + V8::SetAccessor(isolate, tpl, "wheelColor", &WheelColorGetter); + V8::SetAccessor(isolate, tpl, "interiorColor", &InteriorColorGetter); + V8::SetAccessor(isolate, tpl, "dashboardColor", &DashboardColorGetter); + //V8::SetAccessor(isolate, tpl, "hasCustomTireSmokeColor", &IsTireSmokeColorCustomGetter); + V8::SetAccessor(isolate, tpl, "tireSmokeColor", &TireSmokeColorGetter); + V8::SetAccessor(isolate, tpl, "wheelType", &WheelTypeGetter); + V8::SetAccessor(isolate, tpl, "frontWheels", &WheelVariationGetter); + V8::SetAccessor(isolate, tpl, "rearWheels", &RearWheelVariationGetter); + V8::SetAccessor(isolate, tpl, "customTires", &IsCustomTiresGetter); + V8::SetAccessor(isolate, tpl, "darkness", &SpecialDarknessGetter); + V8::SetAccessor(isolate, tpl, "numberPlateIndex", &NumberplateIndexGetter); + V8::SetAccessor(isolate, tpl, "numberPlateText", &NumberplateTextGetter); + V8::SetAccessor(isolate, tpl, "windowTint", &WindowTintGetter); + V8::SetAccessor(isolate, tpl, "dirtLevel", &DirtLevelGetter); + //V8::SetAccessor(isolate, tpl, "neonActive", &IsNeonActiveGetter); + V8::SetAccessor(isolate, tpl, "neon", &NeonGetter); + V8::SetAccessor(isolate, tpl, "neonColor", &NeonColorGetter); + V8::SetAccessor(isolate, tpl, "livery", &LiveryGetter); + V8::SetAccessor(isolate, tpl, "roofLivery", &RoofLiveryGetter); + + // Gamestate getters + V8::SetAccessor(isolate, tpl, "engineOn", &EngineOnGetter); + V8::SetAccessor(isolate, tpl, "handbrakeActive", &HandbrakeActiveGetter); + V8::SetAccessor(isolate, tpl, "headlightColor", &HeadlightColorGetter); + V8::SetAccessor(isolate, tpl, "activeRadioStation", &RadioStationIndexGetter); + V8::SetAccessor(isolate, tpl, "sirenActive", &IsSirenActiveGetter); + V8::SetAccessor(isolate, tpl, "lockState", &LockStateGetter); + V8::SetAccessor(isolate, tpl, "daylightOn", &IsDaylightOnGetter); + V8::SetAccessor(isolate, tpl, "nightlightOn", &IsNightlightOnGetter); + V8::SetAccessor(isolate, tpl, "roofState", &RoofStateGetter); + V8::SetAccessor(isolate, tpl, "flamethrowerActive", &IsFlamethrowerActiveGetter); + V8::SetAccessor(isolate, tpl, "lightsMultiplier", &LightsMultiplierGetter); + + // Health getters + V8::SetAccessor(isolate, tpl, "engineHealth", &EngineHealthGetter); + V8::SetAccessor(isolate, tpl, "petrolTankHealth", &PetrolTankHealthGetter); + V8::SetAccessor(isolate, tpl, "repairsCount", &RepairsCountGetter); + V8::SetAccessor(isolate, tpl, "bodyHealth", &BodyHealthGetter); + V8::SetAccessor(isolate, tpl, "bodyAdditionalHealth", &BodyAdditionalHealthGetter); + + // Damage getters + V8::SetAccessor(isolate, tpl, "hasArmoredWindows", &HasArmoredWindowsGetter); + + // Script getters + V8::SetAccessor(isolate, tpl, "manualEngineControl", &IsManualEngineControlGetter); + //V8::SetAccessor(isolate, tpl, "handlingModified", &IsHandlingModifiedGetter); }); From 909234967faf8607d5aa93fae8ea4f5a1d34df1d Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 18 Nov 2020 14:02:41 +0100 Subject: [PATCH 097/564] Fixed self-importing --- src/CV8ScriptRuntime.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 109f94c9..c7b3c688 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -75,14 +75,21 @@ class CV8ScriptRuntime : public alt::IScriptRuntime static v8::MaybeLocal ResolveModule(v8::Local ctx, v8::Local specifier, v8::Local referrer) { + auto isolate = ctx->GetIsolate(); V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); if (!resource) { - ctx->GetIsolate()->ThrowException(v8::Exception::ReferenceError(v8::String::NewFromUtf8(ctx->GetIsolate(), "Invalid resource").ToLocalChecked())); + isolate->ThrowException(v8::Exception::ReferenceError(v8::String::NewFromUtf8(ctx->GetIsolate(), "Invalid resource").ToLocalChecked())); + return v8::MaybeLocal{}; + } + + std::string _specifier = *v8::String::Utf8Value{isolate, specifier}; + if(_specifier == resource->GetResource()->GetName().ToString()) + { + isolate->ThrowException(v8::Exception::ReferenceError(v8::String::NewFromUtf8(ctx->GetIsolate(), "Cannot import the resource itself (self-importing)").ToLocalChecked())); return v8::MaybeLocal{}; } - std::string _specifier = *v8::String::Utf8Value{ctx->GetIsolate(), specifier}; return static_cast(resource)->ResolveModule(_specifier, referrer); } From 58bf1ba238d2894acf517e363d73de5b206cb06a Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 14:40:30 +0100 Subject: [PATCH 098/564] fix macros --- V8Helpers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index 86e07e4e..0e8b4d7f 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -287,8 +287,8 @@ namespace V8 #define V8_CHECK_ARGS_LEN(count) V8_CHECK(info.Length() == (count), #count " arguments expected") #define V8_CHECK_ARGS_LEN2(count1, count2) V8_CHECK(info.Length() == (count1) || info.Length() == (count2), #count1 " or " #count2 " arguments expected") -#define V8_CHECK_ARGS_LEN_MIN_MAX(count1, count2) V8_CHECK(info.Length() >= (count1) && info.Length() <= (count2), "Minimum " #count1 ", maximum " #count2 " arguments expected") -#define V8_CHECK_ARGS_LEN_MIN(count) V8_CHECK(info.Length() <= (count), "Minimum " #count " arguments expected") +#define V8_CHECK_ARGS_LEN_MIN_MAX(count1, count2) V8_CHECK(info.Length() < (count1) || info.Length() > (count2), "Minimum " #count1 ", maximum " #count2 " arguments expected") +#define V8_CHECK_ARGS_LEN_MIN(count) V8_CHECK(info.Length() < (count), "Minimum " #count " arguments expected") #define V8_TO_BOOLEAN(v8Val, val) \ bool val; \ From 527ed27d89ea2637197e791cadda093b4618999a Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 14:41:23 +0100 Subject: [PATCH 099/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 8dbdb345..58bf1ba2 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 8dbdb3451f0ef1f1a69320c70994c17e8d387d80 +Subproject commit 58bf1ba238d2894acf517e363d73de5b206cb06a From a1d65ace821e7cb8c4854c84cb31aea84ea2258f Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 15:14:20 +0100 Subject: [PATCH 100/564] fix macros 2 --- V8Helpers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index 0e8b4d7f..e54d5dca 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -287,8 +287,8 @@ namespace V8 #define V8_CHECK_ARGS_LEN(count) V8_CHECK(info.Length() == (count), #count " arguments expected") #define V8_CHECK_ARGS_LEN2(count1, count2) V8_CHECK(info.Length() == (count1) || info.Length() == (count2), #count1 " or " #count2 " arguments expected") -#define V8_CHECK_ARGS_LEN_MIN_MAX(count1, count2) V8_CHECK(info.Length() < (count1) || info.Length() > (count2), "Minimum " #count1 ", maximum " #count2 " arguments expected") -#define V8_CHECK_ARGS_LEN_MIN(count) V8_CHECK(info.Length() < (count), "Minimum " #count " arguments expected") +#define V8_CHECK_ARGS_LEN_MIN_MAX(count1, count2) V8_CHECK(info.Length() >= (count1) && info.Length() <= (count2), "Minimum " #count1 ", maximum " #count2 " arguments expected") +#define V8_CHECK_ARGS_LEN_MIN(count) V8_CHECK(info.Length() >= (count), "Minimum " #count " arguments expected") #define V8_TO_BOOLEAN(v8Val, val) \ bool val; \ From 90104624eb813db89fd216efb3da1f93b2215d60 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 15:14:35 +0100 Subject: [PATCH 101/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 58bf1ba2..a1d65ace 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 58bf1ba238d2894acf517e363d73de5b206cb06a +Subproject commit a1d65ace821e7cb8c4854c84cb31aea84ea2258f From c6161c673b18da0939091912b5ce5b7e646f232a Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 15:59:06 +0100 Subject: [PATCH 102/564] fix webview emit --- src/bindings/WebView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index e552f6f8..b977e5ca 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -38,7 +38,7 @@ static void Emit(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK_ARGS_LEN(1); + V8_CHECK_ARGS_LEN_MIN(1); V8_ARG_TO_STRING(1, evName); V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); From 83a42d6f85270d583c10bc068067368d81e5d798 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 16:25:41 +0100 Subject: [PATCH 103/564] fix storage save --- src/bindings/LocalStorage.cpp | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/bindings/LocalStorage.cpp b/src/bindings/LocalStorage.cpp index 2bcfa884..9ab59c3d 100644 --- a/src/bindings/LocalStorage.cpp +++ b/src/bindings/LocalStorage.cpp @@ -14,64 +14,46 @@ static void StaticGet(const v8::FunctionCallbackInfo &info) static void Get(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT(); + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, key); - alt::IResource *resource = V8ResourceImpl::GetResource(ctx); - V8_CHECK(resource, "Invalid resource"); - V8_RETURN(V8Helpers::MValueToV8(resource->GetLocalStorage()->Get(key))); } static void Set(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT(); + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); V8_CHECK_ARGS_LEN(2); V8_ARG_TO_STRING(1, key); V8_ARG_TO_MVALUE(2, val); - alt::IResource *resource = V8ResourceImpl::GetResource(ctx); - V8_CHECK(resource, "Invalid resource"); - resource->GetLocalStorage()->Set(key, val); } static void Delete(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT(); + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, key); - alt::IResource *resource = V8ResourceImpl::GetResource(ctx); - V8_CHECK(resource, "Invalid resource"); - resource->GetLocalStorage()->Delete(key); } static void Clear(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT(); - - alt::IResource *resource = V8ResourceImpl::GetResource(ctx); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); resource->GetLocalStorage()->Clear(); } static void Save(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT(); - - V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_STRING(1, key); - - alt::IResource *resource = V8ResourceImpl::GetResource(ctx); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); V8_CHECK(resource->GetLocalStorage()->Save(), "exceeded max local storage size (4MB)"); } From 0508a1a9794d73fd9c0765d6931a8cf3fbe0b2b3 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 17:05:25 +0100 Subject: [PATCH 104/564] add new macros --- V8Helpers.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/V8Helpers.h b/V8Helpers.h index e54d5dca..25da1f77 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -322,6 +322,12 @@ namespace V8 #define V8_OBJECT_SET_INTEGER(v8Val, prop, val) \ (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Integer::New(isolate, val)); +#define V8_OBJECT_GET_BOOLEAN(v8Val, prop, val) \ + V8_TO_BOOLEAN((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) + +#define V8_OBJECT_SET_BOOLEAN(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Boolean::New(isolate, val)); + #define V8_OBJECT_GET_STRING(v8Val, prop, val) \ V8_TO_STRING((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) From 9fe4738c0a3c5ebb4a315dec7c566fb035a73104 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 18 Nov 2020 17:05:13 +0100 Subject: [PATCH 105/564] fix merge --- src/bindings/Player.cpp | 2 -- src/bindings/Vehicle.cpp | 13 +++++-------- src/helpers | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 6d571983..b9fdcc40 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -282,8 +282,6 @@ extern V8Class v8Entity; extern V8Class v8Player("Player", v8Entity, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local proto = tpl->PrototypeTemplate(); - V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index f8bd3b6a..28986514 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -281,15 +281,14 @@ static void NeonGetter(v8::Local, const v8::PropertyCallbackInfo neonActive = v8::Object::New(isolate); - bool left, right, front, back; vehicle->GetNeonActive(&left, &right, &front, &back); - neonActive->Set(ctx, v8::String::NewFromUtf8(isolate, "left").ToLocalChecked(), v8::Boolean::New(isolate, left)); - neonActive->Set(ctx, v8::String::NewFromUtf8(isolate, "right").ToLocalChecked(), v8::Boolean::New(isolate, right)); - neonActive->Set(ctx, v8::String::NewFromUtf8(isolate, "front").ToLocalChecked(), v8::Boolean::New(isolate, front)); - neonActive->Set(ctx, v8::String::NewFromUtf8(isolate, "back").ToLocalChecked(), v8::Boolean::New(isolate, back)); + V8_NEW_OBJECT(neonActive); + V8_OBJECT_SET_BOOLEAN(neonActive, "left", left); + V8_OBJECT_SET_BOOLEAN(neonActive, "right", right); + V8_OBJECT_SET_BOOLEAN(neonActive, "front", front); + V8_OBJECT_SET_BOOLEAN(neonActive, "back", back); V8_RETURN(neonActive); } @@ -539,8 +538,6 @@ extern V8Class v8Entity; extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local proto = tpl->PrototypeTemplate(); - V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); diff --git a/src/helpers b/src/helpers index a1d65ace..0508a1a9 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit a1d65ace821e7cb8c4854c84cb31aea84ea2258f +Subproject commit 0508a1a9794d73fd9c0765d6931a8cf3fbe0b2b3 From 1cc9c75e50598d27cfeace1528efe86c7b5409da Mon Sep 17 00:00:00 2001 From: Vektor Date: Thu, 19 Nov 2020 06:56:06 +0100 Subject: [PATCH 106/564] Remove irrelevant implementation --- src/CV8Resource.h | 57 ----------------------------------------------- 1 file changed, 57 deletions(-) diff --git a/src/CV8Resource.h b/src/CV8Resource.h index 5b42f263..2f2d64ab 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -55,31 +55,6 @@ class CV8ResourceImpl : public V8ResourceImpl } } - void AddGxtText(uint32_t hash, const std::string &text) - { - std::unique_lock lock(gxtAccessMutex); - if (gxtEntries.count(hash) > 0) - gxtEntries[hash] = text; - else - gxtEntries.insert(std::pair(hash, text)); - } - - void RemoveGxtText(uint32_t hash) - { - std::unique_lock lock(gxtAccessMutex); - if (gxtEntries.count(hash) > 0) - gxtEntries.erase(hash); - } - - const std::string &GetGxtText(uint32_t hash) - { - static std::string emptyString = ""; - std::unique_lock lock(gxtAccessMutex); - if (gxtEntries.count(hash) > 0) - return gxtEntries[hash]; - return emptyString; - } - void AddOwned(alt::Ref handle) { ownedObjects.insert(handle); @@ -95,32 +70,6 @@ class CV8ResourceImpl : public V8ResourceImpl V8ResourceImpl::OnRemoveBaseObject(handle); } - bool ToggleCursor(bool state) - { - if (cursorsCount > 0 || state) - { - cursorsCount += state ? 1 : -1; - return true; - } - - return false; - } - - void ToggleGameControls(bool state) - { - gameControlsEnabled = state; - } - - bool CursorVisible() - { - return cursorsCount > 0; - } - - bool GameControlsActive() - { - return gameControlsEnabled; - } - v8::Local GetLocalStorage() { if (localStorage.IsEmpty()) @@ -150,14 +99,8 @@ class CV8ResourceImpl : public V8ResourceImpl std::unordered_map> modules; std::unordered_map, WebViewEvents> webViewHandlers; - std::unordered_map gxtEntries; std::unordered_set> ownedObjects; v8::Persistent localStorage; - - std::mutex gxtAccessMutex; - - uint32_t cursorsCount = 0; - bool gameControlsEnabled = true; }; From b9c3c1afff45dae315da8c1d2ca786ebcf4abf96 Mon Sep 17 00:00:00 2001 From: Vektor Date: Thu, 19 Nov 2020 07:02:43 +0100 Subject: [PATCH 107/564] fix bindings for latest changes --- src/bindings/Main.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 3865bdcb..3a0f7181 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -54,13 +54,12 @@ static void GameControlsEnabled(const v8::FunctionCallbackInfo &info) static void ToggleGameControls(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); V8_CHECK_ARGS_LEN(1); V8_ARG_TO_BOOLEAN(1, state); - CV8ResourceImpl *jsResource = static_cast(resource); - jsResource->ToggleGameControls(state); + resource->ToggleGameControls(state); } static void ToggleVoiceControls(const v8::FunctionCallbackInfo &info) @@ -77,14 +76,12 @@ static void ToggleVoiceControls(const v8::FunctionCallbackInfo &info) static void ShowCursor(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); V8_CHECK_ARGS_LEN(1); V8_ARG_TO_BOOLEAN(1, state); - CV8ResourceImpl *jsResource = static_cast(resource); - - if (!jsResource->ToggleCursor(state)) + if (!resource->ToggleCursor(state)) { if (alt::ICore::Instance().IsDebug()) { @@ -196,33 +193,33 @@ static void IsVoiceActivityInputEnabled(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); V8_CHECK_ARGS_LEN(2); V8_ARG_TO_STRING(1, key); V8_ARG_TO_STRING(2, textValue); - static_cast(resource)->AddGxtText(ICore::Instance().Hash(key), textValue.ToString()); + resource->AddGxtText(ICore::Instance().Hash(key), textValue.ToString()); } static void RemoveGxtText(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, key); - static_cast(resource)->RemoveGxtText(ICore::Instance().Hash(key)); + resource->RemoveGxtText(ICore::Instance().Hash(key)); } static void GetGxtText(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, key); - V8_RETURN_STRING(static_cast(resource)->GetGxtText(ICore::Instance().Hash(key)).c_str()); + resource->GetGxtText(ICore::Instance().Hash(key)).c_str(); } static void GetMsPerGameMinute(const v8::FunctionCallbackInfo &info) From 77e7d3f150411cede36a3e09ca4add11e4f502a2 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 19 Nov 2020 20:31:49 +0100 Subject: [PATCH 108/564] Add GetSDKVersion export --- src/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 109a66d3..2e62aca7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,3 +19,8 @@ ALTV_JS_EXPORT alt::IScriptRuntime *CreateJSScriptRuntime(alt::ICore *core) auto ret = new CV8ScriptRuntime(); return ret; } + +ALTV_JS_EXPORT uint32_t GetSDKVersion() +{ + return alt::ICore::SDK_VERSION; +} \ No newline at end of file From bb6d516228be36091726953bafcba4fbdd908390 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 21 Nov 2020 11:00:21 +0100 Subject: [PATCH 109/564] Removed DefaultDimension and GlobalDimension from Sared Exports --- bindings/Main.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 4f723d0d..213473e2 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -262,9 +262,6 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8Helpers::RegisterFunc(exports, "clearTimeout", &ClearTimer); V8Helpers::RegisterFunc(exports, "clearInterval", &ClearTimer); - V8::DefineOwnProperty(isolate, ctx, exports, "DefaultDimension", v8::Integer::New(isolate, alt::DEFAULT_DIMENSION)); - V8::DefineOwnProperty(isolate, ctx, exports, "GlobalDimension", v8::Integer::New(isolate, alt::GLOBAL_DIMENSION)); - V8::DefineOwnProperty(isolate, ctx, exports, "Version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); V8::DefineOwnProperty(isolate, ctx, exports, "Branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); V8::DefineOwnProperty(isolate, ctx, exports, "sdkVersion", v8::Integer::New(isolate, alt::ICore::Instance().SDK_VERSION)); From c039e3d64b4fc72a34720eedfdb2c33c954254dc Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 21 Nov 2020 16:50:02 +0100 Subject: [PATCH 110/564] Change capitalization for alt.Version and alt.Branch --- bindings/Main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 213473e2..3bf74ead 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -262,7 +262,7 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8Helpers::RegisterFunc(exports, "clearTimeout", &ClearTimer); V8Helpers::RegisterFunc(exports, "clearInterval", &ClearTimer); - V8::DefineOwnProperty(isolate, ctx, exports, "Version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); - V8::DefineOwnProperty(isolate, ctx, exports, "Branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); + V8::DefineOwnProperty(isolate, ctx, exports, "version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); + V8::DefineOwnProperty(isolate, ctx, exports, "branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); V8::DefineOwnProperty(isolate, ctx, exports, "sdkVersion", v8::Integer::New(isolate, alt::ICore::Instance().SDK_VERSION)); } From 8e86e6ae51cf6604ca68fd1263887633b890ab26 Mon Sep 17 00:00:00 2001 From: Hazard Date: Sun, 22 Nov 2020 13:47:51 +0100 Subject: [PATCH 111/564] Fix warning msg --- src/CV8Resource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index a3a1e61b..cb172b0c 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -461,7 +461,7 @@ void CV8ResourceImpl::OnTick() if (GetTime() - time > 10) { - Log::Warning << "Resource" << resource->GetName() << "tick was too long" << GetTime() - time, "ms"; + Log::Warning << "Resource " << resource->GetName() << " tick was too long " << GetTime() - time << " ms" << Log::Endl; } for (auto &view : webViewHandlers) From 88e6925696d083470c4bfb81eecbd7b0a87a1688 Mon Sep 17 00:00:00 2001 From: Hazard Date: Sun, 22 Nov 2020 16:00:27 +0100 Subject: [PATCH 112/564] Added delete entity --- V8ResourceImpl.cpp | 13 +++++++++++++ V8ResourceImpl.h | 1 + 2 files changed, 14 insertions(+) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index fa3723cc..e6042bf7 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -81,6 +81,19 @@ void V8ResourceImpl::OnTick() promiseRejections.ProcessQueue(this); } +bool V8ResourceImpl::DeleteEntity(alt::Ref handle) +{ + auto it = entities.find(handle.Get()); + if(it == entities.end()) return false; + + delete it->second; + entities.erase(it); + + resource->RemoveReference(handle); + + return true; +} + void V8ResourceImpl::BindEntity(v8::Local val, alt::IBaseObject *handle) { V8Entity *ent = new V8Entity(GetContext(), V8Entity::GetClass(handle), val, handle); diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index 6fbd4a04..cba30865 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -116,6 +116,7 @@ class V8ResourceImpl : public alt::IResource::Impl return ent; } + bool DeleteEntity(alt::Ref handle); void BindEntity(v8::Local val, alt::IBaseObject *handle); V8Entity *GetOrCreateEntity(alt::IBaseObject *handle, const char *className = "") From 03cde36efd0a88076f6fb225fb55e2f8cccf0190 Mon Sep 17 00:00:00 2001 From: Hazard Date: Sun, 22 Nov 2020 16:01:15 +0100 Subject: [PATCH 113/564] WIP deleting blip --- src/bindings/Blip.cpp | 9 +++++++++ src/helpers | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index ac5d74cc..14e91154 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -577,6 +577,13 @@ static void Fade(const v8::FunctionCallbackInfo& info) blip->Fade(opacity, duration); } +static void Delete(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_CHECK(resource->DeleteEntity(blip), "Could not delete blip"); +} + extern V8Class v8WorldObject; extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local tpl){ v8::Isolate* isolate = v8::Isolate::GetCurrent(); @@ -614,6 +621,8 @@ extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local tpl) { diff --git a/src/helpers b/src/helpers index 0508a1a9..2a0efeee 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 0508a1a9794d73fd9c0765d6931a8cf3fbe0b2b3 +Subproject commit 2a0efeeec1e726daa3ba42eda5c5ac6673ba20dd From 434e8fc6fbae65244992ed9a7bdf69e51626d63b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 22 Nov 2020 18:30:24 +0100 Subject: [PATCH 114/564] Added alt.Entity.all getter --- bindings/Entity.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index 3cef16c9..0c6044ef 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -243,11 +243,28 @@ static void StaticGetByID(const v8::FunctionCallbackInfo &info) V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id)); } +static void StaticAllGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + v8::Local arr = v8::Array::New(isolate); + + uint16_t i = 0; + for (auto entity : alt::ICore::Instance().GetEntities()) + { + if (entity) + arr->Set(ctx, i++, resource->GetOrCreateEntity(entity.Get(), "Entity")->GetJSVal(isolate)); + }; + + V8_RETURN(arr); +} + extern V8Class v8WorldObject; extern V8Class v8Entity("Entity", v8WorldObject, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); + V8::SetStaticAccessor(isolate, tpl, "all", StaticAllGetter); V8::SetAccessor(isolate, tpl, "id", IDGetter); From e64886b39b45d5b3499714fdc177e82b560eeada Mon Sep 17 00:00:00 2001 From: Hazard Date: Mon, 23 Nov 2020 01:38:38 +0100 Subject: [PATCH 115/564] added error when attempting to delete invalid object --- V8ResourceImpl.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index e6042bf7..e2405063 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -84,11 +84,17 @@ void V8ResourceImpl::OnTick() bool V8ResourceImpl::DeleteEntity(alt::Ref handle) { auto it = entities.find(handle.Get()); - if(it == entities.end()) return false; + if(it == entities.end()) + { + Log::Error << "[JS] Attempted to delete invalid object" << Log::Endl; + return false; + } delete it->second; entities.erase(it); + // BAD, SHOULD ONLY BE DONE FOR ENTITIES + // THAT WAS CREATED FROM JS resource->RemoveReference(handle); return true; From bd3f0667bc9e6112e69b53c4bf616c0451711a23 Mon Sep 17 00:00:00 2001 From: Hazard Date: Mon, 23 Nov 2020 01:39:01 +0100 Subject: [PATCH 116/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 2a0efeee..e64886b3 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 2a0efeeec1e726daa3ba42eda5c5ac6673ba20dd +Subproject commit e64886b39b45d5b3499714fdc177e82b560eeada From 8965d63e8b7b2746c25a83cbccc41c22833a68f3 Mon Sep 17 00:00:00 2001 From: Vektor Date: Tue, 24 Nov 2020 06:47:53 +0100 Subject: [PATCH 117/564] Checkpoints WIP2 --- src/bindings/Checkpoint.cpp | 163 ++++++++++++++++++++++++++++++++++++ src/bindings/Handling.cpp | 2 - 2 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 src/bindings/Checkpoint.cpp diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp new file mode 100644 index 00000000..b01e57d4 --- /dev/null +++ b/src/bindings/Checkpoint.cpp @@ -0,0 +1,163 @@ +#include "../CV8Resource.h" +#include "../helpers/V8Helpers.h" +#include "cpp-sdk/script-objects/ICheckpoint.h" + +static void Constructor(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN(10); + V8_ARG_TO_INTEGER(1, type); + V8_ARG_TO_NUMBER(2, x1); + V8_ARG_TO_NUMBER(3, y1); + V8_ARG_TO_NUMBER(4, z1); + V8_ARG_TO_NUMBER(5, x2); + V8_ARG_TO_NUMBER(6, y2); + V8_ARG_TO_NUMBER(7, z2); + V8_ARG_TO_NUMBER(8, radius); + V8_ARG_TO_NUMBER(9, height); + V8_ARG_TO_OBJECT(10, color); + + V8_OBJECT_GET_INTEGER(color, "r", r); + V8_OBJECT_GET_INTEGER(color, "g", g); + V8_OBJECT_GET_INTEGER(color, "b", b); + V8_OBJECT_GET_INTEGER(color, "a", a); + + alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::Ref cp = res->CreateCheckpoint(type, { x1, y1, z1 }, { x2, y2, z2 }, radius, height, { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); + V8_BIND_BASE_OBJECT(cp); +} + +static void TypeGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + V8_RETURN_INTEGER(cp->GetCheckpointType()); +} + +static void TypeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + V8_TO_INTEGER(value, val); + cp->SetCheckpointType(val); +} + +static void RadiusGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + V8_RETURN_NUMBER(cp->GetRadius()); +} + +static void RadiusSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + V8_TO_NUMBER(value, val); + cp->SetRadius(val); +} + +static void HeightGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + V8_RETURN_NUMBER(cp->GetHeight()); +} + +static void HeightSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + V8_TO_NUMBER(value, val); + cp->SetHeight(val); +} + +static void ColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + V8_RETURN(resource->CreateRGBA(cp->GetColor())); +} + +static void ColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + + V8_TO_OBJECT(value, color); + V8_OBJECT_GET_INTEGER(color, "r", r); + V8_OBJECT_GET_INTEGER(color, "g", g); + V8_OBJECT_GET_INTEGER(color, "b", b); + V8_OBJECT_GET_INTEGER(color, "a", a); + + cp->SetColor({ (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); +} + +static void NextPosGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + + V8_RETURN(resource->CreateVector3(cp->GetNextPosition())); +} + +static void NextPosSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + + V8_TO_OBJECT(val, pos); + V8_OBJECT_GET_NUMBER(pos, "x", x); + V8_OBJECT_GET_NUMBER(pos, "y", y); + V8_OBJECT_GET_NUMBER(pos, "z", z); + + cp->SetNextPosition({ x, y, z }); +} + +static void IsEntityIn(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + + V8_ARG_TO_BASE_OBJECT(1, ent, alt::IEntity, "IEntity"); + + V8_RETURN_BOOLEAN(cp->IsEntityIn(ent)); +} + +static void IsPointIn(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + + V8_ARG_TO_OBJECT(1, pos); + V8_OBJECT_GET_NUMBER(pos, "x", x); + V8_OBJECT_GET_NUMBER(pos, "y", y); + V8_OBJECT_GET_NUMBER(pos, "z", z); + + V8_RETURN_BOOLEAN(cp->IsPointIn({ x, y, z})); +} + +static void Delete(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); + V8_CHECK(resource->DeleteEntity(cp), "Could not delete blip"); +} + +extern V8Class v8WorldObject; +extern V8Class v8Checkpoint("Checkpoint", v8WorldObject, Constructor, [](v8::Local tpl) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8::SetAccessor(isolate, tpl, "checkpointType", &TypeGetter, &TypeSetter); + V8::SetAccessor(isolate, tpl, "radius", &RadiusGetter, &RadiusSetter); + V8::SetAccessor(isolate, tpl, "height", &HeightGetter, &HeightSetter); + V8::SetAccessor(isolate, tpl, "color", &ColorGetter, &ColorSetter); + V8::SetAccessor(isolate, tpl, "nextPos", &NextPosGetter, &NextPosSetter); + + V8::SetMethod(isolate, tpl, "isEntityIn", &IsEntityIn); + V8::SetMethod(isolate, tpl, "isPointIn", &IsPointIn); + + V8::SetMethod(isolate, tpl, "delete", &Delete); + V8::SetMethod(isolate, tpl, "destroy", &Delete); +}); \ No newline at end of file diff --git a/src/bindings/Handling.cpp b/src/bindings/Handling.cpp index b00e18dc..3487099e 100644 --- a/src/bindings/Handling.cpp +++ b/src/bindings/Handling.cpp @@ -135,7 +135,6 @@ static void CentreOfMassOffsetSetter(v8::Local, v8::Local V8_OBJECT_GET_NUMBER(pos, "y", y); V8_OBJECT_GET_NUMBER(pos, "z", z); - V8_TO_NUMBER(val, fvalue); vehicle->GetHandling()->SetCentreOfMassOffset({ x, y, z }); } @@ -157,7 +156,6 @@ static void InertiaMultiplierSetter(v8::Local, v8::Local V8_OBJECT_GET_NUMBER(pos, "y", y); V8_OBJECT_GET_NUMBER(pos, "z", z); - V8_TO_NUMBER(val, fvalue); vehicle->GetHandling()->SetInertiaMultiplier({ x, y, z }); } From 9b8cfa58ba5a3ca57db80234a7c334bb247ec27d Mon Sep 17 00:00:00 2001 From: Vektor Date: Tue, 24 Nov 2020 16:56:02 +0100 Subject: [PATCH 118/564] fix GetGxtText --- src/bindings/Main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 3a0f7181..7627d4e7 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -219,7 +219,7 @@ static void GetGxtText(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, key); - resource->GetGxtText(ICore::Instance().Hash(key)).c_str(); + V8_RETURN_STRING(resource->GetGxtText(ICore::Instance().Hash(key)).c_str()); } static void GetMsPerGameMinute(const v8::FunctionCallbackInfo &info) From 47f7d291112a7f94bceb1f0a66bdd3864295616e Mon Sep 17 00:00:00 2001 From: Vektor Date: Tue, 24 Nov 2020 21:35:21 +0100 Subject: [PATCH 119/564] move stuff to ICore --- src/bindings/Blip.cpp | 17 +++++------------ src/bindings/Checkpoint.cpp | 3 +-- src/bindings/Main.cpp | 32 +++++++++++++++----------------- src/bindings/WebView.cpp | 6 +++--- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index 14e91154..76ac2d16 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -20,8 +20,7 @@ static void ConstructorAreaBlip(const v8::FunctionCallbackInfo& info) V8_ARG_TO_NUMBER(4, width); V8_ARG_TO_NUMBER(5, height); - alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - alt::Ref blip = res->CreateBlip({ x, y, z }, width, height); + alt::Ref blip = alt::ICore::Instance().CreateBlip({ x, y, z }, width, height); V8_BIND_BASE_OBJECT(blip); } @@ -35,8 +34,7 @@ static void ConstructorRadiusBlip(const v8::FunctionCallbackInfo& inf V8_ARG_TO_NUMBER(3, z); V8_ARG_TO_NUMBER(4, radius); - alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - alt::Ref blip = res->CreateBlip({ x, y, z }, radius); + alt::Ref blip = alt::ICore::Instance().CreateBlip({ x, y, z }, radius); V8_BIND_BASE_OBJECT(blip); } @@ -49,8 +47,7 @@ static void ConstructorPointBlip(const v8::FunctionCallbackInfo& info V8_ARG_TO_NUMBER(2, y); V8_ARG_TO_NUMBER(3, z); - alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - alt::Ref blip = res->CreateBlip(alt::IBlip::BlipType::DESTINATION, { x, y, z }); + alt::Ref blip = alt::ICore::Instance().CreateBlip(alt::IBlip::BlipType::DESTINATION, { x, y, z }); V8_BIND_BASE_OBJECT(blip); } @@ -61,8 +58,7 @@ static void ConstructorPedBlip(const v8::FunctionCallbackInfo& info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_INTEGER(1, pedId); - alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - alt::Ref blip = res->CreateBlip(alt::IBlip::BlipType::PED, pedId); + alt::Ref blip = alt::ICore::Instance().CreateBlip(alt::IBlip::BlipType::PED, pedId); V8_BIND_BASE_OBJECT(blip); } @@ -73,10 +69,7 @@ static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo& in V8_CHECK_ARGS_LEN(1); V8_ARG_TO_INTEGER(1, vehicleId); - alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - alt::Ref blip = res->CreateBlip(alt::IBlip::BlipType::VEHICLE, vehicleId); - - + alt::Ref blip = alt::ICore::Instance().CreateBlip(alt::IBlip::BlipType::VEHICLE, vehicleId); V8_BIND_BASE_OBJECT(blip); } diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index b01e57d4..75d9f41a 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -23,8 +23,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_OBJECT_GET_INTEGER(color, "b", b); V8_OBJECT_GET_INTEGER(color, "a", a); - alt::IResource* res = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - alt::Ref cp = res->CreateCheckpoint(type, { x1, y1, z1 }, { x2, y2, z2 }, radius, height, { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); + alt::Ref cp = alt::ICore::Instance().CreateCheckpoint(type, { x1, y1, z1 }, { x2, y2, z2 }, radius, height, { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); V8_BIND_BASE_OBJECT(cp); } diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 7627d4e7..ec2b7ec6 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -59,7 +59,7 @@ static void ToggleGameControls(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_BOOLEAN(1, state); - resource->ToggleGameControls(state); + alt::ICore::Instance().ToggleGameControls(state); } static void ToggleVoiceControls(const v8::FunctionCallbackInfo &info) @@ -81,7 +81,7 @@ static void ShowCursor(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_BOOLEAN(1, state); - if (!resource->ToggleCursor(state)) + if (!alt::ICore::Instance().ToggleCursor(state)) { if (alt::ICore::Instance().IsDebug()) { @@ -199,7 +199,7 @@ static void AddGxtText(const v8::FunctionCallbackInfo &info) V8_ARG_TO_STRING(1, key); V8_ARG_TO_STRING(2, textValue); - resource->AddGxtText(ICore::Instance().Hash(key), textValue.ToString()); + alt::ICore::Instance().AddGxtText(ICore::Instance().Hash(key), textValue.ToString()); } static void RemoveGxtText(const v8::FunctionCallbackInfo &info) @@ -209,7 +209,7 @@ static void RemoveGxtText(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, key); - resource->RemoveGxtText(ICore::Instance().Hash(key)); + alt::ICore::Instance().RemoveGxtText(ICore::Instance().Hash(key)); } static void GetGxtText(const v8::FunctionCallbackInfo &info) @@ -219,7 +219,7 @@ static void GetGxtText(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, key); - V8_RETURN_STRING(resource->GetGxtText(ICore::Instance().Hash(key)).c_str()); + V8_RETURN_STRING(alt::ICore::Instance().GetGxtText(ICore::Instance().Hash(key)).c_str()); } static void GetMsPerGameMinute(const v8::FunctionCallbackInfo &info) @@ -562,20 +562,18 @@ static void DoesConfigFlagExist(const v8::FunctionCallbackInfo &info) // V8_RETURN(buf); // } -// static void SetAngularVelocity(const v8::FunctionCallbackInfo &info) -// { -// V8_GET_ISOLATE_CONTEXT(); -// V8_CHECK_ARGS_LEN(4); - -// V8_ARG_TO_INTEGER(1, id); -// V8_ARG_TO_NUMBER(2, x); -// V8_ARG_TO_NUMBER(3, y); -// V8_ARG_TO_NUMBER(4, z); +static void SetAngularVelocity(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(4); -// ::CDynamicEntity *ent = funcs::GetEntityFromScriptID<::CDynamicEntity *>(id); + V8_ARG_TO_INTEGER(1, id); + V8_ARG_TO_NUMBER(2, x); + V8_ARG_TO_NUMBER(3, y); + V8_ARG_TO_NUMBER(4, z); -// ent->SetAngularVelocity({x, y, z, 0.0}); -// } + alt::ICore::Instance().SetAngularVelocity(id, { x, y, z, 0.0 }); +} static void GetPermissionState(const v8::FunctionCallbackInfo &info) { diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index b977e5ca..4b0dfb3d 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -141,18 +141,18 @@ static void Constructor(const v8::FunctionCallbackInfo& info) auto texture = alt::ICore::Instance().GetTextureFromDrawable(drawableHash, targetTextureStr); V8_CHECK(texture != nullptr, "Texture not found"); - view = altres->CreateWebView(url, (uint32_t)drawableHash, targetTextureStr); + view = alt::ICore::Instance().CreateWebView(altres, url, (uint32_t)drawableHash, targetTextureStr); V8_CHECK(!view.IsEmpty(), "Interactive WebView cannot be created"); } else if (info.Length() == 2) { V8_ARG_TO_BOOLEAN(2, isOverlayBool); - view = altres->CreateWebView(url, { 0, 0 }, { 0, 0 }, true, isOverlayBool); + view = alt::ICore::Instance().CreateWebView(altres, url, { 0, 0 }, { 0, 0 }, true, isOverlayBool); } else { - view = altres->CreateWebView(url, { 0, 0 }, { 0, 0 }, true, false); + view = alt::ICore::Instance().CreateWebView(altres, url, { 0, 0 }, { 0, 0 }, true, false); } V8_BIND_BASE_OBJECT(view); From 3969010944923f50b0adde6886ae1aeead9f4d36 Mon Sep 17 00:00:00 2001 From: Vektor Date: Tue, 24 Nov 2020 22:10:37 +0100 Subject: [PATCH 120/564] remove abandoned ref counter --- V8ResourceImpl.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index e2405063..3cff068b 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -92,11 +92,6 @@ bool V8ResourceImpl::DeleteEntity(alt::Ref handle) delete it->second; entities.erase(it); - - // BAD, SHOULD ONLY BE DONE FOR ENTITIES - // THAT WAS CREATED FROM JS - resource->RemoveReference(handle); - return true; } From 3eb7538724b8426eac25f28980b0e2335c820f5f Mon Sep 17 00:00:00 2001 From: Vektor Date: Tue, 24 Nov 2020 22:10:53 +0100 Subject: [PATCH 121/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index e64886b3..39690109 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit e64886b39b45d5b3499714fdc177e82b560eeada +Subproject commit 3969010944923f50b0adde6886ae1aeead9f4d36 From 0f87f12b3f470a5d87605bccef326e810439c703 Mon Sep 17 00:00:00 2001 From: Hazard Date: Tue, 24 Nov 2020 22:21:36 +0100 Subject: [PATCH 122/564] Reimplement MapZoomData --- src/bindings/MapZoomData.cpp | 296 +++++++++++++++++------------------ 1 file changed, 148 insertions(+), 148 deletions(-) diff --git a/src/bindings/MapZoomData.cpp b/src/bindings/MapZoomData.cpp index 1d246349..88616f4d 100644 --- a/src/bindings/MapZoomData.cpp +++ b/src/bindings/MapZoomData.cpp @@ -1,208 +1,208 @@ -// #include "../CV8Resource.h" -// #include "../helpers/V8Class.h" +#include "../CV8Resource.h" +#include "../helpers/V8Class.h" -// static void Constructor(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); +extern V8Class v8MapZoomData; -// V8_CHECK(info.IsConstructCall(), "HandlingData constructor is not a function"); -// V8_CHECK(info.Length() == 1, "new HandlingData(...) expects 1 arg"); +static void Constructor(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); -// V8_CHECK(info[0]->IsNumber() || info[0]->IsString(), "zoomDataId must be a number or string"); + V8_CHECK(info.IsConstructCall(), "HandlingData constructor is not a function"); + V8_CHECK(info.Length() == 1, "new HandlingData(...) expects 1 arg"); -// if (info[0]->IsNumber()) -// { -// uint8_t zoomDataId = info[0]->Uint32Value(ctx).ToChecked(); -// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); -// V8_CHECK(data, "zoomData with this id not found"); -// info.This()->SetInternalField(0, info[0]); -// } -// else -// { -// std::string zoomDataAlias = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); -// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataAlias); -// V8_CHECK(data, "zoomData with this id not found"); -// uint8_t id = CMapZoomData::Instance().GetIdFromAlias(zoomDataAlias); -// info.This()->SetInternalField(0, v8::Integer::NewFromUnsigned(isolate, id)); -// } -// } + V8_CHECK(info[0]->IsNumber() || info[0]->IsString(), "zoomDataId must be a number or string"); -// static void Get(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); + if (info[0]->IsNumber()) + { + uint8_t zoomDataId = info[0]->Uint32Value(ctx).ToChecked(); + auto data = alt::ICore::Instance().GetMapData(zoomDataId); + V8_CHECK(data, "zoomData with this id not found"); + info.This()->SetInternalField(0, info[0]); + } + else + { + std::string zoomDataAlias = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + auto data = alt::ICore::Instance().GetMapData(zoomDataAlias); + V8_CHECK(data, "zoomData with this id not found"); + uint8_t id = alt::ICore::Instance().GetMapDataIDFromAlias(zoomDataAlias); + info.This()->SetInternalField(0, v8::Integer::NewFromUnsigned(isolate, id)); + } +} -// V8_CHECK(info.Length() == 1, "MapZoomData.get expects 1 arg"); -// V8_CHECK(info[0]->IsNumber() || info[0]->IsString(), "zoomDataId must be a number or string"); +static void Get(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// static V8Class *mapZoomDataClass = &v8MapZoomData; + V8_CHECK(info.Length() == 1, "MapZoomData.get expects 1 arg"); + V8_CHECK(info[0]->IsNumber() || info[0]->IsString(), "zoomDataId must be a number or string"); -// std::vector> args{ -// info[0]}; + std::vector> args{ + info[0]}; -// info.GetReturnValue().Set(mapZoomDataClass->New(isolate->GetEnteredContext(), args)); -// } + info.GetReturnValue().Set(v8MapZoomData.New(isolate->GetEnteredContext(), args)); +} -// static void ResetAll(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void ResetAll(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// CMapZoomData::Instance().ResetAll(); -// } + alt::ICore::Instance().ResetAllMapData(); +} -// static void fZoomScaleGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void fZoomScaleGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); -// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); -// V8_CHECK(data, "zoom data not found"); + auto data = alt::ICore::Instance().GetMapData(zoomDataId); + V8_CHECK(data, "zoom data not found"); -// info.GetReturnValue().Set(v8::Number::New(isolate, data->fZoomScale)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, data->GetZoomScale())); +} -// static void fZoomScaleSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "fZoomScale must be a number"); +static void fZoomScaleSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "fZoomScale must be a number"); -// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); -// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); -// V8_CHECK(data, "zoom data not found"); + auto data = alt::ICore::Instance().GetMapData(zoomDataId); + V8_CHECK(data, "zoom data not found"); -// data->fZoomScale = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + data->SetZoomScale((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void fZoomSpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void fZoomSpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); -// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); -// V8_CHECK(data, "zoom data not found"); + auto data = alt::ICore::Instance().GetMapData(zoomDataId); + V8_CHECK(data, "zoom data not found"); -// info.GetReturnValue().Set(v8::Number::New(isolate, data->fZoomSpeed)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, data->GetZoomSpeed())); +} -// static void fZoomSpeedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "fZoomSpeed must be a number"); +static void fZoomSpeedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "fZoomSpeed must be a number"); -// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); -// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); -// V8_CHECK(data, "zoom data not found"); + auto data = alt::ICore::Instance().GetMapData(zoomDataId); + V8_CHECK(data, "zoom data not found"); -// data->fZoomSpeed = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + data->SetZoomSpeed((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void fScrollSpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void fScrollSpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); -// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); -// V8_CHECK(data, "zoom data not found"); + auto data = alt::ICore::Instance().GetMapData(zoomDataId); + V8_CHECK(data, "zoom data not found"); -// info.GetReturnValue().Set(v8::Number::New(isolate, data->fScrollSpeed)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, data->GetScrollSpeed())); +} -// static void fScrollSpeedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "fScrollSpeed must be a number"); +static void fScrollSpeedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "fScrollSpeed must be a number"); -// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); -// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); -// V8_CHECK(data, "zoom data not found"); + auto data = alt::ICore::Instance().GetMapData(zoomDataId); + V8_CHECK(data, "zoom data not found"); -// data->fScrollSpeed = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + data->SetScrollSpeed((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void vTilesXGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void vTilesXGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); -// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); -// V8_CHECK(data, "zoom data not found"); + auto data = alt::ICore::Instance().GetMapData(zoomDataId); + V8_CHECK(data, "zoom data not found"); -// info.GetReturnValue().Set(v8::Number::New(isolate, data->vTilesX)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, data->GetTilesCountX())); +} -// static void vTilesXSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "vTilesX must be a number"); +static void vTilesXSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "vTilesX must be a number"); -// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); -// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); -// V8_CHECK(data, "zoom data not found"); + auto data = alt::ICore::Instance().GetMapData(zoomDataId); + V8_CHECK(data, "zoom data not found"); -// data->vTilesX = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + data->SetTilesCountX((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void vTilesYGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); +static void vTilesYGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); -// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); -// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); -// V8_CHECK(data, "zoom data not found"); + auto data = alt::ICore::Instance().GetMapData(zoomDataId); + V8_CHECK(data, "zoom data not found"); -// info.GetReturnValue().Set(v8::Number::New(isolate, data->vTilesY)); -// } + info.GetReturnValue().Set(v8::Number::New(isolate, data->GetTilesCountY())); +} -// static void vTilesYSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// v8::Isolate *isolate = info.GetIsolate(); -// V8_CHECK(val->IsNumber(), "vTilesY must be a number"); +static void vTilesYSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + v8::Isolate *isolate = info.GetIsolate(); + V8_CHECK(val->IsNumber(), "vTilesY must be a number"); -// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); -// ZoomData *data = CMapZoomData::Instance().GetZoomData(zoomDataId); -// V8_CHECK(data, "zoom data not found"); + auto data = alt::ICore::Instance().GetMapData(zoomDataId); + V8_CHECK(data, "zoom data not found"); -// data->vTilesY = (float)val->NumberValue(isolate->GetEnteredContext()).ToChecked(); -// } + data->SetTilesCountY((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); +} -// static void Reset(const v8::FunctionCallbackInfo &info) -// { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); +static void Reset(const v8::FunctionCallbackInfo &info) +{ + v8::Isolate *isolate = v8::Isolate::GetCurrent(); -// alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); -// V8_CHECK(resource, "Invalid resource"); + alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); -// uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); -// CMapZoomData::Instance().Reset(zoomDataId); -// } + alt::ICore::Instance().ResetMapData(zoomDataId); +} -// static V8Class v8mapZoomData( -// "MapZoomData", "", Constructor, [](v8::Local tpl) { -// v8::Isolate *isolate = v8::Isolate::GetCurrent(); +// Perhaps rename or something +extern V8Class v8MapZoomData("MapZoomData", Constructor, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); -// v8::Local proto = tpl->PrototypeTemplate(); + v8::Local proto = tpl->PrototypeTemplate(); -// tpl->InstanceTemplate()->SetInternalFieldCount(1); + tpl->InstanceTemplate()->SetInternalFieldCount(1); -// tpl->Set(isolate, "get", v8::FunctionTemplate::New(isolate, &Get)); -// tpl->Set(isolate, "resetAll", v8::FunctionTemplate::New(isolate, &ResetAll)); + tpl->Set(isolate, "get", v8::FunctionTemplate::New(isolate, &Get)); + tpl->Set(isolate, "resetAll", v8::FunctionTemplate::New(isolate, &ResetAll)); -// V8::SetAccessor(isolate, tpl, "fZoomScale", &fZoomScaleGetter, &fZoomScaleSetter); -// V8::SetAccessor(isolate, tpl, "fZoomSpeed", &fZoomSpeedGetter, &fZoomSpeedSetter); -// V8::SetAccessor(isolate, tpl, "fScrollSpeed", &fScrollSpeedGetter, &fScrollSpeedSetter); -// V8::SetAccessor(isolate, tpl, "vTilesX", &vTilesXGetter, &vTilesXSetter); -// V8::SetAccessor(isolate, tpl, "vTilesY", &vTilesYGetter, &vTilesYSetter); -// V8::SetMethod(isolate, tpl, "reset", &Reset); -// }, -// false); + V8::SetAccessor(isolate, tpl, "fZoomScale", &fZoomScaleGetter, &fZoomScaleSetter); + V8::SetAccessor(isolate, tpl, "fZoomSpeed", &fZoomSpeedGetter, &fZoomSpeedSetter); + V8::SetAccessor(isolate, tpl, "fScrollSpeed", &fScrollSpeedGetter, &fScrollSpeedSetter); + V8::SetAccessor(isolate, tpl, "vTilesX", &vTilesXGetter, &vTilesXSetter); + V8::SetAccessor(isolate, tpl, "vTilesY", &vTilesYGetter, &vTilesYSetter); + V8::SetMethod(isolate, tpl, "reset", &Reset); + }, + false); From f5a4b109debdf399b1dedeb4a078c42981b15dc7 Mon Sep 17 00:00:00 2001 From: Hazard Date: Tue, 24 Nov 2020 22:24:52 +0100 Subject: [PATCH 123/564] Fix MapZoomData --- src/bindings/MapZoomData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/MapZoomData.cpp b/src/bindings/MapZoomData.cpp index 88616f4d..d5232d33 100644 --- a/src/bindings/MapZoomData.cpp +++ b/src/bindings/MapZoomData.cpp @@ -188,7 +188,7 @@ static void Reset(const v8::FunctionCallbackInfo &info) } // Perhaps rename or something -extern V8Class v8MapZoomData("MapZoomData", Constructor, [](v8::Local tpl) { +extern V8Class v8MapZoomData("MapZoomData", &Constructor, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local proto = tpl->PrototypeTemplate(); From 7888880404200e13a1439c93762d43657a976a45 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 24 Nov 2020 22:28:48 +0100 Subject: [PATCH 124/564] Added dynamic import --- src/CV8Resource.cpp | 4 +++ src/CV8Resource.h | 5 ++++ src/CV8ScriptRuntime.cpp | 59 ++++++++++++++++++++++++++++++++++++++-- src/CV8ScriptRuntime.h | 38 ++++++++++++++++++++++++++ src/helpers | 2 +- 5 files changed, 104 insertions(+), 4 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index cb172b0c..8c13a734 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -235,6 +235,10 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) case alt::CEvent::Type::CONNECTION_COMPLETE: { handlers = GetLocalHandlers("connectionComplete"); + CV8ScriptRuntime& runtime = CV8ScriptRuntime::Instance(); + runtime._allResourcesLoaded = true; + for (auto result : runtime.onAllResourcesLoadedCallbacks) result.call(); + runtime.onAllResourcesLoadedCallbacks.empty(); break; } case alt::CEvent::Type::DISCONNECT_EVENT: diff --git a/src/CV8Resource.h b/src/CV8Resource.h index 2f2d64ab..a8143108 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -85,6 +85,11 @@ class CV8ResourceImpl : public V8ResourceImpl bool IsValidModule(const std::string &name); std::deque GetModuleKeys(const std::string &name); std::string GetModulePath(v8::Local moduleHandle); + v8::Local GetModuleFromName(const std::string& name, v8::Isolate *isolate) { + auto found = modules.find(name); + auto module = found->second.Get(isolate); + return module; + }; v8::MaybeLocal Require(const std::string &name); v8::MaybeLocal ResolveFile(const std::string &name, v8::Local referrer); diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index d8dc5ee7..c8400911 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -4,8 +4,11 @@ #include "inspector/CV8InspectorChannel.h" #include "helpers/V8Module.h" +v8::Persistent host_import_module_dynamically_callback; + CV8ScriptRuntime::CV8ScriptRuntime() { + CV8ScriptRuntime::SetInstance(this); platform = v8::platform::NewDefaultPlatform(); v8::V8::InitializePlatform(platform.get()); v8::V8::Initialize(); @@ -54,10 +57,54 @@ CV8ScriptRuntime::CV8ScriptRuntime() } }); - /*isolate->SetHostImportModuleDynamicallyCallback([](v8::Local context, v8::Local referrer, v8::Local specifier) { + static std::list> promises; + isolate->SetHostImportModuleDynamicallyCallback([](v8::Local context, v8::Local referrer, v8::Local specifier) + { + v8::Isolate* isolate = context->GetIsolate(); + auto promise = v8::Promise::Resolver::New(context); + auto& persistent = promises.emplace_back(v8::UniquePersistent(isolate, promise.ToLocalChecked())); + + auto result = CV8ScriptRuntime::ResourceLoadResult(context, referrer, specifier, &persistent, + [](v8::Local context, v8::Local referrer, v8::Local specifier, const void* original) + { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + auto persistent = (v8::UniquePersistent*)original; + auto resolver = persistent->Get(isolate); + auto ctx = context; + + v8::Context::Scope ctxscope(ctx); + v8::String::Utf8Value utfValue(isolate, specifier); + std::string name(*utfValue); + V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); - return v8::MaybeLocal(); - });*/ + auto module = static_cast(resource)->GetModuleFromName(name, isolate); + auto resolved = CV8ScriptRuntime::ResolveModule(ctx, specifier, module); + v8::Local outModule; + + if (resolved.IsEmpty() || !resolved.ToLocal(&outModule)) + resolver->Reject(ctx, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); + else + { + Log::Info << std::to_string(outModule->GetStatus()) << Log::Endl; + if (outModule->GetStatus() != v8::Module::Status::kInstantiated) { + outModule->InstantiateModule(ctx, CV8ScriptRuntime::ResolveModule); + } + Log::Info << std::to_string(outModule->GetStatus()) << Log::Endl; + outModule->Evaluate(ctx); + Log::Info << std::to_string(outModule->GetStatus()) << Log::Endl; + resolver->Resolve(ctx, outModule->GetModuleNamespace()); + Log::Info << "1" << Log::Endl; + //resolver->Resolve(ctx, v8::String::NewFromUtf8(isolate, "Fuck").ToLocalChecked()); + } + promises.remove(*persistent); + }); + CV8ScriptRuntime::Instance().OnAllResourcesLoaded(result); + + return v8::MaybeLocal(promise.ToLocalChecked()->GetPromise()); + }); /*{ v8::Locker locker(isolate); @@ -84,3 +131,9 @@ CV8ScriptRuntime::CV8ScriptRuntime() V8Module::Add({altModule, nativesModule}); } } + +void CV8ScriptRuntime::OnAllResourcesLoaded(CV8ScriptRuntime::ResourceLoadResult result) +{ + if (_allResourcesLoaded) result.call(); + else onAllResourcesLoadedCallbacks.emplace_back(result); +} \ No newline at end of file diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index c7b3c688..fe65eb17 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -19,8 +19,16 @@ class CV8ScriptRuntime : public alt::IScriptRuntime std::unique_ptr inspectorChannel; std::unique_ptr inspector; std::unique_ptr inspectorSession; + static CV8ScriptRuntime *&_instance() + { + static CV8ScriptRuntime *inst = nullptr; + return inst; + } public: + static CV8ScriptRuntime &Instance() { return *_instance(); } + static void SetInstance(CV8ScriptRuntime* runtime) { _instance() = runtime; }; + CV8ScriptRuntime(); v8::Isolate *GetIsolate() const { return isolate; } @@ -126,4 +134,34 @@ class CV8ScriptRuntime : public alt::IScriptRuntime return result; } }; + + using ResourcesLoadedCallback = void (*)(v8::Local context, v8::Local referrer, v8::Local specifier, const void* promise); + + class ResourceLoadResult + { + public: + ResourceLoadResult(v8::Local context, v8::Local referrer, v8::Local specifier, const void* promise, ResourcesLoadedCallback cb) + { + _context = context; + _referrer = referrer; + _specifier = specifier; + _promise = promise; + _callback = cb; + } + + v8::Local _context; + v8::Local _referrer; + v8::Local _specifier; + ResourcesLoadedCallback _callback; + const void* _promise; + + void call() + { + _callback(_context, _referrer, _specifier, &_promise); + } + }; + + std::list onAllResourcesLoadedCallbacks; + void OnAllResourcesLoaded(ResourceLoadResult result); + bool _allResourcesLoaded = false; }; \ No newline at end of file diff --git a/src/helpers b/src/helpers index e64886b3..dc505fe2 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit e64886b39b45d5b3499714fdc177e82b560eeada +Subproject commit dc505fe2325faf197df17fa7063940bf0c93a6be From bbce51505a8956a72f6e3db070d6eb64c9572630 Mon Sep 17 00:00:00 2001 From: Hazard Date: Tue, 24 Nov 2020 22:33:39 +0100 Subject: [PATCH 125/564] Fix again --- src/bindings/MapZoomData.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/bindings/MapZoomData.cpp b/src/bindings/MapZoomData.cpp index d5232d33..e9aded71 100644 --- a/src/bindings/MapZoomData.cpp +++ b/src/bindings/MapZoomData.cpp @@ -3,7 +3,7 @@ extern V8Class v8MapZoomData; -static void Constructor(const v8::FunctionCallbackInfo &info) +static void Constructor(const v8::FunctionCallbackInfo& info) { v8::Isolate *isolate = info.GetIsolate(); auto ctx = isolate->GetEnteredContext(); @@ -188,7 +188,7 @@ static void Reset(const v8::FunctionCallbackInfo &info) } // Perhaps rename or something -extern V8Class v8MapZoomData("MapZoomData", &Constructor, [](v8::Local tpl) { +extern V8Class v8MapZoomData("MapZoomData", Constructor, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local proto = tpl->PrototypeTemplate(); @@ -204,5 +204,4 @@ extern V8Class v8MapZoomData("MapZoomData", &Constructor, [](v8::Local Date: Tue, 24 Nov 2020 23:04:56 +0100 Subject: [PATCH 126/564] reenable setRotationVelocity --- src/bindings/Main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index ec2b7ec6..69253d4a 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -767,7 +767,7 @@ extern V8Module altModule( // V8Helpers::RegisterFunc(exports, "getEntityMemoryByID", &GetEntityMemoryByID); - // V8Helpers::RegisterFunc(exports, "setRotationVelocity", &SetAngularVelocity); + V8Helpers::RegisterFunc(exports, "setRotationVelocity", &SetAngularVelocity); // V8Helpers::RegisterFunc(exports, "setAngularVelocity", &SetAngularVelocity); V8Helpers::RegisterFunc(exports, "isInStreamerMode", &IsInStreamerMode); From 6fcdfa1bd7fb1bda2dc651cf8307cb61489c3a6e Mon Sep 17 00:00:00 2001 From: Vektor Date: Tue, 24 Nov 2020 23:32:10 +0100 Subject: [PATCH 127/564] fix cursor & controls --- src/bindings/Main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 69253d4a..587bc26d 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -59,7 +59,7 @@ static void ToggleGameControls(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_BOOLEAN(1, state); - alt::ICore::Instance().ToggleGameControls(state); + resource->ToggleGameControls(state); } static void ToggleVoiceControls(const v8::FunctionCallbackInfo &info) @@ -81,7 +81,7 @@ static void ShowCursor(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_BOOLEAN(1, state); - if (!alt::ICore::Instance().ToggleCursor(state)) + if (!resource->ToggleCursor(state)) { if (alt::ICore::Instance().IsDebug()) { @@ -199,7 +199,7 @@ static void AddGxtText(const v8::FunctionCallbackInfo &info) V8_ARG_TO_STRING(1, key); V8_ARG_TO_STRING(2, textValue); - alt::ICore::Instance().AddGxtText(ICore::Instance().Hash(key), textValue.ToString()); + resource->AddGxtText(ICore::Instance().Hash(key), textValue.ToString()); } static void RemoveGxtText(const v8::FunctionCallbackInfo &info) @@ -209,7 +209,7 @@ static void RemoveGxtText(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, key); - alt::ICore::Instance().RemoveGxtText(ICore::Instance().Hash(key)); + resource->RemoveGxtText(ICore::Instance().Hash(key)); } static void GetGxtText(const v8::FunctionCallbackInfo &info) @@ -219,7 +219,7 @@ static void GetGxtText(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, key); - V8_RETURN_STRING(alt::ICore::Instance().GetGxtText(ICore::Instance().Hash(key)).c_str()); + V8_RETURN_STRING(resource->GetGxtText(ICore::Instance().Hash(key)).c_str()); } static void GetMsPerGameMinute(const v8::FunctionCallbackInfo &info) From 0d66caa36d9ca6124f46e8c73d1eb0cd19a7fc0d Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 25 Nov 2020 00:17:16 +0100 Subject: [PATCH 128/564] remove unused func --- V8ResourceImpl.cpp | 14 -------------- V8ResourceImpl.h | 1 - 2 files changed, 15 deletions(-) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 3cff068b..fa3723cc 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -81,20 +81,6 @@ void V8ResourceImpl::OnTick() promiseRejections.ProcessQueue(this); } -bool V8ResourceImpl::DeleteEntity(alt::Ref handle) -{ - auto it = entities.find(handle.Get()); - if(it == entities.end()) - { - Log::Error << "[JS] Attempted to delete invalid object" << Log::Endl; - return false; - } - - delete it->second; - entities.erase(it); - return true; -} - void V8ResourceImpl::BindEntity(v8::Local val, alt::IBaseObject *handle) { V8Entity *ent = new V8Entity(GetContext(), V8Entity::GetClass(handle), val, handle); diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index cba30865..6fbd4a04 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -116,7 +116,6 @@ class V8ResourceImpl : public alt::IResource::Impl return ent; } - bool DeleteEntity(alt::Ref handle); void BindEntity(v8::Local val, alt::IBaseObject *handle); V8Entity *GetOrCreateEntity(alt::IBaseObject *handle, const char *className = "") From 026dca32411b867a1cb03fc13979fc0bc0ef81a6 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 25 Nov 2020 00:17:46 +0100 Subject: [PATCH 129/564] fix baseobject destroy --- src/bindings/Blip.cpp | 9 --------- src/bindings/Checkpoint.cpp | 10 ---------- src/helpers | 2 +- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index 76ac2d16..d4f2cb50 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -570,13 +570,6 @@ static void Fade(const v8::FunctionCallbackInfo& info) blip->Fade(opacity, duration); } -static void Delete(const v8::FunctionCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_CHECK(resource->DeleteEntity(blip), "Could not delete blip"); -} - extern V8Class v8WorldObject; extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local tpl){ v8::Isolate* isolate = v8::Isolate::GetCurrent(); @@ -614,8 +607,6 @@ extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local tpl) { diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index 75d9f41a..d7370caa 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -137,13 +137,6 @@ static void IsPointIn(const v8::FunctionCallbackInfo& info) V8_RETURN_BOOLEAN(cp->IsPointIn({ x, y, z})); } -static void Delete(const v8::FunctionCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); - V8_CHECK(resource->DeleteEntity(cp), "Could not delete blip"); -} - extern V8Class v8WorldObject; extern V8Class v8Checkpoint("Checkpoint", v8WorldObject, Constructor, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); @@ -156,7 +149,4 @@ extern V8Class v8Checkpoint("Checkpoint", v8WorldObject, Constructor, [](v8::Loc V8::SetMethod(isolate, tpl, "isEntityIn", &IsEntityIn); V8::SetMethod(isolate, tpl, "isPointIn", &IsPointIn); - - V8::SetMethod(isolate, tpl, "delete", &Delete); - V8::SetMethod(isolate, tpl, "destroy", &Delete); }); \ No newline at end of file diff --git a/src/helpers b/src/helpers index 39690109..0d66caa3 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 3969010944923f50b0adde6886ae1aeead9f4d36 +Subproject commit 0d66caa36d9ca6124f46e8c73d1eb0cd19a7fc0d From 5ef615be1eaa59516a85575a28567faf493318bc Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 25 Nov 2020 02:01:53 +0100 Subject: [PATCH 130/564] Reimplement MemoryBuffer --- src/bindings/MemoryBuffer.cpp | 378 +++++++++++++++++----------------- 1 file changed, 189 insertions(+), 189 deletions(-) diff --git a/src/bindings/MemoryBuffer.cpp b/src/bindings/MemoryBuffer.cpp index 599daa68..725138bd 100644 --- a/src/bindings/MemoryBuffer.cpp +++ b/src/bindings/MemoryBuffer.cpp @@ -1,30 +1,29 @@ -// #include "../CV8Resource.h" -// #include "../helpers/V8Class.h" -// #include "memory/CMemoryCacheStorage.h" -// #include "core/CGame.h" - -// //static void weakCallbackForObjectHolder(const v8::WeakCallbackInfo& data) { -// // uint8_t* memory = (uint8_t*)data.GetInternalField(0); -// // delete data.GetParameter(); -// //} - -// //static void WeakCallback(v8::WeakCallbackData data) -// //{ -// // Local val = data.GetValue(); -// // int* ptr = retinterpret_cast(val->GetAlignedPointerFromINternalField(0)); -// // delete ptr; -// // fprintf(stdout, "Deleted internal object!\n"); -// //} - -// static void Constructor(const v8::FunctionCallbackInfo& info) -// { -// v8::Isolate* isolate = info.GetIsolate(); -// auto ctx = isolate->GetEnteredContext(); - -// V8_CHECK(info.IsConstructCall(), "MemoryBuffer constructor is not a function"); -// V8_CHECK(info.Length() == 1, "new MemoryBuffer(...) expects 1 arg"); - +#include "../CV8Resource.h" +#include "../helpers/V8Class.h" + +//static void weakCallbackForObjectHolder(const v8::WeakCallbackInfo& data) { +// uint8_t* memory = (uint8_t*)data.GetInternalField(0); +// delete data.GetParameter(); +//} + +//static void WeakCallback(v8::WeakCallbackData data) +//{ +// Local val = data.GetValue(); +// int* ptr = retinterpret_cast(val->GetAlignedPointerFromINternalField(0)); +// delete ptr; +// fprintf(stdout, "Deleted internal object!\n"); +//} + +static void Constructor(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = info.GetIsolate(); + auto ctx = isolate->GetEnteredContext(); + + V8_CHECK(info.IsConstructCall(), "MemoryBuffer constructor is not a function"); + V8_CHECK(info.Length() == 1, "new MemoryBuffer(...) expects 1 arg"); + + // Ask alt:V to add pattern searching to C++ SDK if you want this available // if(info[0]->IsString()) // { // #ifdef NDEBUG @@ -36,166 +35,167 @@ // info.This()->SetAlignedPointerInInternalField(0, mem.GetAddress()); // info.This()->SetInternalField(1, v8::Integer::NewFromUnsigned(isolate, UINT32_MAX)); // } -// else { -// V8_CHECK(info[0]->IsNumber(), "size must be a number or a string pattern"); -// uint32_t size = info[0]->Uint32Value(ctx).ToChecked(); -// if(size == 0) -// { -// info.This()->SetAlignedPointerInInternalField(0, nullptr); -// info.This()->SetInternalField(1, v8::Integer::NewFromUnsigned(isolate, 0)); -// return; -// } -// V8_CHECK(size <= 1024, "You can't allocate > 1KB"); - -// uint8_t* allocatedMemory = new uint8_t[size]; -// memset(allocatedMemory, 0, size); -// info.This()->SetAlignedPointerInInternalField(0, allocatedMemory); -// info.This()->SetInternalField(1, v8::Integer::NewFromUnsigned(isolate, size)); -// } - -// /*v8::UniquePersistent persistent(isolate, info.This()); -// persistent.SetWeak(info.This(), weakCallbackForObjectHolder, v8::WeakCallbackType::kInternalFields);*/ -// } - -// static void FreeBuffer(const v8::FunctionCallbackInfo& info) -// { -// v8::Isolate* isolate = v8::Isolate::GetCurrent(); - -// V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "Invalid resource"); - -// uint8_t* memory = (uint8_t*)info.This()->GetAlignedPointerFromInternalField(0); -// if (memory != nullptr) -// { -// delete memory; -// info.This()->SetAlignedPointerInInternalField(0, nullptr); -// info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); -// return; -// } -// info.GetReturnValue().Set(v8::Boolean::New(isolate, false)); -// } - -// static void GetAddress(const v8::FunctionCallbackInfo& info) -// { -// v8::Isolate* isolate = v8::Isolate::GetCurrent(); - -// #ifdef NDEBUG -// V8_CHECK(CGame::Instance().IsDebug() && IsDevOrInternalBranch(), "must be in debug mode and dev branch to get the address of memory buffers"); -// #endif - -// V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "Invalid resource"); - -// uintptr_t memory = (uintptr_t)info.This()->GetAlignedPointerFromInternalField(0); -// info.GetReturnValue().Set(v8::BigInt::New(isolate, memory)); -// } - -// template -// static void GetDataOfType(const v8::FunctionCallbackInfo& info) -// { -// v8::Isolate* isolate = v8::Isolate::GetCurrent(); -// auto ctx = isolate->GetEnteredContext(); - -// V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); -// V8_CHECK(resource, "Invalid resource"); - -// bool isString = false; -// if (std::is_same_v) -// { -// V8_CHECK(info.Length() == 2, "2 args expected"); -// isString = true; -// } -// else -// { -// V8_CHECK(info.Length() == 1, "1 arg expected"); -// } - -// V8_CHECK(info[0]->IsNumber(), "offset must be a number"); -// uint32_t offset = info[0]->Uint32Value(ctx).ToChecked(); - -// uint32_t strLength = 0; - -// if (isString) -// strLength = info[1]->Uint32Value(ctx).ToChecked(); - -// uint8_t* memory = (uint8_t*)info.This()->GetAlignedPointerFromInternalField(0); -// uint16_t size = info.This()->GetInternalField(1)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); -// if (memory == nullptr || size == 0) -// { -// info.GetReturnValue().Set(v8::Null(isolate)); -// return; -// } - -// #ifdef NDEBUG -// if(!(CGame::Instance().IsDebug() && std::string(ALTV_BRANCH)=="dev")) -// #endif -// { -// if (isString) -// { -// V8_CHECK((offset + strLength) <= size, "Offset is out of bounds"); -// } -// else -// { -// V8_CHECK((offset + sizeof(T)) <= size, "Offset is out of bounds"); -// } -// } - -// if (!isString) -// { -// if (std::is_same_v || std::is_same_v || std::is_same_v) -// { -// info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, *(uint32_t*)((uintptr_t)memory + offset))); -// return; -// } -// else if (std::is_same_v) -// { -// info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(isolate, *(uint64_t*)((uintptr_t)memory + offset))); -// return; -// } -// else if (std::is_same_v || std::is_same_v || std::is_same_v) -// { -// info.GetReturnValue().Set(v8::Integer::New(isolate, *(int32_t*)((uintptr_t)memory + offset))); -// return; -// } -// else if (std::is_same_v) -// { -// info.GetReturnValue().Set(v8::BigInt::New(isolate, *(int64_t*)((uintptr_t)memory + offset))); -// return; -// } -// else if (std::is_same_v || std::is_same_v) -// { -// info.GetReturnValue().Set(v8::Number::New(isolate, *(double*)((uintptr_t)memory + offset))); -// return; -// } -// } -// else -// { -// char* newString = new char[strLength + 1]; -// memcpy_s(newString, strLength + 1, (void*)((uintptr_t)memory + offset), strLength); -// newString[strLength] = 0; -// info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, newString).ToLocalChecked()); -// delete newString; -// } -// } - -// V8Class v8MemoryBuffer("MemoryBuffer", "", Constructor, [](v8::Local tpl) { -// v8::Isolate* isolate = v8::Isolate::GetCurrent(); - -// v8::Local proto = tpl->PrototypeTemplate(); - -// tpl->InstanceTemplate()->SetInternalFieldCount(2); - -// proto->Set(isolate, "free", v8::FunctionTemplate::New(isolate, &FreeBuffer)); -// proto->Set(isolate, "address", v8::FunctionTemplate::New(isolate, &GetAddress)); -// proto->Set(isolate, "ubyte", v8::FunctionTemplate::New(isolate, &GetDataOfType)); -// proto->Set(isolate, "ushort", v8::FunctionTemplate::New(isolate, &GetDataOfType)); -// proto->Set(isolate, "uint", v8::FunctionTemplate::New(isolate, &GetDataOfType)); -// proto->Set(isolate, "ulong", v8::FunctionTemplate::New(isolate, &GetDataOfType)); -// proto->Set(isolate, "byte", v8::FunctionTemplate::New(isolate, &GetDataOfType)); -// proto->Set(isolate, "short", v8::FunctionTemplate::New(isolate, &GetDataOfType)); -// proto->Set(isolate, "int", v8::FunctionTemplate::New(isolate, &GetDataOfType)); -// proto->Set(isolate, "long", v8::FunctionTemplate::New(isolate, &GetDataOfType)); -// proto->Set(isolate, "float", v8::FunctionTemplate::New(isolate, &GetDataOfType)); -// proto->Set(isolate, "double", v8::FunctionTemplate::New(isolate, &GetDataOfType)); -// proto->Set(isolate, "string", v8::FunctionTemplate::New(isolate, &GetDataOfType)); -// }, false); +// else + { + V8_CHECK(info[0]->IsNumber(), "size must be a number or a string pattern"); + uint32_t size = info[0]->Uint32Value(ctx).ToChecked(); + if(size == 0) + { + info.This()->SetAlignedPointerInInternalField(0, nullptr); + info.This()->SetInternalField(1, v8::Integer::NewFromUnsigned(isolate, 0)); + return; + } + V8_CHECK(size <= 1024, "You can't allocate > 1KB"); + + uint8_t* allocatedMemory = new uint8_t[size]; + memset(allocatedMemory, 0, size); + info.This()->SetAlignedPointerInInternalField(0, allocatedMemory); + info.This()->SetInternalField(1, v8::Integer::NewFromUnsigned(isolate, size)); + } + + /*v8::UniquePersistent persistent(isolate, info.This()); + persistent.SetWeak(info.This(), weakCallbackForObjectHolder, v8::WeakCallbackType::kInternalFields);*/ +} + +static void FreeBuffer(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + uint8_t* memory = (uint8_t*)info.This()->GetAlignedPointerFromInternalField(0); + if (memory != nullptr) + { + delete memory; + info.This()->SetAlignedPointerInInternalField(0, nullptr); + info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + return; + } + info.GetReturnValue().Set(v8::Boolean::New(isolate, false)); +} + +static void GetAddress(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + +#ifdef NDEBUG + V8_CHECK(CGame::Instance().IsDebug() && IsDevOrInternalBranch(), "must be in debug mode and dev branch to get the address of memory buffers"); +#endif + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + uintptr_t memory = (uintptr_t)info.This()->GetAlignedPointerFromInternalField(0); + info.GetReturnValue().Set(v8::BigInt::New(isolate, memory)); +} + +template +static void GetDataOfType(const v8::FunctionCallbackInfo& info) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + auto ctx = isolate->GetEnteredContext(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "Invalid resource"); + + bool isString = false; + if (std::is_same_v) + { + V8_CHECK(info.Length() == 2, "2 args expected"); + isString = true; + } + else + { + V8_CHECK(info.Length() == 1, "1 arg expected"); + } + + V8_CHECK(info[0]->IsNumber(), "offset must be a number"); + uint32_t offset = info[0]->Uint32Value(ctx).ToChecked(); + + uint32_t strLength = 0; + + if (isString) + strLength = info[1]->Uint32Value(ctx).ToChecked(); + + uint8_t* memory = (uint8_t*)info.This()->GetAlignedPointerFromInternalField(0); + uint16_t size = info.This()->GetInternalField(1)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + if (memory == nullptr || size == 0) + { + info.GetReturnValue().Set(v8::Null(isolate)); + return; + } + +#ifdef NDEBUG + if(!(CGame::Instance().IsDebug() && std::string(ALTV_BRANCH)=="dev")) +#endif + { + if (isString) + { + V8_CHECK((offset + strLength) <= size, "Offset is out of bounds"); + } + else + { + V8_CHECK((offset + sizeof(T)) <= size, "Offset is out of bounds"); + } + } + + if (!isString) + { + if (std::is_same_v || std::is_same_v || std::is_same_v) + { + info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, *(uint32_t*)((uintptr_t)memory + offset))); + return; + } + else if (std::is_same_v) + { + info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(isolate, *(uint64_t*)((uintptr_t)memory + offset))); + return; + } + else if (std::is_same_v || std::is_same_v || std::is_same_v) + { + info.GetReturnValue().Set(v8::Integer::New(isolate, *(int32_t*)((uintptr_t)memory + offset))); + return; + } + else if (std::is_same_v) + { + info.GetReturnValue().Set(v8::BigInt::New(isolate, *(int64_t*)((uintptr_t)memory + offset))); + return; + } + else if (std::is_same_v || std::is_same_v) + { + info.GetReturnValue().Set(v8::Number::New(isolate, *(double*)((uintptr_t)memory + offset))); + return; + } + } + else + { + char* newString = new char[strLength + 1]; + memcpy_s(newString, strLength + 1, (void*)((uintptr_t)memory + offset), strLength); + newString[strLength] = 0; + info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, newString).ToLocalChecked()); + delete newString; + } +} + +extern V8Class v8MemoryBuffer("MemoryBuffer", Constructor, [](v8::Local tpl) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + v8::Local proto = tpl->PrototypeTemplate(); + + tpl->InstanceTemplate()->SetInternalFieldCount(2); + + proto->Set(isolate, "free", v8::FunctionTemplate::New(isolate, &FreeBuffer)); + proto->Set(isolate, "address", v8::FunctionTemplate::New(isolate, &GetAddress)); + proto->Set(isolate, "ubyte", v8::FunctionTemplate::New(isolate, &GetDataOfType)); + proto->Set(isolate, "ushort", v8::FunctionTemplate::New(isolate, &GetDataOfType)); + proto->Set(isolate, "uint", v8::FunctionTemplate::New(isolate, &GetDataOfType)); + proto->Set(isolate, "ulong", v8::FunctionTemplate::New(isolate, &GetDataOfType)); + proto->Set(isolate, "byte", v8::FunctionTemplate::New(isolate, &GetDataOfType)); + proto->Set(isolate, "short", v8::FunctionTemplate::New(isolate, &GetDataOfType)); + proto->Set(isolate, "int", v8::FunctionTemplate::New(isolate, &GetDataOfType)); + proto->Set(isolate, "long", v8::FunctionTemplate::New(isolate, &GetDataOfType)); + proto->Set(isolate, "float", v8::FunctionTemplate::New(isolate, &GetDataOfType)); + proto->Set(isolate, "double", v8::FunctionTemplate::New(isolate, &GetDataOfType)); + proto->Set(isolate, "string", v8::FunctionTemplate::New(isolate, &GetDataOfType)); +}); From b580b01e36a1cbb43c610f79aedc35d11ed01543 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 25 Nov 2020 12:20:34 +0100 Subject: [PATCH 131/564] fix memorybuffer build --- src/bindings/MemoryBuffer.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/bindings/MemoryBuffer.cpp b/src/bindings/MemoryBuffer.cpp index 725138bd..a923503d 100644 --- a/src/bindings/MemoryBuffer.cpp +++ b/src/bindings/MemoryBuffer.cpp @@ -79,10 +79,6 @@ static void GetAddress(const v8::FunctionCallbackInfo& info) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); -#ifdef NDEBUG - V8_CHECK(CGame::Instance().IsDebug() && IsDevOrInternalBranch(), "must be in debug mode and dev branch to get the address of memory buffers"); -#endif - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); V8_CHECK(resource, "Invalid resource"); @@ -126,9 +122,6 @@ static void GetDataOfType(const v8::FunctionCallbackInfo& info) return; } -#ifdef NDEBUG - if(!(CGame::Instance().IsDebug() && std::string(ALTV_BRANCH)=="dev")) -#endif { if (isString) { From e482b1dc334df33a6c50de8693cd59fb7a4d88e3 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 25 Nov 2020 14:03:57 +0100 Subject: [PATCH 132/564] Refactor and debug logs --- src/CV8ScriptRuntime.cpp | 39 +++++++++++++++++++++------------------ src/CV8ScriptRuntime.h | 13 +++++++++---- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index c8400911..0c8ff21b 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -62,9 +62,9 @@ CV8ScriptRuntime::CV8ScriptRuntime() { v8::Isolate* isolate = context->GetIsolate(); auto promise = v8::Promise::Resolver::New(context); - auto& persistent = promises.emplace_back(v8::UniquePersistent(isolate, promise.ToLocalChecked())); + auto &persistent = promises.emplace_back(v8::UniquePersistent(isolate, promise.ToLocalChecked())); - auto result = CV8ScriptRuntime::ResourceLoadResult(context, referrer, specifier, &persistent, + auto result = CV8ScriptRuntime::ResourcesLoadedResult(context, referrer, specifier, &persistent, [](v8::Local context, v8::Local referrer, v8::Local specifier, const void* original) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); @@ -81,23 +81,32 @@ CV8ScriptRuntime::CV8ScriptRuntime() V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); auto module = static_cast(resource)->GetModuleFromName(name, isolate); + if(module.IsEmpty()) + resolver->Reject(ctx, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); auto resolved = CV8ScriptRuntime::ResolveModule(ctx, specifier, module); + Log::Info << "Resolved" << Log::Endl; v8::Local outModule; - if (resolved.IsEmpty() || !resolved.ToLocal(&outModule)) + if (resolved.IsEmpty() || !resolved.ToLocal(&outModule)) { + Log::Info << "FuckNo" << Log::Endl; resolver->Reject(ctx, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); + Log::Info << "Fuck" << Log::Endl; + } else { - Log::Info << std::to_string(outModule->GetStatus()) << Log::Endl; - if (outModule->GetStatus() != v8::Module::Status::kInstantiated) { + Log::Info << "Status: " << std::to_string(outModule->GetStatus()) << Log::Endl; + if (outModule->GetStatus() != v8::Module::Status::kInstantiated) outModule->InstantiateModule(ctx, CV8ScriptRuntime::ResolveModule); - } - Log::Info << std::to_string(outModule->GetStatus()) << Log::Endl; - outModule->Evaluate(ctx); - Log::Info << std::to_string(outModule->GetStatus()) << Log::Endl; - resolver->Resolve(ctx, outModule->GetModuleNamespace()); - Log::Info << "1" << Log::Endl; - //resolver->Resolve(ctx, v8::String::NewFromUtf8(isolate, "Fuck").ToLocalChecked()); + Log::Info << "Status2: " << std::to_string(outModule->GetStatus()) << Log::Endl; + if (outModule->GetStatus() != v8::Module::Status::kEvaluated) + outModule->Evaluate(ctx); + Log::Info << "Status3: " << std::to_string(outModule->GetStatus()) << Log::Endl; + //resolver->Resolve(ctx, outModule->GetModuleNamespace()); + Log::Info << "Ctx: " << std::to_string(ctx.IsEmpty()) << Log::Endl; + Log::Info << "Isolate: " << std::to_string(isolate == nullptr) << Log::Endl; + auto str = v8::String::NewFromUtf8(isolate, "Fuck").ToLocalChecked(); + Log::Info << "test" << Log::Endl; + resolver->Resolve(ctx, str); } promises.remove(*persistent); }); @@ -131,9 +140,3 @@ CV8ScriptRuntime::CV8ScriptRuntime() V8Module::Add({altModule, nativesModule}); } } - -void CV8ScriptRuntime::OnAllResourcesLoaded(CV8ScriptRuntime::ResourceLoadResult result) -{ - if (_allResourcesLoaded) result.call(); - else onAllResourcesLoadedCallbacks.emplace_back(result); -} \ No newline at end of file diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index fe65eb17..4f7aa8a8 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -137,10 +137,10 @@ class CV8ScriptRuntime : public alt::IScriptRuntime using ResourcesLoadedCallback = void (*)(v8::Local context, v8::Local referrer, v8::Local specifier, const void* promise); - class ResourceLoadResult + class ResourcesLoadedResult { public: - ResourceLoadResult(v8::Local context, v8::Local referrer, v8::Local specifier, const void* promise, ResourcesLoadedCallback cb) + ResourcesLoadedResult(v8::Local context, v8::Local referrer, v8::Local specifier, const void* promise, ResourcesLoadedCallback cb) { _context = context; _referrer = referrer; @@ -157,11 +157,16 @@ class CV8ScriptRuntime : public alt::IScriptRuntime void call() { + if (&_promise == nullptr) return; _callback(_context, _referrer, _specifier, &_promise); } }; - std::list onAllResourcesLoadedCallbacks; - void OnAllResourcesLoaded(ResourceLoadResult result); + std::list onAllResourcesLoadedCallbacks; + void OnAllResourcesLoaded(ResourcesLoadedResult result) + { + if (_allResourcesLoaded) result.call(); + else onAllResourcesLoadedCallbacks.emplace_back(result); + }; bool _allResourcesLoaded = false; }; \ No newline at end of file From 2c2c17bfa52ff8919e1dca9bd2325b47e522adcb Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 25 Nov 2020 22:28:58 +0100 Subject: [PATCH 133/564] fix valid getter --- bindings/BaseObject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/BaseObject.cpp b/bindings/BaseObject.cpp index b1e96689..4dc76303 100644 --- a/bindings/BaseObject.cpp +++ b/bindings/BaseObject.cpp @@ -17,9 +17,9 @@ static void ValidGetter(v8::Local, const v8::PropertyCallbackInfo &info) From a1e4443e3cf68c92cba42a8798430fd4eb3e3718 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 25 Nov 2020 22:29:18 +0100 Subject: [PATCH 134/564] fix valid getter --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 0d66caa3..2c2c17bf 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 0d66caa36d9ca6124f46e8c73d1eb0cd19a7fc0d +Subproject commit 2c2c17bfa52ff8919e1dca9bd2325b47e522adcb From 1da29ddcd902202b945902e403e5d1c47c6b37e7 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 25 Nov 2020 23:10:05 +0100 Subject: [PATCH 135/564] fix build for different v8 versions --- V8Helpers.h | 62 +++++++++++++++++++++++++++++++++++------------ bindings/Main.cpp | 6 +++++ 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index 25da1f77..218b8d65 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -310,29 +310,59 @@ namespace V8 v8::Local val; \ V8_CHECK(V8::SafeToObject((v8Val), ctx, val), "Failed to convert value to object") -#define V8_OBJECT_GET_NUMBER(v8Val, prop, val) \ - V8_TO_NUMBER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) +#ifdef ALT_SERVER_API -#define V8_OBJECT_SET_NUMBER(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Number::New(isolate, val)); + #define V8_OBJECT_GET_NUMBER(v8Val, prop, val) \ + V8_TO_NUMBER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop)).ToLocalChecked(), val) -#define V8_OBJECT_GET_INTEGER(v8Val, prop, val) \ - V8_TO_INTEGER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) + #define V8_OBJECT_SET_NUMBER(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop), v8::Number::New(isolate, val)); -#define V8_OBJECT_SET_INTEGER(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Integer::New(isolate, val)); + #define V8_OBJECT_GET_INTEGER(v8Val, prop, val) \ + V8_TO_INTEGER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop)).ToLocalChecked(), val) -#define V8_OBJECT_GET_BOOLEAN(v8Val, prop, val) \ - V8_TO_BOOLEAN((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) + #define V8_OBJECT_SET_INTEGER(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop), v8::Integer::New(isolate, val)); -#define V8_OBJECT_SET_BOOLEAN(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Boolean::New(isolate, val)); + #define V8_OBJECT_GET_BOOLEAN(v8Val, prop, val) \ + V8_TO_BOOLEAN((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop)).ToLocalChecked(), val) -#define V8_OBJECT_GET_STRING(v8Val, prop, val) \ - V8_TO_STRING((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) + #define V8_OBJECT_SET_BOOLEAN(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop), v8::Boolean::New(isolate, val)); -#define V8_OBJECT_SET_STRING(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::String::NewFromUtf8(isolate, val.CStr()).ToLocalChecked()); + #define V8_OBJECT_GET_STRING(v8Val, prop, val) \ + V8_TO_STRING((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop)).ToLocalChecked(), val) + + #define V8_OBJECT_SET_STRING(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop), v8::String::NewFromUtf8(isolate, val.CStr())); + +#else + + #define V8_OBJECT_GET_NUMBER(v8Val, prop, val) \ + V8_TO_NUMBER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) + + #define V8_OBJECT_SET_NUMBER(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Number::New(isolate, val)); + + #define V8_OBJECT_GET_INTEGER(v8Val, prop, val) \ + V8_TO_INTEGER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) + + #define V8_OBJECT_SET_INTEGER(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Integer::New(isolate, val)); + + #define V8_OBJECT_GET_BOOLEAN(v8Val, prop, val) \ + V8_TO_BOOLEAN((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) + + #define V8_OBJECT_SET_BOOLEAN(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Boolean::New(isolate, val)); + + #define V8_OBJECT_GET_STRING(v8Val, prop, val) \ + V8_TO_STRING((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) + + #define V8_OBJECT_SET_STRING(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::String::NewFromUtf8(isolate, val.CStr()).ToLocalChecked()); + +#endif #define V8_NEW_OBJECT(val) \ v8::Local val = v8::Object::New(isolate); diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 3bf74ead..8f17452b 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -262,7 +262,13 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8Helpers::RegisterFunc(exports, "clearTimeout", &ClearTimer); V8Helpers::RegisterFunc(exports, "clearInterval", &ClearTimer); +#ifdef ALT_SERVER_API + V8::DefineOwnProperty(isolate, ctx, exports, "version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr())); + V8::DefineOwnProperty(isolate, ctx, exports, "branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr())); +#else V8::DefineOwnProperty(isolate, ctx, exports, "version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); V8::DefineOwnProperty(isolate, ctx, exports, "branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); +#endif + V8::DefineOwnProperty(isolate, ctx, exports, "sdkVersion", v8::Integer::New(isolate, alt::ICore::Instance().SDK_VERSION)); } From b949ddf4606021b6ebd32b0b5b51124689ae9c57 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 25 Nov 2020 23:12:59 +0100 Subject: [PATCH 136/564] update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 2c2c17bf..1da29ddc 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 2c2c17bfa52ff8919e1dca9bd2325b47e522adcb +Subproject commit 1da29ddcd902202b945902e403e5d1c47c6b37e7 From 464d319161055057102ae7e9b0ed202905f1b19c Mon Sep 17 00:00:00 2001 From: Vektor Date: Thu, 26 Nov 2020 00:04:06 +0100 Subject: [PATCH 137/564] change powf to pow --- bindings/Vector3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index 50de70fc..b9d8f18b 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -327,7 +327,7 @@ static void DistanceTo(const v8::FunctionCallbackInfo& info) V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(), z2); - double dist = sqrt(std::powf(x - x2, 2) + std::powf(y - y2, 2) + std::powf(z - z2, 2)); + double dist = sqrt(std::pow(x - x2, 2) + std::pow(y - y2, 2) + std::pow(z - z2, 2)); V8_RETURN_NUMBER(dist); } From 126365bcde0ebc1dbea3813a11c1f5244e2f5dae Mon Sep 17 00:00:00 2001 From: Vektor Date: Thu, 26 Nov 2020 00:05:51 +0100 Subject: [PATCH 138/564] update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 1da29ddc..464d3191 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 1da29ddcd902202b945902e403e5d1c47c6b37e7 +Subproject commit 464d319161055057102ae7e9b0ed202905f1b19c From f562034c43e91969cc47357562d1cb83b7bf67f9 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 26 Nov 2020 12:45:06 +0100 Subject: [PATCH 139/564] Remove check for all resources loaded --- src/CV8ScriptRuntime.cpp | 43 +++++++++++++++++++++++++++++++++++++--- src/helpers | 2 +- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 0c8ff21b..1a34c5b3 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -62,7 +62,7 @@ CV8ScriptRuntime::CV8ScriptRuntime() { v8::Isolate* isolate = context->GetIsolate(); auto promise = v8::Promise::Resolver::New(context); - auto &persistent = promises.emplace_back(v8::UniquePersistent(isolate, promise.ToLocalChecked())); + /*auto &persistent = promises.emplace_back(v8::UniquePersistent(isolate, promise.ToLocalChecked())); auto result = CV8ScriptRuntime::ResourcesLoadedResult(context, referrer, specifier, &persistent, [](v8::Local context, v8::Local referrer, v8::Local specifier, const void* original) @@ -110,9 +110,46 @@ CV8ScriptRuntime::CV8ScriptRuntime() } promises.remove(*persistent); }); - CV8ScriptRuntime::Instance().OnAllResourcesLoaded(result); + CV8ScriptRuntime::Instance().OnAllResourcesLoaded(result);*/ + + v8::Local resolver; + if (!promise.ToLocal(&resolver)) + return v8::MaybeLocal(); + + v8::String::Utf8Value utfValue(isolate, specifier); + std::string name(*utfValue); + V8ResourceImpl* resource = V8ResourceImpl::Get(context); + + auto module = static_cast(resource)->GetModuleFromName(name, isolate); + if (module.IsEmpty()) + resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); + auto resolved = CV8ScriptRuntime::ResolveModule(context, specifier, module); + Log::Info << "Resolved" << Log::Endl; + v8::Local outModule; + + if (resolved.IsEmpty() || !resolved.ToLocal(&outModule)) { + Log::Info << "FuckNo" << Log::Endl; + resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); + Log::Info << "Fuck" << Log::Endl; + } + else + { + Log::Info << "Status: " << std::to_string(outModule->GetStatus()) << Log::Endl; + if (outModule->GetStatus() != v8::Module::Status::kInstantiated) + outModule->InstantiateModule(context, CV8ScriptRuntime::ResolveModule); + Log::Info << "Status2: " << std::to_string(outModule->GetStatus()) << Log::Endl; + if (outModule->GetStatus() != v8::Module::Status::kEvaluated) + outModule->Evaluate(context); + Log::Info << "Status3: " << std::to_string(outModule->GetStatus()) << Log::Endl; + //resolver->Resolve(ctx, outModule->GetModuleNamespace()); + Log::Info << "Ctx: " << std::to_string(context.IsEmpty()) << Log::Endl; + Log::Info << "Isolate: " << std::to_string(isolate == nullptr) << Log::Endl; + auto str = v8::String::NewFromUtf8(isolate, "Fuck").ToLocalChecked(); + Log::Info << "test" << Log::Endl; + resolver->Resolve(context, str); + } - return v8::MaybeLocal(promise.ToLocalChecked()->GetPromise()); + return v8::MaybeLocal(resolver->GetPromise()); }); /*{ diff --git a/src/helpers b/src/helpers index dc505fe2..ec9da103 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit dc505fe2325faf197df17fa7063940bf0c93a6be +Subproject commit ec9da103b5b212b7df4c88f986033262e300a640 From 7c5630ccf3fcc472b5173f0c4f60efea701af943 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 26 Nov 2020 12:45:54 +0100 Subject: [PATCH 140/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 0d66caa3..ec9da103 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 0d66caa36d9ca6124f46e8c73d1eb0cd19a7fc0d +Subproject commit ec9da103b5b212b7df4c88f986033262e300a640 From bd0a449921f60ed8320c4b7e9a9d85a75129a29c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 26 Nov 2020 17:04:52 +0100 Subject: [PATCH 141/564] Added dynamic import --- src/CV8Resource.cpp | 11 ++++++++++ src/CV8Resource.h | 6 +----- src/CV8ScriptRuntime.cpp | 45 ++++++++++++++++++---------------------- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 8c13a734..f40850c3 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -593,6 +593,17 @@ std::string CV8ResourceImpl::GetModulePath(v8::Local moduleHandle) return std::string{}; } +v8::Local CV8ResourceImpl::GetModuleFromPath(std::string modulePath) +{ + for (auto& md : modules) + { + if (md.first == modulePath) + return md.second.Get(isolate); + } + + return v8::Local{}; +} + static bool IsSystemModule(const std::string &name) { return V8Module::Exists(name); diff --git a/src/CV8Resource.h b/src/CV8Resource.h index a8143108..0db2abbe 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -85,11 +85,7 @@ class CV8ResourceImpl : public V8ResourceImpl bool IsValidModule(const std::string &name); std::deque GetModuleKeys(const std::string &name); std::string GetModulePath(v8::Local moduleHandle); - v8::Local GetModuleFromName(const std::string& name, v8::Isolate *isolate) { - auto found = modules.find(name); - auto module = found->second.Get(isolate); - return module; - }; + v8::Local GetModuleFromPath(std::string modulePath); v8::MaybeLocal Require(const std::string &name); v8::MaybeLocal ResolveFile(const std::string &name, v8::Local referrer); diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 1a34c5b3..ad70a034 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -120,35 +120,30 @@ CV8ScriptRuntime::CV8ScriptRuntime() std::string name(*utfValue); V8ResourceImpl* resource = V8ResourceImpl::Get(context); - auto module = static_cast(resource)->GetModuleFromName(name, isolate); - if (module.IsEmpty()) - resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); - auto resolved = CV8ScriptRuntime::ResolveModule(context, specifier, module); - Log::Info << "Resolved" << Log::Endl; - v8::Local outModule; + v8::String::Utf8Value utf8(isolate, referrer->GetResourceName()); + std::string referrerUrl(*utf8); - if (resolved.IsEmpty() || !resolved.ToLocal(&outModule)) { - Log::Info << "FuckNo" << Log::Endl; + auto module = static_cast(resource)->GetModuleFromPath(referrerUrl); + if (module.IsEmpty()) resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); - Log::Info << "Fuck" << Log::Endl; - } else { - Log::Info << "Status: " << std::to_string(outModule->GetStatus()) << Log::Endl; - if (outModule->GetStatus() != v8::Module::Status::kInstantiated) - outModule->InstantiateModule(context, CV8ScriptRuntime::ResolveModule); - Log::Info << "Status2: " << std::to_string(outModule->GetStatus()) << Log::Endl; - if (outModule->GetStatus() != v8::Module::Status::kEvaluated) - outModule->Evaluate(context); - Log::Info << "Status3: " << std::to_string(outModule->GetStatus()) << Log::Endl; - //resolver->Resolve(ctx, outModule->GetModuleNamespace()); - Log::Info << "Ctx: " << std::to_string(context.IsEmpty()) << Log::Endl; - Log::Info << "Isolate: " << std::to_string(isolate == nullptr) << Log::Endl; - auto str = v8::String::NewFromUtf8(isolate, "Fuck").ToLocalChecked(); - Log::Info << "test" << Log::Endl; - resolver->Resolve(context, str); - } + v8::TryCatch tryCatch(isolate); + auto resolved = CV8ScriptRuntime::ResolveModule(context, specifier, module); + v8::Local outModule; + if (tryCatch.HasCaught() || resolved.IsEmpty() || !resolved.ToLocal(&outModule)) { + resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); + } + else + { + if (outModule->GetStatus() != v8::Module::Status::kInstantiated) + outModule->InstantiateModule(context, CV8ScriptRuntime::ResolveModule); + if (outModule->GetStatus() != v8::Module::Status::kEvaluated) + outModule->Evaluate(context); + resolver->Resolve(context, outModule->GetModuleNamespace()); + } + } return v8::MaybeLocal(resolver->GetPromise()); }); @@ -176,4 +171,4 @@ CV8ScriptRuntime::CV8ScriptRuntime() extern V8Module altModule, nativesModule; V8Module::Add({altModule, nativesModule}); } -} +} \ No newline at end of file From 222c0405f3fc8722f6cc6000672df78bd1b2396d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 26 Nov 2020 17:20:30 +0100 Subject: [PATCH 142/564] Added back callback --- src/CV8ScriptRuntime.cpp | 101 ++++++++++++++------------------------- src/CV8ScriptRuntime.h | 8 ++-- 2 files changed, 39 insertions(+), 70 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index ad70a034..2d2bbd53 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -62,88 +62,59 @@ CV8ScriptRuntime::CV8ScriptRuntime() { v8::Isolate* isolate = context->GetIsolate(); auto promise = v8::Promise::Resolver::New(context); - /*auto &persistent = promises.emplace_back(v8::UniquePersistent(isolate, promise.ToLocalChecked())); + v8::Local resolver; + if (!promise.ToLocal(&resolver)) + return v8::MaybeLocal(); + auto &persistent = promises.emplace_back(v8::UniquePersistent(isolate, resolver)); - auto result = CV8ScriptRuntime::ResourcesLoadedResult(context, referrer, specifier, &persistent, - [](v8::Local context, v8::Local referrer, v8::Local specifier, const void* original) + auto result = CV8ScriptRuntime::ResourcesLoadedResult(referrer, specifier, &persistent, + [](v8::Local referrer, v8::Local specifier, const void* original) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); + auto persistent = (v8::UniquePersistent*)original; auto resolver = persistent->Get(isolate); - auto ctx = context; + v8::Local context = resolver->CreationContext(); + context->Enter(); - v8::Context::Scope ctxscope(ctx); v8::String::Utf8Value utfValue(isolate, specifier); std::string name(*utfValue); - V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); - - auto module = static_cast(resource)->GetModuleFromName(name, isolate); - if(module.IsEmpty()) - resolver->Reject(ctx, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); - auto resolved = CV8ScriptRuntime::ResolveModule(ctx, specifier, module); - Log::Info << "Resolved" << Log::Endl; - v8::Local outModule; - - if (resolved.IsEmpty() || !resolved.ToLocal(&outModule)) { - Log::Info << "FuckNo" << Log::Endl; - resolver->Reject(ctx, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); - Log::Info << "Fuck" << Log::Endl; - } + V8ResourceImpl* resource = V8ResourceImpl::Get(context); + + v8::String::Utf8Value utf8(isolate, referrer->GetResourceName()); + std::string referrerUrl(*utf8); + + v8::Context::Scope ctxscope(context); + + auto module = static_cast(resource)->GetModuleFromPath(referrerUrl); + if (module.IsEmpty()) + resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); else { - Log::Info << "Status: " << std::to_string(outModule->GetStatus()) << Log::Endl; - if (outModule->GetStatus() != v8::Module::Status::kInstantiated) - outModule->InstantiateModule(ctx, CV8ScriptRuntime::ResolveModule); - Log::Info << "Status2: " << std::to_string(outModule->GetStatus()) << Log::Endl; - if (outModule->GetStatus() != v8::Module::Status::kEvaluated) - outModule->Evaluate(ctx); - Log::Info << "Status3: " << std::to_string(outModule->GetStatus()) << Log::Endl; - //resolver->Resolve(ctx, outModule->GetModuleNamespace()); - Log::Info << "Ctx: " << std::to_string(ctx.IsEmpty()) << Log::Endl; - Log::Info << "Isolate: " << std::to_string(isolate == nullptr) << Log::Endl; - auto str = v8::String::NewFromUtf8(isolate, "Fuck").ToLocalChecked(); - Log::Info << "test" << Log::Endl; - resolver->Resolve(ctx, str); + v8::TryCatch tryCatch(isolate); + auto resolved = CV8ScriptRuntime::ResolveModule(context, specifier, module); + v8::Local outModule; + + if (tryCatch.HasCaught() || resolved.IsEmpty() || !resolved.ToLocal(&outModule)) { + resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); + } + else + { + if (outModule->GetStatus() != v8::Module::Status::kInstantiated) + outModule->InstantiateModule(context, CV8ScriptRuntime::ResolveModule); + if (outModule->GetStatus() != v8::Module::Status::kEvaluated) + outModule->Evaluate(context); + resolver->Resolve(context, outModule->GetModuleNamespace()); + } } promises.remove(*persistent); + context->Exit(); }); - CV8ScriptRuntime::Instance().OnAllResourcesLoaded(result);*/ + CV8ScriptRuntime::Instance().OnAllResourcesLoaded(result); - v8::Local resolver; - if (!promise.ToLocal(&resolver)) - return v8::MaybeLocal(); - - v8::String::Utf8Value utfValue(isolate, specifier); - std::string name(*utfValue); - V8ResourceImpl* resource = V8ResourceImpl::Get(context); - - v8::String::Utf8Value utf8(isolate, referrer->GetResourceName()); - std::string referrerUrl(*utf8); - - auto module = static_cast(resource)->GetModuleFromPath(referrerUrl); - if (module.IsEmpty()) - resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); - else - { - v8::TryCatch tryCatch(isolate); - auto resolved = CV8ScriptRuntime::ResolveModule(context, specifier, module); - v8::Local outModule; - - if (tryCatch.HasCaught() || resolved.IsEmpty() || !resolved.ToLocal(&outModule)) { - resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); - } - else - { - if (outModule->GetStatus() != v8::Module::Status::kInstantiated) - outModule->InstantiateModule(context, CV8ScriptRuntime::ResolveModule); - if (outModule->GetStatus() != v8::Module::Status::kEvaluated) - outModule->Evaluate(context); - resolver->Resolve(context, outModule->GetModuleNamespace()); - } - } return v8::MaybeLocal(resolver->GetPromise()); }); diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 4f7aa8a8..057a5831 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -135,21 +135,19 @@ class CV8ScriptRuntime : public alt::IScriptRuntime } }; - using ResourcesLoadedCallback = void (*)(v8::Local context, v8::Local referrer, v8::Local specifier, const void* promise); + using ResourcesLoadedCallback = void (*)(v8::Local referrer, v8::Local specifier, const void* promise); class ResourcesLoadedResult { public: - ResourcesLoadedResult(v8::Local context, v8::Local referrer, v8::Local specifier, const void* promise, ResourcesLoadedCallback cb) + ResourcesLoadedResult(v8::Local referrer, v8::Local specifier, const void* promise, ResourcesLoadedCallback cb) { - _context = context; _referrer = referrer; _specifier = specifier; _promise = promise; _callback = cb; } - v8::Local _context; v8::Local _referrer; v8::Local _specifier; ResourcesLoadedCallback _callback; @@ -158,7 +156,7 @@ class CV8ScriptRuntime : public alt::IScriptRuntime void call() { if (&_promise == nullptr) return; - _callback(_context, _referrer, _specifier, &_promise); + _callback(_referrer, _specifier, &_promise); } }; From b04ba7a5156509495bfdbcbadee7a5a9f0748d40 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 26 Nov 2020 21:47:03 +0100 Subject: [PATCH 143/564] Added resourceName getter --- src/bindings/Main.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 587bc26d..22c7e1d6 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -658,6 +658,15 @@ static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &in V8_RETURN(persistent.Get(isolate)->GetPromise()); } +static void ResourceNameGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + auto res = static_cast(CV8ResourceImpl::Get(ctx)); + + V8_RETURN_STRING(res->GetResource()->GetName().CStr()); +} + extern V8Class v8Vector3, v8RGBA, v8BaseObject, @@ -774,4 +783,10 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "takeScreenshot", &TakeScreenshot); V8Helpers::RegisterFunc(exports, "takeScreenshotGameOnly", &TakeScreenshotGameOnly); + + v8::Isolate* isolate = ctx->GetIsolate(); + alt::IResource* resource = V8ResourceImpl::GetResource(ctx); + V8_CHECK(resource, "invalid resource"); + auto resourceName = resource->GetName().CStr(); + exports->Set(ctx, v8::String::NewFromUtf8(isolate, "resourceName").ToLocalChecked(), v8::String::NewFromUtf8(isolate, resourceName).ToLocalChecked()); }); From 119085b08a28be54bd6fe3af003184f773355504 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 26 Nov 2020 21:49:40 +0100 Subject: [PATCH 144/564] Updated helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index ec9da103..bbf4283e 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit ec9da103b5b212b7df4c88f986033262e300a640 +Subproject commit bbf4283e3b15f8b7a0d66453a9205d4f64b9d645 From 17bc097f8b8408fc77af0dfa3943902dcf5ace19 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 26 Nov 2020 21:51:29 +0100 Subject: [PATCH 145/564] Removed unused getter function --- src/bindings/Main.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 22c7e1d6..d8156924 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -658,15 +658,6 @@ static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &in V8_RETURN(persistent.Get(isolate)->GetPromise()); } -static void ResourceNameGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - - auto res = static_cast(CV8ResourceImpl::Get(ctx)); - - V8_RETURN_STRING(res->GetResource()->GetName().CStr()); -} - extern V8Class v8Vector3, v8RGBA, v8BaseObject, From 6c702a329186db9afb3c8a8d65473ee213cc993c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 26 Nov 2020 21:52:53 +0100 Subject: [PATCH 146/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index ec9da103..bbf4283e 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit ec9da103b5b212b7df4c88f986033262e300a640 +Subproject commit bbf4283e3b15f8b7a0d66453a9205d4f64b9d645 From 2c2ec2c6d46e29cf250030ea1b9044b3e1e955f0 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 26 Nov 2020 23:59:55 +0100 Subject: [PATCH 147/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index bbf4283e..464d3191 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit bbf4283e3b15f8b7a0d66453a9205d4f64b9d645 +Subproject commit 464d319161055057102ae7e9b0ed202905f1b19c From f228e0752dc15fbea6d9747236451f17f9ec6f1c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 27 Nov 2020 11:52:17 +0100 Subject: [PATCH 148/564] Added resourceName property --- bindings/Main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 8f17452b..b2cf3458 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -265,9 +265,15 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex #ifdef ALT_SERVER_API V8::DefineOwnProperty(isolate, ctx, exports, "version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr())); V8::DefineOwnProperty(isolate, ctx, exports, "branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr())); + + alt::IResource* resource = V8ResourceImpl::GetResource(ctx); + V8::DefineOwnProperty(isolate, ctx, exports, "resourceName", v8::String::NewFromUtf8(isolate, resource->GetName().CStr())); #else V8::DefineOwnProperty(isolate, ctx, exports, "version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); V8::DefineOwnProperty(isolate, ctx, exports, "branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); + + alt::IResource* resource = V8ResourceImpl::GetResource(ctx); + V8::DefineOwnProperty(isolate, ctx, exports, "resourceName", v8::String::NewFromUtf8(isolate, resource->GetName().CStr()).ToLocalChecked()); #endif V8::DefineOwnProperty(isolate, ctx, exports, "sdkVersion", v8::Integer::New(isolate, alt::ICore::Instance().SDK_VERSION)); From 5325333627c0634b759fbf36225b3639cd17d036 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 27 Nov 2020 11:55:58 +0100 Subject: [PATCH 149/564] Removed resourceName getter --- src/bindings/Main.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index d8156924..587bc26d 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -774,10 +774,4 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "takeScreenshot", &TakeScreenshot); V8Helpers::RegisterFunc(exports, "takeScreenshotGameOnly", &TakeScreenshotGameOnly); - - v8::Isolate* isolate = ctx->GetIsolate(); - alt::IResource* resource = V8ResourceImpl::GetResource(ctx); - V8_CHECK(resource, "invalid resource"); - auto resourceName = resource->GetName().CStr(); - exports->Set(ctx, v8::String::NewFromUtf8(isolate, "resourceName").ToLocalChecked(), v8::String::NewFromUtf8(isolate, resourceName).ToLocalChecked()); }); From 6ab77d61843abc4bbffbdde60025c46479fcb2bf Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 27 Nov 2020 13:45:38 +0100 Subject: [PATCH 150/564] Removed unused variable --- src/CV8ScriptRuntime.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 2d2bbd53..27b3f81b 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -4,8 +4,6 @@ #include "inspector/CV8InspectorChannel.h" #include "helpers/V8Module.h" -v8::Persistent host_import_module_dynamically_callback; - CV8ScriptRuntime::CV8ScriptRuntime() { CV8ScriptRuntime::SetInstance(this); From 015462c14d3657b97ce6bb7509336f30f65fe696 Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 27 Nov 2020 14:33:34 +0100 Subject: [PATCH 151/564] update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index bbf4283e..2c055e27 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit bbf4283e3b15f8b7a0d66453a9205d4f64b9d645 +Subproject commit 2c055e279f75e35b5900a6787875f6c537d26801 From 57105860543fafb45ee2a5796cf00397916c96dd Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 27 Nov 2020 14:44:10 +0100 Subject: [PATCH 152/564] fix model getter --- bindings/Entity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index 0c6044ef..d48baa50 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -58,7 +58,7 @@ static void ModelGetter(v8::Local, const v8::PropertyCallbackInfoGetModel()); + V8_RETURN_UINT32(ent->GetModel()); } static void HasSyncedMeta(const v8::FunctionCallbackInfo &info) From 7c6fec7c0cad6846947817eb39f80c262389a91e Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 27 Nov 2020 14:44:34 +0100 Subject: [PATCH 153/564] fix model getter --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 2c055e27..57105860 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 2c055e279f75e35b5900a6787875f6c537d26801 +Subproject commit 57105860543fafb45ee2a5796cf00397916c96dd From 6d3132b31e0e22195f21588eecb169428d75ad26 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 29 Nov 2020 16:29:19 +0100 Subject: [PATCH 154/564] Add stringification of objects and arrays for log methods --- bindings/Main.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index b2cf3458..3f6016af 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -125,7 +125,15 @@ static void Log(const v8::FunctionCallbackInfo &info) if (i > 0) ss << " "; - ss << *v8::String::Utf8Value(isolate, val->ToString(ctx).ToLocalChecked()); + v8::Local str; + if (val->IsObject() || val->IsArray()) { + v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); + v8::Local stringified; + if (maybe.ToLocal(&stringified)) str = stringified; + } + else str = val->ToString(ctx).ToLocalChecked(); + + ss << *v8::String::Utf8Value(isolate, str); } alt::ICore::Instance().LogColored(ss.str()); @@ -146,7 +154,15 @@ static void LogWarning(const v8::FunctionCallbackInfo &info) if (i > 0) ss << " "; - ss << *v8::String::Utf8Value(isolate, val->ToString(ctx).ToLocalChecked()); + v8::Local str; + if (val->IsObject() || val->IsArray()) { + v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); + v8::Local stringified; + if (maybe.ToLocal(&stringified)) str = stringified; + } + else str = val->ToString(ctx).ToLocalChecked(); + + ss << *v8::String::Utf8Value(isolate, str); } alt::ICore::Instance().LogWarning(ss.str()); @@ -167,7 +183,15 @@ static void LogError(const v8::FunctionCallbackInfo &info) if (i > 0) ss << " "; - ss << *v8::String::Utf8Value(isolate, val->ToString(ctx).ToLocalChecked()); + v8::Local str; + if (val->IsObject() || val->IsArray()) { + v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); + v8::Local stringified; + if (maybe.ToLocal(&stringified)) str = stringified; + } + else str = val->ToString(ctx).ToLocalChecked(); + + ss << *v8::String::Utf8Value(isolate, str); } alt::ICore::Instance().LogError(ss.str()); From f388b41998eaff2222fc1d274ac4974d2cfa620e Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 30 Nov 2020 17:56:57 +0100 Subject: [PATCH 155/564] Fix importing loaded modules --- src/CV8ScriptRuntime.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 27b3f81b..2dbb37f1 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -55,7 +55,7 @@ CV8ScriptRuntime::CV8ScriptRuntime() } }); - static std::list> promises; + std::list> promises; isolate->SetHostImportModuleDynamicallyCallback([](v8::Local context, v8::Local referrer, v8::Local specifier) { v8::Isolate* isolate = context->GetIsolate(); @@ -101,9 +101,9 @@ CV8ScriptRuntime::CV8ScriptRuntime() } else { - if (outModule->GetStatus() != v8::Module::Status::kInstantiated) + if (outModule->GetStatus() < v8::Module::Status::kInstantiating) outModule->InstantiateModule(context, CV8ScriptRuntime::ResolveModule); - if (outModule->GetStatus() != v8::Module::Status::kEvaluated) + if (outModule->GetStatus() < v8::Module::Status::kEvaluating) outModule->Evaluate(context); resolver->Resolve(context, outModule->GetModuleNamespace()); } From 99c4d11d69d8e7a041c6b1f9d41701c63365d0a2 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 30 Nov 2020 18:05:56 +0100 Subject: [PATCH 156/564] Fix missing static --- src/CV8ScriptRuntime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 2dbb37f1..ff41932f 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -55,7 +55,7 @@ CV8ScriptRuntime::CV8ScriptRuntime() } }); - std::list> promises; + static std::list> promises; isolate->SetHostImportModuleDynamicallyCallback([](v8::Local context, v8::Local referrer, v8::Local specifier) { v8::Isolate* isolate = context->GetIsolate(); From 186ffc906a6110214cae6641aaa1fdd78cb3fa9c Mon Sep 17 00:00:00 2001 From: Hazard Date: Mon, 30 Nov 2020 18:08:48 +0100 Subject: [PATCH 157/564] Fixed takeScreenshot and takeScreenshotGameOnly --- src/CV8ScriptRuntime.cpp | 4 ++++ src/CV8ScriptRuntime.h | 1 + src/bindings/Main.cpp | 12 ++++++++---- src/main.cpp | 5 ----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index d8dc5ee7..ba84b1c5 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -4,8 +4,12 @@ #include "inspector/CV8InspectorChannel.h" #include "helpers/V8Module.h" +CV8ScriptRuntime* CV8ScriptRuntime::instance = nullptr; + CV8ScriptRuntime::CV8ScriptRuntime() { + instance = this; + platform = v8::platform::NewDefaultPlatform(); v8::V8::InitializePlatform(platform.get()); v8::V8::Initialize(); diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index c7b3c688..105b6471 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -21,6 +21,7 @@ class CV8ScriptRuntime : public alt::IScriptRuntime std::unique_ptr inspectorSession; public: + static CV8ScriptRuntime* instance; CV8ScriptRuntime(); v8::Isolate *GetIsolate() const { return isolate; } diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 587bc26d..92e9f314 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -606,7 +606,9 @@ static void TakeScreenshot(const v8::FunctionCallbackInfo &info) auto &persistent = promises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); api.TakeScreenshot([](alt::StringView base64, const void *userData) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD + + v8::Isolate *isolate = CV8ScriptRuntime::instance->GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -621,7 +623,8 @@ static void TakeScreenshot(const v8::FunctionCallbackInfo &info) promises.remove(*persistent); }, &persistent); - + + V8_RETURN(persistent.Get(isolate)->GetPromise()); } static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &info) @@ -638,7 +641,9 @@ static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &in auto &persistent = promises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); api.TakeScreenshotGameOnly([](alt::StringView base64, const void *userData) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD + + v8::Isolate *isolate = CV8ScriptRuntime::instance->GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -652,7 +657,6 @@ static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &in } promises.remove(*persistent); - ctx->Exit(); }, &persistent); V8_RETURN(persistent.Get(isolate)->GetPromise()); diff --git a/src/main.cpp b/src/main.cpp index 2e62aca7..cbb58537 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,11 +8,6 @@ #define ALTV_JS_EXPORT extern "C" #endif -void StaticInitialization() -{ - extern V8Class v8Vector3; -} - ALTV_JS_EXPORT alt::IScriptRuntime *CreateJSScriptRuntime(alt::ICore *core) { alt::ICore::SetInstance(core); From c239d32825081abe682728206ceac492aec12955 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 30 Nov 2020 18:31:33 +0100 Subject: [PATCH 158/564] Fix merge --- src/CV8Resource.cpp | 8 +++--- src/CV8ScriptRuntime.cpp | 62 +++++++++++++++++++++++++++++++++++++--- src/CV8ScriptRuntime.h | 33 +++++++++++++++++++++ 3 files changed, 95 insertions(+), 8 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index f40850c3..842f13f4 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -235,10 +235,10 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) case alt::CEvent::Type::CONNECTION_COMPLETE: { handlers = GetLocalHandlers("connectionComplete"); - CV8ScriptRuntime& runtime = CV8ScriptRuntime::Instance(); - runtime._allResourcesLoaded = true; - for (auto result : runtime.onAllResourcesLoadedCallbacks) result.call(); - runtime.onAllResourcesLoadedCallbacks.empty(); + CV8ScriptRuntime* runtime = CV8ScriptRuntime::instance; + runtime->_allResourcesLoaded = true; + for (CV8ScriptRuntime::ResourcesLoadedResult result : runtime->onAllResourcesLoadedCallbacks) result.call(); + runtime->onAllResourcesLoadedCallbacks.empty(); break; } case alt::CEvent::Type::DISCONNECT_EVENT: diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index ba84b1c5..eb7e7a28 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -58,10 +58,64 @@ CV8ScriptRuntime::CV8ScriptRuntime() } }); - /*isolate->SetHostImportModuleDynamicallyCallback([](v8::Local context, v8::Local referrer, v8::Local specifier) { - - return v8::MaybeLocal(); - });*/ + static std::list> promises; + isolate->SetHostImportModuleDynamicallyCallback([](v8::Local context, v8::Local referrer, v8::Local specifier) + { + v8::Isolate* isolate = context->GetIsolate(); + auto promise = v8::Promise::Resolver::New(context); + v8::Local resolver; + if (!promise.ToLocal(&resolver)) + return v8::MaybeLocal(); + auto& persistent = promises.emplace_back(v8::UniquePersistent(isolate, resolver)); + + auto result = CV8ScriptRuntime::ResourcesLoadedResult(referrer, specifier, &persistent, + [](v8::Local referrer, v8::Local specifier, const void* original) + { + v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + auto persistent = (v8::UniquePersistent*)original; + auto resolver = persistent->Get(isolate); + v8::Local context = resolver->CreationContext(); + + v8::String::Utf8Value utfValue(isolate, specifier); + std::string name(*utfValue); + V8ResourceImpl* resource = V8ResourceImpl::Get(context); + + v8::String::Utf8Value utf8(isolate, referrer->GetResourceName()); + std::string referrerUrl(*utf8); + + v8::Context::Scope ctxscope(context); + + auto module = static_cast(resource)->GetModuleFromPath(referrerUrl); + if (module.IsEmpty()) + resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); + else + { + v8::TryCatch tryCatch(isolate); + auto resolved = CV8ScriptRuntime::ResolveModule(context, specifier, module); + v8::Local outModule; + + if (tryCatch.HasCaught() || resolved.IsEmpty() || !resolved.ToLocal(&outModule)) { + resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); + } + else + { + if (outModule->GetStatus() < v8::Module::Status::kInstantiating) + outModule->InstantiateModule(context, CV8ScriptRuntime::ResolveModule); + if (outModule->GetStatus() < v8::Module::Status::kEvaluating) + outModule->Evaluate(context); + resolver->Resolve(context, outModule->GetModuleNamespace()); + } + } + promises.remove(*persistent); + }); + CV8ScriptRuntime::instance->OnAllResourcesLoaded(result); + + return v8::MaybeLocal(resolver->GetPromise()); + }); /*{ v8::Locker locker(isolate); diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 105b6471..50d23f83 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -127,4 +127,37 @@ class CV8ScriptRuntime : public alt::IScriptRuntime return result; } }; + + using ResourcesLoadedCallback = void (*)(v8::Local referrer, v8::Local specifier, const void* promise); + + class ResourcesLoadedResult + { + public: + ResourcesLoadedResult(v8::Local referrer, v8::Local specifier, const void* promise, ResourcesLoadedCallback cb) + { + _referrer = referrer; + _specifier = specifier; + _promise = promise; + _callback = cb; + } + + v8::Local _referrer; + v8::Local _specifier; + ResourcesLoadedCallback _callback; + const void* _promise; + + void call() + { + if (&_promise == nullptr) return; + _callback(_referrer, _specifier, &_promise); + } + }; + + std::list onAllResourcesLoadedCallbacks; + void OnAllResourcesLoaded(ResourcesLoadedResult result) + { + if (_allResourcesLoaded) result.call(); + else onAllResourcesLoadedCallbacks.emplace_back(result); + }; + bool _allResourcesLoaded = false; }; \ No newline at end of file From b6b182c149131a3688f66fdd43ae32b780e0b4c0 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 30 Nov 2020 19:47:55 +0100 Subject: [PATCH 159/564] Fix pointer issue --- src/CV8ScriptRuntime.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 50d23f83..549af869 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -149,7 +149,7 @@ class CV8ScriptRuntime : public alt::IScriptRuntime void call() { if (&_promise == nullptr) return; - _callback(_referrer, _specifier, &_promise); + _callback(_referrer, _specifier, _promise); } }; From 4085f4ebecc6d7badc6e16359b649ffcde81a830 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 30 Nov 2020 20:48:26 +0100 Subject: [PATCH 160/564] Removed leftover debug code --- src/CV8ScriptRuntime.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 549af869..21ff3409 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -148,7 +148,6 @@ class CV8ScriptRuntime : public alt::IScriptRuntime void call() { - if (&_promise == nullptr) return; _callback(_referrer, _specifier, _promise); } }; From ce79b9c25eabd0d824c3d1cf88f66c73205030b8 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 1 Dec 2020 11:07:25 +0100 Subject: [PATCH 161/564] Rename of classes and variables --- src/CV8ScriptRuntime.cpp | 10 +++++----- src/CV8ScriptRuntime.h | 15 ++++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index eb7e7a28..66f1a5fb 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -58,7 +58,7 @@ CV8ScriptRuntime::CV8ScriptRuntime() } }); - static std::list> promises; + static std::list> dynamicImportPromises; isolate->SetHostImportModuleDynamicallyCallback([](v8::Local context, v8::Local referrer, v8::Local specifier) { v8::Isolate* isolate = context->GetIsolate(); @@ -66,9 +66,9 @@ CV8ScriptRuntime::CV8ScriptRuntime() v8::Local resolver; if (!promise.ToLocal(&resolver)) return v8::MaybeLocal(); - auto& persistent = promises.emplace_back(v8::UniquePersistent(isolate, resolver)); + auto& persistent = dynamicImportPromises.emplace_back(v8::UniquePersistent(isolate, resolver)); - auto result = CV8ScriptRuntime::ResourcesLoadedResult(referrer, specifier, &persistent, + auto result = CV8ScriptRuntime::DynamicImportReadyResult(referrer, specifier, &persistent, [](v8::Local referrer, v8::Local specifier, const void* original) { v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); @@ -110,9 +110,9 @@ CV8ScriptRuntime::CV8ScriptRuntime() resolver->Resolve(context, outModule->GetModuleNamespace()); } } - promises.remove(*persistent); + dynamicImportPromises.remove(*persistent); }); - CV8ScriptRuntime::instance->OnAllResourcesLoaded(result); + CV8ScriptRuntime::instance->OnDynamicImportReady(result); return v8::MaybeLocal(resolver->GetPromise()); }); diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 21ff3409..52057459 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -128,12 +128,12 @@ class CV8ScriptRuntime : public alt::IScriptRuntime } }; - using ResourcesLoadedCallback = void (*)(v8::Local referrer, v8::Local specifier, const void* promise); + using DynamicImportReadyCallback = void (*)(v8::Local referrer, v8::Local specifier, const void* promise); - class ResourcesLoadedResult + class DynamicImportReadyResult { public: - ResourcesLoadedResult(v8::Local referrer, v8::Local specifier, const void* promise, ResourcesLoadedCallback cb) + DynamicImportReadyResult(v8::Local referrer, v8::Local specifier, const void* promise, DynamicImportReadyCallback cb) { _referrer = referrer; _specifier = specifier; @@ -143,20 +143,21 @@ class CV8ScriptRuntime : public alt::IScriptRuntime v8::Local _referrer; v8::Local _specifier; - ResourcesLoadedCallback _callback; + DynamicImportReadyCallback _callback; const void* _promise; void call() { _callback(_referrer, _specifier, _promise); + CV8ScriptRuntime::instance->onDynamicImportReadyCallbacks.remove(*this); } }; - std::list onAllResourcesLoadedCallbacks; - void OnAllResourcesLoaded(ResourcesLoadedResult result) + std::list onDynamicImportReadyCallbacks; + void OnDynamicImportReady(DynamicImportReadyResult result) { if (_allResourcesLoaded) result.call(); - else onAllResourcesLoadedCallbacks.emplace_back(result); + else onDynamicImportReadyCallbacks.emplace_back(result); }; bool _allResourcesLoaded = false; }; \ No newline at end of file From e50b1aeadcdf316e0dd26d1e4871ec982b842741 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 1 Dec 2020 11:09:59 +0100 Subject: [PATCH 162/564] Fix clearing import ready callbacks --- src/CV8Resource.cpp | 4 ++-- src/CV8ScriptRuntime.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 842f13f4..ab6bf93f 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -237,8 +237,8 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) handlers = GetLocalHandlers("connectionComplete"); CV8ScriptRuntime* runtime = CV8ScriptRuntime::instance; runtime->_allResourcesLoaded = true; - for (CV8ScriptRuntime::ResourcesLoadedResult result : runtime->onAllResourcesLoadedCallbacks) result.call(); - runtime->onAllResourcesLoadedCallbacks.empty(); + for (CV8ScriptRuntime::DynamicImportReadyResult result : runtime->onDynamicImportReadyCallbacks) result.call(); + runtime->onDynamicImportReadyCallbacks.clear(); break; } case alt::CEvent::Type::DISCONNECT_EVENT: diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 52057459..f816a2dc 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -149,7 +149,6 @@ class CV8ScriptRuntime : public alt::IScriptRuntime void call() { _callback(_referrer, _specifier, _promise); - CV8ScriptRuntime::instance->onDynamicImportReadyCallbacks.remove(*this); } }; From 151f1ee1e47e2ae2de1dd2422bb5ce20272cecb7 Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 2 Dec 2020 06:22:09 +0100 Subject: [PATCH 163/564] Added CPersistent and V8_NEW_STRING --- V8Helpers.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/V8Helpers.h b/V8Helpers.h index 218b8d65..d2711874 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -97,6 +97,9 @@ class V8ResourceImpl; namespace V8 { + template + using CPersistent = v8::Persistent>; + class SourceLocation { public: @@ -364,6 +367,8 @@ namespace V8 #endif +#define V8_NEW_STRING(val) v8::String::NewFromUtf8(isolate, val).ToLocalChecked() + #define V8_NEW_OBJECT(val) \ v8::Local val = v8::Object::New(isolate); From 07c798849d09ba1a8d74c88b84cf14a1b4d07e3b Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 2 Dec 2020 06:22:58 +0100 Subject: [PATCH 164/564] Refined dynamic importing --- src/CV8Resource.cpp | 21 ++++++- src/CV8Resource.h | 6 +- src/CV8ScriptRuntime.cpp | 122 +++++++++++++++++++++------------------ src/CV8ScriptRuntime.h | 64 ++++++++++---------- src/helpers | 2 +- 5 files changed, 121 insertions(+), 94 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index ab6bf93f..0789ec89 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -45,6 +45,14 @@ static void StaticRequire(const v8::FunctionCallbackInfo &info) V8Helpers::Throw(isolate, "No such module " + name); } +void CV8ResourceImpl::ProcessDynamicImports() { + for(auto import : dynamicImports) + { + import(); + } + dynamicImports.clear(); +} + bool CV8ResourceImpl::Start() { if (resource->GetMain().IsEmpty()) @@ -137,6 +145,11 @@ bool CV8ResourceImpl::Start() DispatchStartEvent(!result); + // if all resources are already loaded + if(CV8ScriptRuntime::instance->resourcesLoaded) { + ProcessDynamicImports(); + } + return result; } @@ -236,9 +249,10 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) { handlers = GetLocalHandlers("connectionComplete"); CV8ScriptRuntime* runtime = CV8ScriptRuntime::instance; - runtime->_allResourcesLoaded = true; - for (CV8ScriptRuntime::DynamicImportReadyResult result : runtime->onDynamicImportReadyCallbacks) result.call(); - runtime->onDynamicImportReadyCallbacks.clear(); + runtime->resourcesLoaded = true; + + ProcessDynamicImports(); + break; } case alt::CEvent::Type::DISCONNECT_EVENT: @@ -347,6 +361,7 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) } case alt::CEvent::Type::DISCONNECT_EVENT: { + CV8ScriptRuntime::instance->resourcesLoaded = false; break; } case alt::CEvent::Type::REMOVE_ENTITY_EVENT: diff --git a/src/CV8Resource.h b/src/CV8Resource.h index 0db2abbe..da33ebe3 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -14,6 +14,8 @@ class CV8ScriptRuntime; class CV8ResourceImpl : public V8ResourceImpl { public: + std::list> dynamicImports; + CV8ResourceImpl(alt::IResource *resource, v8::Isolate *isolate) : V8ResourceImpl(isolate, resource) { } @@ -23,6 +25,8 @@ class CV8ResourceImpl : public V8ResourceImpl Log::Debug << __FUNCTION__ << Log::Endl; } + void ProcessDynamicImports(); + bool Start() override; bool Stop() override; @@ -94,8 +98,6 @@ class CV8ResourceImpl : public V8ResourceImpl private: using WebViewEvents = std::unordered_multimap; - CV8ScriptRuntime *runtime; - std::unordered_map> requires; std::unordered_map> modules; diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 66f1a5fb..e315e436 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -54,68 +54,76 @@ CV8ScriptRuntime::CV8ScriptRuntime() } else { - Log::Error << "You're not supposed to ever see this"; + Log::Error << "You're not supposed to ever see this" << Log::Endl; } }); - static std::list> dynamicImportPromises; - isolate->SetHostImportModuleDynamicallyCallback([](v8::Local context, v8::Local referrer, v8::Local specifier) + isolate->SetHostImportModuleDynamicallyCallback([](v8::Local context, v8::Local referrer, v8::Local specifier) { + v8::Isolate* isolate = context->GetIsolate(); + + auto referrerVal = referrer->GetResourceName(); + if(referrerVal->IsUndefined()) { - v8::Isolate* isolate = context->GetIsolate(); - auto promise = v8::Promise::Resolver::New(context); - v8::Local resolver; - if (!promise.ToLocal(&resolver)) - return v8::MaybeLocal(); - auto& persistent = dynamicImportPromises.emplace_back(v8::UniquePersistent(isolate, resolver)); - - auto result = CV8ScriptRuntime::DynamicImportReadyResult(referrer, specifier, &persistent, - [](v8::Local referrer, v8::Local specifier, const void* original) + return v8::MaybeLocal(); + } + + std::string referrerUrl = *v8::String::Utf8Value(isolate, referrer->GetResourceName()); + auto resource = static_cast(V8ResourceImpl::Get(context)); + + auto resolver = v8::Promise::Resolver::New(context).ToLocalChecked(); + + V8::CPersistent presolver(isolate, resolver); + V8::CPersistent pspecifier(isolate, specifier); + V8::CPersistent preferrerModule(isolate, resource->GetModuleFromPath(referrerUrl)); + + // careful what we take in by value in the lambda + // it is possible pass v8::Local but should not be done + // make a V8::CPersistent out of it and pass that + auto domodule = [isolate, presolver, pspecifier, preferrerModule]{ + auto referrerModule = preferrerModule.Get(isolate); + auto resolver = presolver.Get(isolate); + auto specifier = pspecifier.Get(isolate); + + auto ctx = resolver->CreationContext(); + v8::Context::Scope ctxs(ctx); + + auto mmodule = ResolveModule(ctx, specifier, referrerModule); + if(mmodule.IsEmpty()) + { + resolver->Reject(ctx, v8::Exception::ReferenceError(V8_NEW_STRING("Could not resolve module"))); + return; + } + + auto module = mmodule.ToLocalChecked(); + V8Helpers::TryCatch([&]{ + if(module->GetStatus() == v8::Module::Status::kUninstantiated && !module->InstantiateModule(ctx, ResolveModule).ToChecked()) + { + resolver->Reject(ctx, v8::Exception::ReferenceError(V8_NEW_STRING("Error instantiating module"))); + return false; + } + + if(module->GetStatus() != v8::Module::Status::kEvaluated && module->Evaluate(ctx).IsEmpty()) { - v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); - v8::Locker locker(isolate); - v8::Isolate::Scope isolateScope(isolate); - v8::HandleScope handleScope(isolate); - - auto persistent = (v8::UniquePersistent*)original; - auto resolver = persistent->Get(isolate); - v8::Local context = resolver->CreationContext(); - - v8::String::Utf8Value utfValue(isolate, specifier); - std::string name(*utfValue); - V8ResourceImpl* resource = V8ResourceImpl::Get(context); - - v8::String::Utf8Value utf8(isolate, referrer->GetResourceName()); - std::string referrerUrl(*utf8); - - v8::Context::Scope ctxscope(context); - - auto module = static_cast(resource)->GetModuleFromPath(referrerUrl); - if (module.IsEmpty()) - resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); - else - { - v8::TryCatch tryCatch(isolate); - auto resolved = CV8ScriptRuntime::ResolveModule(context, specifier, module); - v8::Local outModule; - - if (tryCatch.HasCaught() || resolved.IsEmpty() || !resolved.ToLocal(&outModule)) { - resolver->Reject(context, v8::Exception::ReferenceError(v8::String::NewFromUtf8(isolate, "Module could not be found").ToLocalChecked())); - } - else - { - if (outModule->GetStatus() < v8::Module::Status::kInstantiating) - outModule->InstantiateModule(context, CV8ScriptRuntime::ResolveModule); - if (outModule->GetStatus() < v8::Module::Status::kEvaluating) - outModule->Evaluate(context); - resolver->Resolve(context, outModule->GetModuleNamespace()); - } - } - dynamicImportPromises.remove(*persistent); - }); - CV8ScriptRuntime::instance->OnDynamicImportReady(result); - - return v8::MaybeLocal(resolver->GetPromise()); - }); + resolver->Reject(ctx, v8::Exception::ReferenceError(V8_NEW_STRING("Error evaluating module"))); + return false; + } + + resolver->Resolve(ctx, module->GetModuleNamespace()); + return true; + }); + }; + + if(instance->resourcesLoaded && resource->GetResource()->IsStarted()) + { + // instantly resolve the module + domodule(); + } else { + // put it in the queue to resolve after all resource are loaded + resource->dynamicImports.emplace_back(domodule); + } + + return v8::MaybeLocal(resolver->GetPromise()); + }); /*{ v8::Locker locker(isolate); diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index f816a2dc..8c2fb8cd 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -22,6 +22,7 @@ class CV8ScriptRuntime : public alt::IScriptRuntime public: static CV8ScriptRuntime* instance; + CV8ScriptRuntime(); v8::Isolate *GetIsolate() const { return isolate; } @@ -128,35 +129,36 @@ class CV8ScriptRuntime : public alt::IScriptRuntime } }; - using DynamicImportReadyCallback = void (*)(v8::Local referrer, v8::Local specifier, const void* promise); - - class DynamicImportReadyResult - { - public: - DynamicImportReadyResult(v8::Local referrer, v8::Local specifier, const void* promise, DynamicImportReadyCallback cb) - { - _referrer = referrer; - _specifier = specifier; - _promise = promise; - _callback = cb; - } - - v8::Local _referrer; - v8::Local _specifier; - DynamicImportReadyCallback _callback; - const void* _promise; - - void call() - { - _callback(_referrer, _specifier, _promise); - } - }; - - std::list onDynamicImportReadyCallbacks; - void OnDynamicImportReady(DynamicImportReadyResult result) - { - if (_allResourcesLoaded) result.call(); - else onDynamicImportReadyCallbacks.emplace_back(result); - }; - bool _allResourcesLoaded = false; + // using DynamicImportReadyCallback = void (*)(v8::Local referrer, v8::Local specifier, const void* promise); + + // class DynamicImportReadyResult + // { + // public: + // DynamicImportReadyResult(v8::Local referrer, v8::Local specifier, const void* promise, DynamicImportReadyCallback cb) + // { + // _referrer = referrer; + // _specifier = specifier; + // _promise = promise; + // _callback = cb; + // } + + // v8::Local _referrer; + // v8::Local _specifier; + // DynamicImportReadyCallback _callback; + // const void* _promise; + + // void call() + // { + // _callback(_referrer, _specifier, _promise); + // } + // }; + + // std::list onDynamicImportReadyCallbacks; + // void OnDynamicImportReady(DynamicImportReadyResult result) + // { + // if (_allResourcesLoaded) result.call(); + // else onDynamicImportReadyCallbacks.emplace_back(result); + // }; + + bool resourcesLoaded = false; }; \ No newline at end of file diff --git a/src/helpers b/src/helpers index 57105860..151f1ee1 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 57105860543fafb45ee2a5796cf00397916c96dd +Subproject commit 151f1ee1e47e2ae2de1dd2422bb5ce20272cecb7 From f9a5fc808518d278e0c6d0d21bc98f0c0d415817 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 3 Dec 2020 01:19:33 +0100 Subject: [PATCH 165/564] Added alt.isGameFocused --- src/bindings/Main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 92e9f314..198ee4f7 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -662,6 +662,12 @@ static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &in V8_RETURN(persistent.Get(isolate)->GetPromise()); } +static void IsGameFocused(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_BOOLEAN(alt::ICore::Instance().IsGameFocused()); +} + extern V8Class v8Vector3, v8RGBA, v8BaseObject, @@ -778,4 +784,6 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "takeScreenshot", &TakeScreenshot); V8Helpers::RegisterFunc(exports, "takeScreenshotGameOnly", &TakeScreenshotGameOnly); + + V8Helpers::RegisterFunc(exports, "isGameFocused", &IsGameFocused); }); From 3fed5cf7961ff64584a2533f099f15a27b373e3c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 3 Dec 2020 21:24:20 +0100 Subject: [PATCH 166/564] Added alt.getPermissionState --- src/bindings/Main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 198ee4f7..de964259 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -781,6 +781,7 @@ extern V8Module altModule( // V8Helpers::RegisterFunc(exports, "setAngularVelocity", &SetAngularVelocity); V8Helpers::RegisterFunc(exports, "isInStreamerMode", &IsInStreamerMode); + V8Helpers::RegisterFunc(exports, "getPermissionState", &GetPermissionState); V8Helpers::RegisterFunc(exports, "takeScreenshot", &TakeScreenshot); V8Helpers::RegisterFunc(exports, "takeScreenshotGameOnly", &TakeScreenshotGameOnly); From cae4345642c11e334726188658369cd0819fc041 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 4 Dec 2020 17:43:42 +0100 Subject: [PATCH 167/564] Add single time event handlers --- V8Helpers.h | 3 ++- V8ResourceImpl.cpp | 3 +++ V8ResourceImpl.h | 8 ++++---- bindings/Main.cpp | 12 ++++++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index d2711874..c99b7f0a 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -121,8 +121,9 @@ namespace V8 v8::UniquePersistent fn; SourceLocation location; bool removed = false; + bool once; - EventCallback(v8::Isolate *isolate, v8::Local _fn, SourceLocation &&location) : fn(isolate, _fn), location(std::move(location)) {} + EventCallback(v8::Isolate *isolate, v8::Local _fn, SourceLocation &&location, bool once = false) : fn(isolate, _fn), location(std::move(location)), once(once) {} }; class EventHandler diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index fa3723cc..a5135725 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -283,6 +283,9 @@ void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent *ev, const std::vecto << " was too long " << (GetTime() - time) << "ms" << Log::Endl; } } + + if (handler->once) + handler->removed = true; } } diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index 6fbd4a04..53b44b21 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -51,14 +51,14 @@ class V8ResourceImpl : public alt::IResource::Impl inline v8::Isolate *GetIsolate() { return isolate; } inline v8::Local GetContext() { return context.Get(isolate); } - void SubscribeLocal(const std::string &ev, v8::Local cb, V8::SourceLocation &&location) + void SubscribeLocal(const std::string &ev, v8::Local cb, V8::SourceLocation &&location, bool once = false) { - localHandlers.insert({ev, V8::EventCallback{isolate, cb, std::move(location)}}); + localHandlers.insert({ev, V8::EventCallback{isolate, cb, std::move(location), once}}); } - void SubscribeRemote(const std::string &ev, v8::Local cb, V8::SourceLocation &&location) + void SubscribeRemote(const std::string &ev, v8::Local cb, V8::SourceLocation &&location, bool once = false) { - remoteHandlers.insert({ev, V8::EventCallback{isolate, cb, std::move(location)}}); + remoteHandlers.insert({ev, V8::EventCallback{isolate, cb, std::move(location), once}}); } void UnsubscribeLocal(const std::string &ev, v8::Local cb) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index b2cf3458..11920683 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -23,6 +23,17 @@ static void On(const v8::FunctionCallbackInfo &info) resource->SubscribeLocal(evName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate)); } +static void Once(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, callback); + + resource->SubscribeLocal(evName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate), true); +} + static void Off(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -241,6 +252,7 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8Helpers::RegisterFunc(exports, "logError", &LogError); V8Helpers::RegisterFunc(exports, "on", &On); + V8Helpers::RegisterFunc(exports, "once", &Once); V8Helpers::RegisterFunc(exports, "off", &Off); V8Helpers::RegisterFunc(exports, "emit", &Emit); From 0286764f3a271d5713eb64e48d3281405db6b028 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 4 Dec 2020 22:13:22 +0100 Subject: [PATCH 168/564] Add alt.onceServer --- src/bindings/Main.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 198ee4f7..618e14c5 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -20,6 +20,17 @@ static void OnServer(const v8::FunctionCallbackInfo &info) resource->SubscribeRemote(eventName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate)); } +static void OnceServer(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, eventName); + V8_ARG_TO_FUNCTION(2, callback); + + resource->SubscribeRemote(eventName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate), true); +} + static void OffServer(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -715,6 +726,7 @@ extern V8Module altModule( V8::RegisterSharedMain(ctx, exports); V8Helpers::RegisterFunc(exports, "onServer", &OnServer); + V8Helpers::RegisterFunc(exports, "onceServer", &OnceServer); V8Helpers::RegisterFunc(exports, "offServer", &OffServer); V8Helpers::RegisterFunc(exports, "emitServer", &EmitServer); V8Helpers::RegisterFunc(exports, "gameControlsEnabled", &GameControlsEnabled); From 319397a950df344fa59af3cac385effe7e51e2db Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 4 Dec 2020 23:41:47 +0100 Subject: [PATCH 169/564] Updated helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 151f1ee1..14fa0191 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 151f1ee1e47e2ae2de1dd2422bb5ce20272cecb7 +Subproject commit 14fa019105fcc64838f441e001b4d457dcd2c69d From 901247ae8d185bddba76ef8bb76918063bb36ec5 Mon Sep 17 00:00:00 2001 From: Leon B Date: Sat, 5 Dec 2020 00:18:01 +0100 Subject: [PATCH 170/564] Add CMake CI --- .github/workflows/cmake.yml | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/cmake.yml diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml new file mode 100644 index 00000000..9a713794 --- /dev/null +++ b/.github/workflows/cmake.yml @@ -0,0 +1,40 @@ +name: CMake + +on: [push, pull_request] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally + # well on Windows or Mac. You can convert this to a matrix build if you need + # cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Create Build Environment + # Some projects don't allow in-source building, so create a separate build directory + # We'll use this as our working directory for all subsequent commands + run: cmake -E make_directory ${{runner.workspace}}/build + + - name: Configure CMake + # Use a bash shell so we can use the same syntax for environment variable + # access regardless of the host operating system + shell: bash + working-directory: ${{runner.workspace}/build + # Note the current convention is to use the -S and -B options here to specify source + # and build directories, but this is only available with CMake 3.13 and higher. + # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE + + - name: Build + working-directory: ${{runner.workspace}}/build + shell: bash + # Execute the build. You can specify a specific target with "--target " + run: cmake --build . --config $BUILD_TYPE + From 582628394676d6dfbcce68fd5679676d74e3d4f5 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 00:21:13 +0100 Subject: [PATCH 171/564] Fix typo in CI action --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 9a713794..055e0abc 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -26,7 +26,7 @@ jobs: # Use a bash shell so we can use the same syntax for environment variable # access regardless of the host operating system shell: bash - working-directory: ${{runner.workspace}/build + working-directory: ${{runner.workspace}}/build # Note the current convention is to use the -S and -B options here to specify source # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 From 8eb09efdcebe0707142ef75a8b38c57058317e9f Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 00:25:51 +0100 Subject: [PATCH 172/564] Remove useless CI step --- .github/workflows/cmake.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 055e0abc..90780888 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -5,6 +5,7 @@ on: [push, pull_request] env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release + CMAKE_DIR: BUILD jobs: build: @@ -17,24 +18,19 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Create Build Environment - # Some projects don't allow in-source building, so create a separate build directory - # We'll use this as our working directory for all subsequent commands - run: cmake -E make_directory ${{runner.workspace}}/build - - - name: Configure CMake + - name: Generate # Use a bash shell so we can use the same syntax for environment variable # access regardless of the host operating system shell: bash - working-directory: ${{runner.workspace}}/build + working-directory: ${{runner.workspace}} # Note the current convention is to use the -S and -B options here to specify source # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE + run: cmake . -BBUILD - name: Build - working-directory: ${{runner.workspace}}/build + working-directory: ${{runner.workspace}} shell: bash # Execute the build. You can specify a specific target with "--target " - run: cmake --build . --config $BUILD_TYPE + run: cmake --build $CMAKE_DIR --config $BUILD_TYPE From 7a95a5a29da5ad479f427c6693a3069c7c1af978 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 00:34:39 +0100 Subject: [PATCH 173/564] Fix paths --- .github/workflows/cmake.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 90780888..cbf48a3c 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -26,11 +26,11 @@ jobs: # Note the current convention is to use the -S and -B options here to specify source # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 - run: cmake . -BBUILD + run: cmake $GITHUB_WORKSPACE -BBUILD - name: Build - working-directory: ${{runner.workspace}} + working-directory: ${{runner.workspace}}/$GITHUB_WORKSPACE shell: bash # Execute the build. You can specify a specific target with "--target " - run: cmake --build $CMAKE_DIR --config $BUILD_TYPE + run: cmake --build BUILD --config $BUILD_TYPE From 2549975cfc5376e623b13144a0bd92350865754d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 00:36:40 +0100 Subject: [PATCH 174/564] Fix path again --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index cbf48a3c..8c5612f4 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -29,7 +29,7 @@ jobs: run: cmake $GITHUB_WORKSPACE -BBUILD - name: Build - working-directory: ${{runner.workspace}}/$GITHUB_WORKSPACE + working-directory: ${{runner.workspace}} shell: bash # Execute the build. You can specify a specific target with "--target " run: cmake --build BUILD --config $BUILD_TYPE From dd17d75ffac2d703efc64cfa75ca4ce88355c5eb Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 00:40:42 +0100 Subject: [PATCH 175/564] Add fetch submodules step --- .github/workflows/cmake.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 8c5612f4..95776fa5 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -18,6 +18,14 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Fetch submodules + shell: bash + working-directory: ${{runner.workspace}} + run: | + git submodule init + git submodule update + + - name: Generate # Use a bash shell so we can use the same syntax for environment variable # access regardless of the host operating system From dbeb0512cec187daf61b01e2f0967a1c05d68580 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 00:42:25 +0100 Subject: [PATCH 176/564] Fix syntax error --- .github/workflows/cmake.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 95776fa5..814d6701 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -21,10 +21,8 @@ jobs: - name: Fetch submodules shell: bash working-directory: ${{runner.workspace}} - run: | - git submodule init - git submodule update - + run: git submodule init + run: git submodule update - name: Generate # Use a bash shell so we can use the same syntax for environment variable From e4225c8772e7971134768fa447b270e1cf86766b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 00:43:56 +0100 Subject: [PATCH 177/564] Wtf --- .github/workflows/cmake.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 814d6701..6d12bf15 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -19,10 +19,10 @@ jobs: - uses: actions/checkout@v2 - name: Fetch submodules - shell: bash working-directory: ${{runner.workspace}} + shell: bash run: git submodule init - run: git submodule update + run: git submodule update - name: Generate # Use a bash shell so we can use the same syntax for environment variable From 3590fd2166fd5fd07a20697074aa71cc145af103 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 00:44:31 +0100 Subject: [PATCH 178/564] MAN --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 6d12bf15..dde8eea1 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Fetch submodules + - name: Submodules working-directory: ${{runner.workspace}} shell: bash run: git submodule init From 1e0dad3d7f53844d793c16aa9480a74c3938051d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 00:45:57 +0100 Subject: [PATCH 179/564] Why this shit no work --- .github/workflows/cmake.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index dde8eea1..e6d7ebc1 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -18,10 +18,14 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Submodules + - name: Fetch Submodules + # Set working directory working-directory: ${{runner.workspace}} + # Set shell shell: bash + # Init submodules run: git submodule init + # Update submodules run: git submodule update - name: Generate From 532f50a1c8f755c7ed3b2bbe4da08efaa3bf2207 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 00:50:21 +0100 Subject: [PATCH 180/564] Fix padding --- .github/workflows/cmake.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index e6d7ebc1..c267278b 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -19,14 +19,14 @@ jobs: - uses: actions/checkout@v2 - name: Fetch Submodules - # Set working directory - working-directory: ${{runner.workspace}} - # Set shell - shell: bash - # Init submodules - run: git submodule init - # Update submodules - run: git submodule update + # Set working directory + working-directory: ${{runner.workspace}} + # Set shell + shell: bash + # Init submodules + run: git submodule init + # Update submodules + run: git submodule update - name: Generate # Use a bash shell so we can use the same syntax for environment variable From 60e8f756e4ccabf5d054ddf109824a6870cbb290 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 00:50:59 +0100 Subject: [PATCH 181/564] Fix run command --- .github/workflows/cmake.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index c267278b..3eeef1f3 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -24,9 +24,9 @@ jobs: # Set shell shell: bash # Init submodules - run: git submodule init - # Update submodules - run: git submodule update + run: | + git submodule init + git submodule update - name: Generate # Use a bash shell so we can use the same syntax for environment variable From beef58d10588ff303968fb57da888df888481cd9 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 11:05:07 +0100 Subject: [PATCH 182/564] Remove working directory in CI --- .github/workflows/cmake.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 3eeef1f3..9a4ce55d 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -20,7 +20,7 @@ jobs: - name: Fetch Submodules # Set working directory - working-directory: ${{runner.workspace}} + #working-directory: ${{runner.workspace}} # Set shell shell: bash # Init submodules @@ -32,14 +32,14 @@ jobs: # Use a bash shell so we can use the same syntax for environment variable # access regardless of the host operating system shell: bash - working-directory: ${{runner.workspace}} + #working-directory: ${{runner.workspace}} # Note the current convention is to use the -S and -B options here to specify source # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 run: cmake $GITHUB_WORKSPACE -BBUILD - name: Build - working-directory: ${{runner.workspace}} + #working-directory: ${{runner.workspace}} shell: bash # Execute the build. You can specify a specific target with "--target " run: cmake --build BUILD --config $BUILD_TYPE From b2f68478102ba7e8199331b509b9cd7f2318cd65 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 12:15:21 +0100 Subject: [PATCH 183/564] Change to windows --- .github/workflows/cmake.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 9a4ce55d..ed03cd2d 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -13,7 +13,7 @@ jobs: # well on Windows or Mac. You can convert this to a matrix build if you need # cross-platform coverage. # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - runs-on: ubuntu-latest + runs-on: windows steps: - uses: actions/checkout@v2 @@ -36,7 +36,7 @@ jobs: # Note the current convention is to use the -S and -B options here to specify source # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 - run: cmake $GITHUB_WORKSPACE -BBUILD + run: cmake . -BBUILD - name: Build #working-directory: ${{runner.workspace}} From c4ce2118c2ee2a78c4420eb82fbd4ee06b17d4cd Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 12:16:45 +0100 Subject: [PATCH 184/564] Fix runs on --- .github/workflows/cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index ed03cd2d..b61c0a48 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -13,7 +13,7 @@ jobs: # well on Windows or Mac. You can convert this to a matrix build if you need # cross-platform coverage. # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - runs-on: windows + runs-on: windows-latest steps: - uses: actions/checkout@v2 From 613b675da2dc5c96b3a5393f8ba4cf322019f68e Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 5 Dec 2020 12:21:42 +0100 Subject: [PATCH 185/564] Remove comments --- .github/workflows/cmake.yml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b61c0a48..2cf22cfa 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -3,44 +3,26 @@ name: CMake on: [push, pull_request] env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release - CMAKE_DIR: BUILD jobs: build: - # The CMake configure and build commands are platform agnostic and should work equally - # well on Windows or Mac. You can convert this to a matrix build if you need - # cross-platform coverage. - # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix runs-on: windows-latest steps: - uses: actions/checkout@v2 - name: Fetch Submodules - # Set working directory - #working-directory: ${{runner.workspace}} - # Set shell shell: bash - # Init submodules run: | git submodule init git submodule update - name: Generate - # Use a bash shell so we can use the same syntax for environment variable - # access regardless of the host operating system shell: bash - #working-directory: ${{runner.workspace}} - # Note the current convention is to use the -S and -B options here to specify source - # and build directories, but this is only available with CMake 3.13 and higher. - # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 run: cmake . -BBUILD - name: Build - #working-directory: ${{runner.workspace}} shell: bash - # Execute the build. You can specify a specific target with "--target " run: cmake --build BUILD --config $BUILD_TYPE From 28feb50ff84b943900a50622805ac4d429a7ab96 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sun, 6 Dec 2020 17:54:20 +0100 Subject: [PATCH 186/564] add visibility bindings --- bindings/Entity.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index d48baa50..cdaa5ff4 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -52,7 +52,7 @@ static void RotationGetter(v8::Local, const v8::PropertyCallbackInfo V8_RETURN(resource->CreateVector3(ent->GetRotation())); } -static void ModelGetter(v8::Local, const v8::PropertyCallbackInfo &info) +static void ModelGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -61,6 +61,15 @@ static void ModelGetter(v8::Local, const v8::PropertyCallbackInfoGetModel()); } +static void VisibleGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); + + V8_RETURN_BOOLEAN(ent->GetVisible()); +} + static void HasSyncedMeta(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); @@ -143,6 +152,17 @@ static void ModelSetter(v8::Local, v8::Local val, const v } } +static void VisibleSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); + + V8_TO_BOOLEAN(val, toggle); + + ent->SetVisible(toggle); +} + static void SetSyncedMeta(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); @@ -280,6 +300,8 @@ extern V8Class v8Entity("Entity", v8WorldObject, [](v8::Local Date: Sun, 6 Dec 2020 18:00:55 +0100 Subject: [PATCH 187/564] update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 14fa0191..28feb50f 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 14fa019105fcc64838f441e001b4d457dcd2c69d +Subproject commit 28feb50ff84b943900a50622805ac4d429a7ab96 From 881e5888d01519aea75eeae6bc3e525621f439b6 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 7 Dec 2020 21:28:10 +0100 Subject: [PATCH 188/564] Add missing entity visible getter clientside --- bindings/Entity.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index cdaa5ff4..bf494dd3 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -320,5 +320,6 @@ extern V8Class v8Entity("Entity", v8WorldObject, [](v8::Local Date: Tue, 8 Dec 2020 04:49:34 +0100 Subject: [PATCH 189/564] add bindings for new events --- src/CV8Resource.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 0789ec89..ddd6c99d 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -315,6 +315,21 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) handlers = GetLocalHandlers("anyResourceError"); break; } + case alt::CEvent::Type::PLAYER_ENTER_VEHICLE: + { + handlers = GetLocalHandlers("enteredVehicle"); + break; + } + case alt::CEvent::Type::PLAYER_LEAVE_VEHICLE: + { + handlers = GetLocalHandlers("leftVehicle"); + break; + } + case alt::CEvent::Type::PLAYER_CHANGE_VEHICLE_SEAT: + { + handlers = GetLocalHandlers("changedVehicleSeat"); + break; + } } if (handlers.size() > 0) @@ -458,6 +473,32 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); break; } + case alt::CEvent::Type::PLAYER_ENTER_VEHICLE: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::Integer::New(isolate, ev->GetSeat())); + break; + } + case alt::CEvent::Type::PLAYER_LEAVE_VEHICLE: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::Integer::New(isolate, ev->GetSeat())); + break; + } + case alt::CEvent::Type::PLAYER_CHANGE_VEHICLE_SEAT: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::Integer::New(isolate, ev->GetOldSeat())); + args.push_back(v8::Integer::New(isolate, ev->GetNewSeat())); + break; + } + } InvokeEventHandlers(e, handlers, args); From 18208242acd2373b955b53de11c81c92ee3fc021 Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 11 Dec 2020 02:58:36 +0100 Subject: [PATCH 190/564] fix player weapon getter hash returning wrong value --- src/bindings/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index b9fdcc40..6027f803 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -69,7 +69,7 @@ static void CurrentWeaponGetter(v8::Local, const v8::PropertyCallbac V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_RETURN_INTEGER(player->GetCurrentWeapon()); + V8_RETURN_UINT32(player->GetCurrentWeapon()); } static void IsJumpingGetter(v8::Local, const v8::PropertyCallbackInfo& info) From 9b46f0035de20ebc224c282edaa91928f18addbc Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 11 Dec 2020 03:45:18 +0100 Subject: [PATCH 191/564] add macro --- V8Helpers.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/V8Helpers.h b/V8Helpers.h index c99b7f0a..a9198a50 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -287,6 +287,10 @@ namespace V8 #define V8_GET_THIS_INTERNAL_FIELD_INTEGER(idx, val) \ auto val = info.This()->GetInternalField((idx)-1)->IntegerValue(ctx).ToChecked(); +// idx starts with 1 +#define V8_GET_THIS_INTERNAL_FIELD_UINT32(idx, val) \ + auto val = info.This()->GetInternalField((idx)-1)->Uint32Value(ctx).ToChecked(); + #define V8_CHECK_CONSTRUCTOR() V8_CHECK(info.IsConstructCall(), "function can't be called without new") #define V8_CHECK_ARGS_LEN(count) V8_CHECK(info.Length() == (count), #count " arguments expected") From b3947ad67eb1805b026b24743fb3ac3fb659c81c Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 11 Dec 2020 03:45:31 +0100 Subject: [PATCH 192/564] fix alt.hash --- bindings/Main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 11920683..49eb9bac 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -9,7 +9,7 @@ static void HashCb(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, str); - V8_RETURN_INTEGER(alt::ICore::Instance().Hash(str)); + V8_RETURN_UINT32(alt::ICore::Instance().Hash(str)); } static void On(const v8::FunctionCallbackInfo &info) From a02a08549520d3214aee5a9e9f8f0dd47653cff3 Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 11 Dec 2020 03:46:53 +0100 Subject: [PATCH 193/564] make mapzoomdata use macros, update helpers --- src/bindings/Main.cpp | 4 +- src/bindings/MapZoomData.cpp | 135 ++++++++++++++++------------------- src/helpers | 2 +- 3 files changed, 64 insertions(+), 77 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index f52f9eb7..bea1d1b1 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -717,9 +717,9 @@ extern V8Module altModule( v8PointBlip, v8HandlingData, v8LocalStorage, - // v8MemoryBuffer, + v8MemoryBuffer, v8File, - // v8MapZoomData, + v8MapZoomData, v8Discord, v8Voice}, [](v8::Local ctx, v8::Local exports) { diff --git a/src/bindings/MapZoomData.cpp b/src/bindings/MapZoomData.cpp index e9aded71..5af47447 100644 --- a/src/bindings/MapZoomData.cpp +++ b/src/bindings/MapZoomData.cpp @@ -5,26 +5,28 @@ extern V8Class v8MapZoomData; static void Constructor(const v8::FunctionCallbackInfo& info) { - v8::Isolate *isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); + V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(info.IsConstructCall(), "HandlingData constructor is not a function"); - V8_CHECK(info.Length() == 1, "new HandlingData(...) expects 1 arg"); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN(1); V8_CHECK(info[0]->IsNumber() || info[0]->IsString(), "zoomDataId must be a number or string"); if (info[0]->IsNumber()) { - uint8_t zoomDataId = info[0]->Uint32Value(ctx).ToChecked(); + V8_ARG_TO_UINT32(1, zoomDataId); auto data = alt::ICore::Instance().GetMapData(zoomDataId); V8_CHECK(data, "zoomData with this id not found"); + info.This()->SetInternalField(0, info[0]); } else { - std::string zoomDataAlias = *v8::String::Utf8Value(info.GetIsolate(), info[0].As()); + V8_ARG_TO_STRING(1, zoomDataAlias); + auto data = alt::ICore::Instance().GetMapData(zoomDataAlias); V8_CHECK(data, "zoomData with this id not found"); + uint8_t id = alt::ICore::Instance().GetMapDataIDFromAlias(zoomDataAlias); info.This()->SetInternalField(0, v8::Integer::NewFromUnsigned(isolate, id)); } @@ -32,176 +34,161 @@ static void Constructor(const v8::FunctionCallbackInfo& info) static void Get(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - V8_CHECK(info.Length() == 1, "MapZoomData.get expects 1 arg"); + V8_GET_ISOLATE(info); + V8_CHECK_ARGS_LEN(1); V8_CHECK(info[0]->IsNumber() || info[0]->IsString(), "zoomDataId must be a number or string"); - std::vector> args{ - info[0]}; - - info.GetReturnValue().Set(v8MapZoomData.New(isolate->GetEnteredContext(), args)); + std::vector> args{ info[0] }; + V8_RETURN(v8MapZoomData.New(isolate->GetEnteredContext(), args)); } static void ResetAll(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - alt::ICore::Instance().ResetAllMapData(); } static void fZoomScaleGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_UINT32(1, zoomDataId); auto data = alt::ICore::Instance().GetMapData(zoomDataId); V8_CHECK(data, "zoom data not found"); - info.GetReturnValue().Set(v8::Number::New(isolate, data->GetZoomScale())); + V8_RETURN_NUMBER(data->GetZoomScale()); } static void fZoomScaleSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "fZoomScale must be a number"); - - uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_UINT32(1, zoomDataId); + V8_TO_NUMBER(val, fvalue); auto data = alt::ICore::Instance().GetMapData(zoomDataId); V8_CHECK(data, "zoom data not found"); - data->SetZoomScale((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + data->SetZoomScale((float)fvalue); } static void fZoomSpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_UINT32(1, zoomDataId); auto data = alt::ICore::Instance().GetMapData(zoomDataId); V8_CHECK(data, "zoom data not found"); info.GetReturnValue().Set(v8::Number::New(isolate, data->GetZoomSpeed())); + V8_RETURN_NUMBER(data->GetZoomSpeed()); } static void fZoomSpeedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "fZoomSpeed must be a number"); - - uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_UINT32(1, zoomDataId); + V8_TO_NUMBER(val, fvalue); auto data = alt::ICore::Instance().GetMapData(zoomDataId); V8_CHECK(data, "zoom data not found"); - data->SetZoomSpeed((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + data->SetZoomSpeed((float)fvalue); } static void fScrollSpeedGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_UINT32(1, zoomDataId); auto data = alt::ICore::Instance().GetMapData(zoomDataId); V8_CHECK(data, "zoom data not found"); info.GetReturnValue().Set(v8::Number::New(isolate, data->GetScrollSpeed())); + V8_RETURN_NUMBER(data->GetScrollSpeed()); } static void fScrollSpeedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "fScrollSpeed must be a number"); - - uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_UINT32(1, zoomDataId); + V8_TO_NUMBER(val, fvalue); auto data = alt::ICore::Instance().GetMapData(zoomDataId); V8_CHECK(data, "zoom data not found"); - data->SetScrollSpeed((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + data->SetScrollSpeed((float)fvalue); } static void vTilesXGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_UINT32(1, zoomDataId); auto data = alt::ICore::Instance().GetMapData(zoomDataId); V8_CHECK(data, "zoom data not found"); info.GetReturnValue().Set(v8::Number::New(isolate, data->GetTilesCountX())); + V8_RETURN_NUMBER(data->GetTilesCountX()); } static void vTilesXSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "vTilesX must be a number"); - - uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_UINT32(1, zoomDataId); + V8_TO_NUMBER(val, fvalue); auto data = alt::ICore::Instance().GetMapData(zoomDataId); V8_CHECK(data, "zoom data not found"); - data->SetTilesCountX((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + data->SetTilesCountX((float)fvalue); } static void vTilesYGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - - uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_UINT32(1, zoomDataId); auto data = alt::ICore::Instance().GetMapData(zoomDataId); V8_CHECK(data, "zoom data not found"); info.GetReturnValue().Set(v8::Number::New(isolate, data->GetTilesCountY())); + V8_RETURN_NUMBER(data->GetTilesCountY()); } static void vTilesYSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) { - v8::Isolate *isolate = info.GetIsolate(); - V8_CHECK(val->IsNumber(), "vTilesY must be a number"); - - uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_UINT32(1, zoomDataId); + V8_TO_NUMBER(val, fvalue); auto data = alt::ICore::Instance().GetMapData(zoomDataId); V8_CHECK(data, "zoom data not found"); - data->SetTilesCountY((float)val->NumberValue(isolate->GetEnteredContext()).ToChecked()); + data->SetTilesCountY((float)fvalue); } static void Reset(const v8::FunctionCallbackInfo &info) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); - - uint8_t zoomDataId = info.This()->GetInternalField(0)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_UINT32(1, zoomDataId); alt::ICore::Instance().ResetMapData(zoomDataId); } // Perhaps rename or something extern V8Class v8MapZoomData("MapZoomData", Constructor, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); - v8::Local proto = tpl->PrototypeTemplate(); + v8::Local proto = tpl->PrototypeTemplate(); - tpl->InstanceTemplate()->SetInternalFieldCount(1); + tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->Set(isolate, "get", v8::FunctionTemplate::New(isolate, &Get)); - tpl->Set(isolate, "resetAll", v8::FunctionTemplate::New(isolate, &ResetAll)); + V8::SetStaticMethod(isolate, tpl, "get", &Get); + V8::SetStaticMethod(isolate, tpl, "resetAll", &ResetAll); - V8::SetAccessor(isolate, tpl, "fZoomScale", &fZoomScaleGetter, &fZoomScaleSetter); - V8::SetAccessor(isolate, tpl, "fZoomSpeed", &fZoomSpeedGetter, &fZoomSpeedSetter); - V8::SetAccessor(isolate, tpl, "fScrollSpeed", &fScrollSpeedGetter, &fScrollSpeedSetter); - V8::SetAccessor(isolate, tpl, "vTilesX", &vTilesXGetter, &vTilesXSetter); - V8::SetAccessor(isolate, tpl, "vTilesY", &vTilesYGetter, &vTilesYSetter); - V8::SetMethod(isolate, tpl, "reset", &Reset); - }); + V8::SetAccessor(isolate, tpl, "fZoomScale", &fZoomScaleGetter, &fZoomScaleSetter); + V8::SetAccessor(isolate, tpl, "fZoomSpeed", &fZoomSpeedGetter, &fZoomSpeedSetter); + V8::SetAccessor(isolate, tpl, "fScrollSpeed", &fScrollSpeedGetter, &fScrollSpeedSetter); + V8::SetAccessor(isolate, tpl, "vTilesX", &vTilesXGetter, &vTilesXSetter); + V8::SetAccessor(isolate, tpl, "vTilesY", &vTilesYGetter, &vTilesYSetter); + V8::SetMethod(isolate, tpl, "reset", &Reset); +}); diff --git a/src/helpers b/src/helpers index 28feb50f..b3947ad6 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 28feb50ff84b943900a50622805ac4d429a7ab96 +Subproject commit b3947ad67eb1805b026b24743fb3ac3fb659c81c From 7e67c210c658182d2bca1b81a88d3324a3dbac7d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 12 Dec 2020 13:09:53 +0100 Subject: [PATCH 194/564] Overwrite global console object --- src/CV8Resource.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index ddd6c99d..b04ef8d6 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -120,6 +120,18 @@ bool CV8ResourceImpl::Start() modules.emplace(path, v8::UniquePersistent{isolate, curModule}); + // Overwrite global console object + auto console = ctx->Global()->Get(ctx, V8_NEW_STRING("console")).ToLocalChecked().As(); + if (!console.IsEmpty()) + { + auto altModule = V8Module::All().at("alt"); + auto exports = altModule->GetExports(isolate, ctx); + + console->Set(ctx, V8_NEW_STRING("log"), exports->Get(ctx, V8_NEW_STRING("log")).ToLocalChecked()); + console->Set(ctx, V8_NEW_STRING("warn"), exports->Get(ctx, V8_NEW_STRING("logWarning")).ToLocalChecked()); + console->Set(ctx, V8_NEW_STRING("error"), exports->Get(ctx, V8_NEW_STRING("logError")).ToLocalChecked()); + } + ctx->Global()->Set(ctx, v8::String::NewFromUtf8(isolate, "__internal_get_exports").ToLocalChecked(), v8::Function::New(ctx, &StaticRequire).ToLocalChecked()); bool res = curModule->InstantiateModule(ctx, CV8ScriptRuntime::ResolveModule).IsJust(); From 89047e5063bef67c61ba7e59a3ad9aa674c28c01 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 13 Dec 2020 11:08:49 +0100 Subject: [PATCH 195/564] Update .all getters to use cached arrays --- src/bindings/Player.cpp | 11 +---------- src/bindings/Vehicle.cpp | 11 +---------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 6027f803..9e8983bd 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -243,16 +243,7 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - v8::Local arr = v8::Array::New(isolate); - - uint16_t i = 0; - for (auto player : alt::ICore::Instance().GetPlayers()) - { - if (player) - arr->Set(ctx, i++, resource->GetOrCreateEntity(player.Get(), "Player")->GetJSVal(isolate)); - }; - - V8_RETURN(arr); + V8_RETURN(resource->GetAllPlayers()); } static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo& info) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 28986514..8eaefc68 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -506,16 +506,7 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - v8::Local arr = v8::Array::New(isolate); - - uint16_t i = 0; - for (auto vehicle : alt::ICore::Instance().GetVehicles()) - { - if (vehicle) - arr->Set(ctx, i++, resource->GetOrCreateEntity(vehicle.Get(), "Vehicle")->GetJSVal(isolate)); - }; - - V8_RETURN(arr); + V8_RETURN(resource->GetAllVehicles()); } static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) From 5a2bc49310ede06c1dd4d5c19817f61d87da1442 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sun, 13 Dec 2020 12:04:44 +0100 Subject: [PATCH 196/564] fix HandlingData::getForHandlingName --- src/bindings/HandlingData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/HandlingData.cpp b/src/bindings/HandlingData.cpp index b3967dfe..09c571fe 100644 --- a/src/bindings/HandlingData.cpp +++ b/src/bindings/HandlingData.cpp @@ -1736,7 +1736,7 @@ extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::LocalInstanceTemplate()->SetInternalFieldCount(1); - V8::SetMethod(isolate, tpl, "getForHandlingName", &GetForHandlingName); + V8::SetStaticMethod(isolate, tpl, "getForHandlingName", &GetForHandlingName); V8::SetAccessor(isolate, tpl, "handlingNameHash", &HandlingNameHashGetter); V8::SetAccessor(isolate, tpl, "mass", &MassGetter, &MassSetter); From 925dcb0c286b68be82ddac0d41315d88f30c826b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 13 Dec 2020 15:01:51 +0100 Subject: [PATCH 197/564] Make natives return instance of Vector3 class instead of object --- src/bindings/V8Natives.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 1dd4f353..6f04e343 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -2,6 +2,7 @@ #include "../helpers/V8Helpers.h" #include "../helpers/V8Module.h" #include "../helpers/Log.h" +#include "../helpers/V8ResourceImpl.h" static uint64_t pointers[32]; static uint32_t pointersCount = 0; @@ -168,15 +169,9 @@ static v8::Local GetReturn(alt::Ref scrCtx, al case alt::INative::Type::ARG_VECTOR3: { alt::INative::Vector3 val = scrCtx->ResultVector3(); - - v8::Local v8Ctx = isolate->GetEnteredContext(); - v8::Local vec = v8::Object::New(isolate); - - V8::DefineOwnProperty(isolate, v8Ctx, vec, "x", v8::Number::New(isolate, val.x), v8::PropertyAttribute::ReadOnly); - V8::DefineOwnProperty(isolate, v8Ctx, vec, "y", v8::Number::New(isolate, val.y), v8::PropertyAttribute::ReadOnly); - V8::DefineOwnProperty(isolate, v8Ctx, vec, "z", v8::Number::New(isolate, val.z), v8::PropertyAttribute::ReadOnly); - - return vec; + V8ResourceImpl* resource = V8ResourceImpl::Get(v8Ctx); + auto vector = resource->CreateVector3({ val.x, val.y, val.z }).As(); + return vector; } case alt::INative::Type::ARG_STRING: if (!scrCtx->ResultString()) From 962838a63bf2dc962c25283bc28a1e3c4b78ef6b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 13 Dec 2020 15:47:59 +0100 Subject: [PATCH 198/564] Clone array --- src/bindings/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 9e8983bd..adf92a1d 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -243,7 +243,7 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_RETURN(resource->GetAllPlayers()); + V8_RETURN(resource->GetAllPlayers()->Clone()); } static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo& info) From 11cded4f61b614b3048d854d787024daa9cd378d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 13 Dec 2020 19:51:33 +0100 Subject: [PATCH 199/564] Add clone for vehicle all getter too --- src/bindings/Vehicle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 8eaefc68..28939065 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -506,7 +506,7 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_RETURN(resource->GetAllVehicles()); + V8_RETURN(resource->GetAllVehicles()->Clone()); } static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) From 06cb4447639cc4546eb7fa378dcb04af6fc630d8 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 13 Dec 2020 20:22:12 +0100 Subject: [PATCH 200/564] Use external altModule --- src/CV8Resource.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index b04ef8d6..b4ff2393 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -53,6 +53,7 @@ void CV8ResourceImpl::ProcessDynamicImports() { dynamicImports.clear(); } +extern V8Module altModule; bool CV8ResourceImpl::Start() { if (resource->GetMain().IsEmpty()) @@ -124,8 +125,7 @@ bool CV8ResourceImpl::Start() auto console = ctx->Global()->Get(ctx, V8_NEW_STRING("console")).ToLocalChecked().As(); if (!console.IsEmpty()) { - auto altModule = V8Module::All().at("alt"); - auto exports = altModule->GetExports(isolate, ctx); + auto exports = altModule.GetExports(isolate, ctx); console->Set(ctx, V8_NEW_STRING("log"), exports->Get(ctx, V8_NEW_STRING("log")).ToLocalChecked()); console->Set(ctx, V8_NEW_STRING("warn"), exports->Get(ctx, V8_NEW_STRING("logWarning")).ToLocalChecked()); From 3fe3aae345711e0c341cfa25d79fdd3b66ef3ca8 Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 14 Dec 2020 12:38:50 +0100 Subject: [PATCH 201/564] fix crash with webview event --- src/CV8Resource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index b4ff2393..8d267ddb 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -222,7 +222,7 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) case alt::CEvent::Type::WEB_VIEW_EVENT: { auto ev = static_cast(e); - auto it = webViewHandlers.find(ev->GetTarget()); + auto it = webViewHandlers.find(ev->GetTarget().Get()); if (it != webViewHandlers.end()) { From c8faa29df7065c8abc71e4edae8ace0e364a8437 Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 14 Dec 2020 19:00:55 +0100 Subject: [PATCH 202/564] mark blip.scale as deprecated --- src/bindings/Blip.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index d4f2cb50..b18fc3a4 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -99,6 +99,18 @@ static void SizeGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK(false, "blip.scale is deprecated, use blip.size instead"); +} + +static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK(false, "blip.scale is deprecated, use blip.size instead"); +} + static void SpriteGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -578,6 +590,7 @@ extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local Date: Mon, 14 Dec 2020 19:20:13 +0100 Subject: [PATCH 203/564] readd blip.scale, quality ensured --- src/bindings/Blip.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index b18fc3a4..b016d468 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -102,13 +102,16 @@ static void SizeGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(false, "blip.scale is deprecated, use blip.size instead"); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_INTEGER(blip->GetScaleXY()[0]); } static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); - V8_CHECK(false, "blip.scale is deprecated, use blip.size instead"); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_INTEGER(value, val); + blip->SetScaleXY(val, val); } static void SpriteGetter(v8::Local, const v8::PropertyCallbackInfo& info) From 3bf54a3fac42e10dc93b9cb0370e1c0009f10ebf Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 19 Dec 2020 15:46:58 +0100 Subject: [PATCH 204/564] mark getForModel and brakeForce as deprecated --- src/bindings/HandlingData.cpp | 49 ++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/bindings/HandlingData.cpp b/src/bindings/HandlingData.cpp index 09c571fe..615134b0 100644 --- a/src/bindings/HandlingData.cpp +++ b/src/bindings/HandlingData.cpp @@ -24,13 +24,30 @@ static void GetForHandlingName(const v8::FunctionCallbackInfo& info) V8_ARG_TO_INTEGER(1, modelHash); std::vector> args{ - v8::Number::New(isolate, modelHash) + v8::Number::New(isolate, modelHash) }; extern V8Class v8HandlingData; V8_RETURN(v8HandlingData.New(isolate->GetEnteredContext(), args)); } +static void GetForHandlingNameDeprecated(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_INTEGER(1, modelHash); + + std::vector> args{ + v8::Number::New(isolate, modelHash) + }; + + extern V8Class v8HandlingData; + V8_RETURN(v8HandlingData.New(isolate->GetEnteredContext(), args)); + + Log::Warning << "alt.HandlingData.getForModel is deprecated and will be removed in the future. Please use alt.HandlingData.getForHandlingName" << Log::Endl; +} + static void HandlingNameHashGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -543,6 +560,34 @@ static void BrakeForceSetter(v8::Local, v8::Local val, co handling->SetBrakeForce(fvalue); } +static void BrakeForceGetterDeprecated(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + V8_RETURN_NUMBER(handling->GetBrakeForce()); + Log::Warning << "HandlingData.breakForce is deprecated and will be removed in the future. Please use HandlingData.brakeForce instead." << Log::Endl; +} + +static void BrakeForceSetterDeprecated(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + V8_TO_NUMBER(val, fvalue); + + handling->SetBrakeForce(fvalue); + Log::Warning << "HandlingData.breakForce is deprecated and will be removed in the future. Please use HandlingData.brakeForce instead." << Log::Endl; +} + static void unkFloat4Getter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -1737,6 +1782,7 @@ extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::LocalInstanceTemplate()->SetInternalFieldCount(1); V8::SetStaticMethod(isolate, tpl, "getForHandlingName", &GetForHandlingName); + V8::SetStaticMethod(isolate, tpl, "getForModel", &GetForHandlingNameDeprecated); V8::SetAccessor(isolate, tpl, "handlingNameHash", &HandlingNameHashGetter); V8::SetAccessor(isolate, tpl, "mass", &MassGetter, &MassSetter); @@ -1758,6 +1804,7 @@ extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::Local Date: Mon, 21 Dec 2020 01:20:00 +0100 Subject: [PATCH 205/564] Add to string method for classes --- src/bindings/Blip.cpp | 16 ++++++++++++++++ src/bindings/Player.cpp | 16 ++++++++++++++++ src/bindings/Vehicle.cpp | 16 ++++++++++++++++ src/bindings/WebView.cpp | 15 +++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index b016d468..e179fa7c 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -2,6 +2,20 @@ #include "../helpers/V8Helpers.h" #include "cpp-sdk/script-objects/IBlip.h" +static void ToString(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + auto blip = info.This(); + V8_OBJECT_GET_STRING(blip, "name", name); + V8_OBJECT_GET_STRING(blip, "category", category); + + std::ostringstream ss; + ss << "Blip{ name: " << name.CStr() << ", category: " << category.CStr() << " }"; + + V8_RETURN_STRING(ss.str().c_str()); +} + static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -589,6 +603,8 @@ extern V8Class v8WorldObject; extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local tpl){ v8::Isolate* isolate = v8::Isolate::GetCurrent(); + V8::SetMethod(isolate, tpl, "toString", ToString); + V8::SetStaticAccessor(isolate, tpl, "routeColor", &RouteColorGetter, &RouteColorSetter); V8::SetAccessor(isolate, tpl, "sprite", &SpriteGetter, &SpriteSetter); diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index adf92a1d..762e0511 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -9,6 +9,20 @@ using namespace alt; +static void ToString(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + auto player = info.This(); + V8_OBJECT_GET_INTEGER(player, "id", id); + V8_OBJECT_GET_STRING(player, "name", name); + + std::ostringstream ss; + ss << "Player{ id: " << std::to_string(id) << ", name: " << name.CStr() << " }"; + + V8_RETURN_STRING(ss.str().c_str()); +} + static void NameGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); @@ -273,6 +287,8 @@ extern V8Class v8Entity; extern V8Class v8Player("Player", v8Entity, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); + V8::SetMethod(isolate, tpl, "toString", ToString); + V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 28939065..d9da907a 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -9,6 +9,20 @@ using namespace alt; +static void ToString(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + auto vehicle = info.This(); + V8_OBJECT_GET_INTEGER(vehicle, "id", id); + V8_OBJECT_GET_NUMBER(vehicle, "model", model); + + std::ostringstream ss; + ss << "Vehicle{ id: " << std::to_string(id) << ", model: " << std::to_string((uint64_t)model) << " }"; + + V8_RETURN_STRING(ss.str().c_str()); +} + static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -529,6 +543,8 @@ extern V8Class v8Entity; extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); + V8::SetMethod(isolate, tpl, "toString", ToString); + V8::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index 4b0dfb3d..a225796e 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -8,6 +8,19 @@ using namespace alt; +static void ToString(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + auto webview = info.This(); + V8_OBJECT_GET_STRING(webview, "url", url); + + std::ostringstream ss; + ss << "WebView{ url: " << url.CStr() << " }"; + + V8_RETURN_STRING(ss.str().c_str()); +} + static void On(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -162,6 +175,8 @@ extern V8Class v8BaseObject; extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8::SetMethod(isolate, tpl, "toString", ToString); + V8::SetAccessor(isolate, tpl, "isVisible", &IsVisibleGetter, &IsVisibleSetter); V8::SetAccessor(isolate, tpl, "url", &URLGetter, &URLSetter); From f0f480cc9bd5265c5c74e59d92a32015cc7760b6 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 21 Dec 2020 01:27:25 +0100 Subject: [PATCH 206/564] Comment out unimplemented vehicle getters --- src/bindings/Vehicle.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 28939065..06eae1ec 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -542,13 +542,14 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); // proto->SetAccessor(v8::String::NewFromUtf8(isolate, "gravity", &GravityGetter).ToLocalChecked(), &GravitySetter); V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); + /* GETTERS BELOW ARE UNIMPLEMENTED V8::SetAccessor(isolate, tpl, "isDestroyed", &IsDestroyedGetter); V8::SetAccessor(isolate, tpl, "driver", &DriverGetter); // Appearance getters V8::SetAccessor(isolate, tpl, "modKitsCount", &ModKitsCountGetter); V8::SetAccessor(isolate, tpl, "modKit", &ModKitGetter); - //V8::SetAccessor(isolate, tpl, "hasCustomPrimaryColor", &IsPrimaryColorRGBGetter); + V8::SetAccessor(isolate, tpl, "hasCustomPrimaryColor", &IsPrimaryColorRGBGetter); V8::SetAccessor(isolate, tpl, "primaryColor", &PrimaryColorGetter); V8::SetAccessor(isolate, tpl, "customPrimaryColor", &PrimaryColorRGBGetter); //V8::SetAccessor(isolate, tpl, "hasCustomSecondaryColor", &IsSecondaryColorRGBGetter); @@ -600,5 +601,6 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local // Script getters V8::SetAccessor(isolate, tpl, "manualEngineControl", &IsManualEngineControlGetter); - //V8::SetAccessor(isolate, tpl, "handlingModified", &IsHandlingModifiedGetter); + V8::SetAccessor(isolate, tpl, "handlingModified", &IsHandlingModifiedGetter); + */ }); From 51b885fd2cbe42c737ba4a692931850c9e08a665 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 21 Dec 2020 01:32:37 +0100 Subject: [PATCH 207/564] Comment out unimplemented getters from player --- src/bindings/Player.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index adf92a1d..61b122f1 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -292,7 +292,7 @@ extern V8Class v8Player("Player", v8Entity, [](v8::Local t // Weapon getters V8::SetAccessor(isolate, tpl, "currentWeaponComponents", &CurrentWeaponComponentsGetter); - V8::SetAccessor(isolate, tpl, "currentWeaponTintIndex", &CurrentWeaponTintIndexGetter); + //V8::SetAccessor(isolate, tpl, "currentWeaponTintIndex", &CurrentWeaponTintIndexGetter); V8::SetAccessor(isolate, tpl, "currentWeapon", &CurrentWeaponGetter); V8::SetAccessor(isolate, tpl, "entityAimingAt", &EntityAimingAtGetter); V8::SetAccessor(isolate, tpl, "entityAimOffset", &EntityAimOffsetGetter); @@ -300,11 +300,11 @@ extern V8Class v8Player("Player", v8Entity, [](v8::Local t V8::SetAccessor(isolate, tpl, "aimPos", &AimPosGetter); // Gamestate getters - V8::SetAccessor(isolate, tpl, "isJumping", &IsJumpingGetter); + //V8::SetAccessor(isolate, tpl, "isJumping", &IsJumpingGetter); V8::SetAccessor(isolate, tpl, "isInRagdoll", &IsInRagdollGetter); V8::SetAccessor(isolate, tpl, "isAiming", &IsAimingGetter); - V8::SetAccessor(isolate, tpl, "isShooting", &IsShootingGetter); - V8::SetAccessor(isolate, tpl, "isReloading", &IsReloadingGetter); + //V8::SetAccessor(isolate, tpl, "isShooting", &IsShootingGetter); + //V8::SetAccessor(isolate, tpl, "isReloading", &IsReloadingGetter); V8::SetAccessor(isolate, tpl, "isDead", &IsDeadGetter); V8::SetAccessor(isolate, tpl, "moveSpeed", &MoveSpeedGetter); V8::SetAccessor(isolate, tpl, "headRot", &HeadRotationGetter); From 14e6b5a99aeb5dbe175230e50c51d80dd520bf89 Mon Sep 17 00:00:00 2001 From: Hazard Date: Mon, 21 Dec 2020 17:28:57 +0100 Subject: [PATCH 208/564] typo camberStiffnesss to camberStiffness --- src/bindings/Handling.cpp | 10 +++++----- src/bindings/HandlingData.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/bindings/Handling.cpp b/src/bindings/Handling.cpp index 3487099e..ae9e8e37 100644 --- a/src/bindings/Handling.cpp +++ b/src/bindings/Handling.cpp @@ -618,21 +618,21 @@ static void LowSpeedTractionLossMultSetter(v8::Local, v8::LocalGetHandling()->SetLowSpeedTractionLossMult(fvalue); } -static void CamberStiffnesssGetter(v8::Local, const v8::PropertyCallbackInfo& info) +static void CamberStiffnessGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - V8_RETURN_NUMBER(vehicle->GetHandling()->GetCamberStiffnesss()); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetCamberStiffness()); } -static void CamberStiffnesssSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +static void CamberStiffnessSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); - vehicle->GetHandling()->SetCamberStiffnesss(fvalue); + vehicle->GetHandling()->SetCamberStiffness(fvalue); } static void TractionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -1188,7 +1188,7 @@ extern V8Class v8Handling("Handling", Constructor, [](v8::Local, v8::LocalSetLowSpeedTractionLossMult(fvalue); } -static void CamberStiffnesssGetter(v8::Local, const v8::PropertyCallbackInfo& info) +static void CamberStiffnessGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -987,10 +987,10 @@ static void CamberStiffnesssGetter(v8::Local, const v8::PropertyCall auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - V8_RETURN_NUMBER(handling->GetCamberStiffnesss()); + V8_RETURN_NUMBER(handling->GetCamberStiffness()); } -static void CamberStiffnesssSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +static void CamberStiffnessSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -1001,7 +1001,7 @@ static void CamberStiffnesssSetter(v8::Local, v8::Local v V8_TO_NUMBER(val, fvalue); - handling->SetCamberStiffnesss(fvalue); + handling->SetCamberStiffness(fvalue); } static void TractionBiasFrontGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -1820,7 +1820,7 @@ extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::Local Date: Mon, 21 Dec 2020 17:47:33 +0100 Subject: [PATCH 209/564] Fix typo --- src/bindings/HandlingData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/HandlingData.cpp b/src/bindings/HandlingData.cpp index 9427ea12..52ee6a54 100644 --- a/src/bindings/HandlingData.cpp +++ b/src/bindings/HandlingData.cpp @@ -1820,7 +1820,7 @@ extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::Local Date: Tue, 22 Dec 2020 02:35:51 +0100 Subject: [PATCH 210/564] Enforced base object references --- V8Helpers.h | 8 +++----- V8ResourceImpl.cpp | 4 ++-- V8ResourceImpl.h | 2 +- bindings/BaseObject.cpp | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index a9198a50..f6d6369a 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -473,10 +473,8 @@ namespace V8 #define V8_RETURN_BASE_OBJECT(baseObjectRef) V8_RETURN(resource->GetBaseObjectOrNull(baseObjectRef)) -#define V8_BIND_BASE_OBJECT(baseObjectRef, msg) \ +#define V8_BIND_BASE_OBJECT(baseObjectRef) \ { \ - V8_CHECK(baseObjectRef, "Failed to create base object"); \ - auto baseObject = (baseObjectRef); \ - V8_CHECK(!baseObject.IsEmpty(), "Failed to bind base object"); \ - resource->BindEntity(info.This(), baseObject.Get()); \ + V8_CHECK(!baseObjectRef.IsEmpty(), "Failed to bind base object"); \ + resource->BindEntity(info.This(), baseObjectRef); \ } diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index a5135725..c86a50f2 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -81,10 +81,10 @@ void V8ResourceImpl::OnTick() promiseRejections.ProcessQueue(this); } -void V8ResourceImpl::BindEntity(v8::Local val, alt::IBaseObject *handle) +void V8ResourceImpl::BindEntity(v8::Local val, alt::Ref handle) { V8Entity *ent = new V8Entity(GetContext(), V8Entity::GetClass(handle), val, handle); - entities.insert({handle, ent}); + entities.insert({handle.Get(), ent}); } v8::Local V8ResourceImpl::GetBaseObjectOrNull(alt::IBaseObject *handle) diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index 53b44b21..1f0c9e50 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -116,7 +116,7 @@ class V8ResourceImpl : public alt::IResource::Impl return ent; } - void BindEntity(v8::Local val, alt::IBaseObject *handle); + void BindEntity(v8::Local val, alt::Ref handle); V8Entity *GetOrCreateEntity(alt::IBaseObject *handle, const char *className = "") { diff --git a/bindings/BaseObject.cpp b/bindings/BaseObject.cpp index 4dc76303..edb149d9 100644 --- a/bindings/BaseObject.cpp +++ b/bindings/BaseObject.cpp @@ -73,7 +73,7 @@ static void DeleteMeta(const v8::FunctionCallbackInfo &info) static void Destroy(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_GET_THIS_BASE_OBJECT(obj, alt::IBaseObject); From 430a2013b83ddff7398be743e09ff8e02d28eedb Mon Sep 17 00:00:00 2001 From: Hazard Date: Tue, 22 Dec 2020 02:36:05 +0100 Subject: [PATCH 211/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index b3947ad6..8a70195c 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit b3947ad67eb1805b026b24743fb3ac3fb659c81c +Subproject commit 8a70195c12e721d84154ecfd9ddf75141a0a4622 From 9efa5150606d4e6e316e3238d85371d595e59f95 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 23 Dec 2020 00:53:04 +0100 Subject: [PATCH 212/564] Add check for custom to string function --- bindings/Main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index ecc227fc..bdc494b1 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -136,13 +136,12 @@ static void Log(const v8::FunctionCallbackInfo &info) if (i > 0) ss << " "; - v8::Local str; - if (val->IsObject() || val->IsArray()) { + v8::Local str = val->ToString(ctx).ToLocalChecked(); + if (val->IsObject() && strcmp(*v8::String::Utf8Value(isolate, str), "[object Object]") == 0) { v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); v8::Local stringified; if (maybe.ToLocal(&stringified)) str = stringified; } - else str = val->ToString(ctx).ToLocalChecked(); ss << *v8::String::Utf8Value(isolate, str); } From c5c23feb410c4f3e338e4f77cfeda472128ef168 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 23 Dec 2020 11:41:20 +0100 Subject: [PATCH 213/564] readd LoadModel and LoadModelAsync and mark them as deprecated --- src/bindings/Main.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index bea1d1b1..5fbd6e7a 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -130,16 +130,6 @@ static void SetCursorPos(const v8::FunctionCallbackInfo &info) ICore::Instance().SetCursorPosition({ x, y }); } -static void LoadModel(const v8::FunctionCallbackInfo &info) -{ - Log::Warning << "loadModel is deprecated, this function has no effect" << Log::Endl; -} - -static void LoadModelAsync(const v8::FunctionCallbackInfo &info) -{ - Log::Warning << "loadModelAsync is deprecated, this function has no effect" << Log::Endl; -} - static void IsTextureExistInArchetype(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); @@ -679,6 +669,30 @@ static void IsGameFocused(const v8::FunctionCallbackInfo &info) V8_RETURN_BOOLEAN(alt::ICore::Instance().IsGameFocused()); } +static void LoadModel(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_UINT32(1, hash); + + alt::ICore::Instance().LoadModel(hash); + + Log::Warning << "loadModel is deprecated and it will be removed in the future. Please use the native requestModel." << Log::Endl; +} + +static void LoadModelAsync(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_UINT32(1, hash); + + alt::ICore::Instance().LoadModelAsync(hash); + + Log::Warning << "loadModelAsync is deprecated and it will be removed in the future. Please use the native requestModel." << Log::Endl; +} + extern V8Class v8Vector3, v8RGBA, v8BaseObject, @@ -799,4 +813,7 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "takeScreenshotGameOnly", &TakeScreenshotGameOnly); V8Helpers::RegisterFunc(exports, "isGameFocused", &IsGameFocused); + + V8Helpers::RegisterFunc(exports, "loadModel", &LoadModel); + V8Helpers::RegisterFunc(exports, "loadModelAsync", &LoadModelAsync); }); From 6d3dab945ae640609f7c41ed61222c07cc24bf9c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 23 Dec 2020 11:44:01 +0100 Subject: [PATCH 214/564] Add check for custom to string for warning and error --- bindings/Main.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index bdc494b1..7f6cba5c 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -164,13 +164,12 @@ static void LogWarning(const v8::FunctionCallbackInfo &info) if (i > 0) ss << " "; - v8::Local str; - if (val->IsObject() || val->IsArray()) { + v8::Local str = val->ToString(ctx).ToLocalChecked(); + if (val->IsObject() && strcmp(*v8::String::Utf8Value(isolate, str), "[object Object]") == 0) { v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); v8::Local stringified; if (maybe.ToLocal(&stringified)) str = stringified; } - else str = val->ToString(ctx).ToLocalChecked(); ss << *v8::String::Utf8Value(isolate, str); } @@ -193,13 +192,12 @@ static void LogError(const v8::FunctionCallbackInfo &info) if (i > 0) ss << " "; - v8::Local str; - if (val->IsObject() || val->IsArray()) { + v8::Local str = val->ToString(ctx).ToLocalChecked(); + if (val->IsObject() && strcmp(*v8::String::Utf8Value(isolate, str), "[object Object]") == 0) { v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); v8::Local stringified; if (maybe.ToLocal(&stringified)) str = stringified; } - else str = val->ToString(ctx).ToLocalChecked(); ss << *v8::String::Utf8Value(isolate, str); } From 5b7b8067d07be9d99ab2d150e619cc8ad1cc987d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 23 Dec 2020 13:18:40 +0100 Subject: [PATCH 215/564] Rework event handling --- src/CV8Resource.cpp | 318 +++------------------------------------- src/CV8Resource.h | 2 + src/events/Entity.cpp | 41 ++++++ src/events/Main.cpp | 101 +++++++++++++ src/events/Meta.cpp | 62 ++++++++ src/events/Resource.cpp | 41 ++++++ src/events/Vehicle.cpp | 45 ++++++ 7 files changed, 311 insertions(+), 299 deletions(-) create mode 100644 src/events/Entity.cpp create mode 100644 src/events/Main.cpp create mode 100644 src/events/Meta.cpp create mode 100644 src/events/Resource.cpp create mode 100644 src/events/Vehicle.cpp diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 8d267ddb..42a905f6 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -205,318 +205,38 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); - auto ctx = GetContext(); - if (ctx.IsEmpty()) - return true; - v8::Context::Scope scope(ctx); - - std::vector handlers; - - switch (e->GetType()) - { - case alt::CEvent::Type::RENDER: - { - handlers = GetLocalHandlers("render"); - break; - } - case alt::CEvent::Type::WEB_VIEW_EVENT: - { - auto ev = static_cast(e); - auto it = webViewHandlers.find(ev->GetTarget().Get()); - if (it != webViewHandlers.end()) - { - auto range = it->second.equal_range(ev->GetName().ToString()); + v8::Context::Scope scope(GetContext()); - for (auto it = range.first; it != range.second; ++it) - handlers.push_back(&it->second); - } + V8::EventHandler* handler = V8::EventHandler::Get(e); + if (!handler) + return true; - break; - } - case alt::CEvent::Type::CLIENT_SCRIPT_EVENT: - { - auto ev = static_cast(e); - handlers = GetLocalHandlers(ev->GetName().ToString()); - break; - } - case alt::CEvent::Type::SERVER_SCRIPT_EVENT: - { - auto ev = static_cast(e); - handlers = GetRemoteHandlers(ev->GetName().ToString()); - break; - } - case alt::CEvent::Type::KEYBOARD_EVENT: + std::vector callbacks = handler->GetCallbacks(this, e); + if (callbacks.size() > 0) { - auto ev = static_cast(e); - - if (ev->GetKeyState() == alt::CKeyboardEvent::KeyState::UP) - handlers = GetLocalHandlers("keyup"); - else if (ev->GetKeyState() == alt::CKeyboardEvent::KeyState::DOWN) - handlers = GetLocalHandlers("keydown"); + std::vector> args = handler->GetArgs(this, e); - break; + InvokeEventHandlers(e, callbacks, args); } - case alt::CEvent::Type::CONNECTION_COMPLETE: - { - handlers = GetLocalHandlers("connectionComplete"); - CV8ScriptRuntime* runtime = CV8ScriptRuntime::instance; - runtime->resourcesLoaded = true; - ProcessDynamicImports(); + return true; +} - break; - } - case alt::CEvent::Type::DISCONNECT_EVENT: - { - handlers = GetLocalHandlers("disconnect"); - break; - } - case alt::CEvent::Type::REMOVE_ENTITY_EVENT: - { - handlers = GetLocalHandlers("removeEntity"); - break; - } - case alt::CEvent::Type::CONSOLE_COMMAND_EVENT: - { - handlers = GetLocalHandlers("consoleCommand"); - break; - } - case alt::CEvent::Type::GAME_ENTITY_CREATE: - { - handlers = GetLocalHandlers("gameEntityCreate"); - break; - } - case alt::CEvent::Type::GAME_ENTITY_DESTROY: - { - handlers = GetLocalHandlers("gameEntityDestroy"); - break; - } - case alt::CEvent::Type::SYNCED_META_CHANGE: - { - handlers = GetLocalHandlers("syncedMetaChange"); - break; - } - case alt::CEvent::Type::STREAM_SYNCED_META_CHANGE: - { - handlers = GetLocalHandlers("streamSyncedMetaChange"); - break; - } - case alt::CEvent::Type::GLOBAL_META_CHANGE: - { - handlers = GetLocalHandlers("globalMetaChange"); - break; - } - case alt::CEvent::Type::GLOBAL_SYNCED_META_CHANGE: - { - handlers = GetLocalHandlers("globalSyncedMetaChange"); - break; - } - case alt::CEvent::Type::RESOURCE_START: - { - handlers = GetLocalHandlers("anyResourceStart"); - break; - } - case alt::CEvent::Type::RESOURCE_STOP: - { - handlers = GetLocalHandlers("anyResourceStop"); - break; - } - case alt::CEvent::Type::RESOURCE_ERROR: - { - handlers = GetLocalHandlers("anyResourceError"); - break; - } - case alt::CEvent::Type::PLAYER_ENTER_VEHICLE: - { - handlers = GetLocalHandlers("enteredVehicle"); - break; - } - case alt::CEvent::Type::PLAYER_LEAVE_VEHICLE: - { - handlers = GetLocalHandlers("leftVehicle"); - break; - } - case alt::CEvent::Type::PLAYER_CHANGE_VEHICLE_SEAT: - { - handlers = GetLocalHandlers("changedVehicleSeat"); - break; - } - } +std::vector CV8ResourceImpl::GetWebviewHandlers(alt::Ref view, const std::string &name) +{ + std::vector handlers; + auto it = webViewHandlers.find(view.Get()); - if (handlers.size() > 0) + if (it != webViewHandlers.end()) { - std::vector> args; - - switch (e->GetType()) - { - case alt::CEvent::Type::WEB_VIEW_EVENT: - { - auto ev = static_cast(e); - - V8Helpers::MValueArgsToV8(ev->GetArgs(), args); - - break; - } - case alt::CEvent::Type::CLIENT_SCRIPT_EVENT: - { - auto ev = static_cast(e); - - V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + auto range = it->second.equal_range(name); - break; - } - case alt::CEvent::Type::SERVER_SCRIPT_EVENT: - { - auto ev = static_cast(e); - - V8Helpers::MValueArgsToV8(ev->GetArgs(), args); - - break; - } - case alt::CEvent::Type::KEYBOARD_EVENT: - { - auto ev = static_cast(e); - - args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetKeyCode())); - - break; - } - case alt::CEvent::Type::CONNECTION_COMPLETE: - { - break; - } - case alt::CEvent::Type::DISCONNECT_EVENT: - { - CV8ScriptRuntime::instance->resourcesLoaded = false; - break; - } - case alt::CEvent::Type::REMOVE_ENTITY_EVENT: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetEntity().Get())->GetJSVal(isolate)); - - break; - } - case alt::CEvent::Type::CONSOLE_COMMAND_EVENT: - { - auto ev = static_cast(e); - - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetName().CStr()).ToLocalChecked()); - for (auto &arg : ev->GetArgs()) - args.push_back(v8::String::NewFromUtf8(isolate, arg.CStr()).ToLocalChecked()); - - break; - } - case alt::CEvent::Type::GAME_ENTITY_CREATE: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - - break; - } - case alt::CEvent::Type::GAME_ENTITY_DESTROY: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - - break; - } - case alt::CEvent::Type::SYNCED_META_CHANGE: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); - args.push_back(V8Helpers::MValueToV8(ev->GetVal())); - args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); - - break; - } - case alt::CEvent::Type::STREAM_SYNCED_META_CHANGE: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); - args.push_back(V8Helpers::MValueToV8(ev->GetVal())); - args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); - - break; - } - case alt::CEvent::Type::GLOBAL_META_CHANGE: - { - auto ev = static_cast(e); - - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); - args.push_back(V8Helpers::MValueToV8(ev->GetVal())); - args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); - - break; - } - case alt::CEvent::Type::GLOBAL_SYNCED_META_CHANGE: - { - auto ev = static_cast(e); - - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); - args.push_back(V8Helpers::MValueToV8(ev->GetVal())); - args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); - - break; - } - case alt::CEvent::Type::RESOURCE_START: - { - auto ev = static_cast(e); - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); - break; - } - case alt::CEvent::Type::RESOURCE_STOP: - { - auto ev = static_cast(e); - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); - break; - } - case alt::CEvent::Type::RESOURCE_ERROR: - { - auto ev = static_cast(e); - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); - break; - } - case alt::CEvent::Type::PLAYER_ENTER_VEHICLE: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - args.push_back(v8::Integer::New(isolate, ev->GetSeat())); - break; - } - case alt::CEvent::Type::PLAYER_LEAVE_VEHICLE: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - args.push_back(v8::Integer::New(isolate, ev->GetSeat())); - break; - } - case alt::CEvent::Type::PLAYER_CHANGE_VEHICLE_SEAT: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - args.push_back(v8::Integer::New(isolate, ev->GetOldSeat())); - args.push_back(v8::Integer::New(isolate, ev->GetNewSeat())); - break; - } - - } - - InvokeEventHandlers(e, handlers, args); + for (auto it = range.first; it != range.second; ++it) + handlers.push_back(&it->second); } - return true; + return handlers; } void CV8ResourceImpl::OnTick() diff --git a/src/CV8Resource.h b/src/CV8Resource.h index da33ebe3..018513ed 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -59,6 +59,8 @@ class CV8ResourceImpl : public V8ResourceImpl } } + std::vector GetWebviewHandlers(alt::Ref view, const std::string &name); + void AddOwned(alt::Ref handle) { ownedObjects.insert(handle); diff --git a/src/events/Entity.cpp b/src/events/Entity.cpp new file mode 100644 index 00000000..33b35ea1 --- /dev/null +++ b/src/events/Entity.cpp @@ -0,0 +1,41 @@ +#include "../helpers/V8ResourceImpl.h" +#include "../helpers/V8Helpers.h" + +#include "cpp-sdk/events/CRemoveEntityEvent.h" +#include "cpp-sdk/events/CGameEntityCreateEvent.h" +#include "cpp-sdk/events/CGameEntityDestroyEvent.h" + +#include "cpp-sdk/SDK.h" + +using alt::CEvent; +using EventType = CEvent::Type; + +V8::LocalEventHandler removeEntity( + EventType::REMOVE_ENTITY_EVENT, + "removeEntity", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(resource->GetOrCreateEntity(ev->GetEntity().Get())->GetJSVal(isolate)); + }); + +V8::LocalEventHandler gameEntityCreate( + EventType::GAME_ENTITY_CREATE, + "gameEntityCreate", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + }); + +V8::LocalEventHandler gameEntityDestroy( + EventType::GAME_ENTITY_DESTROY, + "gameEntityDestroy", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + }); \ No newline at end of file diff --git a/src/events/Main.cpp b/src/events/Main.cpp new file mode 100644 index 00000000..2d6ae9df --- /dev/null +++ b/src/events/Main.cpp @@ -0,0 +1,101 @@ +#include "../CV8Resource.h" +#include "../CV8ScriptRuntime.h" + +#include "../helpers/V8ResourceImpl.h" +#include "../helpers/V8Helpers.h" + +#include "cpp-sdk/events/CConnectionComplete.h" +#include "cpp-sdk/events/CDisconnectEvent.h" +#include "cpp-sdk/events/CRenderEvent.h" +#include "cpp-sdk/events/CConsoleCommandEvent.h" +#include "cpp-sdk/events/CClientScriptEvent.h" +#include "cpp-sdk/events/CServerScriptEvent.h" +#include "cpp-sdk/events/CKeyboardEvent.h" +#include "cpp-sdk/events/CWebViewEvent.h" + +#include "cpp-sdk/SDK.h" + +using alt::CEvent; +using EventType = CEvent::Type; + +V8::EventHandler clientScriptEvent( + EventType::CLIENT_SCRIPT_EVENT, + [](V8ResourceImpl* resource, const CEvent* e) { + auto ev = static_cast(e); + return resource->GetLocalHandlers(ev->GetName().ToString()); + }, + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + } +); + +V8::EventHandler serverScriptEvent( + EventType::SERVER_SCRIPT_EVENT, + [](V8ResourceImpl* resource, const CEvent* e) { + auto ev = static_cast(e); + return resource->GetRemoteHandlers(ev->GetName().ToString()); + }, + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + } +); + +V8::EventHandler webviewEvent( + EventType::WEB_VIEW_EVENT, + [](V8ResourceImpl* resource, const CEvent* e) { + auto ev = static_cast(e); + + return static_cast(resource)->GetWebviewHandlers(ev->GetTarget(), ev->GetName().ToString()); + }, + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + } +); + +V8::EventHandler keyboardEvent( + EventType::KEYBOARD_EVENT, + [](V8ResourceImpl* resource, const CEvent* e) { + auto ev = static_cast(e); + if (ev->GetKeyState() == alt::CKeyboardEvent::KeyState::UP) + return resource->GetLocalHandlers("keyup"); + else if (ev->GetKeyState() == alt::CKeyboardEvent::KeyState::DOWN) + return resource->GetLocalHandlers("keydown"); + }, + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetKeyCode())); + } +); + +V8::LocalEventHandler render( + EventType::RENDER, + "render", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + }); + +V8::LocalEventHandler connectionComplete( + EventType::CONNECTION_COMPLETE, + "connectionComplete", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + CV8ScriptRuntime* runtime = CV8ScriptRuntime::instance; + if(!runtime->resourcesLoaded) + { + runtime->resourcesLoaded = true; + static_cast(resource)->ProcessDynamicImports(); + } + }); + +V8::LocalEventHandler disconnect( + EventType::DISCONNECT_EVENT, + "disconnect", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + CV8ScriptRuntime::instance->resourcesLoaded = false; + }); diff --git a/src/events/Meta.cpp b/src/events/Meta.cpp new file mode 100644 index 00000000..4925e83a --- /dev/null +++ b/src/events/Meta.cpp @@ -0,0 +1,62 @@ +#include "../helpers/V8ResourceImpl.h" +#include "../helpers/V8Helpers.h" + +#include "cpp-sdk/events/CSyncedMetaDataChangeEvent.h" +#include "cpp-sdk/events/CStreamSyncedMetaDataChangeEvent.h" +#include "cpp-sdk/events/CGlobalSyncedMetaDataChangeEvent.h" +#include "cpp-sdk/events/CGlobalMetaDataChangeEvent.h" + +#include "cpp-sdk/SDK.h" + +using alt::CEvent; +using EventType = CEvent::Type; + +V8::LocalEventHandler syncedMetaChange( + EventType::SYNCED_META_CHANGE, + "syncedMetaChange", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(V8_NEW_STRING(ev->GetKey().CStr())); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + }); + +V8::LocalEventHandler streamSyncedMetaChange( + EventType::STREAM_SYNCED_META_CHANGE, + "streamSyncedMetaChange", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(V8_NEW_STRING(ev->GetKey().CStr())); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + }); + +V8::LocalEventHandler globalSyncedMetaChange( + EventType::GLOBAL_SYNCED_META_CHANGE, + "globalSyncedMetaChange", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(V8_NEW_STRING(ev->GetKey().CStr())); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + }); + +V8::LocalEventHandler globalMetaChange( + EventType::GLOBAL_META_CHANGE, + "globalMetaChange", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(V8_NEW_STRING(ev->GetKey().CStr())); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + }); \ No newline at end of file diff --git a/src/events/Resource.cpp b/src/events/Resource.cpp new file mode 100644 index 00000000..18beef7b --- /dev/null +++ b/src/events/Resource.cpp @@ -0,0 +1,41 @@ +#include "../helpers/V8ResourceImpl.h" +#include "../helpers/V8Helpers.h" + +#include "cpp-sdk/events/CResourceStartEvent.h" +#include "cpp-sdk/events/CResourceStopEvent.h" +#include "cpp-sdk/events/CResourceErrorEvent.h" + +#include "cpp-sdk/SDK.h" + +using alt::CEvent; +using EventType = CEvent::Type; + +V8::LocalEventHandler anyResourceStart( + EventType::RESOURCE_START, + "anyResourceStart", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(V8_NEW_STRING(ev->GetResource()->GetName().CStr())); + }); + +V8::LocalEventHandler anyResourceStop( + EventType::RESOURCE_STOP, + "anyResourceStop", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(V8_NEW_STRING(ev->GetResource()->GetName().CStr())); + }); + +V8::LocalEventHandler anyResourceError( + EventType::RESOURCE_ERROR, + "anyResourceError", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(V8_NEW_STRING(ev->GetResource()->GetName().CStr())); + }); \ No newline at end of file diff --git a/src/events/Vehicle.cpp b/src/events/Vehicle.cpp new file mode 100644 index 00000000..7899ac12 --- /dev/null +++ b/src/events/Vehicle.cpp @@ -0,0 +1,45 @@ +#include "../helpers/V8ResourceImpl.h" +#include "../helpers/V8Helpers.h" + +#include "cpp-sdk/events/CPlayerEnterVehicleEvent.h" +#include "cpp-sdk/events/CPlayerLeaveVehicleEvent.h" +#include "cpp-sdk/events/CPlayerChangeVehicleSeatEvent.h" + +#include "cpp-sdk/SDK.h" + +using alt::CEvent; +using EventType = CEvent::Type; + +V8::LocalEventHandler enteredVehicle( + EventType::PLAYER_ENTER_VEHICLE, + "enteredVehicle", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetSeat())); + }); + +V8::LocalEventHandler leftVehicle( + EventType::PLAYER_LEAVE_VEHICLE, + "leftVehicle", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetSeat())); + }); + +V8::LocalEventHandler changedVehicleSeat( + EventType::PLAYER_CHANGE_VEHICLE_SEAT, + "changedVehicleSeat", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetOldSeat())); + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetNewSeat())); + }); From fbd134e812de95b3eab6c8aa5e242b93d4b98164 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 23 Dec 2020 23:55:39 +0100 Subject: [PATCH 216/564] Fix dynamic import after resource restart --- src/CV8Resource.cpp | 17 +++++++++++++++-- src/CV8ScriptRuntime.h | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 8d267ddb..264111b3 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -189,8 +189,22 @@ bool CV8ResourceImpl::Stop() v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); + auto ctx = GetContext(); + v8::Context::Scope scope(ctx); - v8::Context::Scope scope(GetContext()); + auto resources = static_cast(resource->GetRuntime())->GetResources(); + auto name = this->resource->GetName().ToString(); + for(auto res : resources) + { + auto it = res->modules.find(name); + if(it != res->modules.end()) { + res->modules.erase(it); + } + auto found = res->requires.find(name); + if(found != res->requires.end()) { + res->requires.erase(found); + } + } DispatchStopEvent(); } @@ -806,7 +820,6 @@ v8::MaybeLocal CV8ResourceImpl::ResolveModule(const std::string &_na if (!maybeModule.IsEmpty()) { v8::Local _module = maybeModule.ToLocalChecked(); - modules.emplace(name, v8::UniquePersistent{isolate, _module}); /*v8::Maybe res = _module->InstantiateModule(GetContext(), CV8ScriptRuntime::ResolveModule); diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 8c2fb8cd..10aa06fa 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -12,6 +12,7 @@ class CV8ScriptRuntime : public alt::IScriptRuntime { static constexpr char inspectorViewStr[] = "alt:V Multiplayer"; + std::unordered_set resources; std::unique_ptr platform; v8::Isolate::CreateParams create_params; v8::Isolate *isolate; @@ -31,12 +32,16 @@ class CV8ScriptRuntime : public alt::IScriptRuntime alt::IResource::Impl *CreateImpl(alt::IResource *resource) override { - return new CV8ResourceImpl(resource, isolate); + auto res = new CV8ResourceImpl(resource, isolate); + resources.insert(res); + return res; } void DestroyImpl(alt::IResource::Impl *impl) override { - delete static_cast(impl); + auto res = static_cast(impl); + resources.erase(res); + delete res; } void OnTick() override @@ -48,6 +53,11 @@ class CV8ScriptRuntime : public alt::IScriptRuntime v8::platform::PumpMessageLoop(platform.get(), isolate); } + std::unordered_set GetResources() + { + return resources; + } + void HeapBenchmark() { v8::HeapStatistics heapStats; From cb1537569fbd9c5c1508607ca6561600c8af4c12 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Thu, 24 Dec 2020 23:51:53 +0300 Subject: [PATCH 217/564] Fixed blip.scale --- src/bindings/Blip.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index b016d468..a458f784 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -103,14 +103,14 @@ static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfoGetScaleXY()[0]); + V8_RETURN_NUMBER(blip->GetScaleXY()[0]); } static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); + V8_TO_NUMBER(value, val); blip->SetScaleXY(val, val); } From 7aa497ae0990ad0b9b8d5b98b04cc0fdf1bba9d6 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 24 Dec 2020 23:00:06 +0100 Subject: [PATCH 218/564] Remove render event handling --- src/CV8Resource.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 8d267ddb..4699312b 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -214,11 +214,11 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) switch (e->GetType()) { - case alt::CEvent::Type::RENDER: - { - handlers = GetLocalHandlers("render"); - break; - } + //case alt::CEvent::Type::RENDER: + //{ + // handlers = GetLocalHandlers("render"); + // break; + //} case alt::CEvent::Type::WEB_VIEW_EVENT: { auto ev = static_cast(e); From 96199f516b92665d8381bd0f3a4e01e4b941f365 Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 25 Dec 2020 19:56:00 +0100 Subject: [PATCH 219/564] fix deprecated message for getForModelName, fix Handling --- src/bindings/Handling.cpp | 217 ++++++++++++++++++++++------------ src/bindings/HandlingData.cpp | 4 +- 2 files changed, 143 insertions(+), 78 deletions(-) diff --git a/src/bindings/Handling.cpp b/src/bindings/Handling.cpp index ae9e8e37..10d5f7df 100644 --- a/src/bindings/Handling.cpp +++ b/src/bindings/Handling.cpp @@ -51,6 +51,7 @@ static void MassSetter(v8::Local, v8::Local val, const v8 V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetMass(fvalue); } @@ -67,6 +68,7 @@ static void InitialDragCoeffSetter(v8::Local, v8::Local v V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetInitialDragCoeff(fvalue); } @@ -83,6 +85,7 @@ static void DownforceModifierSetter(v8::Local, v8::Local V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetDownforceModifier(fvalue); } @@ -99,6 +102,7 @@ static void unkFloat1Setter(v8::Local, v8::Local val, con V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetunkFloat1(fvalue); } @@ -115,6 +119,7 @@ static void unkFloat2Setter(v8::Local, v8::Local val, con V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetunkFloat2(fvalue); } @@ -135,6 +140,7 @@ static void CentreOfMassOffsetSetter(v8::Local, v8::Local V8_OBJECT_GET_NUMBER(pos, "y", y); V8_OBJECT_GET_NUMBER(pos, "z", z); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetCentreOfMassOffset({ x, y, z }); } @@ -156,6 +162,7 @@ static void InertiaMultiplierSetter(v8::Local, v8::Local V8_OBJECT_GET_NUMBER(pos, "y", y); V8_OBJECT_GET_NUMBER(pos, "z", z); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetInertiaMultiplier({ x, y, z }); } @@ -173,6 +180,7 @@ static void PercentSubmergedSetter(v8::Local, v8::Local v V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetPercentSubmerged(fvalue); } @@ -190,6 +198,7 @@ static void PercentSubmergedRatioSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetPercentSubmergedRatio(fvalue); } @@ -207,6 +216,7 @@ static void DriveBiasFrontSetter(v8::Local, v8::Local val V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetDriveBiasFront(fvalue); } @@ -224,6 +234,7 @@ static void AccelerationSetter(v8::Local, v8::Local val, V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetAcceleration(fvalue); } @@ -241,6 +252,7 @@ static void InitialDriveGearsSetter(v8::Local, v8::Local V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_INTEGER(val, ivalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetInitialDriveGears(ivalue); } @@ -258,6 +270,7 @@ static void DriveInertiaSetter(v8::Local, v8::Local val, V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetDriveInertia(fvalue); } @@ -275,6 +288,7 @@ static void ClutchChangeRateScaleUpShiftSetter(v8::Local, v8::Local< V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetClutchChangeRateScaleUpShift(fvalue); } @@ -292,6 +306,7 @@ static void ClutchChangeRateScaleDownShiftSetter(v8::Local, v8::Loca V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetClutchChangeRateScaleDownShift(fvalue); } @@ -309,6 +324,7 @@ static void InitialDriveForceSetter(v8::Local, v8::Local V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetInitialDriveForce(fvalue); } @@ -326,6 +342,7 @@ static void DriveMaxFlatVelSetter(v8::Local, v8::Local va V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetDriveMaxFlatVel(fvalue); } @@ -343,6 +360,7 @@ static void InitialDriveMaxFlatVelSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetInitialDriveMaxFlatVel(fvalue); } @@ -360,6 +378,7 @@ static void BrakeForceSetter(v8::Local, v8::Local val, co V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetBrakeForce(fvalue); } @@ -377,6 +396,7 @@ static void unkFloat4Setter(v8::Local, v8::Local val, con V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetunkFloat4(fvalue); } @@ -394,6 +414,7 @@ static void BrakeBiasFrontSetter(v8::Local, v8::Local val V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetBrakeBiasFront(fvalue); } @@ -411,6 +432,7 @@ static void BrakeBiasRearSetter(v8::Local, v8::Local val, V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetBrakeBiasRear(fvalue); } @@ -428,6 +450,7 @@ static void HandBrakeForceSetter(v8::Local, v8::Local val V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetHandBrakeForce(fvalue); } @@ -445,6 +468,7 @@ static void SteeringLockSetter(v8::Local, v8::Local val, V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetSteeringLock(fvalue); } @@ -462,6 +486,7 @@ static void SteeringLockRatioSetter(v8::Local, v8::Local V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetSteeringLockRatio(fvalue); } @@ -479,6 +504,7 @@ static void TractionCurveMaxSetter(v8::Local, v8::Local v V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetTractionCurveMax(fvalue); } @@ -496,6 +522,7 @@ static void TractionCurveMaxRatioSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetTractionCurveMaxRatio(fvalue); } @@ -513,6 +540,7 @@ static void TractionCurveMinSetter(v8::Local, v8::Local v V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetTractionCurveMin(fvalue); } @@ -530,6 +558,7 @@ static void TractionCurveMinRatioSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetTractionCurveMinRatio(fvalue); } @@ -547,6 +576,7 @@ static void TractionCurveLateralSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetTractionCurveLateral(fvalue); } @@ -564,6 +594,7 @@ static void TractionCurveLateralRatioSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetTractionCurveLateralRatio(fvalue); } @@ -581,6 +612,7 @@ static void TractionSpringDeltaMaxSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetTractionSpringDeltaMax(fvalue); } @@ -598,6 +630,7 @@ static void TractionSpringDeltaMaxRatioSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetTractionSpringDeltaMaxRatio(fvalue); } @@ -615,6 +648,7 @@ static void LowSpeedTractionLossMultSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetLowSpeedTractionLossMult(fvalue); } @@ -632,6 +666,7 @@ static void CamberStiffnessSetter(v8::Local, v8::Local va V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetCamberStiffness(fvalue); } @@ -649,6 +684,7 @@ static void TractionBiasFrontSetter(v8::Local, v8::Local V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetTractionBiasFront(fvalue); } @@ -666,6 +702,7 @@ static void TractionBiasRearSetter(v8::Local, v8::Local v V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetTractionBiasRear(fvalue); } @@ -683,6 +720,7 @@ static void TractionLossMultSetter(v8::Local, v8::Local v V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetTractionLossMult(fvalue); } @@ -700,6 +738,7 @@ static void SuspensionForceSetter(v8::Local, v8::Local va V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetSuspensionForce(fvalue); } @@ -717,6 +756,7 @@ static void SuspensionCompDampSetter(v8::Local, v8::Local V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetSuspensionCompDamp(fvalue); } @@ -734,6 +774,7 @@ static void SuspensionReboundDampSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetSuspensionReboundDamp(fvalue); } @@ -751,6 +792,7 @@ static void SuspensionUpperLimitSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetSuspensionUpperLimit(fvalue); } @@ -768,6 +810,7 @@ static void SuspensionLowerLimitSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetSuspensionLowerLimit(fvalue); } @@ -785,6 +828,7 @@ static void SuspensionRaiseSetter(v8::Local, v8::Local va V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetSuspensionRaise(fvalue); } @@ -802,6 +846,7 @@ static void SuspensionBiasFrontSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetSuspensionBiasFront(fvalue); } @@ -819,6 +864,7 @@ static void SuspensionBiasRearSetter(v8::Local, v8::Local V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetSuspensionBiasRear(fvalue); } @@ -836,6 +882,7 @@ static void AntiRollBarForceSetter(v8::Local, v8::Local v V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetAntiRollBarForce(fvalue); } @@ -853,6 +900,7 @@ static void AntiRollBarBiasFrontSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetAntiRollBarBiasFront(fvalue); } @@ -870,6 +918,7 @@ static void AntiRollBarBiasRearSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetAntiRollBarBiasRear(fvalue); } @@ -887,6 +936,7 @@ static void RollCentreHeightFrontSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetRollCentreHeightFront(fvalue); } @@ -904,6 +954,7 @@ static void RollCentreHeightRearSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetRollCentreHeightRear(fvalue); } @@ -921,6 +972,7 @@ static void CollisionDamageMultSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetCollisionDamageMult(fvalue); } @@ -938,6 +990,7 @@ static void WeaponDamageMultSetter(v8::Local, v8::Local v V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetWeaponDamageMult(fvalue); } @@ -955,6 +1008,7 @@ static void DeformationDamageMultSetter(v8::Local, v8::LocalReplaceHandling(); vehicle->GetHandling()->SetDeformationDamageMult(fvalue); } @@ -972,6 +1026,7 @@ static void EngineDamageMultSetter(v8::Local, v8::Local v V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetEngineDamageMult(fvalue); } @@ -989,6 +1044,7 @@ static void PetrolTankVolumeSetter(v8::Local, v8::Local v V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetPetrolTankVolume(fvalue); } @@ -1006,6 +1062,7 @@ static void OilVolumeSetter(v8::Local, v8::Local val, con V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetOilVolume(fvalue); } @@ -1023,6 +1080,7 @@ static void unkFloat5Setter(v8::Local, v8::Local val, con V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetunkFloat5(fvalue); } @@ -1040,6 +1098,7 @@ static void SeatOffsetDistXSetter(v8::Local, v8::Local va V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetSeatOffsetDistX(fvalue); } @@ -1057,6 +1116,7 @@ static void SeatOffsetDistYSetter(v8::Local, v8::Local va V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetSeatOffsetDistY(fvalue); } @@ -1074,6 +1134,7 @@ static void SeatOffsetDistZSetter(v8::Local, v8::Local va V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetSeatOffsetDistZ(fvalue); } @@ -1091,6 +1152,7 @@ static void MonetaryValueSetter(v8::Local, v8::Local val, V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_INTEGER(val, ivalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetMonetaryValue(ivalue); } @@ -1108,6 +1170,7 @@ static void ModelFlagsSetter(v8::Local, v8::Local val, co V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_INTEGER(val, ivalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetModelFlags(ivalue); } @@ -1124,6 +1187,7 @@ static void HandlingFlagsSetter(v8::Local, v8::Local val, V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_INTEGER(val, ivalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetHandlingFlags(ivalue); } @@ -1140,83 +1204,84 @@ static void DamageFlagsSetter(v8::Local, v8::Local val, c V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_INTEGER(val, ivalue); + vehicle->ReplaceHandling(); vehicle->GetHandling()->SetDamageFlags(ivalue); } extern V8Class v8Handling("Handling", Constructor, [](v8::Local tpl) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - - v8::Local proto = tpl->PrototypeTemplate(); - - tpl->InstanceTemplate()->SetInternalFieldCount(1); - - V8::SetMethod(isolate, tpl, "isModified", &IsModified); - V8::SetMethod(isolate, tpl, "reset", &Reset); - - V8::SetAccessor(isolate, tpl, "handlingNameHash", &HandlingNameHashGetter); - V8::SetAccessor(isolate, tpl, "mass", &MassGetter, &MassSetter); - V8::SetAccessor(isolate, tpl, "initialDragCoeff", &InitialDragCoeffGetter, &InitialDragCoeffSetter); - V8::SetAccessor(isolate, tpl, "downforceModifier", &DownforceModifierGetter, &DownforceModifierSetter); - V8::SetAccessor(isolate, tpl, "unkFloat1", &unkFloat1Getter, &unkFloat1Setter); - V8::SetAccessor(isolate, tpl, "unkFloat2", &unkFloat2Getter, &unkFloat2Setter); - V8::SetAccessor(isolate, tpl, "centreOfMassOffset", &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); - V8::SetAccessor(isolate, tpl, "inertiaMultiplier", &InertiaMultiplierGetter, &InertiaMultiplierSetter); - V8::SetAccessor(isolate, tpl, "percentSubmerged", &PercentSubmergedGetter, &PercentSubmergedSetter); - V8::SetAccessor(isolate, tpl, "percentSubmergedRatio", &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); - V8::SetAccessor(isolate, tpl, "driveBiasFront", &DriveBiasFrontGetter, &DriveBiasFrontSetter); - V8::SetAccessor(isolate, tpl, "acceleration", &AccelerationGetter, &AccelerationSetter); - V8::SetAccessor(isolate, tpl, "initialDriveGears", &InitialDriveGearsGetter, &InitialDriveGearsSetter); - V8::SetAccessor(isolate, tpl, "driveInertia", &DriveInertiaGetter, &DriveInertiaSetter); - V8::SetAccessor(isolate, tpl, "clutchChangeRateScaleUpShift", &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); - V8::SetAccessor(isolate, tpl, "clutchChangeRateScaleDownShift", &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); - V8::SetAccessor(isolate, tpl, "initialDriveForce", &InitialDriveForceGetter, &InitialDriveForceSetter); - V8::SetAccessor(isolate, tpl, "driveMaxFlatVel", &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); - V8::SetAccessor(isolate, tpl, "initialDriveMaxFlatVel", &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); - V8::SetAccessor(isolate, tpl, "brakeForce", &BrakeForceGetter, &BrakeForceSetter); - V8::SetAccessor(isolate, tpl, "unkFloat4", &unkFloat4Getter, &unkFloat4Setter); - V8::SetAccessor(isolate, tpl, "brakeBiasFront", &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); - V8::SetAccessor(isolate, tpl, "brakeBiasRear", &BrakeBiasRearGetter, &BrakeBiasRearSetter); - V8::SetAccessor(isolate, tpl, "handBrakeForce", &HandBrakeForceGetter, &HandBrakeForceSetter); - V8::SetAccessor(isolate, tpl, "steeringLock", &SteeringLockGetter, &SteeringLockSetter); - V8::SetAccessor(isolate, tpl, "steeringLockRatio", &SteeringLockRatioGetter, &SteeringLockRatioSetter); - V8::SetAccessor(isolate, tpl, "tractionCurveMax", &TractionCurveMaxGetter, &TractionCurveMaxSetter); - V8::SetAccessor(isolate, tpl, "tractionCurveMaxRatio", &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); - V8::SetAccessor(isolate, tpl, "tractionCurveMin", &TractionCurveMinGetter, &TractionCurveMinSetter); - V8::SetAccessor(isolate, tpl, "tractionCurveMinRatio", &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); - V8::SetAccessor(isolate, tpl, "tractionCurveLateral", &TractionCurveLateralGetter, &TractionCurveLateralSetter); - V8::SetAccessor(isolate, tpl, "tractionCurveLateralRatio", &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); - V8::SetAccessor(isolate, tpl, "tractionSpringDeltaMax", &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); - V8::SetAccessor(isolate, tpl, "tractionSpringDeltaMaxRatio", &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); - V8::SetAccessor(isolate, tpl, "lowSpeedTractionLossMult", &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); - V8::SetAccessor(isolate, tpl, "camberStiffness", &CamberStiffnessGetter, &CamberStiffnessSetter); - V8::SetAccessor(isolate, tpl, "tractionBiasFront", &TractionBiasFrontGetter, &TractionBiasFrontSetter); - V8::SetAccessor(isolate, tpl, "tractionBiasRear", &TractionBiasRearGetter, &TractionBiasRearSetter); - V8::SetAccessor(isolate, tpl, "tractionLossMult", &TractionLossMultGetter, &TractionLossMultSetter); - V8::SetAccessor(isolate, tpl, "suspensionForce", &SuspensionForceGetter, &SuspensionForceSetter); - V8::SetAccessor(isolate, tpl, "suspensionCompDamp", &SuspensionCompDampGetter, &SuspensionCompDampSetter); - V8::SetAccessor(isolate, tpl, "suspensionReboundDamp", &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); - V8::SetAccessor(isolate, tpl, "suspensionUpperLimit", &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); - V8::SetAccessor(isolate, tpl, "suspensionLowerLimit", &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); - V8::SetAccessor(isolate, tpl, "suspensionRaise", &SuspensionRaiseGetter, &SuspensionRaiseSetter); - V8::SetAccessor(isolate, tpl, "suspensionBiasFront", &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); - V8::SetAccessor(isolate, tpl, "suspensionBiasRear", &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); - V8::SetAccessor(isolate, tpl, "antiRollBarForce", &AntiRollBarForceGetter, &AntiRollBarForceSetter); - V8::SetAccessor(isolate, tpl, "antiRollBarBiasFront", &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); - V8::SetAccessor(isolate, tpl, "antiRollBarBiasRear", &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); - V8::SetAccessor(isolate, tpl, "rollCentreHeightFront", &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); - V8::SetAccessor(isolate, tpl, "rollCentreHeightRear", &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); - V8::SetAccessor(isolate, tpl, "collisionDamageMult", &CollisionDamageMultGetter, &CollisionDamageMultSetter); - V8::SetAccessor(isolate, tpl, "weaponDamageMult", &WeaponDamageMultGetter, &WeaponDamageMultSetter); - V8::SetAccessor(isolate, tpl, "deformationDamageMult", &DeformationDamageMultGetter, &DeformationDamageMultSetter); - V8::SetAccessor(isolate, tpl, "engineDamageMult", &EngineDamageMultGetter, &EngineDamageMultSetter); - V8::SetAccessor(isolate, tpl, "petrolTankVolume", &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); - V8::SetAccessor(isolate, tpl, "oilVolume", &OilVolumeGetter, &OilVolumeSetter); - V8::SetAccessor(isolate, tpl, "unkFloat5", &unkFloat5Getter, &unkFloat5Setter); - V8::SetAccessor(isolate, tpl, "seatOffsetDistX", &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); - V8::SetAccessor(isolate, tpl, "seatOffsetDistY", &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); - V8::SetAccessor(isolate, tpl, "seatOffsetDistZ", &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); - V8::SetAccessor(isolate, tpl, "monetaryValue", &MonetaryValueGetter, &MonetaryValueSetter); - V8::SetAccessor(isolate, tpl, "modelFlags", &ModelFlagsGetter, &ModelFlagsSetter); - V8::SetAccessor(isolate, tpl, "handlingFlags", &HandlingFlagsGetter, &HandlingFlagsSetter); - V8::SetAccessor(isolate, tpl, "damageFlags", &DamageFlagsGetter, &DamageFlagsSetter); - }); \ No newline at end of file + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + v8::Local proto = tpl->PrototypeTemplate(); + + tpl->InstanceTemplate()->SetInternalFieldCount(1); + + V8::SetMethod(isolate, tpl, "isModified", &IsModified); + V8::SetMethod(isolate, tpl, "reset", &Reset); + + V8::SetAccessor(isolate, tpl, "handlingNameHash", &HandlingNameHashGetter); + V8::SetAccessor(isolate, tpl, "mass", &MassGetter, &MassSetter); + V8::SetAccessor(isolate, tpl, "initialDragCoeff", &InitialDragCoeffGetter, &InitialDragCoeffSetter); + V8::SetAccessor(isolate, tpl, "downforceModifier", &DownforceModifierGetter, &DownforceModifierSetter); + V8::SetAccessor(isolate, tpl, "unkFloat1", &unkFloat1Getter, &unkFloat1Setter); + V8::SetAccessor(isolate, tpl, "unkFloat2", &unkFloat2Getter, &unkFloat2Setter); + V8::SetAccessor(isolate, tpl, "centreOfMassOffset", &CentreOfMassOffsetGetter, &CentreOfMassOffsetSetter); + V8::SetAccessor(isolate, tpl, "inertiaMultiplier", &InertiaMultiplierGetter, &InertiaMultiplierSetter); + V8::SetAccessor(isolate, tpl, "percentSubmerged", &PercentSubmergedGetter, &PercentSubmergedSetter); + V8::SetAccessor(isolate, tpl, "percentSubmergedRatio", &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter); + V8::SetAccessor(isolate, tpl, "driveBiasFront", &DriveBiasFrontGetter, &DriveBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "acceleration", &AccelerationGetter, &AccelerationSetter); + V8::SetAccessor(isolate, tpl, "initialDriveGears", &InitialDriveGearsGetter, &InitialDriveGearsSetter); + V8::SetAccessor(isolate, tpl, "driveInertia", &DriveInertiaGetter, &DriveInertiaSetter); + V8::SetAccessor(isolate, tpl, "clutchChangeRateScaleUpShift", &ClutchChangeRateScaleUpShiftGetter, &ClutchChangeRateScaleUpShiftSetter); + V8::SetAccessor(isolate, tpl, "clutchChangeRateScaleDownShift", &ClutchChangeRateScaleDownShiftGetter, &ClutchChangeRateScaleDownShiftSetter); + V8::SetAccessor(isolate, tpl, "initialDriveForce", &InitialDriveForceGetter, &InitialDriveForceSetter); + V8::SetAccessor(isolate, tpl, "driveMaxFlatVel", &DriveMaxFlatVelGetter, &DriveMaxFlatVelSetter); + V8::SetAccessor(isolate, tpl, "initialDriveMaxFlatVel", &InitialDriveMaxFlatVelGetter, &InitialDriveMaxFlatVelSetter); + V8::SetAccessor(isolate, tpl, "brakeForce", &BrakeForceGetter, &BrakeForceSetter); + V8::SetAccessor(isolate, tpl, "unkFloat4", &unkFloat4Getter, &unkFloat4Setter); + V8::SetAccessor(isolate, tpl, "brakeBiasFront", &BrakeBiasFrontGetter, &BrakeBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "brakeBiasRear", &BrakeBiasRearGetter, &BrakeBiasRearSetter); + V8::SetAccessor(isolate, tpl, "handBrakeForce", &HandBrakeForceGetter, &HandBrakeForceSetter); + V8::SetAccessor(isolate, tpl, "steeringLock", &SteeringLockGetter, &SteeringLockSetter); + V8::SetAccessor(isolate, tpl, "steeringLockRatio", &SteeringLockRatioGetter, &SteeringLockRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMax", &TractionCurveMaxGetter, &TractionCurveMaxSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMaxRatio", &TractionCurveMaxRatioGetter, &TractionCurveMaxRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMin", &TractionCurveMinGetter, &TractionCurveMinSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveMinRatio", &TractionCurveMinRatioGetter, &TractionCurveMinRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveLateral", &TractionCurveLateralGetter, &TractionCurveLateralSetter); + V8::SetAccessor(isolate, tpl, "tractionCurveLateralRatio", &TractionCurveLateralRatioGetter, &TractionCurveLateralRatioSetter); + V8::SetAccessor(isolate, tpl, "tractionSpringDeltaMax", &TractionSpringDeltaMaxGetter, &TractionSpringDeltaMaxSetter); + V8::SetAccessor(isolate, tpl, "tractionSpringDeltaMaxRatio", &TractionSpringDeltaMaxRatioGetter, &TractionSpringDeltaMaxRatioSetter); + V8::SetAccessor(isolate, tpl, "lowSpeedTractionLossMult", &LowSpeedTractionLossMultGetter, &LowSpeedTractionLossMultSetter); + V8::SetAccessor(isolate, tpl, "camberStiffness", &CamberStiffnessGetter, &CamberStiffnessSetter); + V8::SetAccessor(isolate, tpl, "tractionBiasFront", &TractionBiasFrontGetter, &TractionBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "tractionBiasRear", &TractionBiasRearGetter, &TractionBiasRearSetter); + V8::SetAccessor(isolate, tpl, "tractionLossMult", &TractionLossMultGetter, &TractionLossMultSetter); + V8::SetAccessor(isolate, tpl, "suspensionForce", &SuspensionForceGetter, &SuspensionForceSetter); + V8::SetAccessor(isolate, tpl, "suspensionCompDamp", &SuspensionCompDampGetter, &SuspensionCompDampSetter); + V8::SetAccessor(isolate, tpl, "suspensionReboundDamp", &SuspensionReboundDampGetter, &SuspensionReboundDampSetter); + V8::SetAccessor(isolate, tpl, "suspensionUpperLimit", &SuspensionUpperLimitGetter, &SuspensionUpperLimitSetter); + V8::SetAccessor(isolate, tpl, "suspensionLowerLimit", &SuspensionLowerLimitGetter, &SuspensionLowerLimitSetter); + V8::SetAccessor(isolate, tpl, "suspensionRaise", &SuspensionRaiseGetter, &SuspensionRaiseSetter); + V8::SetAccessor(isolate, tpl, "suspensionBiasFront", &SuspensionBiasFrontGetter, &SuspensionBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "suspensionBiasRear", &SuspensionBiasRearGetter, &SuspensionBiasRearSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarForce", &AntiRollBarForceGetter, &AntiRollBarForceSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarBiasFront", &AntiRollBarBiasFrontGetter, &AntiRollBarBiasFrontSetter); + V8::SetAccessor(isolate, tpl, "antiRollBarBiasRear", &AntiRollBarBiasRearGetter, &AntiRollBarBiasRearSetter); + V8::SetAccessor(isolate, tpl, "rollCentreHeightFront", &RollCentreHeightFrontGetter, &RollCentreHeightFrontSetter); + V8::SetAccessor(isolate, tpl, "rollCentreHeightRear", &RollCentreHeightRearGetter, &RollCentreHeightRearSetter); + V8::SetAccessor(isolate, tpl, "collisionDamageMult", &CollisionDamageMultGetter, &CollisionDamageMultSetter); + V8::SetAccessor(isolate, tpl, "weaponDamageMult", &WeaponDamageMultGetter, &WeaponDamageMultSetter); + V8::SetAccessor(isolate, tpl, "deformationDamageMult", &DeformationDamageMultGetter, &DeformationDamageMultSetter); + V8::SetAccessor(isolate, tpl, "engineDamageMult", &EngineDamageMultGetter, &EngineDamageMultSetter); + V8::SetAccessor(isolate, tpl, "petrolTankVolume", &PetrolTankVolumeGetter, &PetrolTankVolumeSetter); + V8::SetAccessor(isolate, tpl, "oilVolume", &OilVolumeGetter, &OilVolumeSetter); + V8::SetAccessor(isolate, tpl, "unkFloat5", &unkFloat5Getter, &unkFloat5Setter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistX", &SeatOffsetDistXGetter, &SeatOffsetDistXSetter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistY", &SeatOffsetDistYGetter, &SeatOffsetDistYSetter); + V8::SetAccessor(isolate, tpl, "seatOffsetDistZ", &SeatOffsetDistZGetter, &SeatOffsetDistZSetter); + V8::SetAccessor(isolate, tpl, "monetaryValue", &MonetaryValueGetter, &MonetaryValueSetter); + V8::SetAccessor(isolate, tpl, "modelFlags", &ModelFlagsGetter, &ModelFlagsSetter); + V8::SetAccessor(isolate, tpl, "handlingFlags", &HandlingFlagsGetter, &HandlingFlagsSetter); + V8::SetAccessor(isolate, tpl, "damageFlags", &DamageFlagsGetter, &DamageFlagsSetter); +}); \ No newline at end of file diff --git a/src/bindings/HandlingData.cpp b/src/bindings/HandlingData.cpp index 52ee6a54..ee2aae60 100644 --- a/src/bindings/HandlingData.cpp +++ b/src/bindings/HandlingData.cpp @@ -45,7 +45,7 @@ static void GetForHandlingNameDeprecated(const v8::FunctionCallbackInfoGetEnteredContext(), args)); - Log::Warning << "alt.HandlingData.getForModel is deprecated and will be removed in the future. Please use alt.HandlingData.getForHandlingName" << Log::Endl; + Log::Warning << "alt.HandlingData.getForModelName is deprecated and will be removed in the future. Please use alt.HandlingData.getForHandlingName" << Log::Endl; } static void HandlingNameHashGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -1782,7 +1782,7 @@ extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::LocalInstanceTemplate()->SetInternalFieldCount(1); V8::SetStaticMethod(isolate, tpl, "getForHandlingName", &GetForHandlingName); - V8::SetStaticMethod(isolate, tpl, "getForModel", &GetForHandlingNameDeprecated); + V8::SetStaticMethod(isolate, tpl, "getForModelName", &GetForHandlingNameDeprecated); V8::SetAccessor(isolate, tpl, "handlingNameHash", &HandlingNameHashGetter); V8::SetAccessor(isolate, tpl, "mass", &MassGetter, &MassSetter); From 52a9bf408cfbb96c149da8fc549bd0db12cb1404 Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 25 Dec 2020 20:00:59 +0100 Subject: [PATCH 220/564] Fixed blip.scale --- src/bindings/Blip.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index b016d468..a458f784 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -103,14 +103,14 @@ static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfoGetScaleXY()[0]); + V8_RETURN_NUMBER(blip->GetScaleXY()[0]); } static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); + V8_TO_NUMBER(value, val); blip->SetScaleXY(val, val); } From db45b2361b6ce5d9e90da7e0dd77a3071ce337ac Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 25 Dec 2020 20:41:45 +0100 Subject: [PATCH 221/564] add loadYtyp & unloadYtyp --- src/bindings/Main.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 5fbd6e7a..d85d1b27 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -531,7 +531,7 @@ static void GetConfigFlag(const v8::FunctionCallbackInfo &info) V8_RETURN_BOOLEAN(ICore::Instance().GetConfigFlag(flag)); } -static void DoesConfigFlagExist(const v8::FunctionCallbackInfo &info) +static void DoesConfigFlagExist(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(1); @@ -541,6 +541,28 @@ static void DoesConfigFlagExist(const v8::FunctionCallbackInfo &info) V8_RETURN_BOOLEAN(ICore::Instance().DoesConfigFlagExist(flag)); } +static void LoadYtyp(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, path); + V8_ARG_TO_STRING(2, type); + + V8_RETURN_BOOLEAN(ICore::Instance().LoadYtyp(path.ToString())); +} + +static void UnloadYtyp(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, path); + V8_ARG_TO_STRING(2, type); + + V8_RETURN_BOOLEAN(ICore::Instance().UnloadYtyp(path.ToString())); +} + // extern V8Class v8MemoryBuffer; // static void GetEntityMemoryByID(const v8::FunctionCallbackInfo &info) // { @@ -816,4 +838,7 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "loadModel", &LoadModel); V8Helpers::RegisterFunc(exports, "loadModelAsync", &LoadModelAsync); + + V8Helpers::RegisterFunc(exports, "loadYtyp", &LoadYtyp); + V8Helpers::RegisterFunc(exports, "unloadYtyp", &UnloadYtyp); }); From 9829a3533ebd576281c15f23342f881a4100d9ed Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 25 Dec 2020 20:47:24 +0100 Subject: [PATCH 222/564] fix args for loadYtyp & unloadYtyp --- src/bindings/Main.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index d85d1b27..c21e4beb 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -544,10 +544,9 @@ static void DoesConfigFlagExist(const v8::FunctionCallbackInfo& info) static void LoadYtyp(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); - V8_CHECK_ARGS_LEN(2); + V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, path); - V8_ARG_TO_STRING(2, type); V8_RETURN_BOOLEAN(ICore::Instance().LoadYtyp(path.ToString())); } @@ -555,10 +554,9 @@ static void LoadYtyp(const v8::FunctionCallbackInfo& info) static void UnloadYtyp(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); - V8_CHECK_ARGS_LEN(2); + V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, path); - V8_ARG_TO_STRING(2, type); V8_RETURN_BOOLEAN(ICore::Instance().UnloadYtyp(path.ToString())); } From 57ca6fb4bfb327670a1d951a96d656b405f8ebf4 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 27 Dec 2020 19:17:42 +0100 Subject: [PATCH 223/564] Add CPP SDK as submodule --- .gitmodules | 6 +++++- CMakeLists.txt | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.gitmodules b/.gitmodules index 4ea3e8e6..e5d98fce 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ [submodule "src/helpers"] path = src/helpers - url = https://github.com/altmp/v8-helpers.git \ No newline at end of file + url = https://github.com/altmp/v8-helpers.git + +[submodule "src/cpp-sdk"] + path = src/cpp-sdk + url = https://github.com/altmp/cpp-sdk.git \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 22d5aac0..b2dd5379 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,17 +16,17 @@ FetchContent_Populate(altv-js-deps) set(ALTV_JS_DL_DEPS ${altv-js-deps_SOURCE_DIR}) # cpp-sdk -if(NOT ALTV_JS_CPP_SDK) - git_clone( - PROJECT_NAME cpp-sdk - GIT_URL https://github.com/altmp/cpp-sdk - GIT_BRANCH master - DIRECTORY ${ALTV_JS_DL_DEPS} - ) - set(ALTV_JS_CPP_SDK ${ALTV_JS_DL_DEPS}) -else() - message("alt:V JS - Skipping fetching cpp-sdk") -endif() +#if(NOT ALTV_JS_CPP_SDK) +# git_clone( +# PROJECT_NAME cpp-sdk +# GIT_URL https://github.com/altmp/cpp-sdk +# GIT_BRANCH master +# DIRECTORY ${ALTV_JS_DL_DEPS} +# ) +# set(ALTV_JS_CPP_SDK ${ALTV_JS_DL_DEPS}) +#else() +# message("alt:V JS - Skipping fetching cpp-sdk") +#endif() # Fetch deps file(GLOB_RECURSE PROJECT_SOURCE_FILES "src/*.h" "src/*.hpp" "src/*.cpp" "src/*.c") @@ -49,7 +49,7 @@ endmacro() GroupSources(${PROJECT_SOURCE_DIR}/src "Source Files") include_directories( - ${ALTV_JS_CPP_SDK} + src ${ALTV_JS_DL_DEPS}/include ) From 94013ad303f68cf3f3f8cab1b4e2ed2b919133fa Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 27 Dec 2020 19:34:22 +0100 Subject: [PATCH 224/564] Fix CPP SDK submodule --- .gitmodules | 3 +-- src/cpp-sdk | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) create mode 160000 src/cpp-sdk diff --git a/.gitmodules b/.gitmodules index e5d98fce..0b7b9532 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,6 @@ [submodule "src/helpers"] path = src/helpers url = https://github.com/altmp/v8-helpers.git - [submodule "src/cpp-sdk"] path = src/cpp-sdk - url = https://github.com/altmp/cpp-sdk.git \ No newline at end of file + url = https://github.com/altmp/cpp-sdk.git diff --git a/src/cpp-sdk b/src/cpp-sdk new file mode 160000 index 00000000..de4dd23f --- /dev/null +++ b/src/cpp-sdk @@ -0,0 +1 @@ +Subproject commit de4dd23f0a15a80efe561dbb148abfdbea00b00b From 7636a67c54fe1b97b38f09088df2a1050545a4a1 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 27 Dec 2020 22:05:41 +0100 Subject: [PATCH 225/564] Add back CPP SDK include directory --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2dd5379..82291e62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ endmacro() GroupSources(${PROJECT_SOURCE_DIR}/src "Source Files") include_directories( + ${ALTV_JS_CPP_SDK} src ${ALTV_JS_DL_DEPS}/include ) From 787bcb4960f0575056e8dc8a4cc1effa3fa7e47d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 27 Dec 2020 22:09:06 +0100 Subject: [PATCH 226/564] Fix CPP SDK CMake var path --- CMakeLists.txt | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82291e62..362e49a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,17 +16,9 @@ FetchContent_Populate(altv-js-deps) set(ALTV_JS_DL_DEPS ${altv-js-deps_SOURCE_DIR}) # cpp-sdk -#if(NOT ALTV_JS_CPP_SDK) -# git_clone( -# PROJECT_NAME cpp-sdk -# GIT_URL https://github.com/altmp/cpp-sdk -# GIT_BRANCH master -# DIRECTORY ${ALTV_JS_DL_DEPS} -# ) -# set(ALTV_JS_CPP_SDK ${ALTV_JS_DL_DEPS}) -#else() -# message("alt:V JS - Skipping fetching cpp-sdk") -#endif() +if(NOT ALTV_JS_CPP_SDK) + set(ALTV_JS_CPP_SDK src/cpp-sdk) +endif() # Fetch deps file(GLOB_RECURSE PROJECT_SOURCE_FILES "src/*.h" "src/*.hpp" "src/*.cpp" "src/*.c") @@ -50,7 +42,6 @@ GroupSources(${PROJECT_SOURCE_DIR}/src "Source Files") include_directories( ${ALTV_JS_CPP_SDK} - src ${ALTV_JS_DL_DEPS}/include ) From 919803730e20777b7186498a1de9b5fabc1371eb Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 27 Dec 2020 22:12:43 +0100 Subject: [PATCH 227/564] Fix CPP SDK var path --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 362e49a5..64f50b30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ set(ALTV_JS_DL_DEPS ${altv-js-deps_SOURCE_DIR}) # cpp-sdk if(NOT ALTV_JS_CPP_SDK) - set(ALTV_JS_CPP_SDK src/cpp-sdk) + set(ALTV_JS_CPP_SDK src) endif() # Fetch deps From 77a8f1c203946df7fcaf547fd05b9a54494a12d8 Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 28 Dec 2020 17:35:25 +0100 Subject: [PATCH 228/564] add websocket implementation --- src/CV8Resource.cpp | 33 +++++++- src/CV8Resource.h | 37 ++++++-- src/bindings/Main.cpp | 6 +- src/bindings/WebSocketClient.cpp | 139 +++++++++++++++++++++++++++++++ 4 files changed, 205 insertions(+), 10 deletions(-) create mode 100644 src/bindings/WebSocketClient.cpp diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 42a905f6..c91811f7 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -223,9 +223,9 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) return true; } -std::vector CV8ResourceImpl::GetWebviewHandlers(alt::Ref view, const std::string &name) +std::vector CV8ResourceImpl::GetWebviewHandlers(alt::Ref view, const std::string& name) { - std::vector handlers; + std::vector handlers; auto it = webViewHandlers.find(view.Get()); if (it != webViewHandlers.end()) @@ -239,6 +239,22 @@ std::vector CV8ResourceImpl::GetWebviewHandlers(alt::Ref CV8ResourceImpl::GetWebSocketClientHandlers(alt::Ref view, const std::string& name) +{ + std::vector handlers; + auto it = webSocketClientHandlers.find(view.Get()); + + if (it != webSocketClientHandlers.end()) + { + auto range = it->second.equal_range(name); + + for (auto it = range.first; it != range.second; ++it) + handlers.push_back(&it->second); + } + + return handlers; +} + void CV8ResourceImpl::OnTick() { v8::Locker locker(isolate); @@ -256,7 +272,7 @@ void CV8ResourceImpl::OnTick() Log::Warning << "Resource " << resource->GetName() << " tick was too long " << GetTime() - time << " ms" << Log::Endl; } - for (auto &view : webViewHandlers) + for (auto& view : webViewHandlers) { for (auto it = view.second.begin(); it != view.second.end();) { @@ -266,6 +282,17 @@ void CV8ResourceImpl::OnTick() ++it; } } + + for (auto& webSocket : webSocketClientHandlers) + { + for (auto it = webSocket.second.begin(); it != webSocket.second.end();) + { + if (it->second.removed) + it = webSocket.second.erase(it); + else + ++it; + } + } } void CV8ResourceImpl::OnPromiseRejectedWithNoHandler(v8::PromiseRejectMessage &data) diff --git a/src/CV8Resource.h b/src/CV8Resource.h index 018513ed..e9ca4db4 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -38,17 +38,17 @@ class CV8ResourceImpl : public V8ResourceImpl void OnPromiseRejectedWithNoHandler(v8::PromiseRejectMessage &data); void OnPromiseHandlerAdded(v8::PromiseRejectMessage &data); - void SubscribeWebView(alt::Ref view, const std::string &evName, v8::Local cb, V8::SourceLocation &&location) + void SubscribeWebView(alt::Ref view, const std::string& evName, v8::Local cb, V8::SourceLocation&& location) { - webViewHandlers[view].insert({evName, V8::EventCallback{isolate, cb, std::move(location)}}); + webViewHandlers[view].insert({ evName, V8::EventCallback{isolate, cb, std::move(location)} }); } - void UnsubscribeWebView(alt::Ref view, const std::string &evName, v8::Local cb) + void UnsubscribeWebView(alt::Ref view, const std::string& evName, v8::Local cb) { auto it = webViewHandlers.find(view); if (it != webViewHandlers.end()) { - auto &viewEvents = it->second; + auto& viewEvents = it->second; auto range = viewEvents.equal_range(evName); for (auto it = range.first; it != range.second; ++it) @@ -59,7 +59,30 @@ class CV8ResourceImpl : public V8ResourceImpl } } - std::vector GetWebviewHandlers(alt::Ref view, const std::string &name); + std::vector GetWebviewHandlers(alt::Ref view, const std::string& name); + + void SubscribeWebSocketClient(alt::Ref webSocket, const std::string& evName, v8::Local cb, V8::SourceLocation&& location) + { + webSocketClientHandlers[webSocket].insert({ evName, V8::EventCallback{isolate, cb, std::move(location)} }); + } + + void UnsubscribeWebSocketClient(alt::Ref webSocket, const std::string& evName, v8::Local cb) + { + auto it = webSocketClientHandlers.find(webSocket); + if (it != webSocketClientHandlers.end()) + { + auto& webSocketEvents = it->second; + auto range = webSocketEvents.equal_range(evName); + + for (auto it = range.first; it != range.second; ++it) + { + if (it->second.fn.Get(isolate)->StrictEquals(cb)) + it->second.removed = true; + } + } + } + + std::vector GetWebSocketClientHandlers(alt::Ref webSocket, const std::string& name); void AddOwned(alt::Ref handle) { @@ -73,6 +96,9 @@ class CV8ResourceImpl : public V8ResourceImpl if (handle->GetType() == alt::IBaseObject::Type::WEBVIEW) webViewHandlers.erase(handle.As()); + if (handle->GetType() == alt::IBaseObject::Type::WEBSOCKET_CLIENT) + webSocketClientHandlers.erase(handle.As()); + V8ResourceImpl::OnRemoveBaseObject(handle); } @@ -104,6 +130,7 @@ class CV8ResourceImpl : public V8ResourceImpl std::unordered_map> modules; std::unordered_map, WebViewEvents> webViewHandlers; + std::unordered_map, WebViewEvents> webSocketClientHandlers; std::unordered_set> ownedObjects; diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index c21e4beb..0d949440 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -734,7 +734,8 @@ extern V8Class v8Vector3, v8Discord, v8Voice, v8PedBlip, - v8VehicleBlip; + v8VehicleBlip, + v8WebSocketClient; extern V8Module altModule( "alt", {v8Vector3, @@ -755,7 +756,8 @@ extern V8Module altModule( v8File, v8MapZoomData, v8Discord, - v8Voice}, + v8Voice, + v8WebSocketClient}, [](v8::Local ctx, v8::Local exports) { V8::RegisterSharedMain(ctx, exports); diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp new file mode 100644 index 00000000..a6096176 --- /dev/null +++ b/src/bindings/WebSocketClient.cpp @@ -0,0 +1,139 @@ +#include "../helpers/V8Helpers.h" +#include "../helpers/V8Class.h" +#include "../helpers/V8Entity.h" +#include "../helpers/V8ResourceImpl.h" +#include "../CV8Resource.h" +#include "cpp-sdk/script-objects/IWebView.h" + +using namespace alt; + +static void Constructor(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_STRING(1, url); + + alt::IResource* altres = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_CHECK(altres, "invalid resource"); + + alt::Ref webSocket = nullptr; + + webSocket = alt::ICore::Instance().CreateWebSocketClient(url, altres); + + V8_BIND_BASE_OBJECT(webSocket); +} + +static void On(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, fun); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + static_cast(resource)->SubscribeWebSocketClient(webSocket, evName.ToString(), fun, V8::SourceLocation::GetCurrent(isolate)); +} + +static void Off(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, fun); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + static_cast(resource)->UnsubscribeWebSocketClient(webSocket, evName.ToString(), fun); +} + +static void SetPingInterval(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_UINT32(1, intervalSecs); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + webSocket->SetPingInterval(intervalSecs); +} + +static void Start(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + webSocket->Start(); +} + +static void Send(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, msg); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + webSocket->Send(msg); +} + +static void Stop(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + webSocket->Stop(); +} + +static void URLGetter(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + V8_RETURN_STRING(webSocket->GetUrl().CStr()); +} + +static void URLSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + V8_TO_STRING(value, url); + + webSocket->SetUrl(url); +} + +static void StateGetter(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + V8_RETURN_UINT32(webSocket->GetState()); +} + +extern V8Class v8BaseObject; +extern V8Class v8WebSocketClient("WebSocketClient", v8BaseObject, &Constructor, [](v8::Local tpl) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8::SetMethod(isolate, tpl, "on", &On); + V8::SetMethod(isolate, tpl, "off", &Off); + + V8::SetMethod(isolate, tpl, "setPingInterval", &SetPingInterval); + V8::SetMethod(isolate, tpl, "start", &Start); + V8::SetMethod(isolate, tpl, "send", &Send); + V8::SetMethod(isolate, tpl, "stop", &Stop); + + V8::SetAccessor(isolate, tpl, "url", &URLGetter, &URLSetter); + V8::SetAccessor(isolate, tpl, "state", &StateGetter, nullptr); +}); From ee6888a7d5605b8aa549f6f211e9b96074f5d01a Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 28 Dec 2020 19:36:28 +0100 Subject: [PATCH 229/564] add more websocket api --- src/CV8Resource.cpp | 360 +++++++++++++++++++++++++++---- src/CV8Resource.h | 22 +- src/bindings/WebSocketClient.cpp | 55 +++-- 3 files changed, 375 insertions(+), 62 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index c91811f7..110bccf0 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -5,6 +5,7 @@ #include "cpp-sdk/events/CClientScriptEvent.h" #include "cpp-sdk/events/CServerScriptEvent.h" #include "cpp-sdk/events/CWebViewEvent.h" +#include "cpp-sdk/events/CWebSocketClientEvent.h" #include "cpp-sdk/events/CKeyboardEvent.h" #include "cpp-sdk/events/CConnectionComplete.h" #include "cpp-sdk/events/CDisconnectEvent.h" @@ -205,54 +206,341 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); - - v8::Context::Scope scope(GetContext()); - - V8::EventHandler* handler = V8::EventHandler::Get(e); - if (!handler) + auto ctx = GetContext(); + if (ctx.IsEmpty()) return true; + v8::Context::Scope scope(ctx); - std::vector callbacks = handler->GetCallbacks(this, e); - if (callbacks.size() > 0) + std::vector handlers; + + switch (e->GetType()) + { + //case alt::CEvent::Type::RENDER: + //{ + // handlers = GetLocalHandlers("render"); + // break; + //} + case alt::CEvent::Type::WEB_VIEW_EVENT: { - std::vector> args = handler->GetArgs(this, e); + auto ev = static_cast(e); + auto it = webViewHandlers.find(ev->GetTarget().Get()); + + if (it != webViewHandlers.end()) + { + auto range = it->second.equal_range(ev->GetName().ToString()); + + for (auto it = range.first; it != range.second; ++it) + handlers.push_back(&it->second); + } - InvokeEventHandlers(e, callbacks, args); + break; } + case alt::CEvent::Type::WEB_SOCKET_CLIENT_EVENT: + { + auto ev = static_cast(e); + auto it = webSocketClientHandlers.find(ev->GetTarget().Get()); - return true; -} + if (it != webSocketClientHandlers.end()) + { + auto range = it->second.equal_range(ev->GetName().ToString()); -std::vector CV8ResourceImpl::GetWebviewHandlers(alt::Ref view, const std::string& name) -{ - std::vector handlers; - auto it = webViewHandlers.find(view.Get()); + for (auto it = range.first; it != range.second; ++it) + handlers.push_back(&it->second); + } - if (it != webViewHandlers.end()) + break; + } + case alt::CEvent::Type::CLIENT_SCRIPT_EVENT: + { + auto ev = static_cast(e); + handlers = GetLocalHandlers(ev->GetName().ToString()); + break; + } + case alt::CEvent::Type::SERVER_SCRIPT_EVENT: { - auto range = it->second.equal_range(name); + auto ev = static_cast(e); + handlers = GetRemoteHandlers(ev->GetName().ToString()); + break; + } + case alt::CEvent::Type::KEYBOARD_EVENT: + { + auto ev = static_cast(e); + + if (ev->GetKeyState() == alt::CKeyboardEvent::KeyState::UP) + handlers = GetLocalHandlers("keyup"); + else if (ev->GetKeyState() == alt::CKeyboardEvent::KeyState::DOWN) + handlers = GetLocalHandlers("keydown"); - for (auto it = range.first; it != range.second; ++it) - handlers.push_back(&it->second); + break; } + case alt::CEvent::Type::CONNECTION_COMPLETE: + { + handlers = GetLocalHandlers("connectionComplete"); + CV8ScriptRuntime* runtime = CV8ScriptRuntime::instance; + runtime->resourcesLoaded = true; - return handlers; -} + ProcessDynamicImports(); -std::vector CV8ResourceImpl::GetWebSocketClientHandlers(alt::Ref view, const std::string& name) -{ - std::vector handlers; - auto it = webSocketClientHandlers.find(view.Get()); + break; + } + case alt::CEvent::Type::DISCONNECT_EVENT: + { + handlers = GetLocalHandlers("disconnect"); + break; + } + case alt::CEvent::Type::REMOVE_ENTITY_EVENT: + { + handlers = GetLocalHandlers("removeEntity"); + break; + } + case alt::CEvent::Type::CONSOLE_COMMAND_EVENT: + { + handlers = GetLocalHandlers("consoleCommand"); + break; + } + case alt::CEvent::Type::GAME_ENTITY_CREATE: + { + handlers = GetLocalHandlers("gameEntityCreate"); + break; + } + case alt::CEvent::Type::GAME_ENTITY_DESTROY: + { + handlers = GetLocalHandlers("gameEntityDestroy"); + break; + } + case alt::CEvent::Type::SYNCED_META_CHANGE: + { + handlers = GetLocalHandlers("syncedMetaChange"); + break; + } + case alt::CEvent::Type::STREAM_SYNCED_META_CHANGE: + { + handlers = GetLocalHandlers("streamSyncedMetaChange"); + break; + } + case alt::CEvent::Type::GLOBAL_META_CHANGE: + { + handlers = GetLocalHandlers("globalMetaChange"); + break; + } + case alt::CEvent::Type::GLOBAL_SYNCED_META_CHANGE: + { + handlers = GetLocalHandlers("globalSyncedMetaChange"); + break; + } + case alt::CEvent::Type::RESOURCE_START: + { + handlers = GetLocalHandlers("anyResourceStart"); + break; + } + case alt::CEvent::Type::RESOURCE_STOP: + { + handlers = GetLocalHandlers("anyResourceStop"); + break; + } + case alt::CEvent::Type::RESOURCE_ERROR: + { + handlers = GetLocalHandlers("anyResourceError"); + break; + } + case alt::CEvent::Type::PLAYER_ENTER_VEHICLE: + { + handlers = GetLocalHandlers("enteredVehicle"); + break; + } + case alt::CEvent::Type::PLAYER_LEAVE_VEHICLE: + { + handlers = GetLocalHandlers("leftVehicle"); + break; + } + case alt::CEvent::Type::PLAYER_CHANGE_VEHICLE_SEAT: + { + handlers = GetLocalHandlers("changedVehicleSeat"); + break; + } + } - if (it != webSocketClientHandlers.end()) + if (handlers.size() > 0) { - auto range = it->second.equal_range(name); + std::vector> args; + + switch (e->GetType()) + { + case alt::CEvent::Type::WEB_VIEW_EVENT: + { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + + break; + } + case alt::CEvent::Type::WEB_SOCKET_CLIENT_EVENT: + { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + + break; + } + case alt::CEvent::Type::CLIENT_SCRIPT_EVENT: + { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); - for (auto it = range.first; it != range.second; ++it) - handlers.push_back(&it->second); + break; + } + case alt::CEvent::Type::SERVER_SCRIPT_EVENT: + { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + + break; + } + case alt::CEvent::Type::KEYBOARD_EVENT: + { + auto ev = static_cast(e); + + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetKeyCode())); + + break; + } + case alt::CEvent::Type::CONNECTION_COMPLETE: + { + break; + } + case alt::CEvent::Type::DISCONNECT_EVENT: + { + CV8ScriptRuntime::instance->resourcesLoaded = false; + break; + } + case alt::CEvent::Type::REMOVE_ENTITY_EVENT: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetEntity().Get())->GetJSVal(isolate)); + + break; + } + case alt::CEvent::Type::CONSOLE_COMMAND_EVENT: + { + auto ev = static_cast(e); + + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetName().CStr()).ToLocalChecked()); + for (auto &arg : ev->GetArgs()) + args.push_back(v8::String::NewFromUtf8(isolate, arg.CStr()).ToLocalChecked()); + + break; + } + case alt::CEvent::Type::GAME_ENTITY_CREATE: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + + break; + } + case alt::CEvent::Type::GAME_ENTITY_DESTROY: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + + break; + } + case alt::CEvent::Type::SYNCED_META_CHANGE: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + + break; + } + case alt::CEvent::Type::STREAM_SYNCED_META_CHANGE: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + + break; + } + case alt::CEvent::Type::GLOBAL_META_CHANGE: + { + auto ev = static_cast(e); + + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + + break; + } + case alt::CEvent::Type::GLOBAL_SYNCED_META_CHANGE: + { + auto ev = static_cast(e); + + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + + break; + } + case alt::CEvent::Type::RESOURCE_START: + { + auto ev = static_cast(e); + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); + break; + } + case alt::CEvent::Type::RESOURCE_STOP: + { + auto ev = static_cast(e); + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); + break; + } + case alt::CEvent::Type::RESOURCE_ERROR: + { + auto ev = static_cast(e); + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); + break; + } + case alt::CEvent::Type::PLAYER_ENTER_VEHICLE: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::Integer::New(isolate, ev->GetSeat())); + break; + } + case alt::CEvent::Type::PLAYER_LEAVE_VEHICLE: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::Integer::New(isolate, ev->GetSeat())); + break; + } + case alt::CEvent::Type::PLAYER_CHANGE_VEHICLE_SEAT: + { + auto ev = static_cast(e); + + args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + args.push_back(v8::Integer::New(isolate, ev->GetOldSeat())); + args.push_back(v8::Integer::New(isolate, ev->GetNewSeat())); + break; + } + + } + + InvokeEventHandlers(e, handlers, args); } - return handlers; + return true; } void CV8ResourceImpl::OnTick() @@ -272,7 +560,7 @@ void CV8ResourceImpl::OnTick() Log::Warning << "Resource " << resource->GetName() << " tick was too long " << GetTime() - time << " ms" << Log::Endl; } - for (auto& view : webViewHandlers) + for (auto &view : webViewHandlers) { for (auto it = view.second.begin(); it != view.second.end();) { @@ -281,14 +569,14 @@ void CV8ResourceImpl::OnTick() else ++it; } - } - - for (auto& webSocket : webSocketClientHandlers) + } + + for (auto &view : webSocketClientHandlers) { - for (auto it = webSocket.second.begin(); it != webSocket.second.end();) + for (auto it = view.second.begin(); it != view.second.end();) { if (it->second.removed) - it = webSocket.second.erase(it); + it = view.second.erase(it); else ++it; } diff --git a/src/CV8Resource.h b/src/CV8Resource.h index e9ca4db4..98bc3d65 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -38,17 +38,17 @@ class CV8ResourceImpl : public V8ResourceImpl void OnPromiseRejectedWithNoHandler(v8::PromiseRejectMessage &data); void OnPromiseHandlerAdded(v8::PromiseRejectMessage &data); - void SubscribeWebView(alt::Ref view, const std::string& evName, v8::Local cb, V8::SourceLocation&& location) + void SubscribeWebView(alt::Ref view, const std::string &evName, v8::Local cb, V8::SourceLocation &&location) { - webViewHandlers[view].insert({ evName, V8::EventCallback{isolate, cb, std::move(location)} }); + webViewHandlers[view].insert({evName, V8::EventCallback{isolate, cb, std::move(location)}}); } - void UnsubscribeWebView(alt::Ref view, const std::string& evName, v8::Local cb) + void UnsubscribeWebView(alt::Ref view, const std::string &evName, v8::Local cb) { auto it = webViewHandlers.find(view); if (it != webViewHandlers.end()) { - auto& viewEvents = it->second; + auto &viewEvents = it->second; auto range = viewEvents.equal_range(evName); for (auto it = range.first; it != range.second; ++it) @@ -59,19 +59,17 @@ class CV8ResourceImpl : public V8ResourceImpl } } - std::vector GetWebviewHandlers(alt::Ref view, const std::string& name); - - void SubscribeWebSocketClient(alt::Ref webSocket, const std::string& evName, v8::Local cb, V8::SourceLocation&& location) + void SubscribeWebSocketClient(alt::Ref view, const std::string &evName, v8::Local cb, V8::SourceLocation &&location) { - webSocketClientHandlers[webSocket].insert({ evName, V8::EventCallback{isolate, cb, std::move(location)} }); + webSocketClientHandlers[view].insert({evName, V8::EventCallback{isolate, cb, std::move(location)}}); } - void UnsubscribeWebSocketClient(alt::Ref webSocket, const std::string& evName, v8::Local cb) + void UnsubscribeWebSocketClient(alt::Ref view, const std::string &evName, v8::Local cb) { - auto it = webSocketClientHandlers.find(webSocket); + auto it = webSocketClientHandlers.find(view); if (it != webSocketClientHandlers.end()) { - auto& webSocketEvents = it->second; + auto &webSocketEvents = it->second; auto range = webSocketEvents.equal_range(evName); for (auto it = range.first; it != range.second; ++it) @@ -82,8 +80,6 @@ class CV8ResourceImpl : public V8ResourceImpl } } - std::vector GetWebSocketClientHandlers(alt::Ref webSocket, const std::string& name); - void AddOwned(alt::Ref handle) { ownedObjects.insert(handle); diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index a6096176..fd9df4a2 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -51,18 +51,6 @@ static void Off(const v8::FunctionCallbackInfo& info) static_cast(resource)->UnsubscribeWebSocketClient(webSocket, evName.ToString(), fun); } -static void SetPingInterval(const v8::FunctionCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_UINT32(1, intervalSecs); - - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - - webSocket->SetPingInterval(intervalSecs); -} - static void Start(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE(info); @@ -122,6 +110,46 @@ static void StateGetter(v8::Local property, const v8::PropertyCallba V8_RETURN_UINT32(webSocket->GetState()); } +static void AutoReconnectSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + V8_TO_BOOLEAN(value, toggle); + + webSocket->SetAutoReconnectEnabled(toggle); +} + +static void AutoReconnectGetter(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + V8_RETURN_BOOLEAN(webSocket->IsAutoReconnectEnabled()); +} + +static void PingIntervalSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + V8_TO_INTEGER(value, interval); + + webSocket->SetPingInterval(interval); +} + +static void PingIntervalGetter(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + V8_RETURN_UINT32(webSocket->GetPingInterval()); +} + extern V8Class v8BaseObject; extern V8Class v8WebSocketClient("WebSocketClient", v8BaseObject, &Constructor, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); @@ -129,11 +157,12 @@ extern V8Class v8WebSocketClient("WebSocketClient", v8BaseObject, &Constructor, V8::SetMethod(isolate, tpl, "on", &On); V8::SetMethod(isolate, tpl, "off", &Off); - V8::SetMethod(isolate, tpl, "setPingInterval", &SetPingInterval); V8::SetMethod(isolate, tpl, "start", &Start); V8::SetMethod(isolate, tpl, "send", &Send); V8::SetMethod(isolate, tpl, "stop", &Stop); + V8::SetAccessor(isolate, tpl, "autoReconnect", &AutoReconnectGetter, &AutoReconnectSetter); + V8::SetAccessor(isolate, tpl, "pingInterval", &PingIntervalGetter, &PingIntervalSetter); V8::SetAccessor(isolate, tpl, "url", &URLGetter, &URLSetter); V8::SetAccessor(isolate, tpl, "state", &StateGetter, nullptr); }); From 0a864e0fca44ed29ac2d1b37d676bcd2adad1011 Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 28 Dec 2020 20:40:52 +0100 Subject: [PATCH 230/564] use latest event api --- src/CV8Resource.cpp | 361 +++++--------------------------------------- src/CV8Resource.h | 4 + src/events/Main.cpp | 2 +- 3 files changed, 42 insertions(+), 325 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 110bccf0..7a9fbb4c 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -199,348 +199,61 @@ bool CV8ResourceImpl::Stop() return true; } -bool CV8ResourceImpl::OnEvent(const alt::CEvent *e) +bool CV8ResourceImpl::OnEvent(const alt::CEvent* e) { auto nscope = resource->PushNativesScope(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); - auto ctx = GetContext(); - if (ctx.IsEmpty()) - return true; - v8::Context::Scope scope(ctx); - - std::vector handlers; - switch (e->GetType()) - { - //case alt::CEvent::Type::RENDER: - //{ - // handlers = GetLocalHandlers("render"); - // break; - //} - case alt::CEvent::Type::WEB_VIEW_EVENT: - { - auto ev = static_cast(e); - auto it = webViewHandlers.find(ev->GetTarget().Get()); + v8::Context::Scope scope(GetContext()); - if (it != webViewHandlers.end()) - { - auto range = it->second.equal_range(ev->GetName().ToString()); + V8::EventHandler* handler = V8::EventHandler::Get(e); + if (!handler) + return true; - for (auto it = range.first; it != range.second; ++it) - handlers.push_back(&it->second); - } + std::vector callbacks = handler->GetCallbacks(this, e); + if (callbacks.size() > 0) + { + std::vector> args = handler->GetArgs(this, e); - break; + InvokeEventHandlers(e, callbacks, args); } - case alt::CEvent::Type::WEB_SOCKET_CLIENT_EVENT: - { - auto ev = static_cast(e); - auto it = webSocketClientHandlers.find(ev->GetTarget().Get()); - if (it != webSocketClientHandlers.end()) - { - auto range = it->second.equal_range(ev->GetName().ToString()); + return true; +} - for (auto it = range.first; it != range.second; ++it) - handlers.push_back(&it->second); - } +std::vector CV8ResourceImpl::GetWebViewHandlers(alt::Ref view, const std::string& name) +{ + std::vector handlers; + auto it = webViewHandlers.find(view.Get()); - break; - } - case alt::CEvent::Type::CLIENT_SCRIPT_EVENT: - { - auto ev = static_cast(e); - handlers = GetLocalHandlers(ev->GetName().ToString()); - break; - } - case alt::CEvent::Type::SERVER_SCRIPT_EVENT: + if (it != webViewHandlers.end()) { - auto ev = static_cast(e); - handlers = GetRemoteHandlers(ev->GetName().ToString()); - break; - } - case alt::CEvent::Type::KEYBOARD_EVENT: - { - auto ev = static_cast(e); - - if (ev->GetKeyState() == alt::CKeyboardEvent::KeyState::UP) - handlers = GetLocalHandlers("keyup"); - else if (ev->GetKeyState() == alt::CKeyboardEvent::KeyState::DOWN) - handlers = GetLocalHandlers("keydown"); + auto range = it->second.equal_range(name); - break; + for (auto it = range.first; it != range.second; ++it) + handlers.push_back(&it->second); } - case alt::CEvent::Type::CONNECTION_COMPLETE: - { - handlers = GetLocalHandlers("connectionComplete"); - CV8ScriptRuntime* runtime = CV8ScriptRuntime::instance; - runtime->resourcesLoaded = true; - ProcessDynamicImports(); + return handlers; +} - break; - } - case alt::CEvent::Type::DISCONNECT_EVENT: - { - handlers = GetLocalHandlers("disconnect"); - break; - } - case alt::CEvent::Type::REMOVE_ENTITY_EVENT: - { - handlers = GetLocalHandlers("removeEntity"); - break; - } - case alt::CEvent::Type::CONSOLE_COMMAND_EVENT: - { - handlers = GetLocalHandlers("consoleCommand"); - break; - } - case alt::CEvent::Type::GAME_ENTITY_CREATE: - { - handlers = GetLocalHandlers("gameEntityCreate"); - break; - } - case alt::CEvent::Type::GAME_ENTITY_DESTROY: - { - handlers = GetLocalHandlers("gameEntityDestroy"); - break; - } - case alt::CEvent::Type::SYNCED_META_CHANGE: - { - handlers = GetLocalHandlers("syncedMetaChange"); - break; - } - case alt::CEvent::Type::STREAM_SYNCED_META_CHANGE: - { - handlers = GetLocalHandlers("streamSyncedMetaChange"); - break; - } - case alt::CEvent::Type::GLOBAL_META_CHANGE: - { - handlers = GetLocalHandlers("globalMetaChange"); - break; - } - case alt::CEvent::Type::GLOBAL_SYNCED_META_CHANGE: - { - handlers = GetLocalHandlers("globalSyncedMetaChange"); - break; - } - case alt::CEvent::Type::RESOURCE_START: - { - handlers = GetLocalHandlers("anyResourceStart"); - break; - } - case alt::CEvent::Type::RESOURCE_STOP: - { - handlers = GetLocalHandlers("anyResourceStop"); - break; - } - case alt::CEvent::Type::RESOURCE_ERROR: - { - handlers = GetLocalHandlers("anyResourceError"); - break; - } - case alt::CEvent::Type::PLAYER_ENTER_VEHICLE: - { - handlers = GetLocalHandlers("enteredVehicle"); - break; - } - case alt::CEvent::Type::PLAYER_LEAVE_VEHICLE: - { - handlers = GetLocalHandlers("leftVehicle"); - break; - } - case alt::CEvent::Type::PLAYER_CHANGE_VEHICLE_SEAT: - { - handlers = GetLocalHandlers("changedVehicleSeat"); - break; - } - } +std::vector CV8ResourceImpl::GetWebSocketClientHandlers(alt::Ref view, const std::string& name) +{ + std::vector handlers; + auto it = webSocketClientHandlers.find(view.Get()); - if (handlers.size() > 0) + if (it != webSocketClientHandlers.end()) { - std::vector> args; - - switch (e->GetType()) - { - case alt::CEvent::Type::WEB_VIEW_EVENT: - { - auto ev = static_cast(e); - - V8Helpers::MValueArgsToV8(ev->GetArgs(), args); - - break; - } - case alt::CEvent::Type::WEB_SOCKET_CLIENT_EVENT: - { - auto ev = static_cast(e); - - V8Helpers::MValueArgsToV8(ev->GetArgs(), args); - - break; - } - case alt::CEvent::Type::CLIENT_SCRIPT_EVENT: - { - auto ev = static_cast(e); - - V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + auto range = it->second.equal_range(name); - break; - } - case alt::CEvent::Type::SERVER_SCRIPT_EVENT: - { - auto ev = static_cast(e); - - V8Helpers::MValueArgsToV8(ev->GetArgs(), args); - - break; - } - case alt::CEvent::Type::KEYBOARD_EVENT: - { - auto ev = static_cast(e); - - args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetKeyCode())); - - break; - } - case alt::CEvent::Type::CONNECTION_COMPLETE: - { - break; - } - case alt::CEvent::Type::DISCONNECT_EVENT: - { - CV8ScriptRuntime::instance->resourcesLoaded = false; - break; - } - case alt::CEvent::Type::REMOVE_ENTITY_EVENT: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetEntity().Get())->GetJSVal(isolate)); - - break; - } - case alt::CEvent::Type::CONSOLE_COMMAND_EVENT: - { - auto ev = static_cast(e); - - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetName().CStr()).ToLocalChecked()); - for (auto &arg : ev->GetArgs()) - args.push_back(v8::String::NewFromUtf8(isolate, arg.CStr()).ToLocalChecked()); - - break; - } - case alt::CEvent::Type::GAME_ENTITY_CREATE: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - - break; - } - case alt::CEvent::Type::GAME_ENTITY_DESTROY: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - - break; - } - case alt::CEvent::Type::SYNCED_META_CHANGE: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); - args.push_back(V8Helpers::MValueToV8(ev->GetVal())); - args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); - - break; - } - case alt::CEvent::Type::STREAM_SYNCED_META_CHANGE: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); - args.push_back(V8Helpers::MValueToV8(ev->GetVal())); - args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); - - break; - } - case alt::CEvent::Type::GLOBAL_META_CHANGE: - { - auto ev = static_cast(e); - - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); - args.push_back(V8Helpers::MValueToV8(ev->GetVal())); - args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); - - break; - } - case alt::CEvent::Type::GLOBAL_SYNCED_META_CHANGE: - { - auto ev = static_cast(e); - - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetKey().CStr()).ToLocalChecked()); - args.push_back(V8Helpers::MValueToV8(ev->GetVal())); - args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); - - break; - } - case alt::CEvent::Type::RESOURCE_START: - { - auto ev = static_cast(e); - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); - break; - } - case alt::CEvent::Type::RESOURCE_STOP: - { - auto ev = static_cast(e); - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); - break; - } - case alt::CEvent::Type::RESOURCE_ERROR: - { - auto ev = static_cast(e); - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetResource()->GetName().CStr()).ToLocalChecked()); - break; - } - case alt::CEvent::Type::PLAYER_ENTER_VEHICLE: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - args.push_back(v8::Integer::New(isolate, ev->GetSeat())); - break; - } - case alt::CEvent::Type::PLAYER_LEAVE_VEHICLE: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - args.push_back(v8::Integer::New(isolate, ev->GetSeat())); - break; - } - case alt::CEvent::Type::PLAYER_CHANGE_VEHICLE_SEAT: - { - auto ev = static_cast(e); - - args.push_back(GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - args.push_back(v8::Integer::New(isolate, ev->GetOldSeat())); - args.push_back(v8::Integer::New(isolate, ev->GetNewSeat())); - break; - } - - } - - InvokeEventHandlers(e, handlers, args); + for (auto it = range.first; it != range.second; ++it) + handlers.push_back(&it->second); } - return true; + return handlers; } void CV8ResourceImpl::OnTick() @@ -560,7 +273,7 @@ void CV8ResourceImpl::OnTick() Log::Warning << "Resource " << resource->GetName() << " tick was too long " << GetTime() - time << " ms" << Log::Endl; } - for (auto &view : webViewHandlers) + for (auto& view : webViewHandlers) { for (auto it = view.second.begin(); it != view.second.end();) { @@ -569,14 +282,14 @@ void CV8ResourceImpl::OnTick() else ++it; } - } - - for (auto &view : webSocketClientHandlers) + } + + for (auto& webSocket : webSocketClientHandlers) { - for (auto it = view.second.begin(); it != view.second.end();) + for (auto it = webSocket.second.begin(); it != webSocket.second.end();) { if (it->second.removed) - it = view.second.erase(it); + it = webSocket.second.erase(it); else ++it; } diff --git a/src/CV8Resource.h b/src/CV8Resource.h index 98bc3d65..26c36727 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -59,6 +59,8 @@ class CV8ResourceImpl : public V8ResourceImpl } } + std::vector GetWebViewHandlers(alt::Ref view, const std::string& name); + void SubscribeWebSocketClient(alt::Ref view, const std::string &evName, v8::Local cb, V8::SourceLocation &&location) { webSocketClientHandlers[view].insert({evName, V8::EventCallback{isolate, cb, std::move(location)}}); @@ -79,6 +81,8 @@ class CV8ResourceImpl : public V8ResourceImpl } } } + + std::vector GetWebSocketClientHandlers(alt::Ref webSocket, const std::string& name); void AddOwned(alt::Ref handle) { diff --git a/src/events/Main.cpp b/src/events/Main.cpp index 2d6ae9df..67e63688 100644 --- a/src/events/Main.cpp +++ b/src/events/Main.cpp @@ -49,7 +49,7 @@ V8::EventHandler webviewEvent( [](V8ResourceImpl* resource, const CEvent* e) { auto ev = static_cast(e); - return static_cast(resource)->GetWebviewHandlers(ev->GetTarget(), ev->GetName().ToString()); + return static_cast(resource)->GetWebViewHandlers(ev->GetTarget(), ev->GetName().ToString()); }, [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { auto ev = static_cast(e); From 7a5532d7b61bf21624fa03c82208f88564c4ad61 Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 28 Dec 2020 21:19:26 +0100 Subject: [PATCH 231/564] add websocket event handler --- src/events/Main.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/events/Main.cpp b/src/events/Main.cpp index 67e63688..e8de4440 100644 --- a/src/events/Main.cpp +++ b/src/events/Main.cpp @@ -12,6 +12,7 @@ #include "cpp-sdk/events/CServerScriptEvent.h" #include "cpp-sdk/events/CKeyboardEvent.h" #include "cpp-sdk/events/CWebViewEvent.h" +#include "cpp-sdk/events/CWebSocketClientEvent.h" #include "cpp-sdk/SDK.h" @@ -58,6 +59,20 @@ V8::EventHandler webviewEvent( } ); +V8::EventHandler webSocketEvent( + EventType::WEB_SOCKET_CLIENT_EVENT, + [](V8ResourceImpl* resource, const CEvent* e) { + auto ev = static_cast(e); + + return static_cast(resource)->GetWebSocketClientHandlers(ev->GetTarget(), ev->GetName().ToString()); + }, + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + } +); + V8::EventHandler keyboardEvent( EventType::KEYBOARD_EVENT, [](V8ResourceImpl* resource, const CEvent* e) { From 764e44d7b779bf52b3efd88ff9a888ac24862c29 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 29 Dec 2020 12:54:22 +0100 Subject: [PATCH 232/564] Added new voice method and moved old one to Voice class --- src/bindings/Voice.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/bindings/Voice.cpp b/src/bindings/Voice.cpp index 82c4fd28..fd6c9ec6 100644 --- a/src/bindings/Voice.cpp +++ b/src/bindings/Voice.cpp @@ -3,13 +3,14 @@ #include "../helpers/V8ResourceImpl.h" #include "../helpers/V8Class.h" -static void StaticGetInputMuted(v8::Local name, const v8::PropertyCallbackInfo &info) +static void StaticGetInputMuted(v8::Local, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); + V8_RETURN_BOOLEAN(alt::ICore::Instance().IsVoiceInputMuted()); } -static void StaticSetInputMuted(v8::Local name, v8::Local value, const v8::PropertyCallbackInfo &info) +static void StaticSetInputMuted(v8::Local, v8::Local value, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); V8_TO_BOOLEAN(value, state); @@ -17,8 +18,24 @@ static void StaticSetInputMuted(v8::Local name, v8::Local alt::ICore::Instance().SetVoiceInputMuted(state); } +static void StaticGetVoiceActivityInputEnabled(v8::Local, const v8::PropertyCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_RETURN_BOOLEAN(alt::ICore::Instance().IsVoiceActivationEnabled()); +} + +static void StaticGetVoiceActivationKey(v8::Local, const v8::PropertyCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_RETURN_UINT32(alt::ICore::Instance().GetVoiceActivationKey()); +} + extern V8Class v8Voice("Voice", [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetStaticAccessor(isolate, tpl, "muteInput", StaticGetInputMuted, StaticSetInputMuted); + V8::SetStaticAccessor(isolate, tpl, "activityInputEnabled", StaticGetVoiceActivityInputEnabled); + V8::SetStaticAccessor(isolate, tpl, "activationKey", StaticGetVoiceActivationKey); }); From b1eaf13eba7ec4bcdbe714ae3b701f219cd34b7a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 29 Dec 2020 12:54:53 +0100 Subject: [PATCH 233/564] Deprecated moved voice method --- src/bindings/Main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index c21e4beb..71eed91d 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -189,6 +189,8 @@ static void IsVoiceActivityInputEnabled(const v8::FunctionCallbackInfo Date: Tue, 29 Dec 2020 14:08:56 +0100 Subject: [PATCH 234/564] Update CPP SDK --- src/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index de4dd23f..3f14ad8b 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit de4dd23f0a15a80efe561dbb148abfdbea00b00b +Subproject commit 3f14ad8bd3af35b2c4f94c7eaf1c6ab4aa87773c From ea0d90e9625574442fd828240d49a58740fc3a8a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 29 Dec 2020 17:58:22 +0100 Subject: [PATCH 235/564] Add Vector2 class --- V8ResourceImpl.cpp | 17 +++++++++++- V8ResourceImpl.h | 3 +++ bindings/Vector2.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 bindings/Vector2.cpp diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index c86a50f2..672e610f 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -19,10 +19,11 @@ V8ResourceImpl::~V8ResourceImpl() { entities.clear(); } -extern V8Class v8Vector3, v8RGBA, v8BaseObject; +extern V8Class v8Vector3, v8Vector2, v8RGBA, v8BaseObject; bool V8ResourceImpl::Start() { vector3Class.Reset(isolate, v8Vector3.JSValue(isolate, GetContext())); + vector2Class.Reset(isolate, v8Vector2.JSValue(isolate, GetContext())); rgbaClass.Reset(isolate, v8RGBA.JSValue(isolate, GetContext())); baseObjectClass.Reset(isolate, v8BaseObject.JSValue(isolate, GetContext())); @@ -109,6 +110,15 @@ v8::Local V8ResourceImpl::CreateVector3(alt::Vector3f vec) return v8Vector3.CreateInstance(isolate, GetContext(), args); } +v8::Local V8ResourceImpl::CreateVector2(alt::Vector2f vec) +{ + std::vector> args{ + v8::Number::New(isolate, vec[0]), + v8::Number::New(isolate, vec[1])}; + + return v8Vector2.CreateInstance(isolate, GetContext(), args); +} + v8::Local V8ResourceImpl::CreateRGBA(alt::RGBA rgba) { std::vector> args{ @@ -125,6 +135,11 @@ bool V8ResourceImpl::IsVector3(v8::Local val) return val->InstanceOf(GetContext(), vector3Class.Get(isolate)).ToChecked(); } +bool V8ResourceImpl::IsVector2(v8::Local val) +{ + return val->InstanceOf(GetContext(), vector2Class.Get(isolate)).ToChecked(); +} + bool V8ResourceImpl::IsRGBA(v8::Local val) { return val->InstanceOf(GetContext(), rgbaClass.Get(isolate)).ToChecked(); diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index 1f0c9e50..e1a612df 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -140,9 +140,11 @@ class V8ResourceImpl : public alt::IResource::Impl } v8::Local CreateVector3(alt::Vector3f vec); + v8::Local CreateVector2(alt::Vector2f vec); v8::Local CreateRGBA(alt::RGBA rgba); bool IsVector3(v8::Local val); + bool IsVector2(v8::Local val); bool IsRGBA(v8::Local val); bool IsBaseObject(v8::Local val); @@ -219,6 +221,7 @@ class V8ResourceImpl : public alt::IResource::Impl V8::PromiseRejections promiseRejections; v8::Persistent vector3Class; + v8::Persistent vector2Class; v8::Persistent rgbaClass; v8::Persistent baseObjectClass; diff --git a/bindings/Vector2.cpp b/bindings/Vector2.cpp new file mode 100644 index 00000000..09a43970 --- /dev/null +++ b/bindings/Vector2.cpp @@ -0,0 +1,63 @@ +#include "../V8Class.h" +#include "../V8Helpers.h" +#include "../V8ResourceImpl.h" + +static void Constructor(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN2(1, 2); + + v8::Local _this = info.This(); + + v8::Local x, y; + + if (info.Length() == 2) + { + V8_ARG_CHECK_NUMBER(1); + V8_ARG_CHECK_NUMBER(2); + + x = info[0]; + y = info[1]; + } + else + { + v8::Local val = info[0]; + + if (val->IsArray()) + { + v8::Local arr = val.As(); + V8_CHECK(arr->Length() == 2, "Argument must be an array of 2 numbers"); + + x = arr->Get(ctx, 0).ToLocalChecked(); + y = arr->Get(ctx, 1).ToLocalChecked(); + + V8_CHECK(x->IsNumber(), "Argument must be an array of 2 numbers"); + V8_CHECK(y->IsNumber(), "Argument must be an array of 2 numbers"); + } + else if (val->IsObject()) + { + v8::Local obj = val.As(); + + x = obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(); + y = obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(); + + V8_CHECK(x->IsNumber(), "x must be a number"); + V8_CHECK(y->IsNumber(), "y must be a number"); + } + else + { + V8Helpers::Throw(isolate, "Argument must be an array of 2 numbers or IVector2"); + return; + } + } + + V8::DefineOwnProperty(isolate, ctx, _this, V8::Vector3_XKey(isolate), x, v8::PropertyAttribute::ReadOnly); + V8::DefineOwnProperty(isolate, ctx, _this, V8::Vector3_YKey(isolate), y, v8::PropertyAttribute::ReadOnly); +} + +extern V8Class v8Vector2("Vector2", Constructor, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + +}); From ec22e323aa695546580c8de60596c6b65aa30711 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 29 Dec 2020 18:06:51 +0100 Subject: [PATCH 236/564] Add Vector2 class and update helpers --- src/bindings/Main.cpp | 2 ++ src/helpers | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 71eed91d..12bb645e 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -716,6 +716,7 @@ static void LoadModelAsync(const v8::FunctionCallbackInfo& info) } extern V8Class v8Vector3, + v8Vector2, v8RGBA, v8BaseObject, v8WorldObject, @@ -740,6 +741,7 @@ extern V8Class v8Vector3, extern V8Module altModule( "alt", {v8Vector3, + v8Vector2, v8RGBA, v8BaseObject, v8WorldObject, diff --git a/src/helpers b/src/helpers index 8a70195c..ea0d90e9 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 8a70195c12e721d84154ecfd9ddf75141a0a4622 +Subproject commit ea0d90e9625574442fd828240d49a58740fc3a8a From c262427fda57eaa14c2bf44ad5bfe2e0829cc431 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 29 Dec 2020 19:17:40 +0100 Subject: [PATCH 237/564] Add pos and size param to webview constructor --- src/bindings/WebView.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index 4b0dfb3d..f059dcc6 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -124,7 +124,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_CONSTRUCTOR(); - V8_CHECK_ARGS_LEN_MIN_MAX(1, 3); + V8_CHECK_ARGS_LEN_MIN_MAX(1, 4); V8_ARG_TO_STRING(1, url); @@ -133,7 +133,34 @@ static void Constructor(const v8::FunctionCallbackInfo& info) alt::Ref view = nullptr; - if (info.Length() == 3) + if (info.Length() == 4) + { + V8_ARG_TO_BOOLEAN(2, isOverlayBool); + V8_ARG_TO_OBJECT(3, pos); + V8_ARG_TO_OBJECT(4, size); + + V8_OBJECT_GET_INTEGER(pos, "x", posX); + V8_OBJECT_GET_INTEGER(pos, "y", posY); + + V8_OBJECT_GET_INTEGER(size, "x", sizeX); + V8_OBJECT_GET_INTEGER(size, "y", sizeY); + + view = alt::ICore::Instance().CreateWebView(altres, url, { posX, posY }, { sizeX, sizeY }, true, isOverlayBool); + } + else if (info.Length() == 3 && info[2]->IsObject()) + { + V8_ARG_TO_OBJECT(2, pos); + V8_ARG_TO_OBJECT(3, size); + + V8_OBJECT_GET_INTEGER(pos, "x", posX); + V8_OBJECT_GET_INTEGER(pos, "y", posY); + + V8_OBJECT_GET_INTEGER(size, "x", sizeX); + V8_OBJECT_GET_INTEGER(size, "y", sizeY); + + view = alt::ICore::Instance().CreateWebView(altres, url, { posX, posY }, { sizeX, sizeY }, true, false); + } + else if (info.Length() == 3) { V8_ARG_TO_INTEGER(2, drawableHash); V8_ARG_TO_STRING(3, targetTextureStr); @@ -144,6 +171,15 @@ static void Constructor(const v8::FunctionCallbackInfo& info) view = alt::ICore::Instance().CreateWebView(altres, url, (uint32_t)drawableHash, targetTextureStr); V8_CHECK(!view.IsEmpty(), "Interactive WebView cannot be created"); } + else if (info.Length() == 2 && info[1]->IsObject()) + { + V8_ARG_TO_OBJECT(2, pos); + + V8_OBJECT_GET_INTEGER(pos, "x", posX); + V8_OBJECT_GET_INTEGER(pos, "y", posY); + + view = alt::ICore::Instance().CreateWebView(altres, url, { posX, posY }, { 0, 0 }, true, false); + } else if (info.Length() == 2) { V8_ARG_TO_BOOLEAN(2, isOverlayBool); From e4af3b66123f4eecbcda1f84b246bbd04f2c9f97 Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 30 Dec 2020 02:13:25 +0100 Subject: [PATCH 238/564] Helpers for event subscribing (needed for static builds) --- V8Helpers.cpp | 11 +++++++++++ V8Helpers.h | 14 ++++++++++---- events/Main.cpp | 20 ++++++++++---------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 32205fdb..b14f1bc9 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -639,3 +639,14 @@ V8::EventHandler::CallbacksGetter V8::LocalEventHandler::GetCallbacksGetter(cons return resource->GetLocalHandlers(name); }; } + +V8::EventHandler::EventHandler(alt::CEvent::Type type, CallbacksGetter &&_handlersGetter, ArgsGetter &&_argsGetter) + : callbacksGetter(std::move(_handlersGetter)), argsGetter(std::move(_argsGetter)), type(type) +{ + Register(type, this); +} + +// Temp issue fix for https://stackoverflow.com/questions/9459980/c-global-variable-not-initialized-when-linked-through-static-libraries-but-ok +void V8::EventHandler::Reference() { + Log::Info << "[V8] Registered handler for " << std::to_string((int)type) << Log::Endl; +} diff --git a/V8Helpers.h b/V8Helpers.h index f6d6369a..8188dc71 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -132,10 +132,10 @@ namespace V8 using CallbacksGetter = std::function(V8ResourceImpl *resource, const alt::CEvent *)>; using ArgsGetter = std::function> &args)>; - EventHandler(alt::CEvent::Type type, CallbacksGetter &&_handlersGetter, ArgsGetter &&_argsGetter) : callbacksGetter(std::move(_handlersGetter)), argsGetter(std::move(_argsGetter)) - { - Register(type, this); - } + EventHandler(alt::CEvent::Type type, CallbacksGetter &&_handlersGetter, ArgsGetter &&_argsGetter); + + // Temp issue fix for https://stackoverflow.com/questions/9459980/c-global-variable-not-initialized-when-linked-through-static-libraries-but-ok + void Reference(); std::vector GetCallbacks(V8ResourceImpl *impl, const alt::CEvent *e); std::vector> GetArgs(V8ResourceImpl *impl, const alt::CEvent *e); @@ -143,6 +143,7 @@ namespace V8 static EventHandler *Get(const alt::CEvent *e); private: + alt::CEvent::Type type; CallbacksGetter callbacksGetter; ArgsGetter argsGetter; @@ -478,3 +479,8 @@ namespace V8 V8_CHECK(!baseObjectRef.IsEmpty(), "Failed to bind base object"); \ resource->BindEntity(info.This(), baseObjectRef); \ } + +#define V8_EVENT_HANDLER extern V8::EventHandler +#define V8_LOCAL_EVENT_HANDLER extern V8::LocalEventHandler +#define V8_REFERENCE_EVENT_HANDLER(name) V8_EVENT_HANDLER name; name.Reference(); +#define V8_REFERENCE_LOCAL_EVENT_HANDLER(name) V8_LOCAL_EVENT_HANDLER name; name.Reference(); diff --git a/events/Main.cpp b/events/Main.cpp index 0a4e6036..8c364669 100644 --- a/events/Main.cpp +++ b/events/Main.cpp @@ -6,14 +6,14 @@ using EventType = alt::CEvent::Type; -V8::LocalEventHandler consoleCommand( - EventType::CONSOLE_COMMAND_EVENT, - "consoleCommand", - [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { - auto ev = static_cast(e); - v8::Isolate *isolate = resource->GetIsolate(); +V8_LOCAL_EVENT_HANDLER consoleCommand( + EventType::CONSOLE_COMMAND_EVENT, + "consoleCommand", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); - args.push_back(v8::String::NewFromUtf8(isolate, ev->GetName().GetData(), v8::NewStringType::kNormal, ev->GetName().GetSize()).ToLocalChecked()); - for (auto &arg : ev->GetArgs()) - args.push_back(v8::String::NewFromUtf8(isolate, arg.GetData(), v8::NewStringType::kNormal, arg.GetSize()).ToLocalChecked()); - }); + args.push_back(v8::String::NewFromUtf8(isolate, ev->GetName().GetData(), v8::NewStringType::kNormal, ev->GetName().GetSize()).ToLocalChecked()); + for (auto &arg : ev->GetArgs()) + args.push_back(v8::String::NewFromUtf8(isolate, arg.GetData(), v8::NewStringType::kNormal, arg.GetSize()).ToLocalChecked()); + }); From 7f1c7607bfa56b7dc53781bfac484b74a36f3d18 Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 30 Dec 2020 02:14:25 +0100 Subject: [PATCH 239/564] Fixed events in static builds --- src/CV8ScriptRuntime.cpp | 3 +++ src/events/Entity.cpp | 58 ++++++++++++++++++++-------------------- src/events/Events.h | 47 ++++++++++++++++++++++++++++++++ src/events/Main.cpp | 14 +++++----- src/events/Meta.cpp | 8 +++--- src/events/Resource.cpp | 58 ++++++++++++++++++++-------------------- src/events/Vehicle.cpp | 6 ++--- src/helpers | 2 +- 8 files changed, 123 insertions(+), 73 deletions(-) create mode 100644 src/events/Events.h diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index e315e436..2a457287 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -3,6 +3,7 @@ #include "inspector/CV8InspectorClient.h" #include "inspector/CV8InspectorChannel.h" #include "helpers/V8Module.h" +#include "events/Events.h" CV8ScriptRuntime* CV8ScriptRuntime::instance = nullptr; @@ -149,4 +150,6 @@ CV8ScriptRuntime::CV8ScriptRuntime() extern V8Module altModule, nativesModule; V8Module::Add({altModule, nativesModule}); } + + RegisterEvents(); } diff --git a/src/events/Entity.cpp b/src/events/Entity.cpp index 33b35ea1..15c34df3 100644 --- a/src/events/Entity.cpp +++ b/src/events/Entity.cpp @@ -10,32 +10,32 @@ using alt::CEvent; using EventType = CEvent::Type; -V8::LocalEventHandler removeEntity( - EventType::REMOVE_ENTITY_EVENT, - "removeEntity", - [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { - auto ev = static_cast(e); - v8::Isolate *isolate = resource->GetIsolate(); - - args.push_back(resource->GetOrCreateEntity(ev->GetEntity().Get())->GetJSVal(isolate)); - }); - -V8::LocalEventHandler gameEntityCreate( - EventType::GAME_ENTITY_CREATE, - "gameEntityCreate", - [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { - auto ev = static_cast(e); - v8::Isolate *isolate = resource->GetIsolate(); - - args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - }); - -V8::LocalEventHandler gameEntityDestroy( - EventType::GAME_ENTITY_DESTROY, - "gameEntityDestroy", - [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { - auto ev = static_cast(e); - v8::Isolate *isolate = resource->GetIsolate(); - - args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - }); \ No newline at end of file +V8_LOCAL_EVENT_HANDLER removeEntity( + EventType::REMOVE_ENTITY_EVENT, + "removeEntity", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(resource->GetOrCreateEntity(ev->GetEntity().Get())->GetJSVal(isolate)); + }); + +V8_LOCAL_EVENT_HANDLER gameEntityCreate( + EventType::GAME_ENTITY_CREATE, + "gameEntityCreate", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + }); + +V8_LOCAL_EVENT_HANDLER gameEntityDestroy( + EventType::GAME_ENTITY_DESTROY, + "gameEntityDestroy", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); + }); \ No newline at end of file diff --git a/src/events/Events.h b/src/events/Events.h new file mode 100644 index 00000000..8fc706f6 --- /dev/null +++ b/src/events/Events.h @@ -0,0 +1,47 @@ +#pragma once + +#include "../helpers/V8Helpers.h" + +/** + * Needed cause MSVC requires globals to be references + * or they will be optimized away in static builds + * https://stackoverflow.com/questions/9459980/c-global-variable-not-initialized-when-linked-through-static-libraries-but-ok + * the other solutions didn't work + * + * Once the module is completely a DLL, this will not be necessary + */ +inline void RegisterEvents() +{ + // Shared + V8_REFERENCE_LOCAL_EVENT_HANDLER(consoleCommand); + + // Main + V8_REFERENCE_EVENT_HANDLER(clientScriptEvent); + V8_REFERENCE_EVENT_HANDLER(serverScriptEvent); + V8_REFERENCE_EVENT_HANDLER(webviewEvent); + V8_REFERENCE_EVENT_HANDLER(keyboardEvent); + V8_REFERENCE_LOCAL_EVENT_HANDLER(render); + V8_REFERENCE_LOCAL_EVENT_HANDLER(connectionComplete); + V8_REFERENCE_LOCAL_EVENT_HANDLER(disconnect); + + // Entity + V8_REFERENCE_LOCAL_EVENT_HANDLER(removeEntity); + V8_REFERENCE_LOCAL_EVENT_HANDLER(gameEntityCreate); + V8_REFERENCE_LOCAL_EVENT_HANDLER(gameEntityDestroy); + + // Meta + V8_REFERENCE_LOCAL_EVENT_HANDLER(syncedMetaChange); + V8_REFERENCE_LOCAL_EVENT_HANDLER(streamSyncedMetaChange); + V8_REFERENCE_LOCAL_EVENT_HANDLER(globalSyncedMetaChange); + V8_REFERENCE_LOCAL_EVENT_HANDLER(globalMetaChange); + + // Resource + V8_REFERENCE_LOCAL_EVENT_HANDLER(anyResourceStart); + V8_REFERENCE_LOCAL_EVENT_HANDLER(anyResourceStop); + V8_REFERENCE_LOCAL_EVENT_HANDLER(anyResourceError); + + // Vehicle + V8_REFERENCE_LOCAL_EVENT_HANDLER(enteredVehicle); + V8_REFERENCE_LOCAL_EVENT_HANDLER(leftVehicle); + V8_REFERENCE_LOCAL_EVENT_HANDLER(changedVehicleSeat); +} diff --git a/src/events/Main.cpp b/src/events/Main.cpp index 2d6ae9df..312c193a 100644 --- a/src/events/Main.cpp +++ b/src/events/Main.cpp @@ -18,7 +18,7 @@ using alt::CEvent; using EventType = CEvent::Type; -V8::EventHandler clientScriptEvent( +V8_EVENT_HANDLER clientScriptEvent( EventType::CLIENT_SCRIPT_EVENT, [](V8ResourceImpl* resource, const CEvent* e) { auto ev = static_cast(e); @@ -31,7 +31,7 @@ V8::EventHandler clientScriptEvent( } ); -V8::EventHandler serverScriptEvent( +V8_EVENT_HANDLER serverScriptEvent( EventType::SERVER_SCRIPT_EVENT, [](V8ResourceImpl* resource, const CEvent* e) { auto ev = static_cast(e); @@ -44,7 +44,7 @@ V8::EventHandler serverScriptEvent( } ); -V8::EventHandler webviewEvent( +V8_EVENT_HANDLER webviewEvent( EventType::WEB_VIEW_EVENT, [](V8ResourceImpl* resource, const CEvent* e) { auto ev = static_cast(e); @@ -58,7 +58,7 @@ V8::EventHandler webviewEvent( } ); -V8::EventHandler keyboardEvent( +V8_EVENT_HANDLER keyboardEvent( EventType::KEYBOARD_EVENT, [](V8ResourceImpl* resource, const CEvent* e) { auto ev = static_cast(e); @@ -75,13 +75,13 @@ V8::EventHandler keyboardEvent( } ); -V8::LocalEventHandler render( +V8_LOCAL_EVENT_HANDLER render( EventType::RENDER, "render", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { }); -V8::LocalEventHandler connectionComplete( +V8_LOCAL_EVENT_HANDLER connectionComplete( EventType::CONNECTION_COMPLETE, "connectionComplete", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { @@ -93,7 +93,7 @@ V8::LocalEventHandler connectionComplete( } }); -V8::LocalEventHandler disconnect( +V8_LOCAL_EVENT_HANDLER disconnect( EventType::DISCONNECT_EVENT, "disconnect", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { diff --git a/src/events/Meta.cpp b/src/events/Meta.cpp index 4925e83a..1a51bbd5 100644 --- a/src/events/Meta.cpp +++ b/src/events/Meta.cpp @@ -11,7 +11,7 @@ using alt::CEvent; using EventType = CEvent::Type; -V8::LocalEventHandler syncedMetaChange( +V8_LOCAL_EVENT_HANDLER syncedMetaChange( EventType::SYNCED_META_CHANGE, "syncedMetaChange", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { @@ -24,7 +24,7 @@ V8::LocalEventHandler syncedMetaChange( args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); }); -V8::LocalEventHandler streamSyncedMetaChange( +V8_LOCAL_EVENT_HANDLER streamSyncedMetaChange( EventType::STREAM_SYNCED_META_CHANGE, "streamSyncedMetaChange", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { @@ -37,7 +37,7 @@ V8::LocalEventHandler streamSyncedMetaChange( args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); }); -V8::LocalEventHandler globalSyncedMetaChange( +V8_LOCAL_EVENT_HANDLER globalSyncedMetaChange( EventType::GLOBAL_SYNCED_META_CHANGE, "globalSyncedMetaChange", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { @@ -49,7 +49,7 @@ V8::LocalEventHandler globalSyncedMetaChange( args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); }); -V8::LocalEventHandler globalMetaChange( +V8_LOCAL_EVENT_HANDLER globalMetaChange( EventType::GLOBAL_META_CHANGE, "globalMetaChange", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { diff --git a/src/events/Resource.cpp b/src/events/Resource.cpp index 18beef7b..b3aec7b6 100644 --- a/src/events/Resource.cpp +++ b/src/events/Resource.cpp @@ -10,32 +10,32 @@ using alt::CEvent; using EventType = CEvent::Type; -V8::LocalEventHandler anyResourceStart( - EventType::RESOURCE_START, - "anyResourceStart", - [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { - auto ev = static_cast(e); - v8::Isolate *isolate = resource->GetIsolate(); - - args.push_back(V8_NEW_STRING(ev->GetResource()->GetName().CStr())); - }); - -V8::LocalEventHandler anyResourceStop( - EventType::RESOURCE_STOP, - "anyResourceStop", - [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { - auto ev = static_cast(e); - v8::Isolate *isolate = resource->GetIsolate(); - - args.push_back(V8_NEW_STRING(ev->GetResource()->GetName().CStr())); - }); - -V8::LocalEventHandler anyResourceError( - EventType::RESOURCE_ERROR, - "anyResourceError", - [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { - auto ev = static_cast(e); - v8::Isolate *isolate = resource->GetIsolate(); - - args.push_back(V8_NEW_STRING(ev->GetResource()->GetName().CStr())); - }); \ No newline at end of file +V8_LOCAL_EVENT_HANDLER anyResourceStart( + EventType::RESOURCE_START, + "anyResourceStart", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(V8_NEW_STRING(ev->GetResource()->GetName().CStr())); + }); + +V8_LOCAL_EVENT_HANDLER anyResourceStop( + EventType::RESOURCE_STOP, + "anyResourceStop", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(V8_NEW_STRING(ev->GetResource()->GetName().CStr())); + }); + +V8_LOCAL_EVENT_HANDLER anyResourceError( + EventType::RESOURCE_ERROR, + "anyResourceError", + [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { + auto ev = static_cast(e); + v8::Isolate *isolate = resource->GetIsolate(); + + args.push_back(V8_NEW_STRING(ev->GetResource()->GetName().CStr())); + }); \ No newline at end of file diff --git a/src/events/Vehicle.cpp b/src/events/Vehicle.cpp index 7899ac12..d06c4e64 100644 --- a/src/events/Vehicle.cpp +++ b/src/events/Vehicle.cpp @@ -10,7 +10,7 @@ using alt::CEvent; using EventType = CEvent::Type; -V8::LocalEventHandler enteredVehicle( +V8_LOCAL_EVENT_HANDLER enteredVehicle( EventType::PLAYER_ENTER_VEHICLE, "enteredVehicle", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { @@ -21,7 +21,7 @@ V8::LocalEventHandler enteredVehicle( args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetSeat())); }); -V8::LocalEventHandler leftVehicle( +V8_LOCAL_EVENT_HANDLER leftVehicle( EventType::PLAYER_LEAVE_VEHICLE, "leftVehicle", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { @@ -32,7 +32,7 @@ V8::LocalEventHandler leftVehicle( args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetSeat())); }); -V8::LocalEventHandler changedVehicleSeat( +V8_LOCAL_EVENT_HANDLER changedVehicleSeat( EventType::PLAYER_CHANGE_VEHICLE_SEAT, "changedVehicleSeat", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { diff --git a/src/helpers b/src/helpers index ea0d90e9..e8876a10 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit ea0d90e9625574442fd828240d49a58740fc3a8a +Subproject commit e8876a1000432fb19fa43c82c0ce2e86a40637dc From 7d310baae5ef22f00af3544b18d6052596826cb1 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 30 Dec 2020 02:38:04 +0100 Subject: [PATCH 240/564] fix websocket stuff --- src/bindings/WebSocketClient.cpp | 6 +++--- src/cpp-sdk | 2 +- src/events/Main.cpp | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index fd9df4a2..dc70d39b 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -20,7 +20,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) alt::Ref webSocket = nullptr; - webSocket = alt::ICore::Instance().CreateWebSocketClient(url, altres); + webSocket = alt::ICore::Instance().CreateWebSocketClient(url.ToString(), altres); V8_BIND_BASE_OBJECT(webSocket); } @@ -69,7 +69,7 @@ static void Send(const v8::FunctionCallbackInfo& info) V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - webSocket->Send(msg); + webSocket->Send(msg.CStr()); } static void Stop(const v8::FunctionCallbackInfo& info) @@ -98,7 +98,7 @@ static void URLSetter(v8::Local property, v8::Local value V8_TO_STRING(value, url); - webSocket->SetUrl(url); + webSocket->SetUrl(url.ToString()); } static void StateGetter(v8::Local property, const v8::PropertyCallbackInfo& info) diff --git a/src/cpp-sdk b/src/cpp-sdk index 3f14ad8b..98b8e18d 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 3f14ad8bd3af35b2c4f94c7eaf1c6ab4aa87773c +Subproject commit 98b8e18de88d7f0f9ece43c7fe25250fc017bde7 diff --git a/src/events/Main.cpp b/src/events/Main.cpp index 312c193a..f0c77de2 100644 --- a/src/events/Main.cpp +++ b/src/events/Main.cpp @@ -12,6 +12,7 @@ #include "cpp-sdk/events/CServerScriptEvent.h" #include "cpp-sdk/events/CKeyboardEvent.h" #include "cpp-sdk/events/CWebViewEvent.h" +#include "cpp-sdk/events/CWebSocketClientEvent.h" #include "cpp-sdk/SDK.h" @@ -49,7 +50,7 @@ V8_EVENT_HANDLER webviewEvent( [](V8ResourceImpl* resource, const CEvent* e) { auto ev = static_cast(e); - return static_cast(resource)->GetWebviewHandlers(ev->GetTarget(), ev->GetName().ToString()); + return static_cast(resource)->GetWebViewHandlers(ev->GetTarget(), ev->GetName().ToString()); }, [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { auto ev = static_cast(e); @@ -58,6 +59,20 @@ V8_EVENT_HANDLER webviewEvent( } ); +V8_EVENT_HANDLER webSocketEvent( + EventType::WEB_SOCKET_CLIENT_EVENT, + [](V8ResourceImpl* resource, const CEvent* e) { + auto ev = static_cast(e); + + return static_cast(resource)->GetWebSocketClientHandlers(ev->GetTarget(), ev->GetName().ToString()); + }, + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + } + ); + V8_EVENT_HANDLER keyboardEvent( EventType::KEYBOARD_EVENT, [](V8ResourceImpl* resource, const CEvent* e) { From a572647fa6d512f3d34d075a632e2965dd4942d4 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 30 Dec 2020 02:45:31 +0100 Subject: [PATCH 241/564] Revert "Merge pull request #29 from LeonMrBonnie/cpp-sdk-submodule" This reverts commit 2f7896fa003975893dcfcc9030086e1a9868a72b, reversing changes made to 15235ff933893de8e0accfbc4e0cf1a7786b590a. --- .gitmodules | 5 +---- CMakeLists.txt | 10 +++++++++- src/cpp-sdk | 1 - 3 files changed, 10 insertions(+), 6 deletions(-) delete mode 160000 src/cpp-sdk diff --git a/.gitmodules b/.gitmodules index 0b7b9532..4ea3e8e6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "src/helpers"] path = src/helpers - url = https://github.com/altmp/v8-helpers.git -[submodule "src/cpp-sdk"] - path = src/cpp-sdk - url = https://github.com/altmp/cpp-sdk.git + url = https://github.com/altmp/v8-helpers.git \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 64f50b30..22d5aac0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,15 @@ set(ALTV_JS_DL_DEPS ${altv-js-deps_SOURCE_DIR}) # cpp-sdk if(NOT ALTV_JS_CPP_SDK) - set(ALTV_JS_CPP_SDK src) + git_clone( + PROJECT_NAME cpp-sdk + GIT_URL https://github.com/altmp/cpp-sdk + GIT_BRANCH master + DIRECTORY ${ALTV_JS_DL_DEPS} + ) + set(ALTV_JS_CPP_SDK ${ALTV_JS_DL_DEPS}) +else() + message("alt:V JS - Skipping fetching cpp-sdk") endif() # Fetch deps diff --git a/src/cpp-sdk b/src/cpp-sdk deleted file mode 160000 index 98b8e18d..00000000 --- a/src/cpp-sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 98b8e18de88d7f0f9ece43c7fe25250fc017bde7 From b0bd8af2a9699f408f4d973d14de939d2e98d562 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 30 Dec 2020 03:21:31 +0100 Subject: [PATCH 242/564] add per message deflate options --- src/bindings/WebSocketClient.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index dc70d39b..1b08cc3f 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -130,6 +130,26 @@ static void AutoReconnectGetter(v8::Local property, const v8::Proper V8_RETURN_BOOLEAN(webSocket->IsAutoReconnectEnabled()); } +static void PerMessageDeflateSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + V8_TO_BOOLEAN(value, toggle); + + webSocket->SetPerMessageDeflateEnabled(toggle); +} + +static void PerMessageDeflateGetter(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + V8_RETURN_BOOLEAN(webSocket->IsPerMessageDeflateEnabled()); +} + static void PingIntervalSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -162,6 +182,7 @@ extern V8Class v8WebSocketClient("WebSocketClient", v8BaseObject, &Constructor, V8::SetMethod(isolate, tpl, "stop", &Stop); V8::SetAccessor(isolate, tpl, "autoReconnect", &AutoReconnectGetter, &AutoReconnectSetter); + V8::SetAccessor(isolate, tpl, "perMessageDeflate", &PerMessageDeflateGetter, &PerMessageDeflateSetter); V8::SetAccessor(isolate, tpl, "pingInterval", &PingIntervalGetter, &PingIntervalSetter); V8::SetAccessor(isolate, tpl, "url", &URLGetter, &URLSetter); V8::SetAccessor(isolate, tpl, "state", &StateGetter, nullptr); From eb9e78192e073e91aee9688dc3b3473e8b2575fb Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 30 Dec 2020 03:25:23 +0100 Subject: [PATCH 243/564] websocket send will now return boolean to know if the send was successful or not --- src/bindings/WebSocketClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index 1b08cc3f..cf2fce75 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -69,7 +69,7 @@ static void Send(const v8::FunctionCallbackInfo& info) V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - webSocket->Send(msg.CStr()); + V8_RETURN_BOOLEAN(webSocket->Send(msg.CStr())); } static void Stop(const v8::FunctionCallbackInfo& info) From d5542c9f50dfa4956ac5c2e9662e7b611a475b66 Mon Sep 17 00:00:00 2001 From: Vektor Date: Wed, 30 Dec 2020 03:59:54 +0100 Subject: [PATCH 244/564] add protocol stuff to websocket --- src/bindings/WebSocketClient.cpp | 36 ++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index cf2fce75..eb341903 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -20,7 +20,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) alt::Ref webSocket = nullptr; - webSocket = alt::ICore::Instance().CreateWebSocketClient(url.ToString(), altres); + webSocket = alt::ICore::Instance().CreateWebSocketClient(url, altres); V8_BIND_BASE_OBJECT(webSocket); } @@ -81,6 +81,35 @@ static void Stop(const v8::FunctionCallbackInfo& info) webSocket->Stop(); } +static void AddSubProtocol(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, msg); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + webSocket->AddSubProtocol(msg); +} + +static void GetSubProtocols(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + auto protocols = webSocket->GetSubProtocols(); + + v8::Local protocolsArray = v8::Array::New(isolate, protocols.size()); + + int idx = 0; + for(auto& protocol : protocols) + protocolsArray->Set(ctx, idx++, v8::String::NewFromUtf8(isolate, protocol.CStr()).ToLocalChecked()); + + V8_RETURN(protocolsArray); +} + static void URLGetter(v8::Local property, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); @@ -98,7 +127,7 @@ static void URLSetter(v8::Local property, v8::Local value V8_TO_STRING(value, url); - webSocket->SetUrl(url.ToString()); + webSocket->SetUrl(url); } static void StateGetter(v8::Local property, const v8::PropertyCallbackInfo& info) @@ -181,6 +210,9 @@ extern V8Class v8WebSocketClient("WebSocketClient", v8BaseObject, &Constructor, V8::SetMethod(isolate, tpl, "send", &Send); V8::SetMethod(isolate, tpl, "stop", &Stop); + V8::SetMethod(isolate, tpl, "addSubProtocol", &AddSubProtocol); + V8::SetMethod(isolate, tpl, "getSubProtocols", &GetSubProtocols); + V8::SetAccessor(isolate, tpl, "autoReconnect", &AutoReconnectGetter, &AutoReconnectSetter); V8::SetAccessor(isolate, tpl, "perMessageDeflate", &PerMessageDeflateGetter, &PerMessageDeflateSetter); V8::SetAccessor(isolate, tpl, "pingInterval", &PingIntervalGetter, &PingIntervalSetter); From 389308bf939a09dedacf76c9f50b69cb8eb86d0a Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 30 Dec 2020 05:21:40 +0100 Subject: [PATCH 245/564] Deinit cpp-sdk if set external --- CMakeLists.txt | 5 +++++ tools/deinit-cppsdk.bat | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 tools/deinit-cppsdk.bat diff --git a/CMakeLists.txt b/CMakeLists.txt index 64f50b30..fcc2a6c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,3 +105,8 @@ target_compile_definitions(${PROJECT_NAME}-static PRIVATE target_link_libraries(${PROJECT_NAME}-static PRIVATE ${ALTV_JS_LINKS} ) +add_custom_command(TARGET ${PROJECT_NAME}-static + PRE_BUILD + COMMAND cmd /C "tools\\deinit-cppsdk.bat" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} +) diff --git a/tools/deinit-cppsdk.bat b/tools/deinit-cppsdk.bat new file mode 100644 index 00000000..6f8851de --- /dev/null +++ b/tools/deinit-cppsdk.bat @@ -0,0 +1,6 @@ +@echo off + +if EXIST src/cpp-sdk/SDK.h ( + echo alt:V JS - Using external cpp-sdk, deiniting local cpp-sdk + git submodule deinit -f src/cpp-sdk +) From a87f4b38a4cf16228a460e1638e7c1d83cf1ff32 Mon Sep 17 00:00:00 2001 From: Hazard Date: Wed, 30 Dec 2020 19:09:58 +0100 Subject: [PATCH 246/564] Deinit CPPSDK only if set to external path --- CMakeLists.txt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fcc2a6c5..31dfb8ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,8 @@ set(ALTV_JS_DL_DEPS ${altv-js-deps_SOURCE_DIR}) # cpp-sdk if(NOT ALTV_JS_CPP_SDK) set(ALTV_JS_CPP_SDK src) +else() + set(ALTV_JS_DEINIT_CPPSDK) endif() # Fetch deps @@ -105,8 +107,10 @@ target_compile_definitions(${PROJECT_NAME}-static PRIVATE target_link_libraries(${PROJECT_NAME}-static PRIVATE ${ALTV_JS_LINKS} ) -add_custom_command(TARGET ${PROJECT_NAME}-static - PRE_BUILD - COMMAND cmd /C "tools\\deinit-cppsdk.bat" - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} -) +if(ALTV_JS_DEINIT_CPPSDK) + add_custom_command(TARGET ${PROJECT_NAME}-static + PRE_BUILD + COMMAND cmd /C "tools\\deinit-cppsdk.bat" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + ) +endif() \ No newline at end of file From cea7528403dfc63f47562c70cf565f504ef4eece Mon Sep 17 00:00:00 2001 From: Vektor Date: Thu, 31 Dec 2020 17:46:32 +0100 Subject: [PATCH 247/564] merge dev --- .gitmodules | 5 ++++- src/cpp-sdk | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) create mode 160000 src/cpp-sdk diff --git a/.gitmodules b/.gitmodules index 4ea3e8e6..39da27e1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "src/helpers"] path = src/helpers - url = https://github.com/altmp/v8-helpers.git \ No newline at end of file + url = https://github.com/altmp/v8-helpers.git +[submodule "src/cpp-sdk"] + path = src/cpp-sdk + url = ../cpp-sdk.git diff --git a/src/cpp-sdk b/src/cpp-sdk new file mode 160000 index 00000000..98b8e18d --- /dev/null +++ b/src/cpp-sdk @@ -0,0 +1 @@ +Subproject commit 98b8e18de88d7f0f9ece43c7fe25250fc017bde7 From e72bc60c97f14d60b76b5e9d62485bdf02ccc209 Mon Sep 17 00:00:00 2001 From: Vektor Date: Thu, 31 Dec 2020 17:50:04 +0100 Subject: [PATCH 248/564] update cpp sdk --- src/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index 98b8e18d..cfcb8c2b 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 98b8e18de88d7f0f9ece43c7fe25250fc017bde7 +Subproject commit cfcb8c2bcd5963e227b2e76537d2f8e01495101a From 2e2d3c51511dd29b89ca505ff53ee87bb935c144 Mon Sep 17 00:00:00 2001 From: Hazard Date: Thu, 31 Dec 2020 19:51:06 +0100 Subject: [PATCH 249/564] Move cpp-sdk --- .gitmodules | 6 +++--- CMakeLists.txt | 4 ++-- {src => deps/cpp-sdk}/cpp-sdk | 0 tools/deinit-cppsdk.bat | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) rename {src => deps/cpp-sdk}/cpp-sdk (100%) diff --git a/.gitmodules b/.gitmodules index 39da27e1..010a1fef 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "src/helpers"] path = src/helpers url = https://github.com/altmp/v8-helpers.git -[submodule "src/cpp-sdk"] - path = src/cpp-sdk - url = ../cpp-sdk.git +[submodule "deps/cpp-sdk/cpp-sdk"] + path = deps/cpp-sdk/cpp-sdk + url = https://github.com/altmp/cpp-sdk.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 31dfb8ad..df97dc7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,9 +17,9 @@ set(ALTV_JS_DL_DEPS ${altv-js-deps_SOURCE_DIR}) # cpp-sdk if(NOT ALTV_JS_CPP_SDK) - set(ALTV_JS_CPP_SDK src) + set(ALTV_JS_CPP_SDK deps/cpp-sdk) else() - set(ALTV_JS_DEINIT_CPPSDK) + set(ALTV_JS_DEINIT_CPPSDK 1) endif() # Fetch deps diff --git a/src/cpp-sdk b/deps/cpp-sdk/cpp-sdk similarity index 100% rename from src/cpp-sdk rename to deps/cpp-sdk/cpp-sdk diff --git a/tools/deinit-cppsdk.bat b/tools/deinit-cppsdk.bat index 6f8851de..843a061b 100644 --- a/tools/deinit-cppsdk.bat +++ b/tools/deinit-cppsdk.bat @@ -1,6 +1,6 @@ @echo off -if EXIST src/cpp-sdk/SDK.h ( +if EXIST deps/cpp-sdk/cpp-sdk/SDK.h ( echo alt:V JS - Using external cpp-sdk, deiniting local cpp-sdk - git submodule deinit -f src/cpp-sdk + git submodule deinit -f deps/cpp-sdk/cpp-sdk ) From 641a151bf1a7866b4bc819d9ac088708b526879b Mon Sep 17 00:00:00 2001 From: Hazard Date: Fri, 1 Jan 2021 17:45:27 +0100 Subject: [PATCH 250/564] Update cppsdk --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/WebSocketClient.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index cfcb8c2b..109bb998 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit cfcb8c2bcd5963e227b2e76537d2f8e01495101a +Subproject commit 109bb998736820e58657abb69e257dafeefd04ef diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index eb341903..4ddb1736 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -101,7 +101,7 @@ static void GetSubProtocols(const v8::FunctionCallbackInfo& info) auto protocols = webSocket->GetSubProtocols(); - v8::Local protocolsArray = v8::Array::New(isolate, protocols.size()); + v8::Local protocolsArray = v8::Array::New(isolate, protocols.GetSize()); int idx = 0; for(auto& protocol : protocols) From b2ae0bc7ce9cc180d9987963f0fd91a51999b47c Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 1 Jan 2021 20:24:36 +0100 Subject: [PATCH 251/564] ws: rename state to readyState, add extra header functions --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/WebSocketClient.cpp | 41 ++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 109bb998..4104eca8 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 109bb998736820e58657abb69e257dafeefd04ef +Subproject commit 4104eca8b353c6800db96de6aa5e33d723cc1ecc diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index 4ddb1736..bf1cdcb3 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -104,12 +104,42 @@ static void GetSubProtocols(const v8::FunctionCallbackInfo& info) v8::Local protocolsArray = v8::Array::New(isolate, protocols.GetSize()); int idx = 0; - for(auto& protocol : protocols) + for (auto& protocol : protocols) protocolsArray->Set(ctx, idx++, v8::String::NewFromUtf8(isolate, protocol.CStr()).ToLocalChecked()); V8_RETURN(protocolsArray); } +static void SetExtraHeader(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, msg); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + webSocket->AddSubProtocol(msg); +} + +static void GetExtraHeaders(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + auto extraHeaders = webSocket->GetExtraHeaders(); + V8_NEW_OBJECT(headersObject); + + for (auto it = extraHeaders->Begin(); it; it = extraHeaders->Next()) + { + alt::String key = it->GetKey(); + V8_OBJECT_SET_STRING(headersObject, key.CStr(), extraHeaders->Get(key).As()->Value()); + } + + V8_RETURN(headersObject); +} + static void URLGetter(v8::Local property, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); @@ -130,13 +160,13 @@ static void URLSetter(v8::Local property, v8::Local value webSocket->SetUrl(url); } -static void StateGetter(v8::Local property, const v8::PropertyCallbackInfo& info) +static void ReadyStateGetter(v8::Local property, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - V8_RETURN_UINT32(webSocket->GetState()); + V8_RETURN_UINT32(webSocket->GetReadyState()); } static void AutoReconnectSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -213,9 +243,12 @@ extern V8Class v8WebSocketClient("WebSocketClient", v8BaseObject, &Constructor, V8::SetMethod(isolate, tpl, "addSubProtocol", &AddSubProtocol); V8::SetMethod(isolate, tpl, "getSubProtocols", &GetSubProtocols); + V8::SetMethod(isolate, tpl, "setExtraHeader", &SetExtraHeader); + V8::SetMethod(isolate, tpl, "getExtraHeaders", &GetExtraHeaders); + V8::SetAccessor(isolate, tpl, "autoReconnect", &AutoReconnectGetter, &AutoReconnectSetter); V8::SetAccessor(isolate, tpl, "perMessageDeflate", &PerMessageDeflateGetter, &PerMessageDeflateSetter); V8::SetAccessor(isolate, tpl, "pingInterval", &PingIntervalGetter, &PingIntervalSetter); V8::SetAccessor(isolate, tpl, "url", &URLGetter, &URLSetter); - V8::SetAccessor(isolate, tpl, "state", &StateGetter, nullptr); + V8::SetAccessor(isolate, tpl, "readyState", &ReadyStateGetter, nullptr); }); From dc33987128efc9696db59da00e769d391bc302ef Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 1 Jan 2021 21:54:27 +0100 Subject: [PATCH 252/564] fix ws setExtraHeader --- src/bindings/WebSocketClient.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index bf1cdcb3..04aeb9ff 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -114,12 +114,13 @@ static void SetExtraHeader(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); - V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_STRING(1, msg); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, name); + V8_ARG_TO_STRING(2, value); V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - webSocket->AddSubProtocol(msg); + webSocket->SetExtraHeader(name, value); } static void GetExtraHeaders(const v8::FunctionCallbackInfo& info) From a8c177af79514e95978cc2e8fe078a7fca60c30c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 1 Jan 2021 23:04:52 +0100 Subject: [PATCH 253/564] Fix Vector3 add method with array --- bindings/Vector3.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index b9d8f18b..982ff6b3 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -92,8 +92,8 @@ static void Add(const v8::FunctionCallbackInfo& info) V8_CHECK(arr->Length() == 3, "Argument must be an array of 3 numbers"); V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); - V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), y2); - V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), z2); + V8_TO_NUMBER(arr->Get(ctx, 1).ToLocalChecked(), y2); + V8_TO_NUMBER(arr->Get(ctx, 2).ToLocalChecked(), z2); V8_RETURN(resource->CreateVector3({ x + x2, y + y2, z + z2 })); } else if (arg->IsObject()) From df584008765506ceb806a817659ec022963a3490 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 1 Jan 2021 23:06:56 +0100 Subject: [PATCH 254/564] Fix all Vector3 methods that accept array --- bindings/Vector3.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index 982ff6b3..f58a8f59 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -147,8 +147,8 @@ static void Sub(const v8::FunctionCallbackInfo& info) V8_CHECK(arr->Length() == 3, "Argument must be an array of 3 numbers"); V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); - V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), y2); - V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), z2); + V8_TO_NUMBER(arr->Get(ctx, 1).ToLocalChecked(), y2); + V8_TO_NUMBER(arr->Get(ctx, 2).ToLocalChecked(), z2); V8_RETURN(resource->CreateVector3({ x - x2, y - y2, z - z2 })); } else if (arg->IsObject()) @@ -204,8 +204,8 @@ static void Divide(const v8::FunctionCallbackInfo& info) V8_CHECK(arr->Length() == 3, "Argument must be an array of 3 numbers"); V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); - V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), y2); - V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), z2); + V8_TO_NUMBER(arr->Get(ctx, 1).ToLocalChecked(), y2); + V8_TO_NUMBER(arr->Get(ctx, 2).ToLocalChecked(), z2); V8_CHECK(x2 != 0 && y2 != 0 && z2 != 0, "Division by zero"); V8_RETURN(resource->CreateVector3({ x / x2, y / y2, z / z2 })); } @@ -260,8 +260,8 @@ static void Multiply(const v8::FunctionCallbackInfo& info) V8_CHECK(arr->Length() == 3, "Argument must be an array of 3 numbers"); V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); - V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), y2); - V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), z2); + V8_TO_NUMBER(arr->Get(ctx, 1).ToLocalChecked(), y2); + V8_TO_NUMBER(arr->Get(ctx, 2).ToLocalChecked(), z2); V8_RETURN(resource->CreateVector3({ x * x2, y * y2, z * z2 })); } else if (arg->IsObject()) From 688e5289cb30004d17c86c06e4c59f66f8010cd9 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 1 Jan 2021 23:21:53 +0100 Subject: [PATCH 255/564] Add helper methods to Vector2 class --- bindings/Vector2.cpp | 440 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 440 insertions(+) diff --git a/bindings/Vector2.cpp b/bindings/Vector2.cpp index 09a43970..b3c7ff93 100644 --- a/bindings/Vector2.cpp +++ b/bindings/Vector2.cpp @@ -2,6 +2,431 @@ #include "../V8Helpers.h" #include "../V8ResourceImpl.h" +constexpr double PI = 3.141592653589793238463; + +static void ToString(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + std::ostringstream ss; + ss << std::fixed << std::setprecision(4) + << "Vector2{ x: " << x << ", y: " << y << " }"; + + V8_RETURN_STRING(ss.str().c_str()); +} + +static void ToArray(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + v8::Local arr = v8::Array::New(isolate, 2); + arr->Set(ctx, 0, v8::Number::New(isolate, x)); + arr->Set(ctx, 1, v8::Number::New(isolate, y)); + + V8_RETURN(arr); +} + +static void Length(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + double length = sqrt(x * x + y * y); + + V8_RETURN_NUMBER(length); +} + + +static void Add(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN2(1, 2); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + if (info.Length() == 2) + { + V8_ARG_TO_NUMBER(1, x2); + V8_ARG_TO_NUMBER(2, y2); + + V8_RETURN(resource->CreateVector2({ x + x2, y + y2 })); + } + else if (info.Length() == 1) + { + auto arg = info[0]; + if (arg->IsNumber()) + { + V8_ARG_TO_NUMBER(1, value); + V8_RETURN(resource->CreateVector2({ x + value, y + value })); + } + else if (arg->IsArray()) + { + v8::Local arr = arg.As(); + V8_CHECK(arr->Length() == 2, "Argument must be an array of 2 numbers"); + + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); + V8_TO_NUMBER(arr->Get(ctx, 1).ToLocalChecked(), y2); + V8_RETURN(resource->CreateVector2({ x + x2, y + y2 })); + } + else if (arg->IsObject()) + { + v8::Local obj = arg.As(); + + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + + V8_RETURN(resource->CreateVector2({ x + x2, y + y2 })); + } + else + { + V8Helpers::Throw(isolate, "Argument must be a number, an array of 2 numbers or IVector2"); + } + } +} + +static void Sub(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN2(1, 3); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + if (info.Length() == 2) + { + V8_ARG_TO_NUMBER(1, x2); + V8_ARG_TO_NUMBER(2, y2); + + V8_RETURN(resource->CreateVector2({ x - x2, y - y2 })); + } + else if (info.Length() == 1) + { + auto arg = info[0]; + if (arg->IsNumber()) + { + V8_ARG_TO_NUMBER(1, value); + V8_RETURN(resource->CreateVector2({ x - value, y - value })); + } + else if (arg->IsArray()) + { + v8::Local arr = arg.As(); + V8_CHECK(arr->Length() == 2, "Argument must be an array of 2 numbers"); + + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); + V8_TO_NUMBER(arr->Get(ctx, 1).ToLocalChecked(), y2); + V8_RETURN(resource->CreateVector2({ x - x2, y - y2 })); + } + else if (arg->IsObject()) + { + v8::Local obj = arg.As(); + + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + + V8_RETURN(resource->CreateVector2({ x - x2, y - y2 })); + } + else + { + V8Helpers::Throw(isolate, "Argument must be a number, an array of 2 numbers or IVector2"); + } + } +} + +static void Divide(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN2(1, 3); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + if (info.Length() == 2) + { + V8_ARG_TO_NUMBER(1, x2); + V8_ARG_TO_NUMBER(2, y2); + + V8_CHECK(x2 != 0 && y2 != 0, "Division by zero"); + V8_RETURN(resource->CreateVector2({ x / x2, y / y2 })); + } + else if (info.Length() == 1) + { + auto arg = info[0]; + if (arg->IsNumber()) + { + V8_ARG_TO_NUMBER(1, value); + V8_CHECK(value != 0, "Division by zero"); + V8_RETURN(resource->CreateVector2({ x / value, y / value })); + } + else if (arg->IsArray()) + { + v8::Local arr = arg.As(); + V8_CHECK(arr->Length() == 2, "Argument must be an array of 2 numbers"); + + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); + V8_TO_NUMBER(arr->Get(ctx, 1).ToLocalChecked(), y2); + V8_CHECK(x2 != 0 && y2 != 0, "Division by zero"); + V8_RETURN(resource->CreateVector2({ x / x2, y / y2 })); + } + else if (arg->IsObject()) + { + v8::Local obj = arg.As(); + + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + V8_CHECK(x2 != 0 && y2 != 0, "Division by zero"); + V8_RETURN(resource->CreateVector2({ x / x2, y / y2 })); + } + else + { + V8Helpers::Throw(isolate, "Argument must be a number, an array of 2 numbers or IVector2"); + } + } +} + +static void Multiply(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN2(1, 3); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + if (info.Length() == 2) + { + V8_ARG_TO_NUMBER(1, x2); + V8_ARG_TO_NUMBER(2, y2); + + V8_RETURN(resource->CreateVector2({ x * x2, y * y2 })); + } + else if (info.Length() == 1) + { + auto arg = info[0]; + if (arg->IsNumber()) + { + V8_ARG_TO_NUMBER(1, value); + V8_RETURN(resource->CreateVector2({ x * value, y * value })); + } + else if (arg->IsArray()) + { + v8::Local arr = arg.As(); + V8_CHECK(arr->Length() == 2, "Argument must be an array of 2 numbers"); + + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); + V8_TO_NUMBER(arr->Get(ctx, 1).ToLocalChecked(), y2); + V8_RETURN(resource->CreateVector2({ x * x2, y * y2 })); + } + else if (arg->IsObject()) + { + v8::Local obj = arg.As(); + + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + + V8_RETURN(resource->CreateVector2({ x * x2, y * y2 })); + } + else + { + V8Helpers::Throw(isolate, "Argument must be a number, an array of 2 numbers or IVector2"); + } + } +} + +static void Negative(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + V8_RETURN(resource->CreateVector2({ -x, -y })); +} + +static void Normalize(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + double length = sqrt(x * x + y * y); + + V8_RETURN(resource->CreateVector2({ x / length, y / length })); +} + + +static void DistanceTo(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + V8_ARG_TO_OBJECT(1, vec); + + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + + double dist = sqrt(std::pow(x - x2, 2) + std::pow(y - y2, 2)); + + V8_RETURN_NUMBER(dist); +} + +static void AngleTo(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + V8_ARG_TO_OBJECT(1, vec); + + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + + double xy = x * x2 + y * y2; + double posALength = sqrt(std::pow(x, 2) + std::pow(y, 2)); + double posBLength = sqrt(std::pow(x2, 2) + std::pow(y2, 2)); + + if (posALength == 0 || posBLength == 0) + { + V8Helpers::Throw(isolate, "Division by zero!"); + return; + } + + double cos = xy / (posALength * posBLength); + double radians = std::acos(cos); + // double angle = radians * (180 / PI); + + V8_RETURN_NUMBER(radians); +} + +static void AngleToDegrees(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + V8_ARG_TO_OBJECT(1, vec); + + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + + double xy = x * x2 + y * y2; + double posALength = sqrt(std::pow(x, 2) + std::pow(y, 2)); + double posBLength = sqrt(std::pow(x2, 2) + std::pow(y2, 2)); + + if (posALength == 0 || posBLength == 0) + { + V8Helpers::Throw(isolate, "Division by zero!"); + return; + } + + double cos = xy / (posALength * posBLength); + double radians = std::acos(cos); + double angle = radians * (180 / PI); + + V8_RETURN_NUMBER(angle); +} + +static void ToDegrees(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + double x2 = (x * 180) / PI; + double y2 = (y * 180) / PI; + + V8_RETURN(resource->CreateVector2({ x2, y2 })); +} + +static void ToRadians(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + double x2 = (x * PI) / 180; + double y2 = (y * PI) / 180; + + V8_RETURN(resource->CreateVector2({ x2, y2 })); +} + +static void IsInRange(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN(2); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + V8_ARG_TO_OBJECT(1, vec); + V8_ARG_TO_NUMBER(2, range); + + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + + double dx = abs(x - x2); + double dy = abs(y - y2); + + bool isInRange = + dx <= range && // perform fast check first + dy <= range && + dx * dx + dy * dy <= range * range; // perform exact check + + V8_RETURN_BOOLEAN(isInRange); +} + static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -60,4 +485,19 @@ static void Constructor(const v8::FunctionCallbackInfo& info) extern V8Class v8Vector2("Vector2", Constructor, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8::SetAccessor(isolate, tpl, "length", Length); + V8::SetMethod(isolate, tpl, "toString", ToString); + V8::SetMethod(isolate, tpl, "toArray", ToArray); + V8::SetMethod(isolate, tpl, "add", Add); + V8::SetMethod(isolate, tpl, "sub", Sub); + V8::SetMethod(isolate, tpl, "div", Divide); + V8::SetMethod(isolate, tpl, "mul", Multiply); + V8::SetMethod(isolate, tpl, "negative", Negative); + V8::SetMethod(isolate, tpl, "normalize", Normalize); + V8::SetMethod(isolate, tpl, "distanceTo", DistanceTo); + V8::SetMethod(isolate, tpl, "angleTo", AngleTo); + V8::SetMethod(isolate, tpl, "angleToDegrees", AngleToDegrees); + V8::SetMethod(isolate, tpl, "toRadians", ToRadians); + V8::SetMethod(isolate, tpl, "toDegrees", ToDegrees); + V8::SetMethod(isolate, tpl, "isInRange", IsInRange); }); From ad911b2d90fd284a17cb2d8749caab266644e790 Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 1 Jan 2021 23:39:40 +0100 Subject: [PATCH 256/564] add ArrayBuffer and ArrayBufferView support --- V8Helpers.cpp | 22 ++++++++++++++++++++++ V8Helpers.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index b14f1bc9..dde71820 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -600,6 +600,28 @@ bool V8::SafeToObject(v8::Local val, v8::Local ctx, v8:: return false; } +bool V8::SafeToArrayBuffer(v8::Local val, v8::Local ctx, v8::Local& out) +{ + if (val->IsArrayBuffer()) + { + out = val.As(); + return true; + } + + return false; +} + +bool V8::SafeToArrayBufferView(v8::Local val, v8::Local ctx, v8::Local& out) +{ + if (val->IsArrayBufferView()) + { + out = val.As(); + return true; + } + + return false; +} + std::vector V8::EventHandler::GetCallbacks(V8ResourceImpl *impl, const alt::CEvent *e) { return callbacksGetter(impl, e); diff --git a/V8Helpers.h b/V8Helpers.h index 8188dc71..09c1d61d 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -212,6 +212,8 @@ namespace V8 bool SafeToString(v8::Local val, v8::Isolate *isolate, v8::Local ctx, alt::String &out); bool SafeToFunction(v8::Local val, v8::Local ctx, v8::Local& out); bool SafeToObject(v8::Local val, v8::Local ctx, v8::Local& out); + bool SafeToArrayBuffer(v8::Local val, v8::Local ctx, v8::Local& out); + bool SafeToArrayBufferView(v8::Local val, v8::Local ctx, v8::Local& out); bool SafeToUInt64(v8::Local val, v8::Local ctx, uint64_t& out); bool SafeToInt64(v8::Local val, v8::Local ctx, int64_t& out); From 1c9d08ac3def82e286d77dae0371c5573169a3b9 Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 1 Jan 2021 23:41:35 +0100 Subject: [PATCH 257/564] add ws binary sending support --- src/bindings/WebSocketClient.cpp | 26 +++++++++++++++++++++++--- src/helpers | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index 04aeb9ff..ebd3cc1a 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -65,11 +65,31 @@ static void Send(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_STRING(1, msg); - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - V8_RETURN_BOOLEAN(webSocket->Send(msg.CStr())); + bool ret = false; + if (info[0]->IsString()) + { + V8_ARG_TO_STRING(1, msg); + ret = webSocket->Send(msg); + } + else if (info[0]->IsArrayBufferView()) + { + V8_ARG_TO_ARRAY_BUFFER_VIEW(1, v8ArrayBufferView); + auto v8Buffer = v8ArrayBufferView->Buffer()->GetContents(); + ret = webSocket->SendBinary(alt::StringView((char*)v8Buffer.Data(), v8Buffer.ByteLength())); + } + else if (info[0]->IsArrayBuffer()) + { + V8_ARG_TO_ARRAY_BUFFER(1, v8ArrayBuffer); + auto v8Buffer = v8ArrayBuffer->GetContents(); + ret = webSocket->SendBinary(alt::StringView((char*)v8Buffer.Data(), v8Buffer.ByteLength())); + } + else + { + V8_CHECK(false, "Unknown parameter type specified for IWebSocketClient::Send"); + } + V8_RETURN_BOOLEAN(ret); } static void Stop(const v8::FunctionCallbackInfo& info) diff --git a/src/helpers b/src/helpers index e8876a10..ad911b2d 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit e8876a1000432fb19fa43c82c0ce2e86a40637dc +Subproject commit ad911b2d90fd284a17cb2d8749caab266644e790 From dfddac9169e256d5b2c9fe2fc6dd73e2bab409a8 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 2 Jan 2021 00:33:59 +0100 Subject: [PATCH 258/564] readd missing macros --- V8Helpers.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/V8Helpers.h b/V8Helpers.h index 09c1d61d..f5998a05 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -440,6 +440,15 @@ namespace V8 alt::Ref val; \ V8_CHECK(V8::SafeToBaseObject(info[(idx)-1], isolate, val), "Argument " #idx " must be a " jsClassName) +// idx starts with 1 +#define V8_ARG_TO_ARRAY_BUFFER(idx, val) \ + v8::Local val; \ + V8_CHECK(V8::SafeToArrayBuffer(info[(idx) - 1], ctx, val), "Failed to convert argument " #idx " to ArrayBuffer") + +// idx starts with 1 +#define V8_ARG_TO_ARRAY_BUFFER_VIEW(idx, val) \ + v8::Local val; \ + V8_CHECK(V8::SafeToArrayBufferView(info[(idx) - 1], ctx, val), "Failed to convert argument " #idx " to ArrayBufferView") // idx starts with 1 #define V8_ARG_TO_UINT64(idx, val) \ From c290b1a1cfdcd85d9fdf8027eb115a4fa3c24ed2 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 2 Jan 2021 00:34:12 +0100 Subject: [PATCH 259/564] update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index ad911b2d..dfddac91 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit ad911b2d90fd284a17cb2d8749caab266644e790 +Subproject commit dfddac9169e256d5b2c9fe2fc6dd73e2bab409a8 From bb3e529079bfdcbfc2faa4630de44afd3d7092c6 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 8 Jan 2021 15:39:11 +0100 Subject: [PATCH 260/564] Convert entity to scriptID in native calls --- src/bindings/V8Natives.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 6f04e343..c8f3e4b5 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -65,6 +65,8 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a using ArgType = alt::INative::Type; v8::Local v8Ctx = isolate->GetEnteredContext(); + auto resource = V8ResourceImpl::Get(v8Ctx); + auto ent = V8Entity::Get(val); switch (argType) { @@ -76,7 +78,10 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a scrCtx->Push(SavePointer((int32_t)val->ToBoolean(isolate)->Value())); break; case alt::INative::Type::ARG_INT32: - scrCtx->Push((int32_t)val->ToInteger(v8Ctx).ToLocalChecked()->Value()); + int32_t value; + if(ent != nullptr) value = (int32_t)ent->GetHandle().As()->GetScriptGuid(); + else value = (int32_t)val->ToInteger(v8Ctx).ToLocalChecked()->Value(); + scrCtx->Push(value); break; case alt::INative::Type::ARG_INT32_PTR: ++returnsCount; From 5f37efafed278a5800a08978428716bbafe64990 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 8 Jan 2021 16:13:55 +0100 Subject: [PATCH 261/564] Update C++ SDK --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 4104eca8..ca242455 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 4104eca8b353c6800db96de6aa5e33d723cc1ecc +Subproject commit ca24245564933f6a6ec7ef3b01d7aa3e1da6d928 From 893d968fa2ee78172257a3f80e0db7e38b08288e Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Sat, 9 Jan 2021 02:59:26 +0300 Subject: [PATCH 262/564] SetAccessor helper to avoid writing useless code --- V8BindHelpers.h | 89 +++++++++++++++++++++++++ V8Helpers.cpp | 41 ++++++++++++ V8Helpers.h | 84 ++++++++++-------------- bindings/BaseObject.cpp | 5 +- bindings/Entity.cpp | 137 ++++----------------------------------- bindings/Main.cpp | 8 +-- bindings/WorldObject.cpp | 50 +------------- 7 files changed, 185 insertions(+), 229 deletions(-) create mode 100644 V8BindHelpers.h diff --git a/V8BindHelpers.h b/V8BindHelpers.h new file mode 100644 index 00000000..f191b1f6 --- /dev/null +++ b/V8BindHelpers.h @@ -0,0 +1,89 @@ +#pragma once + +#include "V8Helpers.h" +#include "V8ResourceImpl.h" + +#define V8_CALL_GETTER(type, req, retn) \ + template \ + static inline void CallGetter(const v8::PropertyCallbackInfo& info, T* _this, type(T::* getter)() const) \ + { \ + req(); \ + retn((_this->*getter)()); \ + } + +#define V8_CALL_SETTER(type, req, convert) \ + template \ + static inline void CallSetter(const v8::PropertyCallbackInfo& info, v8::Local value, T* _this, void(T::* setter)(type)) \ + { \ + req(); \ + convert(value, _val); \ + (_this->*setter)(type(_val)); \ + } + +namespace V8 +{ + namespace detail + { + V8_CALL_GETTER(bool, V8_GET_ISOLATE, V8_RETURN_BOOLEAN); + V8_CALL_GETTER(uint8_t, V8_GET_ISOLATE, V8_RETURN_UINTEGER); + V8_CALL_GETTER(uint16_t, V8_GET_ISOLATE, V8_RETURN_UINTEGER); + V8_CALL_GETTER(uint32_t, V8_GET_ISOLATE, V8_RETURN_UINTEGER); + V8_CALL_GETTER(uint64_t, V8_GET_ISOLATE, V8_RETURN_UINT64); + V8_CALL_GETTER(int8_t, V8_GET_ISOLATE, V8_RETURN_INTEGER); + V8_CALL_GETTER(int16_t, V8_GET_ISOLATE, V8_RETURN_INTEGER); + V8_CALL_GETTER(int32_t, V8_GET_ISOLATE, V8_RETURN_INTEGER); + V8_CALL_GETTER(int64_t, V8_GET_ISOLATE, V8_RETURN_INT64); + V8_CALL_GETTER(float, V8_GET_ISOLATE, V8_RETURN_NUMBER); + V8_CALL_GETTER(alt::StringView, V8_GET_ISOLATE, V8_RETURN_ALT_STRING); + V8_CALL_GETTER(alt::Position, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_VECTOR3); + V8_CALL_GETTER(alt::Rotation, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_VECTOR3); + V8_CALL_GETTER(alt::RGBA, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_RGBA); + V8_CALL_GETTER(alt::IColShape::ColShapeType, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_ENUM); + V8_CALL_GETTER(alt::IBaseObject::Type, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_ENUM); + V8_CALL_GETTER(alt::Ref, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_BASE_OBJECT); + V8_CALL_GETTER(alt::Ref, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_BASE_OBJECT); + V8_CALL_GETTER(alt::Ref, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_BASE_OBJECT); + V8_CALL_GETTER(alt::Ref, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_BASE_OBJECT); + + V8_CALL_SETTER(bool, V8_GET_ISOLATE, V8_TO_BOOLEAN); + V8_CALL_SETTER(uint8_t, V8_GET_ISOLATE_CONTEXT, V8_TO_INTEGER); + V8_CALL_SETTER(uint16_t, V8_GET_ISOLATE_CONTEXT, V8_TO_INTEGER); + V8_CALL_SETTER(uint32_t, V8_GET_ISOLATE_CONTEXT, V8_TO_INTEGER); + V8_CALL_SETTER(int8_t, V8_GET_ISOLATE_CONTEXT, V8_TO_INTEGER); + V8_CALL_SETTER(int16_t, V8_GET_ISOLATE_CONTEXT, V8_TO_INTEGER); + V8_CALL_SETTER(int32_t, V8_GET_ISOLATE_CONTEXT, V8_TO_INTEGER); + V8_CALL_SETTER(float, V8_GET_ISOLATE_CONTEXT, V8_TO_NUMBER); + V8_CALL_SETTER(alt::StringView, V8_GET_ISOLATE_CONTEXT, V8_TO_STRING); + V8_CALL_SETTER(alt::Position, V8_GET_ISOLATE_CONTEXT, V8_TO_VECTOR3); + V8_CALL_SETTER(alt::Rotation, V8_GET_ISOLATE_CONTEXT, V8_TO_VECTOR3); + V8_CALL_SETTER(alt::RGBA, V8_GET_ISOLATE_CONTEXT, V8_TO_RGBA); + + template + static void WrapGetter(v8::Local, const v8::PropertyCallbackInfo& info) + { + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(_this, T); + CallGetter(info, _this.Get(), Getter); + } + + template + static void WrapSetter(v8::Local, v8::Local value, const v8::PropertyCallbackInfo& info) + { + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(_this, T); + CallSetter(info, value, _this.Get(), Setter); + } + } + + template + inline void SetAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name) + { + V8::SetAccessor(isolate, tpl, name, &V8::detail::WrapGetter, nullptr); + } + + template + inline void SetAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name) + { + V8::SetAccessor(isolate, tpl, name, V8::detail::WrapGetter, V8::detail::WrapSetter); + } +} diff --git a/V8Helpers.cpp b/V8Helpers.cpp index dde71820..4cc5f0c7 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -600,6 +600,47 @@ bool V8::SafeToObject(v8::Local val, v8::Local ctx, v8:: return false; } +bool V8::SafeToRGBA(v8::Local val, v8::Local ctx, alt::RGBA& out) +{ + v8::MaybeLocal maybeVal = val->ToObject(ctx); + if (!maybeVal.IsEmpty()) + { + v8::Local val = maybeVal.ToLocalChecked(); + + uint32_t r, g, b, a; + if (SafeToUInt32(V8::Get(ctx, val, "r"), ctx, r) + && SafeToUInt32(V8::Get(ctx, val, "g"), ctx, g) + && SafeToUInt32(V8::Get(ctx, val, "b"), ctx, b) + && SafeToUInt32(V8::Get(ctx, val, "a"), ctx, a) + ) { + out = alt::RGBA{ uint8_t(r), uint8_t(g), uint8_t(b), uint8_t(a) }; + return true; + } + } + + return false; +} + +bool V8::SafeToVector3(v8::Local val, v8::Local ctx, alt::Vector3f& out) +{ + v8::MaybeLocal maybeVal = val->ToObject(ctx); + if (!maybeVal.IsEmpty()) + { + v8::Local val = maybeVal.ToLocalChecked(); + + double x, y, z; + if (SafeToNumber(V8::Get(ctx, val, "x"), ctx, x) + && SafeToNumber(V8::Get(ctx, val, "y"), ctx, y) + && SafeToNumber(V8::Get(ctx, val, "z"), ctx, z) + ) { + out = alt::Vector3f{ float(x), float(y), float(z) }; + return true; + } + } + + return false; +} + bool V8::SafeToArrayBuffer(v8::Local val, v8::Local ctx, v8::Local& out) { if (val->IsArrayBuffer()) diff --git a/V8Helpers.h b/V8Helpers.h index f5998a05..33ae98bb 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -212,6 +212,8 @@ namespace V8 bool SafeToString(v8::Local val, v8::Isolate *isolate, v8::Local ctx, alt::String &out); bool SafeToFunction(v8::Local val, v8::Local ctx, v8::Local& out); bool SafeToObject(v8::Local val, v8::Local ctx, v8::Local& out); + bool SafeToRGBA(v8::Local val, v8::Local ctx, alt::RGBA& out); + bool SafeToVector3(v8::Local val, v8::Local ctx, alt::Vector3f& out); bool SafeToArrayBuffer(v8::Local val, v8::Local ctx, v8::Local& out); bool SafeToArrayBufferView(v8::Local val, v8::Local ctx, v8::Local& out); @@ -235,11 +237,11 @@ namespace V8 } } // namespace V8 -#define V8_GET_ISOLATE(info) v8::Isolate *isolate = (info).GetIsolate() -#define V8_GET_CONTEXT(isolate) v8::Local ctx = (isolate)->GetEnteredContext() +#define V8_GET_ISOLATE() v8::Isolate *isolate = info.GetIsolate() +#define V8_GET_CONTEXT() v8::Local ctx = isolate->GetEnteredContext() #define V8_GET_ISOLATE_CONTEXT() \ - V8_GET_ISOLATE(info); \ - V8_GET_CONTEXT(isolate) + V8_GET_ISOLATE(); \ + V8_GET_CONTEXT() #define V8_GET_RESOURCE() \ V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); \ @@ -321,59 +323,37 @@ namespace V8 v8::Local val; \ V8_CHECK(V8::SafeToObject((v8Val), ctx, val), "Failed to convert value to object") -#ifdef ALT_SERVER_API +#define V8_TO_VECTOR3(v8Val, val) \ + alt::Vector3f val; \ + V8_CHECK(V8::SafeToVector3((v8Val), ctx, val), "Failed to convert value to Vector3") - #define V8_OBJECT_GET_NUMBER(v8Val, prop, val) \ - V8_TO_NUMBER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop)).ToLocalChecked(), val) +#define V8_TO_RGBA(v8Val, val) \ + alt::RGBA val; \ + V8_CHECK(V8::SafeToRGBA((v8Val), ctx, val), "Failed to convert value to RGBA") - #define V8_OBJECT_SET_NUMBER(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop), v8::Number::New(isolate, val)); +#define V8_OBJECT_GET_NUMBER(v8Val, prop, val) \ + V8_TO_NUMBER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) - #define V8_OBJECT_GET_INTEGER(v8Val, prop, val) \ - V8_TO_INTEGER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop)).ToLocalChecked(), val) +#define V8_OBJECT_SET_NUMBER(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Number::New(isolate, val)); - #define V8_OBJECT_SET_INTEGER(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop), v8::Integer::New(isolate, val)); +#define V8_OBJECT_GET_INTEGER(v8Val, prop, val) \ + V8_TO_INTEGER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) - #define V8_OBJECT_GET_BOOLEAN(v8Val, prop, val) \ - V8_TO_BOOLEAN((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop)).ToLocalChecked(), val) +#define V8_OBJECT_SET_INTEGER(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Integer::New(isolate, val)); - #define V8_OBJECT_SET_BOOLEAN(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop), v8::Boolean::New(isolate, val)); +#define V8_OBJECT_GET_BOOLEAN(v8Val, prop, val) \ + V8_TO_BOOLEAN((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) - #define V8_OBJECT_GET_STRING(v8Val, prop, val) \ - V8_TO_STRING((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop)).ToLocalChecked(), val) +#define V8_OBJECT_SET_BOOLEAN(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Boolean::New(isolate, val)); - #define V8_OBJECT_SET_STRING(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop), v8::String::NewFromUtf8(isolate, val.CStr())); +#define V8_OBJECT_GET_STRING(v8Val, prop, val) \ + V8_TO_STRING((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) -#else - - #define V8_OBJECT_GET_NUMBER(v8Val, prop, val) \ - V8_TO_NUMBER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) - - #define V8_OBJECT_SET_NUMBER(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Number::New(isolate, val)); - - #define V8_OBJECT_GET_INTEGER(v8Val, prop, val) \ - V8_TO_INTEGER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) - - #define V8_OBJECT_SET_INTEGER(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Integer::New(isolate, val)); - - #define V8_OBJECT_GET_BOOLEAN(v8Val, prop, val) \ - V8_TO_BOOLEAN((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) - - #define V8_OBJECT_SET_BOOLEAN(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Boolean::New(isolate, val)); - - #define V8_OBJECT_GET_STRING(v8Val, prop, val) \ - V8_TO_STRING((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) - - #define V8_OBJECT_SET_STRING(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::String::NewFromUtf8(isolate, val.CStr()).ToLocalChecked()); - -#endif +#define V8_OBJECT_SET_STRING(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::String::NewFromUtf8(isolate, val.CStr()).ToLocalChecked()); #define V8_NEW_STRING(val) v8::String::NewFromUtf8(isolate, val).ToLocalChecked() @@ -474,14 +454,16 @@ namespace V8 #define V8_RETURN_NULL() V8_RETURN(v8::Null(isolate)) #define V8_RETURN_BOOLEAN(val) V8_RETURN(v8::Boolean::New(isolate, (val))) #define V8_RETURN_INTEGER(val) V8_RETURN(v8::Integer::New(isolate, (val))) +#define V8_RETURN_UINTEGER(val) V8_RETURN(v8::Integer::NewFromUnsigned(isolate, (val))) #define V8_RETURN_NUMBER(val) V8_RETURN(v8::Number::New(isolate, (val))) #define V8_RETURN_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val), v8::NewStringType::kNormal).ToLocalChecked()) +#define V8_RETURN_ALT_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val).CStr(), v8::NewStringType::kNormal).ToLocalChecked()) #define V8_RETURN_MVALUE(val) V8_RETURN(V8Helpers::MValueToV8(val)) - #define V8_RETURN_UINT64(val) V8_RETURN(v8::BigInt::NewFromUnsigned(isolate, (val))) #define V8_RETURN_INT64(val) V8_RETURN(v8::BigInt::New(isolate, (val))) -#define V8_RETURN_UINT32(val) V8_RETURN(v8::Integer::NewFromUnsigned(isolate, (val))) -#define V8_RETURN_INT32(val) V8_RETURN(v8::Integer::New(isolate, (val))) +#define V8_RETURN_VECTOR3(val) V8_RETURN(resource->CreateVector3(val)) +#define V8_RETURN_RGBA(val) V8_RETURN(resource->CreateRGBA(val)) +#define V8_RETURN_ENUM(val) V8_RETURN(v8::Integer::NewFromUnsigned(isolate, uint32_t(val))) #define V8_RETURN_BASE_OBJECT(baseObjectRef) V8_RETURN(resource->GetBaseObjectOrNull(baseObjectRef)) diff --git a/bindings/BaseObject.cpp b/bindings/BaseObject.cpp index edb149d9..549c02aa 100644 --- a/bindings/BaseObject.cpp +++ b/bindings/BaseObject.cpp @@ -1,9 +1,12 @@ #include "../V8Helpers.h" +#include "../V8BindHelpers.h" #include "../V8ResourceImpl.h" #include "../V8Class.h" #include "../V8Entity.h" +using namespace alt; + static void TypeGetter(v8::Local, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE(info); @@ -85,7 +88,7 @@ extern V8Class v8BaseObject("BaseObject", [](v8::Local tpl tpl->InstanceTemplate()->SetInternalFieldCount(1); - V8::SetAccessor(isolate, tpl, "type", &TypeGetter); + V8::SetAccessor(isolate, tpl, "type"); V8::SetAccessor(isolate, tpl, "valid", &ValidGetter); V8::SetMethod(isolate, tpl, "hasMeta", HasMeta); diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index bf494dd3..c58ca514 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -1,5 +1,6 @@ #include "../V8Helpers.h" +#include "../V8BindHelpers.h" #include "../V8ResourceImpl.h" #include "../V8Class.h" #include "../V8Entity.h" @@ -7,69 +8,6 @@ using namespace alt; -static void IDGetter(v8::Local, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - - V8_RETURN_INTEGER(ent->GetID()); -} - -static void OwnerGetter(v8::Local, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - - V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - - V8_RETURN_BASE_OBJECT(ent->GetNetworkOwner()); -} - -static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - - V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - - V8_RETURN(resource->CreateVector3(ent->GetPosition())); -} - -static void DimensionGetter(v8::Local, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - - V8_RETURN_INTEGER(ent->GetDimension()); -} - -static void RotationGetter(v8::Local, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - - V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - - V8_RETURN(resource->CreateVector3(ent->GetRotation())); -} - -static void ModelGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - - V8_RETURN_UINT32(ent->GetModel()); -} - -static void VisibleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - - V8_RETURN_BOOLEAN(ent->GetVisible()); -} - static void HasSyncedMeta(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); @@ -120,49 +58,6 @@ static void GetStreamSyncedMeta(const v8::FunctionCallbackInfo &info) #ifdef ALT_SERVER_API -static void RotationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - - V8_TO_OBJECT(val, pos); - V8_OBJECT_GET_NUMBER(pos, "x", x); - V8_OBJECT_GET_NUMBER(pos, "y", y); - V8_OBJECT_GET_NUMBER(pos, "z", z); - - ent->SetRotation({ x, y, z }); -} - -static void ModelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - if (val->IsNumber()) - { - V8_TO_INTEGER(val, model); - player->SetModel(model); - } - else - { - V8_TO_STRING(val, model); - player->SetModel(alt::ICore::Instance().Hash(model)); - } -} - -static void VisibleSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); - - V8_TO_BOOLEAN(val, toggle); - - ent->SetVisible(toggle); -} - static void SetSyncedMeta(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); @@ -238,13 +133,6 @@ static void ResetNetOwner(const v8::FunctionCallbackInfo &info) #ifdef ALT_CLIENT_API -static void ScriptIDGetter(v8::Local, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(_this, IEntity); - V8_RETURN_INTEGER(_this->GetScriptGuid()); -} - static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -286,9 +174,8 @@ extern V8Class v8Entity("Entity", v8WorldObject, [](v8::Local(isolate, tpl, "id"); + V8::SetAccessor, &IEntity::GetNetworkOwner>(isolate, tpl, "netOwner"); V8::SetMethod(isolate, tpl, "hasSyncedMeta", HasSyncedMeta); V8::SetMethod(isolate, tpl, "getSyncedMeta", GetSyncedMeta); @@ -297,10 +184,9 @@ extern V8Class v8Entity("Entity", v8WorldObject, [](v8::Local(isolate, tpl, "rot"); + V8::SetAccessor(isolate, tpl, "model"); + V8::SetAccessor(isolate, tpl, "visible"); V8::SetMethod(isolate, tpl, "setSyncedMeta", SetSyncedMeta); V8::SetMethod(isolate, tpl, "deleteSyncedMeta", DeleteSyncedMeta); @@ -315,11 +201,10 @@ extern V8Class v8Entity("Entity", v8WorldObject, [](v8::Local(isolate, tpl, "pos"); + V8::SetAccessor(isolate, tpl, "rot"); + V8::SetAccessor(isolate, tpl, "model"); + V8::SetAccessor(isolate, tpl, "scriptID"); + V8::SetAccessor(isolate, tpl, "visible"); #endif // ALT_CLIENT_API }); diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 49eb9bac..c7e368e9 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -9,7 +9,7 @@ static void HashCb(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, str); - V8_RETURN_UINT32(alt::ICore::Instance().Hash(str)); + V8_RETURN_UINTEGER(alt::ICore::Instance().Hash(str)); } static void On(const v8::FunctionCallbackInfo &info) @@ -275,11 +275,11 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8Helpers::RegisterFunc(exports, "clearInterval", &ClearTimer); #ifdef ALT_SERVER_API - V8::DefineOwnProperty(isolate, ctx, exports, "version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr())); - V8::DefineOwnProperty(isolate, ctx, exports, "branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr())); + V8::DefineOwnProperty(isolate, ctx, exports, "version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); + V8::DefineOwnProperty(isolate, ctx, exports, "branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); alt::IResource* resource = V8ResourceImpl::GetResource(ctx); - V8::DefineOwnProperty(isolate, ctx, exports, "resourceName", v8::String::NewFromUtf8(isolate, resource->GetName().CStr())); + V8::DefineOwnProperty(isolate, ctx, exports, "resourceName", v8::String::NewFromUtf8(isolate, resource->GetName().CStr()).ToLocalChecked()); #else V8::DefineOwnProperty(isolate, ctx, exports, "version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); V8::DefineOwnProperty(isolate, ctx, exports, "branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); diff --git a/bindings/WorldObject.cpp b/bindings/WorldObject.cpp index 1ec437c2..ed661e9a 100644 --- a/bindings/WorldObject.cpp +++ b/bindings/WorldObject.cpp @@ -1,63 +1,19 @@ #include "../V8Helpers.h" +#include "../V8BindHelpers.h" #include "../V8ResourceImpl.h" #include "../V8Class.h" #include "../V8Entity.h" using namespace alt; -static void PositionGetter(v8::Local, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - - V8_GET_THIS_BASE_OBJECT(obj, alt::IWorldObject); - - V8_RETURN(resource->CreateVector3(obj->GetPosition())); -} - -static void PositionSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - - V8_GET_THIS_BASE_OBJECT(obj, alt::IWorldObject); - - V8_TO_OBJECT(val, pos); - V8_OBJECT_GET_NUMBER(pos, "x", x); - V8_OBJECT_GET_NUMBER(pos, "y", y); - V8_OBJECT_GET_NUMBER(pos, "z", z); - - obj->SetPosition({ x, y, z }); -} - -#ifdef ALT_SERVER_API -static void DimensionGetter(v8::Local, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(obj, alt::IWorldObject); - - V8_RETURN_INTEGER(obj->GetDimension()); -} - -static void DimensionSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(obj, alt::IWorldObject); - - V8_TO_INTEGER(val, dim); - - obj->SetDimension(dim); -} -#endif // ALT_SERVER_API - extern V8Class v8BaseObject; extern V8Class v8WorldObject("WorldObject", v8BaseObject, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); - V8::SetAccessor(isolate, tpl, "pos", PositionGetter, PositionSetter); + V8::SetAccessor(isolate, tpl, "pos"); #ifdef ALT_SERVER_API - V8::SetAccessor(isolate, tpl, "dimension", DimensionGetter, DimensionSetter); + V8::SetAccessor(isolate, tpl, "dimension"); #endif // ALT_SERVER_API }); \ No newline at end of file From 22dad7a0e7d4686880f5f905f82160b0c21369cd Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Sat, 9 Jan 2021 03:00:15 +0300 Subject: [PATCH 263/564] Code format --- V8Helpers.cpp | 160 +++++++++++++++++++++++++------------------------- V8Helpers.h | 4 +- 2 files changed, 82 insertions(+), 82 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 4cc5f0c7..309b8fdf 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -4,13 +4,13 @@ #include "V8Helpers.h" #include -bool V8Helpers::TryCatch(const std::function &fn) +bool V8Helpers::TryCatch(const std::function& fn) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Local context = isolate->GetEnteredContext(); v8::TryCatch tryCatch(isolate); - alt::IResource *resource = V8ResourceImpl::GetResource(context); + alt::IResource* resource = V8ResourceImpl::GetResource(context); if (!fn()) { @@ -26,7 +26,7 @@ bool V8Helpers::TryCatch(const std::function &fn) if (!origin.ResourceName()->IsUndefined()) { Log::Error << "[V8] Exception at " << resource->GetName() << ":" - << *v8::String::Utf8Value(isolate, origin.ResourceName()) << ":" << line.ToChecked() << Log::Endl; + << *v8::String::Utf8Value(isolate, origin.ResourceName()) << ":" << line.ToChecked() << Log::Endl; if (!maybeSourceLine.IsEmpty()) { @@ -38,7 +38,7 @@ bool V8Helpers::TryCatch(const std::function &fn) } else { - Log::Error << " " << std::string{*v8::String::Utf8Value(isolate, sourceLine), 80} << "..." << Log::Endl; + Log::Error << " " << std::string{ *v8::String::Utf8Value(isolate, sourceLine), 80 } << "..." << Log::Endl; } } } @@ -57,7 +57,7 @@ bool V8Helpers::TryCatch(const std::function &fn) else if (!exception.IsEmpty()) { Log::Error << "[V8] Exception: " - << *v8::String::Utf8Value(isolate, exception) << Log::Endl; + << *v8::String::Utf8Value(isolate, exception) << Log::Endl; } else { @@ -70,13 +70,13 @@ bool V8Helpers::TryCatch(const std::function &fn) return true; } -void V8Helpers::FunctionCallback(const v8::FunctionCallbackInfo &info) +void V8Helpers::FunctionCallback(const v8::FunctionCallbackInfo& info) { - auto fn = static_cast(info.Data().As()->Value()); + auto fn = static_cast(info.Data().As()->Value()); - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Local ctx = isolate->GetEnteredContext(); - V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); + V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); Log::Debug << "FunctionCallback " << resource->GetResource()->GetName() << " " << V8ResourceImpl::Get(isolate->GetEnteredContext())->GetResource()->GetName() << Log::Endl; @@ -92,9 +92,9 @@ void V8Helpers::FunctionCallback(const v8::FunctionCallbackInfo &info alt::MValue V8Helpers::V8ToMValue(v8::Local val) { - auto &core = alt::ICore::Instance(); + auto& core = alt::ICore::Instance(); - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Local ctx = isolate->GetEnteredContext(); if (val.IsEmpty()) @@ -144,11 +144,11 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) else if (val->IsArrayBuffer()) { v8::ArrayBuffer::Contents v8Buffer = val.As()->GetContents(); - return core.CreateMValueByteArray((uint8_t *)v8Buffer.Data(), v8Buffer.ByteLength()); + return core.CreateMValueByteArray((uint8_t*)v8Buffer.Data(), v8Buffer.ByteLength()); } else { - V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); + V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); v8::Local v8Obj = val.As(); //if (v8Obj->InstanceOf(ctx, v8Vector3->JSValue(isolate, ctx)).ToChecked()) @@ -162,7 +162,7 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) alt::Vector3f{ x->Value(), y->Value(), - z->Value()}); + z->Value() }); } else if (resource->IsRGBA(v8Obj)) { @@ -176,11 +176,11 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) (uint8_t)r->Value(), (uint8_t)g->Value(), (uint8_t)b->Value(), - (uint8_t)a->Value()}); + (uint8_t)a->Value() }); } else if (resource->IsBaseObject(v8Obj)) { - V8Entity *ent = V8Entity::Get(v8Obj); + V8Entity* ent = V8Entity::Get(v8Obj); Log::Debug << "Instanceof BaseObject" << Log::Endl; if (!ent) @@ -216,7 +216,7 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) v8::Local V8Helpers::MValueToV8(alt::MValueConst val) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Local ctx = isolate->GetEnteredContext(); switch (val->GetType()) @@ -300,49 +300,49 @@ v8::Local V8Helpers::MValueToV8(alt::MValueConst val) return v8::Undefined(isolate); } -void V8::DefineOwnProperty(v8::Isolate *isolate, v8::Local ctx, v8::Local val, const char *name, v8::Local value, v8::PropertyAttribute attributes) +void V8::DefineOwnProperty(v8::Isolate* isolate, v8::Local ctx, v8::Local val, const char* name, v8::Local value, v8::PropertyAttribute attributes) { val->DefineOwnProperty(ctx, v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized).ToLocalChecked(), value, attributes); } -void V8::DefineOwnProperty(v8::Isolate *isolate, v8::Local ctx, v8::Local val, v8::Local name, v8::Local value, v8::PropertyAttribute attributes) +void V8::DefineOwnProperty(v8::Isolate* isolate, v8::Local ctx, v8::Local val, v8::Local name, v8::Local value, v8::PropertyAttribute attributes) { val->DefineOwnProperty(ctx, name, value, attributes); } -void V8::SetAccessor(v8::Isolate *isolate, v8::Local tpl, const char *name, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) +void V8::SetAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) { tpl->PrototypeTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, name, - v8::NewStringType::kInternalized) - .ToLocalChecked(), - getter, setter, - v8::Local(), v8::AccessControl::DEFAULT, - setter != nullptr ? v8::PropertyAttribute::None : v8::PropertyAttribute::ReadOnly); + v8::NewStringType::kInternalized) + .ToLocalChecked(), + getter, setter, + v8::Local(), v8::AccessControl::DEFAULT, + setter != nullptr ? v8::PropertyAttribute::None : v8::PropertyAttribute::ReadOnly); } -void V8::SetMethod(v8::Isolate *isolate, v8::Local tpl, const char *name, v8::FunctionCallback callback) +void V8::SetMethod(v8::Isolate* isolate, v8::Local tpl, const char* name, v8::FunctionCallback callback) { tpl->PrototypeTemplate()->Set(isolate, name, v8::FunctionTemplate::New(isolate, callback)); } -void V8::SetStaticAccessor(v8::Isolate *isolate, v8::Local tpl, const char *name, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) +void V8::SetStaticAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) { tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, name, - v8::NewStringType::kInternalized) - .ToLocalChecked(), - getter, setter); + v8::NewStringType::kInternalized) + .ToLocalChecked(), + getter, setter); } -void V8::SetStaticMethod(v8::Isolate *isolate, v8::Local tpl, const char *name, v8::FunctionCallback callback) +void V8::SetStaticMethod(v8::Isolate* isolate, v8::Local tpl, const char* name, v8::FunctionCallback callback) { tpl->Set(isolate, name, v8::FunctionTemplate::New(isolate, callback)); } -v8::Local V8::Get(v8::Local ctx, v8::Local obj, const char *name) +v8::Local V8::Get(v8::Local ctx, v8::Local obj, const char* name) { return obj->Get(ctx, v8::String::NewFromUtf8(ctx->GetIsolate(), name, - v8::NewStringType::kInternalized) - .ToLocalChecked()) + v8::NewStringType::kInternalized) + .ToLocalChecked()) .ToLocalChecked(); } @@ -351,7 +351,7 @@ v8::Local V8::Get(v8::Local ctx, v8::Local o return obj->Get(ctx, name).ToLocalChecked(); } -void V8::SetFunction(v8::Isolate *isolate, v8::Local ctx, v8::Local target, const char *name, v8::FunctionCallback cb, void *userData) +void V8::SetFunction(v8::Isolate* isolate, v8::Local ctx, v8::Local target, const char* name, v8::FunctionCallback cb, void* userData) { v8::Local _name = v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized).ToLocalChecked(); @@ -361,7 +361,7 @@ void V8::SetFunction(v8::Isolate *isolate, v8::Local ctx, v8::Local target->Set(ctx, _name, fn); } -v8::Local V8::New(v8::Isolate *isolate, v8::Local ctx, v8::Local constructor, std::vector> &args) +v8::Local V8::New(v8::Isolate* isolate, v8::Local ctx, v8::Local constructor, std::vector>& args) { v8::Local obj; @@ -378,7 +378,7 @@ v8::Local V8::New(v8::Isolate *isolate, v8::Local ctx, v return obj; } -V8::SourceLocation V8::SourceLocation::GetCurrent(v8::Isolate *isolate) +V8::SourceLocation V8::SourceLocation::GetCurrent(v8::Isolate* isolate) { v8::Local stackTrace = v8::StackTrace::CurrentStackTrace(isolate, 1); if (stackTrace->GetFrameCount() > 0) @@ -391,103 +391,103 @@ V8::SourceLocation V8::SourceLocation::GetCurrent(v8::Isolate *isolate) std::string fileName = *v8::String::Utf8Value(isolate, frame->GetScriptName()); int line = frame->GetLineNumber(); - return SourceLocation{std::move(fileName), line}; + return SourceLocation{ std::move(fileName), line }; } else if (frame->IsEval()) { - return SourceLocation{"[eval]", 0}; + return SourceLocation{ "[eval]", 0 }; } } - return SourceLocation{"[unknown]", 0}; + return SourceLocation{ "[unknown]", 0 }; } -V8::SourceLocation::SourceLocation(std::string &&_fileName, int _line) : fileName(_fileName), line(_line) +V8::SourceLocation::SourceLocation(std::string&& _fileName, int _line) : fileName(_fileName), line(_line) { } -v8::Local V8::Vector3_XKey(v8::Isolate *isolate) +v8::Local V8::Vector3_XKey(v8::Isolate* isolate) { - static v8::Persistent xKey{isolate, v8::String::NewFromUtf8(isolate, "x", + static v8::Persistent xKey{ isolate, v8::String::NewFromUtf8(isolate, "x", v8::NewStringType::kInternalized) - .ToLocalChecked()}; + .ToLocalChecked() }; return xKey.Get(isolate); } -v8::Local V8::Vector3_YKey(v8::Isolate *isolate) +v8::Local V8::Vector3_YKey(v8::Isolate* isolate) { - static v8::Persistent yKey{isolate, v8::String::NewFromUtf8(isolate, "y", + static v8::Persistent yKey{ isolate, v8::String::NewFromUtf8(isolate, "y", v8::NewStringType::kInternalized) - .ToLocalChecked()}; + .ToLocalChecked() }; return yKey.Get(isolate); } -v8::Local V8::Vector3_ZKey(v8::Isolate *isolate) +v8::Local V8::Vector3_ZKey(v8::Isolate* isolate) { - static v8::Persistent zKey{isolate, v8::String::NewFromUtf8(isolate, "z", + static v8::Persistent zKey{ isolate, v8::String::NewFromUtf8(isolate, "z", v8::NewStringType::kInternalized) - .ToLocalChecked()}; + .ToLocalChecked() }; return zKey.Get(isolate); } -v8::Local V8::RGBA_RKey(v8::Isolate *isolate) +v8::Local V8::RGBA_RKey(v8::Isolate* isolate) { - static v8::Persistent rKey{isolate, v8::String::NewFromUtf8(isolate, "r", + static v8::Persistent rKey{ isolate, v8::String::NewFromUtf8(isolate, "r", v8::NewStringType::kInternalized) - .ToLocalChecked()}; + .ToLocalChecked() }; return rKey.Get(isolate); } -v8::Local V8::RGBA_GKey(v8::Isolate *isolate) +v8::Local V8::RGBA_GKey(v8::Isolate* isolate) { - static v8::Persistent gKey{isolate, v8::String::NewFromUtf8(isolate, "g", + static v8::Persistent gKey{ isolate, v8::String::NewFromUtf8(isolate, "g", v8::NewStringType::kInternalized) - .ToLocalChecked()}; + .ToLocalChecked() }; return gKey.Get(isolate); } -v8::Local V8::RGBA_BKey(v8::Isolate *isolate) +v8::Local V8::RGBA_BKey(v8::Isolate* isolate) { - static v8::Persistent bKey{isolate, v8::String::NewFromUtf8(isolate, "b", + static v8::Persistent bKey{ isolate, v8::String::NewFromUtf8(isolate, "b", v8::NewStringType::kInternalized) - .ToLocalChecked()}; + .ToLocalChecked() }; return bKey.Get(isolate); } -v8::Local V8::RGBA_AKey(v8::Isolate *isolate) +v8::Local V8::RGBA_AKey(v8::Isolate* isolate) { - static v8::Persistent aKey{isolate, v8::String::NewFromUtf8(isolate, "a", + static v8::Persistent aKey{ isolate, v8::String::NewFromUtf8(isolate, "a", v8::NewStringType::kInternalized) - .ToLocalChecked()}; + .ToLocalChecked() }; return aKey.Get(isolate); } -v8::Local V8::Fire_PosKey(v8::Isolate *isolate) +v8::Local V8::Fire_PosKey(v8::Isolate* isolate) { - static v8::Persistent aKey{isolate, v8::String::NewFromUtf8(isolate, "pos", + static v8::Persistent aKey{ isolate, v8::String::NewFromUtf8(isolate, "pos", v8::NewStringType::kInternalized) - .ToLocalChecked()}; + .ToLocalChecked() }; return aKey.Get(isolate); } -v8::Local V8::Fire_WeaponKey(v8::Isolate *isolate) +v8::Local V8::Fire_WeaponKey(v8::Isolate* isolate) { - static v8::Persistent aKey{isolate, v8::String::NewFromUtf8(isolate, "weapon", + static v8::Persistent aKey{ isolate, v8::String::NewFromUtf8(isolate, "weapon", v8::NewStringType::kInternalized) - .ToLocalChecked()}; + .ToLocalChecked() }; return aKey.Get(isolate); } -bool V8::SafeToBoolean(v8::Local val, v8::Isolate *isolate, bool &out) +bool V8::SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool& out) { out = val->ToBoolean(isolate)->Value(); return true; @@ -553,7 +553,7 @@ bool V8::SafeToInt32(v8::Local val, v8::Local ctx, int32 return false; } -bool V8::SafeToNumber(v8::Local val, v8::Local ctx, double &out) +bool V8::SafeToNumber(v8::Local val, v8::Local ctx, double& out) { v8::MaybeLocal maybeVal = val->ToNumber(ctx); if (!maybeVal.IsEmpty()) @@ -565,7 +565,7 @@ bool V8::SafeToNumber(v8::Local val, v8::Local ctx, doub return false; } -bool V8::SafeToString(v8::Local val, v8::Isolate *isolate, v8::Local ctx, alt::String &out) +bool V8::SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String& out) { v8::MaybeLocal maybeVal = val->ToString(ctx); if (!maybeVal.IsEmpty()) @@ -668,27 +668,27 @@ std::vector V8::EventHandler::GetCallbacks(V8ResourceImpl * return callbacksGetter(impl, e); } -std::vector> V8::EventHandler::GetArgs(V8ResourceImpl *impl, const alt::CEvent *e) +std::vector> V8::EventHandler::GetArgs(V8ResourceImpl* impl, const alt::CEvent* e) { std::vector> args; argsGetter(impl, e, args); return args; } -V8::EventHandler *V8::EventHandler::Get(const alt::CEvent *e) +V8::EventHandler* V8::EventHandler::Get(const alt::CEvent* e) { - auto &_all = all(); + auto& _all = all(); auto it = _all.find(e->GetType()); return (it != _all.end()) ? it->second : nullptr; } -void V8::EventHandler::Register(alt::CEvent::Type type, EventHandler *handler) +void V8::EventHandler::Register(alt::CEvent::Type type, EventHandler* handler) { - auto &_all = all(); + auto& _all = all(); if (_all.count(type) == 0) { - _all.insert({type, handler}); + _all.insert({ type, handler }); } else { @@ -696,9 +696,9 @@ void V8::EventHandler::Register(alt::CEvent::Type type, EventHandler *handler) } } -V8::EventHandler::CallbacksGetter V8::LocalEventHandler::GetCallbacksGetter(const std::string &name) +V8::EventHandler::CallbacksGetter V8::LocalEventHandler::GetCallbacksGetter(const std::string& name) { - return [name](V8ResourceImpl *resource, const alt::CEvent *) -> std::vector { + return [name](V8ResourceImpl* resource, const alt::CEvent*) -> std::vector { return resource->GetLocalHandlers(name); }; } diff --git a/V8Helpers.h b/V8Helpers.h index 33ae98bb..35edd520 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -171,8 +171,8 @@ namespace V8 void DefineOwnProperty(v8::Isolate *isolate, v8::Local ctx, v8::Local val, v8::Local name, v8::Local value, v8::PropertyAttribute attributes = v8::PropertyAttribute::None); - void SetAccessor(v8::Isolate *isolate, v8::Local tpl, const char *name, - v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter = nullptr); + void SetAccessor(v8::Isolate* isolate, v8::Local tpl, const char* name, + v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter = nullptr); void SetMethod(v8::Isolate *isolate, v8::Local tpl, const char *name, v8::FunctionCallback callback); From 21216b4088a07fd8a52d21d6a6df27a4f8cb600a Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Sat, 9 Jan 2021 03:22:42 +0300 Subject: [PATCH 264/564] Added V8_ARG_TO_VECTOR3 --- V8Helpers.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/V8Helpers.h b/V8Helpers.h index 35edd520..521d7232 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -450,6 +450,11 @@ namespace V8 int32_t val; \ V8_CHECK(V8::SafeToInt32(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to integer") +// idx starts with 1 +#define V8_ARG_TO_VECTOR3(idx, val) \ + alt::Vector3f val; \ + V8_CHECK(V8::SafeToVector3(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to vector3") + #define V8_RETURN(val) info.GetReturnValue().Set(val) #define V8_RETURN_NULL() V8_RETURN(v8::Null(isolate)) #define V8_RETURN_BOOLEAN(val) V8_RETURN(v8::Boolean::New(isolate, (val))) From 2dfacc3d8734a4dd0e66abd026697b016f35d460 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Sat, 9 Jan 2021 04:06:57 +0300 Subject: [PATCH 265/564] Some cleanup to fix linux build --- bindings/BaseObject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/BaseObject.cpp b/bindings/BaseObject.cpp index 549c02aa..5c5ded69 100644 --- a/bindings/BaseObject.cpp +++ b/bindings/BaseObject.cpp @@ -9,7 +9,7 @@ using namespace alt; static void TypeGetter(v8::Local, const v8::PropertyCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(obj, alt::IBaseObject); @@ -18,7 +18,7 @@ static void TypeGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8Entity* ent = V8Entity::Get(info.This()); From 99726937348f2b678ba1a647d37dfd6564c79982 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Sat, 9 Jan 2021 04:12:11 +0300 Subject: [PATCH 266/564] Fixed V8_BIND_BASE_OBJECT --- V8Helpers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index 521d7232..82e90d86 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -472,9 +472,9 @@ namespace V8 #define V8_RETURN_BASE_OBJECT(baseObjectRef) V8_RETURN(resource->GetBaseObjectOrNull(baseObjectRef)) -#define V8_BIND_BASE_OBJECT(baseObjectRef) \ +#define V8_BIND_BASE_OBJECT(baseObjectRef, reason) \ { \ - V8_CHECK(!baseObjectRef.IsEmpty(), "Failed to bind base object"); \ + V8_CHECK(!baseObjectRef.IsEmpty(), reason); \ resource->BindEntity(info.This(), baseObjectRef); \ } From 8307bc4d95a5e0b03a9d8c8280a071813c7ab3d5 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Sat, 9 Jan 2021 04:29:21 +0300 Subject: [PATCH 267/564] Fixed model property --- bindings/Entity.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index c58ca514..dafc28f3 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -58,6 +58,30 @@ static void GetStreamSyncedMeta(const v8::FunctionCallbackInfo &info) #ifdef ALT_SERVER_API +static void ModelGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); + V8_RETURN_UINTEGER(ent->GetModel()); +} + +static void ModelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + if (val->IsNumber()) + { + V8_TO_INTEGER(val, model); + player->SetModel(model); + } + else + { + V8_TO_STRING(val, model); + player->SetModel(alt::ICore::Instance().Hash(model)); + } +} + static void SetSyncedMeta(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); @@ -185,7 +209,7 @@ extern V8Class v8Entity("Entity", v8WorldObject, [](v8::Local(isolate, tpl, "rot"); - V8::SetAccessor(isolate, tpl, "model"); + V8::SetAccessor(isolate, tpl, "model", &ModelGetter, &ModelSetter); V8::SetAccessor(isolate, tpl, "visible"); V8::SetMethod(isolate, tpl, "setSyncedMeta", SetSyncedMeta); From 80ea53448a62d4a4280382c31097ea468547b9c5 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 9 Jan 2021 19:35:02 +0100 Subject: [PATCH 268/564] add latest helpers compatibility --- src/bindings/Blip.cpp | 10 +++++----- src/bindings/Checkpoint.cpp | 2 +- src/bindings/Main.cpp | 10 +++++----- src/bindings/Player.cpp | 2 +- src/bindings/Voice.cpp | 2 +- src/bindings/WebSocketClient.cpp | 6 +++--- src/bindings/WebView.cpp | 2 +- src/helpers | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index a458f784..e1ce791a 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -21,7 +21,7 @@ static void ConstructorAreaBlip(const v8::FunctionCallbackInfo& info) V8_ARG_TO_NUMBER(5, height); alt::Ref blip = alt::ICore::Instance().CreateBlip({ x, y, z }, width, height); - V8_BIND_BASE_OBJECT(blip); + V8_BIND_BASE_OBJECT(blip, "Failed to create AreaBlip"); } static void ConstructorRadiusBlip(const v8::FunctionCallbackInfo& info) @@ -35,7 +35,7 @@ static void ConstructorRadiusBlip(const v8::FunctionCallbackInfo& inf V8_ARG_TO_NUMBER(4, radius); alt::Ref blip = alt::ICore::Instance().CreateBlip({ x, y, z }, radius); - V8_BIND_BASE_OBJECT(blip); + V8_BIND_BASE_OBJECT(blip, "Failed to create RadiusBlip"); } static void ConstructorPointBlip(const v8::FunctionCallbackInfo& info) @@ -48,7 +48,7 @@ static void ConstructorPointBlip(const v8::FunctionCallbackInfo& info V8_ARG_TO_NUMBER(3, z); alt::Ref blip = alt::ICore::Instance().CreateBlip(alt::IBlip::BlipType::DESTINATION, { x, y, z }); - V8_BIND_BASE_OBJECT(blip); + V8_BIND_BASE_OBJECT(blip, "Failed to create PointBlip"); } static void ConstructorPedBlip(const v8::FunctionCallbackInfo& info) @@ -59,7 +59,7 @@ static void ConstructorPedBlip(const v8::FunctionCallbackInfo& info) V8_ARG_TO_INTEGER(1, pedId); alt::Ref blip = alt::ICore::Instance().CreateBlip(alt::IBlip::BlipType::PED, pedId); - V8_BIND_BASE_OBJECT(blip); + V8_BIND_BASE_OBJECT(blip, "Failed to create PedBlip"); } static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo& info) @@ -70,7 +70,7 @@ static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo& in V8_ARG_TO_INTEGER(1, vehicleId); alt::Ref blip = alt::ICore::Instance().CreateBlip(alt::IBlip::BlipType::VEHICLE, vehicleId); - V8_BIND_BASE_OBJECT(blip); + V8_BIND_BASE_OBJECT(blip, "Failed to create VehicleBlip"); } static void SizeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index d7370caa..867f4f21 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -24,7 +24,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_OBJECT_GET_INTEGER(color, "a", a); alt::Ref cp = alt::ICore::Instance().CreateCheckpoint(type, { x1, y1, z1 }, { x2, y2, z2 }, radius, height, { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); - V8_BIND_BASE_OBJECT(cp); + V8_BIND_BASE_OBJECT(cp, "Failed to create Checkpoint"); } static void TypeGetter(v8::Local, const v8::PropertyCallbackInfo& info) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 5d692e0c..55461570 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -408,7 +408,7 @@ static void GetCharStat(const v8::FunctionCallbackInfo &info) if (!strcmp(targetStat->GetStatType(), "INT")) { - V8_RETURN_INT32(targetStat->GetInt32Value()); + V8_RETURN_INTEGER(targetStat->GetInt32Value()); return; } else if (!strcmp(targetStat->GetStatType(), "INT64")) @@ -418,7 +418,7 @@ static void GetCharStat(const v8::FunctionCallbackInfo &info) } else if (!strcmp(targetStat->GetStatType(), "TEXTLABEL")) { - V8_RETURN_INT32(targetStat->GetInt32Value()); + V8_RETURN_INTEGER(targetStat->GetInt32Value()); return; } else if (!strcmp(targetStat->GetStatType(), "FLOAT")) @@ -438,17 +438,17 @@ static void GetCharStat(const v8::FunctionCallbackInfo &info) } else if (!strcmp(targetStat->GetStatType(), "UINT8")) { - V8_RETURN_UINT32(targetStat->GetUInt8Value()); + V8_RETURN_UINTEGER(targetStat->GetUInt8Value()); return; } else if (!strcmp(targetStat->GetStatType(), "UINT16")) { - V8_RETURN_UINT32(targetStat->GetUInt16Value()); + V8_RETURN_UINTEGER(targetStat->GetUInt16Value()); return; } else if (!strcmp(targetStat->GetStatType(), "UINT32")) { - V8_RETURN_UINT32(targetStat->GetUInt32Value()); + V8_RETURN_UINTEGER(targetStat->GetUInt32Value()); return; } else if ( diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 61b122f1..2298bee7 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -69,7 +69,7 @@ static void CurrentWeaponGetter(v8::Local, const v8::PropertyCallbac V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_RETURN_UINT32(player->GetCurrentWeapon()); + V8_RETURN_UINTEGER(player->GetCurrentWeapon()); } static void IsJumpingGetter(v8::Local, const v8::PropertyCallbackInfo& info) diff --git a/src/bindings/Voice.cpp b/src/bindings/Voice.cpp index fd6c9ec6..d75c3468 100644 --- a/src/bindings/Voice.cpp +++ b/src/bindings/Voice.cpp @@ -29,7 +29,7 @@ static void StaticGetVoiceActivationKey(v8::Local, const v8::Propert { V8_GET_ISOLATE_CONTEXT(); - V8_RETURN_UINT32(alt::ICore::Instance().GetVoiceActivationKey()); + V8_RETURN_UINTEGER(alt::ICore::Instance().GetVoiceActivationKey()); } extern V8Class v8Voice("Voice", [](v8::Local tpl) { diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index ebd3cc1a..c9014340 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -22,7 +22,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) webSocket = alt::ICore::Instance().CreateWebSocketClient(url, altres); - V8_BIND_BASE_OBJECT(webSocket); + V8_BIND_BASE_OBJECT(webSocket, "Failed to create WebSocketClient"); } static void On(const v8::FunctionCallbackInfo& info) @@ -187,7 +187,7 @@ static void ReadyStateGetter(v8::Local property, const v8::PropertyC V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - V8_RETURN_UINT32(webSocket->GetReadyState()); + V8_RETURN_UINTEGER(webSocket->GetReadyState()); } static void AutoReconnectSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -247,7 +247,7 @@ static void PingIntervalGetter(v8::Local property, const v8::Propert V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - V8_RETURN_UINT32(webSocket->GetPingInterval()); + V8_RETURN_UINTEGER(webSocket->GetPingInterval()); } extern V8Class v8BaseObject; diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index f059dcc6..7fadab4c 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -191,7 +191,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) view = alt::ICore::Instance().CreateWebView(altres, url, { 0, 0 }, { 0, 0 }, true, false); } - V8_BIND_BASE_OBJECT(view); + V8_BIND_BASE_OBJECT(view, "Failed to create WebView"); } extern V8Class v8BaseObject; diff --git a/src/helpers b/src/helpers index dfddac91..8307bc4d 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit dfddac9169e256d5b2c9fe2fc6dd73e2bab409a8 +Subproject commit 8307bc4d95a5e0b03a9d8c8280a071813c7ab3d5 From 89972fcdfd8f2f80c40cb910a9da61dcc8148ccd Mon Sep 17 00:00:00 2001 From: Eugene Pogrebnyak Date: Sun, 10 Jan 2021 22:58:22 +0300 Subject: [PATCH 269/564] Uninline some shit --- V8Helpers.cpp | 27 +++++++++++++++++++++++++++ V8Helpers.h | 31 ++++++------------------------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 309b8fdf..52684aa5 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -70,6 +70,19 @@ bool V8Helpers::TryCatch(const std::function& fn) return true; } +void V8Helpers::RegisterFunc(v8::Local exports, const std::string& _name, v8::FunctionCallback cb, void* data) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Local ctx = isolate->GetEnteredContext(); + + v8::Local name = v8::String::NewFromUtf8(isolate, _name.data(), v8::NewStringType::kNormal, _name.size()).ToLocalChecked(); + + v8::Local fn = v8::Function::New(ctx, cb, v8::External::New(isolate, data)).ToLocalChecked(); + fn->SetName(name); + + exports->Set(ctx, name, fn); +} + void V8Helpers::FunctionCallback(const v8::FunctionCallbackInfo& info) { auto fn = static_cast(info.Data().As()->Value()); @@ -300,6 +313,20 @@ v8::Local V8Helpers::MValueToV8(alt::MValueConst val) return v8::Undefined(isolate); } +void V8Helpers::MValueArgsToV8(alt::MValueArgs args, std::vector>& v8Args) +{ + for (uint64_t i = 0; i < args.GetSize(); ++i) + v8Args.push_back(MValueToV8(args[i])); +} + +void V8Helpers::SetAccessor(v8::Local tpl, v8::Isolate* isolate, const char* name, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) +{ + tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, name, + v8::NewStringType::kInternalized) + .ToLocalChecked(), + getter, setter); +} + void V8::DefineOwnProperty(v8::Isolate* isolate, v8::Local ctx, v8::Local val, const char* name, v8::Local value, v8::PropertyAttribute attributes) { val->DefineOwnProperty(ctx, v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized).ToLocalChecked(), value, attributes); diff --git a/V8Helpers.h b/V8Helpers.h index 82e90d86..d05bdc82 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -58,18 +58,7 @@ namespace V8Helpers } }; - inline void RegisterFunc(v8::Local exports, const std::string &_name, v8::FunctionCallback cb, void *data = nullptr) - { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - v8::Local ctx = isolate->GetEnteredContext(); - - v8::Local name = v8::String::NewFromUtf8(isolate, _name.data(), v8::NewStringType::kNormal, _name.size()).ToLocalChecked(); - - v8::Local fn = v8::Function::New(ctx, cb, v8::External::New(isolate, data)).ToLocalChecked(); - fn->SetName(name); - - exports->Set(ctx, name, fn); - } + void RegisterFunc(v8::Local exports, const std::string& _name, v8::FunctionCallback cb, void* data = nullptr); void FunctionCallback(const v8::FunctionCallbackInfo &info); @@ -77,20 +66,12 @@ namespace V8Helpers v8::Local MValueToV8(alt::MValueConst val); - inline void MValueArgsToV8(alt::MValueArgs args, std::vector> &v8Args) - { - for (uint64_t i = 0; i < args.GetSize(); ++i) - v8Args.push_back(MValueToV8(args[i])); - } + void MValueArgsToV8(alt::MValueArgs args, std::vector>& v8Args); + - inline void SetAccessor(v8::Local tpl, v8::Isolate *isolate, const char *name, v8::AccessorGetterCallback getter, - v8::AccessorSetterCallback setter = nullptr) - { - tpl->SetNativeDataProperty(v8::String::NewFromUtf8(isolate, name, - v8::NewStringType::kInternalized) - .ToLocalChecked(), - getter, setter); - } + void SetAccessor(v8::Local tpl, v8::Isolate* isolate, const char* name, v8::AccessorGetterCallback getter, + v8::AccessorSetterCallback setter = nullptr); + }; // namespace V8Helpers class V8ResourceImpl; From a5141f0c3457993c19ddfff3648ef609996fde3c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 14 Jan 2021 10:50:50 +0100 Subject: [PATCH 270/564] Add new export and adapt old export --- src/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index cbb58537..43376dcf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,13 +8,18 @@ #define ALTV_JS_EXPORT extern "C" #endif -ALTV_JS_EXPORT alt::IScriptRuntime *CreateJSScriptRuntime(alt::ICore *core) +ALTV_JS_EXPORT alt::IScriptRuntime *CreateScriptRuntime(alt::ICore *core) { alt::ICore::SetInstance(core); auto ret = new CV8ScriptRuntime(); return ret; } +ALTV_JS_EXPORT const char* GetType() +{ + return "js"; +} + ALTV_JS_EXPORT uint32_t GetSDKVersion() { return alt::ICore::SDK_VERSION; From 1e28497dcbbe40e1475001528e98bf0e92a33279 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 24 Jan 2021 12:43:23 +0100 Subject: [PATCH 271/564] Make getCursorPos return Vector2 instance --- src/bindings/Main.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 55461570..5b5f81db 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -107,15 +107,11 @@ static void ShowCursor(const v8::FunctionCallbackInfo &info) static void GetCursorPos(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE_CONTEXT(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); alt::Vector2i cursorPos = alt::ICore::Instance().GetCursorPosition(); - - V8_NEW_OBJECT(pos); - V8_OBJECT_SET_INTEGER(pos, "x", cursorPos[0]); - V8_OBJECT_SET_INTEGER(pos, "y", cursorPos[1]); - V8_RETURN(pos); + V8_RETURN(resource->CreateVector2(cursorPos)); } static void SetCursorPos(const v8::FunctionCallbackInfo &info) From 07e1dacaaf7a1323c26b31592e8b8efb805b71d1 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 24 Jan 2021 12:44:18 +0100 Subject: [PATCH 272/564] Make blip.size getter return Vector2 instance --- src/bindings/Blip.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index e1ce791a..d31df793 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -87,16 +87,12 @@ static void SizeSetter(v8::Local property, v8::Local valu static void SizeGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE_CONTEXT(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); alt::Vector2f blipPos = blip->GetScaleXY(); - V8_NEW_OBJECT(pos); - V8_OBJECT_SET_NUMBER(pos, "x", blipPos[0]); - V8_OBJECT_SET_NUMBER(pos, "y", blipPos[1]); - - V8_RETURN(pos); + V8_RETURN(resource->CreateVector2(blipPos)); } static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) From c703def31a0abbd89c0bd6317f7d7db903746d91 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 26 Jan 2021 21:09:47 +0100 Subject: [PATCH 273/564] Update CPP SDK --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 4104eca8..428fd335 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 4104eca8b353c6800db96de6aa5e33d723cc1ecc +Subproject commit 428fd335c7b8dbf0b707c3972cfb32f762762d4b From 598843fd7e3701b880e6390ffe269461d1586dc5 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 26 Jan 2021 21:10:18 +0100 Subject: [PATCH 274/564] Update CPP SDK --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 4104eca8..428fd335 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 4104eca8b353c6800db96de6aa5e33d723cc1ecc +Subproject commit 428fd335c7b8dbf0b707c3972cfb32f762762d4b From c42d30032d9ba69176681a816a47dd5e10de5077 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 26 Jan 2021 21:45:15 +0100 Subject: [PATCH 275/564] Update SDK --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index ca242455..428fd335 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit ca24245564933f6a6ec7ef3b01d7aa3e1da6d928 +Subproject commit 428fd335c7b8dbf0b707c3972cfb32f762762d4b From 90718d368aeaf586b0e1b4476a29a2ddf2750375 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 26 Jan 2021 21:53:35 +0100 Subject: [PATCH 276/564] Performance improvements --- src/bindings/V8Natives.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index c8f3e4b5..35efc106 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -60,13 +60,11 @@ static void *ToMemoryBuffer(v8::Local val, v8::Local ctx return nullptr; } -static void PushArg(alt::Ref scrCtx, alt::INative::Type argType, v8::Isolate *isolate, v8::Local val) +static void PushArg(alt::Ref scrCtx, alt::INative::Type argType, v8::Isolate *isolate, V8ResourceImpl* resource, v8::Local val) { using ArgType = alt::INative::Type; v8::Local v8Ctx = isolate->GetEnteredContext(); - auto resource = V8ResourceImpl::Get(v8Ctx); - auto ent = V8Entity::Get(val); switch (argType) { @@ -79,6 +77,8 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a break; case alt::INative::Type::ARG_INT32: int32_t value; + V8Entity* ent; + ent = V8Entity::Get(val); if(ent != nullptr) value = (int32_t)ent->GetHandle().As()->GetScriptGuid(); else value = (int32_t)val->ToInteger(v8Ctx).ToLocalChecked()->Value(); scrCtx->Push(value); @@ -213,8 +213,9 @@ static void InvokeNative(const v8::FunctionCallbackInfo &info) pointersCount = 0; returnsCount = 1; + auto resource = V8ResourceImpl::Get(v8Ctx); for (uint32_t i = 0; i < argsSize; ++i) - PushArg(ctx, args[i], isolate, info[i]); + PushArg(ctx, args[i], isolate, resource, info[i]); if (!native->Invoke(ctx)) { From 217d3768f00749550948159660ab065624b5295e Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 28 Jan 2021 19:12:04 +0100 Subject: [PATCH 277/564] Fix args length check --- bindings/Vector2.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/Vector2.cpp b/bindings/Vector2.cpp index b3c7ff93..8db4f974 100644 --- a/bindings/Vector2.cpp +++ b/bindings/Vector2.cpp @@ -106,7 +106,7 @@ static void Sub(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK_ARGS_LEN2(1, 3); + V8_CHECK_ARGS_LEN2(1, 2); v8::Local _this = info.This(); @@ -157,7 +157,7 @@ static void Divide(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK_ARGS_LEN2(1, 3); + V8_CHECK_ARGS_LEN2(1, 2); v8::Local _this = info.This(); @@ -211,7 +211,7 @@ static void Multiply(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK_ARGS_LEN2(1, 3); + V8_CHECK_ARGS_LEN2(1, 2); v8::Local _this = info.This(); From ceaf87b9011481af50f6290c62a61e20db1aefbc Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 31 Jan 2021 21:35:37 +0100 Subject: [PATCH 278/564] Handle MValueVector2 --- V8Helpers.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 52684aa5..69913b2b 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -177,6 +177,16 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) y->Value(), z->Value() }); } + else if (resource->IsVector2(v8Obj)) + { + v8::Local x = v8Obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local y = v8Obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + + return core.CreateMValueVector2( + alt::Vector2f{ + x->Value(), + y->Value() }); + } else if (resource->IsRGBA(v8Obj)) { v8::Local r = v8Obj->Get(ctx, V8::RGBA_RKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); @@ -297,6 +307,8 @@ v8::Local V8Helpers::MValueToV8(alt::MValueConst val) } case alt::IMValue::Type::VECTOR3: return V8ResourceImpl::Get(ctx)->CreateVector3(val.As()->Value()); + case alt::IMValue::Type::VECTOR2: + return V8ResourceImpl::Get(ctx)->CreateVector2(val.As()->Value()); case alt::IMValue::Type::RGBA: return V8ResourceImpl::Get(ctx)->CreateRGBA(val.As()->Value()); case alt::IMValue::Type::BYTE_ARRAY: From 85d5fa451f55eb320f7f88fe3363b7d3e9bad80f Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Mon, 1 Feb 2021 00:11:31 +0300 Subject: [PATCH 279/564] Updated SDK --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 428fd335..e283ccf0 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 428fd335c7b8dbf0b707c3972cfb32f762762d4b +Subproject commit e283ccf0d2e91ab06d79572aa6c3d12821d86846 From 056326797f2362669f081c4a16c74be55e411b0b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 31 Jan 2021 22:15:56 +0100 Subject: [PATCH 280/564] Update SDK --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 428fd335..e283ccf0 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 428fd335c7b8dbf0b707c3972cfb32f762762d4b +Subproject commit e283ccf0d2e91ab06d79572aa6c3d12821d86846 From 0dab3c61ef3968c30a25c3c95353d71df8715ce6 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 31 Jan 2021 23:00:30 +0100 Subject: [PATCH 281/564] Add heap console command --- src/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index cbb58537..0c41eaa1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,10 +8,19 @@ #define ALTV_JS_EXPORT extern "C" #endif +static void HeapCommand(alt::Array, void* runtime) +{ + static_cast(runtime)->HeapBenchmark(); +} + ALTV_JS_EXPORT alt::IScriptRuntime *CreateJSScriptRuntime(alt::ICore *core) { alt::ICore::SetInstance(core); auto ret = new CV8ScriptRuntime(); + + // Commands + core->SubscribeCommand("heap", HeapCommand, ret); + return ret; } From d009d9a1c93c491ef97a0a4480ccf2c079d54862 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 2 Feb 2021 11:45:11 +0100 Subject: [PATCH 282/564] Add timers command --- src/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 0c41eaa1..b62fb059 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,11 @@ static void HeapCommand(alt::Array, void* runtime) static_cast(runtime)->HeapBenchmark(); } +static void TimersCommand(alt::Array, void* runtime) +{ + // TODO: Add timers command +} + ALTV_JS_EXPORT alt::IScriptRuntime *CreateJSScriptRuntime(alt::ICore *core) { alt::ICore::SetInstance(core); @@ -20,6 +25,7 @@ ALTV_JS_EXPORT alt::IScriptRuntime *CreateJSScriptRuntime(alt::ICore *core) // Commands core->SubscribeCommand("heap", HeapCommand, ret); + core->SubscribeCommand("timers", TimersCommand, ret); return ret; } From f436f16207c69786341100d738fc6b57ece2ef08 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 2 Feb 2021 11:49:17 +0100 Subject: [PATCH 283/564] Add settings.json to gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1678a5b2..c29aef7d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ BUILD/ deps/v8/ -.vs/ \ No newline at end of file +.vs/ + +.vscode/settings.json From 1f67097df325d602ef1d8d086129dd2f3e48d684 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 2 Feb 2021 11:49:38 +0100 Subject: [PATCH 284/564] Change default build to release build and add debug build task --- .vscode/tasks.json | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 12902f7d..846d1ecb 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,7 +6,17 @@ { "label": "Build", "type": "shell", - "command": "cmake --build BUILD", + "command": "cmake --build BUILD --config Release", + "problemMatcher": ["$msCompile"], + "group": { + "kind": "build", + "isDefault": true + }, + }, + { + "label": "Build (Debug)", + "type": "shell", + "command": "cmake --build BUILD --config Debug", "problemMatcher": ["$msCompile"], "group": { "kind": "build", From 69639f9b5f9b8b0ae8ea235f1f4497f962d1874d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 2 Feb 2021 11:50:51 +0100 Subject: [PATCH 285/564] Remove outdated include path from VSCode CPP properties file --- .vscode/c_cpp_properties.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index e135dc76..de300375 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -24,8 +24,7 @@ "name": "Win32 Shared", "includePath": [ "${workspaceFolder}/**", - "${workspaceFolder}/deps", - "${workspaceFolder}/deps/v8/include" + "${workspaceFolder}/deps" ], "defines": [ "_DEBUG", From 44aeaf81d108930d04c6d0254badfc6cf3c55263 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 2 Feb 2021 11:58:49 +0100 Subject: [PATCH 286/564] Use RegisterScriptRuntime instead of return --- src/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 43376dcf..300f6f22 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,11 +8,11 @@ #define ALTV_JS_EXPORT extern "C" #endif -ALTV_JS_EXPORT alt::IScriptRuntime *CreateScriptRuntime(alt::ICore *core) +ALTV_JS_EXPORT void CreateScriptRuntime(alt::ICore *core) { alt::ICore::SetInstance(core); - auto ret = new CV8ScriptRuntime(); - return ret; + auto runtime = new CV8ScriptRuntime(); + core->RegisterScriptRuntime("js", runtime); } ALTV_JS_EXPORT const char* GetType() @@ -23,4 +23,4 @@ ALTV_JS_EXPORT const char* GetType() ALTV_JS_EXPORT uint32_t GetSDKVersion() { return alt::ICore::SDK_VERSION; -} \ No newline at end of file +} From d6680e15014a580a5607497f243185e65c7b6eac Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 2 Feb 2021 17:48:49 +0100 Subject: [PATCH 287/564] Add macro to get internal field external value --- V8Helpers.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/V8Helpers.h b/V8Helpers.h index 82e90d86..2ab03bfa 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -296,6 +296,10 @@ namespace V8 #define V8_GET_THIS_INTERNAL_FIELD_UINT32(idx, val) \ auto val = info.This()->GetInternalField((idx)-1)->Uint32Value(ctx).ToChecked(); +// idx starts with 1 +#define V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(idx, val, type) \ + auto val = static_cast(info.This()->GetInternalField((idx)-1).As()->Value()); + #define V8_CHECK_CONSTRUCTOR() V8_CHECK(info.IsConstructCall(), "function can't be called without new") #define V8_CHECK_ARGS_LEN(count) V8_CHECK(info.Length() == (count), #count " arguments expected") From 099e40554e03c8758b3211565eedcbe186f081de Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Fri, 26 Feb 2021 16:33:16 +0300 Subject: [PATCH 288/564] Add player volume properties --- src/bindings/Player.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 287f176b..3a3a3378 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -253,6 +253,42 @@ static void GetCurrentWeapon(const v8::FunctionCallbackInfo& info) V8_RETURN_INTEGER(player->GetCurrentWeapon()); } +static void SpatialVolumeGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(_this, alt::IPlayer); + + V8_RETURN_NUMBER(_this->GetSpatialVolume()); +} + +static void SpatialVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(_this, alt::IPlayer); + + V8_TO_NUMBER(val, volume); + + _this->SetSpatialVolume(volume); +} + +static void NonSpatialVolumeGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(_this, alt::IPlayer); + + V8_RETURN_NUMBER(_this->GetNonSpatialVolume()); +} + +static void NonSpatialVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(_this, alt::IPlayer); + + V8_TO_NUMBER(val, volume); + + _this->SetNonSpatialVolume(volume); +} + static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -305,6 +341,8 @@ extern V8Class v8Player("Player", v8Entity, [](v8::Local t V8::SetAccessor(isolate, tpl, "maxHealth", &MaxHealthGetter); V8::SetAccessor(isolate, tpl, "armour", &ArmourGetter); V8::SetAccessor(isolate, tpl, "maxArmour", &MaxArmourGetter); + V8::SetAccessor(isolate, tpl, "spatialVolume", &SpatialVolumeGetter, &SpatialVolumeSetter); + V8::SetAccessor(isolate, tpl, "nonSpatialVolume", &NonSpatialVolumeGetter, &NonSpatialVolumeSetter); // Weapon getters V8::SetAccessor(isolate, tpl, "currentWeaponComponents", &CurrentWeaponComponentsGetter); From 5b77373e038660d868f0aece68b8f3600d7be2db Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 27 Feb 2021 16:07:37 +0100 Subject: [PATCH 289/564] Add shared debug property --- bindings/Main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 2fb6574a..29bdcea3 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -310,4 +310,6 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex #endif V8::DefineOwnProperty(isolate, ctx, exports, "sdkVersion", v8::Integer::New(isolate, alt::ICore::Instance().SDK_VERSION)); + + V8::DefineOwnProperty(isolate, ctx, exports, "debug", v8::Boolean::New(isolate, alt::ICore::Instance().IsDebug())); } From 325455fa7163ca9e8f478d3436898b0a61e05cbe Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 27 Feb 2021 16:08:07 +0100 Subject: [PATCH 290/564] Add isInDebug method and update helpers --- src/bindings/Main.cpp | 1 - src/helpers | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 5b5f81db..f591c589 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -780,7 +780,6 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "removeIpl", &RemoveIPL); //V8Helpers::RegisterFunc(exports, "wait", &ScriptWait); //V8Helpers::RegisterFunc(exports, "isInSandbox", &IsInSandbox); - V8Helpers::RegisterFunc(exports, "isInDebug", &IsInDebug); V8Helpers::RegisterFunc(exports, "setCamFrozen", &SetCamFrozen); V8Helpers::RegisterFunc(exports, "getLicenseHash", &GetLicenseHash); diff --git a/src/helpers b/src/helpers index 8307bc4d..5b77373e 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 8307bc4d95a5e0b03a9d8c8280a071813c7ab3d5 +Subproject commit 5b77373e038660d868f0aece68b8f3600d7be2db From 8958d303445b222216710c65bd2ac65d6a3ac81f Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 27 Feb 2021 16:18:48 +0100 Subject: [PATCH 291/564] Update SDK --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index e283ccf0..af18755e 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit e283ccf0d2e91ab06d79572aa6c3d12821d86846 +Subproject commit af18755e2824c8b843033ad8b7f8aa6bea208eae From 42193b1d7d84fda232f60bc694296a38b9e6e4b5 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 28 Feb 2021 12:33:43 +0100 Subject: [PATCH 292/564] Add global timer funcs --- src/CV8Resource.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 7a9fbb4c..2415f339 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -122,17 +122,22 @@ bool CV8ResourceImpl::Start() modules.emplace(path, v8::UniquePersistent{isolate, curModule}); + auto exports = altModule.GetExports(isolate, ctx); // Overwrite global console object auto console = ctx->Global()->Get(ctx, V8_NEW_STRING("console")).ToLocalChecked().As(); if (!console.IsEmpty()) { - auto exports = altModule.GetExports(isolate, ctx); - console->Set(ctx, V8_NEW_STRING("log"), exports->Get(ctx, V8_NEW_STRING("log")).ToLocalChecked()); console->Set(ctx, V8_NEW_STRING("warn"), exports->Get(ctx, V8_NEW_STRING("logWarning")).ToLocalChecked()); console->Set(ctx, V8_NEW_STRING("error"), exports->Get(ctx, V8_NEW_STRING("logError")).ToLocalChecked()); } + // Add global timer funcs + ctx->Global()->Set(ctx, V8_NEW_STRING("setInterval"), exports->Get(ctx, V8_NEW_STRING("setInterval")).ToLocalChecked()); + ctx->Global()->Set(ctx, V8_NEW_STRING("setTimeout"), exports->Get(ctx, V8_NEW_STRING("setTimeout")).ToLocalChecked()); + ctx->Global()->Set(ctx, V8_NEW_STRING("clearInterval"), exports->Get(ctx, V8_NEW_STRING("clearInterval")).ToLocalChecked()); + ctx->Global()->Set(ctx, V8_NEW_STRING("clearTimeout"), exports->Get(ctx, V8_NEW_STRING("clearTimeout")).ToLocalChecked()); + ctx->Global()->Set(ctx, v8::String::NewFromUtf8(isolate, "__internal_get_exports").ToLocalChecked(), v8::Function::New(ctx, &StaticRequire).ToLocalChecked()); bool res = curModule->InstantiateModule(ctx, CV8ScriptRuntime::ResolveModule).IsJust(); From 7fb01a905ed3f75e9258eb65dea3579834282cda Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 1 Mar 2021 18:21:52 +0100 Subject: [PATCH 293/564] Add checkpoint binding --- src/bindings/Main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 5b5f81db..c45c53bb 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -734,7 +734,8 @@ extern V8Class v8Vector3, v8Voice, v8PedBlip, v8VehicleBlip, - v8WebSocketClient; + v8WebSocketClient, + v8Checkpoint; extern V8Module altModule( "alt", {v8Vector3, @@ -757,7 +758,8 @@ extern V8Module altModule( v8MapZoomData, v8Discord, v8Voice, - v8WebSocketClient}, + v8WebSocketClient, + v8Checkpoint}, [](v8::Local ctx, v8::Local exports) { V8::RegisterSharedMain(ctx, exports); From 46ee4cd45ff347ce23f8a35bcf890945baf82382 Mon Sep 17 00:00:00 2001 From: fabian Date: Sun, 7 Mar 2021 16:55:05 +0100 Subject: [PATCH 294/564] Fix crash when pushing invalid args to natives --- src/bindings/V8Natives.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 6f04e343..e064e143 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -76,22 +76,46 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a scrCtx->Push(SavePointer((int32_t)val->ToBoolean(isolate)->Value())); break; case alt::INative::Type::ARG_INT32: - scrCtx->Push((int32_t)val->ToInteger(v8Ctx).ToLocalChecked()->Value()); + { + v8::Local value; + if (val->ToInteger(v8Ctx).ToLocal(&value)) { + scrCtx->Push((int32_t)value->Value()); + } + else { + Log::Error << "Unknown native arg type" << (int)argType; + } break; + } case alt::INative::Type::ARG_INT32_PTR: ++returnsCount; scrCtx->Push(SavePointer((int32_t)val->ToInteger(v8Ctx).ToLocalChecked()->Value())); break; case alt::INative::Type::ARG_UINT32: - scrCtx->Push((uint32_t)val->ToInteger(v8Ctx).ToLocalChecked()->Value()); + { + v8::Local value; + if (val->ToInteger(v8Ctx).ToLocal(&value)) { + scrCtx->Push((uint32_t)value->Value()); + } + else { + Log::Error << "Unknown native arg type" << (int)argType; + } break; + } case alt::INative::Type::ARG_UINT32_PTR: ++returnsCount; scrCtx->Push(SavePointer((uint32_t)val->ToInteger(v8Ctx).ToLocalChecked()->Value())); break; case alt::INative::Type::ARG_FLOAT: - scrCtx->Push((float)val->ToNumber(v8Ctx).ToLocalChecked()->Value()); + { + v8::Local value; + if (val->ToNumber(v8Ctx).ToLocal(&value)) { + scrCtx->Push((float)value->Value()); + } + else { + Log::Error << "Unknown native arg type" << (int)argType; + } break; + } case alt::INative::Type::ARG_FLOAT_PTR: ++returnsCount; scrCtx->Push(SavePointer((float)val->ToNumber(v8Ctx).ToLocalChecked()->Value())); From 0ed886967c5f0ed0a409dc14b058f3fecf902431 Mon Sep 17 00:00:00 2001 From: fabian Date: Sun, 7 Mar 2021 17:01:21 +0100 Subject: [PATCH 295/564] add bigint support for natives --- src/bindings/V8Natives.cpp | 64 ++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index e064e143..8cbabc5a 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -77,11 +77,32 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a break; case alt::INative::Type::ARG_INT32: { - v8::Local value; - if (val->ToInteger(v8Ctx).ToLocal(&value)) { - scrCtx->Push((int32_t)value->Value()); + if (val->IsInt32()) + { + v8::Local value; + if (val->ToInteger(v8Ctx).ToLocal(&value)) + { + scrCtx->Push((int32_t)value->Value()); + } + else + { + Log::Error << "Unknown native arg type" << (int)argType; + } + } + else if (val->IsBigInt()) + { + v8::Local value; + if (val->ToBigInt(v8Ctx).ToLocal(&value)) + { + scrCtx->Push((int32_t)value->Int64Value()); + } + else + { + Log::Error << "Unknown native arg type" << (int)argType; + } } - else { + else + { Log::Error << "Unknown native arg type" << (int)argType; } break; @@ -92,11 +113,32 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a break; case alt::INative::Type::ARG_UINT32: { - v8::Local value; - if (val->ToInteger(v8Ctx).ToLocal(&value)) { - scrCtx->Push((uint32_t)value->Value()); + if (val->IsInt32()) + { + v8::Local value; + if (val->ToInteger(v8Ctx).ToLocal(&value)) + { + scrCtx->Push((uint32_t)value->Value()); + } + else + { + Log::Error << "Unknown native arg type" << (int)argType; + } } - else { + else if (val->IsBigInt()) + { + v8::Local value; + if (val->ToBigInt(v8Ctx).ToLocal(&value)) + { + scrCtx->Push((uint32_t)value->Int64Value()); + } + else + { + Log::Error << "Unknown native arg type" << (int)argType; + } + } + else + { Log::Error << "Unknown native arg type" << (int)argType; } break; @@ -108,10 +150,12 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a case alt::INative::Type::ARG_FLOAT: { v8::Local value; - if (val->ToNumber(v8Ctx).ToLocal(&value)) { + if (val->ToNumber(v8Ctx).ToLocal(&value)) + { scrCtx->Push((float)value->Value()); } - else { + else + { Log::Error << "Unknown native arg type" << (int)argType; } break; From d0a2c9fcc319f08370f7fd5ca79e85572c31faaf Mon Sep 17 00:00:00 2001 From: fabian Date: Sun, 7 Mar 2021 17:03:20 +0100 Subject: [PATCH 296/564] Update cpp-sdk --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index e283ccf0..a3f8de6e 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit e283ccf0d2e91ab06d79572aa6c3d12821d86846 +Subproject commit a3f8de6e960fc9feaa9dc22fac427de36609f09c From 23c00a6c7ee951ef264a32da44c8f676dafa980a Mon Sep 17 00:00:00 2001 From: fabian Date: Mon, 8 Mar 2021 23:54:54 +0100 Subject: [PATCH 297/564] fix int32 check --- src/bindings/V8Natives.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 8cbabc5a..60b5f977 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -77,7 +77,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a break; case alt::INative::Type::ARG_INT32: { - if (val->IsInt32()) + if (val->IsInteger()) { v8::Local value; if (val->ToInteger(v8Ctx).ToLocal(&value)) @@ -113,7 +113,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a break; case alt::INative::Type::ARG_UINT32: { - if (val->IsInt32()) + if (val->IsInteger()) { v8::Local value; if (val->ToInteger(v8Ctx).ToLocal(&value)) From 8916c0daa9cf229dc786be0f06ddd6a62594d731 Mon Sep 17 00:00:00 2001 From: fabian Date: Tue, 9 Mar 2021 00:26:07 +0100 Subject: [PATCH 298/564] fix int checks --- src/bindings/V8Natives.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 60b5f977..d6c93425 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -77,7 +77,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a break; case alt::INative::Type::ARG_INT32: { - if (val->IsInteger()) + if (val->IsUint32() || val->IsInt32()) { v8::Local value; if (val->ToInteger(v8Ctx).ToLocal(&value)) @@ -113,7 +113,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a break; case alt::INative::Type::ARG_UINT32: { - if (val->IsInteger()) + if (val->IsUint32() || val->IsInt32()) { v8::Local value; if (val->ToInteger(v8Ctx).ToLocal(&value)) From e7cb7df01c99887e3f374f191c9df6cbec76c994 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 13 Mar 2021 21:07:05 +0100 Subject: [PATCH 299/564] Update SDK --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index af18755e..a3f8de6e 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit af18755e2824c8b843033ad8b7f8aa6bea208eae +Subproject commit a3f8de6e960fc9feaa9dc22fac427de36609f09c From e9e1bc945026c348076e2c5203c9d9cbfd692b34 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 13 Mar 2021 22:51:26 +0100 Subject: [PATCH 300/564] Added check for res == this --- src/CV8Resource.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 264111b3..57a7b043 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -196,6 +196,7 @@ bool CV8ResourceImpl::Stop() auto name = this->resource->GetName().ToString(); for(auto res : resources) { + if(res == this) continue; auto it = res->modules.find(name); if(it != res->modules.end()) { res->modules.erase(it); From c875e3004509718857b96fe4e459ff8ef8f18007 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 14 Mar 2021 00:27:05 +0100 Subject: [PATCH 301/564] Improve performance with IsObject call --- src/bindings/V8Natives.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 35efc106..7ea52a95 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -78,8 +78,8 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a case alt::INative::Type::ARG_INT32: int32_t value; V8Entity* ent; - ent = V8Entity::Get(val); - if(ent != nullptr) value = (int32_t)ent->GetHandle().As()->GetScriptGuid(); + if(val->IsObject() && (ent = V8Entity::Get(val)) != nullptr) + value = (int32_t)ent->GetHandle().As()->GetScriptGuid(); else value = (int32_t)val->ToInteger(v8Ctx).ToLocalChecked()->Value(); scrCtx->Push(value); break; From ed2a37c9329ee76c69b8349f20bb4a1de6a70153 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 17 Mar 2021 20:12:29 +0100 Subject: [PATCH 302/564] Change checkpoint constructor to use Vector3 object --- src/bindings/Checkpoint.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index 867f4f21..9066ce33 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -6,17 +6,21 @@ static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_CONSTRUCTOR(); - V8_CHECK_ARGS_LEN(10); + V8_CHECK_ARGS_LEN(6); V8_ARG_TO_INTEGER(1, type); - V8_ARG_TO_NUMBER(2, x1); - V8_ARG_TO_NUMBER(3, y1); - V8_ARG_TO_NUMBER(4, z1); - V8_ARG_TO_NUMBER(5, x2); - V8_ARG_TO_NUMBER(6, y2); - V8_ARG_TO_NUMBER(7, z2); - V8_ARG_TO_NUMBER(8, radius); - V8_ARG_TO_NUMBER(9, height); - V8_ARG_TO_OBJECT(10, color); + V8_ARG_TO_OBJECT(2, pos); + V8_ARG_TO_OBJECT(3, nextPos); + V8_ARG_TO_NUMBER(4, radius); + V8_ARG_TO_NUMBER(5, height); + V8_ARG_TO_OBJECT(6, color); + + V8_OBJECT_GET_NUMBER(pos, "x", x1); + V8_OBJECT_GET_NUMBER(pos, "y", y1); + V8_OBJECT_GET_NUMBER(pos, "z", z1); + + V8_OBJECT_GET_NUMBER(nextPos, "x", x2); + V8_OBJECT_GET_NUMBER(nextPos, "y", y2); + V8_OBJECT_GET_NUMBER(nextPos, "z", z2); V8_OBJECT_GET_INTEGER(color, "r", r); V8_OBJECT_GET_INTEGER(color, "g", g); @@ -149,4 +153,4 @@ extern V8Class v8Checkpoint("Checkpoint", v8WorldObject, Constructor, [](v8::Loc V8::SetMethod(isolate, tpl, "isEntityIn", &IsEntityIn); V8::SetMethod(isolate, tpl, "isPointIn", &IsPointIn); -}); \ No newline at end of file +}); From f45b00be6ab8a24bbfb6b5c5b09a43ba98a94fbc Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 17 Mar 2021 20:13:31 +0100 Subject: [PATCH 303/564] Fix variable ambiguity --- src/bindings/Checkpoint.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index 9066ce33..fdc0fcd3 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -14,9 +14,9 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_ARG_TO_NUMBER(5, height); V8_ARG_TO_OBJECT(6, color); - V8_OBJECT_GET_NUMBER(pos, "x", x1); - V8_OBJECT_GET_NUMBER(pos, "y", y1); - V8_OBJECT_GET_NUMBER(pos, "z", z1); + V8_OBJECT_GET_NUMBER(pos, "x", x); + V8_OBJECT_GET_NUMBER(pos, "y", y); + V8_OBJECT_GET_NUMBER(pos, "z", z); V8_OBJECT_GET_NUMBER(nextPos, "x", x2); V8_OBJECT_GET_NUMBER(nextPos, "y", y2); @@ -27,7 +27,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_OBJECT_GET_INTEGER(color, "b", b); V8_OBJECT_GET_INTEGER(color, "a", a); - alt::Ref cp = alt::ICore::Instance().CreateCheckpoint(type, { x1, y1, z1 }, { x2, y2, z2 }, radius, height, { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); + alt::Ref cp = alt::ICore::Instance().CreateCheckpoint(type, { x, y, z }, { x2, y2, z2 }, radius, height, { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); V8_BIND_BASE_OBJECT(cp, "Failed to create Checkpoint"); } From e75514546c09c6e2f57188dac834ef483811d77f Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 17 Mar 2021 20:24:27 +0100 Subject: [PATCH 304/564] Add backwards compatibility --- src/bindings/Checkpoint.cpp | 70 +++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index fdc0fcd3..05568312 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -6,29 +6,53 @@ static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_CONSTRUCTOR(); - V8_CHECK_ARGS_LEN(6); - V8_ARG_TO_INTEGER(1, type); - V8_ARG_TO_OBJECT(2, pos); - V8_ARG_TO_OBJECT(3, nextPos); - V8_ARG_TO_NUMBER(4, radius); - V8_ARG_TO_NUMBER(5, height); - V8_ARG_TO_OBJECT(6, color); - - V8_OBJECT_GET_NUMBER(pos, "x", x); - V8_OBJECT_GET_NUMBER(pos, "y", y); - V8_OBJECT_GET_NUMBER(pos, "z", z); - - V8_OBJECT_GET_NUMBER(nextPos, "x", x2); - V8_OBJECT_GET_NUMBER(nextPos, "y", y2); - V8_OBJECT_GET_NUMBER(nextPos, "z", z2); - - V8_OBJECT_GET_INTEGER(color, "r", r); - V8_OBJECT_GET_INTEGER(color, "g", g); - V8_OBJECT_GET_INTEGER(color, "b", b); - V8_OBJECT_GET_INTEGER(color, "a", a); - - alt::Ref cp = alt::ICore::Instance().CreateCheckpoint(type, { x, y, z }, { x2, y2, z2 }, radius, height, { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); - V8_BIND_BASE_OBJECT(cp, "Failed to create Checkpoint"); + if(info.Length() == 6) + { + V8_ARG_TO_INTEGER(1, type); + V8_ARG_TO_OBJECT(2, pos); + V8_ARG_TO_OBJECT(3, nextPos); + V8_ARG_TO_NUMBER(4, radius); + V8_ARG_TO_NUMBER(5, height); + V8_ARG_TO_OBJECT(6, color); + + V8_OBJECT_GET_NUMBER(pos, "x", x); + V8_OBJECT_GET_NUMBER(pos, "y", y); + V8_OBJECT_GET_NUMBER(pos, "z", z); + + V8_OBJECT_GET_NUMBER(nextPos, "x", x2); + V8_OBJECT_GET_NUMBER(nextPos, "y", y2); + V8_OBJECT_GET_NUMBER(nextPos, "z", z2); + + V8_OBJECT_GET_INTEGER(color, "r", r); + V8_OBJECT_GET_INTEGER(color, "g", g); + V8_OBJECT_GET_INTEGER(color, "b", b); + V8_OBJECT_GET_INTEGER(color, "a", a); + + alt::Ref cp = alt::ICore::Instance().CreateCheckpoint(type, { x, y, z }, { x2, y2, z2 }, radius, height, { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); + V8_BIND_BASE_OBJECT(cp, "Failed to create Checkpoint"); + } + else if(info.Length() == 10) + { + V8_ARG_TO_INTEGER(1, type); + V8_ARG_TO_NUMBER(2, x); + V8_ARG_TO_NUMBER(3, y); + V8_ARG_TO_NUMBER(4, z); + V8_ARG_TO_NUMBER(5, x2); + V8_ARG_TO_NUMBER(6, y2); + V8_ARG_TO_NUMBER(7, z2); + V8_ARG_TO_NUMBER(8, radius); + V8_ARG_TO_NUMBER(9, height); + V8_ARG_TO_OBJECT(10, color); + + V8_OBJECT_GET_INTEGER(color, "r", r); + V8_OBJECT_GET_INTEGER(color, "g", g); + V8_OBJECT_GET_INTEGER(color, "b", b); + V8_OBJECT_GET_INTEGER(color, "a", a); + + alt::Ref cp = alt::ICore::Instance().CreateCheckpoint(type, { x, y, z }, { x2, y2, z2 }, radius, height, { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); + V8_BIND_BASE_OBJECT(cp, "Failed to create Checkpoint"); + } + else V8Helpers::Throw(isolate, "6 or 10 arguments expected"); } static void TypeGetter(v8::Local, const v8::PropertyCallbackInfo& info) From 70e3b8357b8aff9d6bebd621a5abd09f39bdcab1 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 19 Mar 2021 09:28:47 +0100 Subject: [PATCH 305/564] Fix error logs for natives --- src/bindings/V8Natives.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index d6c93425..7d822149 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -86,7 +86,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a } else { - Log::Error << "Unknown native arg type" << (int)argType; + Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; } } else if (val->IsBigInt()) @@ -98,12 +98,12 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a } else { - Log::Error << "Unknown native arg type" << (int)argType; + Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; } } else { - Log::Error << "Unknown native arg type" << (int)argType; + Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; } break; } @@ -122,7 +122,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a } else { - Log::Error << "Unknown native arg type" << (int)argType; + Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; } } else if (val->IsBigInt()) @@ -134,12 +134,12 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a } else { - Log::Error << "Unknown native arg type" << (int)argType; + Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; } } else { - Log::Error << "Unknown native arg type" << (int)argType; + Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; } break; } @@ -156,7 +156,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a } else { - Log::Error << "Unknown native arg type" << (int)argType; + Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; } break; } @@ -178,7 +178,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a scrCtx->Push(ToMemoryBuffer(val, v8Ctx)); break; default: - Log::Error << "Unknown native arg type" << (int)argType; + Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; } } From 34f64907cea45d624bcaacea23d5aebcf16acbdb Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 19 Mar 2021 09:29:28 +0100 Subject: [PATCH 306/564] Fix last broken error in natives --- src/bindings/V8Natives.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 7d822149..71824522 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -249,7 +249,7 @@ static v8::Local GetReturn(alt::Ref scrCtx, al case alt::INative::Type::ARG_VOID: return v8::Undefined(isolate); default: - Log::Error << "Unknown native return type" << (int)retnType; + Log::Error << "Unknown native return type " << (int)retnType << Log::Endl; return v8::Undefined(isolate); } } From b12150140356f0f597aabbbfedb4ddd2f1f748eb Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 20 Mar 2021 20:12:57 +0100 Subject: [PATCH 307/564] Add shared hasResource --- bindings/Main.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 2fb6574a..b85b80a1 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -262,6 +262,18 @@ static void ClearTimer(const v8::FunctionCallbackInfo &info) resource->RemoveTimer(timer); } +static void HasResource(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_STRING(1, name); + + alt::IResource* resource = alt::ICore::Instance().GetResource(name); + + V8_RETURN_BOOLEAN(resource && resource->IsStarted()); +} + void V8::RegisterSharedMain(v8::Local ctx, v8::Local exports) { v8::Isolate *isolate = ctx->GetIsolate(); @@ -295,6 +307,8 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8Helpers::RegisterFunc(exports, "clearTimeout", &ClearTimer); V8Helpers::RegisterFunc(exports, "clearInterval", &ClearTimer); + V8Helpers::RegisterFunc(exports, "hasResource", &HasResource); + #ifdef ALT_SERVER_API V8::DefineOwnProperty(isolate, ctx, exports, "version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); V8::DefineOwnProperty(isolate, ctx, exports, "branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); From 225d1bf4a1f67fb0545f106b8be00a7d4db16e28 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 1 Apr 2021 19:09:23 +0200 Subject: [PATCH 308/564] Add streamedIn getter --- src/CV8ScriptRuntime.cpp | 34 ++++++++++++++++++++++++++++++++++ src/CV8ScriptRuntime.h | 17 +++++++++++++++++ src/bindings/Player.cpp | 17 +++++++++++++++++ src/bindings/Vehicle.cpp | 17 +++++++++++++++++ src/events/Entity.cpp | 22 ++++++++++++++++------ src/events/Events.h | 4 ++-- 6 files changed, 103 insertions(+), 8 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 2a457287..ed2a0e97 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -153,3 +153,37 @@ CV8ScriptRuntime::CV8ScriptRuntime() RegisterEvents(); } + +void CV8ScriptRuntime::OnEntityStreamIn(alt::Ref entity) +{ + switch(entity->GetType()) + { + case alt::IEntity::Type::PLAYER: + { + streamedInPlayers.push_back(entity.As()); + break; + } + case alt::IEntity::Type::VEHICLE: + { + streamedInVehicles.push_back(entity.As()); + break; + } + } +} + +void CV8ScriptRuntime::OnEntityStreamOut(alt::Ref entity) +{ + switch(entity->GetType()) + { + case alt::IEntity::Type::PLAYER: + { + streamedInPlayers.erase(std::find(streamedInPlayers.begin(), streamedInPlayers.end(), entity)); + break; + } + case alt::IEntity::Type::VEHICLE: + { + streamedInVehicles.erase(std::find(streamedInVehicles.begin(), streamedInVehicles.end(), entity)); + break; + } + } +} diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 8c2fb8cd..0cceb1eb 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -5,6 +5,8 @@ #include "libplatform/libplatform.h" #include "cpp-sdk/IScriptRuntime.h" +#include "cpp-sdk/objects/IPlayer.h" +#include "cpp-sdk/objects/IVehicle.h" #include "CV8Resource.h" @@ -20,6 +22,9 @@ class CV8ScriptRuntime : public alt::IScriptRuntime std::unique_ptr inspector; std::unique_ptr inspectorSession; + std::vector> streamedInPlayers; + std::vector> streamedInVehicles; + public: static CV8ScriptRuntime* instance; @@ -161,4 +166,16 @@ class CV8ScriptRuntime : public alt::IScriptRuntime // }; bool resourcesLoaded = false; + + void OnEntityStreamIn(alt::Ref entity); + void OnEntityStreamOut(alt::Ref entity); + + std::vector> GetStreamedInPlayers() + { + return streamedInPlayers; + } + std::vector> GetStreamedInVehicles() + { + return streamedInVehicles; + } }; \ No newline at end of file diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 3a3a3378..0a93c49a 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -4,6 +4,8 @@ #include "../helpers/V8Entity.h" #include "../helpers/V8ResourceImpl.h" +#include "../CV8ScriptRuntime.h" + #include "cpp-sdk/objects/IPlayer.h" #include "cpp-sdk/objects/IVehicle.h" @@ -296,6 +298,20 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo V8_RETURN(resource->GetAllPlayers()->Clone()); } +static void StreamedInGetter(v8::Local name, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + auto streamedIn = CV8ScriptRuntime::instance->GetStreamedInPlayers(); + auto arr = v8::Array::New(isolate, streamedIn.size()); + for(auto i = 0; i < streamedIn.size(); i++) + { + arr->Set(ctx, i, resource->GetOrCreateEntity(streamedIn[i].Get(), "Player")->GetJSVal(isolate)); + } + + V8_RETURN(arr); +} + static void LocalGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -329,6 +345,7 @@ extern V8Class v8Player("Player", v8Entity, [](v8::Local t V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); V8::SetStaticAccessor(isolate, tpl, "all", &AllGetter); + V8::SetStaticAccessor(isolate, tpl, "streamedIn", &StreamedInGetter); V8::SetStaticAccessor(isolate, tpl, "local", &LocalGetter); // Common getters diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index ee30f0c6..52daee0b 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -4,6 +4,8 @@ #include "../helpers/V8Entity.h" #include "../helpers/V8ResourceImpl.h" +#include "../CV8ScriptRuntime.h" + #include "cpp-sdk/objects/IPlayer.h" #include "cpp-sdk/objects/IVehicle.h" @@ -523,6 +525,20 @@ static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo V8_RETURN(resource->GetAllVehicles()->Clone()); } +static void StreamedInGetter(v8::Local name, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + auto streamedIn = CV8ScriptRuntime::instance->GetStreamedInVehicles(); + auto arr = v8::Array::New(isolate, streamedIn.size()); + for(auto i = 0; i < streamedIn.size(); i++) + { + arr->Set(ctx, i, resource->GetOrCreateEntity(streamedIn[i].Get(), "Vehicle")->GetJSVal(isolate)); + } + + V8_RETURN(arr); +} + static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -549,6 +565,7 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); V8::SetStaticAccessor(isolate, tpl, "all", &AllGetter); + V8::SetStaticAccessor(isolate, tpl, "streamedIn", &StreamedInGetter); // Common getters V8::SetAccessor(isolate, tpl, "speed", &SpeedGetter); diff --git a/src/events/Entity.cpp b/src/events/Entity.cpp index 15c34df3..a61191aa 100644 --- a/src/events/Entity.cpp +++ b/src/events/Entity.cpp @@ -1,6 +1,8 @@ #include "../helpers/V8ResourceImpl.h" #include "../helpers/V8Helpers.h" +#include "../CV8ScriptRuntime.h" + #include "cpp-sdk/events/CRemoveEntityEvent.h" #include "cpp-sdk/events/CGameEntityCreateEvent.h" #include "cpp-sdk/events/CGameEntityDestroyEvent.h" @@ -20,9 +22,13 @@ V8_LOCAL_EVENT_HANDLER removeEntity( args.push_back(resource->GetOrCreateEntity(ev->GetEntity().Get())->GetJSVal(isolate)); }); -V8_LOCAL_EVENT_HANDLER gameEntityCreate( +V8_EVENT_HANDLER gameEntityCreate( EventType::GAME_ENTITY_CREATE, - "gameEntityCreate", + [](V8ResourceImpl* resource, const alt::CEvent* e) { + CV8ScriptRuntime::instance->OnEntityStreamIn(static_cast(e)->GetTarget()); + + return resource->GetLocalHandlers("gameEntityCreate"); + }, [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { auto ev = static_cast(e); v8::Isolate *isolate = resource->GetIsolate(); @@ -30,12 +36,16 @@ V8_LOCAL_EVENT_HANDLER gameEntityCreate( args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); }); -V8_LOCAL_EVENT_HANDLER gameEntityDestroy( +V8_EVENT_HANDLER gameEntityDestroy( EventType::GAME_ENTITY_DESTROY, - "gameEntityDestroy", + [](V8ResourceImpl* resource, const alt::CEvent* e) { + CV8ScriptRuntime::instance->OnEntityStreamOut(static_cast(e)->GetTarget()); + + return resource->GetLocalHandlers("gameEntityDestroy"); + }, [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { - auto ev = static_cast(e); + auto ev = static_cast(e); v8::Isolate *isolate = resource->GetIsolate(); args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); - }); \ No newline at end of file + }); diff --git a/src/events/Events.h b/src/events/Events.h index 8fc706f6..507b9740 100644 --- a/src/events/Events.h +++ b/src/events/Events.h @@ -26,8 +26,8 @@ inline void RegisterEvents() // Entity V8_REFERENCE_LOCAL_EVENT_HANDLER(removeEntity); - V8_REFERENCE_LOCAL_EVENT_HANDLER(gameEntityCreate); - V8_REFERENCE_LOCAL_EVENT_HANDLER(gameEntityDestroy); + V8_REFERENCE_EVENT_HANDLER(gameEntityCreate); + V8_REFERENCE_EVENT_HANDLER(gameEntityDestroy); // Meta V8_REFERENCE_LOCAL_EVENT_HANDLER(syncedMetaChange); From 3a892f49c37ef1ec30b8d3c9523801e6fff8c904 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 2 Apr 2021 19:44:11 +0200 Subject: [PATCH 309/564] Add clientjs command to show general info --- src/main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 300f6f22..4f8237f7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,11 +8,21 @@ #define ALTV_JS_EXPORT extern "C" #endif +static void ClientJSCommand(alt::Array args, void*) +{ + Log::Colored << "~b~[[ ~w~Client JS ~b~]]" << Log::Endl; + Log::Colored << "~y~Powered by V8" << Log::Endl; + Log::Colored << "V8 version: ~g~v" << V8_MAJOR_VERSION << "." << V8_MINOR_VERSION << Log::Endl; + Log::Colored << "SDK version: ~g~v" << alt::ICore::SDK_VERSION << Log::Endl; +} + ALTV_JS_EXPORT void CreateScriptRuntime(alt::ICore *core) { alt::ICore::SetInstance(core); auto runtime = new CV8ScriptRuntime(); core->RegisterScriptRuntime("js", runtime); + + core->SubscribeCommand("clientjs", &ClientJSCommand); } ALTV_JS_EXPORT const char* GetType() From 49e206de5968a2f1ad3f015548c7dbd0c7956bef Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 3 Apr 2021 01:53:18 +0200 Subject: [PATCH 310/564] Make the message prettier --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4f8237f7..8377ea29 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,10 +10,11 @@ static void ClientJSCommand(alt::Array args, void*) { - Log::Colored << "~b~[[ ~w~Client JS ~b~]]" << Log::Endl; - Log::Colored << "~y~Powered by V8" << Log::Endl; + Log::Colored << "~r~--------------------------------" << Log::Endl; + Log::Colored << "~y~Client JS module - Powered by V8" << Log::Endl; Log::Colored << "V8 version: ~g~v" << V8_MAJOR_VERSION << "." << V8_MINOR_VERSION << Log::Endl; Log::Colored << "SDK version: ~g~v" << alt::ICore::SDK_VERSION << Log::Endl; + Log::Colored << "~r~--------------------------------" << Log::Endl; } ALTV_JS_EXPORT void CreateScriptRuntime(alt::ICore *core) From 12e23fe13924919836fa61efa583f7d61ba25403 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 3 Apr 2021 02:20:33 +0200 Subject: [PATCH 311/564] Match behaviour of serverside JS module command --- src/main.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8377ea29..50dd92df 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,11 +10,26 @@ static void ClientJSCommand(alt::Array args, void*) { - Log::Colored << "~r~--------------------------------" << Log::Endl; - Log::Colored << "~y~Client JS module - Powered by V8" << Log::Endl; - Log::Colored << "V8 version: ~g~v" << V8_MAJOR_VERSION << "." << V8_MINOR_VERSION << Log::Endl; - Log::Colored << "SDK version: ~g~v" << alt::ICore::SDK_VERSION << Log::Endl; - Log::Colored << "~r~--------------------------------" << Log::Endl; + if (args.GetSize() > 0 && args[0] == "--version") + { + Log::Colored << "~ly~cpp-sdk: v" << alt::ICore::SDK_VERSION << Log::Endl; + Log::Colored << "~ly~" << u8"Copyright © 2020 altMP team." << Log::Endl; + + Log::Colored << "~ly~v8: v" << V8_MAJOR_VERSION << "." << V8_MINOR_VERSION << Log::Endl; + Log::Colored << "~ly~" << u8"Copyright © 2014 The V8 project authors." << Log::Endl; + } + else if (args.GetSize() > 0 && args[0] == "--help") + { + Log::Colored << "~y~Usage: ~w~js-module [options]" << Log::Endl; + Log::Colored << "~y~Options:" << Log::Endl; + Log::Colored << " ~ly~--help ~w~- this message." << Log::Endl; + Log::Colored << " ~ly~--version ~w~- version info." << Log::Endl; + } + else + { + Log::Colored << "~y~Usage: ~w~js-module [options]" << Log::Endl; + Log::Colored << " Use: ~ly~\"js-module --help\" ~w~for more info" << Log::Endl; + } } ALTV_JS_EXPORT void CreateScriptRuntime(alt::ICore *core) @@ -23,7 +38,7 @@ ALTV_JS_EXPORT void CreateScriptRuntime(alt::ICore *core) auto runtime = new CV8ScriptRuntime(); core->RegisterScriptRuntime("js", runtime); - core->SubscribeCommand("clientjs", &ClientJSCommand); + core->SubscribeCommand("js-module", &ClientJSCommand); } ALTV_JS_EXPORT const char* GetType() From 91df7eddbd4bb19fc05fae9180f25d320456a20e Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 3 Apr 2021 16:39:57 +0200 Subject: [PATCH 312/564] Add static local storage methods and deprecate instance methods --- src/bindings/LocalStorage.cpp | 85 ++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 12 deletions(-) diff --git a/src/bindings/LocalStorage.cpp b/src/bindings/LocalStorage.cpp index 9ab59c3d..78d79b79 100644 --- a/src/bindings/LocalStorage.cpp +++ b/src/bindings/LocalStorage.cpp @@ -8,8 +8,54 @@ static void StaticGet(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); + if(info.Length() == 0) + { + V8_RETURN(static_cast(resource)->GetLocalStorage()); + + Log::Warning << "Using the local storage instance methods is deprecated. Use the static methods instead." << Log::Endl; + } + else + { + alt::IResource *iresource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + V8_ARG_TO_STRING(1, key); + V8_RETURN(V8Helpers::MValueToV8(iresource->GetLocalStorage()->Get(key))); + } +} + +static void StaticSet(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); + + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, key); + V8_ARG_TO_MVALUE(2, val); + + resource->GetLocalStorage()->Set(key, val); +} + +static void StaticDelete(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, key); + + resource->GetLocalStorage()->Delete(key); +} + +static void StaticClear(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); - V8_RETURN(static_cast(resource)->GetLocalStorage()); + resource->GetLocalStorage()->Clear(); +} + +static void StaticSave(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT_IRESOURCE(); + + V8_CHECK(resource->GetLocalStorage()->Save(), "exceeded max local storage size (4MB)"); } static void Get(const v8::FunctionCallbackInfo &info) @@ -20,6 +66,8 @@ static void Get(const v8::FunctionCallbackInfo &info) V8_ARG_TO_STRING(1, key); V8_RETURN(V8Helpers::MValueToV8(resource->GetLocalStorage()->Get(key))); + + Log::Warning << "Using the local storage instance methods is deprecated. Use the static methods instead." << Log::Endl; } static void Set(const v8::FunctionCallbackInfo &info) @@ -32,6 +80,8 @@ static void Set(const v8::FunctionCallbackInfo &info) V8_ARG_TO_MVALUE(2, val); resource->GetLocalStorage()->Set(key, val); + + Log::Warning << "Using the local storage instance methods is deprecated. Use the static methods instead." << Log::Endl; } static void Delete(const v8::FunctionCallbackInfo &info) @@ -42,6 +92,8 @@ static void Delete(const v8::FunctionCallbackInfo &info) V8_ARG_TO_STRING(1, key); resource->GetLocalStorage()->Delete(key); + + Log::Warning << "Using the local storage instance methods is deprecated. Use the static methods instead." << Log::Endl; } static void Clear(const v8::FunctionCallbackInfo &info) @@ -49,6 +101,8 @@ static void Clear(const v8::FunctionCallbackInfo &info) V8_GET_ISOLATE_CONTEXT_IRESOURCE(); resource->GetLocalStorage()->Clear(); + + Log::Warning << "Using the local storage instance methods is deprecated. Use the static methods instead." << Log::Endl; } static void Save(const v8::FunctionCallbackInfo &info) @@ -56,17 +110,24 @@ static void Save(const v8::FunctionCallbackInfo &info) V8_GET_ISOLATE_CONTEXT_IRESOURCE(); V8_CHECK(resource->GetLocalStorage()->Save(), "exceeded max local storage size (4MB)"); + + Log::Warning << "Using the local storage instance methods is deprecated. Use the static methods instead." << Log::Endl; } extern V8Class v8LocalStorage("LocalStorage", nullptr, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); - - V8::SetStaticMethod(isolate, tpl, "get", &StaticGet); - - V8::SetMethod(isolate, tpl, "get", &Get); - V8::SetMethod(isolate, tpl, "set", &Set); - V8::SetMethod(isolate, tpl, "delete", &Delete); - V8::SetMethod(isolate, tpl, "deleteAll", &Clear); - V8::SetMethod(isolate, tpl, "clear", &Clear); - V8::SetMethod(isolate, tpl, "save", &Save); - }); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8::SetStaticMethod(isolate, tpl, "get", &StaticGet); + V8::SetStaticMethod(isolate, tpl, "set", &StaticSet); + V8::SetStaticMethod(isolate, tpl, "delete", &StaticDelete); + V8::SetStaticMethod(isolate, tpl, "deleteAll", &StaticClear); + V8::SetStaticMethod(isolate, tpl, "clear", &StaticClear); + V8::SetStaticMethod(isolate, tpl, "save", &StaticSave); + + V8::SetMethod(isolate, tpl, "get", &Get); + V8::SetMethod(isolate, tpl, "set", &Set); + V8::SetMethod(isolate, tpl, "delete", &Delete); + V8::SetMethod(isolate, tpl, "deleteAll", &Clear); + V8::SetMethod(isolate, tpl, "clear", &Clear); + V8::SetMethod(isolate, tpl, "save", &Save); +}); From 4eade72da027da6bb6ad06d2c198b30ebe8e5613 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 10 Apr 2021 02:50:06 +0200 Subject: [PATCH 313/564] Add generic event handler --- src/CV8Resource.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 2415f339..374918dd 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -218,6 +218,31 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent* e) if (!handler) return true; + // Generic event handler + { + auto evType = e->GetType(); + if(evType == alt::CEvent::Type::CLIENT_SCRIPT_EVENT || evType == alt::CEvent::Type::SERVER_SCRIPT_EVENT) + { + std::vector callbacks; + auto args = handler->GetArgs(this, e); + if(evType == alt::CEvent::Type::CLIENT_SCRIPT_EVENT) + { + callbacks = GetLocalHandlers("*"); + args.insert(args.begin(), V8_NEW_STRING(static_cast(e)->GetName().CStr())); + } + else if(evType == alt::CEvent::Type::SERVER_SCRIPT_EVENT) + { + callbacks = GetRemoteHandlers("*"); + args.insert(args.begin(), V8_NEW_STRING(static_cast(e)->GetName().CStr())); + } + + if(callbacks.size() != 0) + { + InvokeEventHandlers(e, callbacks, args); + } + } + } + std::vector callbacks = handler->GetCallbacks(this, e); if (callbacks.size() > 0) { From 509136dfce2c729b5aa5851e87904461b6eeae69 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 10 Apr 2021 03:03:00 +0200 Subject: [PATCH 314/564] Improve generic event handler code --- src/CV8Resource.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 374918dd..327b801d 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -224,20 +224,26 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent* e) if(evType == alt::CEvent::Type::CLIENT_SCRIPT_EVENT || evType == alt::CEvent::Type::SERVER_SCRIPT_EVENT) { std::vector callbacks; - auto args = handler->GetArgs(this, e); + std::vector> args; + const char* eventName; if(evType == alt::CEvent::Type::CLIENT_SCRIPT_EVENT) { callbacks = GetLocalHandlers("*"); - args.insert(args.begin(), V8_NEW_STRING(static_cast(e)->GetName().CStr())); + eventName = static_cast(e)->GetName().CStr(); } else if(evType == alt::CEvent::Type::SERVER_SCRIPT_EVENT) { callbacks = GetRemoteHandlers("*"); - args.insert(args.begin(), V8_NEW_STRING(static_cast(e)->GetName().CStr())); + eventName = static_cast(e)->GetName().CStr(); } - + if(callbacks.size() != 0) { + auto evArgs = handler->GetArgs(this, e); + args.reserve(evArgs.size() + 1); + args.push_back(V8_NEW_STRING(eventName)); + args.insert(args.end(), evArgs.begin(), evArgs.end()); + InvokeEventHandlers(e, callbacks, args); } } From 06fbf98531fd1fd0dbb389c08b83c52b30d0a188 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 10 Apr 2021 13:31:34 +0200 Subject: [PATCH 315/564] Don't copy into new array --- src/CV8Resource.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 327b801d..4e4d4a17 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -224,8 +224,8 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent* e) if(evType == alt::CEvent::Type::CLIENT_SCRIPT_EVENT || evType == alt::CEvent::Type::SERVER_SCRIPT_EVENT) { std::vector callbacks; - std::vector> args; const char* eventName; + if(evType == alt::CEvent::Type::CLIENT_SCRIPT_EVENT) { callbacks = GetLocalHandlers("*"); @@ -240,11 +240,9 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent* e) if(callbacks.size() != 0) { auto evArgs = handler->GetArgs(this, e); - args.reserve(evArgs.size() + 1); - args.push_back(V8_NEW_STRING(eventName)); - args.insert(args.end(), evArgs.begin(), evArgs.end()); + evArgs.insert(evArgs.begin(), V8_NEW_STRING(eventName)); - InvokeEventHandlers(e, callbacks, args); + InvokeEventHandlers(e, callbacks, evArgs); } } } From 63c4996ca470317802fdba4e0c46b685f694aaef Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 11 Apr 2021 16:14:18 +0200 Subject: [PATCH 316/564] Move instead of copy --- src/CV8Resource.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 4e4d4a17..b8489642 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -228,12 +228,12 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent* e) if(evType == alt::CEvent::Type::CLIENT_SCRIPT_EVENT) { - callbacks = GetLocalHandlers("*"); + callbacks = std::move(GetLocalHandlers("*")); eventName = static_cast(e)->GetName().CStr(); } else if(evType == alt::CEvent::Type::SERVER_SCRIPT_EVENT) { - callbacks = GetRemoteHandlers("*"); + callbacks = std::move(GetRemoteHandlers("*")); eventName = static_cast(e)->GetName().CStr(); } From 51619ac2454e836e6bf4e3792678712a8fe0f89b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 12 Apr 2021 14:07:01 +0200 Subject: [PATCH 317/564] Add generic event handler --- V8ResourceImpl.cpp | 11 ++++++++++ V8ResourceImpl.h | 18 ++++++++++++++++ bindings/Main.cpp | 51 +++++++++++++++++++++++++++++++++++----------- 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 672e610f..623ee180 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -262,6 +262,17 @@ std::vector V8ResourceImpl::GetRemoteHandlers(const std::st return handlers; } +std::vector V8ResourceImpl::GetGenericHandlers(bool local) +{ + std::vector handlers; + auto range = genericHandlers.equal_range(local); + + for (auto it = range.first; it != range.second; ++it) + handlers.push_back(&it->second); + + return handlers; +} + void V8ResourceImpl::InvokeEventHandlers(const alt::CEvent *ev, const std::vector &handlers, std::vector> &args) { for (auto handler : handlers) diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index e1a612df..39d31285 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -61,6 +61,11 @@ class V8ResourceImpl : public alt::IResource::Impl remoteHandlers.insert({ev, V8::EventCallback{isolate, cb, std::move(location), once}}); } + void SubscribeGeneric(bool local, v8::Local cb, V8::SourceLocation &&location, bool once = false) + { + genericHandlers.insert({local, V8::EventCallback{isolate, cb, std::move(location), once}}); + } + void UnsubscribeLocal(const std::string &ev, v8::Local cb) { auto range = localHandlers.equal_range(ev); @@ -83,6 +88,17 @@ class V8ResourceImpl : public alt::IResource::Impl } } + void UnsubscribeGeneric(bool local, v8::Local cb) + { + auto range = genericHandlers.equal_range(local); + + for (auto it = range.first; it != range.second; ++it) + { + if (it->second.fn.Get(isolate)->StrictEquals(cb)) + it->second.removed = true; + } + } + void DispatchStartEvent(bool error) { std::vector> args; @@ -183,6 +199,7 @@ class V8ResourceImpl : public alt::IResource::Impl std::vector GetLocalHandlers(const std::string &name); std::vector GetRemoteHandlers(const std::string &name); + std::vector GetGenericHandlers(bool local); static V8ResourceImpl *Get(v8::Local ctx) { @@ -208,6 +225,7 @@ class V8ResourceImpl : public alt::IResource::Impl std::unordered_multimap localHandlers; std::unordered_multimap remoteHandlers; + std::unordered_multimap genericHandlers; uint32_t nextTimerId = 0; std::vector oldTimers; diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 29bdcea3..ac2d035b 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -16,33 +16,60 @@ static void On(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_STRING(1, evName); - V8_ARG_TO_FUNCTION(2, callback); + V8_CHECK_ARGS_LEN2(1, 2); + if(info.Length() == 1) + { + V8_ARG_TO_FUNCTION(1, callback); + + resource->SubscribeGeneric(true, callback, V8::SourceLocation::GetCurrent(isolate)); + } + else if(info.Length() == 2) + { + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, callback); - resource->SubscribeLocal(evName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate)); + resource->SubscribeLocal(evName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate)); + } } static void Once(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_STRING(1, evName); - V8_ARG_TO_FUNCTION(2, callback); + V8_CHECK_ARGS_LEN2(1, 2); + if(info.Length() == 1) + { + V8_ARG_TO_FUNCTION(1, callback); + + resource->SubscribeGeneric(true, callback, V8::SourceLocation::GetCurrent(isolate), true); + } + else if(info.Length() == 2) + { + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, callback); - resource->SubscribeLocal(evName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate), true); + resource->SubscribeLocal(evName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate), true); + } } static void Off(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_STRING(1, evName); - V8_ARG_TO_FUNCTION(2, callback); + V8_CHECK_ARGS_LEN2(1, 2); + if(info.Length() == 1) + { + V8_ARG_TO_FUNCTION(1, callback); - resource->UnsubscribeLocal(evName.ToString(), callback); + resource->UnsubscribeGeneric(true, callback); + } + else if(info.Length() == 2) + { + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, callback); + + resource->UnsubscribeLocal(evName.ToString(), callback); + } } static void Emit(const v8::FunctionCallbackInfo &info) From c66c9009f96c91a5a0a787eb961903db19a204e9 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 12 Apr 2021 14:31:35 +0200 Subject: [PATCH 318/564] Use vectors instead of multimap --- V8ResourceImpl.cpp | 19 ++++++++++++++----- V8ResourceImpl.h | 30 ++++++++++++++++++++++-------- bindings/Main.cpp | 6 +++--- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 623ee180..e54ee758 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -265,11 +265,20 @@ std::vector V8ResourceImpl::GetRemoteHandlers(const std::st std::vector V8ResourceImpl::GetGenericHandlers(bool local) { std::vector handlers; - auto range = genericHandlers.equal_range(local); - - for (auto it = range.first; it != range.second; ++it) - handlers.push_back(&it->second); - + if(local) + { + for(auto& it : localGenericHandlers) + { + handlers.push_back(&it); + } + } + else + { + for(auto& it : remoteGenericHandlers) + { + handlers.push_back(&it); + } + } return handlers; } diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index 39d31285..f58b87de 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -61,9 +61,14 @@ class V8ResourceImpl : public alt::IResource::Impl remoteHandlers.insert({ev, V8::EventCallback{isolate, cb, std::move(location), once}}); } - void SubscribeGeneric(bool local, v8::Local cb, V8::SourceLocation &&location, bool once = false) + void SubscribeGenericLocal(v8::Local cb, V8::SourceLocation &&location, bool once = false) { - genericHandlers.insert({local, V8::EventCallback{isolate, cb, std::move(location), once}}); + localGenericHandlers.push_back(V8::EventCallback{isolate, cb, std::move(location), once}); + } + + void SubscribeGenericRemote(v8::Local cb, V8::SourceLocation &&location, bool once = false) + { + remoteGenericHandlers.push_back(V8::EventCallback{isolate, cb, std::move(location), once}); } void UnsubscribeLocal(const std::string &ev, v8::Local cb) @@ -88,14 +93,21 @@ class V8ResourceImpl : public alt::IResource::Impl } } - void UnsubscribeGeneric(bool local, v8::Local cb) + void UnsubscribeGenericLocal(v8::Local cb) { - auto range = genericHandlers.equal_range(local); + for (auto& it : localGenericHandlers) + { + if (it.fn.Get(isolate)->StrictEquals(cb)) + it.removed = true; + } + } - for (auto it = range.first; it != range.second; ++it) + void UnsubscribeGenericRemote(v8::Local cb) + { + for (auto& it : localGenericHandlers) { - if (it->second.fn.Get(isolate)->StrictEquals(cb)) - it->second.removed = true; + if (it.fn.Get(isolate)->StrictEquals(cb)) + it.removed = true; } } @@ -225,7 +237,9 @@ class V8ResourceImpl : public alt::IResource::Impl std::unordered_multimap localHandlers; std::unordered_multimap remoteHandlers; - std::unordered_multimap genericHandlers; + std::vector localGenericHandlers; + std::vector remoteGenericHandlers; + uint32_t nextTimerId = 0; std::vector oldTimers; diff --git a/bindings/Main.cpp b/bindings/Main.cpp index ac2d035b..0e75d3a3 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -21,7 +21,7 @@ static void On(const v8::FunctionCallbackInfo &info) { V8_ARG_TO_FUNCTION(1, callback); - resource->SubscribeGeneric(true, callback, V8::SourceLocation::GetCurrent(isolate)); + resource->SubscribeGenericLocal(callback, V8::SourceLocation::GetCurrent(isolate)); } else if(info.Length() == 2) { @@ -41,7 +41,7 @@ static void Once(const v8::FunctionCallbackInfo& info) { V8_ARG_TO_FUNCTION(1, callback); - resource->SubscribeGeneric(true, callback, V8::SourceLocation::GetCurrent(isolate), true); + resource->SubscribeGenericLocal(callback, V8::SourceLocation::GetCurrent(isolate), true); } else if(info.Length() == 2) { @@ -61,7 +61,7 @@ static void Off(const v8::FunctionCallbackInfo &info) { V8_ARG_TO_FUNCTION(1, callback); - resource->UnsubscribeGeneric(true, callback); + resource->UnsubscribeGenericLocal(callback); } else if(info.Length() == 2) { From f2fafd3287fa7b43ecdf69620a4a8603cf562245 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 12 Apr 2021 15:00:41 +0200 Subject: [PATCH 319/564] Update for new helpers --- src/CV8Resource.cpp | 4 ++-- src/bindings/Main.cpp | 51 +++++++++++++++++++++++++++++++++---------- src/helpers | 2 +- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index b8489642..faabf9d1 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -228,12 +228,12 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent* e) if(evType == alt::CEvent::Type::CLIENT_SCRIPT_EVENT) { - callbacks = std::move(GetLocalHandlers("*")); + callbacks = std::move(GetGenericHandlers(true)); eventName = static_cast(e)->GetName().CStr(); } else if(evType == alt::CEvent::Type::SERVER_SCRIPT_EVENT) { - callbacks = std::move(GetRemoteHandlers("*")); + callbacks = std::move(GetGenericHandlers(false)); eventName = static_cast(e)->GetName().CStr(); } diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 56500efa..019c08ac 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -12,34 +12,61 @@ using namespace alt; static void OnServer(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN2(1, 2); - V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_STRING(1, eventName); - V8_ARG_TO_FUNCTION(2, callback); + if(info.Length() == 1) + { + V8_ARG_TO_FUNCTION(1, callback); + + resource->SubscribeGenericRemote(callback, V8::SourceLocation::GetCurrent(isolate)); + } + else if(info.Length() == 2) + { + V8_ARG_TO_STRING(1, eventName); + V8_ARG_TO_FUNCTION(2, callback); - resource->SubscribeRemote(eventName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate)); + resource->SubscribeRemote(eventName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate)); + } } static void OnceServer(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN2(1, 2); - V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_STRING(1, eventName); - V8_ARG_TO_FUNCTION(2, callback); + if(info.Length() == 1) + { + V8_ARG_TO_FUNCTION(1, callback); - resource->SubscribeRemote(eventName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate), true); + resource->SubscribeGenericRemote(callback, V8::SourceLocation::GetCurrent(isolate), true); + } + else if(info.Length() == 2) + { + V8_ARG_TO_STRING(1, eventName); + V8_ARG_TO_FUNCTION(2, callback); + + resource->SubscribeRemote(eventName.ToString(), callback, V8::SourceLocation::GetCurrent(isolate), true); + } } static void OffServer(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN2(1, 2); - V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_STRING(1, eventName); - V8_ARG_TO_FUNCTION(2, callback); + if(info.Length() == 1) + { + V8_ARG_TO_FUNCTION(1, callback); - resource->UnsubscribeRemote(eventName.ToString(), callback); + resource->UnsubscribeGenericRemote(callback); + } + else if(info.Length() == 2) + { + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, callback); + + resource->UnsubscribeRemote(evName.ToString(), callback); + } } static void EmitServer(const v8::FunctionCallbackInfo &info) diff --git a/src/helpers b/src/helpers index 5b77373e..c66c9009 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 5b77373e038660d868f0aece68b8f3600d7be2db +Subproject commit c66c9009f96c91a5a0a787eb961903db19a204e9 From 0640d55f8ee1e210f8618c7cc00d2e21dda61e19 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 14 Apr 2021 00:38:09 +0200 Subject: [PATCH 320/564] Add get event listeners methods --- bindings/Main.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index e765a057..055060ed 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -301,6 +301,58 @@ static void HasResource(const v8::FunctionCallbackInfo& info) V8_RETURN_BOOLEAN(resource && resource->IsStarted()); } +static void GetEventListeners(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + std::vector handlers; + + if(info[0]->IsNull()) + { + handlers = resource->GetGenericHandlers(true); + } + else + { + V8_ARG_TO_STRING(1, eventName); + handlers = resource->GetLocalHandlers(eventName.ToString()); + } + + auto array = v8::Array::New(isolate, handlers.size()); + for(int i = 0; i < handlers.size(); i++) + { + array->Set(ctx, i, handlers[i]->fn.Get(isolate)); + } + + V8_RETURN(array); +} + +static void GetRemoteEventListeners(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + + std::vector handlers; + + if(info[0]->IsNull()) + { + handlers = resource->GetGenericHandlers(false); + } + else + { + V8_ARG_TO_STRING(1, eventName); + handlers = resource->GetRemoteHandlers(eventName.ToString()); + } + + auto array = v8::Array::New(isolate, handlers.size()); + for(int i = 0; i < handlers.size(); i++) + { + array->Set(ctx, i, handlers[i]->fn.Get(isolate)); + } + + V8_RETURN(array); +} + void V8::RegisterSharedMain(v8::Local ctx, v8::Local exports) { v8::Isolate *isolate = ctx->GetIsolate(); @@ -316,6 +368,9 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8Helpers::RegisterFunc(exports, "off", &Off); V8Helpers::RegisterFunc(exports, "emit", &Emit); + V8Helpers::RegisterFunc(exports, "getEventListeners", &GetEventListeners); + V8Helpers::RegisterFunc(exports, "getRemoteEventListeners", &GetRemoteEventListeners); + V8Helpers::RegisterFunc(exports, "hasMeta", &HasMeta); V8Helpers::RegisterFunc(exports, "getMeta", &GetMeta); V8Helpers::RegisterFunc(exports, "setMeta", &SetMeta); From 49a95f237b34ae64cb68139a2a0c532512ef98d4 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 14 Apr 2021 00:50:42 +0200 Subject: [PATCH 321/564] Add get event listeners to webview and websocketclient --- src/bindings/WebSocketClient.cpp | 20 ++++++++++++++++++++ src/bindings/WebView.cpp | 20 ++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index c9014340..a674501f 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -161,6 +161,25 @@ static void GetExtraHeaders(const v8::FunctionCallbackInfo& info) V8_RETURN(headersObject); } +static void GetEventListeners(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); + + V8_ARG_TO_STRING(1, eventName); + + std::vector handlers = static_cast(resource)->GetWebSocketClientHandlers(webSocket, eventName.ToString()); + + auto array = v8::Array::New(isolate, handlers.size()); + for(int i = 0; i < handlers.size(); i++) + { + array->Set(ctx, i, handlers[i]->fn.Get(isolate)); + } + + V8_RETURN(array); +} + static void URLGetter(v8::Local property, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); @@ -256,6 +275,7 @@ extern V8Class v8WebSocketClient("WebSocketClient", v8BaseObject, &Constructor, V8::SetMethod(isolate, tpl, "on", &On); V8::SetMethod(isolate, tpl, "off", &Off); + V8::SetMethod(isolate, tpl, "getEventListeners", GetEventListeners); V8::SetMethod(isolate, tpl, "start", &Start); V8::SetMethod(isolate, tpl, "send", &Send); diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index 66bb12f0..94c4a8fa 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -82,16 +82,23 @@ static void Unfocus(const v8::FunctionCallbackInfo &info) view->Unfocus(); } -static void SetURL(const v8::FunctionCallbackInfo &info) +static void GetEventListeners(const v8::FunctionCallbackInfo& info) { - V8_GET_ISOLATE_CONTEXT(); - + V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_STRING(1, url); - V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - view->SetUrl(url); + V8_ARG_TO_STRING(1, eventName); + + std::vector handlers = static_cast(resource)->GetWebViewHandlers(view, eventName.ToString()); + + auto array = v8::Array::New(isolate, handlers.size()); + for(int i = 0; i < handlers.size(); i++) + { + array->Set(ctx, i, handlers[i]->fn.Get(isolate)); + } + + V8_RETURN(array); } static void IsVisibleGetter(v8::Local property, const v8::PropertyCallbackInfo &info) @@ -218,6 +225,7 @@ extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local Date: Wed, 14 Apr 2021 13:53:58 +0200 Subject: [PATCH 322/564] Move instead of copy --- bindings/Main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 055060ed..73b4162e 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -310,12 +310,12 @@ static void GetEventListeners(const v8::FunctionCallbackInfo& info) if(info[0]->IsNull()) { - handlers = resource->GetGenericHandlers(true); + handlers = std::move(resource->GetGenericHandlers(true)); } else { V8_ARG_TO_STRING(1, eventName); - handlers = resource->GetLocalHandlers(eventName.ToString()); + handlers = std::move(resource->GetLocalHandlers(eventName.ToString())); } auto array = v8::Array::New(isolate, handlers.size()); @@ -336,12 +336,12 @@ static void GetRemoteEventListeners(const v8::FunctionCallbackInfo& i if(info[0]->IsNull()) { - handlers = resource->GetGenericHandlers(false); + handlers = std::move(resource->GetGenericHandlers(false)); } else { V8_ARG_TO_STRING(1, eventName); - handlers = resource->GetRemoteHandlers(eventName.ToString()); + handlers = std::move(resource->GetRemoteHandlers(eventName.ToString())); } auto array = v8::Array::New(isolate, handlers.size()); From 6124b76e4a0be0f25d4e49ac537332640dc39001 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 15 Apr 2021 19:25:11 +0200 Subject: [PATCH 323/564] Move IsObject check down in if else chain --- src/bindings/V8Natives.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index cad28d96..14b3e47a 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -77,12 +77,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a break; case alt::INative::Type::ARG_INT32: { - V8Entity* ent; - if (val->IsObject() && (ent = V8Entity::Get(val)) != nullptr) - { - scrCtx->Push(ent->GetHandle().As()->GetScriptGuid()); - } - else if (val->IsUint32() || val->IsInt32()) + if (val->IsUint32() || val->IsInt32()) { v8::Local value; if (val->ToInteger(v8Ctx).ToLocal(&value)) @@ -106,6 +101,11 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a Log::Error << "Unknown native arg type" << (int)argType; } } + else if (val->IsObject()) + { + auto ent = V8Entity::Get(val); + if(ent != nullptr) scrCtx->Push(ent->GetHandle().As()->GetScriptGuid()); + } else { Log::Error << "Unknown native arg type" << (int)argType; From 0ed9c90531458553f870b6978993dac6d890160f Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 16 Apr 2021 18:40:45 +0200 Subject: [PATCH 324/564] Add code import to imports --- src/CV8Resource.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 2415f339..2c866df3 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -46,7 +46,8 @@ static void StaticRequire(const v8::FunctionCallbackInfo &info) V8Helpers::Throw(isolate, "No such module " + name); } -void CV8ResourceImpl::ProcessDynamicImports() { +void CV8ResourceImpl::ProcessDynamicImports() +{ for(auto import : dynamicImports) { import(); @@ -597,6 +598,11 @@ v8::MaybeLocal CV8ResourceImpl::ResolveModule(const std::string &_na maybeModule = ResolveFile(name, referrer); } + if(maybeModule.IsEmpty()) + { + maybeModule = CompileESM(isolate, "[import]", name); + } + if (maybeModule.IsEmpty()) { modules.erase(name); From 67afb99be51c4d650cf2beef173f3938f5eaa21b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 16 Apr 2021 19:53:21 +0200 Subject: [PATCH 325/564] Use map instead of vector --- src/CV8ScriptRuntime.cpp | 8 ++++---- src/CV8ScriptRuntime.h | 8 ++++---- src/bindings/Player.cpp | 6 ++++-- src/bindings/Vehicle.cpp | 6 ++++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index ed2a0e97..98cfc67f 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -160,12 +160,12 @@ void CV8ScriptRuntime::OnEntityStreamIn(alt::Ref entity) { case alt::IEntity::Type::PLAYER: { - streamedInPlayers.push_back(entity.As()); + streamedInPlayers.insert({ entity->GetID(), entity.As() }); break; } case alt::IEntity::Type::VEHICLE: { - streamedInVehicles.push_back(entity.As()); + streamedInVehicles.insert({ entity->GetID(), entity.As() }); break; } } @@ -177,12 +177,12 @@ void CV8ScriptRuntime::OnEntityStreamOut(alt::Ref entity) { case alt::IEntity::Type::PLAYER: { - streamedInPlayers.erase(std::find(streamedInPlayers.begin(), streamedInPlayers.end(), entity)); + streamedInPlayers.erase(entity->GetID()); break; } case alt::IEntity::Type::VEHICLE: { - streamedInVehicles.erase(std::find(streamedInVehicles.begin(), streamedInVehicles.end(), entity)); + streamedInVehicles.erase(entity->GetID()); break; } } diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 0cceb1eb..abc88527 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -22,8 +22,8 @@ class CV8ScriptRuntime : public alt::IScriptRuntime std::unique_ptr inspector; std::unique_ptr inspectorSession; - std::vector> streamedInPlayers; - std::vector> streamedInVehicles; + std::unordered_map> streamedInPlayers; + std::unordered_map> streamedInVehicles; public: static CV8ScriptRuntime* instance; @@ -170,11 +170,11 @@ class CV8ScriptRuntime : public alt::IScriptRuntime void OnEntityStreamIn(alt::Ref entity); void OnEntityStreamOut(alt::Ref entity); - std::vector> GetStreamedInPlayers() + auto GetStreamedInPlayers() { return streamedInPlayers; } - std::vector> GetStreamedInVehicles() + auto GetStreamedInVehicles() { return streamedInVehicles; } diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 0a93c49a..ec09c42c 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -304,9 +304,11 @@ static void StreamedInGetter(v8::Local name, const v8::PropertyCallb auto streamedIn = CV8ScriptRuntime::instance->GetStreamedInPlayers(); auto arr = v8::Array::New(isolate, streamedIn.size()); - for(auto i = 0; i < streamedIn.size(); i++) + int i = 0; + for(auto kv : streamedIn) { - arr->Set(ctx, i, resource->GetOrCreateEntity(streamedIn[i].Get(), "Player")->GetJSVal(isolate)); + arr->Set(ctx, i, resource->GetOrCreateEntity(kv.second.Get(), "Player")->GetJSVal(isolate)); + i++; } V8_RETURN(arr); diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 52daee0b..56e5121e 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -531,9 +531,11 @@ static void StreamedInGetter(v8::Local name, const v8::PropertyCallb auto streamedIn = CV8ScriptRuntime::instance->GetStreamedInVehicles(); auto arr = v8::Array::New(isolate, streamedIn.size()); - for(auto i = 0; i < streamedIn.size(); i++) + int i = 0; + for(auto kv : streamedIn) { - arr->Set(ctx, i, resource->GetOrCreateEntity(streamedIn[i].Get(), "Vehicle")->GetJSVal(isolate)); + arr->Set(ctx, i, resource->GetOrCreateEntity(kv.second.Get(), "Vehicle")->GetJSVal(isolate)); + i++; } V8_RETURN(arr); From ccae2cf73146b4667010c68cd2d97594c5f65c92 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 16 Apr 2021 22:08:40 +0200 Subject: [PATCH 326/564] Add evalModule method --- src/CV8Resource.cpp | 16 +++++++++++----- src/CV8Resource.h | 1 + src/bindings/Main.cpp | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 2c866df3..e74bfd0a 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -140,6 +140,7 @@ bool CV8ResourceImpl::Start() ctx->Global()->Set(ctx, V8_NEW_STRING("clearTimeout"), exports->Get(ctx, V8_NEW_STRING("clearTimeout")).ToLocalChecked()); ctx->Global()->Set(ctx, v8::String::NewFromUtf8(isolate, "__internal_get_exports").ToLocalChecked(), v8::Function::New(ctx, &StaticRequire).ToLocalChecked()); + bool res = curModule->InstantiateModule(ctx, CV8ScriptRuntime::ResolveModule).IsJust(); if (!res) @@ -598,11 +599,6 @@ v8::MaybeLocal CV8ResourceImpl::ResolveModule(const std::string &_na maybeModule = ResolveFile(name, referrer); } - if(maybeModule.IsEmpty()) - { - maybeModule = CompileESM(isolate, "[import]", name); - } - if (maybeModule.IsEmpty()) { modules.erase(name); @@ -620,3 +616,13 @@ v8::MaybeLocal CV8ResourceImpl::ResolveModule(const std::string &_na return maybeModule; } + +v8::MaybeLocal CV8ResourceImpl::ResolveCode(const std::string& code, const V8::SourceLocation& location) +{ + v8::MaybeLocal maybeModule; + std::stringstream name; + name << "[module " << location.GetFileName() << ":" << location.GetLineNumber() << "]"; + maybeModule = CompileESM(isolate, name.str(), code); + + return maybeModule; +} diff --git a/src/CV8Resource.h b/src/CV8Resource.h index 26c36727..00e8bfd5 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -122,6 +122,7 @@ class CV8ResourceImpl : public V8ResourceImpl v8::MaybeLocal Require(const std::string &name); v8::MaybeLocal ResolveFile(const std::string &name, v8::Local referrer); v8::MaybeLocal ResolveModule(const std::string &name, v8::Local referrer); + v8::MaybeLocal ResolveCode(const std::string& code, const V8::SourceLocation& location); private: using WebViewEvents = std::unordered_multimap; diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 56500efa..63309071 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -711,6 +711,38 @@ static void LoadModelAsync(const v8::FunctionCallbackInfo& info) Log::Warning << "loadModelAsync is deprecated and it will be removed in the future. Please use the native requestModel." << Log::Endl; } +static void EvalModule(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_STRING(1, code); + + auto maybeModule = static_cast(resource)->ResolveCode(code.ToString(), V8::SourceLocation::GetCurrent(isolate)); + if(maybeModule.IsEmpty()) + { + V8Helpers::Throw(isolate, "Failed to resolve module"); + return; + } + + auto module = maybeModule.ToLocalChecked(); + v8::Maybe result = module->InstantiateModule(ctx, CV8ScriptRuntime::ResolveModule); + if(result.IsNothing() || result.ToChecked() == false) + { + V8Helpers::Throw(isolate, "Failed to instantiate module"); + return; + } + + auto returnValue = module->Evaluate(ctx); + if(returnValue.IsEmpty()) + { + V8Helpers::Throw(isolate, "Failed to evaluate module"); + return; + } + + V8_RETURN(module->GetModuleNamespace()); +} + extern V8Class v8Vector3, v8Vector2, v8RGBA, @@ -842,4 +874,6 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "loadYtyp", &LoadYtyp); V8Helpers::RegisterFunc(exports, "unloadYtyp", &UnloadYtyp); + + V8Helpers::RegisterFunc(exports, "evalModule", &EvalModule); }); From f76871de180003494941fedd226c414bd844ff01 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 16 Apr 2021 22:13:54 +0200 Subject: [PATCH 327/564] Fixed log functions causing a crash in rare situations --- bindings/Main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index e765a057..2c0f04f5 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -163,7 +163,8 @@ static void Log(const v8::FunctionCallbackInfo &info) if (i > 0) ss << " "; - v8::Local str = val->ToString(ctx).ToLocalChecked(); + v8::Local str; + if(!val->ToString(ctx).ToLocal(&str)) continue; if (val->IsObject() && strcmp(*v8::String::Utf8Value(isolate, str), "[object Object]") == 0) { v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); v8::Local stringified; @@ -191,7 +192,8 @@ static void LogWarning(const v8::FunctionCallbackInfo &info) if (i > 0) ss << " "; - v8::Local str = val->ToString(ctx).ToLocalChecked(); + v8::Local str; + if(!val->ToString(ctx).ToLocal(&str)) continue; if (val->IsObject() && strcmp(*v8::String::Utf8Value(isolate, str), "[object Object]") == 0) { v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); v8::Local stringified; @@ -219,7 +221,8 @@ static void LogError(const v8::FunctionCallbackInfo &info) if (i > 0) ss << " "; - v8::Local str = val->ToString(ctx).ToLocalChecked(); + v8::Local str; + if(!val->ToString(ctx).ToLocal(&str)) continue; if (val->IsObject() && strcmp(*v8::String::Utf8Value(isolate, str), "[object Object]") == 0) { v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); v8::Local stringified; From 64e9f42334cc97968405c792db2e8ac6acc58322 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 17 Apr 2021 17:31:05 +0200 Subject: [PATCH 328/564] Add timers command --- src/main.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b899560e..ee7e477a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,13 @@ static void HeapCommand(alt::Array, void* runtime) static void TimersCommand(alt::Array, void* runtime) { - // TODO: Add timers command + auto resources = static_cast(runtime)->GetResources(); + Log::Info << "================ Timer info =================" << Log::Endl; + for(auto resource : resources) + { + Log::Info << resource->GetResource()->GetName() << ": " << resource->GetTimersCount() << " running timers"; + } + Log::Info << "======================================================" << Log::Endl; } ALTV_JS_EXPORT void CreateScriptRuntime(alt::ICore *core) From 3e5c6cc172b212d4ea2d1b75b00893ae28595f7f Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 18 Apr 2021 15:11:23 +0200 Subject: [PATCH 329/564] Add once event handlers to WebView --- src/CV8Resource.h | 4 ++-- src/bindings/WebView.cpp | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/CV8Resource.h b/src/CV8Resource.h index 00e8bfd5..32a737fe 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -38,9 +38,9 @@ class CV8ResourceImpl : public V8ResourceImpl void OnPromiseRejectedWithNoHandler(v8::PromiseRejectMessage &data); void OnPromiseHandlerAdded(v8::PromiseRejectMessage &data); - void SubscribeWebView(alt::Ref view, const std::string &evName, v8::Local cb, V8::SourceLocation &&location) + void SubscribeWebView(alt::Ref view, const std::string &evName, v8::Local cb, V8::SourceLocation &&location, bool once = false) { - webViewHandlers[view].insert({evName, V8::EventCallback{isolate, cb, std::move(location)}}); + webViewHandlers[view].insert({evName, V8::EventCallback{isolate, cb, std::move(location), once}}); } void UnsubscribeWebView(alt::Ref view, const std::string &evName, v8::Local cb) diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index 66bb12f0..352c5005 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -12,8 +12,8 @@ static void ToString(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); - auto webview = info.This(); - V8_OBJECT_GET_STRING(webview, "url", url); + auto webview = info.This(); + V8_OBJECT_GET_STRING(webview, "url", url); std::ostringstream ss; ss << "WebView{ url: " << url.CStr() << " }"; @@ -34,6 +34,19 @@ static void On(const v8::FunctionCallbackInfo &info) static_cast(resource)->SubscribeWebView(view, evName.ToString(), fun, V8::SourceLocation::GetCurrent(isolate)); } +static void Once(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, fun); + + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); + + static_cast(resource)->SubscribeWebView(view, evName.ToString(), fun, V8::SourceLocation::GetCurrent(isolate), true); +} + static void Off(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -217,6 +230,7 @@ extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local Date: Sun, 18 Apr 2021 15:19:35 +0200 Subject: [PATCH 330/564] Clear removed generic handlers --- V8ResourceImpl.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index e54ee758..7f8e8ccd 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -79,6 +79,16 @@ void V8ResourceImpl::OnTick() ++it; } + for (auto it = localGenericHandlers.begin(); it != localGenericHandlers.end(); it++) + { + if (it->removed) localGenericHandlers.erase(it); + } + + for (auto it = remoteGenericHandlers.begin(); it != remoteGenericHandlers.end(); it++) + { + if (it->removed) remoteGenericHandlers.erase(it); + } + promiseRejections.ProcessQueue(this); } From c01b2a62ef3ffd5bfa16339cd69f26114556c373 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 19 Apr 2021 21:57:50 +0200 Subject: [PATCH 331/564] Check args length in local storage get method --- src/bindings/LocalStorage.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bindings/LocalStorage.cpp b/src/bindings/LocalStorage.cpp index 78d79b79..4b2b059b 100644 --- a/src/bindings/LocalStorage.cpp +++ b/src/bindings/LocalStorage.cpp @@ -8,6 +8,8 @@ static void StaticGet(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN2(0, 1); + if(info.Length() == 0) { V8_RETURN(static_cast(resource)->GetLocalStorage()); From 3e57c0f46c8479af33ff1c9eaf20acd4d626b358 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 19 Apr 2021 22:06:28 +0200 Subject: [PATCH 332/564] Add native name to native arg conversion errors --- src/bindings/V8Natives.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index affb0f40..15472458 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -60,7 +60,7 @@ static void *ToMemoryBuffer(v8::Local val, v8::Local ctx return nullptr; } -static void PushArg(alt::Ref scrCtx, alt::INative::Type argType, v8::Isolate *isolate, V8ResourceImpl* resource, v8::Local val) +static void PushArg(alt::Ref scrCtx, alt::INative* native, alt::INative::Type argType, v8::Isolate *isolate, V8ResourceImpl* resource, v8::Local val) { using ArgType = alt::INative::Type; @@ -86,7 +86,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a } else { - Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; + Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } } else if (val->IsBigInt()) @@ -98,7 +98,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a } else { - Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; + Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } } else if (val->IsObject()) @@ -108,7 +108,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a } else { - Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; + Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } break; } @@ -127,7 +127,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a } else { - Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; + Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } } else if (val->IsBigInt()) @@ -139,12 +139,12 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a } else { - Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; + Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } } else { - Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; + Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } break; } @@ -161,7 +161,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a } else { - Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; + Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } break; } @@ -183,7 +183,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative::Type a scrCtx->Push(ToMemoryBuffer(val, v8Ctx)); break; default: - Log::Error << "Unknown native arg type " << (int)argType << Log::Endl; + Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } } @@ -223,7 +223,7 @@ static void PushPointerReturn(alt::INative::Type argType, v8::Local r } } -static v8::Local GetReturn(alt::Ref scrCtx, alt::INative::Type retnType, v8::Isolate *isolate) +static v8::Local GetReturn(alt::Ref scrCtx, alt::INative* native, alt::INative::Type retnType, v8::Isolate *isolate) { using ArgType = alt::INative::Type; @@ -254,7 +254,7 @@ static v8::Local GetReturn(alt::Ref scrCtx, al case alt::INative::Type::ARG_VOID: return v8::Undefined(isolate); default: - Log::Error << "Unknown native return type " << (int)retnType << Log::Endl; + Log::Error << "Unknown native return type " << (int)retnType << " (" << native->GetName() << ")" << Log::Endl; return v8::Undefined(isolate); } } @@ -283,7 +283,7 @@ static void InvokeNative(const v8::FunctionCallbackInfo &info) auto resource = V8ResourceImpl::Get(v8Ctx); for (uint32_t i = 0; i < argsSize; ++i) - PushArg(ctx, args[i], isolate, resource, info[i]); + PushArg(ctx, native, args[i], isolate, resource, info[i]); if (!native->Invoke(ctx)) { @@ -293,12 +293,12 @@ static void InvokeNative(const v8::FunctionCallbackInfo &info) if (returnsCount == 1) { - info.GetReturnValue().Set(GetReturn(ctx, native->GetRetnType(), isolate)); + info.GetReturnValue().Set(GetReturn(ctx, native, native->GetRetnType(), isolate)); } else { v8::Local retns = v8::Array::New(isolate, returnsCount); - retns->Set(v8Ctx, 0, GetReturn(ctx, native->GetRetnType(), isolate)); + retns->Set(v8Ctx, 0, GetReturn(ctx, native, native->GetRetnType(), isolate)); pointersCount = 0; returnsCount = 1; From 77ba1732cdc3a33286bfe36bf41650fd86b6fa58 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 19 Apr 2021 22:17:47 +0200 Subject: [PATCH 333/564] Clearer error message on native arg parse error --- src/bindings/V8Natives.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 15472458..7bf087db 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -86,7 +86,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } } else if (val->IsBigInt()) @@ -98,7 +98,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } } else if (val->IsObject()) @@ -108,7 +108,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } break; } @@ -127,7 +127,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } } else if (val->IsBigInt()) @@ -139,12 +139,12 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } } else { - Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } break; } @@ -161,7 +161,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } break; } From dc10231a04f6a555944b1422decde6082ae72add Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 20 Apr 2021 08:57:08 +0200 Subject: [PATCH 334/564] Parse native type id to name in error --- src/bindings/V8Natives.cpp | 44 ++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 7bf087db..ac80a3d5 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -60,6 +60,36 @@ static void *ToMemoryBuffer(v8::Local val, v8::Local ctx return nullptr; } +static const char* GetNativeTypeName(alt::INative::Type type) +{ + using Type = alt::INative::Type; + switch(type) + { + case Type::ARG_BOOL: + case Type::ARG_BOOL_PTR: + return "bool"; + case Type::ARG_INT32: + case Type::ARG_INT32_PTR: + return "int32"; + case Type::ARG_UINT32: + case Type::ARG_UINT32_PTR: + return "uint32"; + case Type::ARG_FLOAT: + case Type::ARG_FLOAT_PTR: + return "float"; + case Type::ARG_VECTOR3: + case Type::ARG_VECTOR3_PTR: + return "vector3"; + case Type::ARG_STRING: + return "string"; + case Type::ARG_STRUCT: + return "struct"; + case Type::ARG_VOID: + return "void"; + } + return "unknown"; +} + static void PushArg(alt::Ref scrCtx, alt::INative* native, alt::INative::Type argType, v8::Isolate *isolate, V8ResourceImpl* resource, v8::Local val) { using ArgType = alt::INative::Type; @@ -86,7 +116,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } } else if (val->IsBigInt()) @@ -98,7 +128,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } } else if (val->IsObject()) @@ -108,7 +138,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } break; } @@ -127,7 +157,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } } else if (val->IsBigInt()) @@ -139,12 +169,12 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } } else { - Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } break; } @@ -161,7 +191,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument could not be parsed to type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } break; } From 2a1a2a3883f114164c2ae359f999e63317bfc256 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 24 Apr 2021 01:54:04 +0200 Subject: [PATCH 335/564] Add argument type name to native error message --- src/bindings/V8Natives.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index ac80a3d5..370e54cc 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -116,7 +116,8 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); + Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } } else if (val->IsBigInt()) @@ -128,7 +129,8 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); + Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } } else if (val->IsObject()) @@ -138,7 +140,8 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); + Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } break; } @@ -157,7 +160,8 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); + Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } } else if (val->IsBigInt()) @@ -169,12 +173,14 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); + Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } } else { - Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); + Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } break; } @@ -191,7 +197,8 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); + Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } break; } From 6ef694dda6b531d2405f35af4eff0b6e5969dbfe Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 3 May 2021 12:27:05 +0200 Subject: [PATCH 336/564] implement new func --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/Main.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index a3f8de6e..74dd37ce 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit a3f8de6e960fc9feaa9dc22fac427de36609f09c +Subproject commit 74dd37ce099444fe35fa30ef39f9f935d7a42a98 diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 63309071..70d3eee0 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -743,6 +743,16 @@ static void EvalModule(const v8::FunctionCallbackInfo& info) V8_RETURN(module->GetModuleNamespace()); } +static void GetHeadshotBase64(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_UINT32(1, id); + + V8_RETURN_STRING(alt::ICore::Instance().HeadshotToBase64(id).CStr()); +} + extern V8Class v8Vector3, v8Vector2, v8RGBA, @@ -876,4 +886,6 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "unloadYtyp", &UnloadYtyp); V8Helpers::RegisterFunc(exports, "evalModule", &EvalModule); + + V8Helpers::RegisterFunc(exports, "getHeadshotBase64", &GetHeadshotBase64); }); From ca74ece47210a4863528940707c2b5d03eb56b4a Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 10 May 2021 18:57:40 +0200 Subject: [PATCH 337/564] update cpp sdk --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 74dd37ce..6d1e7ed7 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 74dd37ce099444fe35fa30ef39f9f935d7a42a98 +Subproject commit 6d1e7ed7ab9acb5957fdb94ec683558df5643674 From aa0e314fba0cb1bb9f39badbbe151690bb5233e5 Mon Sep 17 00:00:00 2001 From: Jovan Ivanovic Date: Wed, 12 May 2021 17:20:21 +0200 Subject: [PATCH 338/564] Update Vector2.cpp --- bindings/Vector2.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bindings/Vector2.cpp b/bindings/Vector2.cpp index 8db4f974..99943a84 100644 --- a/bindings/Vector2.cpp +++ b/bindings/Vector2.cpp @@ -1,3 +1,5 @@ +#include + #include "../V8Class.h" #include "../V8Helpers.h" #include "../V8ResourceImpl.h" From 80e8ef632b23498d290ae81f6739d82a3b162e45 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 12 May 2021 22:15:54 +0200 Subject: [PATCH 339/564] Add HttpClient class --- src/bindings/HttpClient.cpp | 104 ++++++++++++++++++++++++++++++++++++ src/bindings/Main.cpp | 6 ++- 2 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 src/bindings/HttpClient.cpp diff --git a/src/bindings/HttpClient.cpp b/src/bindings/HttpClient.cpp new file mode 100644 index 00000000..ce15a432 --- /dev/null +++ b/src/bindings/HttpClient.cpp @@ -0,0 +1,104 @@ +#include "../helpers/V8Helpers.h" +#include "../helpers/V8ResourceImpl.h" +#include "../helpers/V8Class.h" +#include "../CV8ScriptRuntime.h" + +static void SetExtraHeader(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(client, alt::IHttpClient); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, name); + V8_ARG_TO_STRING(2, value); + + client->SetExtraHeader(name, value); +} + +static void GetExtraHeaders(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(client, alt::IHttpClient); + + auto dict = client->GetExtraHeaders(); + V8_NEW_OBJECT(headers); + for(auto it = dict->Begin(); it; it = dict->Next()) + { + headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); + } + + V8_RETURN(headers); +} + +static void Constructor(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + + auto client = alt::ICore::Instance().CreateHttpClient(resource->GetResource()); + V8_BIND_BASE_OBJECT(client, "Failed to create HttpClient"); +} + +static std::list> requestPromises; + +template +static void Request(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(client, alt::IHttpClient); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_STRING(1, url); + alt::String body; + if constexpr(HasBody == true) V8_CHECK(V8::SafeToString(info[1], isolate, ctx, body), "Failed to convert argument 2 to string") + + auto& persistent = requestPromises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); + auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { + // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD + + v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + auto persistent = (v8::UniquePersistent*)userData; + auto resolver = persistent->Get(isolate); + auto ctx = resolver->CreationContext(); + { + v8::Context::Scope ctxscope(ctx); + V8_NEW_OBJECT(responseObj); + V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_STRING(responseObj, "body", response.body.CStr()); + V8_NEW_OBJECT(headers); + for(auto it = response.headers->Begin(); it; it = response.headers->Next()) + { + headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); + } + + resolver->Resolve(ctx, responseObj); + } + + requestPromises.remove(*persistent); + }; + + if constexpr(HasBody == true) std::invoke(Func, client.Get(), callback, url, body); + else std::invoke(Func, client.Get(), callback, url); +} + +extern V8Class v8BaseObject; +extern V8Class v8HttpClient("HttpClient", v8BaseObject, &Constructor, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8::SetMethod(isolate, tpl, "setExtraHeader", &SetExtraHeader); + V8::SetMethod(isolate, tpl, "getExtraHeaders", &GetExtraHeaders); + + V8::SetMethod(isolate, tpl, "get", Request<&alt::IHttpClient::Get, false>); + V8::SetMethod(isolate, tpl, "head", Request<&alt::IHttpClient::Head, false>); + V8::SetMethod(isolate, tpl, "post", Request<&alt::IHttpClient::Post, true>); + V8::SetMethod(isolate, tpl, "put", Request<&alt::IHttpClient::Put, true>); + V8::SetMethod(isolate, tpl, "delete", Request<&alt::IHttpClient::Delete, true>); + V8::SetMethod(isolate, tpl, "connect", Request<&alt::IHttpClient::Connect, true>); + V8::SetMethod(isolate, tpl, "options", Request<&alt::IHttpClient::Options, true>); + V8::SetMethod(isolate, tpl, "trace", Request<&alt::IHttpClient::Trace, true>); + V8::SetMethod(isolate, tpl, "patch", Request<&alt::IHttpClient::Patch, true>); +}); diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 0e69237d..cfaf77da 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -804,7 +804,8 @@ extern V8Class v8Vector3, v8PedBlip, v8VehicleBlip, v8WebSocketClient, - v8Checkpoint; + v8Checkpoint, + v8HttpClient; extern V8Module altModule( "alt", {v8Vector3, @@ -828,7 +829,8 @@ extern V8Module altModule( v8Discord, v8Voice, v8WebSocketClient, - v8Checkpoint}, + v8Checkpoint, + v8HttpClient}, [](v8::Local ctx, v8::Local exports) { V8::RegisterSharedMain(ctx, exports); From 6cc66ff3d5e33fde0cec00cae654fd9f6f93c9bb Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 12 May 2021 22:17:37 +0200 Subject: [PATCH 340/564] Fix indent --- src/bindings/HttpClient.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/bindings/HttpClient.cpp b/src/bindings/HttpClient.cpp index ce15a432..dfc8eb9e 100644 --- a/src/bindings/HttpClient.cpp +++ b/src/bindings/HttpClient.cpp @@ -56,16 +56,16 @@ static void Request(const v8::FunctionCallbackInfo& info) auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD - v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); - v8::Locker locker(isolate); - v8::Isolate::Scope isolateScope(isolate); - v8::HandleScope handleScope(isolate); + v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); auto persistent = (v8::UniquePersistent*)userData; - auto resolver = persistent->Get(isolate); - auto ctx = resolver->CreationContext(); - { - v8::Context::Scope ctxscope(ctx); + auto resolver = persistent->Get(isolate); + auto ctx = resolver->CreationContext(); + { + v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); V8_OBJECT_SET_STRING(responseObj, "body", response.body.CStr()); @@ -75,10 +75,10 @@ static void Request(const v8::FunctionCallbackInfo& info) headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } - resolver->Resolve(ctx, responseObj); - } + resolver->Resolve(ctx, responseObj); + } - requestPromises.remove(*persistent); + requestPromises.remove(*persistent); }; if constexpr(HasBody == true) std::invoke(Func, client.Get(), callback, url, body); From c03b619006159ffdb6103eba396c9f249053631a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 12 May 2021 22:25:32 +0200 Subject: [PATCH 341/564] Update SDK --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/HttpClient.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 6d1e7ed7..3d1e8177 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 6d1e7ed7ab9acb5957fdb94ec683558df5643674 +Subproject commit 3d1e8177e2253fa8e3eefb2af224e96315412362 diff --git a/src/bindings/HttpClient.cpp b/src/bindings/HttpClient.cpp index dfc8eb9e..13eaa93a 100644 --- a/src/bindings/HttpClient.cpp +++ b/src/bindings/HttpClient.cpp @@ -81,8 +81,8 @@ static void Request(const v8::FunctionCallbackInfo& info) requestPromises.remove(*persistent); }; - if constexpr(HasBody == true) std::invoke(Func, client.Get(), callback, url, body); - else std::invoke(Func, client.Get(), callback, url); + if constexpr(HasBody == true) std::invoke(Func, client.Get(), callback, url, body, &persistent); + else std::invoke(Func, client.Get(), callback, url, &persistent); } extern V8Class v8BaseObject; From 4738035df808b7692bd521606dcfd23880642c26 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 12 May 2021 22:30:30 +0200 Subject: [PATCH 342/564] Fix typo --- src/bindings/HttpClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/HttpClient.cpp b/src/bindings/HttpClient.cpp index 13eaa93a..35e5a959 100644 --- a/src/bindings/HttpClient.cpp +++ b/src/bindings/HttpClient.cpp @@ -68,7 +68,7 @@ static void Request(const v8::FunctionCallbackInfo& info) v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); - V8_OBJECT_SET_STRING(responseObj, "body", response.body.CStr()); + V8_OBJECT_SET_STRING(responseObj, "body", response.body); V8_NEW_OBJECT(headers); for(auto it = response.headers->Begin(); it; it = response.headers->Next()) { From de05a8e3c308bf10212ebb1f0f21d85d2914b479 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 12 May 2021 22:39:24 +0200 Subject: [PATCH 343/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index c66c9009..c1d79741 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit c66c9009f96c91a5a0a787eb961903db19a204e9 +Subproject commit c1d797419c3e064e97bef81b7084ab07a0af07e6 From 0d42056a8c277f5d00b1bb6c499208d46d6663b9 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 12 May 2021 23:45:40 +0200 Subject: [PATCH 344/564] Fix http client class --- src/bindings/HttpClient.cpp | 364 ++++++++++++++++++++++++++++++++++-- 1 file changed, 348 insertions(+), 16 deletions(-) diff --git a/src/bindings/HttpClient.cpp b/src/bindings/HttpClient.cpp index 35e5a959..d405a17f 100644 --- a/src/bindings/HttpClient.cpp +++ b/src/bindings/HttpClient.cpp @@ -41,16 +41,13 @@ static void Constructor(const v8::FunctionCallbackInfo& info) static std::list> requestPromises; -template -static void Request(const v8::FunctionCallbackInfo& info) +static void Get(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(client, alt::IHttpClient); V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, url); - alt::String body; - if constexpr(HasBody == true) V8_CHECK(V8::SafeToString(info[1], isolate, ctx, body), "Failed to convert argument 2 to string") auto& persistent = requestPromises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { @@ -74,15 +71,350 @@ static void Request(const v8::FunctionCallbackInfo& info) { headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } + resolver->Resolve(resolver->CreationContext(), responseObj); + } + + requestPromises.remove(*persistent); + }; + + client->Get(callback, url, &persistent); + + V8_RETURN(persistent.Get(isolate)->GetPromise()); +} + +static void Head(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(client, alt::IHttpClient); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_STRING(1, url); + + auto& persistent = requestPromises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); + auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { + // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD + + v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + auto persistent = (v8::UniquePersistent*)userData; + auto resolver = persistent->Get(isolate); + auto ctx = resolver->CreationContext(); + { + v8::Context::Scope ctxscope(ctx); + V8_NEW_OBJECT(responseObj); + V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_STRING(responseObj, "body", response.body); + V8_NEW_OBJECT(headers); + for(auto it = response.headers->Begin(); it; it = response.headers->Next()) + { + headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); + } + resolver->Resolve(resolver->CreationContext(), responseObj); + } + + requestPromises.remove(*persistent); + }; + + client->Head(callback, url, &persistent); + + V8_RETURN(persistent.Get(isolate)->GetPromise()); +} + +static void Post(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(client, alt::IHttpClient); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, url); + V8_ARG_TO_STRING(2, body); + + auto& persistent = requestPromises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); + auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { + // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD + + v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + auto persistent = (v8::UniquePersistent*)userData; + auto resolver = persistent->Get(isolate); + auto ctx = resolver->CreationContext(); + { + v8::Context::Scope ctxscope(ctx); + V8_NEW_OBJECT(responseObj); + V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_STRING(responseObj, "body", response.body); + V8_NEW_OBJECT(headers); + for(auto it = response.headers->Begin(); it; it = response.headers->Next()) + { + headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); + } + resolver->Resolve(resolver->CreationContext(), responseObj); + } + + requestPromises.remove(*persistent); + }; + + client->Post(callback, url, body, &persistent); + + V8_RETURN(persistent.Get(isolate)->GetPromise()); +} + +static void Put(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(client, alt::IHttpClient); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, url); + V8_ARG_TO_STRING(2, body); + + auto& persistent = requestPromises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); + auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { + // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD + + v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + auto persistent = (v8::UniquePersistent*)userData; + auto resolver = persistent->Get(isolate); + auto ctx = resolver->CreationContext(); + { + v8::Context::Scope ctxscope(ctx); + V8_NEW_OBJECT(responseObj); + V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_STRING(responseObj, "body", response.body); + V8_NEW_OBJECT(headers); + for(auto it = response.headers->Begin(); it; it = response.headers->Next()) + { + headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); + } + resolver->Resolve(resolver->CreationContext(), responseObj); + } + + requestPromises.remove(*persistent); + }; + + client->Put(callback, url, body, &persistent); + + V8_RETURN(persistent.Get(isolate)->GetPromise()); +} + +static void Delete(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(client, alt::IHttpClient); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, url); + V8_ARG_TO_STRING(2, body); + + auto& persistent = requestPromises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); + auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { + // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD + + v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + auto persistent = (v8::UniquePersistent*)userData; + auto resolver = persistent->Get(isolate); + auto ctx = resolver->CreationContext(); + { + v8::Context::Scope ctxscope(ctx); + V8_NEW_OBJECT(responseObj); + V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_STRING(responseObj, "body", response.body); + V8_NEW_OBJECT(headers); + for(auto it = response.headers->Begin(); it; it = response.headers->Next()) + { + headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); + } + resolver->Resolve(resolver->CreationContext(), responseObj); + } + + requestPromises.remove(*persistent); + }; + + client->Delete(callback, url, body, &persistent); + + V8_RETURN(persistent.Get(isolate)->GetPromise()); +} + +static void Connect(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(client, alt::IHttpClient); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, url); + V8_ARG_TO_STRING(2, body); + + auto& persistent = requestPromises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); + auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { + // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD + + v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + auto persistent = (v8::UniquePersistent*)userData; + auto resolver = persistent->Get(isolate); + auto ctx = resolver->CreationContext(); + { + v8::Context::Scope ctxscope(ctx); + V8_NEW_OBJECT(responseObj); + V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_STRING(responseObj, "body", response.body); + V8_NEW_OBJECT(headers); + for(auto it = response.headers->Begin(); it; it = response.headers->Next()) + { + headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); + } + resolver->Resolve(resolver->CreationContext(), responseObj); + } + + requestPromises.remove(*persistent); + }; + + client->Connect(callback, url, body, &persistent); + + V8_RETURN(persistent.Get(isolate)->GetPromise()); +} + +static void Options(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(client, alt::IHttpClient); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, url); + V8_ARG_TO_STRING(2, body); + + auto& persistent = requestPromises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); + auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { + // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD + + v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + auto persistent = (v8::UniquePersistent*)userData; + auto resolver = persistent->Get(isolate); + auto ctx = resolver->CreationContext(); + { + v8::Context::Scope ctxscope(ctx); + V8_NEW_OBJECT(responseObj); + V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_STRING(responseObj, "body", response.body); + V8_NEW_OBJECT(headers); + for(auto it = response.headers->Begin(); it; it = response.headers->Next()) + { + headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); + } + resolver->Resolve(resolver->CreationContext(), responseObj); + } + + requestPromises.remove(*persistent); + }; + + client->Options(callback, url, body, &persistent); + + V8_RETURN(persistent.Get(isolate)->GetPromise()); +} + +static void Trace(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(client, alt::IHttpClient); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, url); + V8_ARG_TO_STRING(2, body); + + auto& persistent = requestPromises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); + auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { + // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD + + v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + auto persistent = (v8::UniquePersistent*)userData; + auto resolver = persistent->Get(isolate); + auto ctx = resolver->CreationContext(); + { + v8::Context::Scope ctxscope(ctx); + V8_NEW_OBJECT(responseObj); + V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_STRING(responseObj, "body", response.body); + V8_NEW_OBJECT(headers); + for(auto it = response.headers->Begin(); it; it = response.headers->Next()) + { + headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); + } + resolver->Resolve(resolver->CreationContext(), responseObj); + } + + requestPromises.remove(*persistent); + }; + + client->Trace(callback, url, body, &persistent); - resolver->Resolve(ctx, responseObj); + V8_RETURN(persistent.Get(isolate)->GetPromise()); +} + +static void Patch(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(client, alt::IHttpClient); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, url); + V8_ARG_TO_STRING(2, body); + + auto& persistent = requestPromises.emplace_back(v8::UniquePersistent(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked())); + auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { + // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD + + v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + + auto persistent = (v8::UniquePersistent*)userData; + auto resolver = persistent->Get(isolate); + auto ctx = resolver->CreationContext(); + { + v8::Context::Scope ctxscope(ctx); + V8_NEW_OBJECT(responseObj); + V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_STRING(responseObj, "body", response.body); + V8_NEW_OBJECT(headers); + for(auto it = response.headers->Begin(); it; it = response.headers->Next()) + { + headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); + } + resolver->Resolve(resolver->CreationContext(), responseObj); } requestPromises.remove(*persistent); }; - if constexpr(HasBody == true) std::invoke(Func, client.Get(), callback, url, body, &persistent); - else std::invoke(Func, client.Get(), callback, url, &persistent); + client->Patch(callback, url, body, &persistent); + + V8_RETURN(persistent.Get(isolate)->GetPromise()); } extern V8Class v8BaseObject; @@ -92,13 +424,13 @@ extern V8Class v8HttpClient("HttpClient", v8BaseObject, &Constructor, [](v8::Loc V8::SetMethod(isolate, tpl, "setExtraHeader", &SetExtraHeader); V8::SetMethod(isolate, tpl, "getExtraHeaders", &GetExtraHeaders); - V8::SetMethod(isolate, tpl, "get", Request<&alt::IHttpClient::Get, false>); - V8::SetMethod(isolate, tpl, "head", Request<&alt::IHttpClient::Head, false>); - V8::SetMethod(isolate, tpl, "post", Request<&alt::IHttpClient::Post, true>); - V8::SetMethod(isolate, tpl, "put", Request<&alt::IHttpClient::Put, true>); - V8::SetMethod(isolate, tpl, "delete", Request<&alt::IHttpClient::Delete, true>); - V8::SetMethod(isolate, tpl, "connect", Request<&alt::IHttpClient::Connect, true>); - V8::SetMethod(isolate, tpl, "options", Request<&alt::IHttpClient::Options, true>); - V8::SetMethod(isolate, tpl, "trace", Request<&alt::IHttpClient::Trace, true>); - V8::SetMethod(isolate, tpl, "patch", Request<&alt::IHttpClient::Patch, true>); + V8::SetMethod(isolate, tpl, "get", Get); + V8::SetMethod(isolate, tpl, "head", Head); + V8::SetMethod(isolate, tpl, "post", Post); + V8::SetMethod(isolate, tpl, "put", Put); + V8::SetMethod(isolate, tpl, "delete", Delete); + V8::SetMethod(isolate, tpl, "connect", Connect); + V8::SetMethod(isolate, tpl, "options", Options); + V8::SetMethod(isolate, tpl, "trace", Trace); + V8::SetMethod(isolate, tpl, "patch", Patch); }); From f05f41771337bf6933f9e28d272b30834afd7061 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 13 May 2021 18:43:28 +0200 Subject: [PATCH 345/564] Add Audio class --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/Audio.cpp | 237 +++++++++++++++++++++++++++++++++++++++++ src/bindings/Main.cpp | 6 +- 3 files changed, 242 insertions(+), 3 deletions(-) create mode 100644 src/bindings/Audio.cpp diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 3d1e8177..4fce73fb 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 3d1e8177e2253fa8e3eefb2af224e96315412362 +Subproject commit 4fce73fbff9bd47f860618de1d739f7c555e6cc5 diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp new file mode 100644 index 00000000..bfa778e9 --- /dev/null +++ b/src/bindings/Audio.cpp @@ -0,0 +1,237 @@ +#include "../helpers/V8Helpers.h" +#include "../helpers/V8ResourceImpl.h" +#include "../helpers/V8Class.h" +#include "../CV8ScriptRuntime.h" +#include "cpp-sdk/script-objects/IAudio.h" + +static void Constructor(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN(3); + + V8_ARG_TO_STRING(1, source); + V8_ARG_TO_NUMBER(2, volume); + V8_ARG_TO_STRING(3, category); + + auto audio = alt::ICore::Instance().CreateAudio(source, volume, category, resource->GetResource()); + V8_BIND_BASE_OBJECT(audio, "Failed to create Audio"); +} + +static void SourceGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_RETURN_ALT_STRING(audio->GetSource()); +} + +static void SourceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_TO_STRING(val, source); + audio->SetSource(source); +} + +static void LoopedGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_RETURN_BOOLEAN(audio->IsLoop()); +} + +static void LoopedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_TO_BOOLEAN(val, looped); + audio->SetLoop(looped); +} + +static void VolumeGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_RETURN_NUMBER(audio->GetVolume()); +} + +static void VolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_TO_NUMBER(val, volume); + audio->SetVolume(volume); +} + +static void CategoryGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_RETURN_ALT_STRING(audio->GetCategory()); +} + +static void CategorySetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_TO_STRING(val, category); + audio->SetCategory(category); +} + +static void FrontendPlayGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_RETURN_BOOLEAN(audio->IsFrontendPlay()); +} + +static void FrontendPlaySetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_TO_BOOLEAN(val, frontendPlay); + audio->SetFrontendPlay(frontendPlay); +} + +static void AddOutput(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + V8_CHECK_ARGS_LEN(1); + + if(info[0]->IsInt32() || info[0]->IsUint32()) + { + V8_ARG_TO_INTEGER(1, scriptId); + audio->AddOutput(scriptId); + } + else + { + V8_ARG_TO_BASE_OBJECT(1, entity, alt::IEntity, "Entity"); + audio->AddOutput(entity); + } +} + +static void RemoveOutput(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + V8_CHECK_ARGS_LEN(1); + + if(info[0]->IsInt32() || info[0]->IsUint32()) + { + V8_ARG_TO_INTEGER(1, scriptId); + audio->RemoveOutput(scriptId); + } + else + { + V8_ARG_TO_BASE_OBJECT(1, entity, alt::IEntity, "Entity"); + audio->RemoveOutput(entity); + } +} + +static void GetOutputs(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + auto list = audio->GetOutputs(); + auto arr = v8::Array::New(isolate, list->GetSize()); + for(int i = 0; i < list->GetSize(); i++) + { + arr->Set(ctx, i, V8_NEW_STRING(list->Get(i).As()->Value().CStr())); + } + + V8_RETURN(arr); +} + +static void CurrentTimeGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_RETURN_INTEGER(audio->GetCurrentTime()); +} + +static void MaxTimeGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_RETURN_INTEGER(audio->GetMaxTime()); +} + +static void PlayingGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_RETURN_BOOLEAN(audio->IsPlaying()); +} + +static void Play(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + audio->Play(); +} + +static void Pause(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + audio->Pause(); +} + +static void Reset(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + audio->Reset(); +} + +static void Seek(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_INTEGER(1, time); + + audio->Seek(time); +} + +extern V8Class v8BaseObject; +extern V8Class v8Audio("Audio", v8BaseObject, &Constructor, [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8::SetAccessor(isolate, tpl, "source", &SourceGetter, &SourceSetter); + V8::SetAccessor(isolate, tpl, "looped", &LoopedGetter, &LoopedSetter); + V8::SetAccessor(isolate, tpl, "volume", &VolumeGetter, &VolumeSetter); + V8::SetAccessor(isolate, tpl, "category", &CategoryGetter, &CategorySetter); + V8::SetAccessor(isolate, tpl, "frontendPlay", &FrontendPlayGetter, &FrontendPlaySetter); + V8::SetAccessor(isolate, tpl, "currentTime", &CurrentTimeGetter); + V8::SetAccessor(isolate, tpl, "maxTime", &MaxTimeGetter); + V8::SetAccessor(isolate, tpl, "playing", &PlayingGetter); + + V8::SetMethod(isolate, tpl, "addOutput", &AddOutput); + V8::SetMethod(isolate, tpl, "removeOutput", &RemoveOutput); + V8::SetMethod(isolate, tpl, "getOutputs", &GetOutputs); + + V8::SetMethod(isolate, tpl, "play", &Play); + V8::SetMethod(isolate, tpl, "pause", &Pause); + V8::SetMethod(isolate, tpl, "reset", &Reset); + V8::SetMethod(isolate, tpl, "seek", &Seek); +}); diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index cfaf77da..a0356efe 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -805,7 +805,8 @@ extern V8Class v8Vector3, v8VehicleBlip, v8WebSocketClient, v8Checkpoint, - v8HttpClient; + v8HttpClient, + v8Audio; extern V8Module altModule( "alt", {v8Vector3, @@ -830,7 +831,8 @@ extern V8Module altModule( v8Voice, v8WebSocketClient, v8Checkpoint, - v8HttpClient}, + v8HttpClient, + v8Audio}, [](v8::Local ctx, v8::Local exports) { V8::RegisterSharedMain(ctx, exports); From 930ca1b2ad0bb2d2202983033e84ee5bb612ac9a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 13 May 2021 18:45:22 +0200 Subject: [PATCH 346/564] Fix indent --- src/bindings/Audio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp index bfa778e9..7c4ded1b 100644 --- a/src/bindings/Audio.cpp +++ b/src/bindings/Audio.cpp @@ -215,7 +215,7 @@ static void Seek(const v8::FunctionCallbackInfo& info) extern V8Class v8BaseObject; extern V8Class v8Audio("Audio", v8BaseObject, &Constructor, [](v8::Local tpl) { - v8::Isolate *isolate = v8::Isolate::GetCurrent(); + v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetAccessor(isolate, tpl, "source", &SourceGetter, &SourceSetter); V8::SetAccessor(isolate, tpl, "looped", &LoopedGetter, &LoopedSetter); From 6756ec2a8cc5ac202648c74d8e6989cc310b4727 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 13 May 2021 20:57:13 +0200 Subject: [PATCH 347/564] Set headers prop on http client request methods return object --- src/bindings/HttpClient.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/bindings/HttpClient.cpp b/src/bindings/HttpClient.cpp index d405a17f..bedfc38c 100644 --- a/src/bindings/HttpClient.cpp +++ b/src/bindings/HttpClient.cpp @@ -71,6 +71,7 @@ static void Get(const v8::FunctionCallbackInfo& info) { headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } + responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); resolver->Resolve(resolver->CreationContext(), responseObj); } @@ -112,6 +113,7 @@ static void Head(const v8::FunctionCallbackInfo& info) { headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } + responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); resolver->Resolve(resolver->CreationContext(), responseObj); } @@ -154,6 +156,7 @@ static void Post(const v8::FunctionCallbackInfo& info) { headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } + responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); resolver->Resolve(resolver->CreationContext(), responseObj); } @@ -196,6 +199,7 @@ static void Put(const v8::FunctionCallbackInfo& info) { headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } + responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); resolver->Resolve(resolver->CreationContext(), responseObj); } @@ -238,6 +242,7 @@ static void Delete(const v8::FunctionCallbackInfo& info) { headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } + responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); resolver->Resolve(resolver->CreationContext(), responseObj); } @@ -280,6 +285,7 @@ static void Connect(const v8::FunctionCallbackInfo& info) { headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } + responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); resolver->Resolve(resolver->CreationContext(), responseObj); } @@ -322,6 +328,7 @@ static void Options(const v8::FunctionCallbackInfo& info) { headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } + responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); resolver->Resolve(resolver->CreationContext(), responseObj); } @@ -364,6 +371,7 @@ static void Trace(const v8::FunctionCallbackInfo& info) { headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } + responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); resolver->Resolve(resolver->CreationContext(), responseObj); } @@ -406,6 +414,7 @@ static void Patch(const v8::FunctionCallbackInfo& info) { headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } + responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); resolver->Resolve(resolver->CreationContext(), responseObj); } From 4d2458d889b96ba41e2fe4ec9bab610e504b8f12 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 13 May 2021 23:02:39 +0200 Subject: [PATCH 348/564] Fix Audio getOutputs --- src/bindings/Audio.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp index 7c4ded1b..ee9aa55f 100644 --- a/src/bindings/Audio.cpp +++ b/src/bindings/Audio.cpp @@ -141,14 +141,21 @@ static void RemoveOutput(const v8::FunctionCallbackInfo& info) static void GetOutputs(const v8::FunctionCallbackInfo& info) { - V8_GET_ISOLATE_CONTEXT(); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); auto list = audio->GetOutputs(); auto arr = v8::Array::New(isolate, list->GetSize()); for(int i = 0; i < list->GetSize(); i++) { - arr->Set(ctx, i, V8_NEW_STRING(list->Get(i).As()->Value().CStr())); + auto val = list->Get(i); + if(val->GetType() == alt::IMValue::Type::BASE_OBJECT) + { + auto baseObj = resource->GetBaseObjectOrNull(val.As()->Value()); + arr->Set(ctx, i, baseObj); + } + else if(val->GetType() == alt::IMValue::Type::UINT) + arr->Set(ctx, i, v8::Integer::NewFromUnsigned(isolate, val.As()->Value())); } V8_RETURN(arr); From 66f1639be40357b1b5096f7e401c75109341fe42 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 14 May 2021 17:44:03 +0200 Subject: [PATCH 349/564] Change Audio ints to doubles --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/Audio.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 4fce73fb..934f6fbc 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 4fce73fbff9bd47f860618de1d739f7c555e6cc5 +Subproject commit 934f6fbc5a2db3c53502195c30676cf909d74957 diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp index ee9aa55f..c2ea1d4a 100644 --- a/src/bindings/Audio.cpp +++ b/src/bindings/Audio.cpp @@ -166,7 +166,7 @@ static void CurrentTimeGetter(v8::Local, const v8::PropertyCallbackI V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - V8_RETURN_INTEGER(audio->GetCurrentTime()); + V8_RETURN_NUMBER(audio->GetCurrentTime()); } static void MaxTimeGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -174,7 +174,7 @@ static void MaxTimeGetter(v8::Local, const v8::PropertyCallbackInfo< V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - V8_RETURN_INTEGER(audio->GetMaxTime()); + V8_RETURN_NUMBER(audio->GetMaxTime()); } static void PlayingGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -215,7 +215,7 @@ static void Seek(const v8::FunctionCallbackInfo& info) V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, time); + V8_ARG_TO_NUMBER(1, time); audio->Seek(time); } From 53924b659cb81b24f68804545ca9f37850d8a581 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 15 May 2021 11:06:57 +0200 Subject: [PATCH 350/564] Return Vector3 class instance if native returns Vector3Ptr --- src/bindings/V8Natives.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 370e54cc..85d9658f 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -248,13 +248,10 @@ static void PushPointerReturn(alt::INative::Type argType, v8::Local r pointersCount += 3; v8::Local v8Ctx = isolate->GetEnteredContext(); - v8::Local vec = v8::Object::New(isolate); - - V8::DefineOwnProperty(isolate, v8Ctx, vec, "x", v8::Number::New(isolate, val->x), v8::PropertyAttribute::ReadOnly); - V8::DefineOwnProperty(isolate, v8Ctx, vec, "y", v8::Number::New(isolate, val->y), v8::PropertyAttribute::ReadOnly); - V8::DefineOwnProperty(isolate, v8Ctx, vec, "z", v8::Number::New(isolate, val->z), v8::PropertyAttribute::ReadOnly); + V8ResourceImpl* resource = V8ResourceImpl::Get(v8Ctx); + auto vector = resource->CreateVector3({ val->x, val->y, val->z }).As(); - retns->Set(ctx, returnsCount++, vec); + retns->Set(ctx, returnsCount++, vector); break; } } From bd093a3df9dca1ce232c6d0db97203dcb6dc3bb1 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 15 May 2021 11:13:51 +0200 Subject: [PATCH 351/564] Set category arg for Audio to 'radio' by default --- src/bindings/Audio.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp index c2ea1d4a..f0571f3a 100644 --- a/src/bindings/Audio.cpp +++ b/src/bindings/Audio.cpp @@ -8,11 +8,16 @@ static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_CONSTRUCTOR(); - V8_CHECK_ARGS_LEN(3); + V8_CHECK_ARGS_LEN2(2, 3); V8_ARG_TO_STRING(1, source); V8_ARG_TO_NUMBER(2, volume); - V8_ARG_TO_STRING(3, category); + alt::String category = "radio"; + if(info.Length() == 3) + { + V8_ARG_TO_STRING(3, categ); + category = categ; + } auto audio = alt::ICore::Instance().CreateAudio(source, volume, category, resource->GetResource()); V8_BIND_BASE_OBJECT(audio, "Failed to create Audio"); From 0fae40d9f9a26b23a2cdeb8da6e0bfee5d3bbbba Mon Sep 17 00:00:00 2001 From: Vektor Date: Tue, 18 May 2021 15:43:09 +0200 Subject: [PATCH 352/564] make category accept hash only --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/Audio.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 934f6fbc..4fce73fb 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 934f6fbc5a2db3c53502195c30676cf909d74957 +Subproject commit 4fce73fbff9bd47f860618de1d739f7c555e6cc5 diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp index f0571f3a..6efa647e 100644 --- a/src/bindings/Audio.cpp +++ b/src/bindings/Audio.cpp @@ -12,10 +12,11 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_ARG_TO_STRING(1, source); V8_ARG_TO_NUMBER(2, volume); - alt::String category = "radio"; + + uint32_t category = 0; if(info.Length() == 3) { - V8_ARG_TO_STRING(3, categ); + V8_ARG_TO_UINT32(3, categ); category = categ; } @@ -79,7 +80,7 @@ static void CategoryGetter(v8::Local, const v8::PropertyCallbackInfo V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - V8_RETURN_ALT_STRING(audio->GetCategory()); + V8_RETURN_UINTEGER(audio->GetCategory()); } static void CategorySetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) @@ -87,7 +88,7 @@ static void CategorySetter(v8::Local, v8::Local val, cons V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - V8_TO_STRING(val, category); + V8_TO_INTEGER(val, category); audio->SetCategory(category); } From 5815facae253f86e4b5cc1527ec1234641265a5a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 20 May 2021 18:32:59 +0200 Subject: [PATCH 353/564] Add entity.isSpawned --- bindings/Entity.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index dafc28f3..9ff74a4a 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -157,6 +157,14 @@ static void ResetNetOwner(const v8::FunctionCallbackInfo &info) #ifdef ALT_CLIENT_API +static void IsSpawnedGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + + V8_RETURN_BOOLEAN(player->GetScriptGuid() != 0); +} + static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -230,5 +238,7 @@ extern V8Class v8Entity("Entity", v8WorldObject, [](v8::Local(isolate, tpl, "model"); V8::SetAccessor(isolate, tpl, "scriptID"); V8::SetAccessor(isolate, tpl, "visible"); + + V8::SetAccessor(isolate, tpl, "isSpawned", &IsSpawnedGetter); #endif // ALT_CLIENT_API }); From f273d16f715a6d84a7843bead7669bb5f6120e9b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 20 May 2021 18:33:53 +0200 Subject: [PATCH 354/564] Fix indentation --- bindings/Entity.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index 9ff74a4a..4eac0ffe 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -159,10 +159,10 @@ static void ResetNetOwner(const v8::FunctionCallbackInfo &info) static void IsSpawnedGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_RETURN_BOOLEAN(player->GetScriptGuid() != 0); + V8_RETURN_BOOLEAN(player->GetScriptGuid() != 0); } static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) From cb732f8c9c7f1e79fbdf5863e3f09b9d79ed6e12 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 20 May 2021 19:19:13 +0200 Subject: [PATCH 355/564] Allow string as category for Audio class --- src/bindings/Audio.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp index 6efa647e..48d4ac32 100644 --- a/src/bindings/Audio.cpp +++ b/src/bindings/Audio.cpp @@ -16,8 +16,16 @@ static void Constructor(const v8::FunctionCallbackInfo& info) uint32_t category = 0; if(info.Length() == 3) { - V8_ARG_TO_UINT32(3, categ); - category = categ; + if(info[2]->IsNumber()) + { + V8_ARG_TO_UINT32(3, categ); + category = categ; + } + else if(info[2]->IsString()) + { + V8_ARG_TO_STRING(3, categ); + category = alt::ICore::Instance().Hash(categ); + } } auto audio = alt::ICore::Instance().CreateAudio(source, volume, category, resource->GetResource()); @@ -88,7 +96,17 @@ static void CategorySetter(v8::Local, v8::Local val, cons V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - V8_TO_INTEGER(val, category); + int64_t category; + if(val->IsNumber()) + { + V8_TO_INTEGER(val, categ); + category = categ; + } + else if(val->IsString()) + { + V8_TO_STRING(val, categ); + category = alt::ICore::Instance().Hash(categ); + } audio->SetCategory(category); } From e98970f4c76b7bbe8e490afe3435174a80b387bf Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 20 May 2021 19:20:45 +0200 Subject: [PATCH 356/564] Update CPP SDK --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 4fce73fb..0802852e 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 4fce73fbff9bd47f860618de1d739f7c555e6cc5 +Subproject commit 0802852e0e7d2a8007d53d8520fc7922a5aa2031 From 51aca398f96aff9518d500988928b9450bf0a38d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 24 May 2021 00:58:38 +0200 Subject: [PATCH 357/564] Update error message when passing invalid base object --- V8Helpers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 69913b2b..1999c52a 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -208,7 +208,7 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) if (!ent) { - Log::Warning << "Has internal field but is not entity" << Log::Endl; + Log::Error << "Unable to convert base object to MValue because it was destroyed and is now invalid" << Log::Endl; return core.CreateMValueNil(); } else @@ -319,7 +319,7 @@ v8::Local V8Helpers::MValueToV8(alt::MValueConst val) return v8Buffer; } default: - Log::Warning << "V8::MValueToV8 Unknown MValue type" << (int)val->GetType() << Log::Endl; + Log::Warning << "V8::MValueToV8 Unknown MValue type " << (int)val->GetType() << Log::Endl; } return v8::Undefined(isolate); From 042fb871a6593038fb145f9da1b782892d0cab7d Mon Sep 17 00:00:00 2001 From: fabian Date: Mon, 24 May 2021 02:07:44 +0200 Subject: [PATCH 358/564] add toggle extra --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/Vehicle.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 4fce73fb..5a4ec6cb 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 4fce73fbff9bd47f860618de1d739f7c555e6cc5 +Subproject commit 5a4ec6cb4b23f1eab692eeeccf7a705eae8031ff diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 56e5121e..d93919e0 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -477,6 +477,16 @@ static void IsHandlingModifiedGetter(v8::Local, const v8::PropertyCa V8_RETURN_BOOLEAN(vehicle->IsHandlingModified()); } +static void toggleExtra(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_INTEGER(1, extraID); + V8_ARG_TO_BOOLEAN(1, toggle); + vehicle->ToggleExtra(extraID, toggle); +} + // static void GravityGetter(v8::Local, const v8::PropertyCallbackInfo &info) // { // V8_GET_ISOLATE(info); @@ -577,6 +587,7 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); // proto->SetAccessor(v8::String::NewFromUtf8(isolate, "gravity", &GravityGetter).ToLocalChecked(), &GravitySetter); V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); + V8::SetMethod(isolate, tpl, "toggleExtra", ToggleExtra); /* GETTERS BELOW ARE UNIMPLEMENTED V8::SetAccessor(isolate, tpl, "isDestroyed", &IsDestroyedGetter); V8::SetAccessor(isolate, tpl, "driver", &DriverGetter); From 81b332a773d2a08ba8567da8134da88f33ff0063 Mon Sep 17 00:00:00 2001 From: fabian Date: Mon, 24 May 2021 02:08:54 +0200 Subject: [PATCH 359/564] fix --- src/bindings/Vehicle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index d93919e0..2eb84e5b 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -483,7 +483,7 @@ static void toggleExtra(v8::Local, const v8::PropertyCallbackInfoToggleExtra(extraID, toggle); } From 9c1fa5488486b8c87d5d6b5e1dd34039322edee5 Mon Sep 17 00:00:00 2001 From: fabian Date: Mon, 24 May 2021 02:13:18 +0200 Subject: [PATCH 360/564] fix --- src/bindings/Vehicle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 2eb84e5b..59965e53 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -477,7 +477,7 @@ static void IsHandlingModifiedGetter(v8::Local, const v8::PropertyCa V8_RETURN_BOOLEAN(vehicle->IsHandlingModified()); } -static void toggleExtra(v8::Local, const v8::PropertyCallbackInfo& info) +static void ToggleExtra(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); From 2369b70427a12d90ffdbd8cd60eea2a0cd9e65ef Mon Sep 17 00:00:00 2001 From: fabian Date: Mon, 24 May 2021 02:13:59 +0200 Subject: [PATCH 361/564] Fix method v8 signature --- src/bindings/Vehicle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 59965e53..4a069a7f 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -477,7 +477,7 @@ static void IsHandlingModifiedGetter(v8::Local, const v8::PropertyCa V8_RETURN_BOOLEAN(vehicle->IsHandlingModified()); } -static void ToggleExtra(v8::Local, const v8::PropertyCallbackInfo& info) +static void ToggleExtra(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); From 79c2f655885a24d5880e741c3af7c7cb1389ed01 Mon Sep 17 00:00:00 2001 From: fabian Date: Mon, 24 May 2021 02:15:22 +0200 Subject: [PATCH 362/564] fix isolation --- src/bindings/Vehicle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 4a069a7f..20e5b598 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -479,7 +479,7 @@ static void IsHandlingModifiedGetter(v8::Local, const v8::PropertyCa static void ToggleExtra(const v8::FunctionCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_CHECK_ARGS_LEN(2); V8_ARG_TO_INTEGER(1, extraID); From fcd6c5e1a7e98eb4779a945ec5fc4e4a181977eb Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 25 May 2021 17:15:02 +0200 Subject: [PATCH 363/564] Check for number instead of int in native arg parsing --- src/bindings/V8Natives.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 85d9658f..4e2da9b1 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -107,7 +107,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native break; case alt::INative::Type::ARG_INT32: { - if (val->IsUint32() || val->IsInt32()) + if (val->IsNumber()) { v8::Local value; if (val->ToInteger(v8Ctx).ToLocal(&value)) @@ -151,7 +151,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native break; case alt::INative::Type::ARG_UINT32: { - if (val->IsUint32() || val->IsInt32()) + if (val->IsNumber()) { v8::Local value; if (val->ToInteger(v8Ctx).ToLocal(&value)) From 36ecdc9b69ab2e2a21d7c822c023dde55577de66 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 25 May 2021 17:16:03 +0200 Subject: [PATCH 364/564] Fix crash in native args float parsing --- src/bindings/V8Natives.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 4e2da9b1..5dce62e4 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -190,10 +190,18 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native break; case alt::INative::Type::ARG_FLOAT: { - v8::Local value; - if (val->ToNumber(v8Ctx).ToLocal(&value)) + if (val->IsNumber()) { - scrCtx->Push((float)value->Value()); + v8::Local value; + if (val->ToNumber(v8Ctx).ToLocal(&value)) + { + scrCtx->Push((float)value->Value()); + } + else + { + v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); + Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + } } else { From bb9d8e9366e94db57e970c9a38f51f5f5718e863 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 1 Jun 2021 23:17:55 +0200 Subject: [PATCH 365/564] Add new gear property setters and getters --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/Vehicle.cpp | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 5a4ec6cb..1e4e16c0 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 5a4ec6cb4b23f1eab692eeeccf7a705eae8031ff +Subproject commit 1e4e16c01320dc5aa7702d94e24e6fb0920441d9 diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 20e5b598..095cfb18 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -52,6 +52,15 @@ static void GearGetter(v8::Local, const v8::PropertyCallbackInfoGetCurrentGear()); } +static void GearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_TO_INTEGER(val, gear); + vehicle->SetCurrentGear(gear); +} + static void RPMGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(info); @@ -528,6 +537,23 @@ static void ToggleExtra(const v8::FunctionCallbackInfo& info) // vehicle->gravity = newval; // } +static void MaxGearGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetMaxGear()); +} + +static void MaxGearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_TO_INTEGER(val, maxGear); + vehicle->SetMaxGear(maxGear); +} + static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -581,7 +607,8 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local // Common getters V8::SetAccessor(isolate, tpl, "speed", &SpeedGetter); - V8::SetAccessor(isolate, tpl, "gear", &GearGetter); + V8::SetAccessor(isolate, tpl, "gear", &GearGetter, &GearSetter); + V8::SetAccessor(isolate, tpl, "maxGear", &MaxGearGetter, &MaxGearSetter); V8::SetAccessor(isolate, tpl, "rpm", &RPMGetter); V8::SetAccessor(isolate, tpl, "wheelsCount", &WheelsCountGetter); V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); From 6302d5e7ad743384d0949b3de7130a959874fa15 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 3 Jun 2021 14:52:12 +0200 Subject: [PATCH 366/564] Add Vector3 dot product --- bindings/Vector3.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index f58a8f59..b0d4d9ff 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -281,6 +281,63 @@ static void Multiply(const v8::FunctionCallbackInfo& info) } } +static void Dot(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN2(1, 3); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + if (info.Length() == 3) + { + V8_ARG_TO_NUMBER(1, x2); + V8_ARG_TO_NUMBER(2, y2); + V8_ARG_TO_NUMBER(3, z2); + + V8_RETURN_NUMBER(x * x2 + y * y2 + z * z2); + } + else if (info.Length() == 1) + { + auto arg = info[0]; + if (arg->IsNumber()) + { + V8_ARG_TO_NUMBER(1, value); + + V8_RETURN_NUMBER(x * value + y * value + z * value); + } + else if (arg->IsArray()) + { + v8::Local arr = arg.As(); + V8_CHECK(arr->Length() == 3, "Argument must be an array of 3 numbers"); + + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); + V8_TO_NUMBER(arr->Get(ctx, 1).ToLocalChecked(), y2); + V8_TO_NUMBER(arr->Get(ctx, 2).ToLocalChecked(), z2); + + V8_RETURN_NUMBER(x * x2 + y * y2 + z * z2); + } + else if (arg->IsObject()) + { + v8::Local obj = arg.As(); + + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(), z2); + + V8_RETURN_NUMBER(x * x2 + y * y2 + z * z2); + } + else + { + V8Helpers::Throw(isolate, "Argument must be a number, an array of 3 numbers or IVector3"); + } + } +} + static void Negative(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -538,6 +595,7 @@ extern V8Class v8Vector3("Vector3", Constructor, [](v8::Local Date: Thu, 3 Jun 2021 15:01:34 +0200 Subject: [PATCH 367/564] Add attachment methods --- bindings/Entity.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index 4eac0ffe..065ab760 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -153,6 +153,31 @@ static void ResetNetOwner(const v8::FunctionCallbackInfo &info) _this->SetNetworkOwner(nullptr, disableMigration); } +static void AttachTo(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(7); + V8_GET_THIS_BASE_OBJECT(_this, IEntity); + + V8_ARG_TO_BASE_OBJECT(1, entity, IEntity, "Entity"); + V8_ARG_TO_UINT32(2, otherBone); + V8_ARG_TO_UINT32(3, ownBone); + V8_ARG_TO_VECTOR3(4, pos); + V8_ARG_TO_VECTOR3(5, rot); + V8_ARG_TO_BOOLEAN(6, collision); + V8_ARG_TO_BOOLEAN(7, noFixedRot); + + _this->AttachToEntity(entity, otherBone, ownBone, pos, rot, collision, noFixedRot); +} + +static void Detach(const v8::FunctionCallbackInfo &info) +{ + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(_this, IEntity); + + _this->Detach(); +} + #endif // ALT_SERVER_API #ifdef ALT_CLIENT_API @@ -228,6 +253,9 @@ extern V8Class v8Entity("Entity", v8WorldObject, [](v8::Local Date: Sat, 5 Jun 2021 15:29:44 +0200 Subject: [PATCH 368/564] Fix converting BigInt to MValue --- V8Helpers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 69913b2b..883fc231 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -128,8 +128,8 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) if (val->IsUint32()) return core.CreateMValueUInt(val->Uint32Value(ctx).ToChecked()); - if (val->IsBigInt()) - return core.CreateMValueInt(val->IntegerValue(ctx).ToChecked()); + if (val->IsBigInt()) + return core.CreateMValueInt(val.As()->Int64Value()); if (val->IsNumber()) return core.CreateMValueDouble(val->NumberValue(ctx).ToChecked()); From d017cb6a37d472c1890a029bfb7778c0a9cfb376 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sun, 6 Jun 2021 21:09:48 +0200 Subject: [PATCH 369/564] add audio events --- src/CV8Resource.cpp | 20 +++++++++++++++-- src/CV8Resource.h | 36 +++++++++++++++++++++++++------ src/bindings/Audio.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++ src/events/Events.h | 2 ++ src/events/Main.cpp | 17 ++++++++++++++- 5 files changed, 115 insertions(+), 9 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 8647c24b..22f0ff40 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -291,10 +291,10 @@ std::vector CV8ResourceImpl::GetWebViewHandlers(alt::Ref CV8ResourceImpl::GetWebSocketClientHandlers(alt::Ref view, const std::string& name) +std::vector CV8ResourceImpl::GetWebSocketClientHandlers(alt::Ref webSocket, const std::string& name) { std::vector handlers; - auto it = webSocketClientHandlers.find(view.Get()); + auto it = webSocketClientHandlers.find(webSocket.Get()); if (it != webSocketClientHandlers.end()) { @@ -307,6 +307,22 @@ std::vector CV8ResourceImpl::GetWebSocketClientHandlers(alt: return handlers; } +std::vector CV8ResourceImpl::GetAudioHandlers(alt::Ref audio, const std::string& name) +{ + std::vector handlers; + auto it = audioHandlers.find(audio.Get()); + + if (it != audioHandlers.end()) + { + auto range = it->second.equal_range(name); + + for (auto it = range.first; it != range.second; ++it) + handlers.push_back(&it->second); + } + + return handlers; +} + void CV8ResourceImpl::OnTick() { v8::Locker locker(isolate); diff --git a/src/CV8Resource.h b/src/CV8Resource.h index 32a737fe..8242d7ee 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -61,17 +61,17 @@ class CV8ResourceImpl : public V8ResourceImpl std::vector GetWebViewHandlers(alt::Ref view, const std::string& name); - void SubscribeWebSocketClient(alt::Ref view, const std::string &evName, v8::Local cb, V8::SourceLocation &&location) + void SubscribeWebSocketClient(alt::Ref webSocket, const std::string& evName, v8::Local cb, V8::SourceLocation&& location) { - webSocketClientHandlers[view].insert({evName, V8::EventCallback{isolate, cb, std::move(location)}}); + webSocketClientHandlers[webSocket].insert({ evName, V8::EventCallback{isolate, cb, std::move(location)} }); } - void UnsubscribeWebSocketClient(alt::Ref view, const std::string &evName, v8::Local cb) + void UnsubscribeWebSocketClient(alt::Ref webSocket, const std::string& evName, v8::Local cb) { - auto it = webSocketClientHandlers.find(view); + auto it = webSocketClientHandlers.find(webSocket); if (it != webSocketClientHandlers.end()) { - auto &webSocketEvents = it->second; + auto& webSocketEvents = it->second; auto range = webSocketEvents.equal_range(evName); for (auto it = range.first; it != range.second; ++it) @@ -81,9 +81,32 @@ class CV8ResourceImpl : public V8ResourceImpl } } } - + std::vector GetWebSocketClientHandlers(alt::Ref webSocket, const std::string& name); + void SubscribeAudio(alt::Ref audio, const std::string& evName, v8::Local cb, V8::SourceLocation&& location) + { + audioHandlers[audio].insert({ evName, V8::EventCallback{isolate, cb, std::move(location)} }); + } + + void UnsubscribeAudio(alt::Ref audio, const std::string& evName, v8::Local cb) + { + auto it = audioHandlers.find(audio); + if (it != audioHandlers.end()) + { + auto& audioEvents = it->second; + auto range = audioEvents.equal_range(evName); + + for (auto it = range.first; it != range.second; ++it) + { + if (it->second.fn.Get(isolate)->StrictEquals(cb)) + it->second.removed = true; + } + } + } + + std::vector GetAudioHandlers(alt::Ref audio, const std::string& name); + void AddOwned(alt::Ref handle) { ownedObjects.insert(handle); @@ -132,6 +155,7 @@ class CV8ResourceImpl : public V8ResourceImpl std::unordered_map, WebViewEvents> webViewHandlers; std::unordered_map, WebViewEvents> webSocketClientHandlers; + std::unordered_map, WebViewEvents> audioHandlers; std::unordered_set> ownedObjects; diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp index 48d4ac32..91122342 100644 --- a/src/bindings/Audio.cpp +++ b/src/bindings/Audio.cpp @@ -32,6 +32,51 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_BIND_BASE_OBJECT(audio, "Failed to create Audio"); } +static void On(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, fun); + + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + static_cast(resource)->SubscribeAudio(audio, evName.ToString(), fun, V8::SourceLocation::GetCurrent(isolate)); +} + +static void Off(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, evName); + V8_ARG_TO_FUNCTION(2, fun); + + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + static_cast(resource)->UnsubscribeAudio(audio, evName.ToString(), fun); +} + +static void GetEventListeners(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_ARGS_LEN(1); + V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); + + V8_ARG_TO_STRING(1, eventName); + + std::vector handlers = static_cast(resource)->GetAudioHandlers(audio, eventName.ToString()); + + auto array = v8::Array::New(isolate, handlers.size()); + for (int i = 0; i < handlers.size(); i++) + { + array->Set(ctx, i, handlers[i]->fn.Get(isolate)); + } + + V8_RETURN(array); +} + static void SourceGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(); @@ -248,6 +293,10 @@ extern V8Class v8BaseObject; extern V8Class v8Audio("Audio", v8BaseObject, &Constructor, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8::SetMethod(isolate, tpl, "on", &On); + V8::SetMethod(isolate, tpl, "off", &Off); + V8::SetMethod(isolate, tpl, "getEventListeners", GetEventListeners); + V8::SetAccessor(isolate, tpl, "source", &SourceGetter, &SourceSetter); V8::SetAccessor(isolate, tpl, "looped", &LoopedGetter, &LoopedSetter); V8::SetAccessor(isolate, tpl, "volume", &VolumeGetter, &VolumeSetter); diff --git a/src/events/Events.h b/src/events/Events.h index 507b9740..b39d4ecf 100644 --- a/src/events/Events.h +++ b/src/events/Events.h @@ -19,6 +19,8 @@ inline void RegisterEvents() V8_REFERENCE_EVENT_HANDLER(clientScriptEvent); V8_REFERENCE_EVENT_HANDLER(serverScriptEvent); V8_REFERENCE_EVENT_HANDLER(webviewEvent); + V8_REFERENCE_EVENT_HANDLER(webSocketEvent); + V8_REFERENCE_EVENT_HANDLER(audioEvent); V8_REFERENCE_EVENT_HANDLER(keyboardEvent); V8_REFERENCE_LOCAL_EVENT_HANDLER(render); V8_REFERENCE_LOCAL_EVENT_HANDLER(connectionComplete); diff --git a/src/events/Main.cpp b/src/events/Main.cpp index f0c77de2..cbde1d0f 100644 --- a/src/events/Main.cpp +++ b/src/events/Main.cpp @@ -13,6 +13,7 @@ #include "cpp-sdk/events/CKeyboardEvent.h" #include "cpp-sdk/events/CWebViewEvent.h" #include "cpp-sdk/events/CWebSocketClientEvent.h" +#include "cpp-sdk/events/CAudioEvent.h" #include "cpp-sdk/SDK.h" @@ -71,7 +72,21 @@ V8_EVENT_HANDLER webSocketEvent( V8Helpers::MValueArgsToV8(ev->GetArgs(), args); } - ); +); + +V8_EVENT_HANDLER audioEvent( + EventType::AUDIO_EVENT, + [](V8ResourceImpl* resource, const CEvent* e) { + auto ev = static_cast(e); + + return static_cast(resource)->GetAudioHandlers(ev->GetTarget(), ev->GetName().ToString()); + }, + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + + V8Helpers::MValueArgsToV8(ev->GetArgs(), args); + } +); V8_EVENT_HANDLER keyboardEvent( EventType::KEYBOARD_EVENT, From 8c0679fc35f3158c70e59c8c41773bcdbd828fb8 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sun, 6 Jun 2021 21:17:08 +0200 Subject: [PATCH 370/564] update sdk --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 1e4e16c0..91a8ded2 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 1e4e16c01320dc5aa7702d94e24e6fb0920441d9 +Subproject commit 91a8ded2d9baaf5abf9520131ab53ab902baf82d From 3d50b32da0a5db7d693e51feb21f7c91daf6839e Mon Sep 17 00:00:00 2001 From: YannBCF <54820465+YannBCF@users.noreply.github.com> Date: Mon, 7 Jun 2021 00:35:38 +0200 Subject: [PATCH 371/564] Update cpp-sdk --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 91a8ded2..45d5979b 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 91a8ded2d9baaf5abf9520131ab53ab902baf82d +Subproject commit 45d5979bc3d2639803c9e47bd3b024755d8b614e From 7f289efe5b6bdcd8cf9d9924e34a141169910181 Mon Sep 17 00:00:00 2001 From: YannBCF <54820465+YannBCF@users.noreply.github.com> Date: Mon, 7 Jun 2021 00:36:30 +0200 Subject: [PATCH 372/564] Add lights indicator bindings --- src/bindings/Vehicle.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 095cfb18..6140be8d 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -593,6 +593,23 @@ static void StaticGetByID(const v8::FunctionCallbackInfo& info) V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id).As()); } +static void IndicatorLightsGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(info); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_RETURN_INTEGER(vehicle->GetLightsIndicator()); +} + +static void IndicatorLightsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + + V8_TO_INTEGER(val, indicatorLights); + vehicle->SetLightsIndicator(indicatorLights); +} + extern V8Class v8Entity; extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); @@ -615,6 +632,8 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local // proto->SetAccessor(v8::String::NewFromUtf8(isolate, "gravity", &GravityGetter).ToLocalChecked(), &GravitySetter); V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); V8::SetMethod(isolate, tpl, "toggleExtra", ToggleExtra); + V8::SetAccessor(isolate, tpl, "indicatorLights", &IndicatorLightsGetter, &IndicatorLightsSetter); + /* GETTERS BELOW ARE UNIMPLEMENTED V8::SetAccessor(isolate, tpl, "isDestroyed", &IsDestroyedGetter); V8::SetAccessor(isolate, tpl, "driver", &DriverGetter); From 15b149a99fdf05bd439a5aeb3bc5fd8229e26ea3 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 7 Jun 2021 19:04:36 +0200 Subject: [PATCH 373/564] Stricter SafeTo* helpers type checks --- V8Helpers.cpp | 91 ++++++++++++++++++++------------------------------- 1 file changed, 35 insertions(+), 56 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 69913b2b..7602f330 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -528,92 +528,72 @@ v8::Local V8::Fire_WeaponKey(v8::Isolate* isolate) bool V8::SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool& out) { + if(!val->IsBoolean()) return false; out = val->ToBoolean(isolate)->Value(); return true; } bool V8::SafeToInteger(v8::Local val, v8::Local ctx, int64_t& out) { + if(!val->IsNumber()) return false; v8::MaybeLocal maybeVal = val->ToInteger(ctx); - if (!maybeVal.IsEmpty()) - { - out = maybeVal.ToLocalChecked()->Value(); - return true; - } - - return false; + if(maybeVal.IsEmpty()) return false; + out = maybeVal.ToLocalChecked()->Value(); + return true; } bool V8::SafeToUInt64(v8::Local val, v8::Local ctx, uint64_t& out) { + if(!val->IsNumber()) return false; v8::MaybeLocal maybeVal = val->ToBigInt(ctx); - if (!maybeVal.IsEmpty()) - { - out = maybeVal.ToLocalChecked()->Uint64Value(); - return true; - } - - return false; + if(maybeVal.IsEmpty()) return false; + out = maybeVal.ToLocalChecked()->Uint64Value(); + return true; } bool V8::SafeToInt64(v8::Local val, v8::Local ctx, int64_t& out) { + if(!val->IsNumber()) return false; v8::MaybeLocal maybeVal = val->ToBigInt(ctx); - if (!maybeVal.IsEmpty()) - { - out = maybeVal.ToLocalChecked()->Int64Value(); - return true; - } - - return false; + if(maybeVal.IsEmpty()) return false; + out = maybeVal.ToLocalChecked()->Int64Value(); + return true; } bool V8::SafeToUInt32(v8::Local val, v8::Local ctx, uint32_t& out) { + if(!val->IsNumber()) return false; v8::MaybeLocal maybeVal = val->ToUint32(ctx); - if (!maybeVal.IsEmpty()) - { - out = maybeVal.ToLocalChecked()->Value(); - return true; - } - - return false; + if(maybeVal.IsEmpty()) return false; + out = maybeVal.ToLocalChecked()->Value(); + return true; } bool V8::SafeToInt32(v8::Local val, v8::Local ctx, int32_t& out) { + if(!val->IsNumber()) return false; v8::MaybeLocal maybeVal = val->ToInt32(ctx); - if (!maybeVal.IsEmpty()) - { - out = maybeVal.ToLocalChecked()->Value(); - return true; - } - - return false; + if(maybeVal.IsEmpty()) return false; + out = maybeVal.ToLocalChecked()->Value(); + return true; } bool V8::SafeToNumber(v8::Local val, v8::Local ctx, double& out) { + if(!val->IsNumber()) return false; v8::MaybeLocal maybeVal = val->ToNumber(ctx); - if (!maybeVal.IsEmpty()) - { - out = maybeVal.ToLocalChecked()->Value(); - return true; - } - - return false; + if(maybeVal.IsEmpty()) return false; + out = maybeVal.ToLocalChecked()->Value(); + return true; } bool V8::SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String& out) { + if(!val->IsString()) return false; v8::MaybeLocal maybeVal = val->ToString(ctx); - if (!maybeVal.IsEmpty()) - { - out = *v8::String::Utf8Value(isolate, maybeVal.ToLocalChecked()); - return true; - } - - return false; + if(maybeVal.IsEmpty()) return false; + out = *v8::String::Utf8Value(isolate, maybeVal.ToLocalChecked()); + return true; } bool V8::SafeToFunction(v8::Local val, v8::Local ctx, v8::Local& out) @@ -629,18 +609,16 @@ bool V8::SafeToFunction(v8::Local val, v8::Local ctx, v8 bool V8::SafeToObject(v8::Local val, v8::Local ctx, v8::Local& out) { + if(!val->IsObject()) return false; v8::MaybeLocal maybeVal = val->ToObject(ctx); - if (!maybeVal.IsEmpty()) - { - out = maybeVal.ToLocalChecked(); - return true; - } - - return false; + if (maybeVal.IsEmpty()) return false; + out = maybeVal.ToLocalChecked(); + return true; } bool V8::SafeToRGBA(v8::Local val, v8::Local ctx, alt::RGBA& out) { + if(!val->IsObject()) return false; v8::MaybeLocal maybeVal = val->ToObject(ctx); if (!maybeVal.IsEmpty()) { @@ -662,6 +640,7 @@ bool V8::SafeToRGBA(v8::Local val, v8::Local ctx, alt::R bool V8::SafeToVector3(v8::Local val, v8::Local ctx, alt::Vector3f& out) { + if(!val->IsObject()) return false; v8::MaybeLocal maybeVal = val->ToObject(ctx); if (!maybeVal.IsEmpty()) { From 5d0f45cc328ad2b690d0ed9d55ecd7ba0f5b8f61 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 9 Jun 2021 16:22:38 +0200 Subject: [PATCH 374/564] Allow hash as first arg in addGxtText --- src/bindings/Main.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index a0356efe..eaf828d7 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -220,12 +220,23 @@ static void IsVoiceActivityInputEnabled(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_IRESOURCE(); - V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_STRING(1, key); + + uint32_t gxtHash; + if(info[0]->IsString()) + { + V8_ARG_TO_STRING(1, key); + gxtHash = alt::ICore::Instance().Hash(key); + } + else if(info[0]->IsNumber()) + { + V8_ARG_TO_UINT32(1, hash); + gxtHash = hash; + } + V8_ARG_TO_STRING(2, textValue); - resource->AddGxtText(ICore::Instance().Hash(key), textValue.ToString()); + resource->AddGxtText(gxtHash, textValue.ToString()); } static void RemoveGxtText(const v8::FunctionCallbackInfo &info) From 84cb22787eb27f29a62e31d22472b98b538f86c8 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 10 Jun 2021 23:07:26 +0200 Subject: [PATCH 375/564] Convert AttachTo args to int32 instead of uint32 --- bindings/Entity.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index 065ab760..17f681db 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -160,8 +160,8 @@ static void AttachTo(const v8::FunctionCallbackInfo &info) V8_GET_THIS_BASE_OBJECT(_this, IEntity); V8_ARG_TO_BASE_OBJECT(1, entity, IEntity, "Entity"); - V8_ARG_TO_UINT32(2, otherBone); - V8_ARG_TO_UINT32(3, ownBone); + V8_ARG_TO_INT32(2, otherBone); + V8_ARG_TO_INT32(3, ownBone); V8_ARG_TO_VECTOR3(4, pos); V8_ARG_TO_VECTOR3(5, rot); V8_ARG_TO_BOOLEAN(6, collision); From 37cc16418662bb9fd6145dffbd288bd7d1032557 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 11 Jun 2021 15:58:22 +0200 Subject: [PATCH 376/564] Fix crash for wrong arg type in addGxtText and Audio constructor --- src/bindings/Audio.cpp | 2 +- src/bindings/Main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp index 91122342..58d6c9b9 100644 --- a/src/bindings/Audio.cpp +++ b/src/bindings/Audio.cpp @@ -21,7 +21,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_ARG_TO_UINT32(3, categ); category = categ; } - else if(info[2]->IsString()) + else { V8_ARG_TO_STRING(3, categ); category = alt::ICore::Instance().Hash(categ); diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index eaf828d7..6a834778 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -228,7 +228,7 @@ static void AddGxtText(const v8::FunctionCallbackInfo &info) V8_ARG_TO_STRING(1, key); gxtHash = alt::ICore::Instance().Hash(key); } - else if(info[0]->IsNumber()) + else { V8_ARG_TO_UINT32(1, hash); gxtHash = hash; From a7cc998400931804a403f35a32d62586d0608659 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 11 Jun 2021 19:43:57 +0200 Subject: [PATCH 377/564] Add binding helper for methods --- V8BindHelpers.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/V8BindHelpers.h b/V8BindHelpers.h index f191b1f6..0b2cc05f 100644 --- a/V8BindHelpers.h +++ b/V8BindHelpers.h @@ -73,6 +73,14 @@ namespace V8 V8_GET_THIS_BASE_OBJECT(_this, T); CallSetter(info, value, _this.Get(), Setter); } + + template + static void WrapMethod(const v8::FunctionCallbackInfo &info) + { + V8_GET_ISOLATE(); + V8_GET_THIS_BASE_OBJECT(_this, T); + (_this.Get()->*Method)(); + } } template @@ -86,4 +94,10 @@ namespace V8 { V8::SetAccessor(isolate, tpl, name, V8::detail::WrapGetter, V8::detail::WrapSetter); } + + template + inline void SetMethod(v8::Isolate* isolate, v8::Local tpl, const char* name) + { + V8::SetMethod(isolate, tpl, name, V8::detail::WrapMethod); + } } From 419aee3d77c2e0f7d0f7731c09f3ee4eece37a0d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 11 Jun 2021 20:20:04 +0200 Subject: [PATCH 378/564] Add Vector2 to helper functions --- V8BindHelpers.h | 2 ++ V8Helpers.cpp | 19 +++++++++++++++++++ V8Helpers.h | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/V8BindHelpers.h b/V8BindHelpers.h index 0b2cc05f..8a48bb91 100644 --- a/V8BindHelpers.h +++ b/V8BindHelpers.h @@ -37,6 +37,7 @@ namespace V8 V8_CALL_GETTER(alt::StringView, V8_GET_ISOLATE, V8_RETURN_ALT_STRING); V8_CALL_GETTER(alt::Position, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_VECTOR3); V8_CALL_GETTER(alt::Rotation, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_VECTOR3); + V8_CALL_GETTER(alt::Vector2f, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_VECTOR2); V8_CALL_GETTER(alt::RGBA, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_RGBA); V8_CALL_GETTER(alt::IColShape::ColShapeType, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_ENUM); V8_CALL_GETTER(alt::IBaseObject::Type, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_ENUM); @@ -56,6 +57,7 @@ namespace V8 V8_CALL_SETTER(alt::StringView, V8_GET_ISOLATE_CONTEXT, V8_TO_STRING); V8_CALL_SETTER(alt::Position, V8_GET_ISOLATE_CONTEXT, V8_TO_VECTOR3); V8_CALL_SETTER(alt::Rotation, V8_GET_ISOLATE_CONTEXT, V8_TO_VECTOR3); + V8_CALL_SETTER(alt::Vector2f, V8_GET_ISOLATE_CONTEXT, V8_TO_VECTOR2); V8_CALL_SETTER(alt::RGBA, V8_GET_ISOLATE_CONTEXT, V8_TO_RGBA); template diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 883fc231..0cce8798 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -680,6 +680,25 @@ bool V8::SafeToVector3(v8::Local val, v8::Local ctx, alt return false; } +bool V8::SafeToVector2(v8::Local val, v8::Local ctx, alt::Vector2f& out) +{ + v8::MaybeLocal maybeVal = val->ToObject(ctx); + if (!maybeVal.IsEmpty()) + { + v8::Local val = maybeVal.ToLocalChecked(); + + double x, y; + if (SafeToNumber(V8::Get(ctx, val, "x"), ctx, x) + && SafeToNumber(V8::Get(ctx, val, "y"), ctx, y) + ) { + out = alt::Vector2f{ float(x), float(y) }; + return true; + } + } + + return false; +} + bool V8::SafeToArrayBuffer(v8::Local val, v8::Local ctx, v8::Local& out) { if (val->IsArrayBuffer()) diff --git a/V8Helpers.h b/V8Helpers.h index 38ec139b..00d66afb 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -195,6 +195,7 @@ namespace V8 bool SafeToObject(v8::Local val, v8::Local ctx, v8::Local& out); bool SafeToRGBA(v8::Local val, v8::Local ctx, alt::RGBA& out); bool SafeToVector3(v8::Local val, v8::Local ctx, alt::Vector3f& out); + bool SafeToVector2(v8::Local val, v8::Local ctx, alt::Vector2f& out); bool SafeToArrayBuffer(v8::Local val, v8::Local ctx, v8::Local& out); bool SafeToArrayBufferView(v8::Local val, v8::Local ctx, v8::Local& out); @@ -312,6 +313,10 @@ namespace V8 alt::Vector3f val; \ V8_CHECK(V8::SafeToVector3((v8Val), ctx, val), "Failed to convert value to Vector3") +#define V8_TO_VECTOR2(v8Val, val) \ + alt::Vector2f val; \ + V8_CHECK(V8::SafeToVector2((v8Val), ctx, val), "Failed to convert value to Vector2") + #define V8_TO_RGBA(v8Val, val) \ alt::RGBA val; \ V8_CHECK(V8::SafeToRGBA((v8Val), ctx, val), "Failed to convert value to RGBA") @@ -452,6 +457,7 @@ namespace V8 #define V8_RETURN_UINT64(val) V8_RETURN(v8::BigInt::NewFromUnsigned(isolate, (val))) #define V8_RETURN_INT64(val) V8_RETURN(v8::BigInt::New(isolate, (val))) #define V8_RETURN_VECTOR3(val) V8_RETURN(resource->CreateVector3(val)) +#define V8_RETURN_VECTOR2(val) V8_RETURN(resource->CreateVector2(val)) #define V8_RETURN_RGBA(val) V8_RETURN(resource->CreateRGBA(val)) #define V8_RETURN_ENUM(val) V8_RETURN(v8::Integer::NewFromUnsigned(isolate, uint32_t(val))) From 3d36ecc3ee1d43c550ea713487465e9b9817c19a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 11 Jun 2021 20:21:12 +0200 Subject: [PATCH 379/564] Add Vector3f as type in bind helpers --- V8BindHelpers.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/V8BindHelpers.h b/V8BindHelpers.h index 8a48bb91..90bd7504 100644 --- a/V8BindHelpers.h +++ b/V8BindHelpers.h @@ -37,6 +37,7 @@ namespace V8 V8_CALL_GETTER(alt::StringView, V8_GET_ISOLATE, V8_RETURN_ALT_STRING); V8_CALL_GETTER(alt::Position, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_VECTOR3); V8_CALL_GETTER(alt::Rotation, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_VECTOR3); + V8_CALL_GETTER(alt::Vector3f, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_VECTOR3); V8_CALL_GETTER(alt::Vector2f, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_VECTOR2); V8_CALL_GETTER(alt::RGBA, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_RGBA); V8_CALL_GETTER(alt::IColShape::ColShapeType, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_ENUM); @@ -57,6 +58,7 @@ namespace V8 V8_CALL_SETTER(alt::StringView, V8_GET_ISOLATE_CONTEXT, V8_TO_STRING); V8_CALL_SETTER(alt::Position, V8_GET_ISOLATE_CONTEXT, V8_TO_VECTOR3); V8_CALL_SETTER(alt::Rotation, V8_GET_ISOLATE_CONTEXT, V8_TO_VECTOR3); + V8_CALL_SETTER(alt::Vector3f, V8_GET_ISOLATE_CONTEXT, V8_TO_VECTOR3); V8_CALL_SETTER(alt::Vector2f, V8_GET_ISOLATE_CONTEXT, V8_TO_VECTOR2); V8_CALL_SETTER(alt::RGBA, V8_GET_ISOLATE_CONTEXT, V8_TO_RGBA); From a446cc7571fa902974b7e920c137d82e50da34c2 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 11 Jun 2021 20:58:16 +0200 Subject: [PATCH 380/564] Add double as type to binding helpers --- V8BindHelpers.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/V8BindHelpers.h b/V8BindHelpers.h index 90bd7504..0f8a32fa 100644 --- a/V8BindHelpers.h +++ b/V8BindHelpers.h @@ -34,6 +34,7 @@ namespace V8 V8_CALL_GETTER(int32_t, V8_GET_ISOLATE, V8_RETURN_INTEGER); V8_CALL_GETTER(int64_t, V8_GET_ISOLATE, V8_RETURN_INT64); V8_CALL_GETTER(float, V8_GET_ISOLATE, V8_RETURN_NUMBER); + V8_CALL_GETTER(double, V8_GET_ISOLATE, V8_RETURN_NUMBER); V8_CALL_GETTER(alt::StringView, V8_GET_ISOLATE, V8_RETURN_ALT_STRING); V8_CALL_GETTER(alt::Position, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_VECTOR3); V8_CALL_GETTER(alt::Rotation, V8_GET_ISOLATE_CONTEXT_RESOURCE, V8_RETURN_VECTOR3); @@ -55,6 +56,7 @@ namespace V8 V8_CALL_SETTER(int16_t, V8_GET_ISOLATE_CONTEXT, V8_TO_INTEGER); V8_CALL_SETTER(int32_t, V8_GET_ISOLATE_CONTEXT, V8_TO_INTEGER); V8_CALL_SETTER(float, V8_GET_ISOLATE_CONTEXT, V8_TO_NUMBER); + V8_CALL_SETTER(double, V8_GET_ISOLATE_CONTEXT, V8_TO_NUMBER); V8_CALL_SETTER(alt::StringView, V8_GET_ISOLATE_CONTEXT, V8_TO_STRING); V8_CALL_SETTER(alt::Position, V8_GET_ISOLATE_CONTEXT, V8_TO_VECTOR3); V8_CALL_SETTER(alt::Rotation, V8_GET_ISOLATE_CONTEXT, V8_TO_VECTOR3); From 1b691061a2459d3f22db0b1cae641a6435363e7e Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 12 Jun 2021 17:10:38 +0200 Subject: [PATCH 381/564] add frontend audio --- src/bindings/Audio.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp index 58d6c9b9..9fa793d0 100644 --- a/src/bindings/Audio.cpp +++ b/src/bindings/Audio.cpp @@ -8,13 +8,14 @@ static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_CONSTRUCTOR(); - V8_CHECK_ARGS_LEN2(2, 3); + V8_CHECK_ARGS_LEN_MIN_MAX(2, 4); V8_ARG_TO_STRING(1, source); V8_ARG_TO_NUMBER(2, volume); uint32_t category = 0; - if(info.Length() == 3) + bool frontend = false; + if(info.Length() == 3 || info.Length() == 4) { if(info[2]->IsNumber()) { @@ -26,9 +27,14 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_ARG_TO_STRING(3, categ); category = alt::ICore::Instance().Hash(categ); } + if (info.Length() == 4) + { + V8_ARG_TO_BOOLEAN(4, frntnd); + frontend = frntnd; + } } - auto audio = alt::ICore::Instance().CreateAudio(source, volume, category, resource->GetResource()); + auto audio = alt::ICore::Instance().CreateAudio(source, volume, category, frontend, resource->GetResource()); V8_BIND_BASE_OBJECT(audio, "Failed to create Audio"); } @@ -163,15 +169,6 @@ static void FrontendPlayGetter(v8::Local, const v8::PropertyCallback V8_RETURN_BOOLEAN(audio->IsFrontendPlay()); } -static void FrontendPlaySetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - V8_TO_BOOLEAN(val, frontendPlay); - audio->SetFrontendPlay(frontendPlay); -} - static void AddOutput(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -301,7 +298,7 @@ extern V8Class v8Audio("Audio", v8BaseObject, &Constructor, [](v8::Local Date: Sat, 12 Jun 2021 17:11:48 +0200 Subject: [PATCH 382/564] update sdk --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 45d5979b..06719d69 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 45d5979bc3d2639803c9e47bd3b024755d8b614e +Subproject commit 06719d6994fe825afd32df9e45727ca3995887fb From d9368c95a1553eae93e677e46a0d564c23fede72 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sun, 13 Jun 2021 12:58:48 +0200 Subject: [PATCH 383/564] update cpp sdk --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 06719d69..995dd695 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 06719d6994fe825afd32df9e45727ca3995887fb +Subproject commit 995dd69573fed893e85b11036841291f0302abf4 From eac727b500346c89822431ee5041e6fd24e76ab4 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 14 Jun 2021 15:45:36 +0200 Subject: [PATCH 384/564] Add Vector2 dot method --- bindings/Vector2.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/bindings/Vector2.cpp b/bindings/Vector2.cpp index 99943a84..b28cddfd 100644 --- a/bindings/Vector2.cpp +++ b/bindings/Vector2.cpp @@ -260,6 +260,60 @@ static void Multiply(const v8::FunctionCallbackInfo& info) } } + +static void Dot(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN2(1, 2); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + + if (info.Length() == 2) + { + V8_ARG_TO_NUMBER(1, x2); + V8_ARG_TO_NUMBER(2, y2); + + V8_RETURN_NUMBER(x * x2 + y * y2); + } + else if (info.Length() == 1) + { + auto arg = info[0]; + if (arg->IsNumber()) + { + V8_ARG_TO_NUMBER(1, value); + + V8_RETURN_NUMBER(x * value + y * value); + } + else if (arg->IsArray()) + { + v8::Local arr = arg.As(); + V8_CHECK(arr->Length() == 2, "Argument must be an array of 2 numbers"); + + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); + V8_TO_NUMBER(arr->Get(ctx, 1).ToLocalChecked(), y2); + + V8_RETURN_NUMBER(x * x2 + y * y2); + } + else if (arg->IsObject()) + { + v8::Local obj = arg.As(); + + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + + V8_RETURN_NUMBER(x * x2 + y * y2); + } + else + { + V8Helpers::Throw(isolate, "Argument must be a number, an array of 2 numbers or IVector2"); + } + } +} + static void Negative(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); From f4fcfdedce8bd8dbce1cecb9f827ddf4dfc98bad Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 14 Jun 2021 15:46:59 +0200 Subject: [PATCH 385/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index c1d79741..eac727b5 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit c1d797419c3e064e97bef81b7084ab07a0af07e6 +Subproject commit eac727b500346c89822431ee5041e6fd24e76ab4 From fbb44f938fb4f361ef7e11f9b083fc2dce6a8143 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 14 Jun 2021 22:34:41 +0200 Subject: [PATCH 386/564] Add Stringify helper func --- V8Helpers.cpp | 12 ++++++++++++ V8Helpers.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 0cce8798..43ba8013 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -771,3 +771,15 @@ V8::EventHandler::EventHandler(alt::CEvent::Type type, CallbacksGetter &&_handle void V8::EventHandler::Reference() { Log::Info << "[V8] Registered handler for " << std::to_string((int)type) << Log::Endl; } + +alt::String V8::Stringify(v8::Local val, v8::Local ctx) +{ + v8::Local str; + if(!val->ToString(ctx).ToLocal(&str)) return nullptr; + if (val->IsObject() && strcmp(*v8::String::Utf8Value(ctx->GetIsolate(), str), "[object Object]") == 0) { + v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); + v8::Local stringified; + if (maybe.ToLocal(&stringified)) str = stringified; + } + return *v8::String::Utf8Value(ctx->GetIsolate(), str); +} diff --git a/V8Helpers.h b/V8Helpers.h index 00d66afb..d5824183 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -217,6 +217,8 @@ namespace V8 return true; } + + alt::String Stringify(v8::Local val, v8::Local ctx); } // namespace V8 #define V8_GET_ISOLATE() v8::Isolate *isolate = info.GetIsolate() From a422c4520b7e0197689e4e066ebf7c0f99ed9cea Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 14 Jun 2021 22:37:39 +0200 Subject: [PATCH 387/564] Use Stringify helper in Log bindings --- bindings/Main.cpp | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 88eefd16..4d9f0d63 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -151,11 +151,9 @@ static void GetSyncedMeta(const v8::FunctionCallbackInfo &info) static void Log(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); - V8_CHECK_ARGS_LEN_MIN(1); std::stringstream ss; - for (int i = 0; i < info.Length(); ++i) { v8::Local val = info[i]; @@ -163,15 +161,10 @@ static void Log(const v8::FunctionCallbackInfo &info) if (i > 0) ss << " "; - v8::Local str; - if(!val->ToString(ctx).ToLocal(&str)) continue; - if (val->IsObject() && strcmp(*v8::String::Utf8Value(isolate, str), "[object Object]") == 0) { - v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); - v8::Local stringified; - if (maybe.ToLocal(&stringified)) str = stringified; - } + auto str = V8::Stringify(val, ctx); + if(str.IsEmpty()) continue; - ss << *v8::String::Utf8Value(isolate, str); + ss << str.CStr(); } alt::ICore::Instance().LogColored(ss.str()); @@ -180,11 +173,9 @@ static void Log(const v8::FunctionCallbackInfo &info) static void LogWarning(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); - V8_CHECK_ARGS_LEN_MIN(1); std::stringstream ss; - for (int i = 0; i < info.Length(); ++i) { v8::Local val = info[i]; @@ -192,15 +183,10 @@ static void LogWarning(const v8::FunctionCallbackInfo &info) if (i > 0) ss << " "; - v8::Local str; - if(!val->ToString(ctx).ToLocal(&str)) continue; - if (val->IsObject() && strcmp(*v8::String::Utf8Value(isolate, str), "[object Object]") == 0) { - v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); - v8::Local stringified; - if (maybe.ToLocal(&stringified)) str = stringified; - } + auto str = V8::Stringify(val, ctx); + if(str.IsEmpty()) continue; - ss << *v8::String::Utf8Value(isolate, str); + ss << str.CStr(); } alt::ICore::Instance().LogWarning(ss.str()); @@ -209,11 +195,9 @@ static void LogWarning(const v8::FunctionCallbackInfo &info) static void LogError(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); - V8_CHECK_ARGS_LEN_MIN(1); std::stringstream ss; - for (int i = 0; i < info.Length(); ++i) { v8::Local val = info[i]; @@ -221,15 +205,10 @@ static void LogError(const v8::FunctionCallbackInfo &info) if (i > 0) ss << " "; - v8::Local str; - if(!val->ToString(ctx).ToLocal(&str)) continue; - if (val->IsObject() && strcmp(*v8::String::Utf8Value(isolate, str), "[object Object]") == 0) { - v8::MaybeLocal maybe = v8::JSON::Stringify(ctx, val); - v8::Local stringified; - if (maybe.ToLocal(&stringified)) str = stringified; - } + auto str = V8::Stringify(val, ctx); + if(str.IsEmpty()) continue; - ss << *v8::String::Utf8Value(isolate, str); + ss << str.CStr(); } alt::ICore::Instance().LogError(ss.str()); From b153620d210cc131257130da79751986ca57e2ad Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 19 Jun 2021 10:35:28 +0200 Subject: [PATCH 388/564] update cpp sdk & helpers --- deps/cpp-sdk/cpp-sdk | 2 +- src/helpers | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 995dd695..65a545df 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 995dd69573fed893e85b11036841291f0302abf4 +Subproject commit 65a545df32496fee926b7fbb2c3151683dea7ae9 diff --git a/src/helpers b/src/helpers index eac727b5..a422c452 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit eac727b500346c89822431ee5041e6fd24e76ab4 +Subproject commit a422c4520b7e0197689e4e066ebf7c0f99ed9cea From 7df9ce2b24894e03dc4533b73ca60b1a49ac9144 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 19 Jun 2021 19:44:39 +0200 Subject: [PATCH 389/564] update cpp sdk --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 65a545df..a6e7d7b0 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 65a545df32496fee926b7fbb2c3151683dea7ae9 +Subproject commit a6e7d7b0e818f07b18b0c658075398ed3f1c745b From 33d05eb570e996a5a888f25296d26082522458f8 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 19 Jun 2021 20:15:55 +0200 Subject: [PATCH 390/564] Faster Vector distanceTo methods --- bindings/Vector2.cpp | 4 +++- bindings/Vector3.cpp | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bindings/Vector2.cpp b/bindings/Vector2.cpp index b28cddfd..e6f6b0f5 100644 --- a/bindings/Vector2.cpp +++ b/bindings/Vector2.cpp @@ -356,7 +356,9 @@ static void DistanceTo(const v8::FunctionCallbackInfo& info) V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); - double dist = sqrt(std::pow(x - x2, 2) + std::pow(y - y2, 2)); + double xFinal = x - x2; + double yFinal = y - y2; + double dist = sqrt((xFinal * xFinal) + (yFinal * yFinal)); V8_RETURN_NUMBER(dist); } diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index b0d4d9ff..a6e2c362 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -384,7 +384,10 @@ static void DistanceTo(const v8::FunctionCallbackInfo& info) V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); V8_TO_NUMBER(vec->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(), z2); - double dist = sqrt(std::pow(x - x2, 2) + std::pow(y - y2, 2) + std::pow(z - z2, 2)); + double xFinal = x - x2; + double yFinal = y - y2; + double zFinal = z - z2; + double dist = sqrt((xFinal * xFinal) + (yFinal * yFinal) + (zFinal * zFinal)); V8_RETURN_NUMBER(dist); } From bd670ea2ea2260b9643615f35567d713dfdacec7 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 19 Jun 2021 20:19:01 +0200 Subject: [PATCH 391/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index a422c452..33d05eb5 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit a422c4520b7e0197689e4e066ebf7c0f99ed9cea +Subproject commit 33d05eb570e996a5a888f25296d26082522458f8 From da65e849823052ed3c2aa74bfec457b2f959715a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 20 Jun 2021 01:19:57 +0200 Subject: [PATCH 392/564] Add check when converting struct arg to memory buffer --- src/bindings/V8Natives.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 5dce62e4..9f582393 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -225,8 +225,16 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native scrCtx->Push((char *)nullptr); break; case alt::INative::Type::ARG_STRUCT: - scrCtx->Push(ToMemoryBuffer(val, v8Ctx)); + { + auto buffer = ToMemoryBuffer(val, v8Ctx); + if(buffer != nullptr) scrCtx->Push(buffer); + else + { + v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); + Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + } break; + } default: Log::Error << "Unknown native arg type " << (int)argType << " (" << native->GetName() << ")" << Log::Endl; } From af93e375c20e970434349e6d533cbcd0b21ed3d5 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 20 Jun 2021 01:31:08 +0200 Subject: [PATCH 393/564] Add V8_GET_THIS_INTERNAL_FIELD_PTR macro --- V8Helpers.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/V8Helpers.h b/V8Helpers.h index d5824183..4842bc7b 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -284,6 +284,10 @@ namespace V8 #define V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(idx, val, type) \ auto val = static_cast(info.This()->GetInternalField((idx)-1).As()->Value()); +// idx starts with 1 +#define V8_GET_THIS_INTERNAL_FIELD_PTR(idx, val, type) \ + auto val = static_cast(info.This()->GetAlignedPointerFromInternalField((idx)-1)); + #define V8_CHECK_CONSTRUCTOR() V8_CHECK(info.IsConstructCall(), "function can't be called without new") #define V8_CHECK_ARGS_LEN(count) V8_CHECK(info.Length() == (count), #count " arguments expected") From 141c8b6549799f1a868e2440acd8281bac3f6a78 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 20 Jun 2021 01:44:21 +0200 Subject: [PATCH 394/564] Refactor MemoryBuffer --- src/bindings/MemoryBuffer.cpp | 72 +++++++++++++++-------------------- src/helpers | 2 +- 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/src/bindings/MemoryBuffer.cpp b/src/bindings/MemoryBuffer.cpp index a923503d..aaf5edd7 100644 --- a/src/bindings/MemoryBuffer.cpp +++ b/src/bindings/MemoryBuffer.cpp @@ -17,11 +17,9 @@ static void Constructor(const v8::FunctionCallbackInfo& info) { - v8::Isolate* isolate = info.GetIsolate(); - auto ctx = isolate->GetEnteredContext(); - - V8_CHECK(info.IsConstructCall(), "MemoryBuffer constructor is not a function"); - V8_CHECK(info.Length() == 1, "new MemoryBuffer(...) expects 1 arg"); + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN(1); // Ask alt:V to add pattern searching to C++ SDK if you want this available // if(info[0]->IsString()) @@ -37,8 +35,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) // } // else { - V8_CHECK(info[0]->IsNumber(), "size must be a number or a string pattern"); - uint32_t size = info[0]->Uint32Value(ctx).ToChecked(); + V8_ARG_TO_UINT32(1, size); if(size == 0) { info.This()->SetAlignedPointerInInternalField(0, nullptr); @@ -59,66 +56,57 @@ static void Constructor(const v8::FunctionCallbackInfo& info) static void FreeBuffer(const v8::FunctionCallbackInfo& info) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); - - uint8_t* memory = (uint8_t*)info.This()->GetAlignedPointerFromInternalField(0); + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_INTERNAL_FIELD_PTR(1, memory, uint8_t); if (memory != nullptr) { delete memory; info.This()->SetAlignedPointerInInternalField(0, nullptr); - info.GetReturnValue().Set(v8::Boolean::New(isolate, true)); + V8_RETURN_BOOLEAN(true); return; } - info.GetReturnValue().Set(v8::Boolean::New(isolate, false)); + V8_RETURN_BOOLEAN(false); } static void GetAddress(const v8::FunctionCallbackInfo& info) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); - - uintptr_t memory = (uintptr_t)info.This()->GetAlignedPointerFromInternalField(0); - info.GetReturnValue().Set(v8::BigInt::New(isolate, memory)); + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_INTERNAL_FIELD_PTR(1, memory, uint8_t); + V8_RETURN_INT64((uintptr_t)memory); } template static void GetDataOfType(const v8::FunctionCallbackInfo& info) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - auto ctx = isolate->GetEnteredContext(); - - V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); - V8_CHECK(resource, "Invalid resource"); + V8_GET_ISOLATE_CONTEXT_RESOURCE(); bool isString = false; if (std::is_same_v) { - V8_CHECK(info.Length() == 2, "2 args expected"); + V8_CHECK_ARGS_LEN(2); isString = true; } else { - V8_CHECK(info.Length() == 1, "1 arg expected"); + V8_CHECK_ARGS_LEN(1); } - V8_CHECK(info[0]->IsNumber(), "offset must be a number"); - uint32_t offset = info[0]->Uint32Value(ctx).ToChecked(); + V8_ARG_TO_UINT32(1, offset); uint32_t strLength = 0; - if (isString) - strLength = info[1]->Uint32Value(ctx).ToChecked(); + { + V8_ARG_TO_UINT32(2, len); + strLength = len; + } - uint8_t* memory = (uint8_t*)info.This()->GetAlignedPointerFromInternalField(0); - uint16_t size = info.This()->GetInternalField(1)->Uint32Value(isolate->GetEnteredContext()).ToChecked(); + V8_GET_THIS_INTERNAL_FIELD_PTR(1, memory, uint8_t); + V8_GET_THIS_INTERNAL_FIELD_UINT32(2, size); if (memory == nullptr || size == 0) { - info.GetReturnValue().Set(v8::Null(isolate)); + V8_RETURN_NULL(); return; } @@ -137,27 +125,27 @@ static void GetDataOfType(const v8::FunctionCallbackInfo& info) { if (std::is_same_v || std::is_same_v || std::is_same_v) { - info.GetReturnValue().Set(v8::Integer::NewFromUnsigned(isolate, *(uint32_t*)((uintptr_t)memory + offset))); + V8_RETURN_UINTEGER(*(uint32_t*)((uintptr_t)memory + offset)); return; } else if (std::is_same_v) { - info.GetReturnValue().Set(v8::BigInt::NewFromUnsigned(isolate, *(uint64_t*)((uintptr_t)memory + offset))); + V8_RETURN_UINT64(*(uint64_t*)((uintptr_t)memory + offset)); return; } else if (std::is_same_v || std::is_same_v || std::is_same_v) { - info.GetReturnValue().Set(v8::Integer::New(isolate, *(int32_t*)((uintptr_t)memory + offset))); + V8_RETURN_INTEGER(*(int32_t*)((uintptr_t)memory + offset)); return; } else if (std::is_same_v) { - info.GetReturnValue().Set(v8::BigInt::New(isolate, *(int64_t*)((uintptr_t)memory + offset))); + V8_RETURN_INT64(*(int64_t*)((uintptr_t)memory + offset)); return; } else if (std::is_same_v || std::is_same_v) { - info.GetReturnValue().Set(v8::Number::New(isolate, *(double*)((uintptr_t)memory + offset))); + V8_RETURN_NUMBER(*(double*)((uintptr_t)memory + offset)); return; } } @@ -166,7 +154,7 @@ static void GetDataOfType(const v8::FunctionCallbackInfo& info) char* newString = new char[strLength + 1]; memcpy_s(newString, strLength + 1, (void*)((uintptr_t)memory + offset), strLength); newString[strLength] = 0; - info.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, newString).ToLocalChecked()); + V8_RETURN_STRING(newString); delete newString; } } diff --git a/src/helpers b/src/helpers index 33d05eb5..af93e375 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 33d05eb570e996a5a888f25296d26082522458f8 +Subproject commit af93e375c20e970434349e6d533cbcd0b21ed3d5 From b3daf5f1c97f73dd6238191e855d8086eea24124 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 20 Jun 2021 01:47:14 +0200 Subject: [PATCH 395/564] Rename V8_RETURN_INTEGER to V8_RETURN_INT and V8_RETURN_UINTEGER to V8_RETURN_UINT --- V8BindHelpers.h | 12 ++++++------ V8Helpers.h | 4 ++-- bindings/BaseObject.cpp | 2 +- bindings/Entity.cpp | 2 +- bindings/Main.cpp | 10 +++++----- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/V8BindHelpers.h b/V8BindHelpers.h index 0f8a32fa..8dab667e 100644 --- a/V8BindHelpers.h +++ b/V8BindHelpers.h @@ -25,13 +25,13 @@ namespace V8 namespace detail { V8_CALL_GETTER(bool, V8_GET_ISOLATE, V8_RETURN_BOOLEAN); - V8_CALL_GETTER(uint8_t, V8_GET_ISOLATE, V8_RETURN_UINTEGER); - V8_CALL_GETTER(uint16_t, V8_GET_ISOLATE, V8_RETURN_UINTEGER); - V8_CALL_GETTER(uint32_t, V8_GET_ISOLATE, V8_RETURN_UINTEGER); + V8_CALL_GETTER(uint8_t, V8_GET_ISOLATE, V8_RETURN_UINT); + V8_CALL_GETTER(uint16_t, V8_GET_ISOLATE, V8_RETURN_UINT); + V8_CALL_GETTER(uint32_t, V8_GET_ISOLATE, V8_RETURN_UINT); V8_CALL_GETTER(uint64_t, V8_GET_ISOLATE, V8_RETURN_UINT64); - V8_CALL_GETTER(int8_t, V8_GET_ISOLATE, V8_RETURN_INTEGER); - V8_CALL_GETTER(int16_t, V8_GET_ISOLATE, V8_RETURN_INTEGER); - V8_CALL_GETTER(int32_t, V8_GET_ISOLATE, V8_RETURN_INTEGER); + V8_CALL_GETTER(int8_t, V8_GET_ISOLATE, V8_RETURN_INT); + V8_CALL_GETTER(int16_t, V8_GET_ISOLATE, V8_RETURN_INT); + V8_CALL_GETTER(int32_t, V8_GET_ISOLATE, V8_RETURN_INT); V8_CALL_GETTER(int64_t, V8_GET_ISOLATE, V8_RETURN_INT64); V8_CALL_GETTER(float, V8_GET_ISOLATE, V8_RETURN_NUMBER); V8_CALL_GETTER(double, V8_GET_ISOLATE, V8_RETURN_NUMBER); diff --git a/V8Helpers.h b/V8Helpers.h index 4842bc7b..ad8f357d 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -454,8 +454,8 @@ namespace V8 #define V8_RETURN(val) info.GetReturnValue().Set(val) #define V8_RETURN_NULL() V8_RETURN(v8::Null(isolate)) #define V8_RETURN_BOOLEAN(val) V8_RETURN(v8::Boolean::New(isolate, (val))) -#define V8_RETURN_INTEGER(val) V8_RETURN(v8::Integer::New(isolate, (val))) -#define V8_RETURN_UINTEGER(val) V8_RETURN(v8::Integer::NewFromUnsigned(isolate, (val))) +#define V8_RETURN_INT(val) V8_RETURN(v8::Integer::New(isolate, (val))) +#define V8_RETURN_UINT(val) V8_RETURN(v8::Integer::NewFromUnsigned(isolate, (val))) #define V8_RETURN_NUMBER(val) V8_RETURN(v8::Number::New(isolate, (val))) #define V8_RETURN_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val), v8::NewStringType::kNormal).ToLocalChecked()) #define V8_RETURN_ALT_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val).CStr(), v8::NewStringType::kNormal).ToLocalChecked()) diff --git a/bindings/BaseObject.cpp b/bindings/BaseObject.cpp index 5c5ded69..2e2de57e 100644 --- a/bindings/BaseObject.cpp +++ b/bindings/BaseObject.cpp @@ -13,7 +13,7 @@ static void TypeGetter(v8::Local, const v8::PropertyCallbackInfoGetType()); + V8_RETURN_INT((uint32_t)obj->GetType()); } static void ValidGetter(v8::Local, const v8::PropertyCallbackInfo &info) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index 17f681db..3fe9802c 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -62,7 +62,7 @@ static void ModelGetter(v8::Local, const v8::PropertyCallbackInfoGetModel()); + V8_RETURN_UINT(ent->GetModel()); } static void ModelSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 4d9f0d63..245463dc 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -9,7 +9,7 @@ static void HashCb(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_STRING(1, str); - V8_RETURN_UINTEGER(alt::ICore::Instance().Hash(str)); + V8_RETURN_UINT(alt::ICore::Instance().Hash(str)); } static void On(const v8::FunctionCallbackInfo &info) @@ -223,7 +223,7 @@ static void SetTimeout(const v8::FunctionCallbackInfo &info) V8_ARG_TO_FUNCTION(1, callback); V8_ARG_TO_INTEGER(2, time); - V8_RETURN_INTEGER(resource->CreateTimer(ctx, callback, time, true, V8::SourceLocation::GetCurrent(isolate))); + V8_RETURN_INT(resource->CreateTimer(ctx, callback, time, true, V8::SourceLocation::GetCurrent(isolate))); } static void SetInterval(const v8::FunctionCallbackInfo &info) @@ -235,7 +235,7 @@ static void SetInterval(const v8::FunctionCallbackInfo &info) V8_ARG_TO_FUNCTION(1, callback); V8_ARG_TO_INTEGER(2, time); - V8_RETURN_INTEGER(resource->CreateTimer(ctx, callback, time, false, V8::SourceLocation::GetCurrent(isolate))); + V8_RETURN_INT(resource->CreateTimer(ctx, callback, time, false, V8::SourceLocation::GetCurrent(isolate))); } static void NextTick(const v8::FunctionCallbackInfo &info) @@ -246,7 +246,7 @@ static void NextTick(const v8::FunctionCallbackInfo &info) V8_ARG_TO_FUNCTION(1, callback); - V8_RETURN_INTEGER(resource->CreateTimer(ctx, callback, 0, true, V8::SourceLocation::GetCurrent(isolate))); + V8_RETURN_INT(resource->CreateTimer(ctx, callback, 0, true, V8::SourceLocation::GetCurrent(isolate))); } static void EveryTick(const v8::FunctionCallbackInfo &info) @@ -257,7 +257,7 @@ static void EveryTick(const v8::FunctionCallbackInfo &info) V8_ARG_TO_FUNCTION(1, callback); - V8_RETURN_INTEGER(resource->CreateTimer(ctx, callback, 0, false, V8::SourceLocation::GetCurrent(isolate))); + V8_RETURN_INT(resource->CreateTimer(ctx, callback, 0, false, V8::SourceLocation::GetCurrent(isolate))); } static void ClearTimer(const v8::FunctionCallbackInfo &info) From 00ebf728e405b6d49521d1de3fee2d3e1cdf0363 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 20 Jun 2021 01:51:36 +0200 Subject: [PATCH 396/564] Update helpers --- src/bindings/Audio.cpp | 2 +- src/bindings/Blip.cpp | 18 +++++----- src/bindings/Checkpoint.cpp | 2 +- src/bindings/Handling.cpp | 12 +++---- src/bindings/Main.cpp | 14 ++++---- src/bindings/MemoryBuffer.cpp | 4 +-- src/bindings/Player.cpp | 18 +++++----- src/bindings/Vehicle.cpp | 60 ++++++++++++++++---------------- src/bindings/Voice.cpp | 2 +- src/bindings/WebSocketClient.cpp | 4 +-- src/helpers | 2 +- 11 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp index 9fa793d0..d3dc7d7d 100644 --- a/src/bindings/Audio.cpp +++ b/src/bindings/Audio.cpp @@ -139,7 +139,7 @@ static void CategoryGetter(v8::Local, const v8::PropertyCallbackInfo V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - V8_RETURN_UINTEGER(audio->GetCategory()); + V8_RETURN_UINT(audio->GetCategory()); } static void CategorySetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index b9b84834..152b3bf4 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -128,7 +128,7 @@ static void SpriteGetter(v8::Local, const v8::PropertyCallbackInfoGetSprite()); + V8_RETURN_INT(blip->GetSprite()); } static void SpriteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -143,7 +143,7 @@ static void ColorGetter(v8::Local, const v8::PropertyCallbackInfoGetColor()); + V8_RETURN_INT(blip->GetColor()); } static void ColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -178,7 +178,7 @@ static void AlphaGetter(v8::Local, const v8::PropertyCallbackInfoGetAlpha()); + V8_RETURN_INT(blip->GetAlpha()); } static void AlphaSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -193,7 +193,7 @@ static void FlashTimerGetter(v8::Local, const v8::PropertyCallbackIn { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INTEGER(blip->GetFlashTimer()); + V8_RETURN_INT(blip->GetFlashTimer()); } static void FlashTimerSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -208,7 +208,7 @@ static void FlashIntervalGetter(v8::Local, const v8::PropertyCallbac { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INTEGER(blip->GetFlashInterval()); + V8_RETURN_INT(blip->GetFlashInterval()); } static void FlashIntervalSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -268,7 +268,7 @@ static void NumberGetter(v8::Local, const v8::PropertyCallbackInfoGetNumber()); + V8_RETURN_INT(blip->GetNumber()); } static void NumberSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -283,7 +283,7 @@ static void DisplayGetter(v8::Local, const v8::PropertyCallbackInfo< { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INTEGER(blip->GetDisplay()); + V8_RETURN_INT(blip->GetDisplay()); } static void DisplaySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -358,7 +358,7 @@ static void PriorityGetter(v8::Local, const v8::PropertyCallbackInfo { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INTEGER(blip->GetPriority()); + V8_RETURN_INT(blip->GetPriority()); } static void PrioritySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -544,7 +544,7 @@ static void CategoryGetter(v8::Local, const v8::PropertyCallbackInfo { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INTEGER(blip->GetCategory()); + V8_RETURN_INT(blip->GetCategory()); } static void CategorySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index 05568312..63ec2735 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -59,7 +59,7 @@ static void TypeGetter(v8::Local, const v8::PropertyCallbackInfoGetCheckpointType()); + V8_RETURN_INT(cp->GetCheckpointType()); } static void TypeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) diff --git a/src/bindings/Handling.cpp b/src/bindings/Handling.cpp index 10d5f7df..9a5d9fd0 100644 --- a/src/bindings/Handling.cpp +++ b/src/bindings/Handling.cpp @@ -34,7 +34,7 @@ static void HandlingNameHashGetter(v8::Local, const v8::PropertyCall { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetHandling()->GetHandlingNameHash()); + V8_RETURN_INT(vehicle->GetHandling()->GetHandlingNameHash()); } static void MassGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -243,7 +243,7 @@ static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCal V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetHandling()->GetInitialDriveGears()); + V8_RETURN_INT(vehicle->GetHandling()->GetInitialDriveGears()); } static void InitialDriveGearsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) @@ -1143,7 +1143,7 @@ static void MonetaryValueGetter(v8::Local, const v8::PropertyCallbac V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetHandling()->GetMonetaryValue()); + V8_RETURN_INT(vehicle->GetHandling()->GetMonetaryValue()); } static void MonetaryValueSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) @@ -1161,7 +1161,7 @@ static void ModelFlagsGetter(v8::Local, const v8::PropertyCallbackIn V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetHandling()->GetModelFlags()); + V8_RETURN_INT(vehicle->GetHandling()->GetModelFlags()); } static void ModelFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) @@ -1178,7 +1178,7 @@ static void HandlingFlagsGetter(v8::Local, const v8::PropertyCallbac { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetHandling()->GetHandlingFlags()); + V8_RETURN_INT(vehicle->GetHandling()->GetHandlingFlags()); } static void HandlingFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) @@ -1195,7 +1195,7 @@ static void DamageFlagsGetter(v8::Local, const v8::PropertyCallbackI { V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetHandling()->GetDamageFlags()); + V8_RETURN_INT(vehicle->GetHandling()->GetDamageFlags()); } static void DamageFlagsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 6a834778..fb30e7ea 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -263,7 +263,7 @@ static void GetMsPerGameMinute(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE(info); - V8_RETURN_INTEGER(ICore::Instance().GetMsPerGameMinute()); + V8_RETURN_INT(ICore::Instance().GetMsPerGameMinute()); } static void SetMsPerGameMinute(const v8::FunctionCallbackInfo &info) @@ -442,7 +442,7 @@ static void GetCharStat(const v8::FunctionCallbackInfo &info) if (!strcmp(targetStat->GetStatType(), "INT")) { - V8_RETURN_INTEGER(targetStat->GetInt32Value()); + V8_RETURN_INT(targetStat->GetInt32Value()); return; } else if (!strcmp(targetStat->GetStatType(), "INT64")) @@ -452,7 +452,7 @@ static void GetCharStat(const v8::FunctionCallbackInfo &info) } else if (!strcmp(targetStat->GetStatType(), "TEXTLABEL")) { - V8_RETURN_INTEGER(targetStat->GetInt32Value()); + V8_RETURN_INT(targetStat->GetInt32Value()); return; } else if (!strcmp(targetStat->GetStatType(), "FLOAT")) @@ -472,17 +472,17 @@ static void GetCharStat(const v8::FunctionCallbackInfo &info) } else if (!strcmp(targetStat->GetStatType(), "UINT8")) { - V8_RETURN_UINTEGER(targetStat->GetUInt8Value()); + V8_RETURN_UINT(targetStat->GetUInt8Value()); return; } else if (!strcmp(targetStat->GetStatType(), "UINT16")) { - V8_RETURN_UINTEGER(targetStat->GetUInt16Value()); + V8_RETURN_UINT(targetStat->GetUInt16Value()); return; } else if (!strcmp(targetStat->GetStatType(), "UINT32")) { - V8_RETURN_UINTEGER(targetStat->GetUInt32Value()); + V8_RETURN_UINT(targetStat->GetUInt32Value()); return; } else if ( @@ -639,7 +639,7 @@ static void GetPermissionState(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_INTEGER(1, permnum); - V8_RETURN_INTEGER((uint8_t)alt::ICore::Instance().GetPermissionState((alt::Permission)permnum)); + V8_RETURN_INT((uint8_t)alt::ICore::Instance().GetPermissionState((alt::Permission)permnum)); } static void IsInStreamerMode(const v8::FunctionCallbackInfo &info) diff --git a/src/bindings/MemoryBuffer.cpp b/src/bindings/MemoryBuffer.cpp index aaf5edd7..1a07a8bd 100644 --- a/src/bindings/MemoryBuffer.cpp +++ b/src/bindings/MemoryBuffer.cpp @@ -125,7 +125,7 @@ static void GetDataOfType(const v8::FunctionCallbackInfo& info) { if (std::is_same_v || std::is_same_v || std::is_same_v) { - V8_RETURN_UINTEGER(*(uint32_t*)((uintptr_t)memory + offset)); + V8_RETURN_UINT(*(uint32_t*)((uintptr_t)memory + offset)); return; } else if (std::is_same_v) @@ -135,7 +135,7 @@ static void GetDataOfType(const v8::FunctionCallbackInfo& info) } else if (std::is_same_v || std::is_same_v || std::is_same_v) { - V8_RETURN_INTEGER(*(int32_t*)((uintptr_t)memory + offset)); + V8_RETURN_INT(*(int32_t*)((uintptr_t)memory + offset)); return; } else if (std::is_same_v) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index ec09c42c..5e13a939 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -77,7 +77,7 @@ static void CurrentWeaponTintIndexGetter(v8::Local, const v8::Proper V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_RETURN_INTEGER(player->GetCurrentWeaponTintIndex()); + V8_RETURN_INT(player->GetCurrentWeaponTintIndex()); } static void CurrentWeaponGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -85,7 +85,7 @@ static void CurrentWeaponGetter(v8::Local, const v8::PropertyCallbac V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_RETURN_UINTEGER(player->GetCurrentWeapon()); + V8_RETURN_UINT(player->GetCurrentWeapon()); } static void IsJumpingGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -133,7 +133,7 @@ static void ArmourGetter(v8::Local, const v8::PropertyCallbackInfoGetArmour()); + V8_RETURN_INT(player->GetArmour()); } static void MaxArmourGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -141,7 +141,7 @@ static void MaxArmourGetter(v8::Local, const v8::PropertyCallbackInf V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_RETURN_INTEGER(player->GetMaxArmour()); + V8_RETURN_INT(player->GetMaxArmour()); } static void MoveSpeedGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -173,7 +173,7 @@ static void SeatGetter(v8::Local, const v8::PropertyCallbackInfoGetSeat()); + V8_RETURN_INT(player->GetSeat()); } static void EntityAimingAtGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -205,7 +205,7 @@ static void HealthGetter(v8::Local, const v8::PropertyCallbackInfoGetHealth()); + V8_RETURN_INT(player->GetHealth()); } static void MaxHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -213,7 +213,7 @@ static void MaxHealthGetter(v8::Local, const v8::PropertyCallbackInf V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_RETURN_INTEGER(player->GetMaxHealth()); + V8_RETURN_INT(player->GetMaxHealth()); } static void IsDeadGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -244,7 +244,7 @@ static void GetWeaponTintIndex(const v8::FunctionCallbackInfo& info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_INTEGER(1, weaponHash); - V8_RETURN_INTEGER(player->GetWeaponTintIndex(weaponHash)); + V8_RETURN_INT(player->GetWeaponTintIndex(weaponHash)); } static void GetCurrentWeapon(const v8::FunctionCallbackInfo& info) @@ -252,7 +252,7 @@ static void GetCurrentWeapon(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_RETURN_INTEGER(player->GetCurrentWeapon()); + V8_RETURN_INT(player->GetCurrentWeapon()); } static void SpatialVolumeGetter(v8::Local, const v8::PropertyCallbackInfo& info) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 6140be8d..e2763b3a 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -49,7 +49,7 @@ static void GearGetter(v8::Local, const v8::PropertyCallbackInfoGetCurrentGear()); + V8_RETURN_INT(vehicle->GetCurrentGear()); } static void GearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) @@ -74,7 +74,7 @@ static void WheelsCountGetter(v8::Local, const v8::PropertyCallbackI V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetWheelsCount()); + V8_RETURN_INT(vehicle->GetWheelsCount()); } static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -106,7 +106,7 @@ static void ModKitsCountGetter(v8::Local, const v8::PropertyCallback V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetModKitsCount()); + V8_RETURN_INT(vehicle->GetModKitsCount()); } static void ModKitGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -114,7 +114,7 @@ static void ModKitGetter(v8::Local, const v8::PropertyCallbackInfoGetModKit()); + V8_RETURN_INT(vehicle->GetModKit()); } static void IsPrimaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -130,7 +130,7 @@ static void PrimaryColorGetter(v8::Local, const v8::PropertyCallback V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetPrimaryColor()); + V8_RETURN_INT(vehicle->GetPrimaryColor()); } static void PrimaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -154,7 +154,7 @@ static void SecondaryColorGetter(v8::Local, const v8::PropertyCallba V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetSecondaryColor()); + V8_RETURN_INT(vehicle->GetSecondaryColor()); } static void SecondaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -170,7 +170,7 @@ static void PearlColorGetter(v8::Local, const v8::PropertyCallbackIn V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetPearlColor()); + V8_RETURN_INT(vehicle->GetPearlColor()); } static void WheelColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -178,7 +178,7 @@ static void WheelColorGetter(v8::Local, const v8::PropertyCallbackIn V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetWheelColor()); + V8_RETURN_INT(vehicle->GetWheelColor()); } static void InteriorColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -186,7 +186,7 @@ static void InteriorColorGetter(v8::Local, const v8::PropertyCallbac V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetInteriorColor()); + V8_RETURN_INT(vehicle->GetInteriorColor()); } static void DashboardColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -194,7 +194,7 @@ static void DashboardColorGetter(v8::Local, const v8::PropertyCallba V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetDashboardColor()); + V8_RETURN_INT(vehicle->GetDashboardColor()); } static void IsTireSmokeColorCustomGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -218,7 +218,7 @@ static void WheelTypeGetter(v8::Local, const v8::PropertyCallbackInf V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetWheelType()); + V8_RETURN_INT(vehicle->GetWheelType()); } static void WheelVariationGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -226,7 +226,7 @@ static void WheelVariationGetter(v8::Local, const v8::PropertyCallba V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetWheelVariation()); + V8_RETURN_INT(vehicle->GetWheelVariation()); } static void RearWheelVariationGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -234,7 +234,7 @@ static void RearWheelVariationGetter(v8::Local, const v8::PropertyCa V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetRearWheelVariation()); + V8_RETURN_INT(vehicle->GetRearWheelVariation()); } static void IsCustomTiresGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -250,7 +250,7 @@ static void SpecialDarknessGetter(v8::Local, const v8::PropertyCallb V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetSpecialDarkness()); + V8_RETURN_INT(vehicle->GetSpecialDarkness()); } static void NumberplateIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -258,7 +258,7 @@ static void NumberplateIndexGetter(v8::Local, const v8::PropertyCall V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetNumberplateIndex()); + V8_RETURN_INT(vehicle->GetNumberplateIndex()); } static void NumberplateTextGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -274,7 +274,7 @@ static void WindowTintGetter(v8::Local, const v8::PropertyCallbackIn V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetWindowTint()); + V8_RETURN_INT(vehicle->GetWindowTint()); } static void DirtLevelGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -282,7 +282,7 @@ static void DirtLevelGetter(v8::Local, const v8::PropertyCallbackInf V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetDirtLevel()); + V8_RETURN_INT(vehicle->GetDirtLevel()); } static void IsNeonActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -323,7 +323,7 @@ static void LiveryGetter(v8::Local, const v8::PropertyCallbackInfoGetLivery()); + V8_RETURN_INT(vehicle->GetLivery()); } static void RoofLiveryGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -331,7 +331,7 @@ static void RoofLiveryGetter(v8::Local, const v8::PropertyCallbackIn V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetRoofLivery()); + V8_RETURN_INT(vehicle->GetRoofLivery()); } static void EngineOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -355,7 +355,7 @@ static void HeadlightColorGetter(v8::Local, const v8::PropertyCallba V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetHeadlightColor()); + V8_RETURN_INT(vehicle->GetHeadlightColor()); } static void RadioStationIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -363,7 +363,7 @@ static void RadioStationIndexGetter(v8::Local, const v8::PropertyCal V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetRadioStationIndex()); + V8_RETURN_INT(vehicle->GetRadioStationIndex()); } static void IsSirenActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -379,7 +379,7 @@ static void LockStateGetter(v8::Local, const v8::PropertyCallbackInf V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetLockState()); + V8_RETURN_INT(vehicle->GetLockState()); } static void IsDaylightOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -403,7 +403,7 @@ static void RoofStateGetter(v8::Local, const v8::PropertyCallbackInf V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetRoofState()); + V8_RETURN_INT(vehicle->GetRoofState()); } static void IsFlamethrowerActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -427,7 +427,7 @@ static void EngineHealthGetter(v8::Local, const v8::PropertyCallback V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetEngineHealth()); + V8_RETURN_INT(vehicle->GetEngineHealth()); } static void PetrolTankHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -435,7 +435,7 @@ static void PetrolTankHealthGetter(v8::Local, const v8::PropertyCall V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetPetrolTankHealth()); + V8_RETURN_INT(vehicle->GetPetrolTankHealth()); } static void RepairsCountGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -443,7 +443,7 @@ static void RepairsCountGetter(v8::Local, const v8::PropertyCallback V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetRepairsCount()); + V8_RETURN_INT(vehicle->GetRepairsCount()); } static void BodyHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -451,7 +451,7 @@ static void BodyHealthGetter(v8::Local, const v8::PropertyCallbackIn V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetBodyHealth()); + V8_RETURN_INT(vehicle->GetBodyHealth()); } static void BodyAdditionalHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -459,7 +459,7 @@ static void BodyAdditionalHealthGetter(v8::Local, const v8::Property V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetBodyAdditionalHealth()); + V8_RETURN_INT(vehicle->GetBodyAdditionalHealth()); } static void HasArmoredWindowsGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -542,7 +542,7 @@ static void MaxGearGetter(v8::Local, const v8::PropertyCallbackInfo< V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetMaxGear()); + V8_RETURN_INT(vehicle->GetMaxGear()); } static void MaxGearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) @@ -598,7 +598,7 @@ static void IndicatorLightsGetter(v8::Local, const v8::PropertyCallb V8_GET_ISOLATE(info); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - V8_RETURN_INTEGER(vehicle->GetLightsIndicator()); + V8_RETURN_INT(vehicle->GetLightsIndicator()); } static void IndicatorLightsSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) diff --git a/src/bindings/Voice.cpp b/src/bindings/Voice.cpp index d75c3468..f737cdf2 100644 --- a/src/bindings/Voice.cpp +++ b/src/bindings/Voice.cpp @@ -29,7 +29,7 @@ static void StaticGetVoiceActivationKey(v8::Local, const v8::Propert { V8_GET_ISOLATE_CONTEXT(); - V8_RETURN_UINTEGER(alt::ICore::Instance().GetVoiceActivationKey()); + V8_RETURN_UINT(alt::ICore::Instance().GetVoiceActivationKey()); } extern V8Class v8Voice("Voice", [](v8::Local tpl) { diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index a674501f..03c3f7b4 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -206,7 +206,7 @@ static void ReadyStateGetter(v8::Local property, const v8::PropertyC V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - V8_RETURN_UINTEGER(webSocket->GetReadyState()); + V8_RETURN_UINT(webSocket->GetReadyState()); } static void AutoReconnectSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -266,7 +266,7 @@ static void PingIntervalGetter(v8::Local property, const v8::Propert V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - V8_RETURN_UINTEGER(webSocket->GetPingInterval()); + V8_RETURN_UINT(webSocket->GetPingInterval()); } extern V8Class v8BaseObject; diff --git a/src/helpers b/src/helpers index af93e375..b3daf5f1 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit af93e375c20e970434349e6d533cbcd0b21ed3d5 +Subproject commit b3daf5f1c97f73dd6238191e855d8086eea24124 From 7cdfa2ef4557d5175e0a67f57375950e9dbc4760 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 20 Jun 2021 21:23:40 +0200 Subject: [PATCH 397/564] Prettier indentation in V8Timer --- V8Timer.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/V8Timer.h b/V8Timer.h index 8c317aa8..dd55594d 100644 --- a/V8Timer.h +++ b/V8Timer.h @@ -6,13 +6,13 @@ class V8Timer { public: - V8Timer(v8::Isolate *_isolate, v8::Local _context, int64_t curTime, v8::Local _callback, uint32_t _interval, bool _once, V8::SourceLocation &&_location) : isolate(_isolate), - context(_isolate, _context), - lastRun(curTime), - callback(_isolate, _callback), - interval(_interval), - once(_once), - location(std::move(_location)) + V8Timer(v8::Isolate *_isolate, v8::Local _context, int64_t curTime, v8::Local _callback, uint32_t _interval, bool _once, V8::SourceLocation &&_location) + : isolate(_isolate), + context(_isolate, _context), + lastRun(curTime), + callback(_isolate, _callback), + interval(_interval), once(_once), + location(std::move(_location)) { //Log::Debug << "Create timer: " << curTime << " " << interval << Log::Endl; } @@ -22,9 +22,7 @@ class V8Timer if (curTime - lastRun >= interval) { V8Helpers::TryCatch([&] { - v8::MaybeLocal result = callback.Get(isolate)->CallAsFunction(context.Get(isolate), - v8::Undefined(isolate), 0, nullptr); - + v8::MaybeLocal result = callback.Get(isolate)->CallAsFunction(context.Get(isolate), v8::Undefined(isolate), 0, nullptr); return !result.IsEmpty(); }); From 60f4351dcb5faf2cd319e70fc472ea17eeb26aef Mon Sep 17 00:00:00 2001 From: Leon B Date: Thu, 24 Jun 2021 16:45:03 +0200 Subject: [PATCH 398/564] Add build script (#50) * Add build script * Add missing newline * Fix path to extra build step file * Remove extra build step from build.bat Co-authored-by: Jovan Ivanovic --- .gitignore | 9 ++++++--- .vscode/settings.json | 6 +++++- .vscode/tasks.json | 12 +----------- tools/build.bat | 13 +++++++++++++ 4 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 tools/build.bat diff --git a/.gitignore b/.gitignore index c29aef7d..4ddf8e9d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ - +# Build files BUILD/ - deps/v8/ +dist/ +# Editors .vs/ - .vscode/settings.json + +# Extra +tools/extra.bat diff --git a/.vscode/settings.json b/.vscode/settings.json index 2e8e1f56..c44ef405 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -65,6 +65,10 @@ "xutility": "cpp", "deque": "cpp", "queue": "cpp", - "sstream": "cpp" + "sstream": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "set": "cpp" } } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 846d1ecb..1e31ce54 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,22 +6,12 @@ { "label": "Build", "type": "shell", - "command": "cmake --build BUILD --config Release", + "command": ".\\tools\\build.bat", "problemMatcher": ["$msCompile"], "group": { "kind": "build", "isDefault": true }, - }, - { - "label": "Build (Debug)", - "type": "shell", - "command": "cmake --build BUILD --config Debug", - "problemMatcher": ["$msCompile"], - "group": { - "kind": "build", - "isDefault": true - } } ] } diff --git a/tools/build.bat b/tools/build.bat new file mode 100644 index 00000000..41dcdee4 --- /dev/null +++ b/tools/build.bat @@ -0,0 +1,13 @@ +@echo off + +:: Build the project +cmake . -BBUILD +cmake --build BUILD --config Release + +:: Copy built binary to dist folder +IF NOT EXIST dist ( + mkdir dist +) +copy BUILD\Release\altv-client-js.dll dist +copy BUILD\Release\altv-client-js.lib dist +copy BUILD\Release\altv-client-js.pdb dist From fa6e4c0e7714d17f53665718a1c9bae81430ceed Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 24 Jun 2021 17:45:44 +0200 Subject: [PATCH 399/564] Push default value for native arg, if parsing failed --- src/bindings/V8Natives.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 9f582393..3738ed63 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -118,6 +118,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native { v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + scrCtx->Push(0); } } else if (val->IsBigInt()) @@ -131,17 +132,20 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native { v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + scrCtx->Push(0); } } else if (val->IsObject()) { auto ent = V8Entity::Get(val); if(ent != nullptr) scrCtx->Push(ent->GetHandle().As()->GetScriptGuid()); + else scrCtx->Push(0); } else { v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + scrCtx->Push(0); } break; } @@ -162,6 +166,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native { v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + scrCtx->Push(0); } } else if (val->IsBigInt()) @@ -175,12 +180,14 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native { v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + scrCtx->Push(0); } } else { v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + scrCtx->Push(0); } break; } @@ -201,12 +208,14 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native { v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + scrCtx->Push(0.f); } } else { v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + scrCtx->Push(0.f); } break; } @@ -232,6 +241,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native { v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + scrCtx->Push((void*)nullptr); } break; } From ced96219fa7454d7dc85a2e2f069093b4f73f94d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 25 Jun 2021 02:27:41 +0200 Subject: [PATCH 400/564] Add missing WebView getters (ready, focused, isOverlay) --- src/bindings/WebView.cpp | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index 912e66b0..c593112b 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -79,7 +79,7 @@ static void Emit(const v8::FunctionCallbackInfo &info) static void Focus(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); @@ -88,7 +88,7 @@ static void Focus(const v8::FunctionCallbackInfo &info) static void Unfocus(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); @@ -116,7 +116,7 @@ static void GetEventListeners(const v8::FunctionCallbackInfo& info) static void IsVisibleGetter(v8::Local property, const v8::PropertyCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); @@ -125,7 +125,7 @@ static void IsVisibleGetter(v8::Local property, const v8::PropertyCa static void IsVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); @@ -135,7 +135,7 @@ static void IsVisibleSetter(v8::Local property, v8::Local static void URLGetter(v8::Local property, const v8::PropertyCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); @@ -153,6 +153,33 @@ static void URLSetter(v8::Local property, v8::Local value view->SetUrl(url); } +static void OverlayGetter(v8::Local property, const v8::PropertyCallbackInfo &info) +{ + V8_GET_ISOLATE(); + + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); + + V8_RETURN_BOOLEAN(view->IsOverlay()); +} + +static void ReadyGetter(v8::Local property, const v8::PropertyCallbackInfo &info) +{ + V8_GET_ISOLATE(); + + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); + + V8_RETURN_BOOLEAN(view->IsReady()); +} + +static void FocusedGetter(v8::Local property, const v8::PropertyCallbackInfo &info) +{ + V8_GET_ISOLATE(); + + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); + + V8_RETURN_BOOLEAN(view->IsFocused()); +} + static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -235,6 +262,9 @@ extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local Date: Fri, 25 Jun 2021 12:48:39 +0200 Subject: [PATCH 401/564] Add WebView focused setter --- src/bindings/WebView.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index c593112b..e6a2a6dc 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -114,7 +114,7 @@ static void GetEventListeners(const v8::FunctionCallbackInfo& info) V8_RETURN(array); } -static void IsVisibleGetter(v8::Local property, const v8::PropertyCallbackInfo &info) +static void IsVisibleGetter(v8::Local, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE(); @@ -123,7 +123,7 @@ static void IsVisibleGetter(v8::Local property, const v8::PropertyCa V8_RETURN_BOOLEAN(view->IsVisible()); } -static void IsVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void IsVisibleSetter(v8::Local, v8::Local value, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE(); @@ -133,7 +133,7 @@ static void IsVisibleSetter(v8::Local property, v8::Local view->SetVisible(state); } -static void URLGetter(v8::Local property, const v8::PropertyCallbackInfo &info) +static void URLGetter(v8::Local, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE(); @@ -142,7 +142,7 @@ static void URLGetter(v8::Local property, const v8::PropertyCallback V8_RETURN_STRING(view->GetUrl().CStr()); } -static void URLSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo &info) +static void URLSetter(v8::Local, v8::Local value, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); @@ -153,7 +153,7 @@ static void URLSetter(v8::Local property, v8::Local value view->SetUrl(url); } -static void OverlayGetter(v8::Local property, const v8::PropertyCallbackInfo &info) +static void OverlayGetter(v8::Local, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE(); @@ -162,7 +162,7 @@ static void OverlayGetter(v8::Local property, const v8::PropertyCall V8_RETURN_BOOLEAN(view->IsOverlay()); } -static void ReadyGetter(v8::Local property, const v8::PropertyCallbackInfo &info) +static void ReadyGetter(v8::Local, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE(); @@ -171,7 +171,7 @@ static void ReadyGetter(v8::Local property, const v8::PropertyCallba V8_RETURN_BOOLEAN(view->IsReady()); } -static void FocusedGetter(v8::Local property, const v8::PropertyCallbackInfo &info) +static void FocusedGetter(v8::Local, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE(); @@ -180,6 +180,18 @@ static void FocusedGetter(v8::Local property, const v8::PropertyCall V8_RETURN_BOOLEAN(view->IsFocused()); } +static void FocusedSetter(v8::Local, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); + + V8_TO_BOOLEAN(value, shouldBeFocused); + + if(shouldBeFocused) view->Focus(); + else view->Unfocus(); +} + static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -264,7 +276,7 @@ extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local Date: Fri, 25 Jun 2021 14:41:14 +0200 Subject: [PATCH 402/564] Rename WebView ready to isReady --- src/bindings/WebView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index e6a2a6dc..46949e97 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -275,7 +275,7 @@ extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local Date: Sat, 26 Jun 2021 14:53:39 +0200 Subject: [PATCH 403/564] Remove duplicate code --- bindings/Main.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 245463dc..85cdad26 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -373,19 +373,10 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8Helpers::RegisterFunc(exports, "hasResource", &HasResource); -#ifdef ALT_SERVER_API V8::DefineOwnProperty(isolate, ctx, exports, "version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); V8::DefineOwnProperty(isolate, ctx, exports, "branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); - alt::IResource* resource = V8ResourceImpl::GetResource(ctx); - V8::DefineOwnProperty(isolate, ctx, exports, "resourceName", v8::String::NewFromUtf8(isolate, resource->GetName().CStr()).ToLocalChecked()); -#else - V8::DefineOwnProperty(isolate, ctx, exports, "version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); - V8::DefineOwnProperty(isolate, ctx, exports, "branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); - - alt::IResource* resource = V8ResourceImpl::GetResource(ctx); - V8::DefineOwnProperty(isolate, ctx, exports, "resourceName", v8::String::NewFromUtf8(isolate, resource->GetName().CStr()).ToLocalChecked()); -#endif + V8::DefineOwnProperty(isolate, ctx, exports, "resourceName", v8::String::NewFromUtf8(isolate, V8ResourceImpl::GetResource(ctx)->GetName().CStr()).ToLocalChecked()); V8::DefineOwnProperty(isolate, ctx, exports, "sdkVersion", v8::Integer::New(isolate, alt::ICore::Instance().SDK_VERSION)); From 29944aafd827a7b5afeea0477cdcefcc25bd6220 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 26 Jun 2021 17:22:42 +0200 Subject: [PATCH 404/564] Add helper to get type name of JS value --- V8Helpers.cpp | 32 ++++++++++++++++++++++++++++++++ V8Helpers.h | 1 + 2 files changed, 33 insertions(+) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 43ba8013..d3b41dff 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -783,3 +783,35 @@ alt::String V8::Stringify(v8::Local val, v8::Local ctx) } return *v8::String::Utf8Value(ctx->GetIsolate(), str); } + +alt::String V8::GetJSValueTypeName(v8::Local val) +{ + if(val->IsUndefined()) return "undefined"; + if(val->IsNull()) return "null"; + if(val->IsNumber()) return "number"; + if(val->IsString()) return "string"; + if(val->IsArray()) return "array"; + if(val->IsBoolean()) return "bool"; + if(val->IsBigInt()) return "bigint"; + if(val->IsArrayBuffer()) return "arraybuffer"; + if(val->IsArrayBufferView()) return "arraybufferview"; + if(val->IsDate()) return "date"; + if(val->IsArgumentsObject()) return "arguments"; + if(val->IsAsyncFunction()) return "asyncfunction"; + if(val->IsExternal()) return "external"; + if(val->IsDataView()) return "dataview"; + if(val->IsSymbol()) return "symbol"; + if(val->IsFunction()) return "function"; + if(val->IsRegExp()) return "regexp"; + if(val->IsGeneratorFunction()) return "generatorfunction"; + if(val->IsPromise()) return "promise"; + if(val->IsProxy()) return "proxy"; + if(val->IsMap()) return "map"; + if(val->IsSet()) return "set"; + if(val->IsWeakMap()) return "weakmap"; + if(val->IsWeakSet()) return "weakset"; + if(val->IsTypedArray()) return "typedarray"; + if(val->IsProxy()) return "proxy"; + if(val->IsObject()) return "object"; + else return "unknown"; +} \ No newline at end of file diff --git a/V8Helpers.h b/V8Helpers.h index ad8f357d..3af3e902 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -219,6 +219,7 @@ namespace V8 } alt::String Stringify(v8::Local val, v8::Local ctx); + alt::String GetJSValueTypeName(v8::Local val); } // namespace V8 #define V8_GET_ISOLATE() v8::Isolate *isolate = info.GetIsolate() From 8a749833f47b60a1c808d578d0e9a8eed03bdcc3 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 26 Jun 2021 17:26:04 +0200 Subject: [PATCH 405/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index b3daf5f1..29944aaf 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit b3daf5f1c97f73dd6238191e855d8086eea24124 +Subproject commit 29944aafd827a7b5afeea0477cdcefcc25bd6220 From 4265e5a039cc4b5fc999c52c6eb812de9e8ae3a0 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 26 Jun 2021 17:28:15 +0200 Subject: [PATCH 406/564] Use helper to get type name in native conversion error msg --- src/bindings/V8Natives.cpp | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 3738ed63..97e20140 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -116,8 +116,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); - Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; scrCtx->Push(0); } } @@ -130,8 +129,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); - Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; scrCtx->Push(0); } } @@ -143,8 +141,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); - Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; scrCtx->Push(0); } break; @@ -164,8 +161,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); - Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; scrCtx->Push(0); } } @@ -178,15 +174,13 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); - Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; scrCtx->Push(0); } } else { - v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); - Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; scrCtx->Push(0); } break; @@ -206,15 +200,13 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); - Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; scrCtx->Push(0.f); } } else { - v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); - Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; scrCtx->Push(0.f); } break; @@ -239,8 +231,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native if(buffer != nullptr) scrCtx->Push(buffer); else { - v8::String::Utf8Value type(isolate, val->TypeOf(isolate)); - Log::Error << "Native argument " << "(" << *type << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; scrCtx->Push((void*)nullptr); } break; From c486b7a4acf0000edb0ee0375950d01838043f4e Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 28 Jun 2021 22:22:17 +0200 Subject: [PATCH 407/564] update client js --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index a6e7d7b0..ea2b6124 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit a6e7d7b0e818f07b18b0c658075398ed3f1c745b +Subproject commit ea2b612451f0992063d6ad60b2026b78a00ca415 From e27f193e685fcc16414f4afe357c53a6e2dadfce Mon Sep 17 00:00:00 2001 From: Vektor Date: Mon, 28 Jun 2021 22:39:55 +0200 Subject: [PATCH 408/564] update cpp-sdk --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index ea2b6124..a9cbb4d0 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit ea2b612451f0992063d6ad60b2026b78a00ca415 +Subproject commit a9cbb4d0decb17fec6b76f3a404f8f43168e80b8 From 25141878a43bc201d33a05258aa282707a430353 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 3 Jul 2021 01:18:39 +0200 Subject: [PATCH 409/564] Add SafeToArray helper --- V8Helpers.cpp | 13 ++++++++++++- V8Helpers.h | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index d3b41dff..cf0e7208 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -721,6 +721,17 @@ bool V8::SafeToArrayBufferView(v8::Local val, v8::Local return false; } +bool V8::SafeToArray(v8::Local val, v8::Local ctx, v8::Local& out) +{ + if (val->IsArray()) + { + out = val.As(); + return true; + } + + return false; +} + std::vector V8::EventHandler::GetCallbacks(V8ResourceImpl *impl, const alt::CEvent *e) { return callbacksGetter(impl, e); @@ -814,4 +825,4 @@ alt::String V8::GetJSValueTypeName(v8::Local val) if(val->IsProxy()) return "proxy"; if(val->IsObject()) return "object"; else return "unknown"; -} \ No newline at end of file +} diff --git a/V8Helpers.h b/V8Helpers.h index 3af3e902..39308e6d 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -198,6 +198,7 @@ namespace V8 bool SafeToVector2(v8::Local val, v8::Local ctx, alt::Vector2f& out); bool SafeToArrayBuffer(v8::Local val, v8::Local ctx, v8::Local& out); bool SafeToArrayBufferView(v8::Local val, v8::Local ctx, v8::Local& out); + bool SafeToArray(v8::Local val, v8::Local ctx, v8::Local& out); bool SafeToUInt64(v8::Local val, v8::Local ctx, uint64_t& out); bool SafeToInt64(v8::Local val, v8::Local ctx, int64_t& out); @@ -427,6 +428,10 @@ namespace V8 v8::Local val; \ V8_CHECK(V8::SafeToArrayBufferView(info[(idx) - 1], ctx, val), "Failed to convert argument " #idx " to ArrayBufferView") +#define V8_ARG_TO_ARRAY(idx, val) \ + v8::Local val; \ + V8_CHECK(V8::SafeToArray(info[(idx) - 1], ctx, val), "Failed to convert argument " #idx " to Array") + // idx starts with 1 #define V8_ARG_TO_UINT64(idx, val) \ uint64_t val; \ From c46bb305bafca4506e75f1e1255fee4c59b23721 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 3 Jul 2021 01:19:12 +0200 Subject: [PATCH 410/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 29944aaf..25141878 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 29944aafd827a7b5afeea0477cdcefcc25bd6220 +Subproject commit 25141878a43bc201d33a05258aa282707a430353 From 4b532591ddd3f08809172d55f8db029a05f36252 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 3 Jul 2021 01:19:32 +0200 Subject: [PATCH 411/564] Cleanup SetWeatherCycle --- src/bindings/Main.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index fb30e7ea..23034355 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -296,31 +296,26 @@ static void GetLocale(const v8::FunctionCallbackInfo &info) static void SetWeatherCycle(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(2); - V8_CHECK(info.Length() == 2, "2 args expected"); - V8_CHECK(info[0]->IsArray(), "weathers must be an array"); - V8_CHECK(info[1]->IsArray(), "timeMultipliers must be an array"); - - v8::Local weathers = info[0].As(); - v8::Local multipliers = info[1].As(); + V8_ARG_TO_ARRAY(1, weathers); + V8_ARG_TO_ARRAY(2, multipliers); - V8_CHECK(weathers->Length() <= 256, "weathers count must be <= 256"); - V8_CHECK(multipliers->Length() <= 256, "multipliers count must be <= 256"); - V8_CHECK(weathers->Length() == multipliers->Length(), "weathers count and multipliers count must be the same"); + V8_CHECK(weathers->Length() < 256, "Weathers array size must be <= 255"); + V8_CHECK(multipliers->Length() < 256, "Multipliers array size must be <= 255"); + V8_CHECK(weathers->Length() == multipliers->Length(), "Weathers and multipliers array has to be the same size"); Array weathersVec; Array multipliersVec; for (int i = 0; i < weathers->Length(); ++i) { - v8::Local weatherVal = weathers->Get(ctx, i).ToLocalChecked(); - uint32_t weatherNum = weatherVal->ToUint32(ctx).ToLocalChecked()->Value(); + V8_TO_INTEGER(weathers->Get(ctx, i).ToLocalChecked(), weatherNum); V8_CHECK(weatherNum >= 0 && weatherNum <= 14, "weather ids must be >= 0 && <= 14"); weathersVec.Push(weatherNum); - v8::Local multiplierVal = multipliers->Get(ctx, i).ToLocalChecked(); - uint32_t multiplierNum = multiplierVal->ToUint32(ctx).ToLocalChecked()->Value(); - V8_CHECK(multiplierNum > 0 && multiplierNum <= 720, "multipliers must be > 0 && <= 720"); + V8_TO_INTEGER(multipliers->Get(ctx, i).ToLocalChecked(), multiplierNum); + V8_CHECK(multiplierNum > 0 && multiplierNum < 256, "multipliers must be > 0 && <= 255"); multipliersVec.Push(multiplierNum); } From 804840d929d3e72ab577c4a3b62839cec1ebf4f3 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 4 Jul 2021 01:34:31 +0200 Subject: [PATCH 412/564] Use static Instance() method instead of static property for runtime class --- src/CV8Resource.cpp | 2 +- src/CV8ScriptRuntime.cpp | 6 +----- src/CV8ScriptRuntime.h | 7 ++++++- src/bindings/HttpClient.cpp | 18 +++++++++--------- src/bindings/Main.cpp | 4 ++-- src/bindings/Player.cpp | 2 +- src/bindings/Vehicle.cpp | 2 +- src/events/Entity.cpp | 4 ++-- src/events/Main.cpp | 8 ++++---- src/main.cpp | 8 ++++---- 10 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 22f0ff40..2e29de1b 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -166,7 +166,7 @@ bool CV8ResourceImpl::Start() DispatchStartEvent(!result); // if all resources are already loaded - if(CV8ScriptRuntime::instance->resourcesLoaded) { + if(CV8ScriptRuntime::Instance().resourcesLoaded) { ProcessDynamicImports(); } diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 98cfc67f..d3afd6c9 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -5,12 +5,8 @@ #include "helpers/V8Module.h" #include "events/Events.h" -CV8ScriptRuntime* CV8ScriptRuntime::instance = nullptr; - CV8ScriptRuntime::CV8ScriptRuntime() { - instance = this; - platform = v8::platform::NewDefaultPlatform(); v8::V8::InitializePlatform(platform.get()); v8::V8::Initialize(); @@ -114,7 +110,7 @@ CV8ScriptRuntime::CV8ScriptRuntime() }); }; - if(instance->resourcesLoaded && resource->GetResource()->IsStarted()) + if(Instance().resourcesLoaded && resource->GetResource()->IsStarted()) { // instantly resolve the module domodule(); diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 4ffb842c..5c41bf9a 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -27,10 +27,15 @@ class CV8ScriptRuntime : public alt::IScriptRuntime std::unordered_map> streamedInVehicles; public: - static CV8ScriptRuntime* instance; CV8ScriptRuntime(); + static CV8ScriptRuntime& Instance() + { + static CV8ScriptRuntime instance; + return instance; + } + v8::Isolate *GetIsolate() const { return isolate; } v8_inspector::V8Inspector *GetInspector() const { return inspector.get(); } diff --git a/src/bindings/HttpClient.cpp b/src/bindings/HttpClient.cpp index bedfc38c..4b0697ed 100644 --- a/src/bindings/HttpClient.cpp +++ b/src/bindings/HttpClient.cpp @@ -53,7 +53,7 @@ static void Get(const v8::FunctionCallbackInfo& info) auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD - v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Isolate* isolate = CV8ScriptRuntime::Instance().GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -95,7 +95,7 @@ static void Head(const v8::FunctionCallbackInfo& info) auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD - v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Isolate* isolate = CV8ScriptRuntime::Instance().GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -138,7 +138,7 @@ static void Post(const v8::FunctionCallbackInfo& info) auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD - v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Isolate* isolate = CV8ScriptRuntime::Instance().GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -181,7 +181,7 @@ static void Put(const v8::FunctionCallbackInfo& info) auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD - v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Isolate* isolate = CV8ScriptRuntime::Instance().GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -224,7 +224,7 @@ static void Delete(const v8::FunctionCallbackInfo& info) auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD - v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Isolate* isolate = CV8ScriptRuntime::Instance().GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -267,7 +267,7 @@ static void Connect(const v8::FunctionCallbackInfo& info) auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD - v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Isolate* isolate = CV8ScriptRuntime::Instance().GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -310,7 +310,7 @@ static void Options(const v8::FunctionCallbackInfo& info) auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD - v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Isolate* isolate = CV8ScriptRuntime::Instance().GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -353,7 +353,7 @@ static void Trace(const v8::FunctionCallbackInfo& info) auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD - v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Isolate* isolate = CV8ScriptRuntime::Instance().GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -396,7 +396,7 @@ static void Patch(const v8::FunctionCallbackInfo& info) auto callback = [](alt::IHttpClient::HttpResponse response, const void* userData) { // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD - v8::Isolate* isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Isolate* isolate = CV8ScriptRuntime::Instance().GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 23034355..08ecb905 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -660,7 +660,7 @@ static void TakeScreenshot(const v8::FunctionCallbackInfo &info) api.TakeScreenshot([](alt::StringView base64, const void *userData) { // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD - v8::Isolate *isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Isolate *isolate = CV8ScriptRuntime::Instance().GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -695,7 +695,7 @@ static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &in api.TakeScreenshotGameOnly([](alt::StringView base64, const void *userData) { // TODO: NOT PERFORMANCE EFFICIENT TO LOCK HERE, RESOLVE IN NEXT TICK INSTEAD - v8::Isolate *isolate = CV8ScriptRuntime::instance->GetIsolate(); + v8::Isolate *isolate = CV8ScriptRuntime::Instance().GetIsolate(); v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 5e13a939..8b0b57bc 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -302,7 +302,7 @@ static void StreamedInGetter(v8::Local name, const v8::PropertyCallb { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - auto streamedIn = CV8ScriptRuntime::instance->GetStreamedInPlayers(); + auto streamedIn = CV8ScriptRuntime::Instance().GetStreamedInPlayers(); auto arr = v8::Array::New(isolate, streamedIn.size()); int i = 0; for(auto kv : streamedIn) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index e2763b3a..80a5f998 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -565,7 +565,7 @@ static void StreamedInGetter(v8::Local name, const v8::PropertyCallb { V8_GET_ISOLATE_CONTEXT_RESOURCE(); - auto streamedIn = CV8ScriptRuntime::instance->GetStreamedInVehicles(); + auto streamedIn = CV8ScriptRuntime::Instance().GetStreamedInVehicles(); auto arr = v8::Array::New(isolate, streamedIn.size()); int i = 0; for(auto kv : streamedIn) diff --git a/src/events/Entity.cpp b/src/events/Entity.cpp index a61191aa..af5a3344 100644 --- a/src/events/Entity.cpp +++ b/src/events/Entity.cpp @@ -25,7 +25,7 @@ V8_LOCAL_EVENT_HANDLER removeEntity( V8_EVENT_HANDLER gameEntityCreate( EventType::GAME_ENTITY_CREATE, [](V8ResourceImpl* resource, const alt::CEvent* e) { - CV8ScriptRuntime::instance->OnEntityStreamIn(static_cast(e)->GetTarget()); + CV8ScriptRuntime::Instance().OnEntityStreamIn(static_cast(e)->GetTarget()); return resource->GetLocalHandlers("gameEntityCreate"); }, @@ -39,7 +39,7 @@ V8_EVENT_HANDLER gameEntityCreate( V8_EVENT_HANDLER gameEntityDestroy( EventType::GAME_ENTITY_DESTROY, [](V8ResourceImpl* resource, const alt::CEvent* e) { - CV8ScriptRuntime::instance->OnEntityStreamOut(static_cast(e)->GetTarget()); + CV8ScriptRuntime::Instance().OnEntityStreamOut(static_cast(e)->GetTarget()); return resource->GetLocalHandlers("gameEntityDestroy"); }, diff --git a/src/events/Main.cpp b/src/events/Main.cpp index cbde1d0f..018d8584 100644 --- a/src/events/Main.cpp +++ b/src/events/Main.cpp @@ -115,10 +115,10 @@ V8_LOCAL_EVENT_HANDLER connectionComplete( EventType::CONNECTION_COMPLETE, "connectionComplete", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { - CV8ScriptRuntime* runtime = CV8ScriptRuntime::instance; - if(!runtime->resourcesLoaded) + CV8ScriptRuntime& runtime = CV8ScriptRuntime::Instance(); + if(!runtime.resourcesLoaded) { - runtime->resourcesLoaded = true; + runtime.resourcesLoaded = true; static_cast(resource)->ProcessDynamicImports(); } }); @@ -127,5 +127,5 @@ V8_LOCAL_EVENT_HANDLER disconnect( EventType::DISCONNECT_EVENT, "disconnect", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { - CV8ScriptRuntime::instance->resourcesLoaded = false; + CV8ScriptRuntime::Instance().resourcesLoaded = false; }); diff --git a/src/main.cpp b/src/main.cpp index 712972d7..05a8503b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,12 +51,12 @@ static void ClientJSCommand(alt::Array args, void*) ALTV_JS_EXPORT void CreateScriptRuntime(alt::ICore *core) { alt::ICore::SetInstance(core); - auto runtime = new CV8ScriptRuntime(); - core->RegisterScriptRuntime("js", runtime); + auto& runtime = CV8ScriptRuntime::Instance(); + core->RegisterScriptRuntime("js", &runtime); // Commands - core->SubscribeCommand("heap", &HeapCommand, runtime); - core->SubscribeCommand("timers", &TimersCommand, runtime); + core->SubscribeCommand("heap", &HeapCommand, &runtime); + core->SubscribeCommand("timers", &TimersCommand, &runtime); core->SubscribeCommand("js-module", &ClientJSCommand); } From 8b47fdbb9cbb89a75991d2e3725e32ce448d2236 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 6 Jul 2021 00:58:09 +0200 Subject: [PATCH 413/564] Update V8_GET_ISOLATE macro everywhere --- src/bindings/Main.cpp | 12 ++-- src/bindings/MapZoomData.cpp | 2 +- src/bindings/Player.cpp | 38 ++++++------ src/bindings/Vehicle.cpp | 102 +++++++++++++++---------------- src/bindings/WebSocketClient.cpp | 14 ++--- 5 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 08ecb905..74ab99f1 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -86,7 +86,7 @@ static void EmitServer(const v8::FunctionCallbackInfo &info) static void GameControlsEnabled(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_RETURN_BOOLEAN(alt::ICore::Instance().AreControlsEnabled()); } @@ -261,7 +261,7 @@ static void GetGxtText(const v8::FunctionCallbackInfo &info) static void GetMsPerGameMinute(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_RETURN_INT(ICore::Instance().GetMsPerGameMinute()); } @@ -324,7 +324,7 @@ static void SetWeatherCycle(const v8::FunctionCallbackInfo &info) static void SetWeatherSyncActive(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_CHECK_ARGS_LEN(1); V8_ARG_TO_BOOLEAN(1, isActive); @@ -511,13 +511,13 @@ static void ResetCharStat(const v8::FunctionCallbackInfo &info) static void IsMenuOpen(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_RETURN_BOOLEAN(ICore::Instance().IsMenuOpen()); } static void IsConsoleOpen(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_RETURN_BOOLEAN(ICore::Instance().IsConsoleOpen()); } @@ -639,7 +639,7 @@ static void GetPermissionState(const v8::FunctionCallbackInfo &info) static void IsInStreamerMode(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_RETURN_BOOLEAN(alt::ICore::Instance().IsInStreamerMode()); } diff --git a/src/bindings/MapZoomData.cpp b/src/bindings/MapZoomData.cpp index 5af47447..06490891 100644 --- a/src/bindings/MapZoomData.cpp +++ b/src/bindings/MapZoomData.cpp @@ -34,7 +34,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) static void Get(const v8::FunctionCallbackInfo &info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_CHECK_ARGS_LEN(1); V8_CHECK(info[0]->IsNumber() || info[0]->IsString(), "zoomDataId must be a number or string"); diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 8b0b57bc..df795840 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -27,7 +27,7 @@ static void ToString(const v8::FunctionCallbackInfo& info) static void NameGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_STRING(player->GetName().CStr()); @@ -43,7 +43,7 @@ static void VehicleGetter(v8::Local, const v8::PropertyCallbackInfo< static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_BOOLEAN(player->IsTalking()); @@ -51,7 +51,7 @@ static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo< static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_NUMBER(player->GetMicLevel()); @@ -74,7 +74,7 @@ static void CurrentWeaponComponentsGetter(v8::Local, const v8::Prope static void CurrentWeaponTintIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_INT(player->GetCurrentWeaponTintIndex()); @@ -82,7 +82,7 @@ static void CurrentWeaponTintIndexGetter(v8::Local, const v8::Proper static void CurrentWeaponGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_UINT(player->GetCurrentWeapon()); @@ -90,7 +90,7 @@ static void CurrentWeaponGetter(v8::Local, const v8::PropertyCallbac static void IsJumpingGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_BOOLEAN(player->IsJumping()); @@ -98,7 +98,7 @@ static void IsJumpingGetter(v8::Local, const v8::PropertyCallbackInf static void IsInRagdollGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_BOOLEAN(player->IsInRagdoll()); @@ -106,7 +106,7 @@ static void IsInRagdollGetter(v8::Local, const v8::PropertyCallbackI static void IsAimingGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_BOOLEAN(player->IsAiming()); @@ -114,7 +114,7 @@ static void IsAimingGetter(v8::Local, const v8::PropertyCallbackInfo static void IsShootingGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_BOOLEAN(player->IsShooting()); @@ -122,7 +122,7 @@ static void IsShootingGetter(v8::Local, const v8::PropertyCallbackIn static void IsReloadingGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_BOOLEAN(player->IsReloading()); @@ -130,7 +130,7 @@ static void IsReloadingGetter(v8::Local, const v8::PropertyCallbackI static void ArmourGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_INT(player->GetArmour()); @@ -138,7 +138,7 @@ static void ArmourGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_INT(player->GetMaxArmour()); @@ -146,7 +146,7 @@ static void MaxArmourGetter(v8::Local, const v8::PropertyCallbackInf static void MoveSpeedGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_NUMBER(player->GetMoveSpeed()); @@ -170,7 +170,7 @@ static void HeadRotationGetter(v8::Local, const v8::PropertyCallback static void SeatGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_INT(player->GetSeat()); @@ -194,7 +194,7 @@ static void EntityAimOffsetGetter(v8::Local, const v8::PropertyCallb static void FlashlightActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_BOOLEAN(player->IsFlashlightActive()); @@ -202,7 +202,7 @@ static void FlashlightActiveGetter(v8::Local, const v8::PropertyCall static void HealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_INT(player->GetHealth()); @@ -210,7 +210,7 @@ static void HealthGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_INT(player->GetMaxHealth()); @@ -218,7 +218,7 @@ static void MaxHealthGetter(v8::Local, const v8::PropertyCallbackInf static void IsDeadGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_BOOLEAN(player->IsDead()); @@ -249,7 +249,7 @@ static void GetWeaponTintIndex(const v8::FunctionCallbackInfo& info) static void GetCurrentWeapon(const v8::FunctionCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_RETURN_INT(player->GetCurrentWeapon()); diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 80a5f998..8ac7417d 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -38,7 +38,7 @@ static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_NUMBER(vehicle->GetWheelSpeed()); @@ -46,7 +46,7 @@ static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetCurrentGear()); @@ -63,7 +63,7 @@ static void GearSetter(v8::Local, v8::Local val, const v8 static void RPMGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_NUMBER(vehicle->GetCurrentRPM()); @@ -71,7 +71,7 @@ static void RPMGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetWheelsCount()); @@ -95,7 +95,7 @@ static void DriverGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsDestroyed()); @@ -103,7 +103,7 @@ static void IsDestroyedGetter(v8::Local, const v8::PropertyCallbackI static void ModKitsCountGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetModKitsCount()); @@ -111,7 +111,7 @@ static void ModKitsCountGetter(v8::Local, const v8::PropertyCallback static void ModKitGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetModKit()); @@ -119,7 +119,7 @@ static void ModKitGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsPrimaryColorRGB()); @@ -127,7 +127,7 @@ static void IsPrimaryColorRGBGetter(v8::Local, const v8::PropertyCal static void PrimaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetPrimaryColor()); @@ -143,7 +143,7 @@ static void PrimaryColorRGBGetter(v8::Local, const v8::PropertyCallb static void IsSecondaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsSecondaryColorRGB()); @@ -151,7 +151,7 @@ static void IsSecondaryColorRGBGetter(v8::Local, const v8::PropertyC static void SecondaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetSecondaryColor()); @@ -167,7 +167,7 @@ static void SecondaryColorRGBGetter(v8::Local, const v8::PropertyCal static void PearlColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetPearlColor()); @@ -175,7 +175,7 @@ static void PearlColorGetter(v8::Local, const v8::PropertyCallbackIn static void WheelColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetWheelColor()); @@ -183,7 +183,7 @@ static void WheelColorGetter(v8::Local, const v8::PropertyCallbackIn static void InteriorColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetInteriorColor()); @@ -191,7 +191,7 @@ static void InteriorColorGetter(v8::Local, const v8::PropertyCallbac static void DashboardColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetDashboardColor()); @@ -199,7 +199,7 @@ static void DashboardColorGetter(v8::Local, const v8::PropertyCallba static void IsTireSmokeColorCustomGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsTireSmokeColorCustom()); @@ -215,7 +215,7 @@ static void TireSmokeColorGetter(v8::Local, const v8::PropertyCallba static void WheelTypeGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetWheelType()); @@ -223,7 +223,7 @@ static void WheelTypeGetter(v8::Local, const v8::PropertyCallbackInf static void WheelVariationGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetWheelVariation()); @@ -231,7 +231,7 @@ static void WheelVariationGetter(v8::Local, const v8::PropertyCallba static void RearWheelVariationGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetRearWheelVariation()); @@ -239,7 +239,7 @@ static void RearWheelVariationGetter(v8::Local, const v8::PropertyCa static void IsCustomTiresGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->GetCustomTires()); @@ -247,7 +247,7 @@ static void IsCustomTiresGetter(v8::Local, const v8::PropertyCallbac static void SpecialDarknessGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetSpecialDarkness()); @@ -255,7 +255,7 @@ static void SpecialDarknessGetter(v8::Local, const v8::PropertyCallb static void NumberplateIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetNumberplateIndex()); @@ -263,7 +263,7 @@ static void NumberplateIndexGetter(v8::Local, const v8::PropertyCall static void NumberplateTextGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_STRING(vehicle->GetNumberplateText().CStr()); @@ -271,7 +271,7 @@ static void NumberplateTextGetter(v8::Local, const v8::PropertyCallb static void WindowTintGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetWindowTint()); @@ -279,7 +279,7 @@ static void WindowTintGetter(v8::Local, const v8::PropertyCallbackIn static void DirtLevelGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetDirtLevel()); @@ -287,7 +287,7 @@ static void DirtLevelGetter(v8::Local, const v8::PropertyCallbackInf static void IsNeonActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsNeonActive()); @@ -320,7 +320,7 @@ static void NeonGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetLivery()); @@ -328,7 +328,7 @@ static void LiveryGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetRoofLivery()); @@ -336,7 +336,7 @@ static void RoofLiveryGetter(v8::Local, const v8::PropertyCallbackIn static void EngineOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsEngineOn()); @@ -344,7 +344,7 @@ static void EngineOnGetter(v8::Local, const v8::PropertyCallbackInfo static void HandbrakeActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsHandbrakeActive()); @@ -352,7 +352,7 @@ static void HandbrakeActiveGetter(v8::Local, const v8::PropertyCallb static void HeadlightColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetHeadlightColor()); @@ -360,7 +360,7 @@ static void HeadlightColorGetter(v8::Local, const v8::PropertyCallba static void RadioStationIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetRadioStationIndex()); @@ -368,7 +368,7 @@ static void RadioStationIndexGetter(v8::Local, const v8::PropertyCal static void IsSirenActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsSirenActive()); @@ -376,7 +376,7 @@ static void IsSirenActiveGetter(v8::Local, const v8::PropertyCallbac static void LockStateGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetLockState()); @@ -384,7 +384,7 @@ static void LockStateGetter(v8::Local, const v8::PropertyCallbackInf static void IsDaylightOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsDaylightOn()); @@ -392,7 +392,7 @@ static void IsDaylightOnGetter(v8::Local, const v8::PropertyCallback static void IsNightlightOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsNightlightOn()); @@ -400,7 +400,7 @@ static void IsNightlightOnGetter(v8::Local, const v8::PropertyCallba static void RoofStateGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetRoofState()); @@ -408,7 +408,7 @@ static void RoofStateGetter(v8::Local, const v8::PropertyCallbackInf static void IsFlamethrowerActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsFlamethrowerActive()); @@ -416,7 +416,7 @@ static void IsFlamethrowerActiveGetter(v8::Local, const v8::Property static void LightsMultiplierGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_NUMBER(vehicle->GetLightsMultiplier()); @@ -424,7 +424,7 @@ static void LightsMultiplierGetter(v8::Local, const v8::PropertyCall static void EngineHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetEngineHealth()); @@ -432,7 +432,7 @@ static void EngineHealthGetter(v8::Local, const v8::PropertyCallback static void PetrolTankHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetPetrolTankHealth()); @@ -440,7 +440,7 @@ static void PetrolTankHealthGetter(v8::Local, const v8::PropertyCall static void RepairsCountGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetRepairsCount()); @@ -448,7 +448,7 @@ static void RepairsCountGetter(v8::Local, const v8::PropertyCallback static void BodyHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetBodyHealth()); @@ -456,7 +456,7 @@ static void BodyHealthGetter(v8::Local, const v8::PropertyCallbackIn static void BodyAdditionalHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetBodyAdditionalHealth()); @@ -464,7 +464,7 @@ static void BodyAdditionalHealthGetter(v8::Local, const v8::Property static void HasArmoredWindowsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->HasArmoredWindows()); @@ -472,7 +472,7 @@ static void HasArmoredWindowsGetter(v8::Local, const v8::PropertyCal static void IsManualEngineControlGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsManualEngineControl()); @@ -480,7 +480,7 @@ static void IsManualEngineControlGetter(v8::Local, const v8::Propert static void IsHandlingModifiedGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_BOOLEAN(vehicle->IsHandlingModified()); @@ -498,7 +498,7 @@ static void ToggleExtra(const v8::FunctionCallbackInfo& info) // static void GravityGetter(v8::Local, const v8::PropertyCallbackInfo &info) // { -// V8_GET_ISOLATE(info); +// V8_GET_ISOLATE(); // V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); // V8_CHECK(resource, "invalid resource"); @@ -517,7 +517,7 @@ static void ToggleExtra(const v8::FunctionCallbackInfo& info) // static void GravitySetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) // { -// V8_GET_ISOLATE(info); +// V8_GET_ISOLATE(); // V8_CHECK(val->IsNumber(), "val must be a number"); // V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); @@ -539,7 +539,7 @@ static void ToggleExtra(const v8::FunctionCallbackInfo& info) static void MaxGearGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetMaxGear()); @@ -595,7 +595,7 @@ static void StaticGetByID(const v8::FunctionCallbackInfo& info) static void IndicatorLightsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_RETURN_INT(vehicle->GetLightsIndicator()); diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index 03c3f7b4..8687312f 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -53,7 +53,7 @@ static void Off(const v8::FunctionCallbackInfo& info) static void Start(const v8::FunctionCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); @@ -94,7 +94,7 @@ static void Send(const v8::FunctionCallbackInfo& info) static void Stop(const v8::FunctionCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); @@ -182,7 +182,7 @@ static void GetEventListeners(const v8::FunctionCallbackInfo& info) static void URLGetter(v8::Local property, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); @@ -202,7 +202,7 @@ static void URLSetter(v8::Local property, v8::Local value static void ReadyStateGetter(v8::Local property, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); @@ -222,7 +222,7 @@ static void AutoReconnectSetter(v8::Local property, v8::Local property, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); @@ -242,7 +242,7 @@ static void PerMessageDeflateSetter(v8::Local property, v8::Local property, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); @@ -262,7 +262,7 @@ static void PingIntervalSetter(v8::Local property, v8::Local property, const v8::PropertyCallbackInfo& info) { - V8_GET_ISOLATE(info); + V8_GET_ISOLATE(); V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); From 8d60d5d1483243f1cbb233f5c235c456778338a3 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 6 Jul 2021 01:00:18 +0200 Subject: [PATCH 414/564] Remove compilerpath from VSC CPP properties file --- .vscode/c_cpp_properties.json | 1 - 1 file changed, 1 deletion(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index de300375..12afd327 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -35,7 +35,6 @@ "ALTV_JS_SHARED" ], "windowsSdkVersion": "10.0.19041.0", - "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "msvc-x64" From 31fffe72c136a06e8fa8c4db67f8b9686f850b6f Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 6 Jul 2021 01:00:40 +0200 Subject: [PATCH 415/564] Add error handler to keyboard event callback --- src/events/Main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/events/Main.cpp b/src/events/Main.cpp index 018d8584..4540d8a2 100644 --- a/src/events/Main.cpp +++ b/src/events/Main.cpp @@ -96,6 +96,11 @@ V8_EVENT_HANDLER keyboardEvent( return resource->GetLocalHandlers("keyup"); else if (ev->GetKeyState() == alt::CKeyboardEvent::KeyState::DOWN) return resource->GetLocalHandlers("keydown"); + else + { + Log::Error << "Unhandled keystate in keyboard event handler: " << (int)ev->GetKeyState() << Log::Endl; + return std::vector(); + } }, [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { auto ev = static_cast(e); From 1fafc3ae6e267d749f236c86a375ab932a9e7feb Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 6 Jul 2021 01:06:14 +0200 Subject: [PATCH 416/564] Add static_cast in V8_RETURN_* macros to fix arg conversion warnings --- V8Helpers.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index 39308e6d..4a565c79 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -460,14 +460,14 @@ namespace V8 #define V8_RETURN(val) info.GetReturnValue().Set(val) #define V8_RETURN_NULL() V8_RETURN(v8::Null(isolate)) #define V8_RETURN_BOOLEAN(val) V8_RETURN(v8::Boolean::New(isolate, (val))) -#define V8_RETURN_INT(val) V8_RETURN(v8::Integer::New(isolate, (val))) -#define V8_RETURN_UINT(val) V8_RETURN(v8::Integer::NewFromUnsigned(isolate, (val))) -#define V8_RETURN_NUMBER(val) V8_RETURN(v8::Number::New(isolate, (val))) +#define V8_RETURN_INT(val) V8_RETURN(v8::Integer::New(isolate, static_cast(val))) +#define V8_RETURN_UINT(val) V8_RETURN(v8::Integer::NewFromUnsigned(isolate, static_cast(val))) +#define V8_RETURN_NUMBER(val) V8_RETURN(v8::Number::New(isolate, static_cast(val))) #define V8_RETURN_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val), v8::NewStringType::kNormal).ToLocalChecked()) #define V8_RETURN_ALT_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val).CStr(), v8::NewStringType::kNormal).ToLocalChecked()) #define V8_RETURN_MVALUE(val) V8_RETURN(V8Helpers::MValueToV8(val)) -#define V8_RETURN_UINT64(val) V8_RETURN(v8::BigInt::NewFromUnsigned(isolate, (val))) -#define V8_RETURN_INT64(val) V8_RETURN(v8::BigInt::New(isolate, (val))) +#define V8_RETURN_UINT64(val) V8_RETURN(v8::BigInt::NewFromUnsigned(isolate, static_cast(val))) +#define V8_RETURN_INT64(val) V8_RETURN(v8::BigInt::New(isolate, static_cast(val))) #define V8_RETURN_VECTOR3(val) V8_RETURN(resource->CreateVector3(val)) #define V8_RETURN_VECTOR2(val) V8_RETURN(resource->CreateVector2(val)) #define V8_RETURN_RGBA(val) V8_RETURN(resource->CreateRGBA(val)) From 12ae0bf717731d000ce3aa8b15517d9f9af9b8cc Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 6 Jul 2021 01:06:22 +0200 Subject: [PATCH 417/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 25141878..1fafc3ae 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 25141878a43bc201d33a05258aa282707a430353 +Subproject commit 1fafc3ae6e267d749f236c86a375ab932a9e7feb From c375c3847124d67eea439b9fad3fe664d20c17ed Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 6 Jul 2021 13:37:25 +0200 Subject: [PATCH 418/564] Use GetEnteredOrMicrotaskContext instead of deprecated GetEnteredContext --- PromiseRejections.cpp | 2 +- V8Helpers.cpp | 12 ++++++------ V8Helpers.h | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/PromiseRejections.cpp b/PromiseRejections.cpp index cfd806be..a90b98ee 100644 --- a/PromiseRejections.cpp +++ b/PromiseRejections.cpp @@ -28,7 +28,7 @@ void V8::PromiseRejections::HandlerAdded(V8ResourceImpl *resource, v8::PromiseRe void V8::PromiseRejections::ProcessQueue(V8ResourceImpl *resource) { v8::Isolate *isolate = resource->GetIsolate(); - v8::Local ctx = isolate->GetEnteredContext(); + v8::Local ctx = isolate->GetEnteredOrMicrotaskContext(); for (auto &rejection : queue) { diff --git a/V8Helpers.cpp b/V8Helpers.cpp index cf0e7208..bfd47560 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -7,7 +7,7 @@ bool V8Helpers::TryCatch(const std::function& fn) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local context = isolate->GetEnteredContext(); + v8::Local context = isolate->GetEnteredOrMicrotaskContext(); v8::TryCatch tryCatch(isolate); alt::IResource* resource = V8ResourceImpl::GetResource(context); @@ -73,7 +73,7 @@ bool V8Helpers::TryCatch(const std::function& fn) void V8Helpers::RegisterFunc(v8::Local exports, const std::string& _name, v8::FunctionCallback cb, void* data) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local ctx = isolate->GetEnteredContext(); + v8::Local ctx = isolate->GetEnteredOrMicrotaskContext(); v8::Local name = v8::String::NewFromUtf8(isolate, _name.data(), v8::NewStringType::kNormal, _name.size()).ToLocalChecked(); @@ -88,10 +88,10 @@ void V8Helpers::FunctionCallback(const v8::FunctionCallbackInfo& info auto fn = static_cast(info.Data().As()->Value()); v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local ctx = isolate->GetEnteredContext(); + v8::Local ctx = isolate->GetEnteredOrMicrotaskContext(); V8ResourceImpl* resource = V8ResourceImpl::Get(ctx); - Log::Debug << "FunctionCallback " << resource->GetResource()->GetName() << " " << V8ResourceImpl::Get(isolate->GetEnteredContext())->GetResource()->GetName() << Log::Endl; + Log::Debug << "FunctionCallback " << resource->GetResource()->GetName() << " " << V8ResourceImpl::Get(isolate->GetEnteredOrMicrotaskContext())->GetResource()->GetName() << Log::Endl; alt::MValueArgs args; @@ -108,7 +108,7 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) auto& core = alt::ICore::Instance(); v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local ctx = isolate->GetEnteredContext(); + v8::Local ctx = isolate->GetEnteredOrMicrotaskContext(); if (val.IsEmpty()) return core.CreateMValueNone(); @@ -240,7 +240,7 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) v8::Local V8Helpers::MValueToV8(alt::MValueConst val) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local ctx = isolate->GetEnteredContext(); + v8::Local ctx = isolate->GetEnteredOrMicrotaskContext(); switch (val->GetType()) { diff --git a/V8Helpers.h b/V8Helpers.h index 4a565c79..bae74c46 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -224,17 +224,17 @@ namespace V8 } // namespace V8 #define V8_GET_ISOLATE() v8::Isolate *isolate = info.GetIsolate() -#define V8_GET_CONTEXT() v8::Local ctx = isolate->GetEnteredContext() +#define V8_GET_CONTEXT() v8::Local ctx = isolate->GetEnteredOrMicrotaskContext() #define V8_GET_ISOLATE_CONTEXT() \ V8_GET_ISOLATE(); \ V8_GET_CONTEXT() #define V8_GET_RESOURCE() \ - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); \ + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredOrMicrotaskContext()); \ V8_CHECK(resource, "invalid resource"); #define V8_GET_IRESOURCE() \ - alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); \ + alt::IResource *resource = V8ResourceImpl::GetResource(isolate->GetEnteredOrMicrotaskContext()); \ V8_CHECK(resource, "invalid resource"); #define V8_GET_ISOLATE_CONTEXT_RESOURCE() \ @@ -264,15 +264,15 @@ namespace V8 // idx starts with 1 #define V8_GET_THIS_INTERNAL_FIELD_OBJECT(idx, val) \ - auto val = info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredContext()).ToLocalChecked(); + auto val = info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked(); // idx starts with 1 #define V8_GET_THIS_INTERNAL_FIELD_V8ENTITY(idx, val) \ - auto val = V8Entity::Get(info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredContext()).ToLocalChecked()); + auto val = V8Entity::Get(info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked()); // idx starts with 1 #define V8_GET_THIS_INTERNAL_FIELD_ENTITY(idx, val, type) \ - auto val = V8Entity::Get(info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredContext()).ToLocalChecked())->GetHandle().As(); + auto val = V8Entity::Get(info.This()->GetInternalField((idx)-1)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked())->GetHandle().As(); // idx starts with 1 #define V8_GET_THIS_INTERNAL_FIELD_INTEGER(idx, val) \ From 1537356d194cf3f86d833722f94418e40ed5ac6c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 6 Jul 2021 13:41:00 +0200 Subject: [PATCH 419/564] Use GetBackingStore instead of deprecated GetContents --- V8Helpers.cpp | 6 +++--- bindings/File.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index bfd47560..349a22ed 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -156,8 +156,8 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) } else if (val->IsArrayBuffer()) { - v8::ArrayBuffer::Contents v8Buffer = val.As()->GetContents(); - return core.CreateMValueByteArray((uint8_t*)v8Buffer.Data(), v8Buffer.ByteLength()); + auto v8Buffer = val.As()->GetBackingStore(); + return core.CreateMValueByteArray((uint8_t*)v8Buffer->Data(), v8Buffer->ByteLength()); } else { @@ -315,7 +315,7 @@ v8::Local V8Helpers::MValueToV8(alt::MValueConst val) { alt::MValueByteArrayConst buffer = val.As(); v8::Local v8Buffer = v8::ArrayBuffer::New(isolate, buffer->GetSize()); - std::memcpy(v8Buffer->GetContents().Data(), buffer->GetData(), buffer->GetSize()); + std::memcpy(v8Buffer->GetBackingStore()->Data(), buffer->GetData(), buffer->GetSize()); return v8Buffer; } default: diff --git a/bindings/File.cpp b/bindings/File.cpp index 4c5d4b5f..742082df 100644 --- a/bindings/File.cpp +++ b/bindings/File.cpp @@ -61,9 +61,9 @@ static void StaticRead(const v8::FunctionCallbackInfo &info) else if (encoding == "binary") { v8::Local buffer = v8::ArrayBuffer::New(isolate, data.GetSize()); - v8::ArrayBuffer::Contents contents = buffer->GetContents(); + auto contents = buffer->GetBackingStore(); - std::memcpy(contents.Data(), data.GetData(), data.GetSize()); + std::memcpy(contents->Data(), data.GetData(), data.GetSize()); V8_RETURN(buffer); } From d444701082eb64afced9bd4ce14571040896663e Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 6 Jul 2021 21:23:42 +0200 Subject: [PATCH 420/564] Update README --- README.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 23cefc77..239bdd2c 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,13 @@ # Official clientside JavaScript runtime for alt:V -## To generate: -`cmake . -BBUILD` - ## To build: -`cmake --build BUILD --config Release` -Built `altv-client-js.dll` is now inside `BUILD/Release` (if build is successful) +Run `.\tools\build.bat` (Make sure to run this script from the main directory of the repo) +Or use the VSCode task +Built `altv-client-js.dll` is now inside `dist` directory (if build was successful) ## To test: Get dev branch of alt:V client (download from https://altv.mp or change branch in `altv.cfg`) -Place `altv-client-js.dll` into alt:V client folder (same folder as altv.exe and altv-client.dll) -Set `debug: true` in `altv.cfg` - +Place `altv-client-js.dll` into the `modules/altv-client-js` directory in the alt:V client folder. (You need to create these directories yourself) +Set `debug: true` in `altv.cfg` ### All contributions are appreciated. From 043c01feeaad161692ffa74eef3b86bf977de9d0 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 6 Jul 2021 21:24:42 +0200 Subject: [PATCH 421/564] Add missing newlines in README --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 239bdd2c..6e4e6bfd 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,16 @@ ## To build: Run `.\tools\build.bat` (Make sure to run this script from the main directory of the repo) + Or use the VSCode task -Built `altv-client-js.dll` is now inside `dist` directory (if build was successful) + +Built `altv-client-js.dll` is now inside `dist` directory (if build was successful) ## To test: Get dev branch of alt:V client (download from https://altv.mp or change branch in `altv.cfg`) + Place `altv-client-js.dll` into the `modules/altv-client-js` directory in the alt:V client folder. (You need to create these directories yourself) + Set `debug: true` in `altv.cfg` ### All contributions are appreciated. From 204c9120b5a967e45d2d78571a263552bd689803 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 7 Jul 2021 16:33:48 +0200 Subject: [PATCH 422/564] Fix microtasks not being executed --- src/CV8ScriptRuntime.cpp | 2 ++ src/CV8ScriptRuntime.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index d3afd6c9..bf7acfbf 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -122,6 +122,8 @@ CV8ScriptRuntime::CV8ScriptRuntime() return v8::MaybeLocal(resolver->GetPromise()); }); + isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit); + /*{ v8::Locker locker(isolate); v8::Isolate::Scope isolate_scope(isolate); diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 5c41bf9a..c750178f 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -61,6 +61,7 @@ class CV8ScriptRuntime : public alt::IScriptRuntime v8::HandleScope handle_scope(isolate); v8::platform::PumpMessageLoop(platform.get(), isolate); + isolate->PerformMicrotaskCheckpoint(); } std::unordered_set GetResources() From d49d8ec5244c65c5b05f9af7e9370517283f52bc Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 8 Jul 2021 03:01:06 +0200 Subject: [PATCH 423/564] Add heap out-of-memory handler --- src/CV8ScriptRuntime.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index bf7acfbf..1a6a5536 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -13,11 +13,26 @@ CV8ScriptRuntime::CV8ScriptRuntime() create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); + /* + !!! This increases the max heap size massively (when having 16GB RAM from 1.41GB to 4GB) + !!! so enable this when there are ever any changes that require a increase in max heap size. + !!! Also needs #include + ::MEMORYSTATUS buffer; + ::GlobalMemoryStatus(&buffer); + create_params.constraints.ConfigureDefaults(buffer.dwTotalPhys, buffer.dwTotalVirtual); + */ + isolate = v8::Isolate::New(create_params); isolate->SetFatalErrorHandler([](const char *location, const char *message) { Log::Error << "[V8] " << location << ": " << message << Log::Endl; }); + isolate->SetOOMErrorHandler([](const char* location, bool isHeap) { + if(!isHeap) return; + Log::Error << "[V8] " << location << ": Heap out of memory." << Log::Endl; + Log::Error << "[V8] The current heap limit can be shown with the 'heap' console command. Consider increasing your system RAM." << Log::Endl; + }); + isolate->SetPromiseRejectCallback([](v8::PromiseRejectMessage message) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local value = message.GetValue(); From 99d5e1b3dcf3f70e13726796734ea4e761409f62 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 8 Jul 2021 03:14:55 +0200 Subject: [PATCH 424/564] Add near heap limit callback warning --- src/CV8ScriptRuntime.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 1a6a5536..14b258ab 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -29,10 +29,20 @@ CV8ScriptRuntime::CV8ScriptRuntime() isolate->SetOOMErrorHandler([](const char* location, bool isHeap) { if(!isHeap) return; - Log::Error << "[V8] " << location << ": Heap out of memory." << Log::Endl; + Log::Error << "[V8] " << location << ": Heap out of memory. Forward this to the server developers." << Log::Endl; Log::Error << "[V8] The current heap limit can be shown with the 'heap' console command. Consider increasing your system RAM." << Log::Endl; }); + isolate->AddNearHeapLimitCallback([](void*, size_t current, size_t initial) { + Log::Warning << "[V8] The remaining V8 heap space is approaching critical levels. Forward this to the server developers." << Log::Endl; + Log::Warning << "[V8] Initial heap limit: " << CV8ScriptRuntime::formatBytes(initial) << " | Current heap limit: " << CV8ScriptRuntime::formatBytes(current) << Log::Endl; + + // Increase the heap limit by 100MB if the heap limit has not exceeded 4GB + uint64_t currentLimitMb = (current / 1024) / 1024; + if(currentLimitMb < 4096) return current + (100 * 1024 * 1024); + else return current; + }, nullptr); + isolate->SetPromiseRejectCallback([](v8::PromiseRejectMessage message) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local value = message.GetValue(); From 4f0ba40a2195234d00ea59cfc1a1076b053256d9 Mon Sep 17 00:00:00 2001 From: Leon B Date: Thu, 8 Jul 2021 15:04:47 +0200 Subject: [PATCH 425/564] Update v8 to 9.2 (#77) * Update v8 to 9.2 * Enable v8 deprecation warnings * Update deprecated APIs --- CMakeLists.txt | 4 ++- src/CV8Resource.cpp | 46 +++++++++++++++++--------------- src/CV8ScriptRuntime.cpp | 8 +++--- src/CV8ScriptRuntime.h | 2 +- src/bindings/HandlingData.cpp | 14 +++++----- src/bindings/HttpClient.cpp | 36 ++++++++++++------------- src/bindings/LocalStorage.cpp | 2 +- src/bindings/Main.cpp | 8 +++--- src/bindings/MapZoomData.cpp | 2 +- src/bindings/V8Natives.cpp | 6 ++--- src/bindings/Vehicle.cpp | 2 +- src/bindings/WebSocketClient.cpp | 10 +++---- src/bindings/WebView.cpp | 2 +- src/helpers | 2 +- 14 files changed, 74 insertions(+), 70 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df97dc7a..833c0b87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ project(altv-client-js) # v8 message("alt:V JS - Fetching v8 deps, can take a while") FetchContent_Declare(altv-js-deps - URL https://github.com/altmp/altv-client-js/releases/download/deps2/deps.zip + URL https://github.com/altmp/altv-client-js/releases/download/deps3/deps.zip ) FetchContent_Populate(altv-js-deps) set(ALTV_JS_DL_DEPS ${altv-js-deps_SOURCE_DIR}) @@ -51,6 +51,7 @@ set(ALTV_JS_LINKS # Platform binaries Winmm.lib DbgHelp.lib + shlwapi.lib # V8 ${ALTV_JS_DL_DEPS}/lib/$,Debug,Release>/v8_monolith.lib @@ -71,6 +72,7 @@ set(ALTV_JS_DEFS # v8 -DV8_COMPRESS_POINTERS -DV8_31BIT_SMIS_ON_64BIT_ARCH + -DV8_IMMINENT_DEPRECATION_WARNINGS ) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /Zi /bigobj") diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 2e29de1b..4021f361 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -33,7 +33,7 @@ static void StaticRequire(const v8::FunctionCallbackInfo &info) V8_CHECK(info.Length() == 1, "1 arg expected"); V8_CHECK(info[0]->IsString(), "moduleName must be a string"); - V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredOrMicrotaskContext()); V8_CHECK(resource, "invalid resource"); std::string name{*v8::String::Utf8Value{isolate, info[0]}}; @@ -78,7 +78,7 @@ bool CV8ResourceImpl::Start() v8::Context::Scope context_scope(ctx); //Log::Debug(V8ResourceImpl::GetResource(ctx)); - //Log::Debug(V8ResourceImpl::GetResource(isolate->GetEnteredContext())); + //Log::Debug(V8ResourceImpl::GetResource(isolate->GetEnteredOrMicrotaskContext())); /*runtime->GetInspector()->contextCreated({ ctx, @@ -100,17 +100,18 @@ bool CV8ResourceImpl::Start() v8::Local sourceCode = v8::String::NewFromUtf8(isolate, src.GetData(), v8::NewStringType::kNormal, src.GetSize()).ToLocalChecked(); - v8::ScriptOrigin scriptOrigin{ - v8::String::NewFromUtf8(isolate, path.c_str()).ToLocalChecked(), - v8::Local(), - v8::Local(), - v8::Local(), - v8::Local(), + v8::ScriptOrigin scriptOrigin( + isolate, + V8_NEW_STRING(path.c_str()), + 0, + 0, false, + -1, v8::Local(), - v8::Local(), - v8::Local(), - v8::True(isolate), - v8::Local()}; + false, + false, + true, + v8::Local() + ); bool result = V8Helpers::TryCatch([&]() { v8::ScriptCompiler::Source source{sourceCode, scriptOrigin}; @@ -377,17 +378,18 @@ static v8::MaybeLocal CompileESM(v8::Isolate *isolate, const std::st { v8::Local sourceCode = v8::String::NewFromUtf8(isolate, src.data(), v8::NewStringType::kNormal, src.size()).ToLocalChecked(); - v8::ScriptOrigin scriptOrigin{ - v8::String::NewFromUtf8(isolate, name.c_str()).ToLocalChecked(), - v8::Local(), - v8::Local(), - v8::Local(), - v8::Local(), + v8::ScriptOrigin scriptOrigin( + isolate, + V8_NEW_STRING(name.c_str()), + 0, + 0, false, + -1, v8::Local(), - v8::Local(), - v8::Local(), - v8::True(isolate), - v8::Local()}; + false, + false, + true, + v8::Local() + ); v8::ScriptCompiler::Source source{sourceCode, scriptOrigin}; return v8::ScriptCompiler::CompileModule(isolate, &source); diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 14b258ab..83d8bb51 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -46,7 +46,7 @@ CV8ScriptRuntime::CV8ScriptRuntime() isolate->SetPromiseRejectCallback([](v8::PromiseRejectMessage message) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local value = message.GetValue(); - v8::Local ctx = isolate->GetEnteredContext(); + v8::Local ctx = isolate->GetEnteredOrMicrotaskContext(); CV8ResourceImpl *resource = static_cast(V8ResourceImpl::Get(ctx)); if (resource) @@ -80,7 +80,7 @@ CV8ScriptRuntime::CV8ScriptRuntime() } }); - isolate->SetHostImportModuleDynamicallyCallback([](v8::Local context, v8::Local referrer, v8::Local specifier) { + isolate->SetHostImportModuleDynamicallyCallback([](v8::Local context, v8::Local referrer, v8::Local specifier, v8::Local) { v8::Isolate* isolate = context->GetIsolate(); auto referrerVal = referrer->GetResourceName(); @@ -106,10 +106,10 @@ CV8ScriptRuntime::CV8ScriptRuntime() auto resolver = presolver.Get(isolate); auto specifier = pspecifier.Get(isolate); - auto ctx = resolver->CreationContext(); + auto ctx = resolver->GetCreationContext().ToLocalChecked(); v8::Context::Scope ctxs(ctx); - auto mmodule = ResolveModule(ctx, specifier, referrerModule); + auto mmodule = ResolveModule(ctx, specifier, v8::Local(), referrerModule); if(mmodule.IsEmpty()) { resolver->Reject(ctx, v8::Exception::ReferenceError(V8_NEW_STRING("Could not resolve module"))); diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index c750178f..9f4778c0 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -96,7 +96,7 @@ class CV8ScriptRuntime : public alt::IScriptRuntime delete create_params.array_buffer_allocator; } - static v8::MaybeLocal ResolveModule(v8::Local ctx, v8::Local specifier, v8::Local referrer) + static v8::MaybeLocal ResolveModule(v8::Local ctx, v8::Local specifier, v8::Local, v8::Local referrer) { auto isolate = ctx->GetIsolate(); V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); diff --git a/src/bindings/HandlingData.cpp b/src/bindings/HandlingData.cpp index ee2aae60..1ddb2267 100644 --- a/src/bindings/HandlingData.cpp +++ b/src/bindings/HandlingData.cpp @@ -28,7 +28,7 @@ static void GetForHandlingName(const v8::FunctionCallbackInfo& info) }; extern V8Class v8HandlingData; - V8_RETURN(v8HandlingData.New(isolate->GetEnteredContext(), args)); + V8_RETURN(v8HandlingData.New(isolate->GetEnteredOrMicrotaskContext(), args)); } static void GetForHandlingNameDeprecated(const v8::FunctionCallbackInfo& info) @@ -43,7 +43,7 @@ static void GetForHandlingNameDeprecated(const v8::FunctionCallbackInfoGetEnteredContext(), args)); + V8_RETURN(v8HandlingData.New(isolate->GetEnteredOrMicrotaskContext(), args)); Log::Warning << "alt.HandlingData.getForModelName is deprecated and will be removed in the future. Please use alt.HandlingData.getForHandlingName" << Log::Endl; } @@ -375,7 +375,7 @@ static void InitialDriveGearsSetter(v8::Local, v8::Local auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetInitialDriveGears(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); + handling->SetInitialDriveGears(val->ToUint32(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked()->Value()); } static void DriveInertiaGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -1701,7 +1701,7 @@ static void MonetaryValueSetter(v8::Local, v8::Local val, auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetMonetaryValue(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); + handling->SetMonetaryValue(val->ToUint32(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked()->Value()); } static void ModelFlagsGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -1725,7 +1725,7 @@ static void ModelFlagsSetter(v8::Local, v8::Local val, co auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetModelFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); + handling->SetModelFlags(val->ToUint32(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked()->Value()); } static void HandlingFlagsGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -1749,7 +1749,7 @@ static void HandlingFlagsSetter(v8::Local, v8::Local val, auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetHandlingFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); + handling->SetHandlingFlags(val->ToUint32(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked()->Value()); } static void DamageFlagsGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -1773,7 +1773,7 @@ static void DamageFlagsSetter(v8::Local, v8::Local val, c auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - handling->SetDamageFlags(val->ToUint32(isolate->GetEnteredContext()).ToLocalChecked()->Value()); + handling->SetDamageFlags(val->ToUint32(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked()->Value()); } extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::Local tpl) { diff --git a/src/bindings/HttpClient.cpp b/src/bindings/HttpClient.cpp index 4b0697ed..c380f5ae 100644 --- a/src/bindings/HttpClient.cpp +++ b/src/bindings/HttpClient.cpp @@ -60,7 +60,7 @@ static void Get(const v8::FunctionCallbackInfo& info) auto persistent = (v8::UniquePersistent*)userData; auto resolver = persistent->Get(isolate); - auto ctx = resolver->CreationContext(); + auto ctx = resolver->GetCreationContext().ToLocalChecked(); { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); @@ -72,7 +72,7 @@ static void Get(const v8::FunctionCallbackInfo& info) headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); - resolver->Resolve(resolver->CreationContext(), responseObj); + resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); } requestPromises.remove(*persistent); @@ -102,7 +102,7 @@ static void Head(const v8::FunctionCallbackInfo& info) auto persistent = (v8::UniquePersistent*)userData; auto resolver = persistent->Get(isolate); - auto ctx = resolver->CreationContext(); + auto ctx = resolver->GetCreationContext().ToLocalChecked(); { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); @@ -114,7 +114,7 @@ static void Head(const v8::FunctionCallbackInfo& info) headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); - resolver->Resolve(resolver->CreationContext(), responseObj); + resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); } requestPromises.remove(*persistent); @@ -145,7 +145,7 @@ static void Post(const v8::FunctionCallbackInfo& info) auto persistent = (v8::UniquePersistent*)userData; auto resolver = persistent->Get(isolate); - auto ctx = resolver->CreationContext(); + auto ctx = resolver->GetCreationContext().ToLocalChecked(); { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); @@ -157,7 +157,7 @@ static void Post(const v8::FunctionCallbackInfo& info) headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); - resolver->Resolve(resolver->CreationContext(), responseObj); + resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); } requestPromises.remove(*persistent); @@ -188,7 +188,7 @@ static void Put(const v8::FunctionCallbackInfo& info) auto persistent = (v8::UniquePersistent*)userData; auto resolver = persistent->Get(isolate); - auto ctx = resolver->CreationContext(); + auto ctx = resolver->GetCreationContext().ToLocalChecked(); { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); @@ -200,7 +200,7 @@ static void Put(const v8::FunctionCallbackInfo& info) headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); - resolver->Resolve(resolver->CreationContext(), responseObj); + resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); } requestPromises.remove(*persistent); @@ -231,7 +231,7 @@ static void Delete(const v8::FunctionCallbackInfo& info) auto persistent = (v8::UniquePersistent*)userData; auto resolver = persistent->Get(isolate); - auto ctx = resolver->CreationContext(); + auto ctx = resolver->GetCreationContext().ToLocalChecked(); { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); @@ -243,7 +243,7 @@ static void Delete(const v8::FunctionCallbackInfo& info) headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); - resolver->Resolve(resolver->CreationContext(), responseObj); + resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); } requestPromises.remove(*persistent); @@ -274,7 +274,7 @@ static void Connect(const v8::FunctionCallbackInfo& info) auto persistent = (v8::UniquePersistent*)userData; auto resolver = persistent->Get(isolate); - auto ctx = resolver->CreationContext(); + auto ctx = resolver->GetCreationContext().ToLocalChecked(); { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); @@ -286,7 +286,7 @@ static void Connect(const v8::FunctionCallbackInfo& info) headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); - resolver->Resolve(resolver->CreationContext(), responseObj); + resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); } requestPromises.remove(*persistent); @@ -317,7 +317,7 @@ static void Options(const v8::FunctionCallbackInfo& info) auto persistent = (v8::UniquePersistent*)userData; auto resolver = persistent->Get(isolate); - auto ctx = resolver->CreationContext(); + auto ctx = resolver->GetCreationContext().ToLocalChecked(); { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); @@ -329,7 +329,7 @@ static void Options(const v8::FunctionCallbackInfo& info) headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); - resolver->Resolve(resolver->CreationContext(), responseObj); + resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); } requestPromises.remove(*persistent); @@ -360,7 +360,7 @@ static void Trace(const v8::FunctionCallbackInfo& info) auto persistent = (v8::UniquePersistent*)userData; auto resolver = persistent->Get(isolate); - auto ctx = resolver->CreationContext(); + auto ctx = resolver->GetCreationContext().ToLocalChecked(); { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); @@ -372,7 +372,7 @@ static void Trace(const v8::FunctionCallbackInfo& info) headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); - resolver->Resolve(resolver->CreationContext(), responseObj); + resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); } requestPromises.remove(*persistent); @@ -403,7 +403,7 @@ static void Patch(const v8::FunctionCallbackInfo& info) auto persistent = (v8::UniquePersistent*)userData; auto resolver = persistent->Get(isolate); - auto ctx = resolver->CreationContext(); + auto ctx = resolver->GetCreationContext().ToLocalChecked(); { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); @@ -415,7 +415,7 @@ static void Patch(const v8::FunctionCallbackInfo& info) headers->Set(ctx, V8_NEW_STRING(it->GetKey().CStr()), V8_NEW_STRING(it->GetValue().As()->Value().CStr())); } responseObj->Set(ctx, V8_NEW_STRING("headers"), headers); - resolver->Resolve(resolver->CreationContext(), responseObj); + resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); } requestPromises.remove(*persistent); diff --git a/src/bindings/LocalStorage.cpp b/src/bindings/LocalStorage.cpp index 4b2b059b..c97f4b1e 100644 --- a/src/bindings/LocalStorage.cpp +++ b/src/bindings/LocalStorage.cpp @@ -18,7 +18,7 @@ static void StaticGet(const v8::FunctionCallbackInfo &info) } else { - alt::IResource *iresource = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::IResource *iresource = V8ResourceImpl::GetResource(isolate->GetEnteredOrMicrotaskContext()); V8_ARG_TO_STRING(1, key); V8_RETURN(V8Helpers::MValueToV8(iresource->GetLocalStorage()->Get(key))); } diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 74ab99f1..7fdd98f4 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -667,10 +667,10 @@ static void TakeScreenshot(const v8::FunctionCallbackInfo &info) auto persistent = (v8::UniquePersistent *)userData; auto resolver = persistent->Get(isolate); - auto ctx = resolver->CreationContext(); + auto ctx = resolver->GetCreationContext().ToLocalChecked(); { v8::Context::Scope ctxscope(ctx); - resolver->Resolve(resolver->CreationContext(), v8::String::NewFromUtf8(isolate, base64.CStr()).ToLocalChecked()); + resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), v8::String::NewFromUtf8(isolate, base64.CStr()).ToLocalChecked()); } promises.remove(*persistent); @@ -702,10 +702,10 @@ static void TakeScreenshotGameOnly(const v8::FunctionCallbackInfo &in auto persistent = (v8::UniquePersistent *)userData; auto resolver = persistent->Get(isolate); - auto ctx = resolver->CreationContext(); + auto ctx = resolver->GetCreationContext().ToLocalChecked(); { v8::Context::Scope ctxscope(ctx); - resolver->Resolve(resolver->CreationContext(), v8::String::NewFromUtf8(isolate, base64.CStr()).ToLocalChecked()); + resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), v8::String::NewFromUtf8(isolate, base64.CStr()).ToLocalChecked()); } promises.remove(*persistent); diff --git a/src/bindings/MapZoomData.cpp b/src/bindings/MapZoomData.cpp index 06490891..7ec40a1a 100644 --- a/src/bindings/MapZoomData.cpp +++ b/src/bindings/MapZoomData.cpp @@ -39,7 +39,7 @@ static void Get(const v8::FunctionCallbackInfo &info) V8_CHECK(info[0]->IsNumber() || info[0]->IsString(), "zoomDataId must be a number or string"); std::vector> args{ info[0] }; - V8_RETURN(v8MapZoomData.New(isolate->GetEnteredContext(), args)); + V8_RETURN(v8MapZoomData.New(isolate->GetEnteredOrMicrotaskContext(), args)); } static void ResetAll(const v8::FunctionCallbackInfo &info) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 97e20140..f44a3df9 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -94,7 +94,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native { using ArgType = alt::INative::Type; - v8::Local v8Ctx = isolate->GetEnteredContext(); + v8::Local v8Ctx = isolate->GetEnteredOrMicrotaskContext(); switch (argType) { @@ -264,7 +264,7 @@ static void PushPointerReturn(alt::INative::Type argType, v8::Local r alt::INative::Vector3 *val = reinterpret_cast(&pointers[pointersCount]); pointersCount += 3; - v8::Local v8Ctx = isolate->GetEnteredContext(); + v8::Local v8Ctx = isolate->GetEnteredOrMicrotaskContext(); V8ResourceImpl* resource = V8ResourceImpl::Get(v8Ctx); auto vector = resource->CreateVector3({ val->x, val->y, val->z }).As(); @@ -278,7 +278,7 @@ static v8::Local GetReturn(alt::Ref scrCtx, al { using ArgType = alt::INative::Type; - v8::Local v8Ctx = isolate->GetEnteredContext(); + v8::Local v8Ctx = isolate->GetEnteredOrMicrotaskContext(); switch (retnType) { diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 8ac7417d..9191c2a4 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -520,7 +520,7 @@ static void ToggleExtra(const v8::FunctionCallbackInfo& info) // V8_GET_ISOLATE(); // V8_CHECK(val->IsNumber(), "val must be a number"); -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); +// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredOrMicrotaskContext()); // V8_CHECK(resource, "invalid resource"); // V8_CHECK(val->IsNumber(), "val needs to be a nummber (float)"); diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index 8687312f..e35a53f0 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -15,7 +15,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_ARG_TO_STRING(1, url); - alt::IResource* altres = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::IResource* altres = V8ResourceImpl::GetResource(isolate->GetEnteredOrMicrotaskContext()); V8_CHECK(altres, "invalid resource"); alt::Ref webSocket = nullptr; @@ -76,14 +76,14 @@ static void Send(const v8::FunctionCallbackInfo& info) else if (info[0]->IsArrayBufferView()) { V8_ARG_TO_ARRAY_BUFFER_VIEW(1, v8ArrayBufferView); - auto v8Buffer = v8ArrayBufferView->Buffer()->GetContents(); - ret = webSocket->SendBinary(alt::StringView((char*)v8Buffer.Data(), v8Buffer.ByteLength())); + auto v8Buffer = v8ArrayBufferView->Buffer()->GetBackingStore(); + ret = webSocket->SendBinary(alt::StringView((char*)v8Buffer->Data(), v8Buffer->ByteLength())); } else if (info[0]->IsArrayBuffer()) { V8_ARG_TO_ARRAY_BUFFER(1, v8ArrayBuffer); - auto v8Buffer = v8ArrayBuffer->GetContents(); - ret = webSocket->SendBinary(alt::StringView((char*)v8Buffer.Data(), v8Buffer.ByteLength())); + auto v8Buffer = v8ArrayBuffer->GetBackingStore(); + ret = webSocket->SendBinary(alt::StringView((char*)v8Buffer->Data(), v8Buffer->ByteLength())); } else { diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index 46949e97..205373b7 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -200,7 +200,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_ARG_TO_STRING(1, url); - alt::IResource* altres = V8ResourceImpl::GetResource(isolate->GetEnteredContext()); + alt::IResource* altres = V8ResourceImpl::GetResource(isolate->GetEnteredOrMicrotaskContext()); V8_CHECK(altres, "invalid resource"); alt::Ref view = nullptr; diff --git a/src/helpers b/src/helpers index 1fafc3ae..1537356d 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 1fafc3ae6e267d749f236c86a375ab932a9e7feb +Subproject commit 1537356d194cf3f86d833722f94418e40ed5ac6c From 9d60831bda6e2e943763c85945b8bde91a8c332f Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 9 Jul 2021 01:06:29 +0200 Subject: [PATCH 426/564] Remove comment about increasing max heap size --- deps/altv-js-bytecode | 1 + src/CV8ScriptRuntime.cpp | 9 --------- 2 files changed, 1 insertion(+), 9 deletions(-) create mode 160000 deps/altv-js-bytecode diff --git a/deps/altv-js-bytecode b/deps/altv-js-bytecode new file mode 160000 index 00000000..0b6ba849 --- /dev/null +++ b/deps/altv-js-bytecode @@ -0,0 +1 @@ +Subproject commit 0b6ba84917fc3685b2e9a2c339909d07780b7298 diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 83d8bb51..8188e8ae 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -13,15 +13,6 @@ CV8ScriptRuntime::CV8ScriptRuntime() create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); - /* - !!! This increases the max heap size massively (when having 16GB RAM from 1.41GB to 4GB) - !!! so enable this when there are ever any changes that require a increase in max heap size. - !!! Also needs #include - ::MEMORYSTATUS buffer; - ::GlobalMemoryStatus(&buffer); - create_params.constraints.ConfigureDefaults(buffer.dwTotalPhys, buffer.dwTotalVirtual); - */ - isolate = v8::Isolate::New(create_params); isolate->SetFatalErrorHandler([](const char *location, const char *message) { Log::Error << "[V8] " << location << ": " << message << Log::Endl; From 52733d039511f9f276f86483222cc54676dc4349 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 9 Jul 2021 01:07:42 +0200 Subject: [PATCH 427/564] Capitalize FormatBytes method for consistency --- src/CV8ScriptRuntime.cpp | 2 +- src/CV8ScriptRuntime.h | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 8188e8ae..f32c93e2 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -26,7 +26,7 @@ CV8ScriptRuntime::CV8ScriptRuntime() isolate->AddNearHeapLimitCallback([](void*, size_t current, size_t initial) { Log::Warning << "[V8] The remaining V8 heap space is approaching critical levels. Forward this to the server developers." << Log::Endl; - Log::Warning << "[V8] Initial heap limit: " << CV8ScriptRuntime::formatBytes(initial) << " | Current heap limit: " << CV8ScriptRuntime::formatBytes(current) << Log::Endl; + Log::Warning << "[V8] Initial heap limit: " << CV8ScriptRuntime::FormatBytes(initial) << " | Current heap limit: " << CV8ScriptRuntime::FormatBytes(current) << Log::Endl; // Increase the heap limit by 100MB if the heap limit has not exceeded 4GB uint64_t currentLimitMb = (current / 1024) / 1024; diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 9f4778c0..9dd4700b 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -74,15 +74,15 @@ class CV8ScriptRuntime : public alt::IScriptRuntime v8::HeapStatistics heapStats; isolate->GetHeapStatistics(&heapStats); Log::Info << "================ Heap benchmark info =================" << Log::Endl; - Log::Info << "total_heap_size = " << formatBytes(heapStats.total_heap_size()) << Log::Endl; - Log::Info << "total_heap_size_executable = " << formatBytes(heapStats.total_heap_size_executable()) << Log::Endl; - Log::Info << "total_physical_size = " << formatBytes(heapStats.total_physical_size()) << Log::Endl; - Log::Info << "total_available_size = " << formatBytes(heapStats.total_available_size()) << Log::Endl; - Log::Info << "used_heap_size = " << formatBytes(heapStats.used_heap_size()) << Log::Endl; - Log::Info << "heap_size_limit = " << formatBytes(heapStats.heap_size_limit()) << Log::Endl; - Log::Info << "malloced_memory = " << formatBytes(heapStats.malloced_memory()) << Log::Endl; - Log::Info << "external_memory = " << formatBytes(heapStats.external_memory()) << Log::Endl; - Log::Info << "peak_malloced_memory = " << formatBytes(heapStats.peak_malloced_memory()) << Log::Endl; + Log::Info << "total_heap_size = " << FormatBytes(heapStats.total_heap_size()) << Log::Endl; + Log::Info << "total_heap_size_executable = " << FormatBytes(heapStats.total_heap_size_executable()) << Log::Endl; + Log::Info << "total_physical_size = " << FormatBytes(heapStats.total_physical_size()) << Log::Endl; + Log::Info << "total_available_size = " << FormatBytes(heapStats.total_available_size()) << Log::Endl; + Log::Info << "used_heap_size = " << FormatBytes(heapStats.used_heap_size()) << Log::Endl; + Log::Info << "heap_size_limit = " << FormatBytes(heapStats.heap_size_limit()) << Log::Endl; + Log::Info << "malloced_memory = " << FormatBytes(heapStats.malloced_memory()) << Log::Endl; + Log::Info << "external_memory = " << FormatBytes(heapStats.external_memory()) << Log::Endl; + Log::Info << "peak_malloced_memory = " << FormatBytes(heapStats.peak_malloced_memory()) << Log::Endl; Log::Info << "number_of_native_contexts = " << heapStats.number_of_native_contexts() << Log::Endl; Log::Info << "number_of_detached_contexts = " << heapStats.number_of_detached_contexts() << Log::Endl; Log::Info << "======================================================" << Log::Endl; @@ -116,7 +116,7 @@ class CV8ScriptRuntime : public alt::IScriptRuntime return static_cast(resource)->ResolveModule(_specifier, referrer); } - static std::string formatBytes(uint64_t bytes) + static std::string FormatBytes(uint64_t bytes) { static std::string result = ""; const char *sizes[5] = {"bytes", "KB", "MB", "GB", "TB"}; From fa5d9365cb207ebb607d8f34cf4cb958f3f4f7ee Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 9 Jul 2021 01:08:53 +0200 Subject: [PATCH 428/564] Remove accidentally added submodule --- deps/altv-js-bytecode | 1 - 1 file changed, 1 deletion(-) delete mode 160000 deps/altv-js-bytecode diff --git a/deps/altv-js-bytecode b/deps/altv-js-bytecode deleted file mode 160000 index 0b6ba849..00000000 --- a/deps/altv-js-bytecode +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0b6ba84917fc3685b2e9a2c339909d07780b7298 From fc94987563f42293f5219c815fd1c07d715516c2 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 9 Jul 2021 01:40:47 +0200 Subject: [PATCH 429/564] Disable microtasks to fix natives --- src/CV8ScriptRuntime.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 9dd4700b..4ed3de79 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -61,7 +61,8 @@ class CV8ScriptRuntime : public alt::IScriptRuntime v8::HandleScope handle_scope(isolate); v8::platform::PumpMessageLoop(platform.get(), isolate); - isolate->PerformMicrotaskCheckpoint(); + // todo: Fix microtasks while not breaking natives + // isolate->PerformMicrotaskCheckpoint(); } std::unordered_set GetResources() From 35b9fa71615645d0c52a914b0771769b3f8e74d6 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 9 Jul 2021 01:58:50 +0200 Subject: [PATCH 430/564] Fix microtasks --- src/CV8Resource.cpp | 13 +++++++++++-- src/CV8Resource.h | 2 ++ src/CV8ScriptRuntime.h | 2 -- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 4021f361..69fb97f2 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -68,7 +68,15 @@ bool CV8ResourceImpl::Start() v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); - v8::Local ctx = v8::Context::New(isolate); + microtaskQueue = v8::MicrotaskQueue::New(isolate, v8::MicrotasksPolicy::kExplicit); + v8::Local ctx = v8::Context::New( + isolate, + nullptr, + v8::MaybeLocal(), + v8::MaybeLocal(), + v8::DeserializeInternalFieldsCallback(), + microtaskQueue.get() + ); context.Reset(isolate, ctx); ctx->SetAlignedPointerInEmbedderData(1, resource); @@ -329,9 +337,10 @@ void CV8ResourceImpl::OnTick() v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); - v8::Context::Scope scope(GetContext()); + microtaskQueue->PerformCheckpoint(isolate); + int64_t time = GetTime(); V8ResourceImpl::OnTick(); diff --git a/src/CV8Resource.h b/src/CV8Resource.h index 8242d7ee..9ef7bd48 100644 --- a/src/CV8Resource.h +++ b/src/CV8Resource.h @@ -160,4 +160,6 @@ class CV8ResourceImpl : public V8ResourceImpl std::unordered_set> ownedObjects; v8::Persistent localStorage; + + std::unique_ptr microtaskQueue; }; diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 4ed3de79..0d4368ff 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -61,8 +61,6 @@ class CV8ScriptRuntime : public alt::IScriptRuntime v8::HandleScope handle_scope(isolate); v8::platform::PumpMessageLoop(platform.get(), isolate); - // todo: Fix microtasks while not breaking natives - // isolate->PerformMicrotaskCheckpoint(); } std::unordered_set GetResources() From eb093adf62d04f6067b3ccddd75fccd334fbaa88 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 11 Jul 2021 01:51:55 +0200 Subject: [PATCH 431/564] Update SDK --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index a9cbb4d0..b2f152db 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit a9cbb4d0decb17fec6b76f3a404f8f43168e80b8 +Subproject commit b2f152dbc7327795c341d6bfcabc56dd5750a515 From 32452e2af6b1e5e876ae7a19116593c5cabe5833 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 11 Jul 2021 01:56:11 +0200 Subject: [PATCH 432/564] Add support for local player v8 class in GetClass --- V8Entity.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/V8Entity.h b/V8Entity.h index ec149758..4776b28f 100644 --- a/V8Entity.h +++ b/V8Entity.h @@ -49,7 +49,7 @@ class V8Entity #ifdef ALT_SERVER_API extern V8Class v8VoiceChannel, v8Colshape, v8Checkpoint; #else - extern V8Class v8WebView; + extern V8Class v8WebView, v8LocalPlayer; #endif if (!handle) @@ -73,6 +73,8 @@ class V8Entity #else case alt::IBaseObject::Type::WEBVIEW: return &v8WebView; + case alt::IBaseObject::Type::LOCAL_PLAYER: + return &v8LocalPlayer; #endif } From 62cb7c2894ba5491edf9f9076a9a346ecccd6486 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 12 Jul 2021 23:44:20 +0200 Subject: [PATCH 433/564] Add local player support --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/LocalPlayer.cpp | 21 +++++++++++++++++++++ src/bindings/Main.cpp | 6 ++++-- src/helpers | 2 +- 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 src/bindings/LocalPlayer.cpp diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index b2f152db..2752a9ca 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit b2f152dbc7327795c341d6bfcabc56dd5750a515 +Subproject commit 2752a9ca8ce2bb3e8677d274f41d216d2736451e diff --git a/src/bindings/LocalPlayer.cpp b/src/bindings/LocalPlayer.cpp new file mode 100644 index 00000000..23190ddc --- /dev/null +++ b/src/bindings/LocalPlayer.cpp @@ -0,0 +1,21 @@ +#include "../helpers/V8Helpers.h" +#include "../helpers/V8Class.h" +#include "../helpers/V8Entity.h" +#include "../helpers/V8ResourceImpl.h" + +#include "cpp-sdk/objects/ILocalPlayer.h" + +static void CurrentAmmoGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(player, alt::ILocalPlayer); + + V8_RETURN_UINT(player->GetCurrentAmmo()); +} + +extern V8Class v8Player; +extern V8Class v8LocalPlayer("LocalPlayer", v8Player, [](v8::Local tpl) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + V8::SetAccessor(isolate, tpl, "currentAmmo", &CurrentAmmoGetter); +}); diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 7fdd98f4..3e787bb1 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -812,7 +812,8 @@ extern V8Class v8Vector3, v8WebSocketClient, v8Checkpoint, v8HttpClient, - v8Audio; + v8Audio, + v8LocalPlayer; extern V8Module altModule( "alt", {v8Vector3, @@ -838,7 +839,8 @@ extern V8Module altModule( v8WebSocketClient, v8Checkpoint, v8HttpClient, - v8Audio}, + v8Audio, + v8LocalPlayer}, [](v8::Local ctx, v8::Local exports) { V8::RegisterSharedMain(ctx, exports); diff --git a/src/helpers b/src/helpers index 1537356d..32452e2a 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 1537356d194cf3f86d833722f94418e40ed5ac6c +Subproject commit 32452e2af6b1e5e876ae7a19116593c5cabe5833 From 0afac21cbca1e034eccd696578cd49c55a727f9d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 14 Jul 2021 02:38:48 +0200 Subject: [PATCH 434/564] Rename V8_ARG_TO_INTEGER TO V8_ARG_TO_INT --- V8Helpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/V8Helpers.h b/V8Helpers.h index bae74c46..23a4da07 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -389,7 +389,7 @@ namespace V8 alt::MValue val = V8Helpers::V8ToMValue(info[(idx)-1]); // idx starts with 1 -#define V8_ARG_TO_INTEGER(idx, val) \ +#define V8_ARG_TO_INT(idx, val) \ int64_t val; \ V8_CHECK(V8::SafeToInteger(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to integer") From ccef3e1a1dcb585ed3683bdc2d5b8fd048b66187 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 14 Jul 2021 02:39:30 +0200 Subject: [PATCH 435/564] Fix old macro being used --- bindings/Entity.cpp | 4 ++-- bindings/Main.cpp | 6 +++--- bindings/RGBA.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index 3fe9802c..2ce5a6ea 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -194,7 +194,7 @@ static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, scriptGuid); + V8_ARG_TO_INT(1, scriptGuid); V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid)); } @@ -204,7 +204,7 @@ static void StaticGetByID(const v8::FunctionCallbackInfo &info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, id); + V8_ARG_TO_INT(1, id); V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id)); } diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 85cdad26..e4a0a240 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -221,7 +221,7 @@ static void SetTimeout(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(2); V8_ARG_TO_FUNCTION(1, callback); - V8_ARG_TO_INTEGER(2, time); + V8_ARG_TO_INT(2, time); V8_RETURN_INT(resource->CreateTimer(ctx, callback, time, true, V8::SourceLocation::GetCurrent(isolate))); } @@ -233,7 +233,7 @@ static void SetInterval(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(2); V8_ARG_TO_FUNCTION(1, callback); - V8_ARG_TO_INTEGER(2, time); + V8_ARG_TO_INT(2, time); V8_RETURN_INT(resource->CreateTimer(ctx, callback, time, false, V8::SourceLocation::GetCurrent(isolate))); } @@ -266,7 +266,7 @@ static void ClearTimer(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, timer); + V8_ARG_TO_INT(1, timer); resource->RemoveTimer(timer); } diff --git a/bindings/RGBA.cpp b/bindings/RGBA.cpp index d5ef9bfc..fc8264c4 100644 --- a/bindings/RGBA.cpp +++ b/bindings/RGBA.cpp @@ -24,10 +24,10 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_CHECK_ARGS_LEN(4); - V8_ARG_TO_INTEGER(1, r); - V8_ARG_TO_INTEGER(2, g); - V8_ARG_TO_INTEGER(3, b); - V8_ARG_TO_INTEGER(4, a); + V8_ARG_TO_INT(1, r); + V8_ARG_TO_INT(2, g); + V8_ARG_TO_INT(3, b); + V8_ARG_TO_INT(4, a); V8::DefineOwnProperty(isolate, ctx, info.This(), V8::RGBA_RKey(isolate), v8::Integer::New(isolate, r), v8::PropertyAttribute::ReadOnly); V8::DefineOwnProperty(isolate, ctx, info.This(), V8::RGBA_GKey(isolate), v8::Integer::New(isolate, g), v8::PropertyAttribute::ReadOnly); From d23edf2be98875433d8beb17a54b759125e6eba8 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 14 Jul 2021 02:42:56 +0200 Subject: [PATCH 436/564] Update helpers --- src/bindings/Audio.cpp | 4 ++-- src/bindings/Blip.cpp | 8 ++++---- src/bindings/Checkpoint.cpp | 4 ++-- src/bindings/HandlingData.cpp | 6 +++--- src/bindings/Main.cpp | 16 ++++++++-------- src/bindings/Player.cpp | 10 +++++----- src/bindings/Vehicle.cpp | 6 +++--- src/bindings/WebView.cpp | 2 +- src/helpers | 2 +- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp index d3dc7d7d..2c224760 100644 --- a/src/bindings/Audio.cpp +++ b/src/bindings/Audio.cpp @@ -177,7 +177,7 @@ static void AddOutput(const v8::FunctionCallbackInfo& info) if(info[0]->IsInt32() || info[0]->IsUint32()) { - V8_ARG_TO_INTEGER(1, scriptId); + V8_ARG_TO_INT(1, scriptId); audio->AddOutput(scriptId); } else @@ -195,7 +195,7 @@ static void RemoveOutput(const v8::FunctionCallbackInfo& info) if(info[0]->IsInt32() || info[0]->IsUint32()) { - V8_ARG_TO_INTEGER(1, scriptId); + V8_ARG_TO_INT(1, scriptId); audio->RemoveOutput(scriptId); } else diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index 152b3bf4..31b235ac 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -70,7 +70,7 @@ static void ConstructorPedBlip(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_CONSTRUCTOR(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, pedId); + V8_ARG_TO_INT(1, pedId); alt::Ref blip = alt::ICore::Instance().CreateBlip(alt::IBlip::BlipType::PED, pedId); V8_BIND_BASE_OBJECT(blip, "Failed to create PedBlip"); @@ -81,7 +81,7 @@ static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo& in V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_CONSTRUCTOR(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, vehicleId); + V8_ARG_TO_INT(1, vehicleId); alt::Ref blip = alt::ICore::Instance().CreateBlip(alt::IBlip::BlipType::VEHICLE, vehicleId); V8_BIND_BASE_OBJECT(blip, "Failed to create VehicleBlip"); @@ -589,8 +589,8 @@ static void Fade(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_INTEGER(1, opacity); - V8_ARG_TO_INTEGER(2, duration); + V8_ARG_TO_INT(1, opacity); + V8_ARG_TO_INT(2, duration); V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); blip->Fade(opacity, duration); } diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index 63ec2735..c4c66ee5 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -8,7 +8,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_CHECK_CONSTRUCTOR(); if(info.Length() == 6) { - V8_ARG_TO_INTEGER(1, type); + V8_ARG_TO_INT(1, type); V8_ARG_TO_OBJECT(2, pos); V8_ARG_TO_OBJECT(3, nextPos); V8_ARG_TO_NUMBER(4, radius); @@ -33,7 +33,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) } else if(info.Length() == 10) { - V8_ARG_TO_INTEGER(1, type); + V8_ARG_TO_INT(1, type); V8_ARG_TO_NUMBER(2, x); V8_ARG_TO_NUMBER(3, y); V8_ARG_TO_NUMBER(4, z); diff --git a/src/bindings/HandlingData.cpp b/src/bindings/HandlingData.cpp index 1ddb2267..9e643aad 100644 --- a/src/bindings/HandlingData.cpp +++ b/src/bindings/HandlingData.cpp @@ -8,7 +8,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_CHECK_CONSTRUCTOR(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, modelHash); + V8_ARG_TO_INT(1, modelHash); auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "model doesn't exist"); @@ -21,7 +21,7 @@ static void GetForHandlingName(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, modelHash); + V8_ARG_TO_INT(1, modelHash); std::vector> args{ v8::Number::New(isolate, modelHash) @@ -36,7 +36,7 @@ static void GetForHandlingNameDeprecated(const v8::FunctionCallbackInfo> args{ v8::Number::New(isolate, modelHash) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 3e787bb1..31544c7d 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -158,7 +158,7 @@ static void IsTextureExistInArchetype(const v8::FunctionCallbackInfo V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_INTEGER(1, modelHash); + V8_ARG_TO_INT(1, modelHash); V8_ARG_TO_STRING(2, modelName); V8_RETURN_BOOLEAN(nullptr != ICore::Instance().GetTextureFromDrawable(modelHash, modelName)); @@ -271,7 +271,7 @@ static void SetMsPerGameMinute(const v8::FunctionCallbackInfo &info) V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, ms); + V8_ARG_TO_INT(1, ms); ICore::Instance().SetMsPerGameMinute(ms); } @@ -346,7 +346,7 @@ static void SetCharStat(const v8::FunctionCallbackInfo &info) if (!strcmp(targetStat->GetStatType(), "INT")) { - V8_ARG_TO_INTEGER(2, value); + V8_ARG_TO_INT(2, value); targetStat->SetInt32Value(value); V8_RETURN_BOOLEAN(true); return; @@ -526,7 +526,7 @@ static void IsKeyDown(const v8::FunctionCallbackInfo &info) V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, keycode); + V8_ARG_TO_INT(1, keycode); V8_RETURN_BOOLEAN(alt::ICore::Instance().GetKeyState(keycode).IsDown()); } @@ -536,7 +536,7 @@ static void IsKeyToggled(const v8::FunctionCallbackInfo &info) V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, keycode); + V8_ARG_TO_INT(1, keycode); V8_RETURN_BOOLEAN(alt::ICore::Instance().GetKeyState(keycode).IsToggled()); } @@ -603,7 +603,7 @@ static void UnloadYtyp(const v8::FunctionCallbackInfo& info) // #endif // V8_CHECK_ARGS_LEN(1); -// V8_ARG_TO_INTEGER(1, id); +// V8_ARG_TO_INT(1, id); // ::CEntity *addr = funcs::GetEntityFromScriptID<::CEntity *>(id); @@ -619,7 +619,7 @@ static void SetAngularVelocity(const v8::FunctionCallbackInfo &info) V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(4); - V8_ARG_TO_INTEGER(1, id); + V8_ARG_TO_INT(1, id); V8_ARG_TO_NUMBER(2, x); V8_ARG_TO_NUMBER(3, y); V8_ARG_TO_NUMBER(4, z); @@ -632,7 +632,7 @@ static void GetPermissionState(const v8::FunctionCallbackInfo &info) V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, permnum); + V8_ARG_TO_INT(1, permnum); V8_RETURN_INT((uint8_t)alt::ICore::Instance().GetPermissionState((alt::Permission)permnum)); } diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index df795840..737edf64 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -230,8 +230,8 @@ static void WeaponHasComponent(const v8::FunctionCallbackInfo& info) V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_INTEGER(1, weaponHash); - V8_ARG_TO_INTEGER(2, componentHash); + V8_ARG_TO_INT(1, weaponHash); + V8_ARG_TO_INT(2, componentHash); V8_RETURN_BOOLEAN(player->HasWeaponComponent(weaponHash, componentHash)); } @@ -242,7 +242,7 @@ static void GetWeaponTintIndex(const v8::FunctionCallbackInfo& info) V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, weaponHash); + V8_ARG_TO_INT(1, weaponHash); V8_RETURN_INT(player->GetWeaponTintIndex(weaponHash)); } @@ -325,7 +325,7 @@ static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, scriptGuid); + V8_ARG_TO_INT(1, scriptGuid); V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid).As()); } @@ -333,7 +333,7 @@ static void StaticGetByID(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, id); + V8_ARG_TO_INT(1, id); V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id).As()); } diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 9191c2a4..130a719a 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -491,7 +491,7 @@ static void ToggleExtra(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_INTEGER(1, extraID); + V8_ARG_TO_INT(1, extraID); V8_ARG_TO_BOOLEAN(2, toggle); vehicle->ToggleExtra(extraID, toggle); } @@ -581,7 +581,7 @@ static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, scriptGuid); + V8_ARG_TO_INT(1, scriptGuid); V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByScriptGuid(scriptGuid).As()); } @@ -589,7 +589,7 @@ static void StaticGetByID(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_INTEGER(1, id); + V8_ARG_TO_INT(1, id); V8_RETURN_BASE_OBJECT(alt::ICore::Instance().GetEntityByID(id).As()); } diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index 205373b7..551fe830 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -234,7 +234,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) } else if (info.Length() == 3) { - V8_ARG_TO_INTEGER(2, drawableHash); + V8_ARG_TO_INT(2, drawableHash); V8_ARG_TO_STRING(3, targetTextureStr); auto texture = alt::ICore::Instance().GetTextureFromDrawable(drawableHash, targetTextureStr); diff --git a/src/helpers b/src/helpers index 32452e2a..ccef3e1a 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 32452e2af6b1e5e876ae7a19116593c5cabe5833 +Subproject commit ccef3e1a1dcb585ed3683bdc2d5b8fd048b66187 From c9b5c57ed48fd8080189f516ddc4262fd4d8abab Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 14 Jul 2021 17:31:57 +0200 Subject: [PATCH 437/564] Fix dynamic import --- .vscode/settings.json | 9 ++++++++- src/CV8Resource.cpp | 17 +++++++++++++++++ src/events/Main.cpp | 7 ------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c44ef405..a9f84797 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -69,6 +69,13 @@ "compare": "cpp", "concepts": "cpp", "condition_variable": "cpp", - "set": "cpp" + "set": "cpp", + "bit": "cpp", + "charconv": "cpp", + "clocale": "cpp", + "format": "cpp", + "forward_list": "cpp", + "optional": "cpp", + "stop_token": "cpp" } } \ No newline at end of file diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index 69fb97f2..ef7b585a 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -281,6 +281,23 @@ bool CV8ResourceImpl::OnEvent(const alt::CEvent* e) InvokeEventHandlers(e, callbacks, args); } + // Dynamic imports + { + if(e->GetType() == alt::CEvent::Type::CONNECTION_COMPLETE) + { + CV8ScriptRuntime& runtime = CV8ScriptRuntime::Instance(); + if(!runtime.resourcesLoaded) + { + runtime.resourcesLoaded = true; + ProcessDynamicImports(); + } + } + else if(e->GetType() == alt::CEvent::Type::DISCONNECT_EVENT) + { + CV8ScriptRuntime::Instance().resourcesLoaded = false; + } + } + return true; } diff --git a/src/events/Main.cpp b/src/events/Main.cpp index 4540d8a2..86ea1587 100644 --- a/src/events/Main.cpp +++ b/src/events/Main.cpp @@ -120,17 +120,10 @@ V8_LOCAL_EVENT_HANDLER connectionComplete( EventType::CONNECTION_COMPLETE, "connectionComplete", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { - CV8ScriptRuntime& runtime = CV8ScriptRuntime::Instance(); - if(!runtime.resourcesLoaded) - { - runtime.resourcesLoaded = true; - static_cast(resource)->ProcessDynamicImports(); - } }); V8_LOCAL_EVENT_HANDLER disconnect( EventType::DISCONNECT_EVENT, "disconnect", [](V8ResourceImpl *resource, const alt::CEvent *e, std::vector> &args) { - CV8ScriptRuntime::Instance().resourcesLoaded = false; }); From 99aefc1341e61a24330bc319db9f849f307aaa7b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 14 Jul 2021 19:32:42 +0200 Subject: [PATCH 438/564] Add ped clothes & props methods --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/Main.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 2752a9ca..f7b046d7 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 2752a9ca8ce2bb3e8677d274f41d216d2736451e +Subproject commit f7b046d7a4a11bbe44065a4225464bf1ed7bb22b diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 31544c7d..1820d06b 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -786,6 +786,56 @@ static void GetHeadshotBase64(const v8::FunctionCallbackInfo& info) V8_RETURN_STRING(alt::ICore::Instance().HeadshotToBase64(id).CStr()); } +static void SetPedDlcClothes(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN2(5, 6); + + V8_ARG_TO_INT(1, scriptId); + V8_ARG_TO_UINT32(2, dlc); + V8_ARG_TO_INT(3, component); + V8_ARG_TO_INT(4, drawable); + V8_ARG_TO_INT(5, texture); + + uint8_t palette; + if(info.Length() == 5) + { + palette = 2; + } + else if(info.Length() == 6) + { + V8_ARG_TO_INT(6, paletteArg); + palette = paletteArg; + } + + alt::ICore::Instance().SetDlcClothes(scriptId, component, drawable, texture, palette, dlc); +} + +static void SetPedDlcProps(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(5); + + V8_ARG_TO_INT(1, scriptId); + V8_ARG_TO_UINT32(2, dlc); + V8_ARG_TO_INT(3, component); + V8_ARG_TO_INT(4, drawable); + V8_ARG_TO_INT(5, texture); + + alt::ICore::Instance().SetDlcProps(scriptId, component, drawable, texture, dlc); +} + +static void ClearPedProps(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_INT(1, scriptId); + V8_ARG_TO_INT(2, component); + + alt::ICore::Instance().ClearProps(scriptId, component); +} + extern V8Class v8Vector3, v8Vector2, v8RGBA, @@ -927,4 +977,8 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "evalModule", &EvalModule); V8Helpers::RegisterFunc(exports, "getHeadshotBase64", &GetHeadshotBase64); + + V8Helpers::RegisterFunc(exports, "setPedDlcClothes", &SetPedDlcClothes); + V8Helpers::RegisterFunc(exports, "setPedDlcProp", &SetPedDlcProps); + V8Helpers::RegisterFunc(exports, "clearPedProp", &ClearPedProps); }); From 3334e4a9aa2bc3fc2455dc79678c484dbb2a29d1 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 14 Jul 2021 21:36:58 +0200 Subject: [PATCH 439/564] Update native arg parse error msg --- src/bindings/V8Natives.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index f44a3df9..e68510fb 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -70,10 +70,10 @@ static const char* GetNativeTypeName(alt::INative::Type type) return "bool"; case Type::ARG_INT32: case Type::ARG_INT32_PTR: - return "int32"; + return "int"; case Type::ARG_UINT32: case Type::ARG_UINT32_PTR: - return "uint32"; + return "unsigned int"; case Type::ARG_FLOAT: case Type::ARG_FLOAT_PTR: return "float"; @@ -90,7 +90,15 @@ static const char* GetNativeTypeName(alt::INative::Type type) return "unknown"; } -static void PushArg(alt::Ref scrCtx, alt::INative* native, alt::INative::Type argType, v8::Isolate *isolate, V8ResourceImpl* resource, v8::Local val) +inline void ShowNativeArgParseErrorMsg(v8::Isolate* isolate, v8::Local val, alt::INative* native, alt::INative::Type argType, uint32_t idx) +{ + V8::SourceLocation source = V8::SourceLocation::GetCurrent(isolate); + Log::Error << "[" << source.GetFileName() << ":" << source.GetLineNumber() << "] " + << "Native argument at index " << idx << " " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) + << " (" << native->GetName() << ")" << Log::Endl; +} + +static void PushArg(alt::Ref scrCtx, alt::INative* native, alt::INative::Type argType, v8::Isolate *isolate, V8ResourceImpl* resource, v8::Local val, uint32_t idx) { using ArgType = alt::INative::Type; @@ -116,7 +124,6 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; scrCtx->Push(0); } } @@ -129,7 +136,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + ShowNativeArgParseErrorMsg(isolate, val, native, argType, idx); scrCtx->Push(0); } } @@ -141,7 +148,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + ShowNativeArgParseErrorMsg(isolate, val, native, argType, idx); scrCtx->Push(0); } break; @@ -161,7 +168,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + ShowNativeArgParseErrorMsg(isolate, val, native, argType, idx); scrCtx->Push(0); } } @@ -174,13 +181,13 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + ShowNativeArgParseErrorMsg(isolate, val, native, argType, idx); scrCtx->Push(0); } } else { - Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + ShowNativeArgParseErrorMsg(isolate, val, native, argType, idx); scrCtx->Push(0); } break; @@ -200,13 +207,13 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { - Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + ShowNativeArgParseErrorMsg(isolate, val, native, argType, idx); scrCtx->Push(0.f); } } else { - Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + ShowNativeArgParseErrorMsg(isolate, val, native, argType, idx); scrCtx->Push(0.f); } break; @@ -231,7 +238,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native if(buffer != nullptr) scrCtx->Push(buffer); else { - Log::Error << "Native argument " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; + ShowNativeArgParseErrorMsg(isolate, val, native, argType, idx); scrCtx->Push((void*)nullptr); } break; @@ -334,7 +341,7 @@ static void InvokeNative(const v8::FunctionCallbackInfo &info) auto resource = V8ResourceImpl::Get(v8Ctx); for (uint32_t i = 0; i < argsSize; ++i) - PushArg(ctx, native, args[i], isolate, resource, info[i]); + PushArg(ctx, native, args[i], isolate, resource, info[i], i); if (!native->Invoke(ctx)) { From 792b527cbb9d72bbc09848e10f8526fb2393a1bd Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 15 Jul 2021 02:41:38 +0200 Subject: [PATCH 440/564] Add missing native arg parse error msg --- src/bindings/V8Natives.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index e68510fb..bcac3545 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -124,6 +124,7 @@ static void PushArg(alt::Ref scrCtx, alt::INative* native } else { + ShowNativeArgParseErrorMsg(isolate, val, native, argType, idx); scrCtx->Push(0); } } From d32249af76e116976a767ac500c1101e98d49e0f Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 15 Jul 2021 02:51:10 +0200 Subject: [PATCH 441/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index ccef3e1a..d29c83b7 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit ccef3e1a1dcb585ed3683bdc2d5b8fd048b66187 +Subproject commit d29c83b7db7e320ba470ad6b27b7c0a383d90a75 From 87e0b3d36214059c0499c6ef040fabcacc3693fc Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 15 Jul 2021 14:15:44 +0200 Subject: [PATCH 442/564] Fix isSpawned getter --- bindings/Entity.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index 3fe9802c..e223d7cd 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -185,9 +185,9 @@ static void Detach(const v8::FunctionCallbackInfo &info) static void IsSpawnedGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); + V8_GET_THIS_BASE_OBJECT(entity, alt::IEntity); - V8_RETURN_BOOLEAN(player->GetScriptGuid() != 0); + V8_RETURN_BOOLEAN(entity->GetScriptGuid() != 0); } static void StaticGetByScriptID(const v8::FunctionCallbackInfo &info) From 474e9c79a64ea7556eab669c475fa55588a2bcd9 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 15 Jul 2021 14:17:02 +0200 Subject: [PATCH 443/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index d29c83b7..dda3e266 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit d29c83b7db7e320ba470ad6b27b7c0a383d90a75 +Subproject commit dda3e266bc00f767c15493aa35bf2de5501fd441 From aa21264aa791981cb022ea412c340e6374d7f365 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 16 Jul 2021 01:32:13 +0200 Subject: [PATCH 444/564] Add resource name to native arg parse error msg --- src/bindings/V8Natives.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index bcac3545..90ccb408 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -93,7 +93,8 @@ static const char* GetNativeTypeName(alt::INative::Type type) inline void ShowNativeArgParseErrorMsg(v8::Isolate* isolate, v8::Local val, alt::INative* native, alt::INative::Type argType, uint32_t idx) { V8::SourceLocation source = V8::SourceLocation::GetCurrent(isolate); - Log::Error << "[" << source.GetFileName() << ":" << source.GetLineNumber() << "] " + auto resource = V8ResourceImpl::GetResource(isolate->GetEnteredOrMicrotaskContext()); + Log::Error << "[" << resource->GetName() << ":" << source.GetFileName() << ":" << source.GetLineNumber() << "] " << "Native argument at index " << idx << " " << "(" << V8::GetJSValueTypeName(val) << ")" << " could not be parsed to type " << GetNativeTypeName(argType) << " (" << native->GetName() << ")" << Log::Endl; } From bfe9b940550608c3e5a114c71a343d2bcfdc2438 Mon Sep 17 00:00:00 2001 From: tastydev <39250826+tastydev@users.noreply.github.com> Date: Fri, 16 Jul 2021 04:18:51 +0200 Subject: [PATCH 445/564] add V8_OBJECT_SET_UNSIGNEDINTEGER helper to support uint32 --- V8Helpers.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/V8Helpers.h b/V8Helpers.h index 23a4da07..4eaf9f6d 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -341,6 +341,9 @@ namespace V8 #define V8_OBJECT_SET_INTEGER(v8Val, prop, val) \ (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Integer::New(isolate, val)); +#define V8_OBJECT_SET_UNSIGNEDINTEGER(v8Val, prop, val) \ + (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Integer::NewFromUnsigned(isolate, val)); + #define V8_OBJECT_GET_BOOLEAN(v8Val, prop, val) \ V8_TO_BOOLEAN((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) From e69bee17bbe8eda1d899998c21a675486ba73020 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 16 Jul 2021 14:50:17 +0200 Subject: [PATCH 446/564] Rename object macros --- V8Helpers.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index 4eaf9f6d..0021c2b7 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -335,13 +335,13 @@ namespace V8 #define V8_OBJECT_SET_NUMBER(v8Val, prop, val) \ (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Number::New(isolate, val)); -#define V8_OBJECT_GET_INTEGER(v8Val, prop, val) \ +#define V8_OBJECT_GET_INT(v8Val, prop, val) \ V8_TO_INTEGER((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) -#define V8_OBJECT_SET_INTEGER(v8Val, prop, val) \ +#define V8_OBJECT_SET_INT(v8Val, prop, val) \ (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Integer::New(isolate, val)); -#define V8_OBJECT_SET_UNSIGNEDINTEGER(v8Val, prop, val) \ +#define V8_OBJECT_SET_UINT(v8Val, prop, val) \ (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Integer::NewFromUnsigned(isolate, val)); #define V8_OBJECT_GET_BOOLEAN(v8Val, prop, val) \ From ebc820090347e87381ff4d183939f7fcfdda6576 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 16 Jul 2021 14:55:27 +0200 Subject: [PATCH 447/564] Update helpers --- src/bindings/Blip.cpp | 14 +++++++------- src/bindings/Checkpoint.cpp | 24 ++++++++++++------------ src/bindings/HttpClient.cpp | 18 +++++++++--------- src/bindings/Main.cpp | 4 ++-- src/bindings/Player.cpp | 2 +- src/bindings/Vehicle.cpp | 2 +- src/bindings/WebView.cpp | 20 ++++++++++---------- src/helpers | 2 +- 8 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index 31b235ac..e3340dcd 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -167,9 +167,9 @@ static void SecondaryColorSetter(v8::Local property, v8::LocalSetSecondaryColor({ (uint8_t)r, (uint8_t)g, (uint8_t)b, 255 }); } @@ -427,10 +427,10 @@ static void RouteColorSetter(v8::Local property, v8::LocalSetRouteColor({ (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); } diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index c4c66ee5..48545b8e 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -23,10 +23,10 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_OBJECT_GET_NUMBER(nextPos, "y", y2); V8_OBJECT_GET_NUMBER(nextPos, "z", z2); - V8_OBJECT_GET_INTEGER(color, "r", r); - V8_OBJECT_GET_INTEGER(color, "g", g); - V8_OBJECT_GET_INTEGER(color, "b", b); - V8_OBJECT_GET_INTEGER(color, "a", a); + V8_OBJECT_GET_INT(color, "r", r); + V8_OBJECT_GET_INT(color, "g", g); + V8_OBJECT_GET_INT(color, "b", b); + V8_OBJECT_GET_INT(color, "a", a); alt::Ref cp = alt::ICore::Instance().CreateCheckpoint(type, { x, y, z }, { x2, y2, z2 }, radius, height, { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); V8_BIND_BASE_OBJECT(cp, "Failed to create Checkpoint"); @@ -44,10 +44,10 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_ARG_TO_NUMBER(9, height); V8_ARG_TO_OBJECT(10, color); - V8_OBJECT_GET_INTEGER(color, "r", r); - V8_OBJECT_GET_INTEGER(color, "g", g); - V8_OBJECT_GET_INTEGER(color, "b", b); - V8_OBJECT_GET_INTEGER(color, "a", a); + V8_OBJECT_GET_INT(color, "r", r); + V8_OBJECT_GET_INT(color, "g", g); + V8_OBJECT_GET_INT(color, "b", b); + V8_OBJECT_GET_INT(color, "a", a); alt::Ref cp = alt::ICore::Instance().CreateCheckpoint(type, { x, y, z }, { x2, y2, z2 }, radius, height, { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); V8_BIND_BASE_OBJECT(cp, "Failed to create Checkpoint"); @@ -113,10 +113,10 @@ static void ColorSetter(v8::Local property, v8::Local val V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); V8_TO_OBJECT(value, color); - V8_OBJECT_GET_INTEGER(color, "r", r); - V8_OBJECT_GET_INTEGER(color, "g", g); - V8_OBJECT_GET_INTEGER(color, "b", b); - V8_OBJECT_GET_INTEGER(color, "a", a); + V8_OBJECT_GET_INT(color, "r", r); + V8_OBJECT_GET_INT(color, "g", g); + V8_OBJECT_GET_INT(color, "b", b); + V8_OBJECT_GET_INT(color, "a", a); cp->SetColor({ (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); } diff --git a/src/bindings/HttpClient.cpp b/src/bindings/HttpClient.cpp index c380f5ae..2913e494 100644 --- a/src/bindings/HttpClient.cpp +++ b/src/bindings/HttpClient.cpp @@ -64,7 +64,7 @@ static void Get(const v8::FunctionCallbackInfo& info) { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); - V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode); V8_OBJECT_SET_STRING(responseObj, "body", response.body); V8_NEW_OBJECT(headers); for(auto it = response.headers->Begin(); it; it = response.headers->Next()) @@ -106,7 +106,7 @@ static void Head(const v8::FunctionCallbackInfo& info) { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); - V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode); V8_OBJECT_SET_STRING(responseObj, "body", response.body); V8_NEW_OBJECT(headers); for(auto it = response.headers->Begin(); it; it = response.headers->Next()) @@ -149,7 +149,7 @@ static void Post(const v8::FunctionCallbackInfo& info) { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); - V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode); V8_OBJECT_SET_STRING(responseObj, "body", response.body); V8_NEW_OBJECT(headers); for(auto it = response.headers->Begin(); it; it = response.headers->Next()) @@ -192,7 +192,7 @@ static void Put(const v8::FunctionCallbackInfo& info) { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); - V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode); V8_OBJECT_SET_STRING(responseObj, "body", response.body); V8_NEW_OBJECT(headers); for(auto it = response.headers->Begin(); it; it = response.headers->Next()) @@ -235,7 +235,7 @@ static void Delete(const v8::FunctionCallbackInfo& info) { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); - V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode); V8_OBJECT_SET_STRING(responseObj, "body", response.body); V8_NEW_OBJECT(headers); for(auto it = response.headers->Begin(); it; it = response.headers->Next()) @@ -278,7 +278,7 @@ static void Connect(const v8::FunctionCallbackInfo& info) { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); - V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode); V8_OBJECT_SET_STRING(responseObj, "body", response.body); V8_NEW_OBJECT(headers); for(auto it = response.headers->Begin(); it; it = response.headers->Next()) @@ -321,7 +321,7 @@ static void Options(const v8::FunctionCallbackInfo& info) { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); - V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode); V8_OBJECT_SET_STRING(responseObj, "body", response.body); V8_NEW_OBJECT(headers); for(auto it = response.headers->Begin(); it; it = response.headers->Next()) @@ -364,7 +364,7 @@ static void Trace(const v8::FunctionCallbackInfo& info) { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); - V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode); V8_OBJECT_SET_STRING(responseObj, "body", response.body); V8_NEW_OBJECT(headers); for(auto it = response.headers->Begin(); it; it = response.headers->Next()) @@ -407,7 +407,7 @@ static void Patch(const v8::FunctionCallbackInfo& info) { v8::Context::Scope ctxscope(ctx); V8_NEW_OBJECT(responseObj); - V8_OBJECT_SET_INTEGER(responseObj, "statusCode", response.statusCode); + V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode); V8_OBJECT_SET_STRING(responseObj, "body", response.body); V8_NEW_OBJECT(headers); for(auto it = response.headers->Begin(); it; it = response.headers->Next()) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 1820d06b..80af7ab2 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -147,8 +147,8 @@ static void SetCursorPos(const v8::FunctionCallbackInfo &info) V8_CHECK_ARGS_LEN(1); V8_ARG_TO_OBJECT(1, pos); - V8_OBJECT_GET_INTEGER(pos, "x", x); - V8_OBJECT_GET_INTEGER(pos, "y", y); + V8_OBJECT_GET_INT(pos, "x", x); + V8_OBJECT_GET_INT(pos, "y", y); ICore::Instance().SetCursorPosition({ x, y }); } diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 737edf64..005c8ce3 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -16,7 +16,7 @@ static void ToString(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE_CONTEXT(); auto player = info.This(); - V8_OBJECT_GET_INTEGER(player, "id", id); + V8_OBJECT_GET_INT(player, "id", id); V8_OBJECT_GET_STRING(player, "name", name); std::ostringstream ss; diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 130a719a..4efcb102 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -16,7 +16,7 @@ static void ToString(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE_CONTEXT(); auto vehicle = info.This(); - V8_OBJECT_GET_INTEGER(vehicle, "id", id); + V8_OBJECT_GET_INT(vehicle, "id", id); V8_OBJECT_GET_NUMBER(vehicle, "model", model); std::ostringstream ss; diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index 551fe830..ccd319f6 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -211,11 +211,11 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_ARG_TO_OBJECT(3, pos); V8_ARG_TO_OBJECT(4, size); - V8_OBJECT_GET_INTEGER(pos, "x", posX); - V8_OBJECT_GET_INTEGER(pos, "y", posY); + V8_OBJECT_GET_INT(pos, "x", posX); + V8_OBJECT_GET_INT(pos, "y", posY); - V8_OBJECT_GET_INTEGER(size, "x", sizeX); - V8_OBJECT_GET_INTEGER(size, "y", sizeY); + V8_OBJECT_GET_INT(size, "x", sizeX); + V8_OBJECT_GET_INT(size, "y", sizeY); view = alt::ICore::Instance().CreateWebView(altres, url, { posX, posY }, { sizeX, sizeY }, true, isOverlayBool); } @@ -224,11 +224,11 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_ARG_TO_OBJECT(2, pos); V8_ARG_TO_OBJECT(3, size); - V8_OBJECT_GET_INTEGER(pos, "x", posX); - V8_OBJECT_GET_INTEGER(pos, "y", posY); + V8_OBJECT_GET_INT(pos, "x", posX); + V8_OBJECT_GET_INT(pos, "y", posY); - V8_OBJECT_GET_INTEGER(size, "x", sizeX); - V8_OBJECT_GET_INTEGER(size, "y", sizeY); + V8_OBJECT_GET_INT(size, "x", sizeX); + V8_OBJECT_GET_INT(size, "y", sizeY); view = alt::ICore::Instance().CreateWebView(altres, url, { posX, posY }, { sizeX, sizeY }, true, false); } @@ -247,8 +247,8 @@ static void Constructor(const v8::FunctionCallbackInfo& info) { V8_ARG_TO_OBJECT(2, pos); - V8_OBJECT_GET_INTEGER(pos, "x", posX); - V8_OBJECT_GET_INTEGER(pos, "y", posY); + V8_OBJECT_GET_INT(pos, "x", posX); + V8_OBJECT_GET_INT(pos, "y", posY); view = alt::ICore::Instance().CreateWebView(altres, url, { posX, posY }, { 0, 0 }, true, false); } diff --git a/src/helpers b/src/helpers index dda3e266..e69bee17 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit dda3e266bc00f767c15493aa35bf2de5501fd441 +Subproject commit e69bee17bbe8eda1d899998c21a675486ba73020 From 9f4952c2217aaaa5023b1976c66d35f289898bd7 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 17 Jul 2021 02:53:36 +0200 Subject: [PATCH 448/564] Output individual timer counts in GetTimersCount --- V8ResourceImpl.h | 10 ++++++++-- V8Timer.h | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index f58b87de..b77f047d 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -199,9 +199,15 @@ class V8ResourceImpl : public alt::IResource::Impl oldTimers.push_back(id); } - uint32_t GetTimersCount() + void GetTimersCount(size_t* totalCount, size_t* everyTickCount, size_t* intervalCount, size_t* timeoutCount) { - return timers.size(); + *totalCount = timers.size(); + for(auto [id, timer] : timers) + { + if(timer->GetInterval() == 0 && !timer->IsOnce()) *everyTickCount += 1; + else if(timer->IsOnce()) *timeoutCount += 1; + else *intervalCount += 1; + } } void NotifyPoolUpdate(alt::IBaseObject *ent); diff --git a/V8Timer.h b/V8Timer.h index dd55594d..a4ea3138 100644 --- a/V8Timer.h +++ b/V8Timer.h @@ -35,6 +35,8 @@ class V8Timer } const V8::SourceLocation &GetLocation() const { return location; } + int64_t GetInterval() { return interval; } + bool IsOnce() { return once; } private: v8::Isolate *isolate; From 8e9f3c09318237ee2153e2608fc79797076cc47a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 17 Jul 2021 02:57:01 +0200 Subject: [PATCH 449/564] Add more detailed info in timers command --- src/helpers | 2 +- src/main.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/helpers b/src/helpers index e69bee17..9f4952c2 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit e69bee17bbe8eda1d899998c21a675486ba73020 +Subproject commit 9f4952c2217aaaa5023b1976c66d35f289898bd7 diff --git a/src/main.cpp b/src/main.cpp index 05a8503b..ee159954 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,11 @@ static void TimersCommand(alt::Array, void* runtime) Log::Info << "================ Timer info =================" << Log::Endl; for(auto resource : resources) { - Log::Info << resource->GetResource()->GetName() << ": " << resource->GetTimersCount() << " running timers"; + size_t total, everyTick, interval, timeout; + resource->GetTimersCount(&total, &everyTick, &interval, &timeout); + Log::Info << resource->GetResource()->GetName() << ": " << total << " running timers (" + << everyTick << " EveryTick, " << interval << " Interval, " << timeout << " Timeout" + << ")" << Log::Endl; } Log::Info << "======================================================" << Log::Endl; } From 06e460208afcbbae042ed140fbab42061e2470b1 Mon Sep 17 00:00:00 2001 From: Leon B Date: Sun, 18 Jul 2021 02:37:57 +0200 Subject: [PATCH 450/564] Use bind helpers (#75) * Update helpers * Use binding helpers * Fix webview url binding * Update SDK * Fix vehicle bindings * Add binding helpers to Blip class * Add bind helpers to local player class * Update SDK * Reenable broken blip properties * Remove unused functions from blip bindings file --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/Audio.cpp | 129 +------- src/bindings/Blip.cpp | 538 ++---------------------------- src/bindings/Checkpoint.cpp | 99 +----- src/bindings/LocalPlayer.cpp | 11 +- src/bindings/Player.cpp | 271 ++-------------- src/bindings/Vehicle.cpp | 541 +------------------------------ src/bindings/WebSocketClient.cpp | 122 +------ src/bindings/WebView.cpp | 88 +---- 9 files changed, 100 insertions(+), 1701 deletions(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index f7b046d7..2ebb0c16 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit f7b046d7a4a11bbe44065a4225464bf1ed7bb22b +Subproject commit 2ebb0c1687d0861b0d346365b0bac9215ccdd501 diff --git a/src/bindings/Audio.cpp b/src/bindings/Audio.cpp index 2c224760..93ffe035 100644 --- a/src/bindings/Audio.cpp +++ b/src/bindings/Audio.cpp @@ -1,4 +1,5 @@ #include "../helpers/V8Helpers.h" +#include "../helpers/V8BindHelpers.h" #include "../helpers/V8ResourceImpl.h" #include "../helpers/V8Class.h" #include "../CV8ScriptRuntime.h" @@ -83,57 +84,6 @@ static void GetEventListeners(const v8::FunctionCallbackInfo& info) V8_RETURN(array); } -static void SourceGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - V8_RETURN_ALT_STRING(audio->GetSource()); -} - -static void SourceSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - V8_TO_STRING(val, source); - audio->SetSource(source); -} - -static void LoopedGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - V8_RETURN_BOOLEAN(audio->IsLoop()); -} - -static void LoopedSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - V8_TO_BOOLEAN(val, looped); - audio->SetLoop(looped); -} - -static void VolumeGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - V8_RETURN_NUMBER(audio->GetVolume()); -} - -static void VolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - V8_TO_NUMBER(val, volume); - audio->SetVolume(volume); -} - static void CategoryGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE(); @@ -161,14 +111,6 @@ static void CategorySetter(v8::Local, v8::Local val, cons audio->SetCategory(category); } -static void FrontendPlayGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - V8_RETURN_BOOLEAN(audio->IsFrontendPlay()); -} - static void AddOutput(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -227,54 +169,6 @@ static void GetOutputs(const v8::FunctionCallbackInfo& info) V8_RETURN(arr); } -static void CurrentTimeGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - V8_RETURN_NUMBER(audio->GetCurrentTime()); -} - -static void MaxTimeGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - V8_RETURN_NUMBER(audio->GetMaxTime()); -} - -static void PlayingGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - V8_RETURN_BOOLEAN(audio->IsPlaying()); -} - -static void Play(const v8::FunctionCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - audio->Play(); -} - -static void Pause(const v8::FunctionCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - audio->Pause(); -} - -static void Reset(const v8::FunctionCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(audio, alt::IAudio); - - audio->Reset(); -} - static void Seek(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -288,27 +182,28 @@ static void Seek(const v8::FunctionCallbackInfo& info) extern V8Class v8BaseObject; extern V8Class v8Audio("Audio", v8BaseObject, &Constructor, [](v8::Local tpl) { + using namespace alt; v8::Isolate *isolate = v8::Isolate::GetCurrent(); V8::SetMethod(isolate, tpl, "on", &On); V8::SetMethod(isolate, tpl, "off", &Off); V8::SetMethod(isolate, tpl, "getEventListeners", GetEventListeners); - V8::SetAccessor(isolate, tpl, "source", &SourceGetter, &SourceSetter); - V8::SetAccessor(isolate, tpl, "looped", &LoopedGetter, &LoopedSetter); - V8::SetAccessor(isolate, tpl, "volume", &VolumeGetter, &VolumeSetter); + V8::SetAccessor(isolate, tpl, "source"); + V8::SetAccessor(isolate, tpl, "looped"); + V8::SetAccessor(isolate, tpl, "volume"); V8::SetAccessor(isolate, tpl, "category", &CategoryGetter, &CategorySetter); - V8::SetAccessor(isolate, tpl, "frontendPlay", &FrontendPlayGetter); - V8::SetAccessor(isolate, tpl, "currentTime", &CurrentTimeGetter); - V8::SetAccessor(isolate, tpl, "maxTime", &MaxTimeGetter); - V8::SetAccessor(isolate, tpl, "playing", &PlayingGetter); + V8::SetAccessor(isolate, tpl, "frontendPlay"); + V8::SetAccessor(isolate, tpl, "currentTime"); + V8::SetAccessor(isolate, tpl, "maxTime"); + V8::SetAccessor(isolate, tpl, "playing"); V8::SetMethod(isolate, tpl, "addOutput", &AddOutput); V8::SetMethod(isolate, tpl, "removeOutput", &RemoveOutput); V8::SetMethod(isolate, tpl, "getOutputs", &GetOutputs); - V8::SetMethod(isolate, tpl, "play", &Play); - V8::SetMethod(isolate, tpl, "pause", &Pause); - V8::SetMethod(isolate, tpl, "reset", &Reset); + V8::SetMethod(isolate, tpl, "play"); + V8::SetMethod(isolate, tpl, "pause"); + V8::SetMethod(isolate, tpl, "reset"); V8::SetMethod(isolate, tpl, "seek", &Seek); }); diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index e3340dcd..8146e02f 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -1,5 +1,6 @@ #include "../CV8Resource.h" #include "../helpers/V8Helpers.h" +#include "../helpers/V8BindHelpers.h" #include "cpp-sdk/script-objects/IBlip.h" static void ToString(const v8::FunctionCallbackInfo& info) @@ -87,333 +88,6 @@ static void ConstructorVehicleBlip(const v8::FunctionCallbackInfo& in V8_BIND_BASE_OBJECT(blip, "Failed to create VehicleBlip"); } -static void SizeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - - V8_TO_OBJECT(value, pos); - V8_OBJECT_GET_NUMBER(pos, "x", x); - V8_OBJECT_GET_NUMBER(pos, "y", y); - - blip->SetScaleXY(x, y); -} - -static void SizeGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - - alt::Vector2f blipPos = blip->GetScaleXY(); - - V8_RETURN(resource->CreateVector2(blipPos)); -} - -static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_NUMBER(blip->GetScaleXY()[0]); -} - -static void ScaleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_NUMBER(value, val); - blip->SetScaleXY(val, val); -} - -static void SpriteGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INT(blip->GetSprite()); -} - -static void SpriteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); - blip->SetSprite(val); -} - -static void ColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INT(blip->GetColor()); -} - -static void ColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); - blip->SetColor(val); -} - -static void SecondaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN(resource->CreateRGBA(blip->GetSecondaryColor())); -} - -static void SecondaryColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - - V8_TO_OBJECT(value, color); - V8_OBJECT_GET_INT(color, "r", r); - V8_OBJECT_GET_INT(color, "g", g); - V8_OBJECT_GET_INT(color, "b", b); - - blip->SetSecondaryColor({ (uint8_t)r, (uint8_t)g, (uint8_t)b, 255 }); -} - -static void AlphaGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INT(blip->GetAlpha()); -} - -static void AlphaSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); - blip->SetAlpha(val); -} - -static void FlashTimerGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INT(blip->GetFlashTimer()); -} - -static void FlashTimerSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); - blip->SetFlashTimer(val); -} - -static void FlashIntervalGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INT(blip->GetFlashInterval()); -} - -static void FlashIntervalSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); - blip->SetFlashInterval(val); -} - -static void FriendlyGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetAsFriendly()); -} - -static void FriendlySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetAsFriendly(val); -} - -static void RouteGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetRoute()); -} - -static void RouteSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetRoute(val); -} - -static void BrightGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetBright()); -} - -static void BrightSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetBright(val); -} - -static void NumberGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INT(blip->GetNumber()); -} - -static void NumberSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); - blip->SetNumber(val); -} - -static void DisplayGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INT(blip->GetDisplay()); -} - -static void DisplaySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); - blip->SetDisplay(val); -} - -static void ShowConeGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetShowCone()); -} - -static void ShowConeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetShowCone(val); -} - -static void FlashesGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetFlashes()); -} - -static void FlashesSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetFlashes(val); -} - -static void FlashesAlternateGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetFlashesAlternate()); -} - -static void FlashesAlternateSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetFlashesAlternate(val); -} - -static void ShortRangeGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetAsShortRange()); -} - -static void ShortRangeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetAsShortRange(val); -} - -static void PriorityGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INT(blip->GetPriority()); -} - -static void PrioritySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); - blip->SetPriority(val); -} - -static void RotationGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_NUMBER(blip->GetRotation()); -} - -static void RotationSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_NUMBER(value, val); - blip->SetRotation(val); -} - -static void GxtNameGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_STRING(blip->GetGxtName()); -} - -static void GxtNameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_STRING(value, val); - blip->SetGxtName(val.CStr()); -} - -static void NameGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_STRING(blip->GetName()); -} - -static void NameSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_STRING(value, val); - blip->SetName(val.CStr()); -} - static void RouteColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -435,156 +109,6 @@ static void RouteColorSetter(v8::Local property, v8::LocalSetRouteColor({ (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); } -static void PulseGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetPulse()); -} - -static void PulseSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetPulse(val); -} - -static void AsMissionCreatorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetAsMissionCreator()); -} - -static void AsMissionCreatorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetAsMissionCreator(val); -} - -static void TickVisibleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetTickVisible()); -} - -static void TickVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetTickVisible(val); -} - -static void HeadingIndicatorVisibleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetHeadingIndicatorVisible()); -} - -static void HeadingIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetHeadingIndicatorVisible(val); -} - -static void OutlineIndicatorVisibleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetOutlineIndicatorVisible()); -} - -static void OutlineIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetOutlineIndicatorVisible(val); -} - -static void FriendIndicatorVisibleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetFriendIndicatorVisible()); -} - -static void FriendIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetFriendIndicatorVisible(val); -} - -static void CrewIndicatorVisibleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetCrewIndicatorVisible()); -} - -static void CrewIndicatorVisibleSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetCrewIndicatorVisible(val); -} - -static void CategoryGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_INT(blip->GetCategory()); -} - -static void CategorySetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_INTEGER(value, val); - blip->SetCategory(val); -} - -static void HighDetailGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetAsHighDetail()); -} - -static void HighDetailSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetAsHighDetail(val); -} - -static void ShrinkedGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_RETURN_BOOLEAN(blip->GetShrinked()); -} - -static void ShrinkedSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); - V8_TO_BOOLEAN(value, val); - blip->SetShrinked(val); -} - static void Fade(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -597,42 +121,42 @@ static void Fade(const v8::FunctionCallbackInfo& info) extern V8Class v8WorldObject; extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local tpl){ + using namespace alt; v8::Isolate* isolate = v8::Isolate::GetCurrent(); V8::SetMethod(isolate, tpl, "toString", ToString); V8::SetStaticAccessor(isolate, tpl, "routeColor", &RouteColorGetter, &RouteColorSetter); - V8::SetAccessor(isolate, tpl, "sprite", &SpriteGetter, &SpriteSetter); - V8::SetAccessor(isolate, tpl, "size", &SizeGetter, &SizeSetter); - V8::SetAccessor(isolate, tpl, "scale", &ScaleGetter, &ScaleSetter); - V8::SetAccessor(isolate, tpl, "color", &ColorGetter, &ColorSetter); - V8::SetAccessor(isolate, tpl, "secondaryColor", &SecondaryColorGetter, &SecondaryColorSetter); - V8::SetAccessor(isolate, tpl, "alpha", &AlphaGetter, &AlphaSetter); - V8::SetAccessor(isolate, tpl, "flashTimer", &FlashTimerGetter, &FlashTimerSetter); - V8::SetAccessor(isolate, tpl, "flashInterval", &FlashIntervalGetter, &FlashIntervalSetter); - V8::SetAccessor(isolate, tpl, "route", &RouteGetter, &RouteSetter); - V8::SetAccessor(isolate, tpl, "bright", &BrightGetter, &BrightSetter); - V8::SetAccessor(isolate, tpl, "number", &NumberGetter, &NumberSetter); - V8::SetAccessor(isolate, tpl, "display", &DisplayGetter, &DisplaySetter); - V8::SetAccessor(isolate, tpl, "showCone", &ShowConeGetter, &ShowConeSetter); - V8::SetAccessor(isolate, tpl, "flashes", &FlashesGetter, &FlashesSetter); - V8::SetAccessor(isolate, tpl, "flashesAlternate", &FlashesAlternateGetter, &FlashesAlternateSetter); - V8::SetAccessor(isolate, tpl, "shortRange", &ShortRangeGetter, &ShortRangeSetter); - V8::SetAccessor(isolate, tpl, "priority", &PriorityGetter, &PrioritySetter); - V8::SetAccessor(isolate, tpl, "heading", &RotationGetter, &RotationSetter); - V8::SetAccessor(isolate, tpl, "gxtName", &GxtNameGetter, &GxtNameSetter); - V8::SetAccessor(isolate, tpl, "name", &NameGetter, &NameSetter); - V8::SetAccessor(isolate, tpl, "pulse", &PulseGetter, &PulseSetter); - V8::SetAccessor(isolate, tpl, "asMissionCreator", &AsMissionCreatorGetter, &AsMissionCreatorSetter); - V8::SetAccessor(isolate, tpl, "tickVisible", &TickVisibleGetter, &TickVisibleSetter); - V8::SetAccessor(isolate, tpl, "headingIndicatorVisible", &HeadingIndicatorVisibleGetter, &HeadingIndicatorVisibleSetter); - V8::SetAccessor(isolate, tpl, "outlineIndicatorVisible", &OutlineIndicatorVisibleGetter, &OutlineIndicatorVisibleSetter); - V8::SetAccessor(isolate, tpl, "friendIndicatorVisible", &FriendIndicatorVisibleGetter, &FriendIndicatorVisibleSetter); - V8::SetAccessor(isolate, tpl, "crewIndicatorVisible", &CrewIndicatorVisibleGetter, &CrewIndicatorVisibleSetter); - V8::SetAccessor(isolate, tpl, "category", &CategoryGetter, &CategorySetter); - V8::SetAccessor(isolate, tpl, "highDetail", &HighDetailGetter, &HighDetailSetter); - V8::SetAccessor(isolate, tpl, "shrinked", &ShrinkedGetter, &ShrinkedSetter); + V8::SetAccessor(isolate, tpl, "sprite"); + V8::SetAccessor(isolate, tpl, "size"); + V8::SetAccessor(isolate, tpl, "color"); + V8::SetAccessor(isolate, tpl, "secondaryColor"); + V8::SetAccessor(isolate, tpl, "alpha"); + V8::SetAccessor(isolate, tpl, "flashTimer"); + V8::SetAccessor(isolate, tpl, "flashInterval"); + V8::SetAccessor(isolate, tpl, "route"); + V8::SetAccessor(isolate, tpl, "bright"); + V8::SetAccessor(isolate, tpl, "number"); + V8::SetAccessor(isolate, tpl, "display"); + V8::SetAccessor(isolate, tpl, "showCone"); + V8::SetAccessor(isolate, tpl, "flashes"); + V8::SetAccessor(isolate, tpl, "flashesAlternate"); + V8::SetAccessor(isolate, tpl, "shortRange"); + V8::SetAccessor(isolate, tpl, "priority"); + V8::SetAccessor(isolate, tpl, "heading"); + V8::SetAccessor(isolate, tpl, "gxtName"); + V8::SetAccessor(isolate, tpl, "name"); + V8::SetAccessor(isolate, tpl, "pulse"); + V8::SetAccessor(isolate, tpl, "asMissionCreator"); + V8::SetAccessor(isolate, tpl, "tickVisible"); + V8::SetAccessor(isolate, tpl, "headingIndicatorVisible"); + V8::SetAccessor(isolate, tpl, "outlineIndicatorVisible"); + V8::SetAccessor(isolate, tpl, "friendIndicatorVisible"); + V8::SetAccessor(isolate, tpl, "crewIndicatorVisible"); + V8::SetAccessor(isolate, tpl, "category"); + V8::SetAccessor(isolate, tpl, "highDetail"); + V8::SetAccessor(isolate, tpl, "shrinked"); V8::SetMethod(isolate, tpl, "fade", &Fade); }); diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index 48545b8e..58389d2f 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -1,5 +1,6 @@ #include "../CV8Resource.h" #include "../helpers/V8Helpers.h" +#include "../helpers/V8BindHelpers.h" #include "cpp-sdk/script-objects/ICheckpoint.h" static void Constructor(const v8::FunctionCallbackInfo& info) @@ -55,93 +56,6 @@ static void Constructor(const v8::FunctionCallbackInfo& info) else V8Helpers::Throw(isolate, "6 or 10 arguments expected"); } -static void TypeGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); - V8_RETURN_INT(cp->GetCheckpointType()); -} - -static void TypeSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); - V8_TO_INTEGER(value, val); - cp->SetCheckpointType(val); -} - -static void RadiusGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); - V8_RETURN_NUMBER(cp->GetRadius()); -} - -static void RadiusSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); - V8_TO_NUMBER(value, val); - cp->SetRadius(val); -} - -static void HeightGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); - V8_RETURN_NUMBER(cp->GetHeight()); -} - -static void HeightSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); - V8_TO_NUMBER(value, val); - cp->SetHeight(val); -} - -static void ColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); - V8_RETURN(resource->CreateRGBA(cp->GetColor())); -} - -static void ColorSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); - - V8_TO_OBJECT(value, color); - V8_OBJECT_GET_INT(color, "r", r); - V8_OBJECT_GET_INT(color, "g", g); - V8_OBJECT_GET_INT(color, "b", b); - V8_OBJECT_GET_INT(color, "a", a); - - cp->SetColor({ (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); -} - -static void NextPosGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); - - V8_RETURN(resource->CreateVector3(cp->GetNextPosition())); -} - -static void NextPosSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(cp, alt::ICheckpoint); - - V8_TO_OBJECT(val, pos); - V8_OBJECT_GET_NUMBER(pos, "x", x); - V8_OBJECT_GET_NUMBER(pos, "y", y); - V8_OBJECT_GET_NUMBER(pos, "z", z); - - cp->SetNextPosition({ x, y, z }); -} - static void IsEntityIn(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -167,13 +81,14 @@ static void IsPointIn(const v8::FunctionCallbackInfo& info) extern V8Class v8WorldObject; extern V8Class v8Checkpoint("Checkpoint", v8WorldObject, Constructor, [](v8::Local tpl) { + using namespace alt; v8::Isolate* isolate = v8::Isolate::GetCurrent(); - V8::SetAccessor(isolate, tpl, "checkpointType", &TypeGetter, &TypeSetter); - V8::SetAccessor(isolate, tpl, "radius", &RadiusGetter, &RadiusSetter); - V8::SetAccessor(isolate, tpl, "height", &HeightGetter, &HeightSetter); - V8::SetAccessor(isolate, tpl, "color", &ColorGetter, &ColorSetter); - V8::SetAccessor(isolate, tpl, "nextPos", &NextPosGetter, &NextPosSetter); + V8::SetAccessor(isolate, tpl, "checkpointType"); + V8::SetAccessor(isolate, tpl, "radius"); + V8::SetAccessor(isolate, tpl, "height"); + V8::SetAccessor(isolate, tpl, "color"); + V8::SetAccessor(isolate, tpl, "nextPos"); V8::SetMethod(isolate, tpl, "isEntityIn", &IsEntityIn); V8::SetMethod(isolate, tpl, "isPointIn", &IsPointIn); diff --git a/src/bindings/LocalPlayer.cpp b/src/bindings/LocalPlayer.cpp index 23190ddc..b354feeb 100644 --- a/src/bindings/LocalPlayer.cpp +++ b/src/bindings/LocalPlayer.cpp @@ -2,20 +2,13 @@ #include "../helpers/V8Class.h" #include "../helpers/V8Entity.h" #include "../helpers/V8ResourceImpl.h" +#include "../helpers/V8BindHelpers.h" #include "cpp-sdk/objects/ILocalPlayer.h" -static void CurrentAmmoGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(player, alt::ILocalPlayer); - - V8_RETURN_UINT(player->GetCurrentAmmo()); -} - extern V8Class v8Player; extern V8Class v8LocalPlayer("LocalPlayer", v8Player, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); - V8::SetAccessor(isolate, tpl, "currentAmmo", &CurrentAmmoGetter); + V8::SetAccessor(isolate, tpl, "currentAmmo"); }); diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 005c8ce3..5ddcffa5 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -1,5 +1,6 @@ #include "../helpers/V8Helpers.h" +#include "../helpers/V8BindHelpers.h" #include "../helpers/V8Class.h" #include "../helpers/V8Entity.h" #include "../helpers/V8ResourceImpl.h" @@ -25,38 +26,6 @@ static void ToString(const v8::FunctionCallbackInfo& info) V8_RETURN_STRING(ss.str().c_str()); } -static void NameGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_STRING(player->GetName().CStr()); -} - -static void VehicleGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_BASE_OBJECT(player->GetVehicle()); -} - -static void TalkingGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_BOOLEAN(player->IsTalking()); -} - -static void MicLevelGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_NUMBER(player->GetMicLevel()); -} - static void CurrentWeaponComponentsGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -72,158 +41,6 @@ static void CurrentWeaponComponentsGetter(v8::Local, const v8::Prope V8_RETURN(componentsArray); } -static void CurrentWeaponTintIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_INT(player->GetCurrentWeaponTintIndex()); -} - -static void CurrentWeaponGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_UINT(player->GetCurrentWeapon()); -} - -static void IsJumpingGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_BOOLEAN(player->IsJumping()); -} - -static void IsInRagdollGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_BOOLEAN(player->IsInRagdoll()); -} - -static void IsAimingGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_BOOLEAN(player->IsAiming()); -} - -static void IsShootingGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_BOOLEAN(player->IsShooting()); -} - -static void IsReloadingGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_BOOLEAN(player->IsReloading()); -} - -static void ArmourGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_INT(player->GetArmour()); -} - -static void MaxArmourGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_INT(player->GetMaxArmour()); -} - -static void MoveSpeedGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_NUMBER(player->GetMoveSpeed()); -} - -static void AimPosGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN(resource->CreateVector3(player->GetAimPos())); -} - -static void HeadRotationGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN(resource->CreateVector3(player->GetHeadRotation())); -} - -static void SeatGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_INT(player->GetSeat()); -} - -static void EntityAimingAtGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_BASE_OBJECT(player->GetEntityAimingAt()); -} - -static void EntityAimOffsetGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN(resource->CreateVector3(player->GetEntityAimOffset())); -} - -static void FlashlightActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_BOOLEAN(player->IsFlashlightActive()); -} - -static void HealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_INT(player->GetHealth()); -} - -static void MaxHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_INT(player->GetMaxHealth()); -} - -static void IsDeadGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_BOOLEAN(player->IsDead()); -} - static void WeaponHasComponent(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -247,50 +64,6 @@ static void GetWeaponTintIndex(const v8::FunctionCallbackInfo& info) V8_RETURN_INT(player->GetWeaponTintIndex(weaponHash)); } -static void GetCurrentWeapon(const v8::FunctionCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - - V8_RETURN_INT(player->GetCurrentWeapon()); -} - -static void SpatialVolumeGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(_this, alt::IPlayer); - - V8_RETURN_NUMBER(_this->GetSpatialVolume()); -} - -static void SpatialVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(_this, alt::IPlayer); - - V8_TO_NUMBER(val, volume); - - _this->SetSpatialVolume(volume); -} - -static void NonSpatialVolumeGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(_this, alt::IPlayer); - - V8_RETURN_NUMBER(_this->GetNonSpatialVolume()); -} - -static void NonSpatialVolumeSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(_this, alt::IPlayer); - - V8_TO_NUMBER(val, volume); - - _this->SetNonSpatialVolume(volume); -} - static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -351,34 +124,34 @@ extern V8Class v8Player("Player", v8Entity, [](v8::Local t V8::SetStaticAccessor(isolate, tpl, "local", &LocalGetter); // Common getters - V8::SetAccessor(isolate, tpl, "name", &NameGetter); - V8::SetAccessor(isolate, tpl, "vehicle", &VehicleGetter); - V8::SetAccessor(isolate, tpl, "seat", &SeatGetter); - V8::SetAccessor(isolate, tpl, "isTalking", &TalkingGetter); - V8::SetAccessor(isolate, tpl, "micLevel", &MicLevelGetter); - V8::SetAccessor(isolate, tpl, "health", &HealthGetter); - V8::SetAccessor(isolate, tpl, "maxHealth", &MaxHealthGetter); - V8::SetAccessor(isolate, tpl, "armour", &ArmourGetter); - V8::SetAccessor(isolate, tpl, "maxArmour", &MaxArmourGetter); - V8::SetAccessor(isolate, tpl, "spatialVolume", &SpatialVolumeGetter, &SpatialVolumeSetter); - V8::SetAccessor(isolate, tpl, "nonSpatialVolume", &NonSpatialVolumeGetter, &NonSpatialVolumeSetter); + V8::SetAccessor(isolate, tpl, "name"); + V8::SetAccessor, &IPlayer::GetVehicle>(isolate, tpl, "vehicle"); + V8::SetAccessor(isolate, tpl, "seat"); + V8::SetAccessor(isolate, tpl, "isTalking"); + V8::SetAccessor(isolate, tpl, "micLevel"); + V8::SetAccessor(isolate, tpl, "health"); + V8::SetAccessor(isolate, tpl, "maxHealth"); + V8::SetAccessor(isolate, tpl, "armour"); + V8::SetAccessor(isolate, tpl, "maxArmour"); + V8::SetAccessor(isolate, tpl, "spatialVolume"); + V8::SetAccessor(isolate, tpl, "nonSpatialVolume"); // Weapon getters V8::SetAccessor(isolate, tpl, "currentWeaponComponents", &CurrentWeaponComponentsGetter); //V8::SetAccessor(isolate, tpl, "currentWeaponTintIndex", &CurrentWeaponTintIndexGetter); - V8::SetAccessor(isolate, tpl, "currentWeapon", &CurrentWeaponGetter); - V8::SetAccessor(isolate, tpl, "entityAimingAt", &EntityAimingAtGetter); - V8::SetAccessor(isolate, tpl, "entityAimOffset", &EntityAimOffsetGetter); - V8::SetAccessor(isolate, tpl, "flashlightActive", &FlashlightActiveGetter); - V8::SetAccessor(isolate, tpl, "aimPos", &AimPosGetter); + V8::SetAccessor(isolate, tpl, "currentWeapon"); + V8::SetAccessor, &IPlayer::GetEntityAimingAt>(isolate, tpl, "entityAimingAt"); + V8::SetAccessor(isolate, tpl, "entityAimOffset"); + V8::SetAccessor(isolate, tpl, "flashlightActive"); + V8::SetAccessor(isolate, tpl, "aimPos"); // Gamestate getters //V8::SetAccessor(isolate, tpl, "isJumping", &IsJumpingGetter); - V8::SetAccessor(isolate, tpl, "isInRagdoll", &IsInRagdollGetter); - V8::SetAccessor(isolate, tpl, "isAiming", &IsAimingGetter); + V8::SetAccessor(isolate, tpl, "isInRagdoll"); + V8::SetAccessor(isolate, tpl, "isAiming"); //V8::SetAccessor(isolate, tpl, "isShooting", &IsShootingGetter); //V8::SetAccessor(isolate, tpl, "isReloading", &IsReloadingGetter); - V8::SetAccessor(isolate, tpl, "isDead", &IsDeadGetter); - V8::SetAccessor(isolate, tpl, "moveSpeed", &MoveSpeedGetter); - V8::SetAccessor(isolate, tpl, "headRot", &HeadRotationGetter); + V8::SetAccessor(isolate, tpl, "isDead"); + V8::SetAccessor(isolate, tpl, "moveSpeed"); + V8::SetAccessor(isolate, tpl, "headRot"); }); diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 4efcb102..44fa3f01 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -1,5 +1,6 @@ #include "../helpers/V8Helpers.h" +#include "../helpers/V8BindHelpers.h" #include "../helpers/V8Class.h" #include "../helpers/V8Entity.h" #include "../helpers/V8ResourceImpl.h" @@ -36,271 +37,6 @@ static void HandlingGetter(v8::Local, const v8::PropertyCallbackInfo V8_RETURN(v8Handling.New(ctx, args)); } -static void SpeedGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_NUMBER(vehicle->GetWheelSpeed()); -} - -static void GearGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetCurrentGear()); -} - -static void GearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_TO_INTEGER(val, gear); - vehicle->SetCurrentGear(gear); -} - -static void RPMGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_NUMBER(vehicle->GetCurrentRPM()); -} - -static void WheelsCountGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetWheelsCount()); -} - -static void SpeedVectorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN(resource->CreateVector3(vehicle->GetSpeedVector())); -} - -static void DriverGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BASE_OBJECT(vehicle->GetDriver()); -} - -static void IsDestroyedGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsDestroyed()); -} - -static void ModKitsCountGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetModKitsCount()); -} - -static void ModKitGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetModKit()); -} - -static void IsPrimaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsPrimaryColorRGB()); -} - -static void PrimaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetPrimaryColor()); -} - -static void PrimaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN(resource->CreateRGBA(vehicle->GetPrimaryColorRGB())); -} - -static void IsSecondaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsSecondaryColorRGB()); -} - -static void SecondaryColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetSecondaryColor()); -} - -static void SecondaryColorRGBGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN(resource->CreateRGBA(vehicle->GetSecondaryColorRGB())); -} - -static void PearlColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetPearlColor()); -} - -static void WheelColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetWheelColor()); -} - -static void InteriorColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetInteriorColor()); -} - -static void DashboardColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetDashboardColor()); -} - -static void IsTireSmokeColorCustomGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsTireSmokeColorCustom()); -} - -static void TireSmokeColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN(resource->CreateRGBA(vehicle->GetTireSmokeColor())); -} - -static void WheelTypeGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetWheelType()); -} - -static void WheelVariationGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetWheelVariation()); -} - -static void RearWheelVariationGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetRearWheelVariation()); -} - -static void IsCustomTiresGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->GetCustomTires()); -} - -static void SpecialDarknessGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetSpecialDarkness()); -} - -static void NumberplateIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetNumberplateIndex()); -} - -static void NumberplateTextGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_STRING(vehicle->GetNumberplateText().CStr()); -} - -static void WindowTintGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetWindowTint()); -} - -static void DirtLevelGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetDirtLevel()); -} - -static void IsNeonActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsNeonActive()); -} - -static void NeonColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT_RESOURCE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN(resource->CreateRGBA(vehicle->GetNeonColor())); -} - static void NeonGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -318,174 +54,6 @@ static void NeonGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetLivery()); -} - -static void RoofLiveryGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetRoofLivery()); -} - -static void EngineOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsEngineOn()); -} - -static void HandbrakeActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsHandbrakeActive()); -} - -static void HeadlightColorGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetHeadlightColor()); -} - -static void RadioStationIndexGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetRadioStationIndex()); -} - -static void IsSirenActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsSirenActive()); -} - -static void LockStateGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetLockState()); -} - -static void IsDaylightOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsDaylightOn()); -} - -static void IsNightlightOnGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsNightlightOn()); -} - -static void RoofStateGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetRoofState()); -} - -static void IsFlamethrowerActiveGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsFlamethrowerActive()); -} - -static void LightsMultiplierGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_NUMBER(vehicle->GetLightsMultiplier()); -} - -static void EngineHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetEngineHealth()); -} - -static void PetrolTankHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetPetrolTankHealth()); -} - -static void RepairsCountGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetRepairsCount()); -} - -static void BodyHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetBodyHealth()); -} - -static void BodyAdditionalHealthGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetBodyAdditionalHealth()); -} - -static void HasArmoredWindowsGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->HasArmoredWindows()); -} - -static void IsManualEngineControlGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsManualEngineControl()); -} - -static void IsHandlingModifiedGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_BOOLEAN(vehicle->IsHandlingModified()); -} - static void ToggleExtra(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -496,64 +64,6 @@ static void ToggleExtra(const v8::FunctionCallbackInfo& info) vehicle->ToggleExtra(extraID, toggle); } -// static void GravityGetter(v8::Local, const v8::PropertyCallbackInfo &info) -// { -// V8_GET_ISOLATE(); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(ctx); -// V8_CHECK(resource, "invalid resource"); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// auto vehicle = _this->GetHandle().As()->GetGameVehicle(); -// V8_CHECK(vehicle, "Could not retrieve game vehicle"); - -// Log::Debug("GRAVITY", vehicle->gravity); -// auto ret = v8::Number::New(isolate, vehicle->gravity); -// Log::Debug("RET GRAVITY", ret->NumberValue(ctx).ToChecked()); -// info.GetReturnValue().Set(ret); -// } - -// static void GravitySetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -// { -// V8_GET_ISOLATE(); -// V8_CHECK(val->IsNumber(), "val must be a number"); - -// V8ResourceImpl *resource = V8ResourceImpl::Get(isolate->GetEnteredOrMicrotaskContext()); -// V8_CHECK(resource, "invalid resource"); - -// V8_CHECK(val->IsNumber(), "val needs to be a nummber (float)"); - -// V8Entity *_this = V8Entity::Get(info.This()); -// V8_CHECK(_this, "entity is invalid"); - -// auto vehicle = _this->GetHandle().As()->GetGameVehicle(); -// V8_CHECK(vehicle, "Could not retrieve game vehicle"); - -// Log::Debug("GRAVITY", vehicle->gravity); -// auto newval = val->NumberValue(ctx).ToChecked(); -// Log::Debug("NEW GRAVITY", newval); -// vehicle->gravity = newval; -// } - -static void MaxGearGetter(v8::Local, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_RETURN_INT(vehicle->GetMaxGear()); -} - -static void MaxGearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT(); - V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); - - V8_TO_INTEGER(val, maxGear); - vehicle->SetMaxGear(maxGear); -} - static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -623,18 +133,17 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetStaticAccessor(isolate, tpl, "streamedIn", &StreamedInGetter); // Common getters - V8::SetAccessor(isolate, tpl, "speed", &SpeedGetter); - V8::SetAccessor(isolate, tpl, "gear", &GearGetter, &GearSetter); - V8::SetAccessor(isolate, tpl, "maxGear", &MaxGearGetter, &MaxGearSetter); - V8::SetAccessor(isolate, tpl, "rpm", &RPMGetter); - V8::SetAccessor(isolate, tpl, "wheelsCount", &WheelsCountGetter); - V8::SetAccessor(isolate, tpl, "speedVector", &SpeedVectorGetter); - // proto->SetAccessor(v8::String::NewFromUtf8(isolate, "gravity", &GravityGetter).ToLocalChecked(), &GravitySetter); + V8::SetAccessor(isolate, tpl, "speed"); + V8::SetAccessor(isolate, tpl, "gear"); + V8::SetAccessor(isolate, tpl, "maxGear"); + V8::SetAccessor(isolate, tpl, "rpm"); + V8::SetAccessor(isolate, tpl, "wheelsCount"); + V8::SetAccessor(isolate, tpl, "speedVector"); V8::SetAccessor(isolate, tpl, "handling", &HandlingGetter); V8::SetMethod(isolate, tpl, "toggleExtra", ToggleExtra); - V8::SetAccessor(isolate, tpl, "indicatorLights", &IndicatorLightsGetter, &IndicatorLightsSetter); + V8::SetAccessor(isolate, tpl, "indicatorLights"); - /* GETTERS BELOW ARE UNIMPLEMENTED + /*GETTERS BELOW ARE UNIMPLEMENTED V8::SetAccessor(isolate, tpl, "isDestroyed", &IsDestroyedGetter); V8::SetAccessor(isolate, tpl, "driver", &DriverGetter); @@ -664,35 +173,5 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, [](v8::Local V8::SetAccessor(isolate, tpl, "dirtLevel", &DirtLevelGetter); //V8::SetAccessor(isolate, tpl, "neonActive", &IsNeonActiveGetter); V8::SetAccessor(isolate, tpl, "neon", &NeonGetter); - V8::SetAccessor(isolate, tpl, "neonColor", &NeonColorGetter); - V8::SetAccessor(isolate, tpl, "livery", &LiveryGetter); - V8::SetAccessor(isolate, tpl, "roofLivery", &RoofLiveryGetter); - - // Gamestate getters - V8::SetAccessor(isolate, tpl, "engineOn", &EngineOnGetter); - V8::SetAccessor(isolate, tpl, "handbrakeActive", &HandbrakeActiveGetter); - V8::SetAccessor(isolate, tpl, "headlightColor", &HeadlightColorGetter); - V8::SetAccessor(isolate, tpl, "activeRadioStation", &RadioStationIndexGetter); - V8::SetAccessor(isolate, tpl, "sirenActive", &IsSirenActiveGetter); - V8::SetAccessor(isolate, tpl, "lockState", &LockStateGetter); - V8::SetAccessor(isolate, tpl, "daylightOn", &IsDaylightOnGetter); - V8::SetAccessor(isolate, tpl, "nightlightOn", &IsNightlightOnGetter); - V8::SetAccessor(isolate, tpl, "roofState", &RoofStateGetter); - V8::SetAccessor(isolate, tpl, "flamethrowerActive", &IsFlamethrowerActiveGetter); - V8::SetAccessor(isolate, tpl, "lightsMultiplier", &LightsMultiplierGetter); - - // Health getters - V8::SetAccessor(isolate, tpl, "engineHealth", &EngineHealthGetter); - V8::SetAccessor(isolate, tpl, "petrolTankHealth", &PetrolTankHealthGetter); - V8::SetAccessor(isolate, tpl, "repairsCount", &RepairsCountGetter); - V8::SetAccessor(isolate, tpl, "bodyHealth", &BodyHealthGetter); - V8::SetAccessor(isolate, tpl, "bodyAdditionalHealth", &BodyAdditionalHealthGetter); - - // Damage getters - V8::SetAccessor(isolate, tpl, "hasArmoredWindows", &HasArmoredWindowsGetter); - - // Script getters - V8::SetAccessor(isolate, tpl, "manualEngineControl", &IsManualEngineControlGetter); - V8::SetAccessor(isolate, tpl, "handlingModified", &IsHandlingModifiedGetter); - */ + V8::SetAccessor(isolate, tpl, "neonColor", &NeonColorGetter);*/ }); diff --git a/src/bindings/WebSocketClient.cpp b/src/bindings/WebSocketClient.cpp index e35a53f0..dbb3179b 100644 --- a/src/bindings/WebSocketClient.cpp +++ b/src/bindings/WebSocketClient.cpp @@ -1,4 +1,5 @@ #include "../helpers/V8Helpers.h" +#include "../helpers/V8BindHelpers.h" #include "../helpers/V8Class.h" #include "../helpers/V8Entity.h" #include "../helpers/V8ResourceImpl.h" @@ -51,15 +52,6 @@ static void Off(const v8::FunctionCallbackInfo& info) static_cast(resource)->UnsubscribeWebSocketClient(webSocket, evName.ToString(), fun); } -static void Start(const v8::FunctionCallbackInfo& info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - - webSocket->Start(); -} - static void Send(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -92,15 +84,6 @@ static void Send(const v8::FunctionCallbackInfo& info) V8_RETURN_BOOLEAN(ret); } -static void Stop(const v8::FunctionCallbackInfo& info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - - webSocket->Stop(); -} - static void AddSubProtocol(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -180,95 +163,6 @@ static void GetEventListeners(const v8::FunctionCallbackInfo& info) V8_RETURN(array); } -static void URLGetter(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - - V8_RETURN_STRING(webSocket->GetUrl().CStr()); -} - -static void URLSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - - V8_TO_STRING(value, url); - - webSocket->SetUrl(url); -} - -static void ReadyStateGetter(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - - V8_RETURN_UINT(webSocket->GetReadyState()); -} - -static void AutoReconnectSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - - V8_TO_BOOLEAN(value, toggle); - - webSocket->SetAutoReconnectEnabled(toggle); -} - -static void AutoReconnectGetter(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - - V8_RETURN_BOOLEAN(webSocket->IsAutoReconnectEnabled()); -} - -static void PerMessageDeflateSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - - V8_TO_BOOLEAN(value, toggle); - - webSocket->SetPerMessageDeflateEnabled(toggle); -} - -static void PerMessageDeflateGetter(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - - V8_RETURN_BOOLEAN(webSocket->IsPerMessageDeflateEnabled()); -} - -static void PingIntervalSetter(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - - V8_TO_INTEGER(value, interval); - - webSocket->SetPingInterval(interval); -} - -static void PingIntervalGetter(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(webSocket, alt::IWebSocketClient); - - V8_RETURN_UINT(webSocket->GetPingInterval()); -} - extern V8Class v8BaseObject; extern V8Class v8WebSocketClient("WebSocketClient", v8BaseObject, &Constructor, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); @@ -277,9 +171,9 @@ extern V8Class v8WebSocketClient("WebSocketClient", v8BaseObject, &Constructor, V8::SetMethod(isolate, tpl, "off", &Off); V8::SetMethod(isolate, tpl, "getEventListeners", GetEventListeners); - V8::SetMethod(isolate, tpl, "start", &Start); + V8::SetMethod(isolate, tpl, "start"); + V8::SetMethod(isolate, tpl, "stop"); V8::SetMethod(isolate, tpl, "send", &Send); - V8::SetMethod(isolate, tpl, "stop", &Stop); V8::SetMethod(isolate, tpl, "addSubProtocol", &AddSubProtocol); V8::SetMethod(isolate, tpl, "getSubProtocols", &GetSubProtocols); @@ -287,9 +181,9 @@ extern V8Class v8WebSocketClient("WebSocketClient", v8BaseObject, &Constructor, V8::SetMethod(isolate, tpl, "setExtraHeader", &SetExtraHeader); V8::SetMethod(isolate, tpl, "getExtraHeaders", &GetExtraHeaders); - V8::SetAccessor(isolate, tpl, "autoReconnect", &AutoReconnectGetter, &AutoReconnectSetter); - V8::SetAccessor(isolate, tpl, "perMessageDeflate", &PerMessageDeflateGetter, &PerMessageDeflateSetter); - V8::SetAccessor(isolate, tpl, "pingInterval", &PingIntervalGetter, &PingIntervalSetter); - V8::SetAccessor(isolate, tpl, "url", &URLGetter, &URLSetter); - V8::SetAccessor(isolate, tpl, "readyState", &ReadyStateGetter, nullptr); + V8::SetAccessor(isolate, tpl, "autoReconnect"); + V8::SetAccessor(isolate, tpl, "perMessageDeflate"); + V8::SetAccessor(isolate, tpl, "pingInterval"); + V8::SetAccessor(isolate, tpl, "url"); + V8::SetAccessor(isolate, tpl, "readyState"); }); diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index ccd319f6..3b22b854 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -1,5 +1,6 @@ #include "../helpers/V8Helpers.h" +#include "../helpers/V8BindHelpers.h" #include "../helpers/V8Class.h" #include "../helpers/V8Entity.h" #include "../helpers/V8ResourceImpl.h" @@ -77,24 +78,6 @@ static void Emit(const v8::FunctionCallbackInfo &info) view->Trigger(evName, mvArgs); } -static void Focus(const v8::FunctionCallbackInfo &info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - - view->Focus(); -} - -static void Unfocus(const v8::FunctionCallbackInfo &info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - - view->Unfocus(); -} - static void GetEventListeners(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -114,63 +97,6 @@ static void GetEventListeners(const v8::FunctionCallbackInfo& info) V8_RETURN(array); } -static void IsVisibleGetter(v8::Local, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - - V8_RETURN_BOOLEAN(view->IsVisible()); -} - -static void IsVisibleSetter(v8::Local, v8::Local value, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - - V8_TO_BOOLEAN(value, state); - view->SetVisible(state); -} - -static void URLGetter(v8::Local, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - - V8_RETURN_STRING(view->GetUrl().CStr()); -} - -static void URLSetter(v8::Local, v8::Local value, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - - V8_TO_STRING(value, url); - - view->SetUrl(url); -} - -static void OverlayGetter(v8::Local, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - - V8_RETURN_BOOLEAN(view->IsOverlay()); -} - -static void ReadyGetter(v8::Local, const v8::PropertyCallbackInfo &info) -{ - V8_GET_ISOLATE(); - - V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); - - V8_RETURN_BOOLEAN(view->IsReady()); -} - static void FocusedGetter(v8::Local, const v8::PropertyCallbackInfo &info) { V8_GET_ISOLATE(); @@ -272,10 +198,10 @@ extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local(isolate, tpl, "isVisible"); + V8::SetAccessor(isolate, tpl, "url"); + V8::SetAccessor(isolate, tpl, "isOverlay"); + V8::SetAccessor(isolate, tpl, "isReady"); V8::SetAccessor(isolate, tpl, "focused", &FocusedGetter, &FocusedSetter); V8::SetMethod(isolate, tpl, "on", &On); @@ -283,6 +209,6 @@ extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local(isolate, tpl, "focus"); + V8::SetMethod(isolate, tpl, "unfocus"); }); From 58f88fb99fb1162154e27195b7db99e475a1ba48 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 18 Jul 2021 13:06:43 +0200 Subject: [PATCH 451/564] Update SDK Former-commit-id: a15b86ca298888fbbab817e815c26fe19c71b226 --- src/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index 2752a9ca..2ebb0c16 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 2752a9ca8ce2bb3e8677d274f41d216d2736451e +Subproject commit 2ebb0c1687d0861b0d346365b0bac9215ccdd501 From 35f62d92acc8378d66469253b9ab8cca41483ea0 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 18 Jul 2021 13:56:38 +0200 Subject: [PATCH 452/564] Fix MValue Uint above 32-bit limit --- V8Helpers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 7d1f63f7..53961676 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -266,7 +266,7 @@ v8::Local V8Helpers::MValueToV8(alt::MValueConst val) if (_val <= UINT_MAX) return v8::Integer::NewFromUnsigned(isolate, _val); - return v8::BigInt::New(isolate, _val); + return v8::BigInt::NewFromUnsigned(isolate, _val); } case alt::IMValue::Type::DOUBLE: return v8::Number::New(isolate, val.As()->Value()); From 29294498f6eacf4e5da8632415e62750dd3fafde Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 19 Jul 2021 22:22:34 +0200 Subject: [PATCH 453/564] Add Vector3 cross method --- bindings/Vector3.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index a6e2c362..d7ae9153 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -338,6 +338,63 @@ static void Dot(const v8::FunctionCallbackInfo& info) } } +static void Cross(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT_RESOURCE(); + + V8_CHECK_ARGS_LEN2(1, 3); + + v8::Local _this = info.This(); + + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_XKey(isolate)), x); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_YKey(isolate)), y); + V8_TO_NUMBER(V8::Get(ctx, _this, V8::Vector3_ZKey(isolate)), z); + + if (info.Length() == 3) + { + V8_ARG_TO_NUMBER(1, x2); + V8_ARG_TO_NUMBER(2, y2); + V8_ARG_TO_NUMBER(3, z2); + + V8_RETURN(resource->CreateVector3({ (y * z2) - (z * y2), (z * x2) - (x * z2), (x * y2) - (y * x2) })); + } + else if (info.Length() == 1) + { + auto arg = info[0]; + if (arg->IsNumber()) + { + V8_ARG_TO_NUMBER(1, value); + + V8_RETURN(resource->CreateVector3({ (y * value) - (z * value), (z * value) - (x * value), (x * value) - (y * value) })); + } + else if (arg->IsArray()) + { + v8::Local arr = arg.As(); + V8_CHECK(arr->Length() == 3, "Argument must be an array of 3 numbers"); + + V8_TO_NUMBER(arr->Get(ctx, 0).ToLocalChecked(), x2); + V8_TO_NUMBER(arr->Get(ctx, 1).ToLocalChecked(), y2); + V8_TO_NUMBER(arr->Get(ctx, 2).ToLocalChecked(), z2); + + V8_RETURN(resource->CreateVector3({ (y * z2) - (z * y2), (z * x2) - (x * z2), (x * y2) - (y * x2) })); + } + else if (arg->IsObject()) + { + v8::Local obj = arg.As(); + + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked(), x2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked(), y2); + V8_TO_NUMBER(obj->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked(), z2); + + V8_RETURN(resource->CreateVector3({ (y * z2) - (z * y2), (z * x2) - (x * z2), (x * y2) - (y * x2) })); + } + else + { + V8Helpers::Throw(isolate, "Argument must be a number, an array of 3 numbers or IVector3"); + } + } +} + static void Negative(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -599,6 +656,7 @@ extern V8Class v8Vector3("Vector3", Constructor, [](v8::Local Date: Mon, 19 Jul 2021 22:23:26 +0200 Subject: [PATCH 454/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 9f4952c2..29294498 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 9f4952c2217aaaa5023b1976c66d35f289898bd7 +Subproject commit 29294498f6eacf4e5da8632415e62750dd3fafde From abaf7a66d055b45200e2aef04e70b2b468b6dd73 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 19 Jul 2021 22:23:59 +0200 Subject: [PATCH 455/564] Update helpers Former-commit-id: 2a9539274c366c43f719ea3e35a804763eefd4ab --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index e69bee17..29294498 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit e69bee17bbe8eda1d899998c21a675486ba73020 +Subproject commit 29294498f6eacf4e5da8632415e62750dd3fafde From 03252a31bff90de35311a1e8869ce761c0d91fef Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 20 Jul 2021 01:11:08 +0200 Subject: [PATCH 456/564] Add missing type check to SafeToVector2 --- V8Helpers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index b0d143bb..2e5f4454 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -661,6 +661,7 @@ bool V8::SafeToVector3(v8::Local val, v8::Local ctx, alt bool V8::SafeToVector2(v8::Local val, v8::Local ctx, alt::Vector2f& out) { + if(!val->IsObject()) return false; v8::MaybeLocal maybeVal = val->ToObject(ctx); if (!maybeVal.IsEmpty()) { From 91c9a2e1bbc9716620593eefb0621088cdd764b5 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 20 Jul 2021 01:11:34 +0200 Subject: [PATCH 457/564] Update helpers Former-commit-id: 7f5adc3e26f70fc25e7713705f8651c77efebdc9 --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 29294498..03252a31 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 29294498f6eacf4e5da8632415e62750dd3fafde +Subproject commit 03252a31bff90de35311a1e8869ce761c0d91fef From 211c7f2fb1b1c466c94c5b67d92d5be4d4485274 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 20 Jul 2021 01:11:56 +0200 Subject: [PATCH 458/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 29294498..03252a31 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 29294498f6eacf4e5da8632415e62750dd3fafde +Subproject commit 03252a31bff90de35311a1e8869ce761c0d91fef From 625a0b1317c3db4439eecfbe783fb0b3f2323d04 Mon Sep 17 00:00:00 2001 From: Leon B Date: Tue, 20 Jul 2021 15:27:04 +0200 Subject: [PATCH 459/564] Add support for shared module (#42) * Add support for shared module * Add isClient and isServer properties --- V8Helpers.h | 2 -- V8Module.h | 5 ++++- bindings/Main.cpp | 45 +++++++++++++++++++++++++++++++++++---------- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index 0021c2b7..e56dabd9 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -170,8 +170,6 @@ namespace V8 v8::Local Get(v8::Local ctx, v8::Local obj, const char *name); v8::Local Get(v8::Local ctx, v8::Local obj, v8::Local name); - void RegisterSharedMain(v8::Local ctx, v8::Local exports); - v8::Local New(v8::Isolate *isolate, v8::Local ctx, v8::Local constructor, std::vector> &args); // TODO: create c++ classes for v8 classes and move there diff --git a/V8Module.h b/V8Module.h index 0015b735..9a78a007 100644 --- a/V8Module.h +++ b/V8Module.h @@ -40,12 +40,14 @@ class V8Module std::string moduleName; std::unordered_set classes; Callback creator; + V8Module* parentModule; template V8Module( std::string moduleName, + V8Module* parent, std::initializer_list> _classes, - Callback fn) : moduleName(moduleName), creator(fn) + Callback fn) : moduleName(moduleName), creator(fn), parentModule(parent) { for (auto &c : _classes) classes.insert(&c.get()); @@ -55,6 +57,7 @@ class V8Module void Register(v8::Isolate *isolate, v8::Local context, v8::Local exports) { + if(parentModule) parentModule->Register(isolate, context, exports); // Load all classes for (auto c : classes) { diff --git a/bindings/Main.cpp b/bindings/Main.cpp index e4a0a240..7b713cc5 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -1,6 +1,7 @@ #include "../V8Helpers.h" #include "../V8ResourceImpl.h" +#include "../V8Module.h" static void HashCb(const v8::FunctionCallbackInfo &info) { @@ -335,8 +336,25 @@ static void GetRemoteEventListeners(const v8::FunctionCallbackInfo& i V8_RETURN(array); } -void V8::RegisterSharedMain(v8::Local ctx, v8::Local exports) +extern V8Class v8BaseObject, + v8WorldObject, + v8Entity, + v8File, + v8RGBA, + v8Vector2, + v8Vector3; + +extern V8Module v8Shared("alt-shared", nullptr, { + v8BaseObject, + v8WorldObject, + v8Entity, + v8File, + v8RGBA, + v8Vector2, + v8Vector3 +}, +[](v8::Local ctx, v8::Local exports) { v8::Isolate *isolate = ctx->GetIsolate(); V8Helpers::RegisterFunc(exports, "hash", &HashCb); @@ -373,12 +391,19 @@ void V8::RegisterSharedMain(v8::Local ctx, v8::Local ex V8Helpers::RegisterFunc(exports, "hasResource", &HasResource); - V8::DefineOwnProperty(isolate, ctx, exports, "version", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetVersion().CStr()).ToLocalChecked()); - V8::DefineOwnProperty(isolate, ctx, exports, "branch", v8::String::NewFromUtf8(isolate, alt::ICore::Instance().GetBranch().CStr()).ToLocalChecked()); - - V8::DefineOwnProperty(isolate, ctx, exports, "resourceName", v8::String::NewFromUtf8(isolate, V8ResourceImpl::GetResource(ctx)->GetName().CStr()).ToLocalChecked()); - - V8::DefineOwnProperty(isolate, ctx, exports, "sdkVersion", v8::Integer::New(isolate, alt::ICore::Instance().SDK_VERSION)); - - V8::DefineOwnProperty(isolate, ctx, exports, "debug", v8::Boolean::New(isolate, alt::ICore::Instance().IsDebug())); -} + V8_OBJECT_SET_STRING(exports, "version", alt::ICore::Instance().GetVersion()); + V8_OBJECT_SET_STRING(exports, "branch", alt::ICore::Instance().GetBranch()); + V8_OBJECT_SET_INT(exports, "sdkVersion", alt::ICore::Instance().SDK_VERSION); + V8_OBJECT_SET_BOOLEAN(exports, "debug", alt::ICore::Instance().IsDebug()); + + V8_OBJECT_SET_STRING(exports, "resourceName", V8ResourceImpl::GetResource(ctx)->GetName()); + +#ifdef ALT_CLIENT_API + V8_OBJECT_SET_BOOLEAN(exports, "isClient", true); + V8_OBJECT_SET_BOOLEAN(exports, "isServer", false); +#endif +#ifdef ALT_SERVER_API + V8_OBJECT_SET_BOOLEAN(exports, "isClient", false); + V8_OBJECT_SET_BOOLEAN(exports, "isServer", true); +#endif +}); From 7a87bb70b3e6b13e96b48df47af8d4d752c876be Mon Sep 17 00:00:00 2001 From: Leon B Date: Tue, 20 Jul 2021 15:27:13 +0200 Subject: [PATCH 460/564] Support shared module (#52) * Support shared module * Update helpers * Update NodeJS for shared module Former-commit-id: 57b574f541d2a6673e57851707a3b5a4098206a0 --- src/bindings/Main.cpp | 20 ++++---------------- src/helpers | 2 +- src/node-module.cpp | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 5495b18b..6d975f3b 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -239,13 +239,7 @@ static void GetResourceExports(const v8::FunctionCallbackInfo& info) } } -extern V8Class v8Vector3, - v8RGBA, - v8File, - v8BaseObject, - v8WorldObject, - v8Entity, - v8Player, +extern V8Class v8Player, v8Vehicle, v8Blip, v8PointBlip, @@ -258,14 +252,10 @@ extern V8Class v8Vector3, v8ColshapeCuboid, v8ColshapeRectangle; -extern V8Module v8Alt("alt", +extern V8Module v8Shared; + +extern V8Module v8Alt("alt", &v8Shared, { - v8Vector3, - v8RGBA, - v8File, - v8BaseObject, - v8WorldObject, - v8Entity, v8Player, v8Vehicle, v8Blip, @@ -282,8 +272,6 @@ extern V8Module v8Alt("alt", [](v8::Local ctx, v8::Local exports) { v8::Isolate* isolate = ctx->GetIsolate(); - V8::RegisterSharedMain(ctx, exports); - V8Helpers::RegisterFunc(exports, "getResourceMain", &GetResourceMain); V8Helpers::RegisterFunc(exports, "getResourcePath", &GetResourcePath); V8Helpers::RegisterFunc(exports, "getResourceExports", &GetResourceExports); diff --git a/src/helpers b/src/helpers index 03252a31..20362809 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 03252a31bff90de35311a1e8869ce761c0d91fef +Subproject commit 2036280949f38667d5089dc331a51ccffdc793d5 diff --git a/src/node-module.cpp b/src/node-module.cpp index 1a8eed3e..869b9fe0 100644 --- a/src/node-module.cpp +++ b/src/node-module.cpp @@ -25,6 +25,8 @@ }*/ extern V8Module v8Alt; +namespace main +{ static void Initialize(v8::Local exports) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); @@ -33,6 +35,20 @@ static void Initialize(v8::Local exports) v8Alt.Register(isolate, isolate->GetEnteredContext(), exports); } NODE_MODULE_LINKED(alt, Initialize) +} + +extern V8Module v8Shared; +namespace shared +{ +static void InitializeShared(v8::Local exports) +{ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::HandleScope handle_scope(isolate); + + v8Shared.Register(isolate, isolate->GetEnteredContext(), exports); +} +NODE_MODULE_LINKED(altShared, InitializeShared) +} static void CommandHandler(alt::Array args, void* userData) { From c9bd20ad054b544eda591181d031cef155cb3d71 Mon Sep 17 00:00:00 2001 From: Leon B Date: Tue, 20 Jul 2021 15:27:28 +0200 Subject: [PATCH 461/564] Add shared module support (#80) --- src/bindings/Main.cpp | 22 ++++------------------ src/bindings/V8Natives.cpp | 2 +- src/helpers | 2 +- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 80af7ab2..9eb9facd 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -836,13 +836,8 @@ static void ClearPedProps(const v8::FunctionCallbackInfo& info) alt::ICore::Instance().ClearProps(scriptId, component); } -extern V8Class v8Vector3, - v8Vector2, - v8RGBA, - v8BaseObject, - v8WorldObject, - v8Entity, - v8Player, +extern V8Module v8Shared; +extern V8Class v8Player, v8Player, v8Vehicle, v8WebView, @@ -853,7 +848,6 @@ extern V8Class v8Vector3, v8HandlingData, v8LocalStorage, v8MemoryBuffer, - v8File, v8MapZoomData, v8Discord, v8Voice, @@ -866,13 +860,8 @@ extern V8Class v8Vector3, v8LocalPlayer; extern V8Module altModule( "alt", - {v8Vector3, - v8Vector2, - v8RGBA, - v8BaseObject, - v8WorldObject, - v8Entity, - v8Player, + &v8Shared, + {v8Player, v8Vehicle, v8WebView, v8Blip, @@ -882,7 +871,6 @@ extern V8Module altModule( v8HandlingData, v8LocalStorage, v8MemoryBuffer, - v8File, v8MapZoomData, v8Discord, v8Voice, @@ -892,8 +880,6 @@ extern V8Module altModule( v8Audio, v8LocalPlayer}, [](v8::Local ctx, v8::Local exports) { - V8::RegisterSharedMain(ctx, exports); - V8Helpers::RegisterFunc(exports, "onServer", &OnServer); V8Helpers::RegisterFunc(exports, "onceServer", &OnceServer); V8Helpers::RegisterFunc(exports, "offServer", &OffServer); diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 90ccb408..3d1282ed 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -380,4 +380,4 @@ static void RegisterNatives(v8::Local ctx, v8::Local ex } } -extern V8Module nativesModule("natives", {}, RegisterNatives); +extern V8Module nativesModule("natives", nullptr, {}, RegisterNatives); diff --git a/src/helpers b/src/helpers index 03252a31..20362809 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 03252a31bff90de35311a1e8869ce761c0d91fef +Subproject commit 2036280949f38667d5089dc331a51ccffdc793d5 From dda8a593d2b7f7c4a2508c5dfdbb3cb5e33909c0 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 20 Jul 2021 18:04:28 +0200 Subject: [PATCH 462/564] Rename shared module variable name --- bindings/Main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/Main.cpp b/bindings/Main.cpp index 7b713cc5..45e6d8a0 100644 --- a/bindings/Main.cpp +++ b/bindings/Main.cpp @@ -344,7 +344,7 @@ extern V8Class v8BaseObject, v8Vector2, v8Vector3; -extern V8Module v8Shared("alt-shared", nullptr, +extern V8Module sharedModule("alt-shared", nullptr, { v8BaseObject, v8WorldObject, From d09d7342fa4194a3c9630af12bc1c88323094305 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 20 Jul 2021 18:05:44 +0200 Subject: [PATCH 463/564] Update helpers --- src/bindings/Main.cpp | 4 ++-- src/helpers | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 9eb9facd..a6054d77 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -836,7 +836,7 @@ static void ClearPedProps(const v8::FunctionCallbackInfo& info) alt::ICore::Instance().ClearProps(scriptId, component); } -extern V8Module v8Shared; +extern V8Module sharedModule; extern V8Class v8Player, v8Player, v8Vehicle, @@ -860,7 +860,7 @@ extern V8Class v8Player, v8LocalPlayer; extern V8Module altModule( "alt", - &v8Shared, + &sharedModule, {v8Player, v8Vehicle, v8WebView, diff --git a/src/helpers b/src/helpers index 20362809..dda8a593 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 2036280949f38667d5089dc331a51ccffdc793d5 +Subproject commit dda8a593d2b7f7c4a2508c5dfdbb3cb5e33909c0 From 2149f588e79e35282ec7c61203daadf06dfd5690 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 20 Jul 2021 18:05:51 +0200 Subject: [PATCH 464/564] Fix shared module not loading --- src/CV8ScriptRuntime.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index f32c93e2..cd8e80bc 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -161,8 +161,8 @@ CV8ScriptRuntime::CV8ScriptRuntime() V8Class::LoadAll(isolate); - extern V8Module altModule, nativesModule; - V8Module::Add({altModule, nativesModule}); + extern V8Module altModule, nativesModule, sharedModule; + V8Module::Add({altModule, nativesModule, sharedModule}); } RegisterEvents(); From 04601c43ef3d8f78a5c2572694e0f69edc768b96 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 20 Jul 2021 18:43:33 +0200 Subject: [PATCH 465/564] Update helpers Former-commit-id: 911beb7ed49f690acc577ed0a2392b78be216f81 --- src/bindings/Main.cpp | 4 ++-- src/helpers | 2 +- src/node-module.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 6d975f3b..e929c183 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -252,9 +252,9 @@ extern V8Class v8Player, v8ColshapeCuboid, v8ColshapeRectangle; -extern V8Module v8Shared; +extern V8Module sharedModule; -extern V8Module v8Alt("alt", &v8Shared, +extern V8Module v8Alt("alt", &sharedModule, { v8Player, v8Vehicle, diff --git a/src/helpers b/src/helpers index 20362809..dda8a593 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 2036280949f38667d5089dc331a51ccffdc793d5 +Subproject commit dda8a593d2b7f7c4a2508c5dfdbb3cb5e33909c0 diff --git a/src/node-module.cpp b/src/node-module.cpp index 869b9fe0..60cb5177 100644 --- a/src/node-module.cpp +++ b/src/node-module.cpp @@ -37,7 +37,7 @@ static void Initialize(v8::Local exports) NODE_MODULE_LINKED(alt, Initialize) } -extern V8Module v8Shared; +extern V8Module sharedModule; namespace shared { static void InitializeShared(v8::Local exports) @@ -45,7 +45,7 @@ static void InitializeShared(v8::Local exports) v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope handle_scope(isolate); - v8Shared.Register(isolate, isolate->GetEnteredContext(), exports); + sharedModule.Register(isolate, isolate->GetEnteredContext(), exports); } NODE_MODULE_LINKED(altShared, InitializeShared) } From b35e51bfea36f7fca0114cce9d59588bb097f8ef Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 21 Jul 2021 01:20:51 +0200 Subject: [PATCH 466/564] Use primitive value return in function return --- V8Helpers.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/V8Helpers.h b/V8Helpers.h index e56dabd9..9a19958b 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -459,11 +459,11 @@ namespace V8 V8_CHECK(V8::SafeToVector3(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to vector3") #define V8_RETURN(val) info.GetReturnValue().Set(val) -#define V8_RETURN_NULL() V8_RETURN(v8::Null(isolate)) -#define V8_RETURN_BOOLEAN(val) V8_RETURN(v8::Boolean::New(isolate, (val))) -#define V8_RETURN_INT(val) V8_RETURN(v8::Integer::New(isolate, static_cast(val))) -#define V8_RETURN_UINT(val) V8_RETURN(v8::Integer::NewFromUnsigned(isolate, static_cast(val))) -#define V8_RETURN_NUMBER(val) V8_RETURN(v8::Number::New(isolate, static_cast(val))) +#define V8_RETURN_NULL() info.GetReturnValue().SetNull() +#define V8_RETURN_BOOLEAN(val) V8_RETURN(val) +#define V8_RETURN_INT(val) V8_RETURN(static_cast(val)) +#define V8_RETURN_UINT(val) V8_RETURN(static_cast(val)) +#define V8_RETURN_NUMBER(val) V8_RETURN(static_cast(val)) #define V8_RETURN_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val), v8::NewStringType::kNormal).ToLocalChecked()) #define V8_RETURN_ALT_STRING(val) V8_RETURN(v8::String::NewFromUtf8(isolate, (val).CStr(), v8::NewStringType::kNormal).ToLocalChecked()) #define V8_RETURN_MVALUE(val) V8_RETURN(V8Helpers::MValueToV8(val)) @@ -472,7 +472,7 @@ namespace V8 #define V8_RETURN_VECTOR3(val) V8_RETURN(resource->CreateVector3(val)) #define V8_RETURN_VECTOR2(val) V8_RETURN(resource->CreateVector2(val)) #define V8_RETURN_RGBA(val) V8_RETURN(resource->CreateRGBA(val)) -#define V8_RETURN_ENUM(val) V8_RETURN(v8::Integer::NewFromUnsigned(isolate, uint32_t(val))) +#define V8_RETURN_ENUM(val) V8_RETURN(uint32_t(val)) #define V8_RETURN_BASE_OBJECT(baseObjectRef) V8_RETURN(resource->GetBaseObjectOrNull(baseObjectRef)) From 94db3ab8b115e5ded15563a301453bd3ba8594d8 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 21 Jul 2021 01:21:12 +0200 Subject: [PATCH 467/564] Update helpers Former-commit-id: e1e9e5e71133ef1cec0c01247c596fd91050b435 --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index dda8a593..b35e51bf 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit dda8a593d2b7f7c4a2508c5dfdbb3cb5e33909c0 +Subproject commit b35e51bfea36f7fca0114cce9d59588bb097f8ef From e80cc55089e159849225fd33f4461e3214e8f97a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 21 Jul 2021 18:29:45 +0200 Subject: [PATCH 468/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index dda8a593..b35e51bf 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit dda8a593d2b7f7c4a2508c5dfdbb3cb5e33909c0 +Subproject commit b35e51bfea36f7fca0114cce9d59588bb097f8ef From c6340d9f4cb9c0118367405c86a25f9bafd61087 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 21 Jul 2021 18:46:01 +0200 Subject: [PATCH 469/564] Update build scripts --- .vscode/tasks.json | 2 +- CMakeLists.txt | 61 +++++++++++++++++++++------------------- src/CV8ScriptRuntime.cpp | 2 ++ tools/build-debug.bat | 12 ++++++++ tools/build.bat | 1 - 5 files changed, 47 insertions(+), 31 deletions(-) create mode 100644 tools/build-debug.bat diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1e31ce54..9096b7aa 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,7 +6,7 @@ { "label": "Build", "type": "shell", - "command": ".\\tools\\build.bat", + "command": ".\\tools\\build-debug.bat", "problemMatcher": ["$msCompile"], "group": { "kind": "build", diff --git a/CMakeLists.txt b/CMakeLists.txt index 833c0b87..590caf77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,36 +79,39 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /Zi /bigobj") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /bigobj") set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG:FULL /OPT:REF /OPT:ICF") -## SHARED -add_library( - ${PROJECT_NAME} SHARED - ${PROJECT_SOURCE_FILES} -) -set_target_properties(${PROJECT_NAME} PROPERTIES - CXX_STANDARD 17 -) -target_compile_definitions(${PROJECT_NAME} PRIVATE - ${ALTV_JS_DEFS} - -DALTV_JS_SHARED -) -target_link_libraries(${PROJECT_NAME} PRIVATE - ${ALTV_JS_LINKS} -) +if(DYNAMIC_BUILD) + ## SHARED + add_library( + ${PROJECT_NAME} SHARED + ${PROJECT_SOURCE_FILES} + ) + set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD 17 + ) + target_compile_definitions(${PROJECT_NAME} PRIVATE + ${ALTV_JS_DEFS} + -DALTV_JS_SHARED + ) + target_link_libraries(${PROJECT_NAME} PRIVATE + ${ALTV_JS_LINKS} + ) +else() + ## STATIC + add_library( + ${PROJECT_NAME}-static STATIC + ${PROJECT_SOURCE_FILES} + ) + set_target_properties(${PROJECT_NAME}-static PROPERTIES + CXX_STANDARD 17 + ) + target_compile_definitions(${PROJECT_NAME}-static PRIVATE + ${ALTV_JS_DEFS} + ) + target_link_libraries(${PROJECT_NAME}-static PRIVATE + ${ALTV_JS_LINKS} + ) +endif() -## STATIC -add_library( - ${PROJECT_NAME}-static STATIC - ${PROJECT_SOURCE_FILES} -) -set_target_properties(${PROJECT_NAME}-static PROPERTIES - CXX_STANDARD 17 -) -target_compile_definitions(${PROJECT_NAME}-static PRIVATE - ${ALTV_JS_DEFS} -) -target_link_libraries(${PROJECT_NAME}-static PRIVATE - ${ALTV_JS_LINKS} -) if(ALTV_JS_DEINIT_CPPSDK) add_custom_command(TARGET ${PROJECT_NAME}-static PRE_BUILD diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index cd8e80bc..38ec7815 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -15,6 +15,7 @@ CV8ScriptRuntime::CV8ScriptRuntime() isolate = v8::Isolate::New(create_params); isolate->SetFatalErrorHandler([](const char *location, const char *message) { + Log::Warning << "SetFatalErrorHandler" << Log::Endl; Log::Error << "[V8] " << location << ": " << message << Log::Endl; }); @@ -35,6 +36,7 @@ CV8ScriptRuntime::CV8ScriptRuntime() }, nullptr); isolate->SetPromiseRejectCallback([](v8::PromiseRejectMessage message) { + Log::Warning << "SetPromiseRejectCallback" << Log::Endl; v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local value = message.GetValue(); v8::Local ctx = isolate->GetEnteredOrMicrotaskContext(); diff --git a/tools/build-debug.bat b/tools/build-debug.bat new file mode 100644 index 00000000..306d30fe --- /dev/null +++ b/tools/build-debug.bat @@ -0,0 +1,12 @@ +@echo off + +:: Build the project +cmake . -BBUILD -DDYNAMIC_BUILD=1 +cmake --build BUILD --config Release + +:: Copy built binary to dist folder +IF NOT EXIST dist ( + mkdir dist +) +copy BUILD\Release\altv-client-js.dll dist +copy BUILD\Release\altv-client-js.pdb dist diff --git a/tools/build.bat b/tools/build.bat index 41dcdee4..71b8c016 100644 --- a/tools/build.bat +++ b/tools/build.bat @@ -8,6 +8,5 @@ cmake --build BUILD --config Release IF NOT EXIST dist ( mkdir dist ) -copy BUILD\Release\altv-client-js.dll dist copy BUILD\Release\altv-client-js.lib dist copy BUILD\Release\altv-client-js.pdb dist From a1ba0ba5b02d3c4edd9fdd4f21847b4ce6a7c832 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 21 Jul 2021 18:50:51 +0200 Subject: [PATCH 470/564] Fix copy of build output --- tools/build.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/build.bat b/tools/build.bat index 71b8c016..47b3109a 100644 --- a/tools/build.bat +++ b/tools/build.bat @@ -8,5 +8,5 @@ cmake --build BUILD --config Release IF NOT EXIST dist ( mkdir dist ) -copy BUILD\Release\altv-client-js.lib dist -copy BUILD\Release\altv-client-js.pdb dist +copy BUILD\Release\altv-client-js-static.lib dist +copy BUILD\Release\altv-client-js-static.pdb dist From b4960ef8a389a65f7326594f0ac9b96c9e3d18d3 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 21 Jul 2021 18:54:33 +0200 Subject: [PATCH 471/564] Remove acidentally added debug logs --- src/CV8ScriptRuntime.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index 38ec7815..cd8e80bc 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -15,7 +15,6 @@ CV8ScriptRuntime::CV8ScriptRuntime() isolate = v8::Isolate::New(create_params); isolate->SetFatalErrorHandler([](const char *location, const char *message) { - Log::Warning << "SetFatalErrorHandler" << Log::Endl; Log::Error << "[V8] " << location << ": " << message << Log::Endl; }); @@ -36,7 +35,6 @@ CV8ScriptRuntime::CV8ScriptRuntime() }, nullptr); isolate->SetPromiseRejectCallback([](v8::PromiseRejectMessage message) { - Log::Warning << "SetPromiseRejectCallback" << Log::Endl; v8::Isolate *isolate = v8::Isolate::GetCurrent(); v8::Local value = message.GetValue(); v8::Local ctx = isolate->GetEnteredOrMicrotaskContext(); From cbb84d11c789f2e9b3d4705c76f971dd0d2e3ca0 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 21 Jul 2021 19:29:33 +0200 Subject: [PATCH 472/564] Add resourceError event --- PromiseRejections.cpp | 15 +++++++++++---- V8Helpers.cpp | 8 +++++++- V8ResourceImpl.h | 6 ++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/PromiseRejections.cpp b/PromiseRejections.cpp index a90b98ee..23e4d6e8 100644 --- a/PromiseRejections.cpp +++ b/PromiseRejections.cpp @@ -32,18 +32,25 @@ void V8::PromiseRejections::ProcessQueue(V8ResourceImpl *resource) for (auto &rejection : queue) { + auto rejectionMsg = *v8::String::Utf8Value(isolate, rejection->value.Get(isolate)->ToString(ctx).ToLocalChecked()); + auto fileName = rejection->location.GetFileName(); if (rejection->location.GetLineNumber() != 0) { Log::Error << "[V8] Unhandled promise rejection at " - << resource->GetResource()->GetName() << ":" << rejection->location.GetFileName() << ":" << rejection->location.GetLineNumber() - << " (" << *v8::String::Utf8Value(isolate, rejection->value.Get(isolate)->ToString(ctx).ToLocalChecked()) << ")" << Log::Endl; + << resource->GetResource()->GetName() << ":" << fileName << ":" << rejection->location.GetLineNumber() + << " (" << rejectionMsg << ")" << Log::Endl; } else { Log::Error << "[V8] Unhandled promise rejection at " - << resource->GetResource()->GetName() << ":" << rejection->location.GetFileName() - << " (" << *v8::String::Utf8Value(isolate, rejection->value.Get(isolate)->ToString(ctx).ToLocalChecked()) << ")" << Log::Endl; + << resource->GetResource()->GetName() << ":" << fileName + << " (" << rejectionMsg << ")" << Log::Endl; } + + resource->DispatchErrorEvent( + rejectionMsg, + fileName, + rejection->location.GetLineNumber()); } queue.clear(); diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 2e5f4454..02642565 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -10,7 +10,8 @@ bool V8Helpers::TryCatch(const std::function& fn) v8::Local context = isolate->GetEnteredOrMicrotaskContext(); v8::TryCatch tryCatch(isolate); - alt::IResource* resource = V8ResourceImpl::GetResource(context); + V8ResourceImpl* v8resource = V8ResourceImpl::Get(context); + alt::IResource* resource = v8resource->GetResource(); if (!fn()) { @@ -41,6 +42,11 @@ bool V8Helpers::TryCatch(const std::function& fn) Log::Error << " " << std::string{ *v8::String::Utf8Value(isolate, sourceLine), 80 } << "..." << Log::Endl; } } + + v8resource->DispatchErrorEvent( + exception.IsEmpty() ? "unknown" : *v8::String::Utf8Value(isolate, exception), + *v8::String::Utf8Value(isolate, origin.ResourceName()), + line.ToChecked()); } else { diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index b77f047d..76c03606 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -125,6 +125,12 @@ class V8ResourceImpl : public alt::IResource::Impl InvokeEventHandlers(nullptr, GetLocalHandlers("resourceStop"), args); } + void DispatchErrorEvent(const std::string& error, const std::string& file, int32_t line) + { + std::vector> args = { V8_NEW_STRING(error.c_str()), V8_NEW_STRING(file.c_str()), v8::Integer::New(isolate, line) }; + InvokeEventHandlers(nullptr, GetLocalHandlers("resourceError"), args); + } + V8Entity *GetEntity(alt::IBaseObject *handle) { auto it = entities.find(handle); From de420e5844816ef64828ac231f9cab7834a4cc87 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 21 Jul 2021 19:29:47 +0200 Subject: [PATCH 473/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index b35e51bf..cbb84d11 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit b35e51bfea36f7fca0114cce9d59588bb097f8ef +Subproject commit cbb84d11c789f2e9b3d4705c76f971dd0d2e3ca0 From f819bced9a84d895ce3938e563cd3600aad088d5 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 21 Jul 2021 19:47:37 +0200 Subject: [PATCH 474/564] Add stack trace to resourceError event --- PromiseRejections.cpp | 1 + V8Helpers.cpp | 2 ++ V8ResourceImpl.h | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/PromiseRejections.cpp b/PromiseRejections.cpp index 23e4d6e8..9ea8a2c9 100644 --- a/PromiseRejections.cpp +++ b/PromiseRejections.cpp @@ -49,6 +49,7 @@ void V8::PromiseRejections::ProcessQueue(V8ResourceImpl *resource) resource->DispatchErrorEvent( rejectionMsg, + "", fileName, rejection->location.GetLineNumber()); } diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 02642565..91e42107 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -43,8 +43,10 @@ bool V8Helpers::TryCatch(const std::function& fn) } } + auto stackTrace = tryCatch.StackTrace(context); v8resource->DispatchErrorEvent( exception.IsEmpty() ? "unknown" : *v8::String::Utf8Value(isolate, exception), + (!stackTrace.IsEmpty() && stackTrace.ToLocalChecked()->IsString()) ? *v8::String::Utf8Value(isolate, stackTrace.ToLocalChecked()) : "", *v8::String::Utf8Value(isolate, origin.ResourceName()), line.ToChecked()); } diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index 76c03606..881afb4d 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -125,9 +125,9 @@ class V8ResourceImpl : public alt::IResource::Impl InvokeEventHandlers(nullptr, GetLocalHandlers("resourceStop"), args); } - void DispatchErrorEvent(const std::string& error, const std::string& file, int32_t line) + void DispatchErrorEvent(const std::string& error, const std::string& stackTrace, const std::string& file, int32_t line) { - std::vector> args = { V8_NEW_STRING(error.c_str()), V8_NEW_STRING(file.c_str()), v8::Integer::New(isolate, line) }; + std::vector> args = { V8_NEW_STRING(error.c_str()), V8_NEW_STRING(stackTrace.c_str()), V8_NEW_STRING(file.c_str()), v8::Integer::New(isolate, line) }; InvokeEventHandlers(nullptr, GetLocalHandlers("resourceError"), args); } From cd7b2600b1ed7cc4886bad487a12b0e31323fd34 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 21 Jul 2021 19:49:06 +0200 Subject: [PATCH 475/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index cbb84d11..f819bced 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit cbb84d11c789f2e9b3d4705c76f971dd0d2e3ca0 +Subproject commit f819bced9a84d895ce3938e563cd3600aad088d5 From 85024b2b93b2e0a9a121fd502366e4498b548b7c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 22 Jul 2021 01:22:24 +0200 Subject: [PATCH 476/564] Fix some crashes in V8 to MValue conversion --- V8Helpers.cpp | 33 ++++++++++++++++++++++++++------- V8ResourceImpl.cpp | 16 ++++++++++++---- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 91e42107..c3f704e6 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -153,7 +153,11 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) alt::MValueList list = core.CreateMValueList(v8Arr->Length()); for (uint32_t i = 0; i < v8Arr->Length(); ++i) - list->Set(i, V8ToMValue(v8Arr->Get(ctx, i).ToLocalChecked())); + { + v8::Local value; + if(!v8Arr->Get(ctx, i).ToLocal(&value)) continue; + list->Set(i, V8ToMValue(value)); + } return list; } @@ -225,16 +229,31 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) else { alt::MValueDict dict = core.CreateMValueDict(); - v8::Local keys = v8Obj->GetOwnPropertyNames(ctx).ToLocalChecked(); - + v8::Local keys; + if(!v8Obj->GetOwnPropertyNames(ctx).ToLocal(&keys)) + { + Log::Error << "Failed to convert object to MValue" << Log::Endl; + return core.CreateMValueNil(); + } for (uint32_t i = 0; i < keys->Length(); ++i) { - v8::Local v8Key = keys->Get(ctx, i).ToLocalChecked(); - if (!v8Obj->Get(ctx, v8Key).ToLocalChecked()->IsUndefined()) + v8::Local v8Key; + if(!keys->Get(ctx, i).ToLocal(&v8Key)) { - std::string key = *v8::String::Utf8Value(isolate, v8Key->ToString(ctx).ToLocalChecked()); - dict->Set(key, V8ToMValue(v8Obj->Get(ctx, v8Key).ToLocalChecked())); + Log::Error << "Failed to convert object to MValue" << Log::Endl; + return core.CreateMValueNil(); } + + v8::Local value; + if(!v8Obj->Get(ctx, v8Key).ToLocal(&value)) + { + Log::Error << "Failed to convert object to MValue" << Log::Endl; + return core.CreateMValueNil(); + } + + if(value->IsUndefined()) continue; + std::string key = *v8::String::Utf8Value(isolate, v8Key); + dict->Set(key, V8ToMValue(value)); } return dict; diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 7f8e8ccd..483421fa 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -142,22 +142,30 @@ v8::Local V8ResourceImpl::CreateRGBA(alt::RGBA rgba) bool V8ResourceImpl::IsVector3(v8::Local val) { - return val->InstanceOf(GetContext(), vector3Class.Get(isolate)).ToChecked(); + bool result = false; + val->InstanceOf(GetContext(), vector3Class.Get(isolate)).To(&result); + return result; } bool V8ResourceImpl::IsVector2(v8::Local val) { - return val->InstanceOf(GetContext(), vector2Class.Get(isolate)).ToChecked(); + bool result = false; + val->InstanceOf(GetContext(), vector2Class.Get(isolate)).To(&result); + return result; } bool V8ResourceImpl::IsRGBA(v8::Local val) { - return val->InstanceOf(GetContext(), rgbaClass.Get(isolate)).ToChecked(); + bool result = false; + val->InstanceOf(GetContext(), rgbaClass.Get(isolate)).To(&result); + return result; } bool V8ResourceImpl::IsBaseObject(v8::Local val) { - return val->InstanceOf(GetContext(), baseObjectClass.Get(isolate)).ToChecked(); + bool result = false; + val->InstanceOf(GetContext(), baseObjectClass.Get(isolate)).To(&result); + return result; } void V8ResourceImpl::OnCreateBaseObject(alt::Ref handle) From ac01dc363e0769c1273433761a0362b0a3604947 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 22 Jul 2021 01:22:42 +0200 Subject: [PATCH 477/564] Update helpers Former-commit-id: 0c76dc581895db2f559c2eca7cb8bc67b5764f25 --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index b35e51bf..85024b2b 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit b35e51bfea36f7fca0114cce9d59588bb097f8ef +Subproject commit 85024b2b93b2e0a9a121fd502366e4498b548b7c From 5c8da104fed65ca03221bfcacd697fc72bea6670 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 22 Jul 2021 01:23:09 +0200 Subject: [PATCH 478/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index f819bced..85024b2b 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit f819bced9a84d895ce3938e563cd3600aad088d5 +Subproject commit 85024b2b93b2e0a9a121fd502366e4498b548b7c From 2798d2dc416a76b7384090a75f5262c5c322cfce Mon Sep 17 00:00:00 2001 From: tastydev <39250826+tastydev@users.noreply.github.com> Date: Thu, 22 Jul 2021 17:42:39 +0200 Subject: [PATCH 479/564] prevent wrong clothes and props setter usage (#53) * fixed dlchash overflow for props, clothes * update v8 helpers * delete bytecode deps in cache * prevent wrong clothes and props usage * remove space * remove newline * fix typo * fix english grammar Former-commit-id: 65811264abcb8662e406dfc41d708259edc52720 --- src/bindings/Player.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index ed1f3e44..2da6ef66 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -207,6 +207,8 @@ static void SetClothes(const v8::FunctionCallbackInfo& info) V8_ARG_TO_INT(2, drawable); V8_ARG_TO_INT(3, texture); + V8_CHECK(component >= 0 && drawable >= 0 && texture >= 0, "setClothes args have to be positive, -1 won't reset"); + if(info.Length() == 3) { player->SetClothes(component, drawable, texture, 2); @@ -229,6 +231,8 @@ static void SetDlcClothes(const v8::FunctionCallbackInfo& info) V8_ARG_TO_INT(3, drawable); V8_ARG_TO_INT(4, texture); + V8_CHECK(component >= 0 && drawable >= 0 && texture >= 0, "setDlcClothes args have to be positive, -1 won't reset"); + if(info.Length() == 4) { player->SetDlcClothes(component, drawable, texture, 2, dlc); @@ -287,6 +291,8 @@ static void SetProps(const v8::FunctionCallbackInfo& info) V8_ARG_TO_INT(2, drawable); V8_ARG_TO_INT(3, texture); + V8_CHECK(component >= 0 && drawable >= 0 && texture >= 0, "setProp args have to be positive, -1 won't reset use clearProp"); + player->SetProps(component, drawable, texture); } @@ -301,6 +307,8 @@ static void SetDlcProps(const v8::FunctionCallbackInfo& info) V8_ARG_TO_INT(3, drawable); V8_ARG_TO_INT(4, texture); + V8_CHECK(component >= 0 && drawable >= 0 && texture >= 0, "setDlcProp args have to be positive, -1 won't reset use clearProp"); + player->SetDlcProps(component, drawable, texture, dlc); } From f937b84d565b11bde18b8f2aebe84b41717ca718 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 23 Jul 2021 18:05:04 +0200 Subject: [PATCH 480/564] Add V8_TO_INT32 macro --- V8Helpers.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/V8Helpers.h b/V8Helpers.h index 9a19958b..20f0d93e 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -307,6 +307,10 @@ namespace V8 int64_t val; \ V8_CHECK(V8::SafeToInteger((v8Val), ctx, val), "Failed to convert value to integer") +#define V8_TO_INT32(v8Val, val) \ + int32_t val; \ + V8_CHECK(V8::SafeToInt32((v8Val), ctx, val), "Failed to convert value to integer") + #define V8_TO_STRING(v8Val, val) \ alt::String val; \ V8_CHECK(V8::SafeToString((v8Val), isolate, ctx, val), "Failed to convert value to string") From 2eb54096e4bb7ee8fd33a021324dd7d962435b8d Mon Sep 17 00:00:00 2001 From: Leon B Date: Fri, 23 Jul 2021 19:34:52 +0200 Subject: [PATCH 481/564] Add profiler api (#81) * Add profiler api * Fix totalHeapSize property twice in heapstats * Return null if node has no children * Fix nulls in lineTicks array * Add samplingInterval and profilesRunning properties to Profiler --- src/CV8ScriptRuntime.cpp | 5 + src/CV8ScriptRuntime.h | 12 +++ src/bindings/Main.cpp | 6 +- src/bindings/Profiler.cpp | 220 ++++++++++++++++++++++++++++++++++++++ src/helpers | 2 +- 5 files changed, 242 insertions(+), 3 deletions(-) create mode 100644 src/bindings/Profiler.cpp diff --git a/src/CV8ScriptRuntime.cpp b/src/CV8ScriptRuntime.cpp index cd8e80bc..a900679e 100644 --- a/src/CV8ScriptRuntime.cpp +++ b/src/CV8ScriptRuntime.cpp @@ -154,6 +154,11 @@ CV8ScriptRuntime::CV8ScriptRuntime() inspectorSession = inspector->connect(1, inspectorChannel.get(), inspectorView); }*/ + profiler = v8::CpuProfiler::New(isolate); + profiler->SetUsePreciseSampling(true); + profiler->SetSamplingInterval(profilerSamplingInterval); + v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate); + { v8::Locker locker(isolate); v8::Isolate::Scope isolate_scope(isolate); diff --git a/src/CV8ScriptRuntime.h b/src/CV8ScriptRuntime.h index 0d4368ff..b546e2bc 100644 --- a/src/CV8ScriptRuntime.h +++ b/src/CV8ScriptRuntime.h @@ -10,6 +10,8 @@ #include "CV8Resource.h" +#include "v8-profiler.h" + class CV8ScriptRuntime : public alt::IScriptRuntime { static constexpr char inspectorViewStr[] = "alt:V Multiplayer"; @@ -22,6 +24,8 @@ class CV8ScriptRuntime : public alt::IScriptRuntime std::unique_ptr inspectorChannel; std::unique_ptr inspector; std::unique_ptr inspectorSession; + v8::CpuProfiler* profiler; + uint32_t profilerSamplingInterval = 100; std::unordered_map> streamedInPlayers; std::unordered_map> streamedInVehicles; @@ -40,6 +44,14 @@ class CV8ScriptRuntime : public alt::IScriptRuntime v8_inspector::V8Inspector *GetInspector() const { return inspector.get(); } + v8::CpuProfiler* GetProfiler() { return profiler; } + uint32_t GetProfilerSamplingInterval() { return profilerSamplingInterval; } + void SetProfilerSamplingInterval(uint32_t interval) + { + profilerSamplingInterval = interval; + profiler->SetSamplingInterval(interval); + } + alt::IResource::Impl *CreateImpl(alt::IResource *resource) override { auto res = new CV8ResourceImpl(resource, isolate); diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index a6054d77..891e3760 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -857,7 +857,8 @@ extern V8Class v8Player, v8Checkpoint, v8HttpClient, v8Audio, - v8LocalPlayer; + v8LocalPlayer, + v8Profiler; extern V8Module altModule( "alt", &sharedModule, @@ -878,7 +879,8 @@ extern V8Module altModule( v8Checkpoint, v8HttpClient, v8Audio, - v8LocalPlayer}, + v8LocalPlayer, + v8Profiler}, [](v8::Local ctx, v8::Local exports) { V8Helpers::RegisterFunc(exports, "onServer", &OnServer); V8Helpers::RegisterFunc(exports, "onceServer", &OnceServer); diff --git a/src/bindings/Profiler.cpp b/src/bindings/Profiler.cpp new file mode 100644 index 00000000..88c11910 --- /dev/null +++ b/src/bindings/Profiler.cpp @@ -0,0 +1,220 @@ +#include "../helpers/V8Helpers.h" +#include "../helpers/V8Class.h" +#include "../CV8ScriptRuntime.h" +#include "v8-profiler.h" +#include +#include +#include + +static void GetHeapStatistics(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + v8::HeapStatistics heapStats; + isolate->GetHeapStatistics(&heapStats); + V8_NEW_OBJECT(stats); + V8_OBJECT_SET_UINT(stats, "heapSizeLimit", heapStats.heap_size_limit()); + V8_OBJECT_SET_UINT(stats, "totalHeapSize", heapStats.total_heap_size()); + V8_OBJECT_SET_UINT(stats, "usedHeapSize", heapStats.used_heap_size()); + V8_OBJECT_SET_UINT(stats, "mallocedMemory", heapStats.malloced_memory()); + V8_OBJECT_SET_UINT(stats, "peakMallocedMemory", heapStats.peak_malloced_memory()); + + V8_RETURN(stats); +} + +// Key = Node ID, Value = Timestamp +// We store a map of the timestamps here, so we can quickly +// access it when setting it while serializing the profiler node +// todo: There is probably some nicer way to do this +static std::unordered_map nodeMap; +static uint32_t profilerRunningCount = 0; +static void GetProfileNodeData(v8::Isolate* isolate, const v8::CpuProfileNode* node, v8::Local result); + +static void StartProfiling(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN2(0, 1); + + v8::Local name; + if(info.Length() == 1) + { + V8_ARG_TO_STRING(1, profileName); + name = V8_NEW_STRING(profileName.CStr()); + } + else name = v8::String::Empty(isolate); + + v8::CpuProfilingStatus status = CV8ScriptRuntime::Instance().GetProfiler()->StartProfiling(name, true); + if(status == v8::CpuProfilingStatus::kStarted) + { + profilerRunningCount++; + return; + } + else if(status == v8::CpuProfilingStatus::kAlreadyStarted) V8Helpers::Throw(isolate, "A profile with the given name is already running"); + else if(status == v8::CpuProfilingStatus::kErrorTooManyProfilers) V8Helpers::Throw(isolate, "There are already too many profilers running"); +} + +static void StopProfiling(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN2(0, 1); + + v8::Local name; + if(info.Length() == 1) + { + V8_ARG_TO_STRING(1, profileName); + name = V8_NEW_STRING(profileName.CStr()); + } + else name = v8::String::Empty(isolate); + + v8::CpuProfile* result = CV8ScriptRuntime::Instance().GetProfiler()->StopProfiling(name); + V8_CHECK(result, "The specified profiler is not running"); + + // Store the node map + int sampleCount = result->GetSamplesCount(); + for(int i = 0; i < sampleCount; i++) + { + unsigned int nodeId = result->GetSample(i)->GetNodeId(); + if(nodeMap.count(nodeId) != 0) continue; + nodeMap.insert({ nodeId, (result->GetSampleTimestamp(i) / 1000) }); + } + + // Set top level info about the profile + V8_NEW_OBJECT(resultObj); + V8_OBJECT_SET_INT(resultObj, "id", std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count()); + V8_OBJECT_SET_STRING(resultObj, "type", alt::String("cpu")); + V8_OBJECT_SET_INT(resultObj, "start", result->GetStartTime() / 1000); + V8_OBJECT_SET_INT(resultObj, "end", result->GetEndTime() / 1000); + V8_OBJECT_SET_INT(resultObj, "samples", result->GetSamplesCount()); + + V8_NEW_OBJECT(root); + GetProfileNodeData(isolate, result->GetTopDownRoot(), root); + resultObj->Set(ctx, V8_NEW_STRING("root"), root); + + // Clear the nodemap to not cause a memory leak + nodeMap.clear(); + + V8_RETURN(resultObj); + + profilerRunningCount--; +} + +static void SamplingIntervalSetter(v8::Local, v8::Local value, const v8::PropertyCallbackInfo &info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_TO_INT32(value, interval); + + V8_CHECK(profilerRunningCount == 0, "Can't set sampling interval while profiler is running"); + + CV8ScriptRuntime::Instance().SetProfilerSamplingInterval(interval); +} + +static void SamplingIntervalGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + V8_RETURN_INT(CV8ScriptRuntime::Instance().GetProfilerSamplingInterval()); +} + +static void ProfilesRunningGetter(v8::Local, const v8::PropertyCallbackInfo &info) +{ + V8_RETURN_UINT(profilerRunningCount); +} + +extern V8Class v8Profiler("Profiler", [](v8::Local tpl) { + v8::Isolate *isolate = v8::Isolate::GetCurrent(); + + V8::SetStaticAccessor(isolate, tpl, "heapStats", GetHeapStatistics); + V8::SetStaticAccessor(isolate, tpl, "samplingInterval", SamplingIntervalGetter, SamplingIntervalSetter); + V8::SetStaticAccessor(isolate, tpl, "profilesRunning", ProfilesRunningGetter); + + V8::SetStaticMethod(isolate, tpl, "startProfiling", StartProfiling); + V8::SetStaticMethod(isolate, tpl, "stopProfiling", StopProfiling); +}); + +// *** CPU Profile Serialization + +inline static const char* GetSourceTypeName(v8::CpuProfileNode::SourceType type) +{ + switch(type) + { + case v8::CpuProfileNode::SourceType::kScript: return "script"; + case v8::CpuProfileNode::SourceType::kBuiltin: return "builtins"; + case v8::CpuProfileNode::SourceType::kCallback: return "native-callback"; + case v8::CpuProfileNode::SourceType::kInternal: return "internal"; + } + return "unknown"; +} + +static void GetProfileNodeData(v8::Isolate* isolate, const v8::CpuProfileNode* node, v8::Local result) +{ + auto ctx = isolate->GetEnteredOrMicrotaskContext(); + + // Node info + result->Set(ctx, V8_NEW_STRING("id"), v8::Integer::NewFromUnsigned(isolate, node->GetNodeId())); + + v8::Local functionName; + const char* name = node->GetFunctionNameStr(); + if(name == NULL || strlen(name) == 0) functionName = V8_NEW_STRING("(anonymous function)"); + else functionName = V8_NEW_STRING(name); + result->Set(ctx, V8_NEW_STRING("function"), functionName); + + v8::Local sourceName; + const char* source = node->GetScriptResourceNameStr(); + if(source == NULL || strlen(source) == 0) sourceName = V8_NEW_STRING("(unknown)"); + else sourceName = V8_NEW_STRING(source); + result->Set(ctx, V8_NEW_STRING("source"), sourceName); + + result->Set(ctx, V8_NEW_STRING("sourceType"), V8_NEW_STRING(GetSourceTypeName(node->GetSourceType()))); + result->Set(ctx, V8_NEW_STRING("line"), v8::Integer::New(isolate, node->GetLineNumber())); + + v8::Local bailoutReason; + const char* reason = node->GetBailoutReason(); + if(reason == NULL || strlen(reason) == 0) bailoutReason = v8::Null(isolate); + else bailoutReason = V8_NEW_STRING(reason); + result->Set(ctx, V8_NEW_STRING("bailoutReason"), bailoutReason); + + result->Set(ctx, V8_NEW_STRING("hitCount"), v8::Integer::NewFromUnsigned(isolate, node->GetHitCount())); + + int64_t timestamp; + if(nodeMap.count(node->GetNodeId()) == 0) timestamp = -1; + else timestamp = nodeMap.at(node->GetNodeId()); + result->Set(ctx, V8_NEW_STRING("timestamp"), v8::Integer::New(isolate, timestamp)); + + // Children + { + int childrenCount = node->GetChildrenCount(); + v8::Local children; + if(childrenCount != 0) + { + children = v8::Array::New(isolate, childrenCount); + for(int i = 0; i < childrenCount; i++) + { + V8_NEW_OBJECT(child); + GetProfileNodeData(isolate, node->GetChild(i), child); + children.As()->Set(ctx, i, child); + } + } + else children = v8::Null(isolate); + + result->Set(ctx, V8_NEW_STRING("children"), children); + } + + // Line ticks + { + std::vector ticks(node->GetHitLineCount()); + auto ticksSize = ticks.size(); + v8::Local val; + if(node->GetLineTicks(&ticks[0], ticksSize)) + { + val = v8::Array::New(isolate, ticksSize); + for(size_t i = 0; i < ticksSize; i++) + { + auto tick = ticks[i]; + V8_NEW_OBJECT(tickObj); + tickObj->Set(ctx, V8_NEW_STRING("line"), v8::Integer::New(isolate, tick.line)); + tickObj->Set(ctx, V8_NEW_STRING("hitCount"), v8::Integer::NewFromUnsigned(isolate, tick.hit_count)); + val.As()->Set(ctx, i, tickObj); + } + } + else val = v8::Null(isolate); + result->Set(ctx, V8_NEW_STRING("lineTicks"), val); + } +} diff --git a/src/helpers b/src/helpers index 85024b2b..f937b84d 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 85024b2b93b2e0a9a121fd502366e4498b548b7c +Subproject commit f937b84d565b11bde18b8f2aebe84b41717ca718 From 6bce8c3aca7034b35fac9f99880ede6e4a71715a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 24 Jul 2021 02:23:25 +0200 Subject: [PATCH 482/564] MemoryBuffer cleanup --- src/bindings/MemoryBuffer.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/bindings/MemoryBuffer.cpp b/src/bindings/MemoryBuffer.cpp index 1a07a8bd..1c031f00 100644 --- a/src/bindings/MemoryBuffer.cpp +++ b/src/bindings/MemoryBuffer.cpp @@ -162,21 +162,19 @@ static void GetDataOfType(const v8::FunctionCallbackInfo& info) extern V8Class v8MemoryBuffer("MemoryBuffer", Constructor, [](v8::Local tpl) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); - v8::Local proto = tpl->PrototypeTemplate(); - tpl->InstanceTemplate()->SetInternalFieldCount(2); - proto->Set(isolate, "free", v8::FunctionTemplate::New(isolate, &FreeBuffer)); - proto->Set(isolate, "address", v8::FunctionTemplate::New(isolate, &GetAddress)); - proto->Set(isolate, "ubyte", v8::FunctionTemplate::New(isolate, &GetDataOfType)); - proto->Set(isolate, "ushort", v8::FunctionTemplate::New(isolate, &GetDataOfType)); - proto->Set(isolate, "uint", v8::FunctionTemplate::New(isolate, &GetDataOfType)); - proto->Set(isolate, "ulong", v8::FunctionTemplate::New(isolate, &GetDataOfType)); - proto->Set(isolate, "byte", v8::FunctionTemplate::New(isolate, &GetDataOfType)); - proto->Set(isolate, "short", v8::FunctionTemplate::New(isolate, &GetDataOfType)); - proto->Set(isolate, "int", v8::FunctionTemplate::New(isolate, &GetDataOfType)); - proto->Set(isolate, "long", v8::FunctionTemplate::New(isolate, &GetDataOfType)); - proto->Set(isolate, "float", v8::FunctionTemplate::New(isolate, &GetDataOfType)); - proto->Set(isolate, "double", v8::FunctionTemplate::New(isolate, &GetDataOfType)); - proto->Set(isolate, "string", v8::FunctionTemplate::New(isolate, &GetDataOfType)); + V8::SetMethod(isolate, tpl, "free", FreeBuffer); + V8::SetMethod(isolate, tpl, "address", GetAddress); + V8::SetMethod(isolate, tpl, "ubyte", GetDataOfType); + V8::SetMethod(isolate, tpl, "ushort", GetDataOfType); + V8::SetMethod(isolate, tpl, "uint", GetDataOfType); + V8::SetMethod(isolate, tpl, "ulong", GetDataOfType); + V8::SetMethod(isolate, tpl, "byte", GetDataOfType); + V8::SetMethod(isolate, tpl, "short", GetDataOfType); + V8::SetMethod(isolate, tpl, "int", GetDataOfType); + V8::SetMethod(isolate, tpl, "long", GetDataOfType); + V8::SetMethod(isolate, tpl, "float", GetDataOfType); + V8::SetMethod(isolate, tpl, "double", GetDataOfType); + V8::SetMethod(isolate, tpl, "string", GetDataOfType); }); From 3ca8a05a04d7746478642aa4dd0589d533a08847 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 24 Jul 2021 02:26:09 +0200 Subject: [PATCH 483/564] Add MemoryBuffer size property --- src/bindings/MemoryBuffer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bindings/MemoryBuffer.cpp b/src/bindings/MemoryBuffer.cpp index 1c031f00..9de7db95 100644 --- a/src/bindings/MemoryBuffer.cpp +++ b/src/bindings/MemoryBuffer.cpp @@ -77,6 +77,14 @@ static void GetAddress(const v8::FunctionCallbackInfo& info) V8_RETURN_INT64((uintptr_t)memory); } +static void SizeGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_INTERNAL_FIELD_UINT32(1, size); + V8_RETURN_UINT(size); +} + template static void GetDataOfType(const v8::FunctionCallbackInfo& info) { @@ -164,6 +172,8 @@ extern V8Class v8MemoryBuffer("MemoryBuffer", Constructor, [](v8::LocalInstanceTemplate()->SetInternalFieldCount(2); + V8::SetAccessor(isolate, tpl, "size", SizeGetter); + V8::SetMethod(isolate, tpl, "free", FreeBuffer); V8::SetMethod(isolate, tpl, "address", GetAddress); V8::SetMethod(isolate, tpl, "ubyte", GetDataOfType); From d39e708ed217d1a78a78a7af696ede9bd7762793 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 24 Jul 2021 02:28:03 +0200 Subject: [PATCH 484/564] Add MemoryBuffer address property and deprecate method --- src/bindings/MemoryBuffer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bindings/MemoryBuffer.cpp b/src/bindings/MemoryBuffer.cpp index 9de7db95..ab7bb835 100644 --- a/src/bindings/MemoryBuffer.cpp +++ b/src/bindings/MemoryBuffer.cpp @@ -71,6 +71,7 @@ static void FreeBuffer(const v8::FunctionCallbackInfo& info) static void GetAddress(const v8::FunctionCallbackInfo& info) { + Log::Warning << "MemoryBuffer.address() method is deprecated. Use the property instead." << Log::Endl; V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_PTR(1, memory, uint8_t); @@ -85,6 +86,14 @@ static void SizeGetter(v8::Local, const v8::PropertyCallbackInfo, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_INTERNAL_FIELD_PTR(1, memory, uint8_t); + V8_RETURN_INT64((uintptr_t)memory); +} + template static void GetDataOfType(const v8::FunctionCallbackInfo& info) { @@ -173,6 +182,7 @@ extern V8Class v8MemoryBuffer("MemoryBuffer", Constructor, [](v8::LocalInstanceTemplate()->SetInternalFieldCount(2); V8::SetAccessor(isolate, tpl, "size", SizeGetter); + V8::SetAccessor(isolate, tpl, "address", AddressGetter); V8::SetMethod(isolate, tpl, "free", FreeBuffer); V8::SetMethod(isolate, tpl, "address", GetAddress); From c444e980482332d2b0a2951db5e348eff3c338de Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 24 Jul 2021 02:30:58 +0200 Subject: [PATCH 485/564] Remove MemoryBuffer address method --- src/bindings/MemoryBuffer.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/bindings/MemoryBuffer.cpp b/src/bindings/MemoryBuffer.cpp index ab7bb835..12609873 100644 --- a/src/bindings/MemoryBuffer.cpp +++ b/src/bindings/MemoryBuffer.cpp @@ -69,15 +69,6 @@ static void FreeBuffer(const v8::FunctionCallbackInfo& info) V8_RETURN_BOOLEAN(false); } -static void GetAddress(const v8::FunctionCallbackInfo& info) -{ - Log::Warning << "MemoryBuffer.address() method is deprecated. Use the property instead." << Log::Endl; - V8_GET_ISOLATE_CONTEXT(); - - V8_GET_THIS_INTERNAL_FIELD_PTR(1, memory, uint8_t); - V8_RETURN_INT64((uintptr_t)memory); -} - static void SizeGetter(v8::Local, const v8::PropertyCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -185,7 +176,6 @@ extern V8Class v8MemoryBuffer("MemoryBuffer", Constructor, [](v8::Local); V8::SetMethod(isolate, tpl, "ushort", GetDataOfType); V8::SetMethod(isolate, tpl, "uint", GetDataOfType); From 06c2225dc155345b0618ea61da5b1e568a6cd4ef Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 26 Jul 2021 03:15:13 +0200 Subject: [PATCH 486/564] Change GetTimersCount method to TimerBenchmark method --- V8ResourceImpl.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index 881afb4d..bed9d0c2 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -205,15 +205,20 @@ class V8ResourceImpl : public alt::IResource::Impl oldTimers.push_back(id); } - void GetTimersCount(size_t* totalCount, size_t* everyTickCount, size_t* intervalCount, size_t* timeoutCount) + void TimerBenchmark() { - *totalCount = timers.size(); + size_t totalCount = 0, everyTickCount = 0, intervalCount = 0, timeoutCount = 0; + totalCount = timers.size(); for(auto [id, timer] : timers) { - if(timer->GetInterval() == 0 && !timer->IsOnce()) *everyTickCount += 1; - else if(timer->IsOnce()) *timeoutCount += 1; - else *intervalCount += 1; + if(timer->GetInterval() == 0 && !timer->IsOnce()) everyTickCount += 1; + else if(timer->IsOnce()) timeoutCount += 1; + else intervalCount += 1; } + + Log::Info << GetResource()->GetName() << ": " << totalCount << " running timers (" + << everyTickCount << " EveryTick, " << intervalCount << " Interval, " << timeoutCount << " Timeout" + << ")" << Log::Endl; } void NotifyPoolUpdate(alt::IBaseObject *ent); From 5c8e95f1b8351785fec1372903d39404d45b6aa6 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 26 Jul 2021 03:15:44 +0200 Subject: [PATCH 487/564] Update helpers --- src/helpers | 2 +- src/main.cpp | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/helpers b/src/helpers index f937b84d..06c2225d 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit f937b84d565b11bde18b8f2aebe84b41717ca718 +Subproject commit 06c2225dc155345b0618ea61da5b1e568a6cd4ef diff --git a/src/main.cpp b/src/main.cpp index ee159954..0d9a9ec6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,11 +19,7 @@ static void TimersCommand(alt::Array, void* runtime) Log::Info << "================ Timer info =================" << Log::Endl; for(auto resource : resources) { - size_t total, everyTick, interval, timeout; - resource->GetTimersCount(&total, &everyTick, &interval, &timeout); - Log::Info << resource->GetResource()->GetName() << ": " << total << " running timers (" - << everyTick << " EveryTick, " << interval << " Interval, " << timeout << " Timeout" - << ")" << Log::Endl; + resource->TimerBenchmark(); } Log::Info << "======================================================" << Log::Endl; } From 6a9421eba62bc931405f8a50ea11a339a31d3d62 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 26 Jul 2021 03:24:24 +0200 Subject: [PATCH 488/564] Update helpers Former-commit-id: ece8f3557b8c1a8deb012a0bbd87089042747f51 --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 85024b2b..8ccc6d66 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 85024b2b93b2e0a9a121fd502366e4498b548b7c +Subproject commit 8ccc6d66cf00e6d4b4a149936e0f8e30e7ce130e From a0dcae24805895c5336ca3213aeb5604f2c9684a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 26 Jul 2021 03:26:16 +0200 Subject: [PATCH 489/564] Add timers command (same as in client js) Former-commit-id: fd6ff6eac451a2cb3a056006c45f21d1c089be4f --- src/CNodeScriptRuntime.cpp | 4 +++- src/CNodeScriptRuntime.h | 4 ++++ src/node-module.cpp | 12 ++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/CNodeScriptRuntime.cpp b/src/CNodeScriptRuntime.cpp index 620d6917..28b97f1c 100644 --- a/src/CNodeScriptRuntime.cpp +++ b/src/CNodeScriptRuntime.cpp @@ -45,7 +45,9 @@ CNodeScriptRuntime::~CNodeScriptRuntime() alt::IResource::Impl* CNodeScriptRuntime::CreateImpl(alt::IResource* resource) { - return new CNodeResourceImpl{ this, isolate, resource }; + auto res = new CNodeResourceImpl{ this, isolate, resource }; + resources.insert(res); + return res; } void CNodeScriptRuntime::OnTick() diff --git a/src/CNodeScriptRuntime.h b/src/CNodeScriptRuntime.h index de5c2221..23a69abd 100644 --- a/src/CNodeScriptRuntime.h +++ b/src/CNodeScriptRuntime.h @@ -10,6 +10,7 @@ class CNodeScriptRuntime : public alt::IScriptRuntime { v8::Isolate* isolate; std::unique_ptr platform; + std::unordered_set resources; public: CNodeScriptRuntime(); @@ -21,6 +22,7 @@ class CNodeScriptRuntime : public alt::IScriptRuntime void DestroyImpl(alt::IResource::Impl* impl) override { + resources.insert(static_cast(impl)); delete static_cast(impl); } @@ -29,6 +31,8 @@ class CNodeScriptRuntime : public alt::IScriptRuntime node::MultiIsolatePlatform* GetPlatform() const { return platform.get(); } + std::unordered_set GetResources() { return resources; } + static CNodeScriptRuntime& Instance() { static CNodeScriptRuntime _Instance; diff --git a/src/node-module.cpp b/src/node-module.cpp index 60cb5177..c480e932 100644 --- a/src/node-module.cpp +++ b/src/node-module.cpp @@ -74,6 +74,17 @@ static void CommandHandler(alt::Array args, void* userData) } } +static void TimersCommand(alt::Array, void* runtime) +{ + auto resources = static_cast(runtime)->GetResources(); + Log::Info << "================ Timer info =================" << Log::Endl; + for(auto resource : resources) + { + resource->TimerBenchmark(); + } + Log::Info << "======================================================" << Log::Endl; +} + EXPORT uint32_t GetSDKVersion() { return alt::ICore::SDK_VERSION; @@ -88,6 +99,7 @@ EXPORT bool altMain(alt::ICore* _core) apiCore.RegisterScriptRuntime("js", &runtime); apiCore.SubscribeCommand("js-module", &CommandHandler); + apiCore.SubscribeCommand("timers", &TimersCommand); return true; } \ No newline at end of file From 1383c268199e88c56f67dc5230e945c171bb42b7 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 26 Jul 2021 22:28:48 +0200 Subject: [PATCH 490/564] Revert type checks in SafeTo* functions --- V8Helpers.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/V8Helpers.cpp b/V8Helpers.cpp index c3f704e6..70cc7c91 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -555,14 +555,12 @@ v8::Local V8::Fire_WeaponKey(v8::Isolate* isolate) bool V8::SafeToBoolean(v8::Local val, v8::Isolate* isolate, bool& out) { - if(!val->IsBoolean()) return false; out = val->ToBoolean(isolate)->Value(); return true; } bool V8::SafeToInteger(v8::Local val, v8::Local ctx, int64_t& out) { - if(!val->IsNumber()) return false; v8::MaybeLocal maybeVal = val->ToInteger(ctx); if(maybeVal.IsEmpty()) return false; out = maybeVal.ToLocalChecked()->Value(); @@ -571,7 +569,6 @@ bool V8::SafeToInteger(v8::Local val, v8::Local ctx, int bool V8::SafeToUInt64(v8::Local val, v8::Local ctx, uint64_t& out) { - if(!val->IsNumber()) return false; v8::MaybeLocal maybeVal = val->ToBigInt(ctx); if(maybeVal.IsEmpty()) return false; out = maybeVal.ToLocalChecked()->Uint64Value(); @@ -580,7 +577,6 @@ bool V8::SafeToUInt64(v8::Local val, v8::Local ctx, uint bool V8::SafeToInt64(v8::Local val, v8::Local ctx, int64_t& out) { - if(!val->IsNumber()) return false; v8::MaybeLocal maybeVal = val->ToBigInt(ctx); if(maybeVal.IsEmpty()) return false; out = maybeVal.ToLocalChecked()->Int64Value(); @@ -589,7 +585,6 @@ bool V8::SafeToInt64(v8::Local val, v8::Local ctx, int64 bool V8::SafeToUInt32(v8::Local val, v8::Local ctx, uint32_t& out) { - if(!val->IsNumber()) return false; v8::MaybeLocal maybeVal = val->ToUint32(ctx); if(maybeVal.IsEmpty()) return false; out = maybeVal.ToLocalChecked()->Value(); @@ -598,7 +593,6 @@ bool V8::SafeToUInt32(v8::Local val, v8::Local ctx, uint bool V8::SafeToInt32(v8::Local val, v8::Local ctx, int32_t& out) { - if(!val->IsNumber()) return false; v8::MaybeLocal maybeVal = val->ToInt32(ctx); if(maybeVal.IsEmpty()) return false; out = maybeVal.ToLocalChecked()->Value(); @@ -607,7 +601,6 @@ bool V8::SafeToInt32(v8::Local val, v8::Local ctx, int32 bool V8::SafeToNumber(v8::Local val, v8::Local ctx, double& out) { - if(!val->IsNumber()) return false; v8::MaybeLocal maybeVal = val->ToNumber(ctx); if(maybeVal.IsEmpty()) return false; out = maybeVal.ToLocalChecked()->Value(); @@ -616,7 +609,6 @@ bool V8::SafeToNumber(v8::Local val, v8::Local ctx, doub bool V8::SafeToString(v8::Local val, v8::Isolate* isolate, v8::Local ctx, alt::String& out) { - if(!val->IsString()) return false; v8::MaybeLocal maybeVal = val->ToString(ctx); if(maybeVal.IsEmpty()) return false; out = *v8::String::Utf8Value(isolate, maybeVal.ToLocalChecked()); @@ -636,7 +628,6 @@ bool V8::SafeToFunction(v8::Local val, v8::Local ctx, v8 bool V8::SafeToObject(v8::Local val, v8::Local ctx, v8::Local& out) { - if(!val->IsObject()) return false; v8::MaybeLocal maybeVal = val->ToObject(ctx); if (maybeVal.IsEmpty()) return false; out = maybeVal.ToLocalChecked(); @@ -645,7 +636,6 @@ bool V8::SafeToObject(v8::Local val, v8::Local ctx, v8:: bool V8::SafeToRGBA(v8::Local val, v8::Local ctx, alt::RGBA& out) { - if(!val->IsObject()) return false; v8::MaybeLocal maybeVal = val->ToObject(ctx); if (!maybeVal.IsEmpty()) { @@ -667,7 +657,6 @@ bool V8::SafeToRGBA(v8::Local val, v8::Local ctx, alt::R bool V8::SafeToVector3(v8::Local val, v8::Local ctx, alt::Vector3f& out) { - if(!val->IsObject()) return false; v8::MaybeLocal maybeVal = val->ToObject(ctx); if (!maybeVal.IsEmpty()) { @@ -688,7 +677,6 @@ bool V8::SafeToVector3(v8::Local val, v8::Local ctx, alt bool V8::SafeToVector2(v8::Local val, v8::Local ctx, alt::Vector2f& out) { - if(!val->IsObject()) return false; v8::MaybeLocal maybeVal = val->ToObject(ctx); if (!maybeVal.IsEmpty()) { From 72c60c89907462bcb6d2e8c51474532d18f624a6 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 26 Jul 2021 22:28:56 +0200 Subject: [PATCH 491/564] Update helpers Former-commit-id: 2f9e219f15e327e1b5b9d93be2bef466e8d4bd5d --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 8ccc6d66..1383c268 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 8ccc6d66cf00e6d4b4a149936e0f8e30e7ce130e +Subproject commit 1383c268199e88c56f67dc5230e945c171bb42b7 From 37acaa3fab6cc51d0f6413b063cf0bf84023d459 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 26 Jul 2021 22:29:29 +0200 Subject: [PATCH 492/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 06c2225d..1383c268 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 06c2225dc155345b0618ea61da5b1e568a6cd4ef +Subproject commit 1383c268199e88c56f67dc5230e945c171bb42b7 From c5a2c5655ef6fa6819257ec3e8a9c4c8b42dacdf Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 28 Jul 2021 00:18:00 +0200 Subject: [PATCH 493/564] Add V8_ARG_TO_RGBA macro --- V8Helpers.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/V8Helpers.h b/V8Helpers.h index 20f0d93e..9d1e1fff 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -462,6 +462,11 @@ namespace V8 alt::Vector3f val; \ V8_CHECK(V8::SafeToVector3(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to vector3") +// idx starts with 1 +#define V8_ARG_TO_RGBA(idx, val) \ + alt::RGBA val; \ + V8_CHECK(V8::SafeToRGBA(info[(idx)-1], ctx, val), "Failed to convert argument " #idx " to rgba") + #define V8_RETURN(val) info.GetReturnValue().Set(val) #define V8_RETURN_NULL() info.GetReturnValue().SetNull() #define V8_RETURN_BOOLEAN(val) V8_RETURN(val) From a274d58b043f0ee872399f6124ab8cbf42a38ccb Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 28 Jul 2021 00:20:41 +0200 Subject: [PATCH 494/564] Add better Checkpoint constructor Former-commit-id: b0dfd229e8812f3c52de06186da598b1f7976822 --- src/bindings/Checkpoint.cpp | 48 ++++++++++++++++++++++++++----------- src/helpers | 2 +- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index ab50b4bd..3131f64e 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -8,23 +8,43 @@ using namespace alt; static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); + V8_CHECK_CONSTRUCTOR(); + V8_CHECK_ARGS_LEN2(5, 10); - V8_CHECK(info.IsConstructCall(), "Checkpoint constructor is not a function"); - V8_CHECK_ARGS_LEN(10); + alt::Position pos; + alt::RGBA color; + float radius, height; V8_ARG_TO_INT(1, type); - V8_ARG_TO_NUMBER(2, x); - V8_ARG_TO_NUMBER(3, y); - V8_ARG_TO_NUMBER(4, z); - V8_ARG_TO_NUMBER(5, radius); - V8_ARG_TO_NUMBER(6, height); - V8_ARG_TO_INT(7, r); - V8_ARG_TO_INT(8, g); - V8_ARG_TO_INT(9, b); - V8_ARG_TO_INT(10, a); - - alt::Position pos(x, y, z); - alt::RGBA color(r, g, b, a); + if(info.Length() == 5) + { + V8_ARG_TO_VECTOR3(2, posVal); + V8_ARG_TO_NUMBER(3, radiusVal); + V8_ARG_TO_NUMBER(4, heightVal); + V8_ARG_TO_RGBA(5, colorVal); + + pos = posVal; + color = colorVal; + radius = radiusVal; + height = heightVal; + } + else + { + V8_ARG_TO_NUMBER(2, x); + V8_ARG_TO_NUMBER(3, y); + V8_ARG_TO_NUMBER(4, z); + V8_ARG_TO_NUMBER(5, radiusVal); + V8_ARG_TO_NUMBER(6, heightVal); + V8_ARG_TO_INT(7, r); + V8_ARG_TO_INT(8, g); + V8_ARG_TO_INT(9, b); + V8_ARG_TO_INT(10, a); + + pos = { x, y, z }; + color = { r, g, b, a }; + radius = radiusVal; + height = heightVal; + } Ref cp = ICore::Instance().CreateCheckpoint(type, pos, radius, height, color); diff --git a/src/helpers b/src/helpers index 1383c268..c5a2c565 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 1383c268199e88c56f67dc5230e945c171bb42b7 +Subproject commit c5a2c5655ef6fa6819257ec3e8a9c4c8b42dacdf From aabfbf4af915a2f5170550565dc68536f41c64c4 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 28 Jul 2021 00:23:03 +0200 Subject: [PATCH 495/564] Fix cast for RGBA constructor Former-commit-id: dfd5bcad4abed8f4fc927432a86e0a54250cef4e --- src/bindings/Checkpoint.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/Checkpoint.cpp b/src/bindings/Checkpoint.cpp index 3131f64e..a93326df 100644 --- a/src/bindings/Checkpoint.cpp +++ b/src/bindings/Checkpoint.cpp @@ -41,7 +41,7 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_ARG_TO_INT(10, a); pos = { x, y, z }; - color = { r, g, b, a }; + color = { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }; radius = radiusVal; height = heightVal; } From 062a3fcfad37e51e411fe7e4139162b4bc990643 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 28 Jul 2021 00:28:47 +0200 Subject: [PATCH 496/564] Check RGBA values in constructor --- bindings/RGBA.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bindings/RGBA.cpp b/bindings/RGBA.cpp index fc8264c4..8b47b32f 100644 --- a/bindings/RGBA.cpp +++ b/bindings/RGBA.cpp @@ -25,9 +25,13 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_CHECK_ARGS_LEN(4); V8_ARG_TO_INT(1, r); + V8_CHECK(r > 0 && r < 256, "Invalid RGBA R value. Allowed is 0 - 255"); V8_ARG_TO_INT(2, g); + V8_CHECK(g > 0 && g < 256, "Invalid RGBA G value. Allowed is 0 - 255"); V8_ARG_TO_INT(3, b); + V8_CHECK(b > 0 && b < 256, "Invalid RGBA B value. Allowed is 0 - 255"); V8_ARG_TO_INT(4, a); + V8_CHECK(a > 0 && a < 256, "Invalid RGBA A value. Allowed is 0 - 255"); V8::DefineOwnProperty(isolate, ctx, info.This(), V8::RGBA_RKey(isolate), v8::Integer::New(isolate, r), v8::PropertyAttribute::ReadOnly); V8::DefineOwnProperty(isolate, ctx, info.This(), V8::RGBA_GKey(isolate), v8::Integer::New(isolate, g), v8::PropertyAttribute::ReadOnly); From 421efb0d041aa517860e08b02a8b2b2300a2978b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 28 Jul 2021 00:28:57 +0200 Subject: [PATCH 497/564] Update helpers Former-commit-id: 5ebb6a345c4b4128e356ae101a58281c57533100 --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index c5a2c565..062a3fcf 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit c5a2c5655ef6fa6819257ec3e8a9c4c8b42dacdf +Subproject commit 062a3fcfad37e51e411fe7e4139162b4bc990643 From d0ce7a6816774b6ba1adc987614030eb42806a13 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 28 Jul 2021 00:31:05 +0200 Subject: [PATCH 498/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 1383c268..062a3fcf 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 1383c268199e88c56f67dc5230e945c171bb42b7 +Subproject commit 062a3fcfad37e51e411fe7e4139162b4bc990643 From e58130b4aa15b6093d85d0d3079e1dc898856d0c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 29 Jul 2021 21:28:51 +0200 Subject: [PATCH 499/564] Add missing Blip.scale --- src/bindings/Blip.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/bindings/Blip.cpp b/src/bindings/Blip.cpp index 8146e02f..70660cfe 100644 --- a/src/bindings/Blip.cpp +++ b/src/bindings/Blip.cpp @@ -109,6 +109,21 @@ static void RouteColorSetter(v8::Local property, v8::LocalSetRouteColor({ (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a }); } +static void ScaleGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_RETURN_NUMBER(blip->GetScaleXY()[0]); +} + +static void ScaleSetter(v8::Local, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(blip, alt::IBlip); + V8_TO_NUMBER(value, val); + blip->SetScaleXY({ val, val }); +} + static void Fade(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -130,6 +145,7 @@ extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local(isolate, tpl, "sprite"); V8::SetAccessor(isolate, tpl, "size"); + V8::SetAccessor(isolate, tpl, "scale", &ScaleGetter, &ScaleSetter); V8::SetAccessor(isolate, tpl, "color"); V8::SetAccessor(isolate, tpl, "secondaryColor"); V8::SetAccessor(isolate, tpl, "alpha"); From 3cd39a2d87a51f6bf694f411abbd2a7d1dd195a1 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 1 Aug 2021 18:19:01 +0200 Subject: [PATCH 500/564] Fix RGBA not accepting 0 as values --- bindings/RGBA.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/RGBA.cpp b/bindings/RGBA.cpp index 8b47b32f..08bb9808 100644 --- a/bindings/RGBA.cpp +++ b/bindings/RGBA.cpp @@ -25,13 +25,13 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_CHECK_ARGS_LEN(4); V8_ARG_TO_INT(1, r); - V8_CHECK(r > 0 && r < 256, "Invalid RGBA R value. Allowed is 0 - 255"); + V8_CHECK(r >= 0 && r < 256, "Invalid RGBA R value. Allowed is 0 - 255"); V8_ARG_TO_INT(2, g); - V8_CHECK(g > 0 && g < 256, "Invalid RGBA G value. Allowed is 0 - 255"); + V8_CHECK(g >= 0 && g < 256, "Invalid RGBA G value. Allowed is 0 - 255"); V8_ARG_TO_INT(3, b); - V8_CHECK(b > 0 && b < 256, "Invalid RGBA B value. Allowed is 0 - 255"); + V8_CHECK(b >= 0 && b < 256, "Invalid RGBA B value. Allowed is 0 - 255"); V8_ARG_TO_INT(4, a); - V8_CHECK(a > 0 && a < 256, "Invalid RGBA A value. Allowed is 0 - 255"); + V8_CHECK(a >= 0 && a < 256, "Invalid RGBA A value. Allowed is 0 - 255"); V8::DefineOwnProperty(isolate, ctx, info.This(), V8::RGBA_RKey(isolate), v8::Integer::New(isolate, r), v8::PropertyAttribute::ReadOnly); V8::DefineOwnProperty(isolate, ctx, info.This(), V8::RGBA_GKey(isolate), v8::Integer::New(isolate, g), v8::PropertyAttribute::ReadOnly); From caf692f3ad9b320ac28f97651bbe26acd1f7bd5e Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 1 Aug 2021 18:19:22 +0200 Subject: [PATCH 501/564] Update helpers Former-commit-id: 8a5542bc29d873be1a42048ca7739cc675153497 --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 062a3fcf..3cd39a2d 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 062a3fcfad37e51e411fe7e4139162b4bc990643 +Subproject commit 3cd39a2d87a51f6bf694f411abbd2a7d1dd195a1 From 7cc0aa1c2e2021ae7a4d920e0a9220f30c1e2a72 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 6 Aug 2021 20:10:56 +0200 Subject: [PATCH 502/564] Update NodeJS binaries Former-commit-id: 36d5efde2be3e79cd8eb3264ae8a62a9caf11c4e From 992314748bfda4a999028bddc557b639d60df6aa Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 11 Aug 2021 14:23:18 +0200 Subject: [PATCH 503/564] Native arg size mismatch error message --- src/bindings/V8Natives.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index 3d1282ed..ec0dc47b 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -99,6 +99,16 @@ inline void ShowNativeArgParseErrorMsg(v8::Isolate* isolate, v8::LocalGetName() << ")" << Log::Endl; } +inline void ShowNativeArgMismatchErrorMsg(v8::Isolate* isolate, alt::INative* native, int expected, int received) +{ + V8::SourceLocation source = V8::SourceLocation::GetCurrent(isolate); + auto resource = V8ResourceImpl::GetResource(isolate->GetEnteredOrMicrotaskContext()); + Log::Error << "[" << resource->GetName() << ":" << source.GetFileName() << ":" << source.GetLineNumber() << "] " + << "Native argument size mismatch. Expected: " << expected << ", Received: " << received + << " (" << native->GetName() << ")" << Log::Endl; + Log::Error << "Check the documentation for the needed arguments of this native." << Log::Endl; +} + static void PushArg(alt::Ref scrCtx, alt::INative* native, alt::INative::Type argType, v8::Isolate *isolate, V8ResourceImpl* resource, v8::Local val, uint32_t idx) { using ArgType = alt::INative::Type; @@ -319,6 +329,20 @@ static v8::Local GetReturn(alt::Ref scrCtx, al } } +static inline int GetNativeNeededArgCount(alt::INative* native) +{ + int count = 0; + auto args = native->GetArgTypes(); + for(auto arg : args) + { + if(arg == alt::INative::Type::ARG_BOOL_PTR || arg == alt::INative::Type::ARG_INT32_PTR || arg == alt::INative::Type::ARG_UINT32_PTR || + arg == alt::INative::Type::ARG_FLOAT_PTR || arg == alt::INative::Type::ARG_INT32_PTR || arg == alt::INative::Type::ARG_VECTOR3_PTR) + continue; + count++; + } + return count; +} + static void InvokeNative(const v8::FunctionCallbackInfo &info) { static auto ctx = alt::ICore::Instance().CreateNativesContext(); @@ -337,6 +361,13 @@ static void InvokeNative(const v8::FunctionCallbackInfo &info) auto args = native->GetArgTypes(); uint32_t argsSize = args.GetSize(); + auto neededArgs = GetNativeNeededArgCount(native); + if(neededArgs != info.Length()) + { + ShowNativeArgMismatchErrorMsg(isolate, native, neededArgs, info.Length()); + return; + } + ctx->Reset(); pointersCount = 0; returnsCount = 1; From fb9829f677800eb3d84ae08b6d5e20c15f256116 Mon Sep 17 00:00:00 2001 From: C0kkie <20169938+C0kkie@users.noreply.github.com> Date: Thu, 19 Aug 2021 00:28:23 +0200 Subject: [PATCH 504/564] Add ArmourDamage to playerDamage event (#54) * Add ArmourDamage to playerDamage event Former-commit-id: 1b911a636ca9fca203b452dabbe54aa39f8d39b0 --- src/cpp-sdk | 2 +- src/events/Player.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index 2ebb0c16..5017971e 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 2ebb0c1687d0861b0d346365b0bac9215ccdd501 +Subproject commit 5017971e470132b12bd09daeb8ba1a1bcca281e8 diff --git a/src/events/Player.cpp b/src/events/Player.cpp index 598af047..a994eaf2 100644 --- a/src/events/Player.cpp +++ b/src/events/Player.cpp @@ -45,7 +45,8 @@ V8::LocalEventHandler playerDamage( args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); args.push_back(resource->GetBaseObjectOrNull(ev->GetAttacker())); - args.push_back(v8::Integer::New(isolate, ev->GetDamage())); + args.push_back(v8::Integer::New(isolate, ev->GetHealthDamage())); + args.push_back(v8::Integer::New(isolate, ev->GetArmourDamage())); args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetWeapon())); } ); From 41deb29c4dc87c444f87ca46b77d82244d0c6b32 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 20 Aug 2021 16:54:17 +0200 Subject: [PATCH 505/564] Fix native arg count mismatch error message appearing when it shouldn't --- src/bindings/V8Natives.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bindings/V8Natives.cpp b/src/bindings/V8Natives.cpp index ec0dc47b..d8b87591 100644 --- a/src/bindings/V8Natives.cpp +++ b/src/bindings/V8Natives.cpp @@ -336,7 +336,7 @@ static inline int GetNativeNeededArgCount(alt::INative* native) for(auto arg : args) { if(arg == alt::INative::Type::ARG_BOOL_PTR || arg == alt::INative::Type::ARG_INT32_PTR || arg == alt::INative::Type::ARG_UINT32_PTR || - arg == alt::INative::Type::ARG_FLOAT_PTR || arg == alt::INative::Type::ARG_INT32_PTR || arg == alt::INative::Type::ARG_VECTOR3_PTR) + arg == alt::INative::Type::ARG_FLOAT_PTR || arg == alt::INative::Type::ARG_VOID || arg == alt::INative::Type::ARG_VECTOR3_PTR) continue; count++; } @@ -362,7 +362,7 @@ static void InvokeNative(const v8::FunctionCallbackInfo &info) uint32_t argsSize = args.GetSize(); auto neededArgs = GetNativeNeededArgCount(native); - if(neededArgs != info.Length()) + if(neededArgs > info.Length()) { ShowNativeArgMismatchErrorMsg(isolate, native, neededArgs, info.Length()); return; From 54b91e9dbb5aa441faef06b3713a49a3099f0e94 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 21 Aug 2021 17:21:04 +0200 Subject: [PATCH 506/564] add taskChange event --- src/events/Entity.cpp | 12 ++++++++++++ src/helpers | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/events/Entity.cpp b/src/events/Entity.cpp index af5a3344..f192f941 100644 --- a/src/events/Entity.cpp +++ b/src/events/Entity.cpp @@ -6,6 +6,7 @@ #include "cpp-sdk/events/CRemoveEntityEvent.h" #include "cpp-sdk/events/CGameEntityCreateEvent.h" #include "cpp-sdk/events/CGameEntityDestroyEvent.h" +#include "cpp-sdk/events/CTaskChangeEvent.h" #include "cpp-sdk/SDK.h" @@ -49,3 +50,14 @@ V8_EVENT_HANDLER gameEntityDestroy( args.push_back(resource->GetOrCreateEntity(ev->GetTarget().Get())->GetJSVal(isolate)); }); + +V8_LOCAL_EVENT_HANDLER taskChange( + EventType::TASK_CHANGE, + "taskChange", + [](V8ResourceImpl* resource, const alt::CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + v8::Isolate* isolate = resource->GetIsolate(); + + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetOldTask())); + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetNewTask())); + }); \ No newline at end of file diff --git a/src/helpers b/src/helpers index 062a3fcf..3cd39a2d 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 062a3fcfad37e51e411fe7e4139162b4bc990643 +Subproject commit 3cd39a2d87a51f6bf694f411abbd2a7d1dd195a1 From c6fb1b5b56eead2ca251f10a3a2e28666fa7b013 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 22 Aug 2021 02:03:03 +0200 Subject: [PATCH 507/564] Update SDK Former-commit-id: 0e56836a0f4f33208c34a804b855806def536de2 --- src/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index 5017971e..374fd1c6 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 5017971e470132b12bd09daeb8ba1a1bcca281e8 +Subproject commit 374fd1c670b2ef631fe533becb14596092487e1c From a90401821d3c323c6f87c6d15b49d1c9bbff5189 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 22 Aug 2021 02:08:01 +0200 Subject: [PATCH 508/564] Fix SDK Former-commit-id: 5fc647145eaeb302bc19a6ad8799383916bdb6f8 --- src/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index 374fd1c6..de4b124d 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 374fd1c670b2ef631fe533becb14596092487e1c +Subproject commit de4b124d28f3560037cdd97bc518ca0e390e80b0 From 5e3ee4a76c2c0fba04c520adb908374c03c6de65 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 28 Aug 2021 15:50:03 +0200 Subject: [PATCH 509/564] Update SDK --- deps/cpp-sdk/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 2ebb0c16..de4b124d 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 2ebb0c1687d0861b0d346365b0bac9215ccdd501 +Subproject commit de4b124d28f3560037cdd97bc518ca0e390e80b0 From 287afe048b0b882b856ab0154ced972931f5b987 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 28 Aug 2021 16:01:59 +0200 Subject: [PATCH 510/564] Timer cleanup on resource stop --- src/CV8Resource.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/CV8Resource.cpp b/src/CV8Resource.cpp index ef7b585a..7fbe8c5b 100644 --- a/src/CV8Resource.cpp +++ b/src/CV8Resource.cpp @@ -199,6 +199,13 @@ bool CV8ResourceImpl::Stop() //runtime->GetInspector()->contextDestroyed(context.Get(isolate)); + for(auto pair : timers) + { + delete pair.second; + } + timers.clear(); + oldTimers.clear(); + if (!context.IsEmpty()) { auto nscope = resource->PushNativesScope(); From 3ec64796f84d490def2614cfb00055bfcaab4110 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 29 Aug 2021 13:35:33 +0200 Subject: [PATCH 511/564] Fix memory leak in profiler --- src/bindings/Profiler.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bindings/Profiler.cpp b/src/bindings/Profiler.cpp index 88c11910..f880c05d 100644 --- a/src/bindings/Profiler.cpp +++ b/src/bindings/Profiler.cpp @@ -92,10 +92,11 @@ static void StopProfiling(const v8::FunctionCallbackInfo& info) // Clear the nodemap to not cause a memory leak nodeMap.clear(); - - V8_RETURN(resultObj); + result->Delete(); profilerRunningCount--; + + V8_RETURN(resultObj); } static void SamplingIntervalSetter(v8::Local, v8::Local value, const v8::PropertyCallbackInfo &info) From 0983384024cefbd80f9c3dcf3ce6760dadaaa811 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 30 Aug 2021 23:07:55 +0200 Subject: [PATCH 512/564] Update SDK Former-commit-id: d84dcba81d729cc0ce56487a9af2363a51d1bb73 --- src/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index de4b124d..115de7e4 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit de4b124d28f3560037cdd97bc518ca0e390e80b0 +Subproject commit 115de7e449f9ab33833eeac2c6ec46b80d647004 From 555a4248bbdc302340fe8fb0815c8f33998d20cf Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 30 Aug 2021 23:08:15 +0200 Subject: [PATCH 513/564] Add vehicle damage event Former-commit-id: 6dd4375bb11250af6da7ae19994039657d240129 --- src/events/Vehicle.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/events/Vehicle.cpp b/src/events/Vehicle.cpp index 75878ea0..e36117c8 100644 --- a/src/events/Vehicle.cpp +++ b/src/events/Vehicle.cpp @@ -51,4 +51,21 @@ V8::LocalEventHandler netOwnerChange( args.push_back(resource->GetBaseObjectOrNull(ev->GetNewOwner())); args.push_back(resource->GetBaseObjectOrNull(ev->GetOldOwner())); } -); \ No newline at end of file +); + +V8::LocalEventHandler vehicleDamage( + EventType::VEHICLE_DAMAGE, + "vehicleDamage", + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + auto ev = static_cast(e); + auto isolate = resource->GetIsolate(); + + args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); + args.push_back(resource->GetBaseObjectOrNull(ev->GetDamager())); + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetBodyHealthDamage())); + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetBodyAdditionalHealthDamage())); + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetEngineHealthDamage())); + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetPetrolTankHealthDamage())); + args.push_back(v8::Integer::NewFromUnsigned(isolate, ev->GetDamagedWith())); + } +); From 739695b371896682dc56c4a1fefc103daff4702b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 30 Aug 2021 23:09:44 +0200 Subject: [PATCH 514/564] Add entity streamed property --- bindings/Entity.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/Entity.cpp b/bindings/Entity.cpp index 90e4e6fd..1c9677b2 100644 --- a/bindings/Entity.cpp +++ b/bindings/Entity.cpp @@ -244,6 +244,7 @@ extern V8Class v8Entity("Entity", v8WorldObject, [](v8::Local(isolate, tpl, "rot"); V8::SetAccessor(isolate, tpl, "model", &ModelGetter, &ModelSetter); V8::SetAccessor(isolate, tpl, "visible"); + V8::SetAccessor(isolate, tpl, "streamed"); V8::SetMethod(isolate, tpl, "setSyncedMeta", SetSyncedMeta); V8::SetMethod(isolate, tpl, "deleteSyncedMeta", DeleteSyncedMeta); From e9d5dee460628ae43e7ff68c4e68d0d3edfb6596 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 30 Aug 2021 23:13:06 +0200 Subject: [PATCH 515/564] Update helpers Former-commit-id: 56914829c4a9d33196d7e0b30cfd4ffb8cefa93f --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 3cd39a2d..739695b3 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 3cd39a2d87a51f6bf694f411abbd2a7d1dd195a1 +Subproject commit 739695b371896682dc56c4a1fefc103daff4702b From 1c4c64722d4cf520092f78f25b92d143c85438d2 Mon Sep 17 00:00:00 2001 From: C0kkie <20169938+C0kkie@users.noreply.github.com> Date: Tue, 31 Aug 2021 18:58:51 +0200 Subject: [PATCH 516/564] Improve toString methods (#82) * Improve toString to vehicle & player to use sdk directly * Update helpers --- src/bindings/Player.cpp | 6 ++---- src/bindings/Vehicle.cpp | 6 ++---- src/helpers | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 5ddcffa5..da3256da 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -16,12 +16,10 @@ static void ToString(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); - auto player = info.This(); - V8_OBJECT_GET_INT(player, "id", id); - V8_OBJECT_GET_STRING(player, "name", name); + V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); std::ostringstream ss; - ss << "Player{ id: " << std::to_string(id) << ", name: " << name.CStr() << " }"; + ss << "Player{ id: " << std::to_string(player->GetID()) << ", name: " << player->GetName().CStr() << " }"; V8_RETURN_STRING(ss.str().c_str()); } diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 44fa3f01..6aad19ae 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -16,12 +16,10 @@ static void ToString(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); - auto vehicle = info.This(); - V8_OBJECT_GET_INT(vehicle, "id", id); - V8_OBJECT_GET_NUMBER(vehicle, "model", model); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); std::ostringstream ss; - ss << "Vehicle{ id: " << std::to_string(id) << ", model: " << std::to_string((uint64_t)model) << " }"; + ss << "Vehicle{ id: " << std::to_string(vehicle->GetID()) << ", model: " << std::to_string((uint64_t)vehicle->GetModel()) << " }"; V8_RETURN_STRING(ss.str().c_str()); } diff --git a/src/helpers b/src/helpers index 3cd39a2d..739695b3 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 3cd39a2d87a51f6bf694f411abbd2a7d1dd195a1 +Subproject commit 739695b371896682dc56c4a1fefc103daff4702b From b56826b603b749dfa7eced57c234413b0eaf79d1 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Tue, 31 Aug 2021 22:59:42 +0200 Subject: [PATCH 517/564] Activate pedblip and vehicleblip in bindings --- src/bindings/Main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index 891e3760..2af9c256 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -869,6 +869,8 @@ extern V8Module altModule( v8AreaBlip, v8RadiusBlip, v8PointBlip, + v8PedBlip, + v8VehicleBlip, v8HandlingData, v8LocalStorage, v8MemoryBuffer, From e089a6b142402f8a9394ba50eefde936e0175bc5 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 2 Sep 2021 17:22:50 +0200 Subject: [PATCH 518/564] Check if string is empty in V8_OBJECT_SET_STRING macro --- V8Helpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/V8Helpers.h b/V8Helpers.h index 9d1e1fff..43b4a5da 100644 --- a/V8Helpers.h +++ b/V8Helpers.h @@ -356,7 +356,7 @@ namespace V8 V8_TO_STRING((v8Val)->Get(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked()).ToLocalChecked(), val) #define V8_OBJECT_SET_STRING(v8Val, prop, val) \ - (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::String::NewFromUtf8(isolate, val.CStr()).ToLocalChecked()); + if(!val.IsEmpty()) (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::String::NewFromUtf8(isolate, val.CStr()).ToLocalChecked()); #define V8_NEW_STRING(val) v8::String::NewFromUtf8(isolate, val).ToLocalChecked() From 3dae4a3f2c1829d949eadf4bbe824de965b9ad90 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 2 Sep 2021 21:43:35 +0200 Subject: [PATCH 519/564] Add player moveSpeed getter Former-commit-id: a86b6f904a06680850417b03d07dd5698c969e4e --- src/bindings/Player.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 2da6ef66..68445c00 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -434,6 +434,8 @@ extern V8Class v8Player("Player", v8Entity, nullptr, [](v8::Local(isolate, tpl, "flashlightActive"); + V8::SetAccessor(isolate, tpl, "moveSpeed"); + V8::SetMethod(isolate, tpl, "spawn", &Spawn); V8::SetMethod(isolate, tpl, "setDateTime", &SetDateTime); V8::SetMethod(isolate, tpl, "setWeather", &SetWeather); From 2c69174f6870e799a6ce29a523e73d4e6dbec3f2 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 2 Sep 2021 22:12:46 +0200 Subject: [PATCH 520/564] Update helpers Former-commit-id: 7e4660bff69a3e4230e284b140bd24f7e36238ad --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 739695b3..e089a6b1 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 739695b371896682dc56c4a1fefc103daff4702b +Subproject commit e089a6b142402f8a9394ba50eefde936e0175bc5 From 84d0d855dd6257bba72f88d098a02c382cce48b4 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Thu, 2 Sep 2021 22:12:58 +0200 Subject: [PATCH 521/564] Add missing player getters Former-commit-id: e787366454ffa7c9a4c9844a91606b00f7f05090 --- src/bindings/Player.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 68445c00..022e83f8 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -417,6 +417,10 @@ extern V8Class v8Player("Player", v8Entity, nullptr, [](v8::Local(isolate, tpl, "armour"); V8::SetAccessor(isolate, tpl, "maxArmour"); V8::SetAccessor(isolate, tpl, "isDead"); + V8::SetAccessor(isolate, tpl, "isInRagdoll"); + V8::SetAccessor(isolate, tpl, "isAiming"); + V8::SetAccessor(isolate, tpl, "aimPos"); + V8::SetAccessor(isolate, tpl, "headRot"); V8::SetAccessor, &IPlayer::GetEntityAimingAt>(isolate, tpl, "entityAimingAt"); V8::SetAccessor(isolate, tpl, "entityAimOffset"); From dae022c563e9a7ef0620838999e5964267077eb9 Mon Sep 17 00:00:00 2001 From: C0kkie <20169938+C0kkie@users.noreply.github.com> Date: Thu, 2 Sep 2021 23:22:18 +0200 Subject: [PATCH 522/564] Add setExtraHeader for webview (#83) * Add setExtraHeader for webview * Get baseobject befor arg check --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/WebView.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index de4b124d..0e376aa9 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit de4b124d28f3560037cdd97bc518ca0e390e80b0 +Subproject commit 0e376aa98b26e4df654c709fe246bdafd20876e4 diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index 3b22b854..a8fd3709 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -192,6 +192,19 @@ static void Constructor(const v8::FunctionCallbackInfo& info) V8_BIND_BASE_OBJECT(view, "Failed to create WebView"); } +static void SetExtraHeader(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); + + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_STRING(1, name); + V8_ARG_TO_STRING(2, value); + + view->SetExtraHeader(name, value); +} + extern V8Class v8BaseObject; extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); @@ -211,4 +224,6 @@ extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local(isolate, tpl, "focus"); V8::SetMethod(isolate, tpl, "unfocus"); + + V8::SetMethod(isolate, tpl, "setExtraHeader", &SetExtraHeader); }); From a1762ee303fa06718cfe0400b4b15b281814b3a1 Mon Sep 17 00:00:00 2001 From: Blue Date: Fri, 3 Sep 2021 00:04:40 +0200 Subject: [PATCH 523/564] Add invincible setter/getter Former-commit-id: ea11a49559d5cc338aa9adb6a92a0282c781184e --- src/bindings/Player.cpp | 2 ++ src/cpp-sdk | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 022e83f8..27f01895 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -440,6 +440,8 @@ extern V8Class v8Player("Player", v8Entity, nullptr, [](v8::Local(isolate, tpl, "moveSpeed"); + V8::SetAccessor(isolate, tpl, "invincible"); + V8::SetMethod(isolate, tpl, "spawn", &Spawn); V8::SetMethod(isolate, tpl, "setDateTime", &SetDateTime); V8::SetMethod(isolate, tpl, "setWeather", &SetWeather); diff --git a/src/cpp-sdk b/src/cpp-sdk index 115de7e4..0d66a538 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 115de7e449f9ab33833eeac2c6ec46b80d647004 +Subproject commit 0d66a538b92b1d351d6a37dcad3c08bda8ad3236 From d00752e3e441d7155eeab13dc05146899d5c52d8 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 4 Sep 2021 15:30:03 +0200 Subject: [PATCH 524/564] Update SDK Former-commit-id: 523798c1317e308dac23d4c687af64f741326877 --- src/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp-sdk b/src/cpp-sdk index 0d66a538..9967ffe7 160000 --- a/src/cpp-sdk +++ b/src/cpp-sdk @@ -1 +1 @@ -Subproject commit 0d66a538b92b1d351d6a37dcad3c08bda8ad3236 +Subproject commit 9967ffe7674b0c831ba2ade0272bf6e52f8daf61 From d40bd636da72dd6a07b23e748f840f1b3931bd61 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 4 Sep 2021 19:10:49 +0200 Subject: [PATCH 525/564] Add vector3.zero --- bindings/Vector3.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index d7ae9153..dd1fdb28 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -583,6 +583,15 @@ static void IsInRange(const v8::FunctionCallbackInfo& info) V8_RETURN_BOOLEAN(isInRange); } +static void StaticZero(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto zero = v8::Eternal(isolate, resource->CreateVector3({0, 0, 0}).As()); + + V8_RETURN(zero.Get(isolate)); +} + static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -648,6 +657,8 @@ static void Constructor(const v8::FunctionCallbackInfo& info) extern V8Class v8Vector3("Vector3", Constructor, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8::SetStaticAccessor(isolate, tpl, "zero", StaticZero); + V8::SetAccessor(isolate, tpl, "length", Length); V8::SetMethod(isolate, tpl, "toString", ToString); V8::SetMethod(isolate, tpl, "toArray", ToArray); From c0aa1e24bb45ba297fb506ec2f9347c7ed7398f3 Mon Sep 17 00:00:00 2001 From: C0kkie <20169938+C0kkie@users.noreply.github.com> Date: Sat, 4 Sep 2021 20:23:06 +0200 Subject: [PATCH 526/564] Add vector3, back, down, left, forward, one, right, up (#44) * Add vector3, back, down, left, forward, one, right, up * Move One below zero for Lhoerion * Add positiveInfinity & negativeInfinity --- bindings/Vector3.cpp | 99 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/bindings/Vector3.cpp b/bindings/Vector3.cpp index dd1fdb28..00f3053d 100644 --- a/bindings/Vector3.cpp +++ b/bindings/Vector3.cpp @@ -579,7 +579,7 @@ static void IsInRange(const v8::FunctionCallbackInfo& info) dy <= range && dz <= range && dx * dx + dy * dy + dz * dz <= range * range; // perform exact check - + V8_RETURN_BOOLEAN(isInRange); } @@ -588,10 +588,96 @@ static void StaticZero(v8::Local, const v8::PropertyCallbackInfo(isolate, resource->CreateVector3({0, 0, 0}).As()); - + V8_RETURN(zero.Get(isolate)); } +static void StaticOne(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto one = v8::Eternal(isolate, resource->CreateVector3({1, 1, 1}).As()); + + V8_RETURN(one.Get(isolate)); +} + +static void StaticBack(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto back = v8::Eternal(isolate, resource->CreateVector3({0, 0, -1}).As()); + + V8_RETURN(back.Get(isolate)); +} + +static void StaticDown(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto down = v8::Eternal(isolate, resource->CreateVector3({0, -1, 0}).As()); + + V8_RETURN(down.Get(isolate)); +} + +static void StaticForward(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto forward = v8::Eternal(isolate, resource->CreateVector3({0, 0, 1}).As()); + + V8_RETURN(forward.Get(isolate)); +} + +static void StaticLeft(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto left = v8::Eternal(isolate, resource->CreateVector3({-1, 0, 0}).As()); + + V8_RETURN(left.Get(isolate)); +} + +static void StaticRight(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto right = v8::Eternal(isolate, resource->CreateVector3({1, 0, 0}).As()); + + V8_RETURN(right.Get(isolate)); +} + +static void StaticUp(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto up = v8::Eternal(isolate, resource->CreateVector3({0, 1, 0}).As()); + + V8_RETURN(up.Get(isolate)); +} + +static void StaticNegativeInfinity(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + + float infinity = -std::numeric_limits::infinity(); + static auto negativeInfinity = v8::Eternal(isolate, resource->CreateVector3({infinity, infinity, infinity}).As()); + + V8_RETURN(negativeInfinity.Get(isolate)); +} + +static void StaticPositiveInfinity(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + + float infinity = std::numeric_limits::infinity(); + static auto positiveInfinity = v8::Eternal(isolate, resource->CreateVector3({infinity, infinity, infinity}).As()); + + V8_RETURN(positiveInfinity.Get(isolate)); +} + + static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -658,6 +744,15 @@ extern V8Class v8Vector3("Vector3", Constructor, [](v8::Local Date: Sat, 4 Sep 2021 20:23:19 +0200 Subject: [PATCH 527/564] Vector2 add zero, one, up, down, left, right (#45) * Vector2 add zero, one, up, down, left, right * Fix * add negativeInfinity & positiveInfinity * Fix --- bindings/Vector2.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/bindings/Vector2.cpp b/bindings/Vector2.cpp index e6f6b0f5..9e95f4f8 100644 --- a/bindings/Vector2.cpp +++ b/bindings/Vector2.cpp @@ -485,6 +485,82 @@ static void IsInRange(const v8::FunctionCallbackInfo& info) V8_RETURN_BOOLEAN(isInRange); } +static void StaticZero(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto zero = v8::Eternal(isolate, resource->CreateVector2({0, 0}).As()); + + V8_RETURN(zero.Get(isolate)); +} + +static void StaticOne(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto one = v8::Eternal(isolate, resource->CreateVector2({1, 1}).As()); + + V8_RETURN(one.Get(isolate)); +} + +static void StaticUp(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto up = v8::Eternal(isolate, resource->CreateVector2({0, 1}).As()); + + V8_RETURN(up.Get(isolate)); +} + +static void StaticDown(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto down = v8::Eternal(isolate, resource->CreateVector2({0, -1}).As()); + + V8_RETURN(down.Get(isolate)); +} + +static void StaticLeft(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto left = v8::Eternal(isolate, resource->CreateVector2({-1, 0}).As()); + + V8_RETURN(left.Get(isolate)); +} + +static void StaticRight(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + static auto right = v8::Eternal(isolate, resource->CreateVector2({1, 0}).As()); + + V8_RETURN(right.Get(isolate)); +} + +static void StaticNegativeInfinity(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + + float infinity = -std::numeric_limits::infinity(); + static auto negativeInfinity = v8::Eternal(isolate, resource->CreateVector2({infinity, infinity}).As()); + + V8_RETURN(negativeInfinity.Get(isolate)); +} + +static void StaticPositiveInfinity(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE(); + V8_GET_RESOURCE(); + + float infinity = std::numeric_limits::infinity(); + static auto positiveInfinity = v8::Eternal(isolate, resource->CreateVector2({infinity, infinity}).As()); + + V8_RETURN(positiveInfinity.Get(isolate)); +} + static void Constructor(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -543,6 +619,15 @@ static void Constructor(const v8::FunctionCallbackInfo& info) extern V8Class v8Vector2("Vector2", Constructor, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); + V8::SetStaticAccessor(isolate, tpl, "zero", StaticZero); + V8::SetStaticAccessor(isolate, tpl, "one", StaticOne); + V8::SetStaticAccessor(isolate, tpl, "up", StaticUp); + V8::SetStaticAccessor(isolate, tpl, "down", StaticDown); + V8::SetStaticAccessor(isolate, tpl, "left", StaticLeft); + V8::SetStaticAccessor(isolate, tpl, "right", StaticRight); + V8::SetStaticAccessor(isolate, tpl, "negativeInfinity", StaticNegativeInfinity); + V8::SetStaticAccessor(isolate, tpl, "positiveInfinity", StaticPositiveInfinity); + V8::SetAccessor(isolate, tpl, "length", Length); V8::SetMethod(isolate, tpl, "toString", ToString); V8::SetMethod(isolate, tpl, "toArray", ToArray); From dbc6c1d34ed36cb97a82df1b024658b105880849 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 4 Sep 2021 20:31:31 +0200 Subject: [PATCH 528/564] Update helpers Former-commit-id: c6cc57ba0d8d976d1751ea9bd3f4c7b5bc46a97d --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index e089a6b1..799d93ba 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit e089a6b142402f8a9394ba50eefde936e0175bc5 +Subproject commit 799d93baf9622aa116c11254128d1b77dac94fb3 From dd4a50f9aa286b81f10d5e6c7b0f9698a85f902f Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 4 Sep 2021 20:32:44 +0200 Subject: [PATCH 529/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 739695b3..799d93ba 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 739695b371896682dc56c4a1fefc103daff4702b +Subproject commit 799d93baf9622aa116c11254128d1b77dac94fb3 From bd38d6faa0e60da1ac9c8378ea6ff59b0455b5e3 Mon Sep 17 00:00:00 2001 From: Blue Date: Mon, 6 Sep 2021 02:22:28 +0200 Subject: [PATCH 530/564] (Client/Webview): add setZoomLevel --- deps/cpp-sdk/cpp-sdk | 2 +- src/bindings/WebView.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/deps/cpp-sdk/cpp-sdk b/deps/cpp-sdk/cpp-sdk index 0e376aa9..60e23a5e 160000 --- a/deps/cpp-sdk/cpp-sdk +++ b/deps/cpp-sdk/cpp-sdk @@ -1 +1 @@ -Subproject commit 0e376aa98b26e4df654c709fe246bdafd20876e4 +Subproject commit 60e23a5e1b1740b3e5269c4f0da442cc8db80fda diff --git a/src/bindings/WebView.cpp b/src/bindings/WebView.cpp index a8fd3709..f96bb364 100644 --- a/src/bindings/WebView.cpp +++ b/src/bindings/WebView.cpp @@ -205,6 +205,18 @@ static void SetExtraHeader(const v8::FunctionCallbackInfo& info) view->SetExtraHeader(name, value); } +static void SetZoomLevel(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_BASE_OBJECT(view, alt::IWebView); + + V8_CHECK_ARGS_LEN(1); + V8_ARG_TO_NUMBER(1, zoomLevel); + + view->SetZoomLevel(zoomLevel); +} + extern V8Class v8BaseObject; extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local tpl) { v8::Isolate *isolate = v8::Isolate::GetCurrent(); @@ -226,4 +238,5 @@ extern V8Class v8WebView("WebView", v8BaseObject, &Constructor, [](v8::Local(isolate, tpl, "unfocus"); V8::SetMethod(isolate, tpl, "setExtraHeader", &SetExtraHeader); + V8::SetMethod(isolate, tpl, "setZoomLevel", &SetZoomLevel); }); From 9d347a6646f126146f923cdad7c33c781c4b24d1 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 8 Sep 2021 19:41:59 +0200 Subject: [PATCH 531/564] Fix more potential crashes in MValue conversion --- V8Class.cpp | 9 ++++++- V8Helpers.cpp | 75 ++++++++++++++++++++++----------------------------- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/V8Class.cpp b/V8Class.cpp index 36193f92..f8500583 100644 --- a/V8Class.cpp +++ b/V8Class.cpp @@ -10,7 +10,14 @@ v8::Local V8Class::New(v8::Local ctx, std::vector obj; V8Helpers::TryCatch([&] { - v8::MaybeLocal maybeObj = _tpl->GetFunction(ctx).ToLocalChecked()->CallAsConstructor(ctx, args.size(), args.data()); + v8::Local func; + if(!_tpl->GetFunction(ctx).ToLocal(&func)) + { + Log::Error << "V8Class::New Invalid constructor called" << Log::Endl; + return false; + } + + v8::MaybeLocal maybeObj = func->CallAsConstructor(ctx, args.size(), args.data()); if (!maybeObj.IsEmpty()) { diff --git a/V8Helpers.cpp b/V8Helpers.cpp index 70cc7c91..3ff4df97 100644 --- a/V8Helpers.cpp +++ b/V8Helpers.cpp @@ -48,7 +48,7 @@ bool V8Helpers::TryCatch(const std::function& fn) exception.IsEmpty() ? "unknown" : *v8::String::Utf8Value(isolate, exception), (!stackTrace.IsEmpty() && stackTrace.ToLocalChecked()->IsString()) ? *v8::String::Utf8Value(isolate, stackTrace.ToLocalChecked()) : "", *v8::String::Utf8Value(isolate, origin.ResourceName()), - line.ToChecked()); + line.IsNothing() ? -1 : line.ToChecked()); } else { @@ -179,77 +179,63 @@ alt::MValue V8Helpers::V8ToMValue(v8::Local val) //if (v8Obj->InstanceOf(ctx, v8Vector3->JSValue(isolate, ctx)).ToChecked()) if (resource->IsVector3(v8Obj)) { - v8::Local x = v8Obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local y = v8Obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local z = v8Obj->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local x, y, z; + V8_CHECK_RETN(v8Obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocal(&x), "Failed to convert Vector3 to MValue", core.CreateMValueNil()); + V8_CHECK_RETN(v8Obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocal(&y), "Failed to convert Vector3 to MValue", core.CreateMValueNil()); + V8_CHECK_RETN(v8Obj->Get(ctx, V8::Vector3_ZKey(isolate)).ToLocal(&z), "Failed to convert Vector3 to MValue", core.CreateMValueNil()); return core.CreateMValueVector3( alt::Vector3f{ - x->Value(), - y->Value(), - z->Value() }); + x.As()->Value(), + y.As()->Value(), + z.As()->Value() }); } else if (resource->IsVector2(v8Obj)) { - v8::Local x = v8Obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local y = v8Obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local x, y; + V8_CHECK_RETN(v8Obj->Get(ctx, V8::Vector3_XKey(isolate)).ToLocal(&x), "Failed to convert Vector2 to MValue", core.CreateMValueNil()); + V8_CHECK_RETN(v8Obj->Get(ctx, V8::Vector3_YKey(isolate)).ToLocal(&y), "Failed to convert Vector2 to MValue", core.CreateMValueNil()); return core.CreateMValueVector2( alt::Vector2f{ - x->Value(), - y->Value() }); + x.As()->Value(), + y.As()->Value() }); } else if (resource->IsRGBA(v8Obj)) { - v8::Local r = v8Obj->Get(ctx, V8::RGBA_RKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local g = v8Obj->Get(ctx, V8::RGBA_GKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local b = v8Obj->Get(ctx, V8::RGBA_BKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); - v8::Local a = v8Obj->Get(ctx, V8::RGBA_AKey(isolate)).ToLocalChecked()->ToNumber(ctx).ToLocalChecked(); + v8::Local r, g, b, a; + V8_CHECK_RETN(v8Obj->Get(ctx, V8::RGBA_RKey(isolate)).ToLocal(&r), "Failed to convert RGBA to MValue", core.CreateMValueNil()); + V8_CHECK_RETN(v8Obj->Get(ctx, V8::RGBA_GKey(isolate)).ToLocal(&g), "Failed to convert RGBA to MValue", core.CreateMValueNil()); + V8_CHECK_RETN(v8Obj->Get(ctx, V8::RGBA_BKey(isolate)).ToLocal(&b), "Failed to convert RGBA to MValue", core.CreateMValueNil()); + V8_CHECK_RETN(v8Obj->Get(ctx, V8::RGBA_AKey(isolate)).ToLocal(&a), "Failed to convert RGBA to MValue", core.CreateMValueNil()); return core.CreateMValueRGBA( alt::RGBA{ - (uint8_t)r->Value(), - (uint8_t)g->Value(), - (uint8_t)b->Value(), - (uint8_t)a->Value() }); + (uint8_t)r.As()->Value(), + (uint8_t)g.As()->Value(), + (uint8_t)b.As()->Value(), + (uint8_t)a.As()->Value() }); } else if (resource->IsBaseObject(v8Obj)) { V8Entity* ent = V8Entity::Get(v8Obj); Log::Debug << "Instanceof BaseObject" << Log::Endl; - if (!ent) - { - Log::Error << "Unable to convert base object to MValue because it was destroyed and is now invalid" << Log::Endl; - return core.CreateMValueNil(); - } - else - return core.CreateMValueBaseObject(ent->GetHandle()); + V8_CHECK_RETN(ent, "Unable to convert base object to MValue because it was destroyed and is now invalid", core.CreateMValueNil()); + return core.CreateMValueBaseObject(ent->GetHandle()); } else { alt::MValueDict dict = core.CreateMValueDict(); v8::Local keys; - if(!v8Obj->GetOwnPropertyNames(ctx).ToLocal(&keys)) - { - Log::Error << "Failed to convert object to MValue" << Log::Endl; - return core.CreateMValueNil(); - } + + V8_CHECK_RETN(v8Obj->GetOwnPropertyNames(ctx).ToLocal(&keys), "Failed to convert object to MValue", core.CreateMValueNil()); for (uint32_t i = 0; i < keys->Length(); ++i) { v8::Local v8Key; - if(!keys->Get(ctx, i).ToLocal(&v8Key)) - { - Log::Error << "Failed to convert object to MValue" << Log::Endl; - return core.CreateMValueNil(); - } - + V8_CHECK_RETN(keys->Get(ctx, i).ToLocal(&v8Key), "Failed to convert object to MValue", core.CreateMValueNil()); v8::Local value; - if(!v8Obj->Get(ctx, v8Key).ToLocal(&value)) - { - Log::Error << "Failed to convert object to MValue" << Log::Endl; - return core.CreateMValueNil(); - } + V8_CHECK_RETN(v8Obj->Get(ctx, v8Key).ToLocal(&value), "Failed to convert object to MValue", core.CreateMValueNil()); if(value->IsUndefined()) continue; std::string key = *v8::String::Utf8Value(isolate, v8Key); @@ -330,7 +316,10 @@ v8::Local V8Helpers::MValueToV8(alt::MValueConst val) { alt::MValueFunctionConst fn = val.As(); v8::Local extFn = v8::External::New(isolate, new alt::MValueFunctionConst(fn)); - return v8::Function::New(ctx, V8Helpers::FunctionCallback, extFn).ToLocalChecked(); + + v8::Local func; + V8_CHECK_RETN(v8::Function::New(ctx, V8Helpers::FunctionCallback, extFn).ToLocal(&func), "Failed to convert MValue to function", v8::Undefined(isolate)); + return func; } case alt::IMValue::Type::VECTOR3: return V8ResourceImpl::Get(ctx)->CreateVector3(val.As()->Value()); From 366b87752dd95b85dca0b1d3653d3afe23fa61b9 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 8 Sep 2021 19:42:30 +0200 Subject: [PATCH 532/564] Fix possible crash in emitClient with player array Former-commit-id: a85dd473b772e1757de7a265bbf77786544c0cac --- src/bindings/Main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index e929c183..380e8495 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -94,7 +94,9 @@ static void EmitClient(const v8::FunctionCallbackInfo& info) for (int i = 0; i < arr->Length(); ++i) { Ref player; - V8Entity* v8Player = V8Entity::Get(arr->Get(ctx, i).ToLocalChecked()); + v8::Local ply; + V8_CHECK(arr->Get(ctx, i).ToLocal(&ply), "Invalid player in emitClient players array"); + V8Entity* v8Player = V8Entity::Get(ply); V8_CHECK(v8Player && v8Player->GetHandle()->GetType() == alt::IBaseObject::Type::PLAYER, "player inside array expected"); targets.Push(v8Player->GetHandle().As()); From c7e1620c464b857937439718eeda61ec4d953ecb Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Wed, 8 Sep 2021 19:42:37 +0200 Subject: [PATCH 533/564] Update helpers Former-commit-id: d3c0c2b5f24f122a52ef11bebc3b7fbf19fb7922 --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 799d93ba..9d347a66 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 799d93baf9622aa116c11254128d1b77dac94fb3 +Subproject commit 9d347a6646f126146f923cdad7c33c781c4b24d1 From 6867952edcaf5935796003c1c6ba1b80b98ec1d0 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 10 Sep 2021 00:09:16 +0200 Subject: [PATCH 534/564] Add base object remove and create events --- V8ResourceImpl.cpp | 4 ++++ V8ResourceImpl.h | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index 483421fa..ff880fa3 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -182,6 +182,8 @@ void V8ResourceImpl::OnCreateBaseObject(alt::Ref handle) CreateEntity(handle.Get()); }*/ + DispatchBaseObjectCreateEvent(handle); + NotifyPoolUpdate(handle.Get()); } @@ -200,6 +202,8 @@ void V8ResourceImpl::OnRemoveBaseObject(alt::Ref handle) if (!ent) return; + DispatchBaseObjectRemoveEvent(handle); + entities.erase(handle.Get()); // TODO: ent->SetWeak(); diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index bed9d0c2..c986c1f8 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -131,6 +131,17 @@ class V8ResourceImpl : public alt::IResource::Impl InvokeEventHandlers(nullptr, GetLocalHandlers("resourceError"), args); } + void DispatchBaseObjectCreateEvent(alt::Ref object) + { + std::vector> args = { GetOrCreateEntity(object.Get())->GetJSVal(isolate) }; + InvokeEventHandlers(nullptr, GetLocalHandlers("baseObjectCreate"), args); + } + void DispatchBaseObjectRemoveEvent(alt::Ref object) + { + std::vector> args = { GetOrCreateEntity(object.Get())->GetJSVal(isolate) }; + InvokeEventHandlers(nullptr, GetLocalHandlers("baseObjectRemove"), args); + } + V8Entity *GetEntity(alt::IBaseObject *handle) { auto it = entities.find(handle); From ccb8a27e9977cb4d3e644e59190e052c71bba981 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 10 Sep 2021 00:25:45 +0200 Subject: [PATCH 535/564] Update helpers Former-commit-id: e71bec997921ac9021cda1b7510e973bae39bcfb --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 9d347a66..6867952e 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 9d347a6646f126146f923cdad7c33c781c4b24d1 +Subproject commit 6867952edcaf5935796003c1c6ba1b80b98ec1d0 From a24cd018f7cc045f94a44e1dc36a0610a71319f3 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 10 Sep 2021 11:19:38 +0200 Subject: [PATCH 536/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 799d93ba..6867952e 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 799d93baf9622aa116c11254128d1b77dac94fb3 +Subproject commit 6867952edcaf5935796003c1c6ba1b80b98ec1d0 From 3e240b0af49f2bd9d09a5c09197ce503d4a289ed Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 10 Sep 2021 15:03:22 +0200 Subject: [PATCH 537/564] Fix crash in OnCreateBaseObject --- V8ResourceImpl.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index ff880fa3..bf29b518 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -182,6 +182,11 @@ void V8ResourceImpl::OnCreateBaseObject(alt::Ref handle) CreateEntity(handle.Get()); }*/ + v8::Locker locker(isolate); + v8::Isolate::Scope isolateScope(isolate); + v8::HandleScope handleScope(isolate); + v8::Context::Scope scope(GetContext()); + DispatchBaseObjectCreateEvent(handle); NotifyPoolUpdate(handle.Get()); @@ -194,7 +199,6 @@ void V8ResourceImpl::OnRemoveBaseObject(alt::Ref handle) v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); - v8::Context::Scope scope(GetContext()); V8Entity *ent = GetEntity(handle.Get()); From f4027ddfe2278526165ed6d4c2850d3270c74cd8 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 10 Sep 2021 15:04:39 +0200 Subject: [PATCH 538/564] Update helpers Former-commit-id: 912be6ba98d63d10d94b18e70b6d3a93a0c79b1d --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 6867952e..3e240b0a 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 6867952edcaf5935796003c1c6ba1b80b98ec1d0 +Subproject commit 3e240b0af49f2bd9d09a5c09197ce503d4a289ed From c0747400718b25d15e45228c00ebe2c8296c41a5 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 10 Sep 2021 19:24:14 +0200 Subject: [PATCH 539/564] Add player.setIntoVehicle Former-commit-id: 733d9ef990fb52fab73cf7aa4cc781d42bda3a2c --- src/bindings/Player.cpp | 14 ++++++++++++++ src/cpp-sdk | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 27f01895..1a074214 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -369,6 +369,18 @@ static void IsEntityInStreamRange(const v8::FunctionCallbackInfo& inf V8_RETURN_BOOLEAN(player->IsEntityInStreamingRange(entity)); } +static void SetIntoVehicle(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(2); + V8_GET_THIS_BASE_OBJECT(player, IPlayer); + + V8_ARG_TO_BASE_OBJECT(1, vehicle, alt::IVehicle, "Vehicle"); + V8_ARG_TO_UINT32(2, seat); + + player->SetIntoVehicle(vehicle, seat); +} + static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); @@ -470,4 +482,6 @@ extern V8Class v8Player("Player", v8Entity, nullptr, [](v8::Local Date: Fri, 10 Sep 2021 20:14:45 +0200 Subject: [PATCH 540/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 6867952e..3e240b0a 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 6867952edcaf5935796003c1c6ba1b80b98ec1d0 +Subproject commit 3e240b0af49f2bd9d09a5c09197ce503d4a289ed From 53f04e6de8483234f2cebd19e9c97a3e741c1126 Mon Sep 17 00:00:00 2001 From: Leon B Date: Fri, 10 Sep 2021 20:58:14 +0200 Subject: [PATCH 541/564] Merge dev to rc (#58) * Fix possible crash in emitClient with player array * Update helpers * Update helpers * Update helpers * Add player.setIntoVehicle Former-commit-id: 55f9169af75abd764c85577d7205488bf8f4b375 --- src/bindings/Main.cpp | 4 +++- src/bindings/Player.cpp | 14 ++++++++++++++ src/cpp-sdk | 2 +- src/helpers | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/bindings/Main.cpp b/src/bindings/Main.cpp index e929c183..380e8495 100644 --- a/src/bindings/Main.cpp +++ b/src/bindings/Main.cpp @@ -94,7 +94,9 @@ static void EmitClient(const v8::FunctionCallbackInfo& info) for (int i = 0; i < arr->Length(); ++i) { Ref player; - V8Entity* v8Player = V8Entity::Get(arr->Get(ctx, i).ToLocalChecked()); + v8::Local ply; + V8_CHECK(arr->Get(ctx, i).ToLocal(&ply), "Invalid player in emitClient players array"); + V8Entity* v8Player = V8Entity::Get(ply); V8_CHECK(v8Player && v8Player->GetHandle()->GetType() == alt::IBaseObject::Type::PLAYER, "player inside array expected"); targets.Push(v8Player->GetHandle().As()); diff --git a/src/bindings/Player.cpp b/src/bindings/Player.cpp index 27f01895..1a074214 100644 --- a/src/bindings/Player.cpp +++ b/src/bindings/Player.cpp @@ -369,6 +369,18 @@ static void IsEntityInStreamRange(const v8::FunctionCallbackInfo& inf V8_RETURN_BOOLEAN(player->IsEntityInStreamingRange(entity)); } +static void SetIntoVehicle(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(2); + V8_GET_THIS_BASE_OBJECT(player, IPlayer); + + V8_ARG_TO_BASE_OBJECT(1, vehicle, alt::IVehicle, "Vehicle"); + V8_ARG_TO_UINT32(2, seat); + + player->SetIntoVehicle(vehicle, seat); +} + static void AllGetter(v8::Local name, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); @@ -470,4 +482,6 @@ extern V8Class v8Player("Player", v8Entity, nullptr, [](v8::Local Date: Sat, 11 Sep 2021 17:48:16 +0200 Subject: [PATCH 542/564] Remove baseObjectCreate and baseObjectRemove event --- V8ResourceImpl.cpp | 9 --------- V8ResourceImpl.h | 11 ----------- 2 files changed, 20 deletions(-) diff --git a/V8ResourceImpl.cpp b/V8ResourceImpl.cpp index bf29b518..9016c28e 100644 --- a/V8ResourceImpl.cpp +++ b/V8ResourceImpl.cpp @@ -182,13 +182,6 @@ void V8ResourceImpl::OnCreateBaseObject(alt::Ref handle) CreateEntity(handle.Get()); }*/ - v8::Locker locker(isolate); - v8::Isolate::Scope isolateScope(isolate); - v8::HandleScope handleScope(isolate); - v8::Context::Scope scope(GetContext()); - - DispatchBaseObjectCreateEvent(handle); - NotifyPoolUpdate(handle.Get()); } @@ -206,8 +199,6 @@ void V8ResourceImpl::OnRemoveBaseObject(alt::Ref handle) if (!ent) return; - DispatchBaseObjectRemoveEvent(handle); - entities.erase(handle.Get()); // TODO: ent->SetWeak(); diff --git a/V8ResourceImpl.h b/V8ResourceImpl.h index c986c1f8..bed9d0c2 100644 --- a/V8ResourceImpl.h +++ b/V8ResourceImpl.h @@ -131,17 +131,6 @@ class V8ResourceImpl : public alt::IResource::Impl InvokeEventHandlers(nullptr, GetLocalHandlers("resourceError"), args); } - void DispatchBaseObjectCreateEvent(alt::Ref object) - { - std::vector> args = { GetOrCreateEntity(object.Get())->GetJSVal(isolate) }; - InvokeEventHandlers(nullptr, GetLocalHandlers("baseObjectCreate"), args); - } - void DispatchBaseObjectRemoveEvent(alt::Ref object) - { - std::vector> args = { GetOrCreateEntity(object.Get())->GetJSVal(isolate) }; - InvokeEventHandlers(nullptr, GetLocalHandlers("baseObjectRemove"), args); - } - V8Entity *GetEntity(alt::IBaseObject *handle) { auto it = entities.find(handle); From 0033debebaf01db75c26c53fe7e8a85e244e2f0b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 17:48:43 +0200 Subject: [PATCH 543/564] Update helpers Former-commit-id: d0e26928dcc423c96ac538c4478fd734072ea67c --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 3e240b0a..36706536 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 3e240b0af49f2bd9d09a5c09197ce503d4a289ed +Subproject commit 3670653662f3ac42d87e93cd40fd260e487c693d From db7f26aaba882ac453f105b702b76024483dc751 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 17:49:52 +0200 Subject: [PATCH 544/564] Update helpers --- src/helpers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers b/src/helpers index 3e240b0a..36706536 160000 --- a/src/helpers +++ b/src/helpers @@ -1 +1 @@ -Subproject commit 3e240b0af49f2bd9d09a5c09197ce503d4a289ed +Subproject commit 3670653662f3ac42d87e93cd40fd260e487c693d From ee830d4bc5c520380ba875bb042452e7d646955b Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 19:50:59 +0200 Subject: [PATCH 545/564] Initial commit From 53c44dab177bedf469f87ba7d2e81eb5b8d0830c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 19:56:30 +0200 Subject: [PATCH 546/564] Add server Former-commit-id: d1a2e8423ec443bca1edc65c23e79c208e62f101 --- .gitattributes => server/.gitattributes | 0 {.github => server/.github}/ISSUE_TEMPLATE/bug_report.md | 0 {.github => server/.github}/ISSUE_TEMPLATE/feature_request.md | 0 {.github => server/.github}/workflows/build-deploy.yml | 0 {.github => server/.github}/workflows/test-changes.yml | 0 .gitignore => server/.gitignore | 0 .gitmodules => server/.gitmodules | 4 ++-- CMakeLists.txt => server/CMakeLists.txt | 0 LICENSE => server/LICENSE | 0 README.md => server/README.md | 0 build.bat => server/build.bat | 0 build.sh => server/build.sh | 0 {deps => server/deps}/nodejs/deps/uv/include/uv.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/aix.h | 0 .../deps}/nodejs/deps/uv/include/uv/android-ifaddrs.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/bsd.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/darwin.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/errno.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/linux.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/os390.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/posix.h | 0 .../deps}/nodejs/deps/uv/include/uv/stdint-msvc2008.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/sunos.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/threadpool.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/tree.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/unix.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/version.h | 0 {deps => server/deps}/nodejs/deps/uv/include/uv/win.h | 0 {deps => server/deps}/nodejs/deps/v8/include/APIDesign.md | 0 {deps => server/deps}/nodejs/deps/v8/include/DEPS | 0 {deps => server/deps}/nodejs/deps/v8/include/OWNERS | 0 {deps => server/deps}/nodejs/deps/v8/include/cppgc/DEPS | 0 {deps => server/deps}/nodejs/deps/v8/include/cppgc/README.md | 0 .../deps}/nodejs/deps/v8/include/cppgc/allocation.h | 0 {deps => server/deps}/nodejs/deps/v8/include/cppgc/common.h | 0 .../deps}/nodejs/deps/v8/include/cppgc/custom-space.h | 0 .../deps}/nodejs/deps/v8/include/cppgc/garbage-collected.h | 0 {deps => server/deps}/nodejs/deps/v8/include/cppgc/heap.h | 0 .../deps}/nodejs/deps/v8/include/cppgc/internal/accessors.h | 0 .../nodejs/deps/v8/include/cppgc/internal/api-constants.h | 0 .../nodejs/deps/v8/include/cppgc/internal/compiler-specific.h | 0 .../nodejs/deps/v8/include/cppgc/internal/finalizer-trait.h | 0 .../deps}/nodejs/deps/v8/include/cppgc/internal/gc-info.h | 0 .../deps}/nodejs/deps/v8/include/cppgc/internal/logging.h | 0 .../nodejs/deps/v8/include/cppgc/internal/persistent-node.h | 0 .../nodejs/deps/v8/include/cppgc/internal/pointer-policies.h | 0 .../deps/v8/include/cppgc/internal/prefinalizer-handler.h | 0 .../deps}/nodejs/deps/v8/include/cppgc/liveness-broker.h | 0 {deps => server/deps}/nodejs/deps/v8/include/cppgc/macros.h | 0 {deps => server/deps}/nodejs/deps/v8/include/cppgc/member.h | 0 .../deps}/nodejs/deps/v8/include/cppgc/persistent.h | 0 {deps => server/deps}/nodejs/deps/v8/include/cppgc/platform.h | 0 .../deps}/nodejs/deps/v8/include/cppgc/prefinalizer.h | 0 .../deps}/nodejs/deps/v8/include/cppgc/source-location.h | 0 .../deps}/nodejs/deps/v8/include/cppgc/trace-trait.h | 0 .../deps}/nodejs/deps/v8/include/cppgc/type-traits.h | 0 {deps => server/deps}/nodejs/deps/v8/include/cppgc/visitor.h | 0 .../deps}/nodejs/deps/v8/include/js_protocol-1.2.json | 0 .../deps}/nodejs/deps/v8/include/js_protocol-1.3.json | 0 {deps => server/deps}/nodejs/deps/v8/include/js_protocol.pdl | 0 {deps => server/deps}/nodejs/deps/v8/include/libplatform/DEPS | 0 .../nodejs/deps/v8/include/libplatform/libplatform-export.h | 0 .../deps}/nodejs/deps/v8/include/libplatform/libplatform.h | 0 .../deps}/nodejs/deps/v8/include/libplatform/v8-tracing.h | 0 .../deps}/nodejs/deps/v8/include/v8-fast-api-calls.h | 0 .../deps}/nodejs/deps/v8/include/v8-inspector-protocol.h | 0 {deps => server/deps}/nodejs/deps/v8/include/v8-inspector.h | 0 {deps => server/deps}/nodejs/deps/v8/include/v8-internal.h | 0 {deps => server/deps}/nodejs/deps/v8/include/v8-platform.h | 0 {deps => server/deps}/nodejs/deps/v8/include/v8-profiler.h | 0 {deps => server/deps}/nodejs/deps/v8/include/v8-util.h | 0 .../nodejs/deps/v8/include/v8-value-serializer-version.h | 0 .../deps}/nodejs/deps/v8/include/v8-version-string.h | 0 {deps => server/deps}/nodejs/deps/v8/include/v8-version.h | 0 .../deps}/nodejs/deps/v8/include/v8-wasm-trap-handler-posix.h | 0 .../deps}/nodejs/deps/v8/include/v8-wasm-trap-handler-win.h | 0 {deps => server/deps}/nodejs/deps/v8/include/v8.h | 0 {deps => server/deps}/nodejs/deps/v8/include/v8config.h | 0 {deps => server/deps}/nodejs/include/aliased_buffer.h | 0 {deps => server/deps}/nodejs/include/aliased_struct-inl.h | 0 {deps => server/deps}/nodejs/include/aliased_struct.h | 0 {deps => server/deps}/nodejs/include/allocated_buffer-inl.h | 0 {deps => server/deps}/nodejs/include/allocated_buffer.h | 0 {deps => server/deps}/nodejs/include/async_wrap-inl.h | 0 {deps => server/deps}/nodejs/include/async_wrap.h | 0 {deps => server/deps}/nodejs/include/base64-inl.h | 0 {deps => server/deps}/nodejs/include/base64.h | 0 {deps => server/deps}/nodejs/include/base_object-inl.h | 0 {deps => server/deps}/nodejs/include/base_object.h | 0 {deps => server/deps}/nodejs/include/callback_queue-inl.h | 0 {deps => server/deps}/nodejs/include/callback_queue.h | 0 {deps => server/deps}/nodejs/include/connect_wrap.h | 0 {deps => server/deps}/nodejs/include/connection_wrap.h | 0 {deps => server/deps}/nodejs/include/debug_utils-inl.h | 0 {deps => server/deps}/nodejs/include/debug_utils.h | 0 {deps => server/deps}/nodejs/include/diagnosticfilename-inl.h | 0 {deps => server/deps}/nodejs/include/env-inl.h | 0 {deps => server/deps}/nodejs/include/env.h | 0 {deps => server/deps}/nodejs/include/handle_wrap.h | 0 {deps => server/deps}/nodejs/include/histogram-inl.h | 0 {deps => server/deps}/nodejs/include/histogram.h | 0 .../deps}/nodejs/include/inspector/main_thread_interface.h | 0 {deps => server/deps}/nodejs/include/inspector/node_string.h | 0 .../deps}/nodejs/include/inspector/runtime_agent.h | 0 .../deps}/nodejs/include/inspector/tracing_agent.h | 0 {deps => server/deps}/nodejs/include/inspector/worker_agent.h | 0 .../deps}/nodejs/include/inspector/worker_inspector.h | 0 {deps => server/deps}/nodejs/include/inspector_agent.h | 0 {deps => server/deps}/nodejs/include/inspector_io.h | 0 {deps => server/deps}/nodejs/include/inspector_profiler.h | 0 {deps => server/deps}/nodejs/include/inspector_socket.h | 0 .../deps}/nodejs/include/inspector_socket_server.h | 0 {deps => server/deps}/nodejs/include/js_native_api.h | 0 {deps => server/deps}/nodejs/include/js_native_api_types.h | 0 {deps => server/deps}/nodejs/include/js_native_api_v8.h | 0 .../deps}/nodejs/include/js_native_api_v8_internals.h | 0 {deps => server/deps}/nodejs/include/js_stream.h | 0 {deps => server/deps}/nodejs/include/json_utils.h | 0 .../deps}/nodejs/include/large_pages/node_large_page.h | 0 {deps => server/deps}/nodejs/include/memory_tracker-inl.h | 0 {deps => server/deps}/nodejs/include/memory_tracker.h | 0 {deps => server/deps}/nodejs/include/module_wrap.h | 0 {deps => server/deps}/nodejs/include/node.h | 0 {deps => server/deps}/nodejs/include/node_api.h | 0 {deps => server/deps}/nodejs/include/node_api_types.h | 0 {deps => server/deps}/nodejs/include/node_binding.h | 0 {deps => server/deps}/nodejs/include/node_buffer.h | 0 {deps => server/deps}/nodejs/include/node_constants.h | 0 {deps => server/deps}/nodejs/include/node_context_data.h | 0 {deps => server/deps}/nodejs/include/node_contextify.h | 0 {deps => server/deps}/nodejs/include/node_crypto.h | 0 {deps => server/deps}/nodejs/include/node_crypto_bio.h | 0 .../deps}/nodejs/include/node_crypto_clienthello-inl.h | 0 .../deps}/nodejs/include/node_crypto_clienthello.h | 0 {deps => server/deps}/nodejs/include/node_crypto_common.h | 0 {deps => server/deps}/nodejs/include/node_crypto_groups.h | 0 {deps => server/deps}/nodejs/include/node_dir.h | 0 {deps => server/deps}/nodejs/include/node_dtrace.h | 0 {deps => server/deps}/nodejs/include/node_errors.h | 0 {deps => server/deps}/nodejs/include/node_file-inl.h | 0 {deps => server/deps}/nodejs/include/node_file.h | 0 {deps => server/deps}/nodejs/include/node_http2.h | 0 {deps => server/deps}/nodejs/include/node_http2_state.h | 0 {deps => server/deps}/nodejs/include/node_http_common-inl.h | 0 {deps => server/deps}/nodejs/include/node_http_common.h | 0 {deps => server/deps}/nodejs/include/node_i18n.h | 0 {deps => server/deps}/nodejs/include/node_internals.h | 0 {deps => server/deps}/nodejs/include/node_main_instance.h | 0 {deps => server/deps}/nodejs/include/node_mem-inl.h | 0 {deps => server/deps}/nodejs/include/node_mem.h | 0 {deps => server/deps}/nodejs/include/node_messaging.h | 0 {deps => server/deps}/nodejs/include/node_metadata.h | 0 {deps => server/deps}/nodejs/include/node_mutex.h | 0 {deps => server/deps}/nodejs/include/node_native_module.h | 0 {deps => server/deps}/nodejs/include/node_native_module_env.h | 0 {deps => server/deps}/nodejs/include/node_object_wrap.h | 0 {deps => server/deps}/nodejs/include/node_options-inl.h | 0 {deps => server/deps}/nodejs/include/node_options.h | 0 {deps => server/deps}/nodejs/include/node_perf.h | 0 {deps => server/deps}/nodejs/include/node_perf_common.h | 0 {deps => server/deps}/nodejs/include/node_platform.h | 0 {deps => server/deps}/nodejs/include/node_process.h | 0 {deps => server/deps}/nodejs/include/node_report.h | 0 {deps => server/deps}/nodejs/include/node_revert.h | 0 {deps => server/deps}/nodejs/include/node_root_certs.h | 0 {deps => server/deps}/nodejs/include/node_sockaddr-inl.h | 0 {deps => server/deps}/nodejs/include/node_sockaddr.h | 0 {deps => server/deps}/nodejs/include/node_stat_watcher.h | 0 {deps => server/deps}/nodejs/include/node_union_bytes.h | 0 {deps => server/deps}/nodejs/include/node_url.h | 0 {deps => server/deps}/nodejs/include/node_v8_platform-inl.h | 0 {deps => server/deps}/nodejs/include/node_version.h | 0 {deps => server/deps}/nodejs/include/node_wasi.h | 0 {deps => server/deps}/nodejs/include/node_watchdog.h | 0 .../deps}/nodejs/include/node_win32_etw_provider-inl.h | 0 .../deps}/nodejs/include/node_win32_etw_provider.h | 0 {deps => server/deps}/nodejs/include/node_worker.h | 0 {deps => server/deps}/nodejs/include/pipe_wrap.h | 0 {deps => server/deps}/nodejs/include/req_wrap-inl.h | 0 {deps => server/deps}/nodejs/include/req_wrap.h | 0 {deps => server/deps}/nodejs/include/spawn_sync.h | 0 {deps => server/deps}/nodejs/include/stream_base-inl.h | 0 {deps => server/deps}/nodejs/include/stream_base.h | 0 {deps => server/deps}/nodejs/include/stream_pipe.h | 0 {deps => server/deps}/nodejs/include/stream_wrap.h | 0 {deps => server/deps}/nodejs/include/string_bytes.h | 0 {deps => server/deps}/nodejs/include/string_decoder-inl.h | 0 {deps => server/deps}/nodejs/include/string_decoder.h | 0 {deps => server/deps}/nodejs/include/string_search.h | 0 {deps => server/deps}/nodejs/include/tcp_wrap.h | 0 {deps => server/deps}/nodejs/include/threadpoolwork-inl.h | 0 {deps => server/deps}/nodejs/include/tls_wrap.h | 0 {deps => server/deps}/nodejs/include/tracing/agent.h | 0 .../deps}/nodejs/include/tracing/node_trace_buffer.h | 0 .../deps}/nodejs/include/tracing/node_trace_writer.h | 0 {deps => server/deps}/nodejs/include/tracing/trace_event.h | 0 .../deps}/nodejs/include/tracing/trace_event_common.h | 0 {deps => server/deps}/nodejs/include/tracing/traced_value.h | 0 {deps => server/deps}/nodejs/include/tty_wrap.h | 0 {deps => server/deps}/nodejs/include/udp_wrap.h | 0 {deps => server/deps}/nodejs/include/util-inl.h | 0 {deps => server/deps}/nodejs/include/util.h | 0 {deps => server/deps}/nodejs/include/v8abbr.h | 0 generate.bat => server/generate.bat | 0 {src => server/src}/CNodeResourceImpl.cpp | 0 {src => server/src}/CNodeResourceImpl.h | 0 {src => server/src}/CNodeScriptRuntime.cpp | 0 {src => server/src}/CNodeScriptRuntime.h | 0 {src => server/src}/Log.h | 0 {src => server/src}/bindings/Blip.cpp | 0 {src => server/src}/bindings/Checkpoint.cpp | 0 {src => server/src}/bindings/ColShape.cpp | 0 {src => server/src}/bindings/Main.cpp | 0 {src => server/src}/bindings/Player.cpp | 0 {src => server/src}/bindings/Vehicle.cpp | 0 {src => server/src}/bindings/VoiceChannel.cpp | 0 {src => server/src}/bindings/vehicle/Appearance.h | 0 {src => server/src}/bindings/vehicle/Damage.h | 0 {src => server/src}/bindings/vehicle/GameState.h | 0 {src => server/src}/bindings/vehicle/Health.h | 0 {src => server/src}/bindings/vehicle/ScriptGameState.h | 0 {src => server/src}/cpp-sdk | 0 {src => server/src}/events/Main.cpp | 0 {src => server/src}/events/Player.cpp | 0 {src => server/src}/events/Vehicle.cpp | 0 {src => server/src}/helpers | 0 {src => server/src}/node-module.cpp | 0 {src => server/src}/stdafx.h | 0 {tools => server/tools}/altv-v8-tool.exe.REMOVED.git-id | 0 {tools => server/tools}/nodejsdefs.js | 0 230 files changed, 2 insertions(+), 2 deletions(-) rename .gitattributes => server/.gitattributes (100%) rename {.github => server/.github}/ISSUE_TEMPLATE/bug_report.md (100%) rename {.github => server/.github}/ISSUE_TEMPLATE/feature_request.md (100%) rename {.github => server/.github}/workflows/build-deploy.yml (100%) rename {.github => server/.github}/workflows/test-changes.yml (100%) rename .gitignore => server/.gitignore (100%) rename .gitmodules => server/.gitmodules (72%) rename CMakeLists.txt => server/CMakeLists.txt (100%) rename LICENSE => server/LICENSE (100%) rename README.md => server/README.md (100%) rename build.bat => server/build.bat (100%) rename build.sh => server/build.sh (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/aix.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/android-ifaddrs.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/bsd.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/darwin.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/errno.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/linux.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/os390.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/posix.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/stdint-msvc2008.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/sunos.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/threadpool.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/tree.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/unix.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/version.h (100%) rename {deps => server/deps}/nodejs/deps/uv/include/uv/win.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/APIDesign.md (100%) rename {deps => server/deps}/nodejs/deps/v8/include/DEPS (100%) rename {deps => server/deps}/nodejs/deps/v8/include/OWNERS (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/DEPS (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/README.md (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/allocation.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/common.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/custom-space.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/garbage-collected.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/heap.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/internal/accessors.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/internal/api-constants.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/internal/compiler-specific.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/internal/finalizer-trait.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/internal/gc-info.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/internal/logging.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/internal/persistent-node.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/internal/pointer-policies.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/internal/prefinalizer-handler.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/liveness-broker.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/macros.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/member.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/persistent.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/platform.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/prefinalizer.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/source-location.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/trace-trait.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/type-traits.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/cppgc/visitor.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/js_protocol-1.2.json (100%) rename {deps => server/deps}/nodejs/deps/v8/include/js_protocol-1.3.json (100%) rename {deps => server/deps}/nodejs/deps/v8/include/js_protocol.pdl (100%) rename {deps => server/deps}/nodejs/deps/v8/include/libplatform/DEPS (100%) rename {deps => server/deps}/nodejs/deps/v8/include/libplatform/libplatform-export.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/libplatform/libplatform.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/libplatform/v8-tracing.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8-fast-api-calls.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8-inspector-protocol.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8-inspector.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8-internal.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8-platform.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8-profiler.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8-util.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8-value-serializer-version.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8-version-string.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8-version.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8-wasm-trap-handler-posix.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8-wasm-trap-handler-win.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8.h (100%) rename {deps => server/deps}/nodejs/deps/v8/include/v8config.h (100%) rename {deps => server/deps}/nodejs/include/aliased_buffer.h (100%) rename {deps => server/deps}/nodejs/include/aliased_struct-inl.h (100%) rename {deps => server/deps}/nodejs/include/aliased_struct.h (100%) rename {deps => server/deps}/nodejs/include/allocated_buffer-inl.h (100%) rename {deps => server/deps}/nodejs/include/allocated_buffer.h (100%) rename {deps => server/deps}/nodejs/include/async_wrap-inl.h (100%) rename {deps => server/deps}/nodejs/include/async_wrap.h (100%) rename {deps => server/deps}/nodejs/include/base64-inl.h (100%) rename {deps => server/deps}/nodejs/include/base64.h (100%) rename {deps => server/deps}/nodejs/include/base_object-inl.h (100%) rename {deps => server/deps}/nodejs/include/base_object.h (100%) rename {deps => server/deps}/nodejs/include/callback_queue-inl.h (100%) rename {deps => server/deps}/nodejs/include/callback_queue.h (100%) rename {deps => server/deps}/nodejs/include/connect_wrap.h (100%) rename {deps => server/deps}/nodejs/include/connection_wrap.h (100%) rename {deps => server/deps}/nodejs/include/debug_utils-inl.h (100%) rename {deps => server/deps}/nodejs/include/debug_utils.h (100%) rename {deps => server/deps}/nodejs/include/diagnosticfilename-inl.h (100%) rename {deps => server/deps}/nodejs/include/env-inl.h (100%) rename {deps => server/deps}/nodejs/include/env.h (100%) rename {deps => server/deps}/nodejs/include/handle_wrap.h (100%) rename {deps => server/deps}/nodejs/include/histogram-inl.h (100%) rename {deps => server/deps}/nodejs/include/histogram.h (100%) rename {deps => server/deps}/nodejs/include/inspector/main_thread_interface.h (100%) rename {deps => server/deps}/nodejs/include/inspector/node_string.h (100%) rename {deps => server/deps}/nodejs/include/inspector/runtime_agent.h (100%) rename {deps => server/deps}/nodejs/include/inspector/tracing_agent.h (100%) rename {deps => server/deps}/nodejs/include/inspector/worker_agent.h (100%) rename {deps => server/deps}/nodejs/include/inspector/worker_inspector.h (100%) rename {deps => server/deps}/nodejs/include/inspector_agent.h (100%) rename {deps => server/deps}/nodejs/include/inspector_io.h (100%) rename {deps => server/deps}/nodejs/include/inspector_profiler.h (100%) rename {deps => server/deps}/nodejs/include/inspector_socket.h (100%) rename {deps => server/deps}/nodejs/include/inspector_socket_server.h (100%) rename {deps => server/deps}/nodejs/include/js_native_api.h (100%) rename {deps => server/deps}/nodejs/include/js_native_api_types.h (100%) rename {deps => server/deps}/nodejs/include/js_native_api_v8.h (100%) rename {deps => server/deps}/nodejs/include/js_native_api_v8_internals.h (100%) rename {deps => server/deps}/nodejs/include/js_stream.h (100%) rename {deps => server/deps}/nodejs/include/json_utils.h (100%) rename {deps => server/deps}/nodejs/include/large_pages/node_large_page.h (100%) rename {deps => server/deps}/nodejs/include/memory_tracker-inl.h (100%) rename {deps => server/deps}/nodejs/include/memory_tracker.h (100%) rename {deps => server/deps}/nodejs/include/module_wrap.h (100%) rename {deps => server/deps}/nodejs/include/node.h (100%) rename {deps => server/deps}/nodejs/include/node_api.h (100%) rename {deps => server/deps}/nodejs/include/node_api_types.h (100%) rename {deps => server/deps}/nodejs/include/node_binding.h (100%) rename {deps => server/deps}/nodejs/include/node_buffer.h (100%) rename {deps => server/deps}/nodejs/include/node_constants.h (100%) rename {deps => server/deps}/nodejs/include/node_context_data.h (100%) rename {deps => server/deps}/nodejs/include/node_contextify.h (100%) rename {deps => server/deps}/nodejs/include/node_crypto.h (100%) rename {deps => server/deps}/nodejs/include/node_crypto_bio.h (100%) rename {deps => server/deps}/nodejs/include/node_crypto_clienthello-inl.h (100%) rename {deps => server/deps}/nodejs/include/node_crypto_clienthello.h (100%) rename {deps => server/deps}/nodejs/include/node_crypto_common.h (100%) rename {deps => server/deps}/nodejs/include/node_crypto_groups.h (100%) rename {deps => server/deps}/nodejs/include/node_dir.h (100%) rename {deps => server/deps}/nodejs/include/node_dtrace.h (100%) rename {deps => server/deps}/nodejs/include/node_errors.h (100%) rename {deps => server/deps}/nodejs/include/node_file-inl.h (100%) rename {deps => server/deps}/nodejs/include/node_file.h (100%) rename {deps => server/deps}/nodejs/include/node_http2.h (100%) rename {deps => server/deps}/nodejs/include/node_http2_state.h (100%) rename {deps => server/deps}/nodejs/include/node_http_common-inl.h (100%) rename {deps => server/deps}/nodejs/include/node_http_common.h (100%) rename {deps => server/deps}/nodejs/include/node_i18n.h (100%) rename {deps => server/deps}/nodejs/include/node_internals.h (100%) rename {deps => server/deps}/nodejs/include/node_main_instance.h (100%) rename {deps => server/deps}/nodejs/include/node_mem-inl.h (100%) rename {deps => server/deps}/nodejs/include/node_mem.h (100%) rename {deps => server/deps}/nodejs/include/node_messaging.h (100%) rename {deps => server/deps}/nodejs/include/node_metadata.h (100%) rename {deps => server/deps}/nodejs/include/node_mutex.h (100%) rename {deps => server/deps}/nodejs/include/node_native_module.h (100%) rename {deps => server/deps}/nodejs/include/node_native_module_env.h (100%) rename {deps => server/deps}/nodejs/include/node_object_wrap.h (100%) rename {deps => server/deps}/nodejs/include/node_options-inl.h (100%) rename {deps => server/deps}/nodejs/include/node_options.h (100%) rename {deps => server/deps}/nodejs/include/node_perf.h (100%) rename {deps => server/deps}/nodejs/include/node_perf_common.h (100%) rename {deps => server/deps}/nodejs/include/node_platform.h (100%) rename {deps => server/deps}/nodejs/include/node_process.h (100%) rename {deps => server/deps}/nodejs/include/node_report.h (100%) rename {deps => server/deps}/nodejs/include/node_revert.h (100%) rename {deps => server/deps}/nodejs/include/node_root_certs.h (100%) rename {deps => server/deps}/nodejs/include/node_sockaddr-inl.h (100%) rename {deps => server/deps}/nodejs/include/node_sockaddr.h (100%) rename {deps => server/deps}/nodejs/include/node_stat_watcher.h (100%) rename {deps => server/deps}/nodejs/include/node_union_bytes.h (100%) rename {deps => server/deps}/nodejs/include/node_url.h (100%) rename {deps => server/deps}/nodejs/include/node_v8_platform-inl.h (100%) rename {deps => server/deps}/nodejs/include/node_version.h (100%) rename {deps => server/deps}/nodejs/include/node_wasi.h (100%) rename {deps => server/deps}/nodejs/include/node_watchdog.h (100%) rename {deps => server/deps}/nodejs/include/node_win32_etw_provider-inl.h (100%) rename {deps => server/deps}/nodejs/include/node_win32_etw_provider.h (100%) rename {deps => server/deps}/nodejs/include/node_worker.h (100%) rename {deps => server/deps}/nodejs/include/pipe_wrap.h (100%) rename {deps => server/deps}/nodejs/include/req_wrap-inl.h (100%) rename {deps => server/deps}/nodejs/include/req_wrap.h (100%) rename {deps => server/deps}/nodejs/include/spawn_sync.h (100%) rename {deps => server/deps}/nodejs/include/stream_base-inl.h (100%) rename {deps => server/deps}/nodejs/include/stream_base.h (100%) rename {deps => server/deps}/nodejs/include/stream_pipe.h (100%) rename {deps => server/deps}/nodejs/include/stream_wrap.h (100%) rename {deps => server/deps}/nodejs/include/string_bytes.h (100%) rename {deps => server/deps}/nodejs/include/string_decoder-inl.h (100%) rename {deps => server/deps}/nodejs/include/string_decoder.h (100%) rename {deps => server/deps}/nodejs/include/string_search.h (100%) rename {deps => server/deps}/nodejs/include/tcp_wrap.h (100%) rename {deps => server/deps}/nodejs/include/threadpoolwork-inl.h (100%) rename {deps => server/deps}/nodejs/include/tls_wrap.h (100%) rename {deps => server/deps}/nodejs/include/tracing/agent.h (100%) rename {deps => server/deps}/nodejs/include/tracing/node_trace_buffer.h (100%) rename {deps => server/deps}/nodejs/include/tracing/node_trace_writer.h (100%) rename {deps => server/deps}/nodejs/include/tracing/trace_event.h (100%) rename {deps => server/deps}/nodejs/include/tracing/trace_event_common.h (100%) rename {deps => server/deps}/nodejs/include/tracing/traced_value.h (100%) rename {deps => server/deps}/nodejs/include/tty_wrap.h (100%) rename {deps => server/deps}/nodejs/include/udp_wrap.h (100%) rename {deps => server/deps}/nodejs/include/util-inl.h (100%) rename {deps => server/deps}/nodejs/include/util.h (100%) rename {deps => server/deps}/nodejs/include/v8abbr.h (100%) rename generate.bat => server/generate.bat (100%) rename {src => server/src}/CNodeResourceImpl.cpp (100%) rename {src => server/src}/CNodeResourceImpl.h (100%) rename {src => server/src}/CNodeScriptRuntime.cpp (100%) rename {src => server/src}/CNodeScriptRuntime.h (100%) rename {src => server/src}/Log.h (100%) rename {src => server/src}/bindings/Blip.cpp (100%) rename {src => server/src}/bindings/Checkpoint.cpp (100%) rename {src => server/src}/bindings/ColShape.cpp (100%) rename {src => server/src}/bindings/Main.cpp (100%) rename {src => server/src}/bindings/Player.cpp (100%) rename {src => server/src}/bindings/Vehicle.cpp (100%) rename {src => server/src}/bindings/VoiceChannel.cpp (100%) rename {src => server/src}/bindings/vehicle/Appearance.h (100%) rename {src => server/src}/bindings/vehicle/Damage.h (100%) rename {src => server/src}/bindings/vehicle/GameState.h (100%) rename {src => server/src}/bindings/vehicle/Health.h (100%) rename {src => server/src}/bindings/vehicle/ScriptGameState.h (100%) rename {src => server/src}/cpp-sdk (100%) rename {src => server/src}/events/Main.cpp (100%) rename {src => server/src}/events/Player.cpp (100%) rename {src => server/src}/events/Vehicle.cpp (100%) rename {src => server/src}/helpers (100%) rename {src => server/src}/node-module.cpp (100%) rename {src => server/src}/stdafx.h (100%) rename {tools => server/tools}/altv-v8-tool.exe.REMOVED.git-id (100%) rename {tools => server/tools}/nodejsdefs.js (100%) diff --git a/.gitattributes b/server/.gitattributes similarity index 100% rename from .gitattributes rename to server/.gitattributes diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/server/.github/ISSUE_TEMPLATE/bug_report.md similarity index 100% rename from .github/ISSUE_TEMPLATE/bug_report.md rename to server/.github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/server/.github/ISSUE_TEMPLATE/feature_request.md similarity index 100% rename from .github/ISSUE_TEMPLATE/feature_request.md rename to server/.github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/workflows/build-deploy.yml b/server/.github/workflows/build-deploy.yml similarity index 100% rename from .github/workflows/build-deploy.yml rename to server/.github/workflows/build-deploy.yml diff --git a/.github/workflows/test-changes.yml b/server/.github/workflows/test-changes.yml similarity index 100% rename from .github/workflows/test-changes.yml rename to server/.github/workflows/test-changes.yml diff --git a/.gitignore b/server/.gitignore similarity index 100% rename from .gitignore rename to server/.gitignore diff --git a/.gitmodules b/server/.gitmodules similarity index 72% rename from .gitmodules rename to server/.gitmodules index 0b7b9532..9d9c47af 100644 --- a/.gitmodules +++ b/server/.gitmodules @@ -1,6 +1,6 @@ [submodule "src/helpers"] - path = src/helpers + path = server/src/helpers url = https://github.com/altmp/v8-helpers.git [submodule "src/cpp-sdk"] - path = src/cpp-sdk + path = server/src/cpp-sdk url = https://github.com/altmp/cpp-sdk.git diff --git a/CMakeLists.txt b/server/CMakeLists.txt similarity index 100% rename from CMakeLists.txt rename to server/CMakeLists.txt diff --git a/LICENSE b/server/LICENSE similarity index 100% rename from LICENSE rename to server/LICENSE diff --git a/README.md b/server/README.md similarity index 100% rename from README.md rename to server/README.md diff --git a/build.bat b/server/build.bat similarity index 100% rename from build.bat rename to server/build.bat diff --git a/build.sh b/server/build.sh similarity index 100% rename from build.sh rename to server/build.sh diff --git a/deps/nodejs/deps/uv/include/uv.h b/server/deps/nodejs/deps/uv/include/uv.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv.h rename to server/deps/nodejs/deps/uv/include/uv.h diff --git a/deps/nodejs/deps/uv/include/uv/aix.h b/server/deps/nodejs/deps/uv/include/uv/aix.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/aix.h rename to server/deps/nodejs/deps/uv/include/uv/aix.h diff --git a/deps/nodejs/deps/uv/include/uv/android-ifaddrs.h b/server/deps/nodejs/deps/uv/include/uv/android-ifaddrs.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/android-ifaddrs.h rename to server/deps/nodejs/deps/uv/include/uv/android-ifaddrs.h diff --git a/deps/nodejs/deps/uv/include/uv/bsd.h b/server/deps/nodejs/deps/uv/include/uv/bsd.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/bsd.h rename to server/deps/nodejs/deps/uv/include/uv/bsd.h diff --git a/deps/nodejs/deps/uv/include/uv/darwin.h b/server/deps/nodejs/deps/uv/include/uv/darwin.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/darwin.h rename to server/deps/nodejs/deps/uv/include/uv/darwin.h diff --git a/deps/nodejs/deps/uv/include/uv/errno.h b/server/deps/nodejs/deps/uv/include/uv/errno.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/errno.h rename to server/deps/nodejs/deps/uv/include/uv/errno.h diff --git a/deps/nodejs/deps/uv/include/uv/linux.h b/server/deps/nodejs/deps/uv/include/uv/linux.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/linux.h rename to server/deps/nodejs/deps/uv/include/uv/linux.h diff --git a/deps/nodejs/deps/uv/include/uv/os390.h b/server/deps/nodejs/deps/uv/include/uv/os390.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/os390.h rename to server/deps/nodejs/deps/uv/include/uv/os390.h diff --git a/deps/nodejs/deps/uv/include/uv/posix.h b/server/deps/nodejs/deps/uv/include/uv/posix.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/posix.h rename to server/deps/nodejs/deps/uv/include/uv/posix.h diff --git a/deps/nodejs/deps/uv/include/uv/stdint-msvc2008.h b/server/deps/nodejs/deps/uv/include/uv/stdint-msvc2008.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/stdint-msvc2008.h rename to server/deps/nodejs/deps/uv/include/uv/stdint-msvc2008.h diff --git a/deps/nodejs/deps/uv/include/uv/sunos.h b/server/deps/nodejs/deps/uv/include/uv/sunos.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/sunos.h rename to server/deps/nodejs/deps/uv/include/uv/sunos.h diff --git a/deps/nodejs/deps/uv/include/uv/threadpool.h b/server/deps/nodejs/deps/uv/include/uv/threadpool.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/threadpool.h rename to server/deps/nodejs/deps/uv/include/uv/threadpool.h diff --git a/deps/nodejs/deps/uv/include/uv/tree.h b/server/deps/nodejs/deps/uv/include/uv/tree.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/tree.h rename to server/deps/nodejs/deps/uv/include/uv/tree.h diff --git a/deps/nodejs/deps/uv/include/uv/unix.h b/server/deps/nodejs/deps/uv/include/uv/unix.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/unix.h rename to server/deps/nodejs/deps/uv/include/uv/unix.h diff --git a/deps/nodejs/deps/uv/include/uv/version.h b/server/deps/nodejs/deps/uv/include/uv/version.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/version.h rename to server/deps/nodejs/deps/uv/include/uv/version.h diff --git a/deps/nodejs/deps/uv/include/uv/win.h b/server/deps/nodejs/deps/uv/include/uv/win.h similarity index 100% rename from deps/nodejs/deps/uv/include/uv/win.h rename to server/deps/nodejs/deps/uv/include/uv/win.h diff --git a/deps/nodejs/deps/v8/include/APIDesign.md b/server/deps/nodejs/deps/v8/include/APIDesign.md similarity index 100% rename from deps/nodejs/deps/v8/include/APIDesign.md rename to server/deps/nodejs/deps/v8/include/APIDesign.md diff --git a/deps/nodejs/deps/v8/include/DEPS b/server/deps/nodejs/deps/v8/include/DEPS similarity index 100% rename from deps/nodejs/deps/v8/include/DEPS rename to server/deps/nodejs/deps/v8/include/DEPS diff --git a/deps/nodejs/deps/v8/include/OWNERS b/server/deps/nodejs/deps/v8/include/OWNERS similarity index 100% rename from deps/nodejs/deps/v8/include/OWNERS rename to server/deps/nodejs/deps/v8/include/OWNERS diff --git a/deps/nodejs/deps/v8/include/cppgc/DEPS b/server/deps/nodejs/deps/v8/include/cppgc/DEPS similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/DEPS rename to server/deps/nodejs/deps/v8/include/cppgc/DEPS diff --git a/deps/nodejs/deps/v8/include/cppgc/README.md b/server/deps/nodejs/deps/v8/include/cppgc/README.md similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/README.md rename to server/deps/nodejs/deps/v8/include/cppgc/README.md diff --git a/deps/nodejs/deps/v8/include/cppgc/allocation.h b/server/deps/nodejs/deps/v8/include/cppgc/allocation.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/allocation.h rename to server/deps/nodejs/deps/v8/include/cppgc/allocation.h diff --git a/deps/nodejs/deps/v8/include/cppgc/common.h b/server/deps/nodejs/deps/v8/include/cppgc/common.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/common.h rename to server/deps/nodejs/deps/v8/include/cppgc/common.h diff --git a/deps/nodejs/deps/v8/include/cppgc/custom-space.h b/server/deps/nodejs/deps/v8/include/cppgc/custom-space.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/custom-space.h rename to server/deps/nodejs/deps/v8/include/cppgc/custom-space.h diff --git a/deps/nodejs/deps/v8/include/cppgc/garbage-collected.h b/server/deps/nodejs/deps/v8/include/cppgc/garbage-collected.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/garbage-collected.h rename to server/deps/nodejs/deps/v8/include/cppgc/garbage-collected.h diff --git a/deps/nodejs/deps/v8/include/cppgc/heap.h b/server/deps/nodejs/deps/v8/include/cppgc/heap.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/heap.h rename to server/deps/nodejs/deps/v8/include/cppgc/heap.h diff --git a/deps/nodejs/deps/v8/include/cppgc/internal/accessors.h b/server/deps/nodejs/deps/v8/include/cppgc/internal/accessors.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/internal/accessors.h rename to server/deps/nodejs/deps/v8/include/cppgc/internal/accessors.h diff --git a/deps/nodejs/deps/v8/include/cppgc/internal/api-constants.h b/server/deps/nodejs/deps/v8/include/cppgc/internal/api-constants.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/internal/api-constants.h rename to server/deps/nodejs/deps/v8/include/cppgc/internal/api-constants.h diff --git a/deps/nodejs/deps/v8/include/cppgc/internal/compiler-specific.h b/server/deps/nodejs/deps/v8/include/cppgc/internal/compiler-specific.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/internal/compiler-specific.h rename to server/deps/nodejs/deps/v8/include/cppgc/internal/compiler-specific.h diff --git a/deps/nodejs/deps/v8/include/cppgc/internal/finalizer-trait.h b/server/deps/nodejs/deps/v8/include/cppgc/internal/finalizer-trait.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/internal/finalizer-trait.h rename to server/deps/nodejs/deps/v8/include/cppgc/internal/finalizer-trait.h diff --git a/deps/nodejs/deps/v8/include/cppgc/internal/gc-info.h b/server/deps/nodejs/deps/v8/include/cppgc/internal/gc-info.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/internal/gc-info.h rename to server/deps/nodejs/deps/v8/include/cppgc/internal/gc-info.h diff --git a/deps/nodejs/deps/v8/include/cppgc/internal/logging.h b/server/deps/nodejs/deps/v8/include/cppgc/internal/logging.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/internal/logging.h rename to server/deps/nodejs/deps/v8/include/cppgc/internal/logging.h diff --git a/deps/nodejs/deps/v8/include/cppgc/internal/persistent-node.h b/server/deps/nodejs/deps/v8/include/cppgc/internal/persistent-node.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/internal/persistent-node.h rename to server/deps/nodejs/deps/v8/include/cppgc/internal/persistent-node.h diff --git a/deps/nodejs/deps/v8/include/cppgc/internal/pointer-policies.h b/server/deps/nodejs/deps/v8/include/cppgc/internal/pointer-policies.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/internal/pointer-policies.h rename to server/deps/nodejs/deps/v8/include/cppgc/internal/pointer-policies.h diff --git a/deps/nodejs/deps/v8/include/cppgc/internal/prefinalizer-handler.h b/server/deps/nodejs/deps/v8/include/cppgc/internal/prefinalizer-handler.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/internal/prefinalizer-handler.h rename to server/deps/nodejs/deps/v8/include/cppgc/internal/prefinalizer-handler.h diff --git a/deps/nodejs/deps/v8/include/cppgc/liveness-broker.h b/server/deps/nodejs/deps/v8/include/cppgc/liveness-broker.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/liveness-broker.h rename to server/deps/nodejs/deps/v8/include/cppgc/liveness-broker.h diff --git a/deps/nodejs/deps/v8/include/cppgc/macros.h b/server/deps/nodejs/deps/v8/include/cppgc/macros.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/macros.h rename to server/deps/nodejs/deps/v8/include/cppgc/macros.h diff --git a/deps/nodejs/deps/v8/include/cppgc/member.h b/server/deps/nodejs/deps/v8/include/cppgc/member.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/member.h rename to server/deps/nodejs/deps/v8/include/cppgc/member.h diff --git a/deps/nodejs/deps/v8/include/cppgc/persistent.h b/server/deps/nodejs/deps/v8/include/cppgc/persistent.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/persistent.h rename to server/deps/nodejs/deps/v8/include/cppgc/persistent.h diff --git a/deps/nodejs/deps/v8/include/cppgc/platform.h b/server/deps/nodejs/deps/v8/include/cppgc/platform.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/platform.h rename to server/deps/nodejs/deps/v8/include/cppgc/platform.h diff --git a/deps/nodejs/deps/v8/include/cppgc/prefinalizer.h b/server/deps/nodejs/deps/v8/include/cppgc/prefinalizer.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/prefinalizer.h rename to server/deps/nodejs/deps/v8/include/cppgc/prefinalizer.h diff --git a/deps/nodejs/deps/v8/include/cppgc/source-location.h b/server/deps/nodejs/deps/v8/include/cppgc/source-location.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/source-location.h rename to server/deps/nodejs/deps/v8/include/cppgc/source-location.h diff --git a/deps/nodejs/deps/v8/include/cppgc/trace-trait.h b/server/deps/nodejs/deps/v8/include/cppgc/trace-trait.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/trace-trait.h rename to server/deps/nodejs/deps/v8/include/cppgc/trace-trait.h diff --git a/deps/nodejs/deps/v8/include/cppgc/type-traits.h b/server/deps/nodejs/deps/v8/include/cppgc/type-traits.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/type-traits.h rename to server/deps/nodejs/deps/v8/include/cppgc/type-traits.h diff --git a/deps/nodejs/deps/v8/include/cppgc/visitor.h b/server/deps/nodejs/deps/v8/include/cppgc/visitor.h similarity index 100% rename from deps/nodejs/deps/v8/include/cppgc/visitor.h rename to server/deps/nodejs/deps/v8/include/cppgc/visitor.h diff --git a/deps/nodejs/deps/v8/include/js_protocol-1.2.json b/server/deps/nodejs/deps/v8/include/js_protocol-1.2.json similarity index 100% rename from deps/nodejs/deps/v8/include/js_protocol-1.2.json rename to server/deps/nodejs/deps/v8/include/js_protocol-1.2.json diff --git a/deps/nodejs/deps/v8/include/js_protocol-1.3.json b/server/deps/nodejs/deps/v8/include/js_protocol-1.3.json similarity index 100% rename from deps/nodejs/deps/v8/include/js_protocol-1.3.json rename to server/deps/nodejs/deps/v8/include/js_protocol-1.3.json diff --git a/deps/nodejs/deps/v8/include/js_protocol.pdl b/server/deps/nodejs/deps/v8/include/js_protocol.pdl similarity index 100% rename from deps/nodejs/deps/v8/include/js_protocol.pdl rename to server/deps/nodejs/deps/v8/include/js_protocol.pdl diff --git a/deps/nodejs/deps/v8/include/libplatform/DEPS b/server/deps/nodejs/deps/v8/include/libplatform/DEPS similarity index 100% rename from deps/nodejs/deps/v8/include/libplatform/DEPS rename to server/deps/nodejs/deps/v8/include/libplatform/DEPS diff --git a/deps/nodejs/deps/v8/include/libplatform/libplatform-export.h b/server/deps/nodejs/deps/v8/include/libplatform/libplatform-export.h similarity index 100% rename from deps/nodejs/deps/v8/include/libplatform/libplatform-export.h rename to server/deps/nodejs/deps/v8/include/libplatform/libplatform-export.h diff --git a/deps/nodejs/deps/v8/include/libplatform/libplatform.h b/server/deps/nodejs/deps/v8/include/libplatform/libplatform.h similarity index 100% rename from deps/nodejs/deps/v8/include/libplatform/libplatform.h rename to server/deps/nodejs/deps/v8/include/libplatform/libplatform.h diff --git a/deps/nodejs/deps/v8/include/libplatform/v8-tracing.h b/server/deps/nodejs/deps/v8/include/libplatform/v8-tracing.h similarity index 100% rename from deps/nodejs/deps/v8/include/libplatform/v8-tracing.h rename to server/deps/nodejs/deps/v8/include/libplatform/v8-tracing.h diff --git a/deps/nodejs/deps/v8/include/v8-fast-api-calls.h b/server/deps/nodejs/deps/v8/include/v8-fast-api-calls.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8-fast-api-calls.h rename to server/deps/nodejs/deps/v8/include/v8-fast-api-calls.h diff --git a/deps/nodejs/deps/v8/include/v8-inspector-protocol.h b/server/deps/nodejs/deps/v8/include/v8-inspector-protocol.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8-inspector-protocol.h rename to server/deps/nodejs/deps/v8/include/v8-inspector-protocol.h diff --git a/deps/nodejs/deps/v8/include/v8-inspector.h b/server/deps/nodejs/deps/v8/include/v8-inspector.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8-inspector.h rename to server/deps/nodejs/deps/v8/include/v8-inspector.h diff --git a/deps/nodejs/deps/v8/include/v8-internal.h b/server/deps/nodejs/deps/v8/include/v8-internal.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8-internal.h rename to server/deps/nodejs/deps/v8/include/v8-internal.h diff --git a/deps/nodejs/deps/v8/include/v8-platform.h b/server/deps/nodejs/deps/v8/include/v8-platform.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8-platform.h rename to server/deps/nodejs/deps/v8/include/v8-platform.h diff --git a/deps/nodejs/deps/v8/include/v8-profiler.h b/server/deps/nodejs/deps/v8/include/v8-profiler.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8-profiler.h rename to server/deps/nodejs/deps/v8/include/v8-profiler.h diff --git a/deps/nodejs/deps/v8/include/v8-util.h b/server/deps/nodejs/deps/v8/include/v8-util.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8-util.h rename to server/deps/nodejs/deps/v8/include/v8-util.h diff --git a/deps/nodejs/deps/v8/include/v8-value-serializer-version.h b/server/deps/nodejs/deps/v8/include/v8-value-serializer-version.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8-value-serializer-version.h rename to server/deps/nodejs/deps/v8/include/v8-value-serializer-version.h diff --git a/deps/nodejs/deps/v8/include/v8-version-string.h b/server/deps/nodejs/deps/v8/include/v8-version-string.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8-version-string.h rename to server/deps/nodejs/deps/v8/include/v8-version-string.h diff --git a/deps/nodejs/deps/v8/include/v8-version.h b/server/deps/nodejs/deps/v8/include/v8-version.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8-version.h rename to server/deps/nodejs/deps/v8/include/v8-version.h diff --git a/deps/nodejs/deps/v8/include/v8-wasm-trap-handler-posix.h b/server/deps/nodejs/deps/v8/include/v8-wasm-trap-handler-posix.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8-wasm-trap-handler-posix.h rename to server/deps/nodejs/deps/v8/include/v8-wasm-trap-handler-posix.h diff --git a/deps/nodejs/deps/v8/include/v8-wasm-trap-handler-win.h b/server/deps/nodejs/deps/v8/include/v8-wasm-trap-handler-win.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8-wasm-trap-handler-win.h rename to server/deps/nodejs/deps/v8/include/v8-wasm-trap-handler-win.h diff --git a/deps/nodejs/deps/v8/include/v8.h b/server/deps/nodejs/deps/v8/include/v8.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8.h rename to server/deps/nodejs/deps/v8/include/v8.h diff --git a/deps/nodejs/deps/v8/include/v8config.h b/server/deps/nodejs/deps/v8/include/v8config.h similarity index 100% rename from deps/nodejs/deps/v8/include/v8config.h rename to server/deps/nodejs/deps/v8/include/v8config.h diff --git a/deps/nodejs/include/aliased_buffer.h b/server/deps/nodejs/include/aliased_buffer.h similarity index 100% rename from deps/nodejs/include/aliased_buffer.h rename to server/deps/nodejs/include/aliased_buffer.h diff --git a/deps/nodejs/include/aliased_struct-inl.h b/server/deps/nodejs/include/aliased_struct-inl.h similarity index 100% rename from deps/nodejs/include/aliased_struct-inl.h rename to server/deps/nodejs/include/aliased_struct-inl.h diff --git a/deps/nodejs/include/aliased_struct.h b/server/deps/nodejs/include/aliased_struct.h similarity index 100% rename from deps/nodejs/include/aliased_struct.h rename to server/deps/nodejs/include/aliased_struct.h diff --git a/deps/nodejs/include/allocated_buffer-inl.h b/server/deps/nodejs/include/allocated_buffer-inl.h similarity index 100% rename from deps/nodejs/include/allocated_buffer-inl.h rename to server/deps/nodejs/include/allocated_buffer-inl.h diff --git a/deps/nodejs/include/allocated_buffer.h b/server/deps/nodejs/include/allocated_buffer.h similarity index 100% rename from deps/nodejs/include/allocated_buffer.h rename to server/deps/nodejs/include/allocated_buffer.h diff --git a/deps/nodejs/include/async_wrap-inl.h b/server/deps/nodejs/include/async_wrap-inl.h similarity index 100% rename from deps/nodejs/include/async_wrap-inl.h rename to server/deps/nodejs/include/async_wrap-inl.h diff --git a/deps/nodejs/include/async_wrap.h b/server/deps/nodejs/include/async_wrap.h similarity index 100% rename from deps/nodejs/include/async_wrap.h rename to server/deps/nodejs/include/async_wrap.h diff --git a/deps/nodejs/include/base64-inl.h b/server/deps/nodejs/include/base64-inl.h similarity index 100% rename from deps/nodejs/include/base64-inl.h rename to server/deps/nodejs/include/base64-inl.h diff --git a/deps/nodejs/include/base64.h b/server/deps/nodejs/include/base64.h similarity index 100% rename from deps/nodejs/include/base64.h rename to server/deps/nodejs/include/base64.h diff --git a/deps/nodejs/include/base_object-inl.h b/server/deps/nodejs/include/base_object-inl.h similarity index 100% rename from deps/nodejs/include/base_object-inl.h rename to server/deps/nodejs/include/base_object-inl.h diff --git a/deps/nodejs/include/base_object.h b/server/deps/nodejs/include/base_object.h similarity index 100% rename from deps/nodejs/include/base_object.h rename to server/deps/nodejs/include/base_object.h diff --git a/deps/nodejs/include/callback_queue-inl.h b/server/deps/nodejs/include/callback_queue-inl.h similarity index 100% rename from deps/nodejs/include/callback_queue-inl.h rename to server/deps/nodejs/include/callback_queue-inl.h diff --git a/deps/nodejs/include/callback_queue.h b/server/deps/nodejs/include/callback_queue.h similarity index 100% rename from deps/nodejs/include/callback_queue.h rename to server/deps/nodejs/include/callback_queue.h diff --git a/deps/nodejs/include/connect_wrap.h b/server/deps/nodejs/include/connect_wrap.h similarity index 100% rename from deps/nodejs/include/connect_wrap.h rename to server/deps/nodejs/include/connect_wrap.h diff --git a/deps/nodejs/include/connection_wrap.h b/server/deps/nodejs/include/connection_wrap.h similarity index 100% rename from deps/nodejs/include/connection_wrap.h rename to server/deps/nodejs/include/connection_wrap.h diff --git a/deps/nodejs/include/debug_utils-inl.h b/server/deps/nodejs/include/debug_utils-inl.h similarity index 100% rename from deps/nodejs/include/debug_utils-inl.h rename to server/deps/nodejs/include/debug_utils-inl.h diff --git a/deps/nodejs/include/debug_utils.h b/server/deps/nodejs/include/debug_utils.h similarity index 100% rename from deps/nodejs/include/debug_utils.h rename to server/deps/nodejs/include/debug_utils.h diff --git a/deps/nodejs/include/diagnosticfilename-inl.h b/server/deps/nodejs/include/diagnosticfilename-inl.h similarity index 100% rename from deps/nodejs/include/diagnosticfilename-inl.h rename to server/deps/nodejs/include/diagnosticfilename-inl.h diff --git a/deps/nodejs/include/env-inl.h b/server/deps/nodejs/include/env-inl.h similarity index 100% rename from deps/nodejs/include/env-inl.h rename to server/deps/nodejs/include/env-inl.h diff --git a/deps/nodejs/include/env.h b/server/deps/nodejs/include/env.h similarity index 100% rename from deps/nodejs/include/env.h rename to server/deps/nodejs/include/env.h diff --git a/deps/nodejs/include/handle_wrap.h b/server/deps/nodejs/include/handle_wrap.h similarity index 100% rename from deps/nodejs/include/handle_wrap.h rename to server/deps/nodejs/include/handle_wrap.h diff --git a/deps/nodejs/include/histogram-inl.h b/server/deps/nodejs/include/histogram-inl.h similarity index 100% rename from deps/nodejs/include/histogram-inl.h rename to server/deps/nodejs/include/histogram-inl.h diff --git a/deps/nodejs/include/histogram.h b/server/deps/nodejs/include/histogram.h similarity index 100% rename from deps/nodejs/include/histogram.h rename to server/deps/nodejs/include/histogram.h diff --git a/deps/nodejs/include/inspector/main_thread_interface.h b/server/deps/nodejs/include/inspector/main_thread_interface.h similarity index 100% rename from deps/nodejs/include/inspector/main_thread_interface.h rename to server/deps/nodejs/include/inspector/main_thread_interface.h diff --git a/deps/nodejs/include/inspector/node_string.h b/server/deps/nodejs/include/inspector/node_string.h similarity index 100% rename from deps/nodejs/include/inspector/node_string.h rename to server/deps/nodejs/include/inspector/node_string.h diff --git a/deps/nodejs/include/inspector/runtime_agent.h b/server/deps/nodejs/include/inspector/runtime_agent.h similarity index 100% rename from deps/nodejs/include/inspector/runtime_agent.h rename to server/deps/nodejs/include/inspector/runtime_agent.h diff --git a/deps/nodejs/include/inspector/tracing_agent.h b/server/deps/nodejs/include/inspector/tracing_agent.h similarity index 100% rename from deps/nodejs/include/inspector/tracing_agent.h rename to server/deps/nodejs/include/inspector/tracing_agent.h diff --git a/deps/nodejs/include/inspector/worker_agent.h b/server/deps/nodejs/include/inspector/worker_agent.h similarity index 100% rename from deps/nodejs/include/inspector/worker_agent.h rename to server/deps/nodejs/include/inspector/worker_agent.h diff --git a/deps/nodejs/include/inspector/worker_inspector.h b/server/deps/nodejs/include/inspector/worker_inspector.h similarity index 100% rename from deps/nodejs/include/inspector/worker_inspector.h rename to server/deps/nodejs/include/inspector/worker_inspector.h diff --git a/deps/nodejs/include/inspector_agent.h b/server/deps/nodejs/include/inspector_agent.h similarity index 100% rename from deps/nodejs/include/inspector_agent.h rename to server/deps/nodejs/include/inspector_agent.h diff --git a/deps/nodejs/include/inspector_io.h b/server/deps/nodejs/include/inspector_io.h similarity index 100% rename from deps/nodejs/include/inspector_io.h rename to server/deps/nodejs/include/inspector_io.h diff --git a/deps/nodejs/include/inspector_profiler.h b/server/deps/nodejs/include/inspector_profiler.h similarity index 100% rename from deps/nodejs/include/inspector_profiler.h rename to server/deps/nodejs/include/inspector_profiler.h diff --git a/deps/nodejs/include/inspector_socket.h b/server/deps/nodejs/include/inspector_socket.h similarity index 100% rename from deps/nodejs/include/inspector_socket.h rename to server/deps/nodejs/include/inspector_socket.h diff --git a/deps/nodejs/include/inspector_socket_server.h b/server/deps/nodejs/include/inspector_socket_server.h similarity index 100% rename from deps/nodejs/include/inspector_socket_server.h rename to server/deps/nodejs/include/inspector_socket_server.h diff --git a/deps/nodejs/include/js_native_api.h b/server/deps/nodejs/include/js_native_api.h similarity index 100% rename from deps/nodejs/include/js_native_api.h rename to server/deps/nodejs/include/js_native_api.h diff --git a/deps/nodejs/include/js_native_api_types.h b/server/deps/nodejs/include/js_native_api_types.h similarity index 100% rename from deps/nodejs/include/js_native_api_types.h rename to server/deps/nodejs/include/js_native_api_types.h diff --git a/deps/nodejs/include/js_native_api_v8.h b/server/deps/nodejs/include/js_native_api_v8.h similarity index 100% rename from deps/nodejs/include/js_native_api_v8.h rename to server/deps/nodejs/include/js_native_api_v8.h diff --git a/deps/nodejs/include/js_native_api_v8_internals.h b/server/deps/nodejs/include/js_native_api_v8_internals.h similarity index 100% rename from deps/nodejs/include/js_native_api_v8_internals.h rename to server/deps/nodejs/include/js_native_api_v8_internals.h diff --git a/deps/nodejs/include/js_stream.h b/server/deps/nodejs/include/js_stream.h similarity index 100% rename from deps/nodejs/include/js_stream.h rename to server/deps/nodejs/include/js_stream.h diff --git a/deps/nodejs/include/json_utils.h b/server/deps/nodejs/include/json_utils.h similarity index 100% rename from deps/nodejs/include/json_utils.h rename to server/deps/nodejs/include/json_utils.h diff --git a/deps/nodejs/include/large_pages/node_large_page.h b/server/deps/nodejs/include/large_pages/node_large_page.h similarity index 100% rename from deps/nodejs/include/large_pages/node_large_page.h rename to server/deps/nodejs/include/large_pages/node_large_page.h diff --git a/deps/nodejs/include/memory_tracker-inl.h b/server/deps/nodejs/include/memory_tracker-inl.h similarity index 100% rename from deps/nodejs/include/memory_tracker-inl.h rename to server/deps/nodejs/include/memory_tracker-inl.h diff --git a/deps/nodejs/include/memory_tracker.h b/server/deps/nodejs/include/memory_tracker.h similarity index 100% rename from deps/nodejs/include/memory_tracker.h rename to server/deps/nodejs/include/memory_tracker.h diff --git a/deps/nodejs/include/module_wrap.h b/server/deps/nodejs/include/module_wrap.h similarity index 100% rename from deps/nodejs/include/module_wrap.h rename to server/deps/nodejs/include/module_wrap.h diff --git a/deps/nodejs/include/node.h b/server/deps/nodejs/include/node.h similarity index 100% rename from deps/nodejs/include/node.h rename to server/deps/nodejs/include/node.h diff --git a/deps/nodejs/include/node_api.h b/server/deps/nodejs/include/node_api.h similarity index 100% rename from deps/nodejs/include/node_api.h rename to server/deps/nodejs/include/node_api.h diff --git a/deps/nodejs/include/node_api_types.h b/server/deps/nodejs/include/node_api_types.h similarity index 100% rename from deps/nodejs/include/node_api_types.h rename to server/deps/nodejs/include/node_api_types.h diff --git a/deps/nodejs/include/node_binding.h b/server/deps/nodejs/include/node_binding.h similarity index 100% rename from deps/nodejs/include/node_binding.h rename to server/deps/nodejs/include/node_binding.h diff --git a/deps/nodejs/include/node_buffer.h b/server/deps/nodejs/include/node_buffer.h similarity index 100% rename from deps/nodejs/include/node_buffer.h rename to server/deps/nodejs/include/node_buffer.h diff --git a/deps/nodejs/include/node_constants.h b/server/deps/nodejs/include/node_constants.h similarity index 100% rename from deps/nodejs/include/node_constants.h rename to server/deps/nodejs/include/node_constants.h diff --git a/deps/nodejs/include/node_context_data.h b/server/deps/nodejs/include/node_context_data.h similarity index 100% rename from deps/nodejs/include/node_context_data.h rename to server/deps/nodejs/include/node_context_data.h diff --git a/deps/nodejs/include/node_contextify.h b/server/deps/nodejs/include/node_contextify.h similarity index 100% rename from deps/nodejs/include/node_contextify.h rename to server/deps/nodejs/include/node_contextify.h diff --git a/deps/nodejs/include/node_crypto.h b/server/deps/nodejs/include/node_crypto.h similarity index 100% rename from deps/nodejs/include/node_crypto.h rename to server/deps/nodejs/include/node_crypto.h diff --git a/deps/nodejs/include/node_crypto_bio.h b/server/deps/nodejs/include/node_crypto_bio.h similarity index 100% rename from deps/nodejs/include/node_crypto_bio.h rename to server/deps/nodejs/include/node_crypto_bio.h diff --git a/deps/nodejs/include/node_crypto_clienthello-inl.h b/server/deps/nodejs/include/node_crypto_clienthello-inl.h similarity index 100% rename from deps/nodejs/include/node_crypto_clienthello-inl.h rename to server/deps/nodejs/include/node_crypto_clienthello-inl.h diff --git a/deps/nodejs/include/node_crypto_clienthello.h b/server/deps/nodejs/include/node_crypto_clienthello.h similarity index 100% rename from deps/nodejs/include/node_crypto_clienthello.h rename to server/deps/nodejs/include/node_crypto_clienthello.h diff --git a/deps/nodejs/include/node_crypto_common.h b/server/deps/nodejs/include/node_crypto_common.h similarity index 100% rename from deps/nodejs/include/node_crypto_common.h rename to server/deps/nodejs/include/node_crypto_common.h diff --git a/deps/nodejs/include/node_crypto_groups.h b/server/deps/nodejs/include/node_crypto_groups.h similarity index 100% rename from deps/nodejs/include/node_crypto_groups.h rename to server/deps/nodejs/include/node_crypto_groups.h diff --git a/deps/nodejs/include/node_dir.h b/server/deps/nodejs/include/node_dir.h similarity index 100% rename from deps/nodejs/include/node_dir.h rename to server/deps/nodejs/include/node_dir.h diff --git a/deps/nodejs/include/node_dtrace.h b/server/deps/nodejs/include/node_dtrace.h similarity index 100% rename from deps/nodejs/include/node_dtrace.h rename to server/deps/nodejs/include/node_dtrace.h diff --git a/deps/nodejs/include/node_errors.h b/server/deps/nodejs/include/node_errors.h similarity index 100% rename from deps/nodejs/include/node_errors.h rename to server/deps/nodejs/include/node_errors.h diff --git a/deps/nodejs/include/node_file-inl.h b/server/deps/nodejs/include/node_file-inl.h similarity index 100% rename from deps/nodejs/include/node_file-inl.h rename to server/deps/nodejs/include/node_file-inl.h diff --git a/deps/nodejs/include/node_file.h b/server/deps/nodejs/include/node_file.h similarity index 100% rename from deps/nodejs/include/node_file.h rename to server/deps/nodejs/include/node_file.h diff --git a/deps/nodejs/include/node_http2.h b/server/deps/nodejs/include/node_http2.h similarity index 100% rename from deps/nodejs/include/node_http2.h rename to server/deps/nodejs/include/node_http2.h diff --git a/deps/nodejs/include/node_http2_state.h b/server/deps/nodejs/include/node_http2_state.h similarity index 100% rename from deps/nodejs/include/node_http2_state.h rename to server/deps/nodejs/include/node_http2_state.h diff --git a/deps/nodejs/include/node_http_common-inl.h b/server/deps/nodejs/include/node_http_common-inl.h similarity index 100% rename from deps/nodejs/include/node_http_common-inl.h rename to server/deps/nodejs/include/node_http_common-inl.h diff --git a/deps/nodejs/include/node_http_common.h b/server/deps/nodejs/include/node_http_common.h similarity index 100% rename from deps/nodejs/include/node_http_common.h rename to server/deps/nodejs/include/node_http_common.h diff --git a/deps/nodejs/include/node_i18n.h b/server/deps/nodejs/include/node_i18n.h similarity index 100% rename from deps/nodejs/include/node_i18n.h rename to server/deps/nodejs/include/node_i18n.h diff --git a/deps/nodejs/include/node_internals.h b/server/deps/nodejs/include/node_internals.h similarity index 100% rename from deps/nodejs/include/node_internals.h rename to server/deps/nodejs/include/node_internals.h diff --git a/deps/nodejs/include/node_main_instance.h b/server/deps/nodejs/include/node_main_instance.h similarity index 100% rename from deps/nodejs/include/node_main_instance.h rename to server/deps/nodejs/include/node_main_instance.h diff --git a/deps/nodejs/include/node_mem-inl.h b/server/deps/nodejs/include/node_mem-inl.h similarity index 100% rename from deps/nodejs/include/node_mem-inl.h rename to server/deps/nodejs/include/node_mem-inl.h diff --git a/deps/nodejs/include/node_mem.h b/server/deps/nodejs/include/node_mem.h similarity index 100% rename from deps/nodejs/include/node_mem.h rename to server/deps/nodejs/include/node_mem.h diff --git a/deps/nodejs/include/node_messaging.h b/server/deps/nodejs/include/node_messaging.h similarity index 100% rename from deps/nodejs/include/node_messaging.h rename to server/deps/nodejs/include/node_messaging.h diff --git a/deps/nodejs/include/node_metadata.h b/server/deps/nodejs/include/node_metadata.h similarity index 100% rename from deps/nodejs/include/node_metadata.h rename to server/deps/nodejs/include/node_metadata.h diff --git a/deps/nodejs/include/node_mutex.h b/server/deps/nodejs/include/node_mutex.h similarity index 100% rename from deps/nodejs/include/node_mutex.h rename to server/deps/nodejs/include/node_mutex.h diff --git a/deps/nodejs/include/node_native_module.h b/server/deps/nodejs/include/node_native_module.h similarity index 100% rename from deps/nodejs/include/node_native_module.h rename to server/deps/nodejs/include/node_native_module.h diff --git a/deps/nodejs/include/node_native_module_env.h b/server/deps/nodejs/include/node_native_module_env.h similarity index 100% rename from deps/nodejs/include/node_native_module_env.h rename to server/deps/nodejs/include/node_native_module_env.h diff --git a/deps/nodejs/include/node_object_wrap.h b/server/deps/nodejs/include/node_object_wrap.h similarity index 100% rename from deps/nodejs/include/node_object_wrap.h rename to server/deps/nodejs/include/node_object_wrap.h diff --git a/deps/nodejs/include/node_options-inl.h b/server/deps/nodejs/include/node_options-inl.h similarity index 100% rename from deps/nodejs/include/node_options-inl.h rename to server/deps/nodejs/include/node_options-inl.h diff --git a/deps/nodejs/include/node_options.h b/server/deps/nodejs/include/node_options.h similarity index 100% rename from deps/nodejs/include/node_options.h rename to server/deps/nodejs/include/node_options.h diff --git a/deps/nodejs/include/node_perf.h b/server/deps/nodejs/include/node_perf.h similarity index 100% rename from deps/nodejs/include/node_perf.h rename to server/deps/nodejs/include/node_perf.h diff --git a/deps/nodejs/include/node_perf_common.h b/server/deps/nodejs/include/node_perf_common.h similarity index 100% rename from deps/nodejs/include/node_perf_common.h rename to server/deps/nodejs/include/node_perf_common.h diff --git a/deps/nodejs/include/node_platform.h b/server/deps/nodejs/include/node_platform.h similarity index 100% rename from deps/nodejs/include/node_platform.h rename to server/deps/nodejs/include/node_platform.h diff --git a/deps/nodejs/include/node_process.h b/server/deps/nodejs/include/node_process.h similarity index 100% rename from deps/nodejs/include/node_process.h rename to server/deps/nodejs/include/node_process.h diff --git a/deps/nodejs/include/node_report.h b/server/deps/nodejs/include/node_report.h similarity index 100% rename from deps/nodejs/include/node_report.h rename to server/deps/nodejs/include/node_report.h diff --git a/deps/nodejs/include/node_revert.h b/server/deps/nodejs/include/node_revert.h similarity index 100% rename from deps/nodejs/include/node_revert.h rename to server/deps/nodejs/include/node_revert.h diff --git a/deps/nodejs/include/node_root_certs.h b/server/deps/nodejs/include/node_root_certs.h similarity index 100% rename from deps/nodejs/include/node_root_certs.h rename to server/deps/nodejs/include/node_root_certs.h diff --git a/deps/nodejs/include/node_sockaddr-inl.h b/server/deps/nodejs/include/node_sockaddr-inl.h similarity index 100% rename from deps/nodejs/include/node_sockaddr-inl.h rename to server/deps/nodejs/include/node_sockaddr-inl.h diff --git a/deps/nodejs/include/node_sockaddr.h b/server/deps/nodejs/include/node_sockaddr.h similarity index 100% rename from deps/nodejs/include/node_sockaddr.h rename to server/deps/nodejs/include/node_sockaddr.h diff --git a/deps/nodejs/include/node_stat_watcher.h b/server/deps/nodejs/include/node_stat_watcher.h similarity index 100% rename from deps/nodejs/include/node_stat_watcher.h rename to server/deps/nodejs/include/node_stat_watcher.h diff --git a/deps/nodejs/include/node_union_bytes.h b/server/deps/nodejs/include/node_union_bytes.h similarity index 100% rename from deps/nodejs/include/node_union_bytes.h rename to server/deps/nodejs/include/node_union_bytes.h diff --git a/deps/nodejs/include/node_url.h b/server/deps/nodejs/include/node_url.h similarity index 100% rename from deps/nodejs/include/node_url.h rename to server/deps/nodejs/include/node_url.h diff --git a/deps/nodejs/include/node_v8_platform-inl.h b/server/deps/nodejs/include/node_v8_platform-inl.h similarity index 100% rename from deps/nodejs/include/node_v8_platform-inl.h rename to server/deps/nodejs/include/node_v8_platform-inl.h diff --git a/deps/nodejs/include/node_version.h b/server/deps/nodejs/include/node_version.h similarity index 100% rename from deps/nodejs/include/node_version.h rename to server/deps/nodejs/include/node_version.h diff --git a/deps/nodejs/include/node_wasi.h b/server/deps/nodejs/include/node_wasi.h similarity index 100% rename from deps/nodejs/include/node_wasi.h rename to server/deps/nodejs/include/node_wasi.h diff --git a/deps/nodejs/include/node_watchdog.h b/server/deps/nodejs/include/node_watchdog.h similarity index 100% rename from deps/nodejs/include/node_watchdog.h rename to server/deps/nodejs/include/node_watchdog.h diff --git a/deps/nodejs/include/node_win32_etw_provider-inl.h b/server/deps/nodejs/include/node_win32_etw_provider-inl.h similarity index 100% rename from deps/nodejs/include/node_win32_etw_provider-inl.h rename to server/deps/nodejs/include/node_win32_etw_provider-inl.h diff --git a/deps/nodejs/include/node_win32_etw_provider.h b/server/deps/nodejs/include/node_win32_etw_provider.h similarity index 100% rename from deps/nodejs/include/node_win32_etw_provider.h rename to server/deps/nodejs/include/node_win32_etw_provider.h diff --git a/deps/nodejs/include/node_worker.h b/server/deps/nodejs/include/node_worker.h similarity index 100% rename from deps/nodejs/include/node_worker.h rename to server/deps/nodejs/include/node_worker.h diff --git a/deps/nodejs/include/pipe_wrap.h b/server/deps/nodejs/include/pipe_wrap.h similarity index 100% rename from deps/nodejs/include/pipe_wrap.h rename to server/deps/nodejs/include/pipe_wrap.h diff --git a/deps/nodejs/include/req_wrap-inl.h b/server/deps/nodejs/include/req_wrap-inl.h similarity index 100% rename from deps/nodejs/include/req_wrap-inl.h rename to server/deps/nodejs/include/req_wrap-inl.h diff --git a/deps/nodejs/include/req_wrap.h b/server/deps/nodejs/include/req_wrap.h similarity index 100% rename from deps/nodejs/include/req_wrap.h rename to server/deps/nodejs/include/req_wrap.h diff --git a/deps/nodejs/include/spawn_sync.h b/server/deps/nodejs/include/spawn_sync.h similarity index 100% rename from deps/nodejs/include/spawn_sync.h rename to server/deps/nodejs/include/spawn_sync.h diff --git a/deps/nodejs/include/stream_base-inl.h b/server/deps/nodejs/include/stream_base-inl.h similarity index 100% rename from deps/nodejs/include/stream_base-inl.h rename to server/deps/nodejs/include/stream_base-inl.h diff --git a/deps/nodejs/include/stream_base.h b/server/deps/nodejs/include/stream_base.h similarity index 100% rename from deps/nodejs/include/stream_base.h rename to server/deps/nodejs/include/stream_base.h diff --git a/deps/nodejs/include/stream_pipe.h b/server/deps/nodejs/include/stream_pipe.h similarity index 100% rename from deps/nodejs/include/stream_pipe.h rename to server/deps/nodejs/include/stream_pipe.h diff --git a/deps/nodejs/include/stream_wrap.h b/server/deps/nodejs/include/stream_wrap.h similarity index 100% rename from deps/nodejs/include/stream_wrap.h rename to server/deps/nodejs/include/stream_wrap.h diff --git a/deps/nodejs/include/string_bytes.h b/server/deps/nodejs/include/string_bytes.h similarity index 100% rename from deps/nodejs/include/string_bytes.h rename to server/deps/nodejs/include/string_bytes.h diff --git a/deps/nodejs/include/string_decoder-inl.h b/server/deps/nodejs/include/string_decoder-inl.h similarity index 100% rename from deps/nodejs/include/string_decoder-inl.h rename to server/deps/nodejs/include/string_decoder-inl.h diff --git a/deps/nodejs/include/string_decoder.h b/server/deps/nodejs/include/string_decoder.h similarity index 100% rename from deps/nodejs/include/string_decoder.h rename to server/deps/nodejs/include/string_decoder.h diff --git a/deps/nodejs/include/string_search.h b/server/deps/nodejs/include/string_search.h similarity index 100% rename from deps/nodejs/include/string_search.h rename to server/deps/nodejs/include/string_search.h diff --git a/deps/nodejs/include/tcp_wrap.h b/server/deps/nodejs/include/tcp_wrap.h similarity index 100% rename from deps/nodejs/include/tcp_wrap.h rename to server/deps/nodejs/include/tcp_wrap.h diff --git a/deps/nodejs/include/threadpoolwork-inl.h b/server/deps/nodejs/include/threadpoolwork-inl.h similarity index 100% rename from deps/nodejs/include/threadpoolwork-inl.h rename to server/deps/nodejs/include/threadpoolwork-inl.h diff --git a/deps/nodejs/include/tls_wrap.h b/server/deps/nodejs/include/tls_wrap.h similarity index 100% rename from deps/nodejs/include/tls_wrap.h rename to server/deps/nodejs/include/tls_wrap.h diff --git a/deps/nodejs/include/tracing/agent.h b/server/deps/nodejs/include/tracing/agent.h similarity index 100% rename from deps/nodejs/include/tracing/agent.h rename to server/deps/nodejs/include/tracing/agent.h diff --git a/deps/nodejs/include/tracing/node_trace_buffer.h b/server/deps/nodejs/include/tracing/node_trace_buffer.h similarity index 100% rename from deps/nodejs/include/tracing/node_trace_buffer.h rename to server/deps/nodejs/include/tracing/node_trace_buffer.h diff --git a/deps/nodejs/include/tracing/node_trace_writer.h b/server/deps/nodejs/include/tracing/node_trace_writer.h similarity index 100% rename from deps/nodejs/include/tracing/node_trace_writer.h rename to server/deps/nodejs/include/tracing/node_trace_writer.h diff --git a/deps/nodejs/include/tracing/trace_event.h b/server/deps/nodejs/include/tracing/trace_event.h similarity index 100% rename from deps/nodejs/include/tracing/trace_event.h rename to server/deps/nodejs/include/tracing/trace_event.h diff --git a/deps/nodejs/include/tracing/trace_event_common.h b/server/deps/nodejs/include/tracing/trace_event_common.h similarity index 100% rename from deps/nodejs/include/tracing/trace_event_common.h rename to server/deps/nodejs/include/tracing/trace_event_common.h diff --git a/deps/nodejs/include/tracing/traced_value.h b/server/deps/nodejs/include/tracing/traced_value.h similarity index 100% rename from deps/nodejs/include/tracing/traced_value.h rename to server/deps/nodejs/include/tracing/traced_value.h diff --git a/deps/nodejs/include/tty_wrap.h b/server/deps/nodejs/include/tty_wrap.h similarity index 100% rename from deps/nodejs/include/tty_wrap.h rename to server/deps/nodejs/include/tty_wrap.h diff --git a/deps/nodejs/include/udp_wrap.h b/server/deps/nodejs/include/udp_wrap.h similarity index 100% rename from deps/nodejs/include/udp_wrap.h rename to server/deps/nodejs/include/udp_wrap.h diff --git a/deps/nodejs/include/util-inl.h b/server/deps/nodejs/include/util-inl.h similarity index 100% rename from deps/nodejs/include/util-inl.h rename to server/deps/nodejs/include/util-inl.h diff --git a/deps/nodejs/include/util.h b/server/deps/nodejs/include/util.h similarity index 100% rename from deps/nodejs/include/util.h rename to server/deps/nodejs/include/util.h diff --git a/deps/nodejs/include/v8abbr.h b/server/deps/nodejs/include/v8abbr.h similarity index 100% rename from deps/nodejs/include/v8abbr.h rename to server/deps/nodejs/include/v8abbr.h diff --git a/generate.bat b/server/generate.bat similarity index 100% rename from generate.bat rename to server/generate.bat diff --git a/src/CNodeResourceImpl.cpp b/server/src/CNodeResourceImpl.cpp similarity index 100% rename from src/CNodeResourceImpl.cpp rename to server/src/CNodeResourceImpl.cpp diff --git a/src/CNodeResourceImpl.h b/server/src/CNodeResourceImpl.h similarity index 100% rename from src/CNodeResourceImpl.h rename to server/src/CNodeResourceImpl.h diff --git a/src/CNodeScriptRuntime.cpp b/server/src/CNodeScriptRuntime.cpp similarity index 100% rename from src/CNodeScriptRuntime.cpp rename to server/src/CNodeScriptRuntime.cpp diff --git a/src/CNodeScriptRuntime.h b/server/src/CNodeScriptRuntime.h similarity index 100% rename from src/CNodeScriptRuntime.h rename to server/src/CNodeScriptRuntime.h diff --git a/src/Log.h b/server/src/Log.h similarity index 100% rename from src/Log.h rename to server/src/Log.h diff --git a/src/bindings/Blip.cpp b/server/src/bindings/Blip.cpp similarity index 100% rename from src/bindings/Blip.cpp rename to server/src/bindings/Blip.cpp diff --git a/src/bindings/Checkpoint.cpp b/server/src/bindings/Checkpoint.cpp similarity index 100% rename from src/bindings/Checkpoint.cpp rename to server/src/bindings/Checkpoint.cpp diff --git a/src/bindings/ColShape.cpp b/server/src/bindings/ColShape.cpp similarity index 100% rename from src/bindings/ColShape.cpp rename to server/src/bindings/ColShape.cpp diff --git a/src/bindings/Main.cpp b/server/src/bindings/Main.cpp similarity index 100% rename from src/bindings/Main.cpp rename to server/src/bindings/Main.cpp diff --git a/src/bindings/Player.cpp b/server/src/bindings/Player.cpp similarity index 100% rename from src/bindings/Player.cpp rename to server/src/bindings/Player.cpp diff --git a/src/bindings/Vehicle.cpp b/server/src/bindings/Vehicle.cpp similarity index 100% rename from src/bindings/Vehicle.cpp rename to server/src/bindings/Vehicle.cpp diff --git a/src/bindings/VoiceChannel.cpp b/server/src/bindings/VoiceChannel.cpp similarity index 100% rename from src/bindings/VoiceChannel.cpp rename to server/src/bindings/VoiceChannel.cpp diff --git a/src/bindings/vehicle/Appearance.h b/server/src/bindings/vehicle/Appearance.h similarity index 100% rename from src/bindings/vehicle/Appearance.h rename to server/src/bindings/vehicle/Appearance.h diff --git a/src/bindings/vehicle/Damage.h b/server/src/bindings/vehicle/Damage.h similarity index 100% rename from src/bindings/vehicle/Damage.h rename to server/src/bindings/vehicle/Damage.h diff --git a/src/bindings/vehicle/GameState.h b/server/src/bindings/vehicle/GameState.h similarity index 100% rename from src/bindings/vehicle/GameState.h rename to server/src/bindings/vehicle/GameState.h diff --git a/src/bindings/vehicle/Health.h b/server/src/bindings/vehicle/Health.h similarity index 100% rename from src/bindings/vehicle/Health.h rename to server/src/bindings/vehicle/Health.h diff --git a/src/bindings/vehicle/ScriptGameState.h b/server/src/bindings/vehicle/ScriptGameState.h similarity index 100% rename from src/bindings/vehicle/ScriptGameState.h rename to server/src/bindings/vehicle/ScriptGameState.h diff --git a/src/cpp-sdk b/server/src/cpp-sdk similarity index 100% rename from src/cpp-sdk rename to server/src/cpp-sdk diff --git a/src/events/Main.cpp b/server/src/events/Main.cpp similarity index 100% rename from src/events/Main.cpp rename to server/src/events/Main.cpp diff --git a/src/events/Player.cpp b/server/src/events/Player.cpp similarity index 100% rename from src/events/Player.cpp rename to server/src/events/Player.cpp diff --git a/src/events/Vehicle.cpp b/server/src/events/Vehicle.cpp similarity index 100% rename from src/events/Vehicle.cpp rename to server/src/events/Vehicle.cpp diff --git a/src/helpers b/server/src/helpers similarity index 100% rename from src/helpers rename to server/src/helpers diff --git a/src/node-module.cpp b/server/src/node-module.cpp similarity index 100% rename from src/node-module.cpp rename to server/src/node-module.cpp diff --git a/src/stdafx.h b/server/src/stdafx.h similarity index 100% rename from src/stdafx.h rename to server/src/stdafx.h diff --git a/tools/altv-v8-tool.exe.REMOVED.git-id b/server/tools/altv-v8-tool.exe.REMOVED.git-id similarity index 100% rename from tools/altv-v8-tool.exe.REMOVED.git-id rename to server/tools/altv-v8-tool.exe.REMOVED.git-id diff --git a/tools/nodejsdefs.js b/server/tools/nodejsdefs.js similarity index 100% rename from tools/nodejsdefs.js rename to server/tools/nodejsdefs.js From a6cce0c860b42a1db57bbb7b0d5e70d9a43bc16d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 19:57:42 +0200 Subject: [PATCH 547/564] Add client Former-commit-id: 9aae25e47b1db8568c8356df2f35bee10154653a --- {.github => client/.github}/workflows/cmake.yml | 0 .gitignore => client/.gitignore | 0 .gitmodules => client/.gitmodules | 4 ++-- {.vscode => client/.vscode}/c_cpp_properties.json | 0 {.vscode => client/.vscode}/launch.json | 0 {.vscode => client/.vscode}/settings.json | 0 {.vscode => client/.vscode}/tasks.json | 0 CMakeLists.txt => client/CMakeLists.txt | 0 README.md => client/README.md | 0 {cmake => client/cmake}/GitUtils.cmake | 0 {cmake => client/cmake}/Utils.cmake | 0 {deps => client/deps}/cpp-sdk/cpp-sdk | 0 {src => client/src}/CV8Resource.cpp | 0 {src => client/src}/CV8Resource.h | 0 {src => client/src}/CV8ScriptRuntime.cpp | 0 {src => client/src}/CV8ScriptRuntime.h | 0 {src => client/src}/V8Entity.h | 0 {src => client/src}/bindings/Audio.cpp | 0 {src => client/src}/bindings/Blip.cpp | 0 {src => client/src}/bindings/Checkpoint.cpp | 0 {src => client/src}/bindings/Discord.cpp | 0 {src => client/src}/bindings/Handling.cpp | 0 {src => client/src}/bindings/HandlingData.cpp | 0 {src => client/src}/bindings/HttpClient.cpp | 0 {src => client/src}/bindings/LocalPlayer.cpp | 0 {src => client/src}/bindings/LocalStorage.cpp | 0 {src => client/src}/bindings/Main.cpp | 0 {src => client/src}/bindings/MapZoomData.cpp | 0 {src => client/src}/bindings/MemoryBuffer.cpp | 0 {src => client/src}/bindings/Player.cpp | 0 {src => client/src}/bindings/Profiler.cpp | 0 {src => client/src}/bindings/V8Natives.cpp | 0 {src => client/src}/bindings/Vehicle.cpp | 0 {src => client/src}/bindings/Voice.cpp | 0 {src => client/src}/bindings/WebSocketClient.cpp | 0 {src => client/src}/bindings/WebView.cpp | 0 {src => client/src}/events/Entity.cpp | 0 {src => client/src}/events/Events.h | 0 {src => client/src}/events/Main.cpp | 0 {src => client/src}/events/Meta.cpp | 0 {src => client/src}/events/Resource.cpp | 0 {src => client/src}/events/Vehicle.cpp | 0 {src => client/src}/helpers | 0 {src => client/src}/inspector/CV8InspectorChannel.h | 0 {src => client/src}/inspector/CV8InspectorClient.h | 0 {src => client/src}/main.cpp | 0 {tools => client/tools}/build-debug.bat | 0 {tools => client/tools}/build.bat | 0 {tools => client/tools}/deinit-cppsdk.bat | 0 49 files changed, 2 insertions(+), 2 deletions(-) rename {.github => client/.github}/workflows/cmake.yml (100%) rename .gitignore => client/.gitignore (100%) rename .gitmodules => client/.gitmodules (70%) rename {.vscode => client/.vscode}/c_cpp_properties.json (100%) rename {.vscode => client/.vscode}/launch.json (100%) rename {.vscode => client/.vscode}/settings.json (100%) rename {.vscode => client/.vscode}/tasks.json (100%) rename CMakeLists.txt => client/CMakeLists.txt (100%) rename README.md => client/README.md (100%) rename {cmake => client/cmake}/GitUtils.cmake (100%) rename {cmake => client/cmake}/Utils.cmake (100%) rename {deps => client/deps}/cpp-sdk/cpp-sdk (100%) rename {src => client/src}/CV8Resource.cpp (100%) rename {src => client/src}/CV8Resource.h (100%) rename {src => client/src}/CV8ScriptRuntime.cpp (100%) rename {src => client/src}/CV8ScriptRuntime.h (100%) rename {src => client/src}/V8Entity.h (100%) rename {src => client/src}/bindings/Audio.cpp (100%) rename {src => client/src}/bindings/Blip.cpp (100%) rename {src => client/src}/bindings/Checkpoint.cpp (100%) rename {src => client/src}/bindings/Discord.cpp (100%) rename {src => client/src}/bindings/Handling.cpp (100%) rename {src => client/src}/bindings/HandlingData.cpp (100%) rename {src => client/src}/bindings/HttpClient.cpp (100%) rename {src => client/src}/bindings/LocalPlayer.cpp (100%) rename {src => client/src}/bindings/LocalStorage.cpp (100%) rename {src => client/src}/bindings/Main.cpp (100%) rename {src => client/src}/bindings/MapZoomData.cpp (100%) rename {src => client/src}/bindings/MemoryBuffer.cpp (100%) rename {src => client/src}/bindings/Player.cpp (100%) rename {src => client/src}/bindings/Profiler.cpp (100%) rename {src => client/src}/bindings/V8Natives.cpp (100%) rename {src => client/src}/bindings/Vehicle.cpp (100%) rename {src => client/src}/bindings/Voice.cpp (100%) rename {src => client/src}/bindings/WebSocketClient.cpp (100%) rename {src => client/src}/bindings/WebView.cpp (100%) rename {src => client/src}/events/Entity.cpp (100%) rename {src => client/src}/events/Events.h (100%) rename {src => client/src}/events/Main.cpp (100%) rename {src => client/src}/events/Meta.cpp (100%) rename {src => client/src}/events/Resource.cpp (100%) rename {src => client/src}/events/Vehicle.cpp (100%) rename {src => client/src}/helpers (100%) rename {src => client/src}/inspector/CV8InspectorChannel.h (100%) rename {src => client/src}/inspector/CV8InspectorClient.h (100%) rename {src => client/src}/main.cpp (100%) rename {tools => client/tools}/build-debug.bat (100%) rename {tools => client/tools}/build.bat (100%) rename {tools => client/tools}/deinit-cppsdk.bat (100%) diff --git a/.github/workflows/cmake.yml b/client/.github/workflows/cmake.yml similarity index 100% rename from .github/workflows/cmake.yml rename to client/.github/workflows/cmake.yml diff --git a/.gitignore b/client/.gitignore similarity index 100% rename from .gitignore rename to client/.gitignore diff --git a/.gitmodules b/client/.gitmodules similarity index 70% rename from .gitmodules rename to client/.gitmodules index 010a1fef..3ce2c386 100644 --- a/.gitmodules +++ b/client/.gitmodules @@ -1,6 +1,6 @@ [submodule "src/helpers"] - path = src/helpers + path = client/src/helpers url = https://github.com/altmp/v8-helpers.git [submodule "deps/cpp-sdk/cpp-sdk"] - path = deps/cpp-sdk/cpp-sdk + path = client/deps/cpp-sdk/cpp-sdk url = https://github.com/altmp/cpp-sdk.git diff --git a/.vscode/c_cpp_properties.json b/client/.vscode/c_cpp_properties.json similarity index 100% rename from .vscode/c_cpp_properties.json rename to client/.vscode/c_cpp_properties.json diff --git a/.vscode/launch.json b/client/.vscode/launch.json similarity index 100% rename from .vscode/launch.json rename to client/.vscode/launch.json diff --git a/.vscode/settings.json b/client/.vscode/settings.json similarity index 100% rename from .vscode/settings.json rename to client/.vscode/settings.json diff --git a/.vscode/tasks.json b/client/.vscode/tasks.json similarity index 100% rename from .vscode/tasks.json rename to client/.vscode/tasks.json diff --git a/CMakeLists.txt b/client/CMakeLists.txt similarity index 100% rename from CMakeLists.txt rename to client/CMakeLists.txt diff --git a/README.md b/client/README.md similarity index 100% rename from README.md rename to client/README.md diff --git a/cmake/GitUtils.cmake b/client/cmake/GitUtils.cmake similarity index 100% rename from cmake/GitUtils.cmake rename to client/cmake/GitUtils.cmake diff --git a/cmake/Utils.cmake b/client/cmake/Utils.cmake similarity index 100% rename from cmake/Utils.cmake rename to client/cmake/Utils.cmake diff --git a/deps/cpp-sdk/cpp-sdk b/client/deps/cpp-sdk/cpp-sdk similarity index 100% rename from deps/cpp-sdk/cpp-sdk rename to client/deps/cpp-sdk/cpp-sdk diff --git a/src/CV8Resource.cpp b/client/src/CV8Resource.cpp similarity index 100% rename from src/CV8Resource.cpp rename to client/src/CV8Resource.cpp diff --git a/src/CV8Resource.h b/client/src/CV8Resource.h similarity index 100% rename from src/CV8Resource.h rename to client/src/CV8Resource.h diff --git a/src/CV8ScriptRuntime.cpp b/client/src/CV8ScriptRuntime.cpp similarity index 100% rename from src/CV8ScriptRuntime.cpp rename to client/src/CV8ScriptRuntime.cpp diff --git a/src/CV8ScriptRuntime.h b/client/src/CV8ScriptRuntime.h similarity index 100% rename from src/CV8ScriptRuntime.h rename to client/src/CV8ScriptRuntime.h diff --git a/src/V8Entity.h b/client/src/V8Entity.h similarity index 100% rename from src/V8Entity.h rename to client/src/V8Entity.h diff --git a/src/bindings/Audio.cpp b/client/src/bindings/Audio.cpp similarity index 100% rename from src/bindings/Audio.cpp rename to client/src/bindings/Audio.cpp diff --git a/src/bindings/Blip.cpp b/client/src/bindings/Blip.cpp similarity index 100% rename from src/bindings/Blip.cpp rename to client/src/bindings/Blip.cpp diff --git a/src/bindings/Checkpoint.cpp b/client/src/bindings/Checkpoint.cpp similarity index 100% rename from src/bindings/Checkpoint.cpp rename to client/src/bindings/Checkpoint.cpp diff --git a/src/bindings/Discord.cpp b/client/src/bindings/Discord.cpp similarity index 100% rename from src/bindings/Discord.cpp rename to client/src/bindings/Discord.cpp diff --git a/src/bindings/Handling.cpp b/client/src/bindings/Handling.cpp similarity index 100% rename from src/bindings/Handling.cpp rename to client/src/bindings/Handling.cpp diff --git a/src/bindings/HandlingData.cpp b/client/src/bindings/HandlingData.cpp similarity index 100% rename from src/bindings/HandlingData.cpp rename to client/src/bindings/HandlingData.cpp diff --git a/src/bindings/HttpClient.cpp b/client/src/bindings/HttpClient.cpp similarity index 100% rename from src/bindings/HttpClient.cpp rename to client/src/bindings/HttpClient.cpp diff --git a/src/bindings/LocalPlayer.cpp b/client/src/bindings/LocalPlayer.cpp similarity index 100% rename from src/bindings/LocalPlayer.cpp rename to client/src/bindings/LocalPlayer.cpp diff --git a/src/bindings/LocalStorage.cpp b/client/src/bindings/LocalStorage.cpp similarity index 100% rename from src/bindings/LocalStorage.cpp rename to client/src/bindings/LocalStorage.cpp diff --git a/src/bindings/Main.cpp b/client/src/bindings/Main.cpp similarity index 100% rename from src/bindings/Main.cpp rename to client/src/bindings/Main.cpp diff --git a/src/bindings/MapZoomData.cpp b/client/src/bindings/MapZoomData.cpp similarity index 100% rename from src/bindings/MapZoomData.cpp rename to client/src/bindings/MapZoomData.cpp diff --git a/src/bindings/MemoryBuffer.cpp b/client/src/bindings/MemoryBuffer.cpp similarity index 100% rename from src/bindings/MemoryBuffer.cpp rename to client/src/bindings/MemoryBuffer.cpp diff --git a/src/bindings/Player.cpp b/client/src/bindings/Player.cpp similarity index 100% rename from src/bindings/Player.cpp rename to client/src/bindings/Player.cpp diff --git a/src/bindings/Profiler.cpp b/client/src/bindings/Profiler.cpp similarity index 100% rename from src/bindings/Profiler.cpp rename to client/src/bindings/Profiler.cpp diff --git a/src/bindings/V8Natives.cpp b/client/src/bindings/V8Natives.cpp similarity index 100% rename from src/bindings/V8Natives.cpp rename to client/src/bindings/V8Natives.cpp diff --git a/src/bindings/Vehicle.cpp b/client/src/bindings/Vehicle.cpp similarity index 100% rename from src/bindings/Vehicle.cpp rename to client/src/bindings/Vehicle.cpp diff --git a/src/bindings/Voice.cpp b/client/src/bindings/Voice.cpp similarity index 100% rename from src/bindings/Voice.cpp rename to client/src/bindings/Voice.cpp diff --git a/src/bindings/WebSocketClient.cpp b/client/src/bindings/WebSocketClient.cpp similarity index 100% rename from src/bindings/WebSocketClient.cpp rename to client/src/bindings/WebSocketClient.cpp diff --git a/src/bindings/WebView.cpp b/client/src/bindings/WebView.cpp similarity index 100% rename from src/bindings/WebView.cpp rename to client/src/bindings/WebView.cpp diff --git a/src/events/Entity.cpp b/client/src/events/Entity.cpp similarity index 100% rename from src/events/Entity.cpp rename to client/src/events/Entity.cpp diff --git a/src/events/Events.h b/client/src/events/Events.h similarity index 100% rename from src/events/Events.h rename to client/src/events/Events.h diff --git a/src/events/Main.cpp b/client/src/events/Main.cpp similarity index 100% rename from src/events/Main.cpp rename to client/src/events/Main.cpp diff --git a/src/events/Meta.cpp b/client/src/events/Meta.cpp similarity index 100% rename from src/events/Meta.cpp rename to client/src/events/Meta.cpp diff --git a/src/events/Resource.cpp b/client/src/events/Resource.cpp similarity index 100% rename from src/events/Resource.cpp rename to client/src/events/Resource.cpp diff --git a/src/events/Vehicle.cpp b/client/src/events/Vehicle.cpp similarity index 100% rename from src/events/Vehicle.cpp rename to client/src/events/Vehicle.cpp diff --git a/src/helpers b/client/src/helpers similarity index 100% rename from src/helpers rename to client/src/helpers diff --git a/src/inspector/CV8InspectorChannel.h b/client/src/inspector/CV8InspectorChannel.h similarity index 100% rename from src/inspector/CV8InspectorChannel.h rename to client/src/inspector/CV8InspectorChannel.h diff --git a/src/inspector/CV8InspectorClient.h b/client/src/inspector/CV8InspectorClient.h similarity index 100% rename from src/inspector/CV8InspectorClient.h rename to client/src/inspector/CV8InspectorClient.h diff --git a/src/main.cpp b/client/src/main.cpp similarity index 100% rename from src/main.cpp rename to client/src/main.cpp diff --git a/tools/build-debug.bat b/client/tools/build-debug.bat similarity index 100% rename from tools/build-debug.bat rename to client/tools/build-debug.bat diff --git a/tools/build.bat b/client/tools/build.bat similarity index 100% rename from tools/build.bat rename to client/tools/build.bat diff --git a/tools/deinit-cppsdk.bat b/client/tools/deinit-cppsdk.bat similarity index 100% rename from tools/deinit-cppsdk.bat rename to client/tools/deinit-cppsdk.bat From 311d4126d92143df117185f09d766ed873223793 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 20:00:07 +0200 Subject: [PATCH 548/564] Add shared Former-commit-id: 74a246674010b763052d69a7c06f70aad810e0ad --- Log.h => shared/Log.h | 0 PromiseRejections.cpp => shared/PromiseRejections.cpp | 0 PromiseRejections.h => shared/PromiseRejections.h | 0 V8BindHelpers.h => shared/V8BindHelpers.h | 0 V8Class.cpp => shared/V8Class.cpp | 0 V8Class.h => shared/V8Class.h | 0 V8Entity.h => shared/V8Entity.h | 0 V8Helpers.cpp => shared/V8Helpers.cpp | 0 V8Helpers.h => shared/V8Helpers.h | 0 V8Module.h => shared/V8Module.h | 0 V8ResourceImpl.cpp => shared/V8ResourceImpl.cpp | 0 V8ResourceImpl.h => shared/V8ResourceImpl.h | 0 V8Timer.h => shared/V8Timer.h | 0 {bindings => shared/bindings}/BaseObject.cpp | 0 {bindings => shared/bindings}/Entity.cpp | 0 {bindings => shared/bindings}/File.cpp | 0 {bindings => shared/bindings}/Main.cpp | 0 {bindings => shared/bindings}/RGBA.cpp | 0 {bindings => shared/bindings}/Vector2.cpp | 0 {bindings => shared/bindings}/Vector3.cpp | 0 {bindings => shared/bindings}/WorldObject.cpp | 0 {events => shared/events}/Main.cpp | 0 22 files changed, 0 insertions(+), 0 deletions(-) rename Log.h => shared/Log.h (100%) rename PromiseRejections.cpp => shared/PromiseRejections.cpp (100%) rename PromiseRejections.h => shared/PromiseRejections.h (100%) rename V8BindHelpers.h => shared/V8BindHelpers.h (100%) rename V8Class.cpp => shared/V8Class.cpp (100%) rename V8Class.h => shared/V8Class.h (100%) rename V8Entity.h => shared/V8Entity.h (100%) rename V8Helpers.cpp => shared/V8Helpers.cpp (100%) rename V8Helpers.h => shared/V8Helpers.h (100%) rename V8Module.h => shared/V8Module.h (100%) rename V8ResourceImpl.cpp => shared/V8ResourceImpl.cpp (100%) rename V8ResourceImpl.h => shared/V8ResourceImpl.h (100%) rename V8Timer.h => shared/V8Timer.h (100%) rename {bindings => shared/bindings}/BaseObject.cpp (100%) rename {bindings => shared/bindings}/Entity.cpp (100%) rename {bindings => shared/bindings}/File.cpp (100%) rename {bindings => shared/bindings}/Main.cpp (100%) rename {bindings => shared/bindings}/RGBA.cpp (100%) rename {bindings => shared/bindings}/Vector2.cpp (100%) rename {bindings => shared/bindings}/Vector3.cpp (100%) rename {bindings => shared/bindings}/WorldObject.cpp (100%) rename {events => shared/events}/Main.cpp (100%) diff --git a/Log.h b/shared/Log.h similarity index 100% rename from Log.h rename to shared/Log.h diff --git a/PromiseRejections.cpp b/shared/PromiseRejections.cpp similarity index 100% rename from PromiseRejections.cpp rename to shared/PromiseRejections.cpp diff --git a/PromiseRejections.h b/shared/PromiseRejections.h similarity index 100% rename from PromiseRejections.h rename to shared/PromiseRejections.h diff --git a/V8BindHelpers.h b/shared/V8BindHelpers.h similarity index 100% rename from V8BindHelpers.h rename to shared/V8BindHelpers.h diff --git a/V8Class.cpp b/shared/V8Class.cpp similarity index 100% rename from V8Class.cpp rename to shared/V8Class.cpp diff --git a/V8Class.h b/shared/V8Class.h similarity index 100% rename from V8Class.h rename to shared/V8Class.h diff --git a/V8Entity.h b/shared/V8Entity.h similarity index 100% rename from V8Entity.h rename to shared/V8Entity.h diff --git a/V8Helpers.cpp b/shared/V8Helpers.cpp similarity index 100% rename from V8Helpers.cpp rename to shared/V8Helpers.cpp diff --git a/V8Helpers.h b/shared/V8Helpers.h similarity index 100% rename from V8Helpers.h rename to shared/V8Helpers.h diff --git a/V8Module.h b/shared/V8Module.h similarity index 100% rename from V8Module.h rename to shared/V8Module.h diff --git a/V8ResourceImpl.cpp b/shared/V8ResourceImpl.cpp similarity index 100% rename from V8ResourceImpl.cpp rename to shared/V8ResourceImpl.cpp diff --git a/V8ResourceImpl.h b/shared/V8ResourceImpl.h similarity index 100% rename from V8ResourceImpl.h rename to shared/V8ResourceImpl.h diff --git a/V8Timer.h b/shared/V8Timer.h similarity index 100% rename from V8Timer.h rename to shared/V8Timer.h diff --git a/bindings/BaseObject.cpp b/shared/bindings/BaseObject.cpp similarity index 100% rename from bindings/BaseObject.cpp rename to shared/bindings/BaseObject.cpp diff --git a/bindings/Entity.cpp b/shared/bindings/Entity.cpp similarity index 100% rename from bindings/Entity.cpp rename to shared/bindings/Entity.cpp diff --git a/bindings/File.cpp b/shared/bindings/File.cpp similarity index 100% rename from bindings/File.cpp rename to shared/bindings/File.cpp diff --git a/bindings/Main.cpp b/shared/bindings/Main.cpp similarity index 100% rename from bindings/Main.cpp rename to shared/bindings/Main.cpp diff --git a/bindings/RGBA.cpp b/shared/bindings/RGBA.cpp similarity index 100% rename from bindings/RGBA.cpp rename to shared/bindings/RGBA.cpp diff --git a/bindings/Vector2.cpp b/shared/bindings/Vector2.cpp similarity index 100% rename from bindings/Vector2.cpp rename to shared/bindings/Vector2.cpp diff --git a/bindings/Vector3.cpp b/shared/bindings/Vector3.cpp similarity index 100% rename from bindings/Vector3.cpp rename to shared/bindings/Vector3.cpp diff --git a/bindings/WorldObject.cpp b/shared/bindings/WorldObject.cpp similarity index 100% rename from bindings/WorldObject.cpp rename to shared/bindings/WorldObject.cpp diff --git a/events/Main.cpp b/shared/events/Main.cpp similarity index 100% rename from events/Main.cpp rename to shared/events/Main.cpp From 719bf0deb296801346fc6926e76a18b1c8968dbe Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 20:48:21 +0200 Subject: [PATCH 549/564] Changes for single repository Former-commit-id: 82e2189586722b62644d3ecaaedd5dbd01cb1ab3 --- server/.gitattributes => .gitattributes | 0 .../ISSUE_TEMPLATE/bug_report.md | 0 .../ISSUE_TEMPLATE/feature_request.md | 0 .../workflows/build-deploy.yml | 2 +- .../workflows/test-client.yml | 11 +++-- .../workflows/test-server.yml | 10 ++++- .gitmodules | 3 ++ .vscode/c_cpp_properties.json | 20 +++++++++ {client/.vscode => .vscode}/launch.json | 0 {client/.vscode => .vscode}/settings.json | 0 .vscode/tasks.json | 30 +++++++++++++ client/.gitmodules | 6 --- client/.vscode/c_cpp_properties.json | 44 ------------------- client/.vscode/tasks.json | 17 ------- client/CMakeLists.txt | 8 +++- client/{tools => }/build-debug.bat | 0 client/{tools => }/build.bat | 0 client/deps/cpp-sdk/cpp-sdk | 1 - client/src/CV8Resource.cpp | 4 +- client/src/CV8Resource.h | 4 +- client/src/CV8ScriptRuntime.cpp | 2 +- client/src/bindings/Audio.cpp | 8 ++-- client/src/bindings/Blip.cpp | 4 +- client/src/bindings/Checkpoint.cpp | 4 +- client/src/bindings/Discord.cpp | 4 +- client/src/bindings/Handling.cpp | 8 ++-- client/src/bindings/HandlingData.cpp | 2 +- client/src/bindings/HttpClient.cpp | 6 +-- client/src/bindings/LocalPlayer.cpp | 10 ++--- client/src/bindings/LocalStorage.cpp | 6 +-- client/src/bindings/Main.cpp | 4 +- client/src/bindings/MapZoomData.cpp | 2 +- client/src/bindings/MemoryBuffer.cpp | 2 +- client/src/bindings/Player.cpp | 10 ++--- client/src/bindings/Profiler.cpp | 4 +- client/src/bindings/V8Natives.cpp | 8 ++-- client/src/bindings/Vehicle.cpp | 10 ++--- client/src/bindings/Voice.cpp | 6 +-- client/src/bindings/WebSocketClient.cpp | 10 ++--- client/src/bindings/WebView.cpp | 10 ++--- client/src/events/Entity.cpp | 4 +- client/src/events/Events.h | 2 +- client/src/events/Main.cpp | 4 +- client/src/events/Meta.cpp | 4 +- client/src/events/Resource.cpp | 4 +- client/src/events/Vehicle.cpp | 4 +- client/src/helpers | 1 - client/src/main.cpp | 2 +- server/.gitmodules | 6 --- server/CMakeLists.txt | 6 ++- server/src/CNodeResourceImpl.h | 6 +-- server/src/CNodeScriptRuntime.h | 2 +- server/src/bindings/Blip.cpp | 4 +- server/src/bindings/Checkpoint.cpp | 4 +- server/src/bindings/ColShape.cpp | 6 +-- server/src/bindings/Main.cpp | 2 +- server/src/bindings/Player.cpp | 6 +-- server/src/bindings/Vehicle.cpp | 6 +-- server/src/bindings/VoiceChannel.cpp | 4 +- server/src/events/Main.cpp | 4 +- server/src/events/Player.cpp | 4 +- server/src/events/Vehicle.cpp | 4 +- server/src/helpers | 1 - server/src/node-module.cpp | 2 +- server/src/stdafx.h | 6 +-- {server/src => shared/deps}/cpp-sdk | 0 66 files changed, 187 insertions(+), 191 deletions(-) rename server/.gitattributes => .gitattributes (100%) rename {server/.github => .github}/ISSUE_TEMPLATE/bug_report.md (100%) rename {server/.github => .github}/ISSUE_TEMPLATE/feature_request.md (100%) rename {server/.github => .github}/workflows/build-deploy.yml (99%) rename client/.github/workflows/cmake.yml => .github/workflows/test-client.yml (77%) rename server/.github/workflows/test-changes.yml => .github/workflows/test-server.yml (89%) create mode 100644 .gitmodules create mode 100644 .vscode/c_cpp_properties.json rename {client/.vscode => .vscode}/launch.json (100%) rename {client/.vscode => .vscode}/settings.json (100%) create mode 100644 .vscode/tasks.json delete mode 100644 client/.gitmodules delete mode 100644 client/.vscode/c_cpp_properties.json delete mode 100644 client/.vscode/tasks.json rename client/{tools => }/build-debug.bat (100%) rename client/{tools => }/build.bat (100%) delete mode 160000 client/deps/cpp-sdk/cpp-sdk delete mode 160000 client/src/helpers delete mode 100644 server/.gitmodules delete mode 160000 server/src/helpers rename {server/src => shared/deps}/cpp-sdk (100%) diff --git a/server/.gitattributes b/.gitattributes similarity index 100% rename from server/.gitattributes rename to .gitattributes diff --git a/server/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md similarity index 100% rename from server/.github/ISSUE_TEMPLATE/bug_report.md rename to .github/ISSUE_TEMPLATE/bug_report.md diff --git a/server/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md similarity index 100% rename from server/.github/ISSUE_TEMPLATE/feature_request.md rename to .github/ISSUE_TEMPLATE/feature_request.md diff --git a/server/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml similarity index 99% rename from server/.github/workflows/build-deploy.yml rename to .github/workflows/build-deploy.yml index 92d7aaab..2ad684af 100644 --- a/server/.github/workflows/build-deploy.yml +++ b/.github/workflows/build-deploy.yml @@ -1,4 +1,4 @@ -name: Build & deploy +name: Build & deploy server on: push: branches-ignore: diff --git a/client/.github/workflows/cmake.yml b/.github/workflows/test-client.yml similarity index 77% rename from client/.github/workflows/cmake.yml rename to .github/workflows/test-client.yml index 2cf22cfa..eb768f62 100644 --- a/client/.github/workflows/cmake.yml +++ b/.github/workflows/test-client.yml @@ -1,6 +1,11 @@ -name: CMake - -on: [push, pull_request] +name: Test client changes +on: + push: + paths: + - "client/**" + pull_request: + paths: + - "client/**" env: BUILD_TYPE: Release diff --git a/server/.github/workflows/test-changes.yml b/.github/workflows/test-server.yml similarity index 89% rename from server/.github/workflows/test-changes.yml rename to .github/workflows/test-server.yml index 983ad237..1d31c8b1 100644 --- a/server/.github/workflows/test-changes.yml +++ b/.github/workflows/test-server.yml @@ -1,5 +1,11 @@ -name: Test changes -on: [pull_request] +name: Test client changes +on: + push: + paths: + - "server/**" + pull_request: + paths: + - "server/**" jobs: test-windows: diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..332d23c7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "shared/deps/cpp-sdk"] + path = shared/deps/cpp-sdk + url = https://github.com/altmp/cpp-sdk.git diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..98f3c2ab --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,20 @@ +{ + "configurations": [ + { + "name": "Win32 Static", + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE", + "ALT_CLIENT_API", + "ALT_CLIENT", + "ALT_SERVER_API", + "ALT_SERVER" + ], + "windowsSdkVersion": "10.0.19041.0", + "cppStandard": "c++17", + "intelliSenseMode": "msvc-x64" + } + ], + "version": 4 +} diff --git a/client/.vscode/launch.json b/.vscode/launch.json similarity index 100% rename from client/.vscode/launch.json rename to .vscode/launch.json diff --git a/client/.vscode/settings.json b/.vscode/settings.json similarity index 100% rename from client/.vscode/settings.json rename to .vscode/settings.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..6f5f1fa8 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,30 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Build client", + "type": "shell", + "command": "cd client && build-debug.bat", + "problemMatcher": ["$msCompile"], + "group": { + "kind": "build", + "isDefault": true + }, + }, + { + "label": "Build server", + "type": "shell", + "command": "cd server && ./build", + "windows": { + "command": "cd server && build.bat" + }, + "problemMatcher": ["$msCompile"], + "group": { + "kind": "build", + "isDefault": true + }, + } + ] +} diff --git a/client/.gitmodules b/client/.gitmodules deleted file mode 100644 index 3ce2c386..00000000 --- a/client/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "src/helpers"] - path = client/src/helpers - url = https://github.com/altmp/v8-helpers.git -[submodule "deps/cpp-sdk/cpp-sdk"] - path = client/deps/cpp-sdk/cpp-sdk - url = https://github.com/altmp/cpp-sdk.git diff --git a/client/.vscode/c_cpp_properties.json b/client/.vscode/c_cpp_properties.json deleted file mode 100644 index 12afd327..00000000 --- a/client/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "configurations": [ - { - "name": "Win32 Static", - "includePath": [ - "${workspaceFolder}/**", - "${workspaceFolder}/deps", - "${workspaceFolder}/deps/v8/include" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE", - "ALT_CLIENT_API", - "ALT_CLIENT" - ], - "windowsSdkVersion": "10.0.19041.0", - "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe", - "cStandard": "c11", - "cppStandard": "c++17", - "intelliSenseMode": "msvc-x64" - }, - { - "name": "Win32 Shared", - "includePath": [ - "${workspaceFolder}/**", - "${workspaceFolder}/deps" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE", - "ALT_CLIENT_API", - "ALT_CLIENT", - "ALTV_JS_SHARED" - ], - "windowsSdkVersion": "10.0.19041.0", - "cStandard": "c11", - "cppStandard": "c++17", - "intelliSenseMode": "msvc-x64" - } - ], - "version": 4 -} diff --git a/client/.vscode/tasks.json b/client/.vscode/tasks.json deleted file mode 100644 index 9096b7aa..00000000 --- a/client/.vscode/tasks.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "Build", - "type": "shell", - "command": ".\\tools\\build-debug.bat", - "problemMatcher": ["$msCompile"], - "group": { - "kind": "build", - "isDefault": true - }, - } - ] -} diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 590caf77..0f1c5a6f 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -17,13 +17,14 @@ set(ALTV_JS_DL_DEPS ${altv-js-deps_SOURCE_DIR}) # cpp-sdk if(NOT ALTV_JS_CPP_SDK) - set(ALTV_JS_CPP_SDK deps/cpp-sdk) + set(ALTV_JS_CPP_SDK ../shared/deps) else() set(ALTV_JS_DEINIT_CPPSDK 1) endif() # Fetch deps file(GLOB_RECURSE PROJECT_SOURCE_FILES "src/*.h" "src/*.hpp" "src/*.cpp" "src/*.c") +file(GLOB_RECURSE PROJECT_SHARED_FILES "../shared/*.h" "../shared/*.cpp") macro(GroupSources curdir groupindex) file(GLOB children RELATIVE ${curdir} ${curdir}/*) @@ -41,10 +42,13 @@ macro(GroupSources curdir groupindex) endmacro() GroupSources(${PROJECT_SOURCE_DIR}/src "Source Files") +GroupSources("../shared" "Shared Files") include_directories( ${ALTV_JS_CPP_SDK} ${ALTV_JS_DL_DEPS}/include + ${PROJECT_SOURCE_DIR} + ../shared ) set(ALTV_JS_LINKS @@ -84,6 +88,7 @@ if(DYNAMIC_BUILD) add_library( ${PROJECT_NAME} SHARED ${PROJECT_SOURCE_FILES} + ${PROJECT_SHARED_FILES} ) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 @@ -100,6 +105,7 @@ else() add_library( ${PROJECT_NAME}-static STATIC ${PROJECT_SOURCE_FILES} + ${PROJECT_SHARED_FILES} ) set_target_properties(${PROJECT_NAME}-static PROPERTIES CXX_STANDARD 17 diff --git a/client/tools/build-debug.bat b/client/build-debug.bat similarity index 100% rename from client/tools/build-debug.bat rename to client/build-debug.bat diff --git a/client/tools/build.bat b/client/build.bat similarity index 100% rename from client/tools/build.bat rename to client/build.bat diff --git a/client/deps/cpp-sdk/cpp-sdk b/client/deps/cpp-sdk/cpp-sdk deleted file mode 160000 index 60e23a5e..00000000 --- a/client/deps/cpp-sdk/cpp-sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 60e23a5e1b1740b3e5269c4f0da442cc8db80fda diff --git a/client/src/CV8Resource.cpp b/client/src/CV8Resource.cpp index 7fbe8c5b..b99aed9d 100644 --- a/client/src/CV8Resource.cpp +++ b/client/src/CV8Resource.cpp @@ -23,8 +23,8 @@ #include "CV8ScriptRuntime.h" #include "CV8Resource.h" -#include "helpers/V8Helpers.h" -#include "helpers/V8Module.h" +#include "V8Helpers.h" +#include "V8Module.h" static void StaticRequire(const v8::FunctionCallbackInfo &info) { diff --git a/client/src/CV8Resource.h b/client/src/CV8Resource.h index 9ef7bd48..c2380f2d 100644 --- a/client/src/CV8Resource.h +++ b/client/src/CV8Resource.h @@ -3,11 +3,11 @@ #include "cpp-sdk/IResource.h" #include "cpp-sdk/objects/IEntity.h" -#include "helpers/V8ResourceImpl.h" +#include "V8ResourceImpl.h" #include -#include "helpers/Log.h" +#include "Log.h" class CV8ScriptRuntime; diff --git a/client/src/CV8ScriptRuntime.cpp b/client/src/CV8ScriptRuntime.cpp index a900679e..e6c2193c 100644 --- a/client/src/CV8ScriptRuntime.cpp +++ b/client/src/CV8ScriptRuntime.cpp @@ -2,7 +2,7 @@ #include "CV8ScriptRuntime.h" #include "inspector/CV8InspectorClient.h" #include "inspector/CV8InspectorChannel.h" -#include "helpers/V8Module.h" +#include "V8Module.h" #include "events/Events.h" CV8ScriptRuntime::CV8ScriptRuntime() diff --git a/client/src/bindings/Audio.cpp b/client/src/bindings/Audio.cpp index 93ffe035..ae31f805 100644 --- a/client/src/bindings/Audio.cpp +++ b/client/src/bindings/Audio.cpp @@ -1,7 +1,7 @@ -#include "../helpers/V8Helpers.h" -#include "../helpers/V8BindHelpers.h" -#include "../helpers/V8ResourceImpl.h" -#include "../helpers/V8Class.h" +#include "V8Helpers.h" +#include "V8BindHelpers.h" +#include "V8ResourceImpl.h" +#include "V8Class.h" #include "../CV8ScriptRuntime.h" #include "cpp-sdk/script-objects/IAudio.h" diff --git a/client/src/bindings/Blip.cpp b/client/src/bindings/Blip.cpp index 70660cfe..d6c47cfd 100644 --- a/client/src/bindings/Blip.cpp +++ b/client/src/bindings/Blip.cpp @@ -1,6 +1,6 @@ #include "../CV8Resource.h" -#include "../helpers/V8Helpers.h" -#include "../helpers/V8BindHelpers.h" +#include "V8Helpers.h" +#include "V8BindHelpers.h" #include "cpp-sdk/script-objects/IBlip.h" static void ToString(const v8::FunctionCallbackInfo& info) diff --git a/client/src/bindings/Checkpoint.cpp b/client/src/bindings/Checkpoint.cpp index 58389d2f..e2b830b9 100644 --- a/client/src/bindings/Checkpoint.cpp +++ b/client/src/bindings/Checkpoint.cpp @@ -1,6 +1,6 @@ #include "../CV8Resource.h" -#include "../helpers/V8Helpers.h" -#include "../helpers/V8BindHelpers.h" +#include "V8Helpers.h" +#include "V8BindHelpers.h" #include "cpp-sdk/script-objects/ICheckpoint.h" static void Constructor(const v8::FunctionCallbackInfo& info) diff --git a/client/src/bindings/Discord.cpp b/client/src/bindings/Discord.cpp index 775311a3..5a4dddd3 100644 --- a/client/src/bindings/Discord.cpp +++ b/client/src/bindings/Discord.cpp @@ -1,7 +1,7 @@ #include "../CV8Resource.h" -#include "../helpers/V8Class.h" -#include "../helpers/V8Helpers.h" +#include "V8Class.h" +#include "V8Helpers.h" struct DiscordRequestOAuth2TokenCallbackData { diff --git a/client/src/bindings/Handling.cpp b/client/src/bindings/Handling.cpp index 9a5d9fd0..f8acf890 100644 --- a/client/src/bindings/Handling.cpp +++ b/client/src/bindings/Handling.cpp @@ -1,9 +1,9 @@ #include "../CV8Resource.h" -#include "../helpers/V8Helpers.h" -#include "../helpers/V8Class.h" -#include "../helpers/V8Entity.h" -#include "../helpers/V8ResourceImpl.h" +#include "V8Helpers.h" +#include "V8Class.h" +#include "V8Entity.h" +#include "V8ResourceImpl.h" #include "cpp-sdk/objects/IVehicle.h" static void Constructor(const v8::FunctionCallbackInfo& info) diff --git a/client/src/bindings/HandlingData.cpp b/client/src/bindings/HandlingData.cpp index 9e643aad..1ca0d6f8 100644 --- a/client/src/bindings/HandlingData.cpp +++ b/client/src/bindings/HandlingData.cpp @@ -1,6 +1,6 @@ #include "../CV8Resource.h" -#include "../helpers/V8Class.h" +#include "V8Class.h" static void Constructor(const v8::FunctionCallbackInfo& info) { diff --git a/client/src/bindings/HttpClient.cpp b/client/src/bindings/HttpClient.cpp index 2913e494..f2e6e915 100644 --- a/client/src/bindings/HttpClient.cpp +++ b/client/src/bindings/HttpClient.cpp @@ -1,6 +1,6 @@ -#include "../helpers/V8Helpers.h" -#include "../helpers/V8ResourceImpl.h" -#include "../helpers/V8Class.h" +#include "V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8Class.h" #include "../CV8ScriptRuntime.h" static void SetExtraHeader(const v8::FunctionCallbackInfo& info) diff --git a/client/src/bindings/LocalPlayer.cpp b/client/src/bindings/LocalPlayer.cpp index b354feeb..82355b0a 100644 --- a/client/src/bindings/LocalPlayer.cpp +++ b/client/src/bindings/LocalPlayer.cpp @@ -1,8 +1,8 @@ -#include "../helpers/V8Helpers.h" -#include "../helpers/V8Class.h" -#include "../helpers/V8Entity.h" -#include "../helpers/V8ResourceImpl.h" -#include "../helpers/V8BindHelpers.h" +#include "V8Helpers.h" +#include "V8Class.h" +#include "V8Entity.h" +#include "V8ResourceImpl.h" +#include "V8BindHelpers.h" #include "cpp-sdk/objects/ILocalPlayer.h" diff --git a/client/src/bindings/LocalStorage.cpp b/client/src/bindings/LocalStorage.cpp index c97f4b1e..6c658455 100644 --- a/client/src/bindings/LocalStorage.cpp +++ b/client/src/bindings/LocalStorage.cpp @@ -1,7 +1,7 @@ -#include "../helpers/V8Class.h" -#include "../helpers/V8Helpers.h" -#include "../helpers/V8ResourceImpl.h" +#include "V8Class.h" +#include "V8Helpers.h" +#include "V8ResourceImpl.h" #include "../CV8Resource.h" #include "cpp-sdk/SDK.h" diff --git a/client/src/bindings/Main.cpp b/client/src/bindings/Main.cpp index 2af9c256..a518ebef 100644 --- a/client/src/bindings/Main.cpp +++ b/client/src/bindings/Main.cpp @@ -1,11 +1,11 @@ #include "../CV8ScriptRuntime.h" #include "cpp-sdk/objects/IPlayer.h" -#include "../helpers/V8Module.h" +#include "V8Module.h" #include "cpp-sdk/SDK.h" -#include "../helpers/Log.h" +#include "Log.h" using namespace alt; diff --git a/client/src/bindings/MapZoomData.cpp b/client/src/bindings/MapZoomData.cpp index 7ec40a1a..b4075809 100644 --- a/client/src/bindings/MapZoomData.cpp +++ b/client/src/bindings/MapZoomData.cpp @@ -1,5 +1,5 @@ #include "../CV8Resource.h" -#include "../helpers/V8Class.h" +#include "V8Class.h" extern V8Class v8MapZoomData; diff --git a/client/src/bindings/MemoryBuffer.cpp b/client/src/bindings/MemoryBuffer.cpp index 12609873..9bb4e9ca 100644 --- a/client/src/bindings/MemoryBuffer.cpp +++ b/client/src/bindings/MemoryBuffer.cpp @@ -1,6 +1,6 @@ #include "../CV8Resource.h" -#include "../helpers/V8Class.h" +#include "V8Class.h" //static void weakCallbackForObjectHolder(const v8::WeakCallbackInfo& data) { // uint8_t* memory = (uint8_t*)data.GetInternalField(0); diff --git a/client/src/bindings/Player.cpp b/client/src/bindings/Player.cpp index da3256da..be460ab6 100644 --- a/client/src/bindings/Player.cpp +++ b/client/src/bindings/Player.cpp @@ -1,9 +1,9 @@ -#include "../helpers/V8Helpers.h" -#include "../helpers/V8BindHelpers.h" -#include "../helpers/V8Class.h" -#include "../helpers/V8Entity.h" -#include "../helpers/V8ResourceImpl.h" +#include "V8Helpers.h" +#include "V8BindHelpers.h" +#include "V8Class.h" +#include "V8Entity.h" +#include "V8ResourceImpl.h" #include "../CV8ScriptRuntime.h" diff --git a/client/src/bindings/Profiler.cpp b/client/src/bindings/Profiler.cpp index f880c05d..56a8b20b 100644 --- a/client/src/bindings/Profiler.cpp +++ b/client/src/bindings/Profiler.cpp @@ -1,5 +1,5 @@ -#include "../helpers/V8Helpers.h" -#include "../helpers/V8Class.h" +#include "V8Helpers.h" +#include "V8Class.h" #include "../CV8ScriptRuntime.h" #include "v8-profiler.h" #include diff --git a/client/src/bindings/V8Natives.cpp b/client/src/bindings/V8Natives.cpp index d8b87591..db050249 100644 --- a/client/src/bindings/V8Natives.cpp +++ b/client/src/bindings/V8Natives.cpp @@ -1,8 +1,8 @@ -#include "../helpers/V8Helpers.h" -#include "../helpers/V8Module.h" -#include "../helpers/Log.h" -#include "../helpers/V8ResourceImpl.h" +#include "V8Helpers.h" +#include "V8Module.h" +#include "Log.h" +#include "V8ResourceImpl.h" static uint64_t pointers[32]; static uint32_t pointersCount = 0; diff --git a/client/src/bindings/Vehicle.cpp b/client/src/bindings/Vehicle.cpp index 6aad19ae..92d751b1 100644 --- a/client/src/bindings/Vehicle.cpp +++ b/client/src/bindings/Vehicle.cpp @@ -1,9 +1,9 @@ -#include "../helpers/V8Helpers.h" -#include "../helpers/V8BindHelpers.h" -#include "../helpers/V8Class.h" -#include "../helpers/V8Entity.h" -#include "../helpers/V8ResourceImpl.h" +#include "V8Helpers.h" +#include "V8BindHelpers.h" +#include "V8Class.h" +#include "V8Entity.h" +#include "V8ResourceImpl.h" #include "../CV8ScriptRuntime.h" diff --git a/client/src/bindings/Voice.cpp b/client/src/bindings/Voice.cpp index f737cdf2..1f3fb443 100644 --- a/client/src/bindings/Voice.cpp +++ b/client/src/bindings/Voice.cpp @@ -1,7 +1,7 @@ -#include "../helpers/V8Helpers.h" -#include "../helpers/V8ResourceImpl.h" -#include "../helpers/V8Class.h" +#include "V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8Class.h" static void StaticGetInputMuted(v8::Local, const v8::PropertyCallbackInfo &info) { diff --git a/client/src/bindings/WebSocketClient.cpp b/client/src/bindings/WebSocketClient.cpp index dbb3179b..84763fa2 100644 --- a/client/src/bindings/WebSocketClient.cpp +++ b/client/src/bindings/WebSocketClient.cpp @@ -1,8 +1,8 @@ -#include "../helpers/V8Helpers.h" -#include "../helpers/V8BindHelpers.h" -#include "../helpers/V8Class.h" -#include "../helpers/V8Entity.h" -#include "../helpers/V8ResourceImpl.h" +#include "V8Helpers.h" +#include "V8BindHelpers.h" +#include "V8Class.h" +#include "V8Entity.h" +#include "V8ResourceImpl.h" #include "../CV8Resource.h" #include "cpp-sdk/script-objects/IWebView.h" diff --git a/client/src/bindings/WebView.cpp b/client/src/bindings/WebView.cpp index f96bb364..a89d41b9 100644 --- a/client/src/bindings/WebView.cpp +++ b/client/src/bindings/WebView.cpp @@ -1,9 +1,9 @@ -#include "../helpers/V8Helpers.h" -#include "../helpers/V8BindHelpers.h" -#include "../helpers/V8Class.h" -#include "../helpers/V8Entity.h" -#include "../helpers/V8ResourceImpl.h" +#include "V8Helpers.h" +#include "V8BindHelpers.h" +#include "V8Class.h" +#include "V8Entity.h" +#include "V8ResourceImpl.h" #include "../CV8Resource.h" #include "cpp-sdk/script-objects/IWebView.h" diff --git a/client/src/events/Entity.cpp b/client/src/events/Entity.cpp index f192f941..66db5dcb 100644 --- a/client/src/events/Entity.cpp +++ b/client/src/events/Entity.cpp @@ -1,5 +1,5 @@ -#include "../helpers/V8ResourceImpl.h" -#include "../helpers/V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8Helpers.h" #include "../CV8ScriptRuntime.h" diff --git a/client/src/events/Events.h b/client/src/events/Events.h index b39d4ecf..066c2076 100644 --- a/client/src/events/Events.h +++ b/client/src/events/Events.h @@ -1,6 +1,6 @@ #pragma once -#include "../helpers/V8Helpers.h" +#include "V8Helpers.h" /** * Needed cause MSVC requires globals to be references diff --git a/client/src/events/Main.cpp b/client/src/events/Main.cpp index 86ea1587..0ba2f383 100644 --- a/client/src/events/Main.cpp +++ b/client/src/events/Main.cpp @@ -1,8 +1,8 @@ #include "../CV8Resource.h" #include "../CV8ScriptRuntime.h" -#include "../helpers/V8ResourceImpl.h" -#include "../helpers/V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8Helpers.h" #include "cpp-sdk/events/CConnectionComplete.h" #include "cpp-sdk/events/CDisconnectEvent.h" diff --git a/client/src/events/Meta.cpp b/client/src/events/Meta.cpp index 1a51bbd5..e5da1171 100644 --- a/client/src/events/Meta.cpp +++ b/client/src/events/Meta.cpp @@ -1,5 +1,5 @@ -#include "../helpers/V8ResourceImpl.h" -#include "../helpers/V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8Helpers.h" #include "cpp-sdk/events/CSyncedMetaDataChangeEvent.h" #include "cpp-sdk/events/CStreamSyncedMetaDataChangeEvent.h" diff --git a/client/src/events/Resource.cpp b/client/src/events/Resource.cpp index b3aec7b6..73535a5f 100644 --- a/client/src/events/Resource.cpp +++ b/client/src/events/Resource.cpp @@ -1,5 +1,5 @@ -#include "../helpers/V8ResourceImpl.h" -#include "../helpers/V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8Helpers.h" #include "cpp-sdk/events/CResourceStartEvent.h" #include "cpp-sdk/events/CResourceStopEvent.h" diff --git a/client/src/events/Vehicle.cpp b/client/src/events/Vehicle.cpp index d06c4e64..ebc43309 100644 --- a/client/src/events/Vehicle.cpp +++ b/client/src/events/Vehicle.cpp @@ -1,5 +1,5 @@ -#include "../helpers/V8ResourceImpl.h" -#include "../helpers/V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8Helpers.h" #include "cpp-sdk/events/CPlayerEnterVehicleEvent.h" #include "cpp-sdk/events/CPlayerLeaveVehicleEvent.h" diff --git a/client/src/helpers b/client/src/helpers deleted file mode 160000 index 36706536..00000000 --- a/client/src/helpers +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3670653662f3ac42d87e93cd40fd260e487c693d diff --git a/client/src/main.cpp b/client/src/main.cpp index 0d9a9ec6..6452a299 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -1,6 +1,6 @@ #include "cpp-sdk/SDK.h" #include "CV8ScriptRuntime.h" -#include "helpers/Log.h" +#include "Log.h" #ifdef ALTV_JS_SHARED #define ALTV_JS_EXPORT extern "C" __declspec(dllexport) diff --git a/server/.gitmodules b/server/.gitmodules deleted file mode 100644 index 9d9c47af..00000000 --- a/server/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "src/helpers"] - path = server/src/helpers - url = https://github.com/altmp/v8-helpers.git -[submodule "src/cpp-sdk"] - path = server/src/cpp-sdk - url = https://github.com/altmp/cpp-sdk.git diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 955de70a..bb0712f7 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -33,6 +33,7 @@ add_definitions(-DHAVE_INSPECTOR=1) add_definitions(-DALT_SERVER_API) file(GLOB_RECURSE PROJECT_SOURCE_FILES "src/*.h" "src/*.hpp" "src/*.cpp") +file(GLOB_RECURSE PROJECT_SHARED_FILES "../shared/*.h" "../shared/*.cpp") macro(GroupSources curdir groupindex) file(GLOB children RELATIVE ${curdir} ${curdir}/*) @@ -53,11 +54,11 @@ GroupSources(${PROJECT_SOURCE_DIR}/src "Source Files") include_directories( src - src/api - src/fivenet-shared/src deps/nodejs/include deps/nodejs/deps/v8/include deps/nodejs/deps/uv/include + ../shared + ../shared/deps ) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") @@ -121,6 +122,7 @@ link_directories( add_library( ${PROJECT_NAME} SHARED ${PROJECT_SOURCE_FILES} + ${PROJECT_SHARED_FILES} ) if (WIN32) diff --git a/server/src/CNodeResourceImpl.h b/server/src/CNodeResourceImpl.h index 70dedf84..d8336340 100644 --- a/server/src/CNodeResourceImpl.h +++ b/server/src/CNodeResourceImpl.h @@ -4,9 +4,9 @@ #include "cpp-sdk/IPackage.h" #include "cpp-sdk/IResource.h" -#include "helpers/V8ResourceImpl.h" -#include "helpers/V8Entity.h" -#include "helpers/V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8Entity.h" +#include "V8Helpers.h" #include "node.h" #include "uv.h" diff --git a/server/src/CNodeScriptRuntime.h b/server/src/CNodeScriptRuntime.h index 23a69abd..f7357564 100644 --- a/server/src/CNodeScriptRuntime.h +++ b/server/src/CNodeScriptRuntime.h @@ -3,7 +3,7 @@ #include "cpp-sdk/IScriptRuntime.h" #include "cpp-sdk/events/CRemoveEntityEvent.h" -#include "helpers/V8Helpers.h" +#include "V8Helpers.h" #include "CNodeResourceImpl.h" class CNodeScriptRuntime : public alt::IScriptRuntime diff --git a/server/src/bindings/Blip.cpp b/server/src/bindings/Blip.cpp index 91ddd65a..e70d5d6b 100644 --- a/server/src/bindings/Blip.cpp +++ b/server/src/bindings/Blip.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" -#include "helpers/V8Helpers.h" -#include "helpers/V8ResourceImpl.h" +#include "V8Helpers.h" +#include "V8ResourceImpl.h" using namespace alt; diff --git a/server/src/bindings/Checkpoint.cpp b/server/src/bindings/Checkpoint.cpp index a93326df..aebb9168 100644 --- a/server/src/bindings/Checkpoint.cpp +++ b/server/src/bindings/Checkpoint.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" -#include "helpers/V8Helpers.h" -#include "helpers/V8ResourceImpl.h" +#include "V8Helpers.h" +#include "V8ResourceImpl.h" using namespace alt; diff --git a/server/src/bindings/ColShape.cpp b/server/src/bindings/ColShape.cpp index 37e149d4..a89c63de 100755 --- a/server/src/bindings/ColShape.cpp +++ b/server/src/bindings/ColShape.cpp @@ -1,8 +1,8 @@ #include "stdafx.h" -#include "helpers/V8Helpers.h" -#include "helpers/V8BindHelpers.h" -#include "helpers/V8ResourceImpl.h" +#include "V8Helpers.h" +#include "V8BindHelpers.h" +#include "V8ResourceImpl.h" using namespace alt; diff --git a/server/src/bindings/Main.cpp b/server/src/bindings/Main.cpp index 380e8495..c80916eb 100644 --- a/server/src/bindings/Main.cpp +++ b/server/src/bindings/Main.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" -#include "helpers/V8Module.h" +#include "V8Module.h" #include "CNodeResourceImpl.h" using namespace alt; diff --git a/server/src/bindings/Player.cpp b/server/src/bindings/Player.cpp index 1a074214..dc3ebef8 100644 --- a/server/src/bindings/Player.cpp +++ b/server/src/bindings/Player.cpp @@ -1,8 +1,8 @@ #include "stdafx.h" -#include "helpers/V8Helpers.h" -#include "helpers/V8ResourceImpl.h" -#include "helpers/V8BindHelpers.h" +#include "V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8BindHelpers.h" using namespace alt; diff --git a/server/src/bindings/Vehicle.cpp b/server/src/bindings/Vehicle.cpp index 4d14ff38..8ef261df 100644 --- a/server/src/bindings/Vehicle.cpp +++ b/server/src/bindings/Vehicle.cpp @@ -1,8 +1,8 @@ #include "stdafx.h" -#include "helpers/V8Helpers.h" -#include "helpers/V8ResourceImpl.h" -#include "helpers/V8BindHelpers.h" +#include "V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8BindHelpers.h" using namespace alt; diff --git a/server/src/bindings/VoiceChannel.cpp b/server/src/bindings/VoiceChannel.cpp index f4382f3b..a0bef1de 100644 --- a/server/src/bindings/VoiceChannel.cpp +++ b/server/src/bindings/VoiceChannel.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" -#include "helpers/V8Helpers.h" -#include "helpers/V8ResourceImpl.h" +#include "V8Helpers.h" +#include "V8ResourceImpl.h" using namespace alt; diff --git a/server/src/events/Main.cpp b/server/src/events/Main.cpp index c091036b..cf4c44ca 100644 --- a/server/src/events/Main.cpp +++ b/server/src/events/Main.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" -#include "helpers/V8ResourceImpl.h" -#include "helpers/V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8Helpers.h" #include "cpp-sdk/events/CClientScriptEvent.h" #include "cpp-sdk/events/CServerScriptEvent.h" diff --git a/server/src/events/Player.cpp b/server/src/events/Player.cpp index a994eaf2..a1d8b31f 100644 --- a/server/src/events/Player.cpp +++ b/server/src/events/Player.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" -#include "helpers/V8ResourceImpl.h" -#include "helpers/V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8Helpers.h" #include "cpp-sdk/events/CPlayerConnectEvent.h" #include "cpp-sdk/events/CPlayerDisconnectEvent.h" diff --git a/server/src/events/Vehicle.cpp b/server/src/events/Vehicle.cpp index e36117c8..b064c9ad 100644 --- a/server/src/events/Vehicle.cpp +++ b/server/src/events/Vehicle.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" -#include "helpers/V8ResourceImpl.h" -#include "helpers/V8Helpers.h" +#include "V8ResourceImpl.h" +#include "V8Helpers.h" #include "cpp-sdk/events/CVehicleAttachEvent.h" #include "cpp-sdk/events/CVehicleDetachEvent.h" diff --git a/server/src/helpers b/server/src/helpers deleted file mode 160000 index 36706536..00000000 --- a/server/src/helpers +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3670653662f3ac42d87e93cd40fd260e487c693d diff --git a/server/src/node-module.cpp b/server/src/node-module.cpp index c480e932..415dbfcb 100644 --- a/server/src/node-module.cpp +++ b/server/src/node-module.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" -#include "helpers/V8Module.h" +#include "V8Module.h" #include "CNodeScriptRuntime.h" /*static void NodeStop() diff --git a/server/src/stdafx.h b/server/src/stdafx.h index ed2828fb..3d8c95a2 100644 --- a/server/src/stdafx.h +++ b/server/src/stdafx.h @@ -1,9 +1,9 @@ #pragma once -#define JS_MODULE_COPYRIGHT u8"Copyright © 2020 altMP team." +#define JS_MODULE_COPYRIGHT u8"Copyright � 2020 altMP team." #define NODEJS_VERSION u8"v12.4.0" -#define NODEJS_COPYRIGHT u8"Copyright © 2020 Node.js Foundation." +#define NODEJS_COPYRIGHT u8"Copyright � 2020 Node.js Foundation." #define NODE_WANT_INTERNALS 1 @@ -18,7 +18,7 @@ #include #include "cpp-sdk/SDK.h" -#include "helpers/Log.h" +#include "Log.h" #include "node.h" #include "node_platform.h" #include "node_internals.h" diff --git a/server/src/cpp-sdk b/shared/deps/cpp-sdk similarity index 100% rename from server/src/cpp-sdk rename to shared/deps/cpp-sdk From 853aa191b726fa59c72fe2a0e1c912a6d09133c4 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 20:50:54 +0200 Subject: [PATCH 550/564] Remove unneeded includes path from client Former-commit-id: 405ea7ff9ddf863e5d0cbf3c4af73824bada6639 --- client/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 0f1c5a6f..25949532 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -47,7 +47,6 @@ GroupSources("../shared" "Shared Files") include_directories( ${ALTV_JS_CPP_SDK} ${ALTV_JS_DL_DEPS}/include - ${PROJECT_SOURCE_DIR} ../shared ) From c46009d6378ba3655f0118b76e9009445aacbe83 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 20:55:00 +0200 Subject: [PATCH 551/564] Add GroupSources for shared files in server CMakeLists Former-commit-id: ff029d6c4077966bfd98d077458a8268ee9d3406 --- server/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index bb0712f7..00c78ad3 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -51,6 +51,7 @@ macro(GroupSources curdir groupindex) endmacro() GroupSources(${PROJECT_SOURCE_DIR}/src "Source Files") +GroupSources("../shared" "Shared Files") include_directories( src From 66208b3f8af36b94b8c6b4fdae1916403f7e45f5 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 20:58:58 +0200 Subject: [PATCH 552/564] Remove unneeded files Former-commit-id: cad41b558507f35b234825d4bf0d4eca34b17bc0 --- client/src/V8Entity.h | 0 server/src/Log.h | 89 ------------------------------------------- 2 files changed, 89 deletions(-) delete mode 100644 client/src/V8Entity.h delete mode 100644 server/src/Log.h diff --git a/client/src/V8Entity.h b/client/src/V8Entity.h deleted file mode 100644 index e69de29b..00000000 diff --git a/server/src/Log.h b/server/src/Log.h deleted file mode 100644 index f27babf4..00000000 --- a/server/src/Log.h +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once - -#include -#include "cpp-sdk/ICore.h" - -class Log -{ - std::stringstream buf; - - typedef Log&(*LogFn)(Log&); - static Log* _Instance; - - enum Type - { - INFO, - DEBUG, - WARNING, - ERROR, - COLORED - } type = INFO; - - Log() = default; - -public: - Log(const Log&) = delete; - Log(Log&&) = delete; - Log& operator=(const Log&) = delete; - - template Log& Put(const T& val) { buf << val; return *this; } - Log& Put(LogFn val) { return val(*this); } - Log& SetType(Type _type) { type = _type; return *this; } - template Log& operator<<(const T& val) { return Put(val); } - - static constexpr struct Log_Info - { - template Log& operator<<(const T& val) const { return Instance().SetType(INFO).Put(val); } - } Info{}; - - static constexpr struct Log_Debug - { - template Log& operator<<(const T& val) const { return Instance().SetType(DEBUG).Put(val); } - } Debug{}; - - static constexpr struct Log_Warning - { - template Log& operator<<(const T& val) const { return Instance().SetType(WARNING).Put(val); } - } Warning{}; - - static constexpr struct Log_Error - { - template Log& operator<<(const T& val) const { return Instance().SetType(ERROR).Put(val); } - } Error{}; - - static constexpr struct Log_Colored - { - template Log& operator<<(const T& val) const { return Instance().SetType(COLORED).Put(val); } - } Colored{}; - - static Log& Endl(Log& log) - { - switch (log.type) - { - case INFO: - alt::ICore::Instance().LogInfo(log.buf.str()); - break; - case DEBUG: - alt::ICore::Instance().LogDebug(log.buf.str().c_str()); - break; - case WARNING: - alt::ICore::Instance().LogWarning(log.buf.str().c_str()); - break; - case ERROR: - alt::ICore::Instance().LogError(log.buf.str().c_str()); - break; - case COLORED: - alt::ICore::Instance().LogColored(log.buf.str().c_str()); - break; - } - - log.buf.str(""); - return log; - } - - static Log& Instance() - { - static Log _Instance; - return _Instance; - } -}; \ No newline at end of file From bb4dd8b1842d6560bec8aaeec48d3dae852c2025 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 21:17:10 +0200 Subject: [PATCH 553/564] Fix workflows wrong working directory Former-commit-id: 922a8786ef34f5de0863a73e06f3d3dcac0fc9f4 --- .github/workflows/test-client.yml | 8 ++++++-- .github/workflows/test-server.yml | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-client.yml b/.github/workflows/test-client.yml index eb768f62..03f8ddd4 100644 --- a/.github/workflows/test-client.yml +++ b/.github/workflows/test-client.yml @@ -25,9 +25,13 @@ jobs: - name: Generate shell: bash - run: cmake . -BBUILD + run: | + cd client + cmake . -BBUILD - name: Build shell: bash - run: cmake --build BUILD --config $BUILD_TYPE + run: | + cd client + cmake --build BUILD --config $BUILD_TYPE diff --git a/.github/workflows/test-server.yml b/.github/workflows/test-server.yml index 1d31c8b1..2ff1b2d5 100644 --- a/.github/workflows/test-server.yml +++ b/.github/workflows/test-server.yml @@ -21,6 +21,7 @@ jobs: - name: Build shell: cmd run: | + cd server mkdir build pushd build cmake -G"Visual Studio 16" -A x64 .. @@ -41,6 +42,7 @@ jobs: sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install gcc-8 g++-8 + cd server mkdir build-linux && cd build-linux cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++-8 .. cmake --build . --config Release From acaa86416cf8667ac35df72f4f8252d7b335e20e Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 21:18:50 +0200 Subject: [PATCH 554/564] Fix workflow title for server workflow Former-commit-id: b64090bd377b24310d7e11c1d76b6544793d3590 --- .github/workflows/test-server.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-server.yml b/.github/workflows/test-server.yml index 2ff1b2d5..9a8349f1 100644 --- a/.github/workflows/test-server.yml +++ b/.github/workflows/test-server.yml @@ -1,4 +1,4 @@ -name: Test client changes +name: Test server changes on: push: paths: From a550b028349ec8922fdf0485c1bbdc3d92075856 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 11 Sep 2021 21:23:15 +0200 Subject: [PATCH 555/564] Fix build & deploy workflow paths Former-commit-id: dbbd80915a1a40e3bf59f5be05b54c2d54e13a4a --- .github/workflows/build-deploy.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml index 2ad684af..1d49cf18 100644 --- a/.github/workflows/build-deploy.yml +++ b/.github/workflows/build-deploy.yml @@ -30,6 +30,7 @@ jobs: - name: Build shell: cmd run: | + cd server mkdir build pushd build cmake -G"Visual Studio 16" -A x64 -DJS_MODULE_VERSION=%VERSION% .. @@ -44,7 +45,7 @@ jobs: - uses: actions/upload-artifact@v2 with: name: js-module-windows - path: ./dist/ + path: ./server/dist/ build-linux: name: Build linux release @@ -66,6 +67,7 @@ jobs: - name: Build run: | + cd server sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install gcc-8 g++-8 @@ -82,7 +84,7 @@ jobs: - uses: actions/upload-artifact@v2 with: name: js-module-linux - path: ./dist/ + path: ./server/dist/ deploy-cdn: name: Deploy release to alt:V CDN From 9ef43a8625bd68de9db52bdafca448d58318209a Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 12 Sep 2021 00:33:23 +0200 Subject: [PATCH 556/564] Add README Former-commit-id: 73770e46ff7f2a91bc3904968a10a3401eb9e1ab --- .vscode/c_cpp_properties.json | 39 ++++++++++++++++++----------------- README.md | 18 ++++++++++++++++ docs/README.md | 1 + 3 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 README.md create mode 100644 docs/README.md diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 98f3c2ab..3e78c6f3 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,20 +1,21 @@ { - "configurations": [ - { - "name": "Win32 Static", - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE", - "ALT_CLIENT_API", - "ALT_CLIENT", - "ALT_SERVER_API", - "ALT_SERVER" - ], - "windowsSdkVersion": "10.0.19041.0", - "cppStandard": "c++17", - "intelliSenseMode": "msvc-x64" - } - ], - "version": 4 -} + "configurations": [ + { + "name": "Win32 Static", + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE", + "ALT_CLIENT_API", + "ALT_CLIENT", + "ALT_SERVER_API", + "ALT_SERVER" + ], + "windowsSdkVersion": "10.0.19041.0", + "cppStandard": "c++17", + "intelliSenseMode": "msvc-x64", + "configurationProvider": "ms-vscode.cmake-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 00000000..ca0f21b8 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# alt:V JS module + +Repository containing the JS module for [alt:V multiplayer](https://altv.mp/). + +## Structure + +| Directory | Description | +| ------------------ | ------------------------------------------------------- | +| [/client](/client) | Clientside JS module powered by V8 | +| [/server](/server) | Serverside JS module powered by Node.js | +| [/shared](/shared) | Shared code for the clientside & serverside module | +| [/docs](/docs) | Documentation for the internal workings of the module | + +## Contributions + +All contributions are greatly appreciated. +If there are any questions or you would like to discuss a feature, +contact the *module maintainer*. diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..1a1aebed --- /dev/null +++ b/docs/README.md @@ -0,0 +1 @@ +# WIP \ No newline at end of file From 0cfc48b172829bb63f5d3c8f089b77329bc8567d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sun, 12 Sep 2021 14:26:11 +0200 Subject: [PATCH 557/564] Add includePaths for VSCode Former-commit-id: f68c863677230a587a19e87b39bf4f45d39c5615 --- .vscode/c_cpp_properties.json | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 3e78c6f3..3cc4d515 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -14,7 +14,18 @@ "windowsSdkVersion": "10.0.19041.0", "cppStandard": "c++17", "intelliSenseMode": "msvc-x64", - "configurationProvider": "ms-vscode.cmake-tools" + "configurationProvider": "ms-vscode.cmake-tools", + "includePath": [ + "client/src", + "client/BUILD/_deps/altv-js-deps-src/include", + "server/src", + "server/deps", + "server/deps/nodejs/include", + "server/deps/nodejs/deps/v8/include", + "server/deps/nodejs/deps/uv/include", + "shared/", + "shared/deps" + ] } ], "version": 4 From 79bf3b0773797503018267393b366a21b2260e6d Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 13 Sep 2021 22:08:09 +0200 Subject: [PATCH 558/564] Add JS_MODULE_VERSION define to VSCode config to supress error Former-commit-id: 37676567c6d9bc39f4079bdbd66c64a6aaa33192 --- .vscode/c_cpp_properties.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 3cc4d515..3cd1c7bf 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -9,7 +9,8 @@ "ALT_CLIENT_API", "ALT_CLIENT", "ALT_SERVER_API", - "ALT_SERVER" + "ALT_SERVER", + "JS_MODULE_VERSION" ], "windowsSdkVersion": "10.0.19041.0", "cppStandard": "c++17", From c690033b51ff6bf299edd113f47ec825e2612d14 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 13 Sep 2021 22:11:11 +0200 Subject: [PATCH 559/564] Fix NodeJS version displayed in js-module command Former-commit-id: bff89ae432d1ff576f46bb0ef141cc05e1a149d0 --- server/src/node-module.cpp | 2 +- server/src/stdafx.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/server/src/node-module.cpp b/server/src/node-module.cpp index 415dbfcb..ef090a47 100644 --- a/server/src/node-module.cpp +++ b/server/src/node-module.cpp @@ -57,7 +57,7 @@ static void CommandHandler(alt::Array args, void* userData) Log::Colored << "~ly~js-module: " << JS_MODULE_VERSION << Log::Endl; Log::Colored << "~ly~" JS_MODULE_COPYRIGHT << Log::Endl; - Log::Colored << "~ly~nodejs: " NODEJS_VERSION << Log::Endl; + Log::Colored << "~ly~nodejs: " << NODE_MAJOR_VERSION << "." << NODE_MINOR_VERSION << "." << NODE_PATCH_VERSION << Log::Endl; Log::Colored << "~ly~" NODEJS_COPYRIGHT << Log::Endl; } else if (args.GetSize() > 0 && args[0] == "--help") diff --git a/server/src/stdafx.h b/server/src/stdafx.h index 3d8c95a2..0161a32e 100644 --- a/server/src/stdafx.h +++ b/server/src/stdafx.h @@ -2,7 +2,6 @@ #define JS_MODULE_COPYRIGHT u8"Copyright � 2020 altMP team." -#define NODEJS_VERSION u8"v12.4.0" #define NODEJS_COPYRIGHT u8"Copyright � 2020 Node.js Foundation." #define NODE_WANT_INTERNALS 1 From 187f4fcc255ae1ccec6df6ea46c44c596bd7b158 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 13 Sep 2021 22:11:41 +0200 Subject: [PATCH 560/564] Use new instead of deprecated API for getting context Former-commit-id: 253ab2c5c3d08983086a1b0dfca20b9b1481bb67 --- server/src/node-module.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/node-module.cpp b/server/src/node-module.cpp index ef090a47..62d4b7c0 100644 --- a/server/src/node-module.cpp +++ b/server/src/node-module.cpp @@ -32,7 +32,7 @@ static void Initialize(v8::Local exports) v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope handle_scope(isolate); - v8Alt.Register(isolate, isolate->GetEnteredContext(), exports); + v8Alt.Register(isolate, isolate->GetEnteredOrMicrotaskContext(), exports); } NODE_MODULE_LINKED(alt, Initialize) } @@ -45,7 +45,7 @@ static void InitializeShared(v8::Local exports) v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope handle_scope(isolate); - sharedModule.Register(isolate, isolate->GetEnteredContext(), exports); + sharedModule.Register(isolate, isolate->GetEnteredOrMicrotaskContext(), exports); } NODE_MODULE_LINKED(altShared, InitializeShared) } From 9e4e1c3a182471b35872dd5847908a22cde5e015 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Mon, 13 Sep 2021 22:17:15 +0200 Subject: [PATCH 561/564] Specify JS module version as DEV during debug builds Former-commit-id: bb36575b1c40f5dc6f970ccec682cea9cb2353f9 --- server/build.bat | 2 +- server/build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/build.bat b/server/build.bat index dbef7704..881a036d 100644 --- a/server/build.bat +++ b/server/build.bat @@ -1,7 +1,7 @@ @echo off mkdir build pushd build -cmake -G"Visual Studio 16" -A x64 .. +cmake -G"Visual Studio 16" -A x64 -DJS_MODULE_VERSION=DEV .. cmake --build . --config Release popd diff --git a/server/build.sh b/server/build.sh index 2c20e915..8cf631fa 100644 --- a/server/build.sh +++ b/server/build.sh @@ -1,5 +1,5 @@ mkdir build-linux cd build-linux -cmake -DCMAKE_BUILD_TYPE=Release .. +cmake -DCMAKE_BUILD_TYPE=Release -DJS_MODULE_VERSION=DEV .. cmake --build . --config Release cd .. From 97e01449d444f098e0cded81b847a89b4503f02d Mon Sep 17 00:00:00 2001 From: Vektor Date: Fri, 17 Sep 2021 12:39:39 +0200 Subject: [PATCH 562/564] added setWatermarkPosition Former-commit-id: dabebf1602c1ec1f00800b80a2eb6df39450faa5 --- client/src/bindings/Main.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/client/src/bindings/Main.cpp b/client/src/bindings/Main.cpp index a518ebef..7e496165 100644 --- a/client/src/bindings/Main.cpp +++ b/client/src/bindings/Main.cpp @@ -836,6 +836,16 @@ static void ClearPedProps(const v8::FunctionCallbackInfo& info) alt::ICore::Instance().ClearProps(scriptId, component); } +static void SetWatermarkPosition(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(1); + + V8_ARG_TO_INT(1, pos); + + alt::ICore::Instance().SetWatermarkPosition(pos); +} + extern V8Module sharedModule; extern V8Class v8Player, v8Player, @@ -971,4 +981,6 @@ extern V8Module altModule( V8Helpers::RegisterFunc(exports, "setPedDlcClothes", &SetPedDlcClothes); V8Helpers::RegisterFunc(exports, "setPedDlcProp", &SetPedDlcProps); V8Helpers::RegisterFunc(exports, "clearPedProp", &ClearPedProps); + + V8Helpers::RegisterFunc(exports, "setWatermarkPosition", &SetWatermarkPosition); }); From d0a8fc5cb11d6ef775b8d521724fd1c32eefcab8 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 18 Sep 2021 19:01:20 +0200 Subject: [PATCH 563/564] [client] add blip.scriptID Former-commit-id: 17949ded2461522286aaebf50f5ed6de5d0485db --- client/src/bindings/Blip.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/src/bindings/Blip.cpp b/client/src/bindings/Blip.cpp index d6c47cfd..6070a1a9 100644 --- a/client/src/bindings/Blip.cpp +++ b/client/src/bindings/Blip.cpp @@ -174,6 +174,8 @@ extern V8Class v8Blip("Blip", v8WorldObject, Constructor, [](v8::Local(isolate, tpl, "highDetail"); V8::SetAccessor(isolate, tpl, "shrinked"); + V8::SetAccessor(isolate, tpl, "scriptID"); + V8::SetMethod(isolate, tpl, "fade", &Fade); }); From a1d4a3179d974a11af58b7b14372298ec8ee17ed Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 18 Sep 2021 19:12:09 +0200 Subject: [PATCH 564/564] update cpp-sdk Former-commit-id: 0f03600114422331c3e98edda9ace127a863aeed --- shared/deps/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/deps/cpp-sdk b/shared/deps/cpp-sdk index a241a745..eee1380f 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit a241a74587d2b33dfe5156e6b97ada1838e78a14 +Subproject commit eee1380f901c0650595d3298d15ef9e734650bd8