From e341e8df15466bf5d87655b391a2750efffd0c3c Mon Sep 17 00:00:00 2001 From: Sychotix Date: Wed, 18 Jan 2023 11:14:01 -0500 Subject: [PATCH] Improvements and new option for ruthless Changes: * Moved logic from Render loop to Tick * Always pull the latest health, using cached version can result in slower quitting... resulting in death. * Add an option to disable when in town/hideout. Ruthless doesn't refill health in these locations, so logging back in after a quit would cause a quit loop until disabled. --- AutoQuitCore.cs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/AutoQuitCore.cs b/AutoQuitCore.cs index 2c4deb0..8315d79 100644 --- a/AutoQuitCore.cs +++ b/AutoQuitCore.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; @@ -18,6 +18,7 @@ public class AutoQuit: BaseSettingsPlugin private readonly int errmsg_time = 10; private ServerInventory flaskInventory = null; + private bool isInTownOrHideout = false; public override bool Initialise() { @@ -29,6 +30,7 @@ public override bool Initialise() public override void AreaChange(AreaInstance area) { flaskInventory = GameController.Game.IngameState.ServerData.GetPlayerInventoryBySlot(InventorySlotE.Flask1); + isInTownOrHideout = area == null ? false : (area.IsTown || area.IsHideout); } @@ -43,18 +45,30 @@ public void Quit() } } - public override void Render() + public override Job Tick() { - base.Render(); - // Panic Quit Key. if (Input.IsKeyDown(Settings.forcedAutoQuit)) Quit(); + if (!Settings.Enable) return null; + + TickLogic(); + return null; + } + + private void TickLogic() + { + // Do not execute logic if we are in town/hideout + // This becomes a problem in Ruthless where health doesn't restore in towns + if (isInTownOrHideout) + return; + var LocalPlayer = GameController.Game.IngameState.Data.LocalPlayer; - var PlayerHealth = LocalPlayer.GetComponent(); - if (Settings.Enable && LocalPlayer.IsValid) + if (LocalPlayer.IsValid) { + var PlayerHealth = LocalPlayer.GetComponentFromMemory(); + if (Math.Round(PlayerHealth.HPPercentage, 3) * 100 < (Settings.percentHPQuit.Value) && PlayerHealth.CurHP != 0) { try @@ -90,6 +104,7 @@ public override void Render() } } } + public bool gotCharges() { int charges = 0; @@ -237,8 +252,10 @@ public AutoQuitSettings() public RangeNode percentESQuit { get; set; } [Menu("Quit if HP flasks are empty", 4)] public ToggleNode emptyHPFlasks { get; set; } = new ToggleNode(false); + [Menu("Disable in town or hideout", 4)] + public ToggleNode disableInTownOrHideout { get; set; } = new ToggleNode(false); #endregion public ToggleNode Enable { get; set; } = new ToggleNode(false); } -} \ No newline at end of file +}