feat: add alpha config and handle invalid data

This commit is contained in:
Anna 2024-07-22 14:33:02 -04:00
parent ee404dea95
commit 5af40e83d4
Signed by: anna
GPG Key ID: D0943384CD9F87D1
4 changed files with 19 additions and 3 deletions

View File

@ -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;
}

View File

@ -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<TerritoryType>();
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) {

View File

@ -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;
}

View File

@ -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;
}