Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of SilksongModMenu v1.2.0
SilksongMenu.dll
Decompiled 5 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("SilksongMenu")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+4264c77bdac03e01467f73979c16e46c60a6c5db")] [assembly: AssemblyProduct("SilksongMenu")] [assembly: AssemblyTitle("SilksongMenu")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } [BepInPlugin("com.kvox.silksongmenu", "Silksong Mod Menu", "1.4.0")] public class SilksongModMenu : BaseUnityPlugin { private static ManualLogSource Log; private const int WindowId = 12345; private const BindingFlags AllInstance = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; private bool _showMenu; private Rect _windowRect = new Rect(100f, 80f, 380f, 430f); private Texture2D _symbolTexture; private Texture2D _frameTexture; private Texture2D _panelTexture; private bool _godMode; private bool _oneHitKill; private bool _infiniteSilk; private bool _stylesInit; private GUIStyle _headerStyle; private GUIStyle _switchStyle; private GUIStyle _buttonStyle; private GUIStyle _hintStyle; private GUIStyle _statusStyle; private Texture2D _lineTexture; private bool _drawPanel = true; private int _fbMinX; private int _fbMinY; private int _fbW; private int _fbH; private const float FramePad = 22f; private string _status = ""; private float _statusUntil; private Type _playerDataType; private Type _heroControllerType; private readonly Dictionary<string, MemberInfo> _memberCache = new Dictionary<string, MemberInfo>(); private readonly HashSet<string> _warned = new HashSet<string>(); private static readonly string[] RosaryNames = new string[3] { "geo", "rosaries", "Rosaries" }; private static readonly string[] ShardNames = new string[3] { "ShellShards", "shellShards", "shards" }; private static readonly string[] SilkNames = new string[2] { "silk", "Silk" }; private static readonly string[] SilkMaxNames = new string[3] { "silkMax", "SilkMax", "maxSilk" }; private static readonly string[] HealthNames = new string[1] { "health" }; private static readonly string[] MaxHealthNames = new string[1] { "maxHealth" }; private static readonly string[] NailDmgNames = new string[1] { "nailDamage" }; private static readonly string[] InvincibleNames = new string[2] { "isInvincible", "invinciTest" }; private void Awake() { Log = ((BaseUnityPlugin)this).Logger; Log.LogInfo((object)"Silksong Mod Menu loaded"); LoadTextures(); CreatePanelTexture(); } private void Update() { if (Input.GetKeyDown((KeyCode)277)) { _showMenu = !_showMenu; } if (_godMode) { ApplyGodMode(); } if (_oneHitKill) { ApplyOneHitKill(); } if (_infiniteSilk) { ApplyInfiniteSilk(); } } private void LoadTextures() { string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _symbolTexture = LoadTexture(Path.Combine(directoryName, "menu_symbol.png")); _frameTexture = LoadTexture(Path.Combine(directoryName, "menu_frame.png")); if ((Object)(object)_frameTexture != (Object)null) { ProcessFrame(_frameTexture); } } private void ProcessFrame(Texture2D tex) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) try { Color32[] pixels = tex.GetPixels32(); int width = ((Texture)tex).width; int height = ((Texture)tex).height; int num = width; int num2 = height; int num3 = -1; int num4 = -1; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int num5 = i * width + j; Color32 val = pixels[num5]; int num6 = Mathf.Max((int)val.r, Mathf.Max((int)val.g, (int)val.b)); float num7 = Mathf.Clamp01(((float)num6 - 14f) / 40f); byte b = (byte)((float)(int)val.a * num7); pixels[num5] = new Color32(val.r, val.g, val.b, b); if (b > 60) { if (j < num) { num = j; } if (j > num3) { num3 = j; } if (i < num2) { num2 = i; } if (i > num4) { num4 = i; } } } } tex.SetPixels32(pixels); tex.Apply(); if (num3 >= num && num4 >= num2) { _fbMinX = num; _fbMinY = num2; _fbW = num3 - num + 1; _fbH = num4 - num2 + 1; } } catch (Exception ex) { Log.LogWarning((object)("Frame processing failed: " + ex.Message)); } } private void CreatePanelTexture() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) _panelTexture = new Texture2D(1, 1, (TextureFormat)4, false); _panelTexture.SetPixel(0, 0, new Color(0.06f, 0.06f, 0.08f, 0.95f)); _panelTexture.Apply(); ((Object)_panelTexture).hideFlags = (HideFlags)61; } private Texture2D LoadTexture(string path) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown if (!File.Exists(path)) { return null; } try { byte[] array = File.ReadAllBytes(path); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (ImageConversion.LoadImage(val, array)) { ((Texture)val).filterMode = (FilterMode)1; return val; } } catch (Exception ex) { Log.LogWarning((object)("Texture load failed: " + ex.Message)); } return null; } private void OnGUI() { //IL_006c: 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_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Expected O, but got Unknown //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) InitStyles(); if ((Object)(object)_symbolTexture != (Object)null) { if (GUI.Button(new Rect(20f, 20f, 120f, 120f), (Texture)(object)_symbolTexture, GUIStyle.none)) { _showMenu = !_showMenu; } } else if (GUI.Button(new Rect(20f, 20f, 140f, 45f), "Menu", _buttonStyle)) { _showMenu = !_showMenu; } if (_showMenu) { ((Rect)(ref _windowRect)).x = Mathf.Clamp(((Rect)(ref _windowRect)).x, 0f, Mathf.Max(0f, (float)Screen.width - ((Rect)(ref _windowRect)).width)); ((Rect)(ref _windowRect)).y = Mathf.Clamp(((Rect)(ref _windowRect)).y, 0f, Mathf.Max(0f, (float)Screen.height - ((Rect)(ref _windowRect)).height)); _windowRect = GUI.Window(12345, _windowRect, new WindowFunction(DrawWindow), GUIContent.none, GUIStyle.none); } } private void DrawFrameOverlay(Rect target) { //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_frameTexture == (Object)null)) { if (_fbW > 0 && _fbH > 0) { float num = ((Rect)(ref target)).width / (float)_fbW; float num2 = ((Rect)(ref target)).height / (float)_fbH; int width = ((Texture)_frameTexture).width; int height = ((Texture)_frameTexture).height; int num3 = height - (_fbMinY + _fbH); Rect val = default(Rect); ((Rect)(ref val))..ctor(((Rect)(ref target)).x - (float)_fbMinX * num, ((Rect)(ref target)).y - (float)num3 * num2, (float)width * num, (float)height * num2); GUI.BeginGroup(target); GUI.DrawTexture(new Rect(((Rect)(ref val)).x - ((Rect)(ref target)).x, ((Rect)(ref val)).y - ((Rect)(ref target)).y, ((Rect)(ref val)).width, ((Rect)(ref val)).height), (Texture)(object)_frameTexture, (ScaleMode)0, true); GUI.EndGroup(); } else { GUI.DrawTexture(target, (Texture)(object)_frameTexture, (ScaleMode)0, true); } } } private void DrawWindow(int id) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_02bb: Unknown result type (might be due to invalid IL or missing references) if (_drawPanel) { GUI.DrawTexture(new Rect(30f, 30f, ((Rect)(ref _windowRect)).width - 60f, ((Rect)(ref _windowRect)).height - 60f), (Texture)(object)_panelTexture); } GUILayout.BeginArea(new Rect(44f, 48f, ((Rect)(ref _windowRect)).width - 88f, ((Rect)(ref _windowRect)).height - 96f)); GUILayout.Label("Silksong Mod Menu", _headerStyle, Array.Empty<GUILayoutOption>()); DrawDivider(); _godMode = GUILayout.Toggle(_godMode, _godMode ? "God Mode - ON" : "God Mode", _switchStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }); GUILayout.Space(3f); _oneHitKill = GUILayout.Toggle(_oneHitKill, _oneHitKill ? "One-Hit Kill - ON" : "One-Hit Kill", _switchStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }); GUILayout.Space(3f); _infiniteSilk = GUILayout.Toggle(_infiniteSilk, _infiniteSilk ? "Infinite Silk - ON" : "Infinite Silk", _switchStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }); DrawDivider(); if (GUILayout.Button("Add 1000 Rosaries", _buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) })) { AddCurrency(RosaryNames, 1000, "Rosaries"); } GUILayout.Space(4f); if (GUILayout.Button("Add 500 Shell Shards", _buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) })) { AddCurrency(ShardNames, 500, "Shell Shards"); } GUILayout.Space(4f); if (GUILayout.Button("Full Heal", _buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) })) { FullHeal(); } GUILayout.Space(6f); if (!string.IsNullOrEmpty(_status) && Time.unscaledTime < _statusUntil) { GUILayout.Label(_status, _statusStyle, Array.Empty<GUILayoutOption>()); } GUILayout.FlexibleSpace(); GUILayout.Label("Insert or symbol to close", _hintStyle, Array.Empty<GUILayoutOption>()); GUILayout.EndArea(); DrawFrameOverlay(new Rect(0f, 0f, ((Rect)(ref _windowRect)).width, ((Rect)(ref _windowRect)).height)); GUI.DragWindow(); } private void DrawDivider() { //IL_0025: 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_0051: Unknown result type (might be due to invalid IL or missing references) GUILayout.Space(6f); Rect rect = GUILayoutUtility.GetRect(1f, 2f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }); GUI.DrawTexture(new Rect(((Rect)(ref rect)).x + 15f, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width - 30f, 1f), (Texture)(object)_lineTexture); GUILayout.Space(6f); } private Texture2D MakeButtonTexture(Color top, Color bottom, Color border) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_0047: 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) //IL_0037: 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) Texture2D val = new Texture2D(16, 32, (TextureFormat)4, false); for (int i = 0; i < 32; i++) { for (int j = 0; j < 16; j++) { bool flag = j < 2 || j >= 14 || i < 2 || i >= 30; val.SetPixel(j, i, flag ? border : Color.Lerp(bottom, top, (float)i / 31f)); } } ((Object)val).hideFlags = (HideFlags)61; ((Texture)val).wrapMode = (TextureWrapMode)1; ((Texture)val).filterMode = (FilterMode)1; val.Apply(); return val; } private GUIStyle MakeFancyStyle(Texture2D normal, Texture2D hover, Texture2D active, Texture2D on, Texture2D onHover) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Expected O, but got Unknown //IL_005a: Expected O, but got Unknown //IL_0086: 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_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_0108: 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) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) GUIStyle val = new GUIStyle(GUI.skin.button) { fontSize = 14, fontStyle = (FontStyle)1, alignment = (TextAnchor)4, border = new RectOffset(3, 3, 3, 3), padding = new RectOffset(8, 8, 3, 3), margin = new RectOffset(0, 0, 0, 0) }; Color textColor = default(Color); ((Color)(ref textColor))..ctor(0.92f, 0.92f, 0.95f); Color textColor2 = default(Color); ((Color)(ref textColor2))..ctor(0.65f, 1f, 1f); Color white = Color.white; val.normal.background = normal; val.normal.textColor = textColor; val.focused.background = normal; val.focused.textColor = textColor; val.hover.background = hover; val.hover.textColor = white; val.active.background = active; val.active.textColor = white; val.onNormal.background = on; val.onNormal.textColor = textColor2; val.onFocused.background = on; val.onFocused.textColor = textColor2; val.onHover.background = onHover; val.onHover.textColor = Color.white; val.onActive.background = active; val.onActive.textColor = textColor2; return val; } private void InitStyles() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown //IL_0044: 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) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0105: 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_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014f: 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_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: 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_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Expected O, but got Unknown //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0201: 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_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Expected O, but got Unknown //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Expected O, but got Unknown if (!_stylesInit) { _stylesInit = true; _lineTexture = new Texture2D(1, 1, (TextureFormat)4, false); _lineTexture.SetPixel(0, 0, new Color(0.62f, 0.6f, 0.72f, 0.55f)); _lineTexture.Apply(); ((Object)_lineTexture).hideFlags = (HideFlags)61; Color border = default(Color); ((Color)(ref border))..ctor(0.62f, 0.6f, 0.72f); Color border2 = default(Color); ((Color)(ref border2))..ctor(0.45f, 0.95f, 1f); Texture2D val = MakeButtonTexture(new Color(0.22f, 0.22f, 0.27f), new Color(0.09f, 0.09f, 0.12f), border); Texture2D val2 = MakeButtonTexture(new Color(0.3f, 0.3f, 0.38f), new Color(0.13f, 0.13f, 0.18f), border2); Texture2D active = MakeButtonTexture(new Color(0.06f, 0.06f, 0.08f), new Color(0.14f, 0.14f, 0.18f), border2); Texture2D val3 = MakeButtonTexture(new Color(0.12f, 0.5f, 0.56f), new Color(0.04f, 0.22f, 0.27f), border2); Texture2D onHover = MakeButtonTexture(new Color(0.18f, 0.62f, 0.68f), new Color(0.06f, 0.28f, 0.34f), Color.white); _buttonStyle = MakeFancyStyle(val, val2, active, val, val2); _switchStyle = MakeFancyStyle(val, val2, active, val3, onHover); GUIStyle val4 = new GUIStyle(GUI.skin.label) { fontSize = 20, fontStyle = (FontStyle)1, alignment = (TextAnchor)4 }; val4.normal.textColor = Color.white; _headerStyle = val4; GUIStyle val5 = new GUIStyle(GUI.skin.label) { fontSize = 13, alignment = (TextAnchor)4 }; val5.normal.textColor = new Color(0.75f, 0.75f, 0.75f); _hintStyle = val5; GUIStyle val6 = new GUIStyle(GUI.skin.label) { fontSize = 13, alignment = (TextAnchor)4, wordWrap = true }; val6.normal.textColor = new Color(1f, 0.85f, 0.4f); _statusStyle = val6; } } private void SetStatus(string text) { _status = text; _statusUntil = Time.unscaledTime + 4f; } private void ApplyGodMode() { object heroController = GetHeroController(); if (heroController == null || !TrySet(heroController, InvincibleNames, true)) { object playerData = GetPlayerData(); if (playerData != null) { TrySet(playerData, InvincibleNames, true); } } } private void ApplyOneHitKill() { object playerData = GetPlayerData(); if (playerData != null) { TrySet(playerData, NailDmgNames, 999); } } private void ApplyInfiniteSilk() { object playerData = GetPlayerData(); if (playerData != null) { if (TryGet(playerData, SilkMaxNames, out var value)) { TrySet(playerData, SilkNames, value); } else { TrySet(playerData, SilkNames, 99); } } } private void AddCurrency(string[] names, int amount, string label) { object playerData = GetPlayerData(); int value; if (playerData == null) { SetStatus("PlayerData not available (are you in a save?)"); } else if (TryGet(playerData, names, out value) && TrySet(playerData, names, value + amount)) { SetStatus("Added " + amount + " " + label); } else { SetStatus(label + ": field not found, check the BepInEx log"); } } private void FullHeal() { object playerData = GetPlayerData(); int value; if (playerData == null) { SetStatus("PlayerData not available (are you in a save?)"); } else if (TryGet(playerData, MaxHealthNames, out value)) { TrySet(playerData, HealthNames, value); } else { SetStatus("Health fields not found, check the BepInEx log"); } } private object GetPlayerData() { try { if (_playerDataType == null) { _playerDataType = Type.GetType("PlayerData, Assembly-CSharp"); } if (_playerDataType == null) { WarnOnce("PlayerData type not found"); return null; } PropertyInfo property = _playerDataType.GetProperty("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (property != null) { return property.GetValue(null, null); } FieldInfo field = _playerDataType.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { return field.GetValue(null); } WarnOnce("PlayerData.instance not found"); } catch (Exception ex) { WarnOnce("GetPlayerData failed: " + ex.Message); } return null; } private object GetHeroController() { try { if (_heroControllerType == null) { _heroControllerType = Type.GetType("HeroController, Assembly-CSharp"); } if (_heroControllerType == null) { return null; } PropertyInfo property = _heroControllerType.GetProperty("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (property != null) { return property.GetValue(null, null); } FieldInfo field = _heroControllerType.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { return field.GetValue(null); } return Object.FindObjectOfType(_heroControllerType); } catch { return null; } } private MemberInfo FindMember(Type type, string[] names) { string key = type.FullName + "|" + names[0]; if (_memberCache.TryGetValue(key, out var value)) { return value; } MemberInfo memberInfo = null; foreach (string name in names) { FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { memberInfo = field; break; } PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.CanRead && property.CanWrite) { memberInfo = property; break; } } if (memberInfo == null) { WarnOnce("None of [" + string.Join(", ", names) + "] exist on " + type.Name); } else { Log.LogInfo((object)("Using " + type.Name + "." + memberInfo.Name)); } _memberCache[key] = memberInfo; return memberInfo; } private bool TrySet(object obj, string[] names, object value) { if (obj == null) { return false; } try { MemberInfo memberInfo = FindMember(obj.GetType(), names); if (memberInfo == null) { return false; } if (memberInfo is FieldInfo fieldInfo) { fieldInfo.SetValue(obj, Convert.ChangeType(value, fieldInfo.FieldType)); } else if (memberInfo is PropertyInfo propertyInfo) { propertyInfo.SetValue(obj, Convert.ChangeType(value, propertyInfo.PropertyType), null); } return true; } catch (Exception ex) { WarnOnce("Set " + names[0] + " failed: " + ex.Message); return false; } } private bool TryGet(object obj, string[] names, out int value) { value = 0; if (obj == null) { return false; } try { MemberInfo memberInfo = FindMember(obj.GetType(), names); if (memberInfo == null) { return false; } object value2 = ((memberInfo is FieldInfo fieldInfo) ? fieldInfo.GetValue(obj) : ((PropertyInfo)memberInfo).GetValue(obj, null)); value = Convert.ToInt32(value2); return true; } catch (Exception ex) { WarnOnce("Get " + names[0] + " failed: " + ex.Message); return false; } } private void WarnOnce(string message) { if (_warned.Add(message)) { Log.LogWarning((object)message); } } }