From 62b65cd0e153a8f0fe2a094cb2668d6942ab2968 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Dec 2023 02:29:22 -0300 Subject: [PATCH] Added property to get the safe zone size Closes #146 --- LemonUI/ObjectPool.cs | 25 ++----------------------- LemonUI/Tools/SafeZone.cs | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/LemonUI/ObjectPool.cs b/LemonUI/ObjectPool.cs index 9935d25..cf4dbac 100644 --- a/LemonUI/ObjectPool.cs +++ b/LemonUI/ObjectPool.cs @@ -33,17 +33,7 @@ public class ObjectPool : IEnumerable /// /// The last know Safezone size. /// -#if FIVEM - private float lastKnownSafezone = API.GetSafeZoneSize(); -#elif ALTV - private float lastKnownSafezone = Alt.Natives.GetSafeZoneSize(); -#elif RAGEMP - private float lastKnownSafezone = Invoker.Invoke(Natives.GetSafeZoneSize); -#elif RPH - private float lastKnownSafezone = NativeFunction.CallByHash(0xBAF107B6BB2C97F0); -#elif SHVDN3 || SHVDNC - private float lastKnownSafezone = Function.Call(Hash.GET_SAFE_ZONE_SIZE); -#endif + private float lastKnownSafezone = SafeZone.Size; /// /// The list of processable objects. /// @@ -112,18 +102,7 @@ private void DetectResolutionChanges() private void DetectSafezoneChanges() { // Get the current Safezone size -#if FIVEM - float safezone = API.GetSafeZoneSize(); -#elif ALTV - float safezone = Alt.Natives.GetSafeZoneSize(); -#elif RAGEMP - float safezone = Invoker.Invoke(Natives.GetSafeZoneSize); -#elif RPH - float safezone = NativeFunction.CallByHash(0xBAF107B6BB2C97F0); -#elif SHVDN3 || SHVDNC - float safezone = Function.Call(Hash.GET_SAFE_ZONE_SIZE); -#endif - + float safezone = SafeZone.Size; // If is not the same as the last one if (lastKnownSafezone != safezone) { diff --git a/LemonUI/Tools/SafeZone.cs b/LemonUI/Tools/SafeZone.cs index 43be35b..4ddfa8d 100644 --- a/LemonUI/Tools/SafeZone.cs +++ b/LemonUI/Tools/SafeZone.cs @@ -23,6 +23,29 @@ public static class SafeZone { #region Properties + /// + /// The size of the safe zone. + /// + /// + /// This property should not be used to manually calculate the safe zone. Use to get the safe zone size. + /// + public static float Size + { + get + { +#if ALTV + return Alt.Natives.GetSafeZoneSize(); +#elif FIVEM + return API.GetSafeZoneSize(); +#elif RAGEMP + return Invoker.Invoke(Natives.GetSafeZoneSize); +#elif RPH + return NativeFunction.CallByHash(0xBAF107B6BB2C97F0); +#elif SHVDN3 || SHVDNC + return Function.Call(Hash.GET_SAFE_ZONE_SIZE); +#endif + } + } /// /// The top left corner after the safe zone. ///