Skip to content

Commit

Permalink
Merge pull request #4 from noverd/performance_fix
Browse files Browse the repository at this point in the history
Performance tweak
  • Loading branch information
noverd authored Nov 18, 2024
2 parents 8b1969b + 8b02142 commit 241aeaa
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 42 deletions.
20 changes: 13 additions & 7 deletions ArabicaCliento/Patches/ClientHeavyAttackPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,31 @@
using Robust.Shared.Map;
using ArabicaCliento.Systems;
using Content.Client.Weapons.Melee;
using Robust.Client.GameObjects;

namespace ArabicaCliento.Patches;

[HarmonyPatch(typeof(MeleeWeaponSystem), "ClientHeavyAttack")]
public class ClientHeavyAttackPatch
{
private static IEntityManager? _entMan;
private static TransformSystem? _transform;
private static ArabicaAimSystem? _aim;


[HarmonyPrefix]
private static void Prefix(ref EntityUid user,
ref EntityCoordinates coordinates,
ref EntityUid meleeUid,
ref MeleeWeaponComponent component)
{
var entity = IoCManager.Resolve<EntityManager>();
var xform = entity.System<SharedTransformSystem>();
var aim = entity.System<ArabicaAimSystem>();

var output = aim.GetClosestToEntInRange(user, component.Range, [user]);
if (output == null || !ArabicaConfig.MeleeAimbotEnabled) return;
if (!ArabicaConfig.MeleeAimbotEnabled) return;
_entMan ??= IoCManager.Resolve<EntityManager>();
_transform ??= _entMan.System<TransformSystem>();
_aim ??= _entMan.System<ArabicaAimSystem>();

coordinates = EntityCoordinates.FromMap(coordinates.EntityId, output.Value.Position, xform, entity);
var output = _aim.GetClosestToEntInRange(user, component.Range, [user]);
if (output == null) return;
coordinates = _transform.ToCoordinates(coordinates.EntityId, output.Value.Position);
}
}
6 changes: 4 additions & 2 deletions ArabicaCliento/Patches/EntityMenuElementPatch.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Reflection;
using Content.Client.ContextMenu.UI;
using HarmonyLib;

Expand All @@ -7,11 +8,12 @@ namespace ArabicaCliento.Patches;
[HarmonyPatch("GetEntityDescription")]
internal class EntityMenuElementPatch
{
private static MethodInfo? _methodCache;
[HarmonyPrefix]
private static bool Prefix(EntityUid entity, EntityMenuElement __instance, ref string __result)
{
__result = AccessTools.Method(typeof(EntityMenuElement), "GetEntityDescriptionAdmin")
.Invoke(__instance, [entity]) as string ?? throw new InvalidOperationException();
_methodCache ??= AccessTools.Method(typeof(EntityMenuElement), "GetEntityDescriptionAdmin");
__result = _methodCache.Invoke(__instance, [entity]) as string ?? throw new InvalidOperationException();
return false;
}
}
1 change: 0 additions & 1 deletion ArabicaCliento/Systems/ArabicaIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ namespace ArabicaCliento.Systems;
public class ArabicaJobIconsSystem : LocalPlayerAddCompSystem<ShowJobIconsComponent>;
public class ArabicaCriminalRecordIcons : LocalPlayerAddCompSystem<ShowCriminalRecordIconsComponent>;
public class ArabicaMindShieldIcons : LocalPlayerAddCompSystem<ShowMindShieldIconsComponent>;

public class ArabicaSyndicateIcons : LocalPlayerAddCompSystem<ShowSyndicateIconsComponent>;
69 changes: 37 additions & 32 deletions ArabicaCliento/UI/Controls/ArabicaWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,51 @@
using System.Numerics;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;

namespace ArabicaCliento.UI.Controls
namespace ArabicaCliento.UI.Controls;

[GenerateTypedNameReferences]
[Virtual]
public partial class ArabicaWindow : BaseWindow
{
[GenerateTypedNameReferences]
[Virtual]
public partial class ArabicaWindow : BaseWindow
private const int DRAG_MARGIN_SIZE = 7;

public ArabicaWindow()
{
private const int DRAG_MARGIN_SIZE = 7;
RobustXamlLoader.Load(this);
CloseButton.OnPressed += CloseButtonPressed;
}

public ArabicaWindow()
private void CloseButtonPressed(BaseButton.ButtonEventArgs buttonEventArgs)
{
Close();
}

protected override DragMode GetDragModeFor(Vector2 relativeMousePos)
{
var mode = DragMode.Move;

if (!Resizable) return mode;
if (relativeMousePos.Y < DRAG_MARGIN_SIZE)
{
mode = DragMode.Top;
}
else if (relativeMousePos.Y > Size.Y - DRAG_MARGIN_SIZE)
{
RobustXamlLoader.Load(this);
mode = DragMode.Bottom;
}

protected override DragMode GetDragModeFor(Vector2 relativeMousePos)
if (relativeMousePos.X < DRAG_MARGIN_SIZE)
{
var mode = DragMode.Move;

if (!Resizable) return mode;
if (relativeMousePos.Y < DRAG_MARGIN_SIZE)
{
mode = DragMode.Top;
}
else if (relativeMousePos.Y > Size.Y - DRAG_MARGIN_SIZE)
{
mode = DragMode.Bottom;
}

if (relativeMousePos.X < DRAG_MARGIN_SIZE)
{
mode |= DragMode.Left;
}
else if (relativeMousePos.X > Size.X - DRAG_MARGIN_SIZE)
{
mode |= DragMode.Right;
}

return mode;
mode |= DragMode.Left;
}
else if (relativeMousePos.X > Size.X - DRAG_MARGIN_SIZE)
{
mode |= DragMode.Right;
}

return mode;
}
}
}

0 comments on commit 241aeaa

Please sign in to comment.