From 5af40e83d4a1c43890cc26e2a60da6c3b3b192ee Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 22 Jul 2024 14:33:02 -0400 Subject: [PATCH] feat: add alpha config and handle invalid data --- client/Configuration.cs | 1 + client/Ui/MainWindowTabs/Settings.cs | 4 +++- client/Ui/MainWindowTabs/Write.cs | 2 ++ client/Util/ActorManager.cs | 15 +++++++++++++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/client/Configuration.cs b/client/Configuration.cs index cba9978..c5789f7 100644 --- a/client/Configuration.cs +++ b/client/Configuration.cs @@ -19,6 +19,7 @@ public class Configuration : IPluginConfiguration { public bool ClickThroughViewer; public bool HideTitlebar; public bool ShowEmotes = true; + public float EmoteAlpha = 25.0f; public float ViewerOpacity = 100.0f; public int DefaultGlyph = 3; } diff --git a/client/Ui/MainWindowTabs/Settings.cs b/client/Ui/MainWindowTabs/Settings.cs index 3919d51..e0cca64 100644 --- a/client/Ui/MainWindowTabs/Settings.cs +++ b/client/Ui/MainWindowTabs/Settings.cs @@ -121,7 +121,6 @@ internal class Settings : ITab { anyChanged |= vfx |= ImGui.Checkbox("Disable in cutscenes", ref this.Plugin.Config.DisableInCutscene); anyChanged |= vfx |= ImGui.Checkbox("Disable in /gpose", ref this.Plugin.Config.DisableInGpose); anyChanged |= vfx |= ImGui.Checkbox("Remove glow effect from signs", ref this.Plugin.Config.RemoveGlow); - anyChanged |= ImGui.Checkbox("Show player emotes", ref this.Plugin.Config.ShowEmotes); var tt = this.Plugin.DataManager.GetExcelSheet(); if (tt == null) { @@ -221,6 +220,9 @@ internal class Settings : ITab { anyChanged |= ImGui.Checkbox("Lock viewer in place", ref this.Plugin.Config.LockViewer); anyChanged |= ImGui.Checkbox("Click through viewer", ref this.Plugin.Config.ClickThroughViewer); + + anyChanged |= ImGui.Checkbox("Show player emotes", ref this.Plugin.Config.ShowEmotes); + anyChanged |= ImGui.SliderFloat("Player emote opacity", ref this.Plugin.Config.EmoteAlpha, 0f, 100f, "%.2f%%"); } private void DrawUnlocks(ref bool anyChanged, ref bool vfx) { diff --git a/client/Ui/MainWindowTabs/Write.cs b/client/Ui/MainWindowTabs/Write.cs index ea6d968..6b8c9fc 100644 --- a/client/Ui/MainWindowTabs/Write.cs +++ b/client/Ui/MainWindowTabs/Write.cs @@ -171,6 +171,7 @@ internal class Write : ITab { return; } + ImGui.SetNextWindowSizeConstraints(new Vector2(100 * ImGuiHelpers.GlobalScale, 0), new Vector2(float.MaxValue)); var preview = x == (-1, -1) ? "" : template.Words[x.Item2]; if (!ImGui.BeginCombo(id, preview)) { return; @@ -207,6 +208,7 @@ internal class Write : ITab { for (var listIdx = 0; listIdx < words.Count; listIdx++) { var list = words[listIdx]; + ImGui.SetNextWindowSizeConstraints(new Vector2(100 * ImGuiHelpers.GlobalScale, 0), new Vector2(float.MaxValue)); if (!ImGui.BeginMenu(list.Name)) { continue; } diff --git a/client/Util/ActorManager.cs b/client/Util/ActorManager.cs index 100febc..2b6b5f3 100644 --- a/client/Util/ActorManager.cs +++ b/client/Util/ActorManager.cs @@ -13,11 +13,13 @@ internal class ActorManager : IDisposable { internal ActorManager(Plugin plugin) { this.Plugin = plugin; this.Plugin.Framework.Update += this.OnFramework; + this.Plugin.ClientState.TerritoryChanged += this.OnTerritoryChange; this.Plugin.Ui.Viewer.View += this.OnView; } public void Dispose() { this.Plugin.Ui.Viewer.View -= this.OnView; + this.Plugin.ClientState.TerritoryChanged -= this.OnTerritoryChange; this.Plugin.Framework.Update -= this.OnFramework; if (this._idx != null) { @@ -54,6 +56,10 @@ internal class ActorManager : IDisposable { } } + private void OnTerritoryChange(ushort obj) { + this._idx = null; + } + private void OnView(Message? message) { var msg = message == null ? "null" : "not null"; Plugin.Log.Debug($"OnView message is {msg}"); @@ -145,6 +151,12 @@ internal class ActorManager : IDisposable { rawCustomise[i] = emote.Customise[i]; } + // check if data is valid to prevent crashes + if (!(&drawData->CustomizeData)->NormalizeCustomizeData(&drawData->CustomizeData)) { + drawData->CustomizeData = new CustomizeData(); + } + + // weapon and equipment values don't cause crashes, just transparent body parts for (var i = 0; i < Math.Min(drawData->EquipmentModelIds.Length, emote.Equipment.Length); i++) { var equip = emote.Equipment[i]; drawData->Equipment((DrawDataContainer.EquipmentSlot) i) = new EquipmentModelId { @@ -177,7 +189,7 @@ internal class ActorManager : IDisposable { drawData->SetGlasses(0, (ushort) emote.Glasses); - chara->Alpha = 0.25f; + chara->Alpha = Math.Clamp(manager.Plugin.Config.EmoteAlpha / 100, 0, 1); chara->SetMode(CharacterModes.AnimLock, 0); if (emoteRow != null) { chara->Timeline.BaseOverride = (ushort) emoteRow.ActionTimeline[0].Row; @@ -235,7 +247,6 @@ internal class ActorManager : IDisposable { return true; } - objMan->DeleteObjectByIndex((ushort) idx, 0); manager._idx = null; return true; }