using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LightEditorPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LightEditorPlugin")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("LightEditorPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace LordAshes;
[BepInPlugin("org.lordashes.plugins.lighteditor", "Light Editor Plug-In", "1.1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class LightEditorPlugin : BaseUnityPlugin
{
public static class Utility
{
public static void PostOnMainPage(MemberInfo plugin)
{
SceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode)
{
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
try
{
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";
}
}
else
{
TextMeshProUGUI uITextByName2 = GetUITextByName("TextMeshPro Text");
if (Object.op_Implicit((Object)(object)uITextByName2))
{
BepInPlugin val = (BepInPlugin)Attribute.GetCustomAttribute(plugin, typeof(BepInPlugin));
if (((TMP_Text)uITextByName2).text.EndsWith("</size>"))
{
((TMP_Text)uITextByName2).text = ((TMP_Text)uITextByName2).text + "\n\nMods Currently Installed:\n";
}
TextMeshProUGUI val2 = uITextByName2;
((TMP_Text)val2).text = ((TMP_Text)val2).text + "\nLord Ashes' " + val.Name + " - " + val.Version;
}
}
}
catch (Exception ex)
{
Debug.Log((object)ex);
}
};
}
public static bool isBoardLoaded()
{
return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
}
public static bool StrictKeyCheck(KeyboardShortcut check)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
if (!((KeyboardShortcut)(ref check)).IsUp())
{
return false;
}
KeyCode[] array = new KeyCode[6];
RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
KeyCode[] array2 = (KeyCode[])(object)array;
foreach (KeyCode val in array2)
{
if (Input.GetKey(val) != ((KeyboardShortcut)(ref check)).Modifiers.Contains(val))
{
return false;
}
}
return true;
}
private 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 const string Name = "Light Editor Plug-In";
public const string Guid = "org.lordashes.plugins.lighteditor";
public const string Version = "1.1.0.0";
private ConfigEntry<KeyboardShortcut> triggerKey { get; set; }
private void Awake()
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)("Light Editor Plugin: " + ((object)this).GetType().AssemblyQualifiedName + " Active."));
triggerKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Open Light Editor", new KeyboardShortcut((KeyCode)107, (KeyCode[])(object)new KeyCode[1] { (KeyCode)305 }), (ConfigDescription)null);
ConfigEditorPlugin.Subscribe((Action<string, string>)EditorCallback);
Utility.PostOnMainPage(((object)this).GetType());
}
private void Update()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
if (Utility.isBoardLoaded() && Utility.StrictKeyCheck(triggerKey.Value))
{
Debug.Log((object)"Light Editor Plugin: Open Editor");
CreatureGuid selectedCreatureId = LocalClient.SelectedCreatureId;
string key = AssetDataPlugin.ReadInfo(((object)(CreatureGuid)(ref selectedCreatureId)).ToString(), "org.lordashes.plugins.light");
if (LightPlugin.lights.ContainsKey(key))
{
ConfigEditorPlugin.offsetXToEntry = 120;
ConfigEditorPlugin.Open("Light", JsonConvert.SerializeObject((object)LightPlugin.lights[key]), new string[3] { "Cancel", "Apply", "Save" });
ConfigEditorPlugin.SetItemDataType("specs.color", typeof(Color));
}
}
}
private void OnGUI()
{
ConfigEditorPlugin.Render();
}
private void EditorCallback(string button, string json)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
CreatureGuid selectedCreatureId = LocalClient.SelectedCreatureId;
string key = AssetDataPlugin.ReadInfo(((object)(CreatureGuid)(ref selectedCreatureId)).ToString(), "org.lordashes.plugins.light");
if (LightPlugin.lights.ContainsKey(key))
{
if (button == "Apply" || button == "Save")
{
Debug.Log((object)"Light Editor Plugin: Apply Light");
LightPlugin.lights[key] = JsonConvert.DeserializeObject<LightSpecs>(json);
AssetDataPlugin.Reset("org.lordashes.plugins.light");
}
if (button == "Save")
{
Debug.Log((object)"Light Editor Plugin: Save Light");
string path = LightPlugin.configLocation.Substring(0, LightPlugin.configLocation.Replace("\\", "/").LastIndexOf("/")) + "/LightSpecs.json";
File.WriteAllText(path, JsonConvert.SerializeObject((object)LightPlugin.lights.Values, (Formatting)1));
}
if (button == "Cancel")
{
Debug.Log((object)"Light Editor Plugin: Cancel Changes");
LightPlugin.ReadConfiguration(ref LightPlugin.lights);
AssetDataPlugin.Reset("org.lordashes.plugins.light");
}
if (button == "Save" || button == "Cancel")
{
Debug.Log((object)"Light Editor Plugin: Closing Light Editor");
ConfigEditorPlugin.Close();
}
}
}
}