diff --git a/lib/Red/TypeInfo/Resolving.hpp b/lib/Red/TypeInfo/Resolving.hpp index 2db21edd..d598f720 100644 --- a/lib/Red/TypeInfo/Resolving.hpp +++ b/lib/Red/TypeInfo/Resolving.hpp @@ -498,7 +498,7 @@ inline const Handle& Cast(const Handle& aObject) } template -inline const WeakHandle& Cast(const WeakHandle& aObject) +inline const WeakHandle& CastWeak(const WeakHandle& aObject) { static const WeakHandle s_null; return (aObject && aObject.instance->GetType()->IsA(Red::GetClass())) diff --git a/scripts/Callback/Events/VehicleLightControlEvent.reds b/scripts/Callback/Events/VehicleLightControlEvent.reds new file mode 100644 index 00000000..8dca8e9c --- /dev/null +++ b/scripts/Callback/Events/VehicleLightControlEvent.reds @@ -0,0 +1,5 @@ +public native class VehicleLightControlEvent extends EntityLifecycleEvent { + public native func IsEnabled() -> Bool + public native func GetLightType() -> vehicleELightType + public native func IsLightType(lightType: vehicleELightType) -> Bool +} diff --git a/src/App/Callback/CallbackSystem.cpp b/src/App/Callback/CallbackSystem.cpp index 409c078a..9528effb 100644 --- a/src/App/Callback/CallbackSystem.cpp +++ b/src/App/Callback/CallbackSystem.cpp @@ -6,9 +6,10 @@ #include "App/Callback/Controllers/EntityReassembleHook.hpp" #include "App/Callback/Controllers/EntityUninitializeHook.hpp" #include "App/Callback/Controllers/PlayerSpawnedHook.hpp" +#include "App/Callback/Controllers/RawInputHook.hpp" #include "App/Callback/Controllers/ResourceLoadHook.hpp" #include "App/Callback/Controllers/ResourceReadyHook.hpp" -#include "App/Callback/Controllers/RawInputHook.hpp" +#include "App/Callback/Controllers/VehicleLightControlHook.hpp" #include "App/Callback/Events/GameSessionEvent.hpp" #include "App/Scripting/ScriptableService.hpp" #include "Red/InkSystem.hpp" @@ -23,6 +24,7 @@ App::CallbackSystem::CallbackSystem() RegisterController(); RegisterController(); RegisterController(); + RegisterController(); RegisterController(); RegisterController(); RegisterController(); diff --git a/src/App/Callback/Controllers/VehicleLightControlHook.hpp b/src/App/Callback/Controllers/VehicleLightControlHook.hpp new file mode 100644 index 00000000..1232efd2 --- /dev/null +++ b/src/App/Callback/Controllers/VehicleLightControlHook.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include "App/Callback/CallbackSystem.hpp" +#include "App/Callback/CallbackSystemController.hpp" +#include "App/Callback/Events/VehicleLightControlEvent.hpp" +#include "Core/Hooking/HookingAgent.hpp" +#include "Red/VehicleController.hpp" + +namespace App +{ +class VehicleLightControlHook + : public CallbackSystemController + , public Core::HookingAgent +{ +public: + constexpr static auto EventName = Red::CName("Vehicle/ToggleLights"); + + Core::Map GetEvents() override + { + return {{EventName, Red::GetTypeName()}}; + } + +protected: + bool OnActivateHook() override + { + return IsHooked() || HookAfter(&OnToggleLights); + } + + bool OnDeactivateHook() override + { + return !IsHooked() || Unhook(); + } + + inline static void OnToggleLights(Red::vehicleController* aController, bool aEnable, Red::vehicleELightType aLightType) + { + CallbackSystem::Get()->DispatchNativeEvent(EventName, Red::AsWeakHandle(aController->owner), aEnable, aLightType); + } +}; +} diff --git a/src/App/Callback/Events/VehicleLightControlEvent.hpp b/src/App/Callback/Events/VehicleLightControlEvent.hpp new file mode 100644 index 00000000..ec3eedee --- /dev/null +++ b/src/App/Callback/Events/VehicleLightControlEvent.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include "App/Callback/CallbackSystemEvent.hpp" +#include "App/Callback/Events/EntityLifecycleEvent.hpp" + +namespace App +{ +struct VehicleLightControlEvent : EntityLifecycleEvent +{ + VehicleLightControlEvent() = default; + + VehicleLightControlEvent(Red::CName aName, Red::WeakHandle aEntity, + bool aEnable, Red::vehicleELightType aLightType) + : EntityLifecycleEvent(aName, std::move(aEntity)) + , enabled(aEnable) + , lightType(aLightType) + { + } + + [[nodiscard]] bool IsLightType(Red::vehicleELightType aLightType) const + { + return (static_cast(lightType) & static_cast(aLightType)) != 0; + } + + bool enabled; + Red::vehicleELightType lightType; + + RTTI_IMPL_TYPEINFO(App::VehicleLightControlEvent); + RTTI_IMPL_ALLOCATOR(); +}; +} + +RTTI_DEFINE_CLASS(App::VehicleLightControlEvent, { + RTTI_PARENT(App::EntityLifecycleEvent); + RTTI_METHOD(IsLightType); + RTTI_GETTER(enabled); + RTTI_GETTER(lightType); +}); diff --git a/src/App/Callback/Targets/EntityTarget.hpp b/src/App/Callback/Targets/EntityTarget.hpp index 6d7e88b8..4b8ab9da 100644 --- a/src/App/Callback/Targets/EntityTarget.hpp +++ b/src/App/Callback/Targets/EntityTarget.hpp @@ -50,7 +50,7 @@ struct EntityTarget : CallbackSystemTarget bool Supports(Red::CName aEventType) override { - return aEventType == Red::GetTypeName(); + return Red::GetClass(aEventType)->IsA(Red::GetClass()); } static Red::Handle ID(Red::EntityID aEntityID) diff --git a/src/Red/Addresses/Library.hpp b/src/Red/Addresses/Library.hpp index 726f2749..d10f009b 100644 --- a/src/Red/Addresses/Library.hpp +++ b/src/Red/Addresses/Library.hpp @@ -126,6 +126,8 @@ constexpr uint32_t ResourceSerializer_OnResourceReady = 1147149338; constexpr uint32_t TagSystem_AssignTag = 1239092911; constexpr uint32_t TagSystem_UnassignTag = 1875775378; +constexpr uint32_t VehicleController_ToggleLights = 3642563117; + constexpr uint32_t VehicleSystem_ToggleGarageVehicle = 3027836941; constexpr uint32_t WorkspotSystem_GetWorkspotInstance = 2234523611; diff --git a/src/Red/VehicleController.hpp b/src/Red/VehicleController.hpp new file mode 100644 index 00000000..81d1d7dd --- /dev/null +++ b/src/Red/VehicleController.hpp @@ -0,0 +1,8 @@ +#pragma once + +namespace Raw::VehicleController +{ +constexpr auto ToggleLights = Core::RawFunc< + /* addr = */ Red::AddressLib::VehicleController_ToggleLights, + /* type = */ void (*)(Red::vehicleController* aController, bool aEnable, Red::vehicleELightType aLightType)>(); +} diff --git a/src/pch.hpp b/src/pch.hpp index 58477186..da9cf5b2 100644 --- a/src/pch.hpp +++ b/src/pch.hpp @@ -158,6 +158,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/xmake.lua b/xmake.lua index bc155bcb..bb4608c6 100644 --- a/xmake.lua +++ b/xmake.lua @@ -1,7 +1,7 @@ set_xmakever("2.5.9") set_project("Codeware") -set_version("1.12.3", {build = "%y%m%d%H%M"}) +set_version("1.12.4", {build = "%y%m%d%H%M"}) set_arch("x64") set_languages("cxx2a")