using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NotificationTweaks;
[BepInPlugin("aedenthorn.NotificationTweaks", "Notification Tweaks", "0.5.0")]
public class BepInExPlugin : BaseUnityPlugin
{
public enum NotificationType
{
TopRight,
TopLeft,
Center,
BottomRight,
BottomLeft
}
[HarmonyPatch(typeof(MessageHud), "Awake")]
private static class Awake_Patch
{
private static void Prefix(MessageHud __instance)
{
if (modEnabled.Value)
{
__instance.m_messageText.alignment = (TextAlignmentOptions)1025;
}
}
}
[HarmonyPatch(typeof(MessageHud), "ShowMessage")]
private static class ShowMessage_Patch
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
if (!modEnabled.Value)
{
return instructions;
}
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (i > 2 && list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 4f && list[i - 3].opcode == OpCodes.Ldc_R4)
{
list[i].operand = (float)list[i].operand / largeSpeedMultiplier.Value;
}
}
return list;
}
}
[HarmonyPatch(typeof(MessageHud), "UpdateMessage")]
private static class UpdateMessage_Patch
{
private static void Prefix(MessageHud __instance, ref float dt)
{
//IL_0050: 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_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
if (modEnabled.Value)
{
__instance.m_messageText.fontSize = smallNotificationSize.Value;
__instance.m_messageCenterText.fontSize = largeNotificationSize.Value;
((Graphic)__instance.m_messageText).color = smallColor.Value;
((Graphic)__instance.m_messageCenterText).color = largeColor.Value;
((Component)__instance.m_messageText.transform.parent).GetComponent<RectTransform>().anchoredPosition = new Vector2(smallNotificationPosition.Value.x, 0f - smallNotificationPosition.Value.y);
}
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
if (!modEnabled.Value)
{
return instructions;
}
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (i > 2 && list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 4f && list[i - 3].opcode == OpCodes.Ldc_R4)
{
list[i].operand = (float)list[i].operand / smallSpeedMultiplier.Value;
}
}
return list;
}
private static void Postfix(MessageHud __instance)
{
if (!modEnabled.Value)
{
return;
}
object value = typeof(MessageHud).GetField("m_msgQeue", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
IEnumerable<object> enumerable = value as IEnumerable<object>;
if (enumerable.Count() == 0)
{
return;
}
((Graphic)__instance.m_messageText).CrossFadeAlpha(1f, 0f, true);
object value2 = typeof(MessageHud).GetField("currentMsg", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
FieldInfo field = value2.GetType().GetField("m_amount", BindingFlags.Instance | BindingFlags.Public);
FieldInfo field2 = value2.GetType().GetField("m_text", BindingFlags.Instance | BindingFlags.Public);
string text = (string)field2.GetValue(value2);
Dictionary<string, object> dictionary = new Dictionary<string, object>();
string[] array = ignoreKeywords.Value.Split(new char[1] { ',' });
foreach (object item in enumerable)
{
int num = (int)field.GetValue(item);
string text2 = (string)field2.GetValue(item);
string[] array2 = array;
foreach (string value3 in array2)
{
if (text2.Contains(value3))
{
}
}
if (text == text2)
{
field.SetValue(value2, (int)field.GetValue(value2) + num);
}
else if (dictionary.ContainsKey(text2))
{
field.SetValue(dictionary[text2], (int)field.GetValue(dictionary[text2]) + num);
}
else
{
dictionary[text2] = item;
}
}
int num2 = (int)field.GetValue(value2);
__instance.m_messageText.text = text + ((num2 > 1) ? (" x" + num2) : "");
typeof(MessageHud).GetField("currentMsg", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance, value2);
value.GetType().GetMethod("Clear", BindingFlags.Instance | BindingFlags.Public).Invoke(value, null);
int num3 = 0;
foreach (KeyValuePair<string, object> item2 in dictionary)
{
if (num3 < ((maxNotifications.Value < 0) ? enumerable.Count() : maxNotifications.Value))
{
int num4 = (int)field.GetValue(item2.Value);
string text3 = (string)field2.GetValue(item2.Value);
__instance.m_messageText.text = text3 + ((num4 > 1) ? (" x" + num4) : "") + "\n" + __instance.m_messageText.text;
}
num3++;
value.GetType().GetMethod("Enqueue", BindingFlags.Instance | BindingFlags.Public).Invoke(value, new object[1] { item2.Value });
}
}
}
[HarmonyPatch(typeof(Terminal), "InputText")]
private static class InputText_Patch
{
private static bool Prefix(Terminal __instance)
{
if (!modEnabled.Value)
{
return true;
}
string text = ((TMP_InputField)__instance.m_input).text;
if (text.ToLower().Equals(typeof(BepInExPlugin).Namespace.ToLower() + " reset"))
{
((BaseUnityPlugin)context).Config.Reload();
((BaseUnityPlugin)context).Config.Save();
Traverse.Create((object)__instance).Method("AddString", new object[1] { text }).GetValue();
Traverse.Create((object)__instance).Method("AddString", new object[1] { ((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded" }).GetValue();
return false;
}
return true;
}
}
private static readonly bool isDebug = true;
private static BepInExPlugin context;
private Harmony harmony;
public static ConfigEntry<bool> modEnabled;
public static ConfigEntry<int> nexusID;
public static ConfigEntry<string> ignoreKeywords;
public static ConfigEntry<int> maxNotifications;
public static ConfigEntry<float> smallSpeedMultiplier;
public static ConfigEntry<float> largeSpeedMultiplier;
public static ConfigEntry<int> smallNotificationSize;
public static ConfigEntry<int> largeNotificationSize;
public static ConfigEntry<Color> smallColor;
public static ConfigEntry<Color> largeColor;
public static ConfigEntry<Vector2> smallNotificationPosition;
public static void Dbgl(string str = "", bool pref = true)
{
if (isDebug)
{
Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
}
}
private void Awake()
{
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Expected O, but got Unknown
context = this;
modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 951, "Nexus mod ID for updates");
ignoreKeywords = ((BaseUnityPlugin)this).Config.Bind<string>("Notifications", "IgnoreKeywords", "", "Don't display notifications with any of these keywords or phrases (comma-separated)");
smallNotificationPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("Notifications", "SmallNotificationPosition", new Vector2(40f, 170f), "Small notification screen position");
maxNotifications = ((BaseUnityPlugin)this).Config.Bind<int>("Notifications", "MaxNotifications", 4, "Max number of notifications to show. Use -1 for unlimited");
smallSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Notifications", "SmallSpeedMultiplier", 1f, "Make small notifications disappear faster by this multiplier (requires game restart)");
largeSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Notifications", "LargeSpeedMultiplier", 1f, "Make large notifications disappear faster by this multiplier (requires game restart)");
smallNotificationSize = ((BaseUnityPlugin)this).Config.Bind<int>("Notifications", "SmallNotificationSize", 20, "Small notification font size");
largeNotificationSize = ((BaseUnityPlugin)this).Config.Bind<int>("Notifications", "LargeNotificationSize", 40, "Large notification font size");
smallColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Notifications", "SmallNotificationColor", new Color(0.86f, 0.86f, 0.86f, 1f), "Small notification color");
largeColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Notifications", "LargeNotificationColor", new Color(1f, 0.807f, 0f, 1f), "Large notification color");
if (modEnabled.Value)
{
harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
harmony.PatchAll();
}
}
private void OnDestroy()
{
Dbgl("Destroying plugin");
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchAll((string)null);
}
}
}