using System;
using System.Collections.Generic;
using System.Diagnostics;
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 Bounce.Unmanaged;
using ModdingTales;
using Newtonsoft.Json;
using RadialUI;
using Unity.Mathematics;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CustomStatsPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomStatsPlugin")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("TemplatePlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("2.4.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("2.4.1.0")]
namespace LordAshes;
[BepInPlugin("org.lordashes.plugins.customstats", "Custom Stats Plug-In", "2.4.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class CustomStatsPlugin : BaseUnityPlugin
{
public static class PatchAssistant
{
public static object GetProperty(object instance, string propertyName)
{
Type type = instance.GetType();
foreach (PropertyInfo runtimeProperty in type.GetRuntimeProperties())
{
if (runtimeProperty.Name.Contains(propertyName))
{
return runtimeProperty.GetValue(instance);
}
}
PropertyInfo[] properties = type.GetProperties();
foreach (PropertyInfo propertyInfo in properties)
{
if (propertyInfo.Name.Contains(propertyName))
{
return propertyInfo.GetValue(instance);
}
}
return null;
}
public static void SetProperty(object instance, string propertyName, object value)
{
Type type = instance.GetType();
foreach (PropertyInfo runtimeProperty in type.GetRuntimeProperties())
{
if (runtimeProperty.Name.Contains(propertyName))
{
runtimeProperty.SetValue(instance, value);
return;
}
}
PropertyInfo[] properties = type.GetProperties();
foreach (PropertyInfo propertyInfo in properties)
{
if (propertyInfo.Name.Contains(propertyName))
{
propertyInfo.SetValue(instance, value);
break;
}
}
}
public static object GetField(object instance, string fieldName)
{
Type type = instance.GetType();
foreach (FieldInfo runtimeField in type.GetRuntimeFields())
{
if (runtimeField.Name.Contains(fieldName))
{
try
{
return runtimeField.GetValue(instance);
}
catch (Exception ex)
{
LoggingPlugin.LogWarning("Patch Assistant: Unable To GetValue Of '" + fieldName + "' From '" + instance?.ToString() + "'\r\n" + ex);
return null;
}
}
}
FieldInfo[] fields = type.GetFields();
foreach (FieldInfo fieldInfo in fields)
{
if (fieldInfo.Name.Contains(fieldName))
{
try
{
return fieldInfo.GetValue(instance);
}
catch (Exception ex2)
{
LoggingPlugin.LogWarning("Patch Assistant: Unable To GetValue Of '" + fieldName + "' From '" + instance?.ToString() + "'\r\n" + ex2);
return null;
}
}
}
return null;
}
public static void SetField(object instance, string fieldName, object value)
{
Type type = instance.GetType();
foreach (FieldInfo runtimeField in type.GetRuntimeFields())
{
if (runtimeField.Name.Contains(fieldName))
{
runtimeField.SetValue(instance, value);
return;
}
}
FieldInfo[] fields = type.GetFields();
foreach (FieldInfo fieldInfo in fields)
{
if (fieldInfo.Name.Contains(fieldName))
{
fieldInfo.SetValue(instance, value);
break;
}
}
}
public static object UseMethod(object instance, string methodName, object[] parameters)
{
Type type = instance.GetType();
foreach (MethodInfo runtimeMethod in type.GetRuntimeMethods())
{
if (runtimeMethod.Name.Contains(methodName))
{
return runtimeMethod.Invoke(instance, parameters);
}
}
MethodInfo[] methods = type.GetMethods();
foreach (MethodInfo methodInfo in methods)
{
if (methodInfo.Name.Contains(methodName))
{
return methodInfo.Invoke(instance, parameters);
}
}
return null;
}
}
public static class Utility
{
private static GameInput gameInputInstance;
private static MethodInfo gameInputDisable;
private static MethodInfo gameInputEnable;
public static void PostOnMainPage(BaseUnityPlugin plugin)
{
string text = "Lord Ashes" + ("Lord Ashes".ToUpper().EndsWith("S") ? "'" : "'s");
ModdingUtils.AddPluginToMenuList(plugin, text);
}
public static bool isBoardLoaded()
{
return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
}
public static void GameInputEnabled(bool setting)
{
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Expected O, but got Unknown
if (gameInputInstance == null || gameInputDisable == null || gameInputEnable == null)
{
try
{
LoggingPlugin.LogInfo("Plane Image Plugin: Getting Game Input Reference");
gameInputInstance = null;
gameInputDisable = null;
gameInputEnable = null;
gameInputInstance = (GameInput)(from f in typeof(ControllerManager).GetRuntimeFields()
where f.Name == "_gameInput"
select f).ToArray()[0].GetValue(null);
gameInputDisable = (from m in typeof(GameInput).GetMethods()
where m.Name == "Disable"
select m).ElementAt(0);
gameInputEnable = (from m in typeof(GameInput).GetMethods()
where m.Name == "Enable"
select m).ElementAt(0);
}
catch
{
LoggingPlugin.LogWarning("Plane Image Plugin: Unable To Get Game Input Reference Or Reference To One Of Its Methods");
}
}
if (setting)
{
LoggingPlugin.LogDebug("Plane Image Plugin: Enabling Game Input");
gameInputEnable.Invoke(gameInputInstance, new object[0]);
}
else
{
LoggingPlugin.LogDebug("Plane Image Plugin: Disabling Game Input");
gameInputDisable.Invoke(gameInputInstance, new object[0]);
}
}
}
private static class Internal
{
public static bool selectedMiniStatsOpen = false;
public static Vector2 statMenuCentre = new Vector2((float)(Screen.width / 2), (float)(Screen.height / 2));
public static Dictionary<string, string> selectedMiniStats = new Dictionary<string, string>();
public static ConfigEntry<KeyboardShortcut> defineModel;
public static ConfigEntry<float> menuBaseRadius;
public static ConfigEntry<float> menuItemMultiplier;
public static ConfigEntry<bool> whisperToGM;
}
public const string Name = "Custom Stats Plug-In";
public const string Guid = "org.lordashes.plugins.customstats";
public const string Version = "2.4.1.0";
public const string Author = "Lord Ashes";
private void Awake()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Expected O, but got Unknown
LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Log Level", (DiagnosticLevel)1, (ConfigDescription)null).Value);
LoggingPlugin.LogInfo(((object)this).GetType().AssemblyQualifiedName + " Active.");
Internal.whisperToGM = ((BaseUnityPlugin)this).Config.Bind<bool>("Hotkeys", "Whisper Changes To GM", true, (ConfigDescription)null);
Internal.defineModel = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Apply Model", new KeyboardShortcut((KeyCode)97, (KeyCode[])(object)new KeyCode[1] { (KeyCode)305 }), (ConfigDescription)null);
Internal.menuBaseRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Setting", "Stat Menu Base Radius", 25f, (ConfigDescription)null);
Internal.menuItemMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Setting", "Stat Menu Radius Increase Per Item", 10f, (ConfigDescription)null);
if (((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Remove Core Stats Menu", true, (ConfigDescription)null).Value)
{
RadialUIPlugin.HideDefaultCharacterMenuItem("org.lordashes.plugins.customstats", "Stats", (ShouldShowMenu)null);
}
RadialUIPlugin.AddCustomButtonOnCharacter("org.lordashes.plugins.customstats", new ItemArgs
{
Action = StatMenuCallback,
CloseMenuOnActivate = true,
FadeName = true,
Icon = Image.LoadSprite("Stats.png", (CacheType)999),
Title = "Custom Stats"
}, (Func<NGuid, NGuid, bool>)((NGuid a, NGuid b) => true));
Utility.PostOnMainPage((BaseUnityPlugin)(object)this);
}
private void StatMenuCallback(MapMenuItem arg1, object arg2)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: 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_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: 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_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
LoggingPlugin.LogDebug("Custom Stats Plugin: Radial Stats Menu Callback");
CreatureBoardAsset val = default(CreatureBoardAsset);
CreaturePresenter.TryGetAsset(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()), ref val);
Vector3 val2 = Camera.main.WorldToScreenPoint(((EmotingMovableBoardAsset)val).GetHook((HookTransform)2).position);
Internal.statMenuCentre = new Vector2(val2.x, 1080f - val2.y);
Internal.selectedMiniStats.Clear();
CreatureGuid creatureId = val.CreatureId;
string text = AssetDataPlugin.ReadInfo(((object)(CreatureGuid)(ref creatureId)).ToString(), "org.lordashes.plugins.customstats.stats");
if (text != null && text.Trim() != "")
{
LoggingPlugin.LogTrace("Custom Stats Plugin: Custom Stats JSON = " + text);
Internal.selectedMiniStats = JsonConvert.DeserializeObject<Dictionary<string, string>>(text);
}
Internal.selectedMiniStatsOpen = true;
Utility.GameInputEnabled(setting: false);
LoggingPlugin.LogDebug("Custom Stats Plugin: Syncing Core Stats With Custom Stats");
CampaignSessionManager instance = Object.FindObjectOfType<CampaignSessionManager>();
string[] array = (string[])PatchAssistant.GetField(instance, "_statNames");
for (int i = 0; i < array.Length; i++)
{
if (Internal.selectedMiniStats.ContainsKey(array[i]))
{
LoggingPlugin.LogTrace("Custom Stats Plugin: Syncing '" + array[i] + "'");
CreatureDataV3 val3 = default(CreatureDataV3);
CreatureManager.TryGetCreatureData(val.CreatureId, ref val3);
Dictionary<string, string> selectedMiniStats = Internal.selectedMiniStats;
string key = array[i];
float value = ((CreatureDataV3)(ref val3)).StatByIndex(i, false).Value;
string text2 = value.ToString();
value = ((CreatureDataV3)(ref val3)).StatByIndex(i, false).Max;
selectedMiniStats[key] = text2 + "/" + value;
}
}
}
private void Update()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
if (!Utility.isBoardLoaded())
{
return;
}
KeyboardShortcut value = Internal.defineModel.Value;
if (!((KeyboardShortcut)(ref value)).IsUp())
{
return;
}
SystemMessage.AskForTextInput("Apply Custom Stats", "Custom Stats Model:", "Apply", (Action<string>)delegate(string modelName)
{
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
Internal.selectedMiniStats.Clear();
string[] array = File.Find(modelName + ".model", (CacheType)999);
if (array.Length != 0)
{
if (array.Length > 1)
{
LoggingPlugin.LogWarning("Custom Stats Plugin: Multiple Definitions For '" + modelName + "' (" + modelName + ".model) Exist. Using First.");
}
string[] array2 = File.ReadAllText(array[0], (CacheType)999).Split(new char[1] { ',' });
foreach (string key in array2)
{
Internal.selectedMiniStats.Add(key, "---");
}
string text = JsonConvert.SerializeObject((object)Internal.selectedMiniStats);
CreatureGuid selectedCreatureId = LocalClient.SelectedCreatureId;
AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref selectedCreatureId)).ToString(), "org.lordashes.plugins.customstats.stats", text, false);
}
else
{
SystemMessage.DisplayInfoText("Custom Stats Plugin: Unable To Find Definition For Model '" + modelName + "'", 2.5f, 0f);
}
}, (Action)null, "Cancel", (Action)null, "");
}
private void OnGUI()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Expected O, but got Unknown
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Unknown result type (might be due to invalid IL or missing references)
//IL_027c: Unknown result type (might be due to invalid IL or missing references)
//IL_0291: Unknown result type (might be due to invalid IL or missing references)
//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
//IL_02be: Unknown result type (might be due to invalid IL or missing references)
//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0318: Unknown result type (might be due to invalid IL or missing references)
//IL_0333: Unknown result type (might be due to invalid IL or missing references)
//IL_0378: Unknown result type (might be due to invalid IL or missing references)
//IL_0390: Unknown result type (might be due to invalid IL or missing references)
//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
if (!Internal.selectedMiniStatsOpen)
{
return;
}
Internal.statMenuCentre = new Vector2((float)(Screen.width / 2), (float)(Screen.height / 2));
LoggingPlugin.LogTrace("Custom Stats Plugin: Screen = " + Screen.width + "x" + Screen.height);
LoggingPlugin.LogTrace("Custom Stats Plugin: Custom Stat Centre = " + Internal.statMenuCentre.x + "x" + Internal.statMenuCentre.y);
GUIStyle val = new GUIStyle();
val.alignment = (TextAnchor)4;
val.fontSize = 16;
val.normal.textColor = Color.red;
GUI.Box(new Rect(Internal.statMenuCentre.x - 10f, Internal.statMenuCentre.y, 20f, 20f), (Texture)(object)Texture2D.blackTexture);
if (GUI.Button(new Rect(Internal.statMenuCentre.x - 10f, Internal.statMenuCentre.y, 20f, 20f), "X", val))
{
Utility.GameInputEnabled(setting: true);
if (Internal.whisperToGM.Value)
{
WhisperToGM();
}
string text = JsonConvert.SerializeObject((object)Internal.selectedMiniStats);
LoggingPlugin.LogTrace("Custom Stats Plugin: Updating Custom Stats");
CreatureGuid val2 = new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature());
AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref val2)).ToString(), "org.lordashes.plugins.customstats.stats", text, false);
LoggingPlugin.LogTrace("Custom Stats Plugin: Updating Core Stats");
UpdateCoreStats(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()), Internal.selectedMiniStats);
Internal.selectedMiniStatsOpen = false;
}
float num = 360f / (float)Internal.selectedMiniStats.Count;
float num2 = Internal.menuBaseRadius.Value + (float)Internal.selectedMiniStats.Count * Internal.menuItemMultiplier.Value;
for (int i = 0; i < Internal.selectedMiniStats.Count; i++)
{
Vector2 val3 = num2 * Rotate(new Vector2(0f, 1f), num * (float)i);
LoggingPlugin.LogTrace("Custom Stats Plugin: Custom Stat Pos = " + (Internal.statMenuCentre.x + val3.x) + "x" + (Internal.statMenuCentre.y + val3.y));
float num3 = ((num * (float)i >= 90f && num * (float)i <= 270f) ? (-20) : 20);
val.normal.textColor = Color.black;
GUI.Label(new Rect(Internal.statMenuCentre.x + val3.x - 100f, Internal.statMenuCentre.y + val3.y + num3, 200f, 20f), Internal.selectedMiniStats.ElementAt(i).Key, val);
val.normal.textColor = Color.white;
GUI.Label(new Rect(Internal.statMenuCentre.x + val3.x + 2f - 100f, Internal.statMenuCentre.y + val3.y + 2f + num3, 200f, 20f), Internal.selectedMiniStats.ElementAt(i).Key, val);
Internal.selectedMiniStats[Internal.selectedMiniStats.ElementAt(i).Key] = GUI.TextField(new Rect(Internal.statMenuCentre.x + val3.x - 30f, Internal.statMenuCentre.y + val3.y, 60f, 20f), Internal.selectedMiniStats.ElementAt(i).Value);
}
}
private void WhisperToGM()
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
LoggingPlugin.LogInfo("Custom Stats Plug-In: Whispering Custom Stats To GM");
CreatureBoardAsset val = null;
CreaturePresenter.TryGetAsset(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()), ref val);
if ((Object)(object)val == (Object)null)
{
CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref val);
}
if (!((Object)(object)val != (Object)null))
{
return;
}
string text = "[" + val.Name + "]\r\n";
foreach (KeyValuePair<string, string> selectedMiniStat in Internal.selectedMiniStats)
{
text = text + selectedMiniStat.Key + " = " + selectedMiniStat.Value + "\r\n";
}
ChatManager.SendChatMessageToGms(text, NGuid.Empty, (float3?)null, false);
}
public void UpdateCoreStats(CreatureGuid cid, Dictionary<string, string> stats)
{
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
string[] array = (string[])PatchAssistant.GetField(Object.FindObjectOfType<CampaignSessionManager>(), "_statNames");
CreatureStat val = default(CreatureStat);
foreach (KeyValuePair<string, string> stat in stats)
{
bool flag = false;
for (int i = 0; i < array.Length; i++)
{
if (stat.Key == array[i])
{
LoggingPlugin.LogDebug("Custom Stats Plugin: Setting Stat '" + stat.Key + "' At Index " + i + " To " + stat.Value);
if (stat.Value.Split(new char[1] { '/' }).Length < 2)
{
((CreatureStat)(ref val))..ctor(float.Parse(stat.Value), float.Parse(stat.Value));
}
else
{
((CreatureStat)(ref val))..ctor(float.Parse(stat.Value.Split(new char[1] { '/' })[0]), float.Parse(stat.Value.Split(new char[1] { '/' })[1]));
}
CreatureManager.SetCreatureStatByIndex(cid, val, i);
flag = true;
break;
}
}
if (!flag)
{
LoggingPlugin.LogWarning("Custom Stats Plugin: Stat '" + stat.Key + "' Not Found In Core Stats");
}
}
}
public static Vector2 Rotate(Vector2 v, float deltaDeg)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: 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_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
return new Vector2(v.x * Mathf.Cos((float)Math.PI / 180f * deltaDeg) - v.y * Mathf.Sin((float)Math.PI / 180f * deltaDeg), v.x * Mathf.Sin((float)Math.PI / 180f * deltaDeg) + v.y * Mathf.Cos((float)Math.PI / 180f * deltaDeg));
}
}