using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using JetBrains.Annotations;
using ModdingTales;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Set Injection Flag Plugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Set Injection Flag Plugin")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4e4deb5e-97f9-4901-bf67-6748a9c1229a")]
[assembly: AssemblyFileVersion("2.5.1.0")]
[assembly: AssemblyInformationalVersion("2.5.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("2.5.1.0")]
namespace PluginUtilities
{
[BepInPlugin("org.generic.plugins.setinjectionflag", "Set Injection Flag Plugin", "2.5.1.0")]
public class SetInjectionFlag : BaseUnityPlugin
{
public const string Guid = "org.generic.plugins.setinjectionflag";
public const string Name = "Set Injection Flag Plugin";
public const string Version = "2.5.1.0";
public static void DoConfig(ConfigFile config)
{
ModdingUtils.LogLevelConfig = config.Bind<ModdingUtils.LogLevel>("Logging", "Level", ModdingUtils.LogLevel.Low, (ConfigDescription)null);
if (ModdingUtils.LogLevelConfig.Value == ModdingUtils.LogLevel.Inherited)
{
ModdingUtils.LogLevelConfig.Value = ModdingUtils.LogLevel.None;
Debug.Log((object)"Logging level set to None, Inherited is for child plugins");
}
}
[UsedImplicitly]
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"In Awake for SetInjectionFlag Plug-in");
Debug.Log((object)"SetInjectionFlag Plug-in loaded");
ModdingUtils.Initialize((BaseUnityPlugin)(object)this, ((BaseUnityPlugin)this).Logger);
SceneManager.sceneLoaded += ModdingUtils.OnSceneLoaded;
DoConfig(((BaseUnityPlugin)this).Config);
}
}
}
namespace ModdingTales
{
public static class ModdingUtils
{
public enum LogLevel
{
Inherited,
None,
Low,
Medium,
High,
All
}
private static readonly Dictionary<(BaseUnityPlugin, string), ManualLogSource> ParentPlugins = new Dictionary<(BaseUnityPlugin, string), ManualLogSource>();
public static ConfigEntry<LogLevel> LogLevelConfig { get; set; }
public static TextMeshProUGUI GetUITextByName(string name)
{
TextMeshProUGUI[] array = Object.FindObjectsOfType<TextMeshProUGUI>();
for (int i = 0; i < array.Length; i++)
{
if (((Object)array[i]).name == name)
{
return array[i];
}
}
return null;
}
public static void Initialize(BaseUnityPlugin parentPlugin, ManualLogSource logger, string author, bool startSocket = false)
{
AppStateManager.UsingCodeInjection = true;
ParentPlugins.Add((parentPlugin, author), logger);
logger.LogInfo((object)"Inside initialize");
}
public static void Initialize(BaseUnityPlugin parentPlugin, ManualLogSource logger, bool startSocket = false)
{
AppStateManager.UsingCodeInjection = true;
ParentPlugins.Add((parentPlugin, ""), logger);
logger.LogInfo((object)"Inside initialize");
}
public static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Expected O, but got Unknown
foreach (KeyValuePair<(BaseUnityPlugin, string), ManualLogSource> parentPlugin in ParentPlugins)
{
try
{
parentPlugin.Value.LogInfo((object)("On Scene Loaded " + ((Scene)(ref scene)).name));
Debug.Log((object)("Loading Scene: " + ((Scene)(ref scene)).name));
if (((Scene)(ref scene)).name == "UI")
{
TextMeshProUGUI uITextByName = GetUITextByName("BETA");
if (Object.op_Implicit((Object)(object)uITextByName))
{
((TMP_Text)uITextByName).text = "INJECTED BUILD - unstable mods";
}
continue;
}
TextMeshProUGUI uITextByName2 = GetUITextByName("TextMeshPro Text");
if (Object.op_Implicit((Object)(object)uITextByName2))
{
BepInPlugin val = (BepInPlugin)Attribute.GetCustomAttribute(((object)parentPlugin.Key.Item1).GetType(), typeof(BepInPlugin));
if (((TMP_Text)uITextByName2).text.EndsWith("</size>"))
{
((TMP_Text)uITextByName2).text = ((TMP_Text)uITextByName2).text + "\n\nMods Currently Installed:\n";
}
((TMP_Text)uITextByName2).text = ((TMP_Text)uITextByName2).text + (string.IsNullOrWhiteSpace(parentPlugin.Key.Item2) ? $"\n{val.Name} - {val.Version}" : $"\n{parentPlugin.Key.Item2} {val.Name} - {val.Version}");
}
}
catch (Exception ex)
{
parentPlugin.Value.LogFatal((object)ex);
}
}
}
}
}