using System;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
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("HeightAdjustPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HeightAdjustPlugin")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("HeightAdjustPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.4.0.0")]
namespace LordAshes;
[BepInPlugin("org.lordashes.plugins.heightadjust", "Height Adjust Plug-In", "1.4.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class HeightAdjustPlugin : 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;
}
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 static string GetCreatureName(string nameBlock)
{
if (nameBlock == null)
{
return "(Unknown)";
}
if (!nameBlock.Contains("<size=0>"))
{
return nameBlock;
}
return nameBlock.Substring(0, nameBlock.IndexOf("<size=0>")).Trim();
}
public static GameObject GetBaseLoader(CreatureGuid cid)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
try
{
CreatureBoardAsset val = null;
CreaturePresenter.TryGetAsset(cid, ref val);
if ((Object)(object)val != (Object)null)
{
Transform match = null;
Traverse(((Component)val).transform, "BaseLoader", 0, 10, ref match);
if ((Object)(object)match != (Object)null)
{
Debug.Log((object)("Height Adjust Plug-In: Base Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
return ((Component)match.GetChild(0)).gameObject;
}
Debug.LogWarning((object)"Height Adjust Plug-In: Could Not Find Base Loader");
return null;
}
return null;
}
catch
{
return null;
}
}
public static GameObject GetAssetLoader(CreatureGuid cid)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
try
{
CreatureBoardAsset val = null;
CreaturePresenter.TryGetAsset(cid, ref val);
if ((Object)(object)val != (Object)null)
{
Transform match = null;
Traverse(((Component)val).transform, "AssetLoader", 0, 10, ref match);
if ((Object)(object)match != (Object)null)
{
Debug.Log((object)("Height Adjust Plug-In: Asset Loader '" + ((Object)match.GetChild(0)).name + "' Found"));
return ((Component)match.GetChild(0)).gameObject;
}
Debug.LogWarning((object)"Height Adjust Plug-In: Could Not Find Asset Loader");
return null;
}
return null;
}
catch
{
return null;
}
}
public static void Traverse(Transform root, string seek, int depth, int depthMax, ref Transform match)
{
try
{
if ((Object)(object)match != (Object)null)
{
return;
}
if (((Object)root).name == seek)
{
match = root;
return;
}
foreach (Transform item in ExtensionMethods.Children(root))
{
if (depth < depthMax)
{
Traverse(item, seek, depth + 1, depthMax, ref match);
}
}
}
catch
{
}
}
public static float ParseFloat(string value)
{
return float.Parse(value, CultureInfo.InvariantCulture);
}
}
public const string Name = "Height Adjust Plug-In";
public const string Guid = "org.lordashes.plugins.heightadjust";
public const string Version = "1.4.0.0";
private Guid[] subscriptions = new Guid[2]
{
System.Guid.Empty,
System.Guid.Empty
};
private bool allowDig = false;
private ConfigEntry<KeyboardShortcut> triggerTransformKey { get; set; }
private ConfigEntry<KeyboardShortcut> triggerUpKey { get; set; }
private ConfigEntry<KeyboardShortcut> triggerDownKey { get; set; }
public void HandleRequest(DatumChange change)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Invalid comparison between Unknown and I4
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
if ((int)change.action != 1)
{
SetRequest(new CreatureGuid(change.source.ToString()), change.value.ToString());
}
}
private void SetRequest(CreatureGuid cid, string offsets)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
CreatureBoardAsset val = null;
CreaturePresenter.TryGetAsset(cid, ref val);
if (!((Object)(object)val != (Object)null))
{
return;
}
CreatureGuid creatureId = val.CreatureId;
string text = AssetDataPlugin.ReadInfo(((object)(CreatureGuid)(ref creatureId)).ToString(), "org.lordashes.plugins.heightadjust.Floor");
string[] array = offsets.Split(new string[1] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < array.Length; i++)
{
string[] obj = new string[8]
{
"Applying Creature ",
Utility.GetCreatureName(val.Name),
" (",
null,
null,
null,
null,
null
};
creatureId = val.CreatureId;
obj[3] = ((object)(CreatureGuid)(ref creatureId)).ToString();
obj[4] = ") Height of ";
obj[5] = array[i];
obj[6] = " with floor at ";
obj[7] = text;
Debug.Log((object)string.Concat(obj));
if (!allowDig && float.Parse(array[i]) < float.Parse(text))
{
array[i] = text;
}
Utility.GetAssetLoader(val.CreatureId).transform.position = new Vector3(Utility.GetAssetLoader(val.CreatureId).transform.position.x, float.Parse(array[i]), Utility.GetAssetLoader(val.CreatureId).transform.position.z);
}
float num = Math.Abs(float.Parse(array[0]) - float.Parse(text));
Renderer component = Utility.GetBaseLoader(val.CreatureId).GetComponent<Renderer>();
string[] obj2 = new string[7]
{
"Creature ",
Utility.GetCreatureName(val.Name),
"(",
null,
null,
null,
null
};
creatureId = val.CreatureId;
obj2[3] = ((object)(CreatureGuid)(ref creatureId)).ToString();
obj2[4] = ") ";
obj2[5] = (((double)num <= 0.1) ? "Showing " : "Hiding");
obj2[6] = " Base";
Debug.Log((object)string.Concat(obj2));
if ((Object)(object)component != (Object)null)
{
component.enabled = (double)num <= 0.1;
}
int instanceID = ((Object)((Component)val).transform).GetInstanceID();
GameObject[] array2 = Object.FindObjectsOfType<GameObject>();
foreach (GameObject val2 in array2)
{
if (!((Object)val2).name.Contains("Indicator"))
{
continue;
}
Transform val3 = val2.transform;
for (int k = 0; k < 10; k++)
{
try
{
val3 = val3.parent;
if (((Object)val3).GetInstanceID() == instanceID)
{
string[] obj3 = new string[7]
{
"Creature ",
Utility.GetCreatureName(val.Name),
"(",
null,
null,
null,
null
};
creatureId = val.CreatureId;
obj3[3] = ((object)(CreatureGuid)(ref creatureId)).ToString();
obj3[4] = ") ";
obj3[5] = (((double)num <= 0.1) ? "Showing " : "Hiding");
obj3[6] = " Ring";
Debug.Log((object)string.Concat(obj3));
component = val2.GetComponentInChildren<Renderer>();
if ((Object)(object)component != (Object)null)
{
component.enabled = (double)num <= 0.1;
}
break;
}
}
catch (Exception)
{
break;
}
}
}
}
private void Awake()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"Template Plugin: Lord Ashes Hight Adjustment Plugin Is Active.");
triggerTransformKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Apply After Board Load", new KeyboardShortcut((KeyCode)116, (KeyCode[])(object)new KeyCode[1] { (KeyCode)305 }), (ConfigDescription)null);
triggerUpKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Adjust Mini Up", new KeyboardShortcut((KeyCode)270, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), (ConfigDescription)null);
triggerDownKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Adjust Mini Down", new KeyboardShortcut((KeyCode)269, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), (ConfigDescription)null);
allowDig = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Allow digging (height adjustment into the ground)", false, (ConfigDescription)null).Value;
subscriptions[0] = AssetDataPlugin.Subscribe("org.lordashes.plugins.heightadjust.Floor", (Action<DatumChange>)HandleRequest, (Func<DatumChange, bool>)Checker.CheckSourceAsCreature);
subscriptions[1] = AssetDataPlugin.Subscribe("org.lordashes.plugins.heightadjust", (Action<DatumChange>)HandleRequest, (Func<DatumChange, bool>)Checker.CheckSourceAsCreature);
Utility.PostOnMainPage(((object)this).GetType());
}
private void OnGUI()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: 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_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Expected O, but got Unknown
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Expected O, but got Unknown
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
if (!Utility.isBoardLoaded())
{
return;
}
CreatureBoardAsset val = null;
CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref val);
if (!((Object)(object)val != (Object)null))
{
return;
}
CreatureGuid creatureId = val.CreatureId;
string text = AssetDataPlugin.ReadInfo(((object)(CreatureGuid)(ref creatureId)).ToString(), "org.lordashes.plugins.heightadjust.Floor");
if (text != "")
{
float num = Utility.GetAssetLoader(val.CreatureId).transform.position.y - float.Parse(text);
if ((double)num > 0.1)
{
GUIStyle val2 = new GUIStyle();
val2.fontSize = 32;
val2.normal.textColor = Color.black;
GUIStyle val3 = new GUIStyle();
val3.fontSize = 32;
val3.normal.textColor = Color.yellow;
GUI.Label(new Rect(908f, 38f, 100f, 120f), Math.Round(num * 5f) + " Feet", val2);
GUI.Label(new Rect(910f, 40f, 100f, 120f), Math.Round(num * 5f) + " Feet", val3);
}
}
}
private void Update()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
if (!Utility.isBoardLoaded())
{
return;
}
float num = 0f;
KeyboardShortcut value = triggerDownKey.Value;
if (((KeyboardShortcut)(ref value)).IsUp())
{
num = 0.2f;
}
else
{
value = triggerUpKey.Value;
if (((KeyboardShortcut)(ref value)).IsUp())
{
num = -0.2f;
}
}
if (num != 0f)
{
CreatureBoardAsset val = null;
CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref val);
string text = "";
CreatureGuid creatureId;
if ((Object)(object)val != (Object)null)
{
creatureId = val.CreatureId;
if (AssetDataPlugin.ReadInfo(((object)(CreatureGuid)(ref creatureId)).ToString(), "org.lordashes.plugins.heightadjust.Floor") == "")
{
creatureId = val.CreatureId;
AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref creatureId)).ToString(), "org.lordashes.plugins.heightadjust.Floor", Utility.GetAssetLoader(val.CreatureId).transform.position.y.ToString(), false);
}
GameObject assetLoader = Utility.GetAssetLoader(val.CreatureId);
string[] obj = new string[8]
{
"Requesting Creature ",
Utility.GetCreatureName(val.Name),
" (",
null,
null,
null,
null,
null
};
creatureId = val.CreatureId;
obj[3] = ((object)(CreatureGuid)(ref creatureId)).ToString();
obj[4] = ") Height From ";
obj[5] = assetLoader.transform.position.y.ToString();
obj[6] = " to ";
obj[7] = (assetLoader.transform.position.y + num).ToString();
Debug.Log((object)string.Concat(obj));
text = text + (assetLoader.transform.position.y + num) + ",";
}
creatureId = val.CreatureId;
AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref creatureId)).ToString(), "org.lordashes.plugins.heightadjust", text, false);
}
value = triggerTransformKey.Value;
if (((KeyboardShortcut)(ref value)).IsUp())
{
Debug.Log((object)"Applying Height Adjustments");
if (subscriptions[0] != System.Guid.Empty)
{
AssetDataPlugin.Unsubscribe(subscriptions[0]);
AssetDataPlugin.Unsubscribe(subscriptions[1]);
}
AssetDataPlugin.Reset("org.lordashes.plugins.heightadjust.Floor");
AssetDataPlugin.Reset("org.lordashes.plugins.heightadjust");
subscriptions[0] = AssetDataPlugin.Subscribe("org.lordashes.plugins.heightadjust.Floor", (Action<DatumChange>)HandleRequest, (Func<DatumChange, bool>)Checker.CheckSourceAsCreature);
subscriptions[1] = AssetDataPlugin.Subscribe("org.lordashes.plugins.heightadjust", (Action<DatumChange>)HandleRequest, (Func<DatumChange, bool>)Checker.CheckSourceAsCreature);
}
}
}