-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Red::CName, Red::CName> GetEvents() override | ||
{ | ||
return {{EventName, Red::GetTypeName<VehicleLightControlEvent>()}}; | ||
} | ||
|
||
protected: | ||
bool OnActivateHook() override | ||
{ | ||
return IsHooked<Raw::VehicleController::ToggleLights>() || HookAfter<Raw::VehicleController::ToggleLights>(&OnToggleLights); | ||
} | ||
|
||
bool OnDeactivateHook() override | ||
{ | ||
return !IsHooked<Raw::VehicleController::ToggleLights>() || Unhook<Raw::VehicleController::ToggleLights>(); | ||
} | ||
|
||
inline static void OnToggleLights(Red::vehicleController* aController, bool aEnable, Red::vehicleELightType aLightType) | ||
{ | ||
CallbackSystem::Get()->DispatchNativeEvent<VehicleLightControlEvent>(EventName, Red::AsWeakHandle(aController->owner), aEnable, aLightType); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Red::Entity> 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<uint32_t>(lightType) & static_cast<uint32_t>(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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters