Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of HUDGifAnimation v1.0.5
plugins/HUDGifAnimation/HUDGifAnimation.dll
Decompiled 4 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using RiskOfOptions; using RiskOfOptions.OptionConfigs; using RiskOfOptions.Options; using RoR2; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("HUDGifAnimation")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("HUDGifAnimation")] [assembly: AssemblyTitle("HUDGifAnimation")] [assembly: AssemblyVersion("1.0.0.0")] namespace HUDGifAnimation; [BepInPlugin("com.moetus.hudgifanimation", "HUD GIF Animation", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class HUDGifMod : BaseUnityPlugin { private ConfigEntry<float> configPosX; private ConfigEntry<float> configPosY; private ConfigEntry<float> configScale; private List<Texture2D> gifFrames = new List<Texture2D>(); private List<float> frameDelays = new List<float>(); private bool gifLoaded = false; private int currentFrame = 0; private float frameTimer = 0f; private GameObject canvasObject; private GameObject gifObject; private bool gifCreated = false; public void Awake() { ((BaseUnityPlugin)this).Logger.LogInfo((object)"HUD GIF Animation Mod loaded!"); SetupConfig(); SetupRiskOfOptions(); LoadGifFrames(); } private void SetupConfig() { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown configPosX = ((BaseUnityPlugin)this).Config.Bind<float>("Position", "X Position", 10f, "Horizontal position from left edge of screen"); configPosY = ((BaseUnityPlugin)this).Config.Bind<float>("Position", "Y Position", -80f, "Vertical position from top edge of screen (negative = down)"); configScale = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "Scale", 1f, new ConfigDescription("Size multiplier for the GIF", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 3f), Array.Empty<object>())); } private void SetupRiskOfOptions() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Expected O, but got Unknown //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions")) { ModSettingsManager.AddOption((BaseOption)new SliderOption(configPosX, new SliderConfig { min = -960f, max = 960f, FormatString = "{0:0}" })); ModSettingsManager.AddOption((BaseOption)new SliderOption(configPosY, new SliderConfig { min = -540f, max = 540f, FormatString = "{0:0}" })); ModSettingsManager.AddOption((BaseOption)new SliderOption(configScale, new SliderConfig { min = 0.1f, max = 3f, FormatString = "{0:0.0}x" })); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Risk of Options integration enabled!"); } } public void Update() { bool flag = (Object)(object)Run.instance != (Object)null; bool isPaused = PauseManager.isPaused; if (gifLoaded && !gifCreated && flag) { CreateStandaloneGif(); } if (gifCreated && (Object)(object)gifObject != (Object)null) { UpdateGifTransform(); } if ((Object)(object)canvasObject != (Object)null) { canvasObject.SetActive(flag && !isPaused); } if (gifLoaded && gifCreated && flag && !isPaused) { UpdateGifAnimation(); } } private void LoadGifFrames() { string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); string path = Path.Combine(directoryName, "gif_frames"); if (!Directory.Exists(path)) { ((BaseUnityPlugin)this).Logger.LogError((object)"gif_frames folder not found!"); return; } string[] array = (from f in Directory.GetFiles(path, "*.png") orderby f select f).ToArray(); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Found {array.Length} frame files"); string[] array2 = array; foreach (string text in array2) { Texture2D val = LoadTexture(text); if ((Object)(object)val != (Object)null) { gifFrames.Add(val); float item = ParseDelayFromFilename(text); frameDelays.Add(item); } } if (gifFrames.Count > 0) { gifLoaded = true; ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Loaded {gifFrames.Count} GIF frames successfully!"); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Frame delays range from {frameDelays.Min()}s to {frameDelays.Max()}s"); } else { ((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load any GIF frames!"); } } private float ParseDelayFromFilename(string filename) { Match match = Regex.Match(filename, "delay-([\\d.]+)s"); if (match.Success && float.TryParse(match.Groups[1].Value, out var result)) { return result; } return 0.04f; } private void CreateStandaloneGif() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Expected O, but got Unknown //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) canvasObject = new GameObject("GifOverlayCanvas"); Object.DontDestroyOnLoad((Object)(object)canvasObject); Canvas val = canvasObject.AddComponent<Canvas>(); val.renderMode = (RenderMode)0; val.sortingOrder = 100; CanvasScaler val2 = canvasObject.AddComponent<CanvasScaler>(); val2.uiScaleMode = (ScaleMode)1; val2.referenceResolution = new Vector2(1920f, 1080f); canvasObject.AddComponent<GraphicRaycaster>(); gifObject = new GameObject("GifImage"); gifObject.transform.SetParent(canvasObject.transform, false); Image val3 = gifObject.AddComponent<Image>(); Sprite sprite = Sprite.Create(gifFrames[0], new Rect(0f, 0f, (float)((Texture)gifFrames[0]).width, (float)((Texture)gifFrames[0]).height), new Vector2(0.5f, 0.5f)); val3.sprite = sprite; UpdateGifTransform(); gifCreated = true; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Created standalone GIF overlay!"); } private void UpdateGifTransform() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) RectTransform component = gifObject.GetComponent<RectTransform>(); component.anchorMin = new Vector2(0f, 1f); component.anchorMax = new Vector2(0f, 1f); component.pivot = new Vector2(0f, 1f); component.anchoredPosition = new Vector2(configPosX.Value, configPosY.Value); float value = configScale.Value; component.sizeDelta = new Vector2((float)((Texture)gifFrames[0]).width * value, (float)((Texture)gifFrames[0]).height * value); } private void UpdateGifAnimation() { //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) float num = frameDelays[currentFrame]; frameTimer += Time.deltaTime; if (!(frameTimer >= num)) { return; } frameTimer = 0f; currentFrame = (currentFrame + 1) % gifFrames.Count; if ((Object)(object)gifObject != (Object)null) { Image component = gifObject.GetComponent<Image>(); if ((Object)(object)component != (Object)null) { Sprite sprite = Sprite.Create(gifFrames[currentFrame], new Rect(0f, 0f, (float)((Texture)gifFrames[currentFrame]).width, (float)((Texture)gifFrames[currentFrame]).height), new Vector2(0.5f, 0.5f)); component.sprite = sprite; } } } private Texture2D LoadTexture(string filePath) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown if (!File.Exists(filePath)) { ((BaseUnityPlugin)this).Logger.LogError((object)("Image not found at: " + filePath)); return null; } byte[] array = File.ReadAllBytes(filePath); Texture2D val = new Texture2D(2, 2); ImageConversion.LoadImage(val, array); return val; } }