using 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.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FancyWeatherAPI.API;
using GeneralImprovements;
using GeneralImprovements.Utilities;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using WeatherRegistry;
[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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("GeneralImprovements")]
[assembly: AssemblyCompany("FancyWeatherAPI")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+cb85ffa1189ccd74ab1b50fd68e77515f999b9b7")]
[assembly: AssemblyProduct("FancyWeatherAPI")]
[assembly: AssemblyTitle("FancyWeatherAPI")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace FancyWeatherAPI
{
internal class Config
{
public readonly ConfigEntry<bool> DebugLogsEnabled;
public Config(ConfigFile cfg)
{
cfg.SaveOnConfigSet = false;
DebugLogsEnabled = cfg.Bind<bool>("Debug", "Debug logs", false, "Enable more explicit logs in the console (for debug reasons).");
cfg.Save();
cfg.SaveOnConfigSet = true;
}
public void SetupCustomConfigs()
{
}
}
[BepInPlugin("zigzag.fancyweatherapi", "Fancy Weather API", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
private const string GUID = "zigzag.fancyweatherapi";
private const string NAME = "Fancy Weather API";
private const string VERSION = "1.0.0";
public static Plugin instance;
public static ManualLogSource logger;
private readonly Harmony harmony = new Harmony("zigzag.fancyweatherapi");
internal static List<string> installedWeathers = new List<string>();
internal static Config config { get; private set; } = null;
internal static void DebugLog(object message)
{
if (config.DebugLogsEnabled.Value)
{
logger.LogWarning(message);
}
}
private void Awake()
{
instance = this;
logger = ((BaseUnityPlugin)this).Logger;
config = new Config(((BaseUnityPlugin)this).Config);
config.SetupCustomConfigs();
AnimationLoader.LoadAllAnimationFiles();
AnimationLoader.LoadAllPredefinedAnimations();
harmony.PatchAll();
logger.LogInfo((object)"Fancy Weather API is loaded !");
}
}
}
namespace FancyWeatherAPI.Patches
{
[HarmonyPatch(typeof(MonitorsHelper))]
internal class MonitorPatch
{
internal static string? _curWeatherColorHex;
internal static string? _curOverlayColorHex;
[HarmonyPrefix]
[HarmonyPatch("UpdateWeatherMonitors")]
public static bool InjectNewWeatherAnimations()
{
if (MonitorsHelper._weatherMonitorTexts.Count > 0 && MonitorsHelper.UpdateGenericTextList(MonitorsHelper._weatherMonitorTexts, "WEATHER:\n" + (Object.op_Implicit((Object)(object)StartOfRound.Instance.currentLevel) ? ((object)(LevelWeatherType)(ref StartOfRound.Instance.currentLevel.currentWeather)).ToString() : "???")))
{
Plugin.MLS.LogInfo((object)"Updated basic weather monitors");
}
if (Settings.SetupFinished && MonitorsHelper._fancyWeatherMonitorTexts.Count > 0 && (Object)(object)StartOfRound.Instance.currentLevel != (Object)null)
{
string name = WeatherManager.GetCurrentLevelWeather().Name;
FancyWeatherAnimation value;
bool flag = AnimationLoader.LoadedAnimations.TryGetValue(name, out value);
if (flag)
{
Plugin.DebugLog("[MonitorPatch] Injecting weather animation for " + name);
}
_curWeatherColorHex = (flag ? value.ColorHex : null);
MonitorsHelper._curWeatherAnimations = (flag ? value.GetFullFrames() : WeatherASCIIArt.UnknownAnimations);
if (flag && value.OverlayKey != null)
{
MonitorsHelper._weatherHasOverlays = AnimationLoader.LoadedOverlays.TryGetValue(value.OverlayKey, out FancyWeatherAnimation value2);
if (MonitorsHelper._weatherHasOverlays)
{
_curOverlayColorHex = value2.ColorHex;
MonitorsHelper._weatherOverlayTimer = 0f;
MonitorsHelper._weatherOverlayCycle = Random.Range(0.1f, 3f);
MonitorsHelper._curWeatherOverlays = value2.GetFullFrames();
MonitorsHelper._curWeatherOverlayIndex = Random.Range(0, MonitorsHelper._curWeatherOverlays.Length);
}
}
else
{
MonitorsHelper._weatherHasOverlays = false;
}
MonitorsHelper._weatherShowingOverlay = false;
MonitorsHelper._curWeatherAnimIndex = 0;
MonitorsHelper._weatherAnimTimer = 0f;
if (MonitorsHelper.UpdateGenericTextList(MonitorsHelper._fancyWeatherMonitorTexts, (_curWeatherColorHex != null) ? ("<color=" + _curWeatherColorHex + ">" + MonitorsHelper._curWeatherAnimations[MonitorsHelper._curWeatherAnimIndex] + "</color>") : MonitorsHelper._curWeatherAnimations[MonitorsHelper._curWeatherAnimIndex]))
{
Plugin.MLS.LogInfo((object)"Updated fancy weather monitors");
}
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch("AnimateSpecialMonitors")]
public static bool AnimateSpecialMonitorsFromAPI()
{
if (MonitorsHelper._fancyWeatherMonitorTexts.Count > 0)
{
if (MonitorsHelper._curWeatherAnimations.Length >= 2)
{
MonitorsHelper._weatherAnimTimer += Time.deltaTime;
if (MonitorsHelper._weatherAnimTimer >= MonitorsHelper._weatherAnimCycle)
{
MonitorsHelper._curWeatherAnimIndex = (MonitorsHelper._curWeatherAnimIndex + 1) % MonitorsHelper._curWeatherAnimations.Length;
MonitorsHelper._weatherAnimTimer = 0f;
DrawCustomWeatherAnimation();
}
}
if (MonitorsHelper._weatherHasOverlays)
{
MonitorsHelper._weatherOverlayTimer += Time.deltaTime;
if (MonitorsHelper._weatherOverlayTimer >= (MonitorsHelper._weatherShowingOverlay ? 0.5f : MonitorsHelper._weatherOverlayCycle))
{
MonitorsHelper._weatherOverlayTimer = 0f;
MonitorsHelper._weatherShowingOverlay = !MonitorsHelper._weatherShowingOverlay;
if (!MonitorsHelper._weatherShowingOverlay)
{
MonitorsHelper._weatherOverlayCycle = Random.Range(0.1f, 3f);
MonitorsHelper._curWeatherOverlayIndex = Random.Range(0, MonitorsHelper._curWeatherOverlays.Length);
}
DrawCustomWeatherAnimation();
}
}
}
if (MonitorsHelper._salesMonitorTexts.Count > 0 && MonitorsHelper._curSalesAnimations.Count >= 2)
{
MonitorsHelper._salesAnimTimer += Time.deltaTime;
if (MonitorsHelper._salesAnimTimer >= MonitorsHelper._salesAnimCycle)
{
MonitorsHelper._salesAnimTimer = 0f;
MonitorsHelper._curSalesAnimIndex = (1 + MonitorsHelper._curSalesAnimIndex) % MonitorsHelper._curSalesAnimations.Count;
string text = ((TMP_Text)MonitorsHelper._salesMonitorTexts.First()).text.Split('\n')[0];
MonitorsHelper.UpdateGenericTextList(MonitorsHelper._salesMonitorTexts, text + "\n" + MonitorsHelper._curSalesAnimations[MonitorsHelper._curSalesAnimIndex]);
}
}
if ((MonitorsHelper._playerHealthMonitorTexts.Count > 0 || MonitorsHelper._playerExactHealthMonitorTexts.Count > 0) && MonitorsHelper._curPlayerHealthAnimations.Count >= 2)
{
MonitorsHelper._playerHealthAnimTimer += Time.deltaTime;
if (MonitorsHelper._playerHealthAnimTimer >= MonitorsHelper._playerHealthAnimCycle)
{
MonitorsHelper._playerHealthAnimTimer = 0f;
MonitorsHelper._curPlayerHealthAnimIndex = (1 + MonitorsHelper._curPlayerHealthAnimIndex) % MonitorsHelper._curPlayerHealthAnimations.Count;
if (MonitorsHelper._playerHealthMonitorTexts.Count > 0)
{
MonitorsHelper.UpdateGenericTextList(MonitorsHelper._playerHealthMonitorTexts, MonitorsHelper._curPlayerHealthAnimations[MonitorsHelper._curPlayerHealthAnimIndex]);
}
if (MonitorsHelper._playerExactHealthMonitorTexts.Count > 0)
{
MonitorsHelper.UpdateGenericTextList(MonitorsHelper._playerExactHealthMonitorTexts, MonitorsHelper._curPlayerExactHealthAnimations[MonitorsHelper._curPlayerHealthAnimIndex]);
}
}
}
return false;
}
private static void DrawCustomWeatherAnimation()
{
StringBuilder stringBuilder = new StringBuilder();
string[] array = MonitorsHelper._curWeatherAnimations[MonitorsHelper._curWeatherAnimIndex].Split(Environment.NewLine);
string[] source = (MonitorsHelper._weatherShowingOverlay ? MonitorsHelper._curWeatherOverlays[MonitorsHelper._curWeatherOverlayIndex] : string.Empty).Split(Environment.NewLine);
for (int i = 0; i < array.Length; i++)
{
string text = array[i];
string text2 = source.ElementAtOrDefault(i);
for (int j = 0; j < text.Length; j++)
{
bool flag = !string.IsNullOrWhiteSpace(text2) && text2.Length > j && text2[j] != ' ';
stringBuilder.Append(flag ? ((_curOverlayColorHex != null) ? $"<color={_curOverlayColorHex}>{text2[j]}</color>" : $"{text2[j]}") : ((_curWeatherColorHex != null) ? $"<color={_curWeatherColorHex}>{text[j]}</color>" : $"{text[j]}"));
}
stringBuilder.AppendLine();
}
MonitorsHelper.UpdateGenericTextList(MonitorsHelper._fancyWeatherMonitorTexts, stringBuilder.ToString());
}
}
}
namespace FancyWeatherAPI.API
{
internal class AnimationLoader
{
public static Dictionary<string, FancyWeatherAnimation> LoadedAnimations = new Dictionary<string, FancyWeatherAnimation>();
public static Dictionary<string, FancyWeatherAnimation> LoadedOverlays = new Dictionary<string, FancyWeatherAnimation>();
internal static void LoadAllAnimationFiles()
{
string[] files = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ASCII_Anim"), "*.txt", SearchOption.AllDirectories);
if (files == null)
{
Plugin.logger.LogError((object)"[AnimationLoader] ASCII_Anim folder not found");
return;
}
string[] array = files;
foreach (string text in array)
{
string fileName = Path.GetFileName(text);
Plugin.DebugLog("[AnimationLoader] Found animation file, now loading: " + fileName);
int num = LoadAnimationFromFile(text);
Plugin.DebugLog($"[AnimationLoader] The file {fileName} has loaded {num} custom animations");
}
}
private static int LoadAnimationFromFile(string filePath)
{
try
{
string text = File.ReadAllText(filePath);
if (text == null || text.Length <= 0)
{
Plugin.logger.LogError((object)"[AnimationLoader] The file is empty or null");
return 0;
}
int num = 0;
bool flag = false;
bool flag2 = false;
bool flag3 = false;
FancyWeatherAnimation fancyWeatherAnimation = new FancyWeatherAnimation();
string[] array = text.Split('\n');
foreach (string text2 in array)
{
string text3 = text2.ToLower().Trim();
if (text3 == "parameters")
{
if (fancyWeatherAnimation != null && fancyWeatherAnimation.IsValid() && fancyWeatherAnimation.Name != null)
{
if (!flag)
{
if (LoadedAnimations.TryAdd(fancyWeatherAnimation.Name, fancyWeatherAnimation))
{
num++;
}
}
else if (LoadedOverlays.TryAdd(fancyWeatherAnimation.Name, fancyWeatherAnimation))
{
num++;
}
}
fancyWeatherAnimation = new FancyWeatherAnimation();
flag2 = true;
flag3 = false;
flag = false;
}
else if (text3 == "animation")
{
flag2 = false;
flag3 = true;
}
else if (flag2)
{
string[] array2 = text2.Split(':');
if (array2.Length == 2)
{
string text4 = array2[0].ToLower().Trim();
string text5 = array2[1].Trim();
switch (text4)
{
case "name":
fancyWeatherAnimation.Name = text5;
break;
case "color":
fancyWeatherAnimation.ColorHex = text5;
break;
case "overlayname":
fancyWeatherAnimation.OverlayKey = text5;
break;
case "isoverlay":
flag = text5.ToLower() == "true";
break;
}
}
}
else if (flag3 && !string.IsNullOrWhiteSpace(text2))
{
string item = text2.Replace("\r", "").Replace("\n", "");
fancyWeatherAnimation.FrameLines.Add(item);
}
}
if (fancyWeatherAnimation != null && fancyWeatherAnimation.IsValid() && fancyWeatherAnimation.Name != null)
{
if (!flag)
{
if (LoadedAnimations.TryAdd(fancyWeatherAnimation.Name, fancyWeatherAnimation))
{
num++;
}
}
else if (LoadedOverlays.TryAdd(fancyWeatherAnimation.Name, fancyWeatherAnimation))
{
num++;
}
}
return num;
}
catch (Exception arg)
{
Plugin.logger.LogError((object)$"[AnimationLoader] Unexpected error while reading the file : {arg}");
return 0;
}
}
internal static void LoadAllPredefinedAnimations()
{
if (!LoadedAnimations.ContainsKey("None"))
{
LoadedAnimations.Add("None", new FancyWeatherAnimation
{
Name = "None",
FullFrames = WeatherASCIIArt.ClearAnimations.ToList()
});
}
if (!LoadedAnimations.ContainsKey("Rainy"))
{
LoadedAnimations.Add("Rainy", new FancyWeatherAnimation
{
Name = "Rainy",
FullFrames = WeatherASCIIArt.RainAnimations.ToList()
});
}
if (!LoadedAnimations.ContainsKey("Stormy"))
{
LoadedAnimations.Add("Stormy", new FancyWeatherAnimation
{
Name = "Stormy",
OverlayKey = "Stormy",
FullFrames = WeatherASCIIArt.RainAnimations.ToList()
});
}
if (!LoadedAnimations.ContainsKey("Flooded"))
{
LoadedAnimations.Add("Flooded", new FancyWeatherAnimation
{
Name = "Flooded",
FullFrames = WeatherASCIIArt.FloodedAnimations.ToList()
});
}
if (!LoadedAnimations.ContainsKey("Foggy"))
{
LoadedAnimations.Add("Foggy", new FancyWeatherAnimation
{
Name = "Foggy",
FullFrames = WeatherASCIIArt.FoggyAnimations.ToList()
});
}
if (!LoadedAnimations.ContainsKey("Eclipsed"))
{
LoadedAnimations.Add("Eclipsed", new FancyWeatherAnimation
{
Name = "Eclipsed",
FullFrames = WeatherASCIIArt.EclipsedAnimations.ToList()
});
}
if (!LoadedOverlays.ContainsKey("Stormy"))
{
LoadedOverlays.Add("Stormy", new FancyWeatherAnimation
{
Name = "Stormy",
ColorHex = "#ffe100",
FullFrames = WeatherASCIIArt.LightningOverlays.ToList()
});
}
}
}
public class FancyWeatherAnimation
{
public string? Name { get; set; }
public string? ColorHex { get; set; }
public string? OverlayKey { get; set; }
public List<string> FrameLines { get; private set; } = new List<string>();
internal List<string> FullFrames { private get; set; } = new List<string>();
public bool IsValid()
{
bool flag = !string.IsNullOrEmpty(Name) && FrameLines.Count > 0;
if (flag)
{
string text = "";
for (int i = 0; i < FrameLines.Count; i++)
{
text += FrameLines[i];
if ((i + 1) % 4 == 0)
{
FullFrames.Add(text);
text = "";
}
else
{
text += Environment.NewLine;
}
}
Color val = default(Color);
if (ColorHex == null || !ColorUtility.TryParseHtmlString(ColorHex, ref val))
{
ColorHex = null;
}
Plugin.DebugLog("[FancyWeatherAnimation] The " + Name + " animation is valid");
}
return flag;
}
public string[] GetFullFrames()
{
return FullFrames.ToArray();
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}