From 76b2129a93a5f592e76b25b4d8e06b98a03e1bfd Mon Sep 17 00:00:00 2001 From: goaaats Date: Sun, 3 Apr 2022 03:02:31 +0200 Subject: [PATCH] chore: purge april fools 2022 code --- .../Internal/DalamudConfiguration.cs | 4 - Dalamud/Dalamud.cs | 14 - Dalamud/Fools22.cs | 426 ------------------ .../Interface/Internal/DalamudInterface.cs | 5 - .../Internal/Windows/FoolsAskWindow.cs | 100 ---- .../Internal/Windows/SettingsWindow.cs | 12 - 6 files changed, 561 deletions(-) delete mode 100644 Dalamud/Fools22.cs delete mode 100644 Dalamud/Interface/Internal/Windows/FoolsAskWindow.cs diff --git a/Dalamud/Configuration/Internal/DalamudConfiguration.cs b/Dalamud/Configuration/Internal/DalamudConfiguration.cs index 7dd5c2ac8..41eeb5b03 100644 --- a/Dalamud/Configuration/Internal/DalamudConfiguration.cs +++ b/Dalamud/Configuration/Internal/DalamudConfiguration.cs @@ -295,10 +295,6 @@ namespace Dalamud.Configuration.Internal /// public bool ShowTsm { get; set; } = true; - public bool AskedFools22 { get; set; } = false; - - public bool Fools22Newer { get; set; } = false; - /// /// Load a configuration from the provided path. /// diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 691a541ef..537ffa516 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -53,8 +53,6 @@ namespace Dalamud #endregion - private Fools22? fools22; - /// /// Initializes a new instance of the class. /// @@ -272,16 +270,6 @@ namespace Dalamud Troubleshooting.LogTroubleshooting(); - try - { - Log.Information("Loading fools22"); - this.fools22 = new Fools22(); - } - catch (Exception ex) - { - Log.Error(ex, "Fools22 load failed."); - } - Log.Information("Dalamud is ready."); } catch (Exception ex) @@ -372,8 +360,6 @@ namespace Dalamud this.processMonoHook?.Dispose(); - this.fools22?.Dispose(); - Log.Debug("Dalamud::Dispose() OK!"); } catch (Exception ex) diff --git a/Dalamud/Fools22.cs b/Dalamud/Fools22.cs deleted file mode 100644 index 8cd5f354b..000000000 --- a/Dalamud/Fools22.cs +++ /dev/null @@ -1,426 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Numerics; -using System.Threading.Tasks; - -using Dalamud.Configuration.Internal; -using Dalamud.Data; -using Dalamud.Game; -using Dalamud.Game.ClientState; -using Dalamud.Game.ClientState.Conditions; -using Dalamud.Game.Gui; -using Dalamud.Game.Network; -using Dalamud.Game.Text; -using Dalamud.Game.Text.SeStringHandling; -using Dalamud.Interface; -using Dalamud.Interface.Animation; -using Dalamud.Interface.Animation.EasingFunctions; -using Dalamud.Interface.Internal; -using Dalamud.Memory; -using Dalamud.Utility; -using ImGuiNET; -using ImGuiScene; -using Lumina.Excel.GeneratedSheets; -using NAudio.Wave; -using Serilog; - -using Condition = Dalamud.Game.ClientState.Conditions.Condition; - -namespace Dalamud; - -public class Fools22 : IDisposable -{ - private readonly TextureWrap erDeathBgTexture; - private readonly TextureWrap erNormalDeathTexture; - private readonly TextureWrap erCraftFailedTexture; - private readonly TextureWrap erEnemyFelledTexture; - - private readonly byte[] soundBytes; - - private readonly string synthesisFailsMessage; - - private readonly Stopwatch time = new Stopwatch(); - - private bool assetsReady = false; - - private AnimationState currentState = AnimationState.NotPlaying; - private DeathType currentDeathType = DeathType.Death; - - private Easing alphaEasing; - private Easing scaleEasing; - - private bool lastFrameUnconscious = false; - - private int msFadeInTime = 1000; - private int msFadeOutTime = 2000; - private int msWaitTime = 1600; - - private TextureWrap TextTexture => this.currentDeathType switch - { - DeathType.Death => this.erNormalDeathTexture, - DeathType.CraftFailed => this.erCraftFailedTexture, - DeathType.EnemyFelled => this.erEnemyFelledTexture, - }; - - private enum AnimationState - { - NotPlaying, - FadeIn, - Wait, - FadeOut, - } - - private enum DeathType - { - Death, - CraftFailed, - EnemyFelled, - } - - public Fools22() - { - var dalamud = Service.Get(); - var interfaceManager = Service.Get(); - var framework = Service.Get(); - var chatGui = Service.Get(); - var dataMgr = Service.Get(); - var gameNetwork = Service.Get(); - var clientState = Service.Get(); - - this.erDeathBgTexture = interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "fools22", "er_death_bg.png"))!; - this.erNormalDeathTexture = interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "fools22", "er_normal_death.png"))!; - this.erCraftFailedTexture = interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "fools22", "er_craft_failed.png"))!; - this.erEnemyFelledTexture = interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "fools22", "er_enemy_felled.png"))!; - - this.soundBytes = File.ReadAllBytes(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "fools22", "snd_death_er.wav")); - - if (this.erDeathBgTexture == null || this.erNormalDeathTexture == null || this.erCraftFailedTexture == null) - { - Log.Error("Fools22: Failed to load images"); - return; - } - - this.synthesisFailsMessage = dataMgr.GetExcelSheet()!.GetRow(1160)!.Text.ToDalamudString().TextValue; - - this.assetsReady = true; - - interfaceManager.Draw += this.Draw; - framework.Update += this.FrameworkOnUpdate; - chatGui.ChatMessage += this.ChatGuiOnChatMessage; - gameNetwork.NetworkMessage += this.GameNetworkOnNetworkMessage; - clientState.Login += ClientStateOnLogin; - } - - private void ClientStateOnLogin(object? sender, EventArgs e) - { - var config = Service.Get(); - - if (!(DateTime.Now.Month == 4 && DateTime.Now.Day == 1)) - return; - - if (config.AskedFools22) - return; - - var di = Service.Get(); - di.OpenFaWindow(); - } - - private unsafe void GameNetworkOnNetworkMessage(IntPtr dataptr, ushort opcode, uint sourceactorid, uint targetactorid, NetworkMessageDirection direction) - { - if (opcode != 0x301) - return; - - var cat = *(ushort*)(dataptr + 0x00); - var updateType = *(uint*)(dataptr + 0x08); - - if (cat == 0x6D && updateType == 0x40000003) - { - Task.Delay(1000).ContinueWith(t => - { - this.PlayAnimation(DeathType.EnemyFelled); - }); - } - } - - private void ChatGuiOnChatMessage(XivChatType type, uint senderid, ref SeString sender, ref SeString message, ref bool ishandled) - { - if (message.TextValue.Contains(this.synthesisFailsMessage)) - { - this.PlayAnimation(DeathType.CraftFailed); - Log.Information("Fools22: Craft failed"); - } - } - - private void FrameworkOnUpdate(Framework framework) - { - var condition = Service.Get(); - var isUnconscious = condition[ConditionFlag.Unconscious]; - - if (isUnconscious && !this.lastFrameUnconscious) - { - this.PlayAnimation(DeathType.Death); - Log.Information("Fools22: Player died"); - } - - this.lastFrameUnconscious = isUnconscious; - } - - private void Draw() - { -#if DEBUG - if (ImGui.Begin("fools test")) - { - if (ImGui.Button("play death")) - { - this.PlayAnimation(DeathType.Death); - } - - if (ImGui.Button("play craft failed")) - { - this.PlayAnimation(DeathType.CraftFailed); - } - - if (ImGui.Button("play enemy felled")) - { - Task.Delay(1000).ContinueWith(t => - { - this.PlayAnimation(DeathType.EnemyFelled); - }); - } - - ImGui.InputInt("fade in time", ref this.msFadeInTime); - ImGui.InputInt("fade out time", ref this.msFadeOutTime); - ImGui.InputInt("wait time", ref this.msWaitTime); - - ImGui.TextUnformatted("state: " + this.currentState); - ImGui.TextUnformatted("time: " + this.time.ElapsedMilliseconds); - - ImGui.TextUnformatted("scale: " + this.scaleEasing?.EasedPoint.X); - } - - ImGui.End(); -#endif - var vpSize = ImGuiHelpers.MainViewport.Size; - - ImGui.SetNextWindowPos(new Vector2(0, 0), ImGuiCond.Always); - ImGui.SetNextWindowSize(new Vector2(vpSize.X, vpSize.Y), ImGuiCond.Always); - ImGuiHelpers.ForceNextWindowMainViewport(); - - ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0); - ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0); - ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0, 0)); - ImGui.PushStyleColor(ImGuiCol.WindowBg, new Vector4(0, 0, 0, 0)); - ImGui.PushStyleColor(ImGuiCol.Border, new Vector4(0, 0, 0, 0)); - ImGui.PushStyleColor(ImGuiCol.BorderShadow, new Vector4(0, 0, 0, 0)); - - if (ImGui.Begin("fools22", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoNavFocus - | ImGuiWindowFlags.NoMouseInputs | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoScrollbar)) - { - if (this.currentState != AnimationState.NotPlaying) - { - this.alphaEasing?.Update(); - this.scaleEasing?.Update(); - } - - switch (this.currentState) - { - case AnimationState.FadeIn: - this.FadeIn(vpSize); - break; - case AnimationState.Wait: - this.Wait(vpSize); - break; - case AnimationState.FadeOut: - this.FadeOut(vpSize); - break; - } - } - - ImGui.End(); - - ImGui.PopStyleColor(3); - ImGui.PopStyleVar(3); - } - - private static void AdjustCursorAndDraw(Vector2 vpSize, TextureWrap tex, float scale = 1.0f) - { - ImGui.SetCursorPos(new Vector2(0, 0)); - - var width = vpSize.X; - var height = tex.Height / (float)tex.Width * width; - - if (height < vpSize.Y) - { - height = vpSize.Y; - width = tex.Width / (float)tex.Height * height; - } - - var scaledSize = new Vector2(width, height) * scale; - var difference = scaledSize - vpSize; - - var cursor = ImGui.GetCursorPos(); - ImGui.SetCursorPos(cursor - (difference / 2)); - - ImGui.Image(tex.ImGuiHandle, scaledSize); - } - - private void FadeIn(Vector2 vpSize) - { - if (this.time.ElapsedMilliseconds > this.msFadeInTime) - this.currentState = AnimationState.Wait; - - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, (float)this.alphaEasing.Value); - - AdjustCursorAndDraw(vpSize, this.erDeathBgTexture); - AdjustCursorAndDraw(vpSize, this.TextTexture, this.scaleEasing.EasedPoint.X); - - ImGui.PopStyleVar(); - } - - private void Wait(Vector2 vpSize) - { - if (this.time.ElapsedMilliseconds > this.msFadeInTime + this.msWaitTime) - { - this.currentState = AnimationState.FadeOut; - this.alphaEasing = new InOutCubic(TimeSpan.FromMilliseconds(this.msFadeOutTime)); - this.alphaEasing.Start(); - } - - AdjustCursorAndDraw(vpSize, this.erDeathBgTexture); - AdjustCursorAndDraw(vpSize, this.TextTexture, this.scaleEasing.EasedPoint.X); - } - - private void FadeOut(Vector2 vpSize) - { - if (this.time.ElapsedMilliseconds > this.msFadeInTime + this.msWaitTime + this.msFadeOutTime) - { - this.currentState = AnimationState.NotPlaying; - this.time.Stop(); - } - - ImGui.PushStyleVar(ImGuiStyleVar.Alpha, 1 - (float)this.alphaEasing.Value); - - AdjustCursorAndDraw(vpSize, this.erDeathBgTexture); - AdjustCursorAndDraw(vpSize, this.TextTexture, this.scaleEasing.EasedPoint.X); - - ImGui.PopStyleVar(); - } - - private void PlayAnimation(DeathType type) - { - if (!this.CheckFoolsApplicable()) - return; - - if (this.currentState != AnimationState.NotPlaying) - return; - - this.currentDeathType = type; - - this.currentState = AnimationState.FadeIn; - this.alphaEasing = new InOutCubic(TimeSpan.FromMilliseconds(this.msFadeInTime)); - this.alphaEasing.Start(); - - this.scaleEasing = new OutCubic(TimeSpan.FromMilliseconds(this.msFadeInTime + this.msWaitTime + this.msFadeOutTime)) - { - Point1 = new Vector2(0.95f, 0.95f), - Point2 = new Vector2(1.05f, 1.05f), - }; - this.scaleEasing.Start(); - - this.time.Reset(); - this.time.Start(); - - var volume = this.GetSfxVolume(); - if (volume > 0) - { - Log.Information("Fools22: Vol {Volume}", volume); - - var waveStream = new WaveFileReader(new MemoryStream(this.soundBytes)); - var volumeStream = new WaveChannel32(waveStream); - volumeStream.Volume = volume; - var player = new WaveOutEvent(); - - player.Init(volumeStream); - player.Play(); - } - } - - private bool CheckFoolsApplicable() - { - var config = Service.Get(); - - if (!config.Fools22Newer) - return false; - - if (!(DateTime.Now.Month == 4 && DateTime.Now.Day == 1)) - return false; - - return this.assetsReady; - } - - private unsafe float GetSfxVolume() - { - try - { - var framework = FFXIVClientStructs.FFXIV.Client.System.Framework.Framework.Instance(); - var configBase = framework->SystemConfig.CommonSystemConfig.ConfigBase; - - var seEnabled = false; - var masterEnabled = false; - var masterVolume = 0u; - - for (var i = 0; i < configBase.ConfigCount; i++) - { - var entry = configBase.ConfigEntry[i]; - - if (entry.Name != null) - { - var name = MemoryHelper.ReadStringNullTerminated(new IntPtr(entry.Name)); - - if (name == "IsSndSe") - { - var value = entry.Value.UInt; - Log.Information("Fools21: {Name} - {Type} - {Value}", name, entry.Type, value); - - seEnabled = value == 0; - } - - if (name == "IsSndMaster") - { - var value = entry.Value.UInt; - Log.Information("Fools21: {Name} - {Type} - {Value}", name, entry.Type, value); - - masterEnabled = value == 0; - } - - if (name == "SoundMaster") - { - var value = entry.Value.UInt; - Log.Information("Fools21: {Name} - {Type} - {Value}", name, entry.Type, value); - - masterVolume = value; - } - } - } - - if (!(seEnabled && masterEnabled)) - return 0; - - var vol = masterVolume / 100F; - return Math.Clamp(vol, 0f, 1f); - } - catch (Exception ex) - { - Log.Error(ex, "Fools21: Error checking if sfx is enabled"); - return 0; - } - } - - public void Dispose() - { - this.erDeathBgTexture.Dispose(); - this.erNormalDeathTexture.Dispose(); - this.erCraftFailedTexture.Dispose(); - } -} diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs index e924774d9..ee56e749f 100644 --- a/Dalamud/Interface/Internal/DalamudInterface.cs +++ b/Dalamud/Interface/Internal/DalamudInterface.cs @@ -53,7 +53,6 @@ namespace Dalamud.Interface.Internal private readonly SelfTestWindow selfTestWindow; private readonly StyleEditorWindow styleEditorWindow; private readonly TitleScreenMenuWindow titleScreenMenuWindow; - private readonly FoolsAskWindow faWindow; private readonly TextureWrap logoTexture; private readonly TextureWrap tsmLogoTexture; @@ -92,7 +91,6 @@ namespace Dalamud.Interface.Internal this.selfTestWindow = new SelfTestWindow() { IsOpen = false }; this.styleEditorWindow = new StyleEditorWindow() { IsOpen = false }; this.titleScreenMenuWindow = new TitleScreenMenuWindow() { IsOpen = false }; - this.faWindow = new FoolsAskWindow() { IsOpen = false }; this.WindowSystem.AddWindow(this.changelogWindow); this.WindowSystem.AddWindow(this.colorDemoWindow); @@ -108,7 +106,6 @@ namespace Dalamud.Interface.Internal this.WindowSystem.AddWindow(this.selfTestWindow); this.WindowSystem.AddWindow(this.styleEditorWindow); this.WindowSystem.AddWindow(this.titleScreenMenuWindow); - this.WindowSystem.AddWindow(this.faWindow); ImGuiManagedAsserts.AssertsEnabled = configuration.AssertsEnabledAtStartup; @@ -250,8 +247,6 @@ namespace Dalamud.Interface.Internal /// public void OpenStyleEditor() => this.styleEditorWindow.IsOpen = true; - public void OpenFaWindow() => this.faWindow.IsOpen = true; - #endregion #region Close diff --git a/Dalamud/Interface/Internal/Windows/FoolsAskWindow.cs b/Dalamud/Interface/Internal/Windows/FoolsAskWindow.cs deleted file mode 100644 index 20bedfbc6..000000000 --- a/Dalamud/Interface/Internal/Windows/FoolsAskWindow.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Numerics; -using Dalamud.Configuration.Internal; -using Dalamud.Interface.Colors; -using Dalamud.Interface.Windowing; -using Dalamud.Utility; -using ImGuiNET; -using ImGuiScene; - -namespace Dalamud.Interface.Internal.Windows -{ - /// - /// For major updates, an in-game Changelog window. - /// - internal sealed class FoolsAskWindow : Window, IDisposable - { - private readonly string assemblyVersion = Util.AssemblyVersion; - - private readonly TextureWrap logoTexture; - - /// - /// Initializes a new instance of the class. - /// - public FoolsAskWindow() - : base("New in Dalamud!", ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse) - { - this.Namespace = "DalamudChangelogWindow"; - - var interfaceManager = Service.Get(); - var dalamud = Service.Get(); - - this.logoTexture = - interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "logo.png"))!; - } - - /// - public override void Draw() - { - this.Size = new Vector2(885, 250); - this.SizeCondition = ImGuiCond.Always; - this.Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse; - - ImGui.TextWrapped("Today, we are proud to announce \"Dalamud: Prepare To Die Edition\".\nIt's a new initiative intended to improve your immersion when playing FFXIV, featuring all new and unintrusive visual and sound effects.\nIt's only available today, so join while you can."); - - ImGuiHelpers.ScaledDummy(10); - - ImGui.TextWrapped("You can choose to opt-in here - thank you for your support!"); - - ImGui.SameLine(); - ImGuiHelpers.ScaledDummy(0); - var imgCursor = ImGui.GetCursorPos(); - - ImGuiHelpers.ScaledDummy(40); - - ImGuiHelpers.ScaledDummy(240); - - ImGui.SameLine(); - - var btnSize = new Vector2(140, 40); - - var config = Service.Get(); - - if (ImGui.Button("No, don't ask again", btnSize)) - { - config.AskedFools22 = true; - config.Fools22Newer = false; - config.Save(); - - this.IsOpen = false; - } - - ImGui.SameLine(); - - if (ImGui.Button("Yes!", btnSize)) - { - config.AskedFools22 = true; - config.Fools22Newer = true; - config.Save(); - - this.IsOpen = false; - } - - imgCursor.X += 750; - imgCursor.Y -= 30; - ImGui.SetCursorPos(imgCursor); - - ImGui.Image(this.logoTexture.ImGuiHandle, new Vector2(100)); - } - - /// - /// Dispose this window. - /// - public void Dispose() - { - this.logoTexture.Dispose(); - } - } -} diff --git a/Dalamud/Interface/Internal/Windows/SettingsWindow.cs b/Dalamud/Interface/Internal/Windows/SettingsWindow.cs index e94d7890b..6edff8e66 100644 --- a/Dalamud/Interface/Internal/Windows/SettingsWindow.cs +++ b/Dalamud/Interface/Internal/Windows/SettingsWindow.cs @@ -50,8 +50,6 @@ namespace Dalamud.Interface.Internal.Windows private bool doFocus; private bool doTsm; - private bool doFools22; - private List? dtrOrder; private List? dtrIgnore; private int dtrSpacing; @@ -176,8 +174,6 @@ namespace Dalamud.Interface.Internal.Windows var configuration = Service.Get(); this.dtrOrder = configuration.DtrOrder; this.dtrIgnore = configuration.DtrIgnore; - - this.doFools22 = configuration.Fools22Newer; } /// @@ -244,12 +240,6 @@ namespace Dalamud.Interface.Internal.Windows private void DrawGeneralTab() { - if (DateTime.Now.Month == 4 && DateTime.Now.Day == 1) - { - ImGui.Checkbox(Loc.Localize("Fools22", "Enable April Fools 2022"), ref this.doFools22); - ImGui.TextColored(ImGuiColors.DalamudGrey, Loc.Localize("Fools22Hint", "Enables the April Fools 2022 funny joke. Turn this off if you don't think it's funny.")); - } - ImGui.Text(Loc.Localize("DalamudSettingsLanguage", "Language")); ImGui.Combo("##XlLangCombo", ref this.langIndex, this.locLanguages, this.locLanguages.Length); ImGui.TextColored(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsLanguageHint", "Select the language Dalamud will be displayed in.")); @@ -870,8 +860,6 @@ namespace Dalamud.Interface.Internal.Windows configuration.IsFocusManagementEnabled = this.doFocus; configuration.ShowTsm = this.doTsm; - configuration.Fools22Newer = this.doFools22; - configuration.UseAxisFontsFromGame = this.doUseAxisFontsFromGame; configuration.AllowBigFontAtlas = this.doAllowBigFontAtlas; configuration.FontGamma = this.fontGamma;