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 Lemons VS Apples v1.0.0
LemonizeMe.dll
Decompiled 8 months agousing System; 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 HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; 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: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("Omniscye")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("LemonizeMe")] [assembly: AssemblyTitle("LemonizeMe")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.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; } } } namespace LemonizeMe { [BepInPlugin("Omniscye.LemonizeMe", "LemonizeMe", "1.0")] public class LemonizeMe : BaseUnityPlugin { internal static LemonizeMe Instance { get; private set; } internal static ManualLogSource Logger => Instance._logger; private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger; internal Harmony? Harmony { get; set; } private void Awake() { Instance = this; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; Patch(); Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!"); } internal void Patch() { //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_0021: Expected O, but got Unknown //IL_0026: Expected O, but got Unknown if (Harmony == null) { Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); Harmony val2 = val; Harmony = val; } Harmony.PatchAll(); } internal void Unpatch() { Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void Update() { } } } namespace EmpressMods.Lemonize { [BepInPlugin("com.empress.repo.lemonize", "Lemonize", "1.0.4")] public class LemonizePlugin : BaseUnityPlugin { public const string PluginGuid = "com.empress.repo.lemonize"; public const string PluginName = "Lemonize"; public const string PluginVersion = "1.0.4"; internal static LemonizePlugin Instance; internal static Harmony Harmony; internal static ManualLogSource Log; internal static AssetBundle Bundle; internal static GameObject LemonPrefab; internal static GameObject ApplePrefab; internal const float LemonScale = 1f; internal const float LemonYOffset = 0.9f; internal const float AppleYOffset = 0.3f; internal const bool ReplaceMenuAvatarsToo = true; private void Awake() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; Harmony = new Harmony("com.empress.repo.lemonize"); try { Harmony.PatchAll(Assembly.GetExecutingAssembly()); Log.LogInfo((object)"Lemonize 1.0.4 loaded. Try not to trip over the fruit."); } catch (Exception arg) { Log.LogError((object)$"Harmony patching failed: {arg}"); } } private void OnDestroy() { try { Harmony harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } } catch { } } internal static bool EnsureBundleLoaded() { if ((Object)(object)LemonPrefab != (Object)null && (Object)(object)ApplePrefab != (Object)null) { return true; } try { string location = Assembly.GetExecutingAssembly().Location; string directoryName = Path.GetDirectoryName(location); string text = Path.Combine(directoryName ?? ".", "lemons"); if ((Object)(object)Bundle == (Object)null) { Bundle = AssetBundle.LoadFromFile(text); if ((Object)(object)Bundle == (Object)null) { Log.LogError((object)("Failed to load AssetBundle at " + text + ". Name it exactly 'lemons'.")); return false; } } string[] allAssetNames = Bundle.GetAllAssetNames(); if (allAssetNames == null || allAssetNames.Length == 0) { Log.LogError((object)"AssetBundle is empty."); return false; } string[] array = allAssetNames; foreach (string text2 in array) { Log.LogInfo((object)("Bundle contains: " + text2)); } LemonPrefab = LoadPrefabPrefer("lemon"); ApplePrefab = LoadPrefabPrefer("apple"); if ((Object)(object)LemonPrefab == (Object)null) { Log.LogError((object)"Couldn't find any prefab for lemon."); return false; } if ((Object)(object)ApplePrefab == (Object)null) { Log.LogWarning((object)"Apple prefab not found. Enemies won't be replaced."); } return true; } catch (Exception arg) { Log.LogError((object)$"Error loading bundle: {arg}"); return false; } } private static GameObject LoadPrefabPrefer(string preferShortName) { try { string[] allAssetNames = Bundle.GetAllAssetNames(); foreach (string text in allAssetNames) { string text2 = Path.GetFileNameWithoutExtension(text)?.ToLowerInvariant(); if (text2 == preferShortName) { GameObject val = Bundle.LoadAsset<GameObject>(text); if ((Object)(object)val != (Object)null) { return val; } } } string[] allAssetNames2 = Bundle.GetAllAssetNames(); foreach (string text3 in allAssetNames2) { GameObject val2 = Bundle.LoadAsset<GameObject>(text3); if ((Object)(object)val2 != (Object)null) { return val2; } } } catch (Exception arg) { Log.LogWarning((object)$"Failed while scanning bundle for '{preferShortName}': {arg}"); } return null; } internal static void DisableAllRenderers(GameObject root) { if (!((Object)(object)root == (Object)null)) { Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } } } } public class LemonMarker : MonoBehaviour { } public class AppleMarker : MonoBehaviour { } [HarmonyPatch] public static class PlayerAvatarVisuals_Start_Patch { private static Type TargetType() { return AccessTools.TypeByName("PlayerAvatarVisuals"); } private static MethodBase TargetMethod() { return AccessTools.Method(TargetType(), "Start", (Type[])null, (Type[])null); } private static void Postfix(object __instance) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) try { if (!LemonizePlugin.EnsureBundleLoaded()) { return; } Type type = __instance.GetType(); if (!GetField<bool>(type, __instance, "isMenuAvatar") && false) { return; } GameObject field = GetField<GameObject>(type, __instance, "meshParent"); Component val = (Component)__instance; if ((Object)(object)field != (Object)null) { LemonizePlugin.DisableAllRenderers(field); } Transform transform = val.transform; if ((Object)(object)((Component)transform).GetComponentInChildren<LemonMarker>(true) != (Object)null) { return; } GameObject val2 = Object.Instantiate<GameObject>(LemonizePlugin.LemonPrefab, transform); ((Object)val2).name = "Empress_Lemon"; Transform transform2 = val2.transform; transform2.localPosition = Vector3.up * 0.9f; transform2.localRotation = Quaternion.identity; transform2.localScale = Vector3.one * 1f; val2.AddComponent<LemonMarker>(); try { object field2 = GetField<object>(type, __instance, "playerAvatar"); PhotonView val3 = null; if (field2 != null) { FieldInfo fieldInfo = AccessTools.Field(field2.GetType(), "photonView"); if (fieldInfo != null) { object? value = fieldInfo.GetValue(field2); val3 = (PhotonView)((value is PhotonView) ? value : null); } } bool flag = (Object)(object)val3 != (Object)null && val3.IsMine; Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = !flag; } if (flag) { LemonizePlugin.Log.LogDebug((object)"Hid local player's lemon to avoid camera clipping."); } } catch { } LemonizePlugin.Log.LogDebug((object)"Player avatar visuals replaced with lemon. You're welcome."); } catch (Exception arg) { LemonizePlugin.Log.LogWarning((object)$"Failed to lemonize avatar: {arg}"); } } private static T GetField<T>(Type t, object inst, string name) { FieldInfo fieldInfo = AccessTools.Field(t, name); if (fieldInfo == null) { return default(T); } if (fieldInfo.GetValue(inst) is T result) { return result; } return default(T); } } [HarmonyPatch] public static class EnemyParent_Awake_Patch { private static Type TargetType() { return AccessTools.TypeByName("EnemyParent"); } private static MethodBase TargetMethod() { return AccessTools.Method(TargetType(), "Awake", (Type[])null, (Type[])null); } private static void Postfix(object __instance) { //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013d: 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_0157: 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) try { if (!LemonizePlugin.EnsureBundleLoaded() || (Object)(object)LemonizePlugin.ApplePrefab == (Object)null) { return; } Type type = __instance.GetType(); GameObject field = GetField<GameObject>(type, __instance, "EnableObject"); Transform val = null; try { object field2 = GetField<object>(type, __instance, "Enemy"); if (field2 != null) { Type type2 = field2.GetType(); FieldInfo fieldInfo = AccessTools.Field(type2, "CenterTransform"); if (fieldInfo != null) { object? value = fieldInfo.GetValue(field2); Transform val2 = (Transform)((value is Transform) ? value : null); if ((Object)(object)val2 != (Object)null) { val = val2; } } if ((Object)(object)val == (Object)null) { Component val3 = (Component)((field2 is Component) ? field2 : null); if (val3 != null) { val = val3.transform; } } } } catch { } if ((Object)(object)val == (Object)null) { val = ((Component)__instance).transform; } if (!((Object)(object)((Component)val).GetComponentInChildren<AppleMarker>(true) != (Object)null)) { if ((Object)(object)field != (Object)null) { LemonizePlugin.DisableAllRenderers(field); } GameObject val4 = Object.Instantiate<GameObject>(LemonizePlugin.ApplePrefab, val); ((Object)val4).name = "Empress_Apple"; Transform transform = val4.transform; transform.localPosition = Vector3.up * 0.3f; transform.localRotation = Quaternion.identity; transform.localScale = Vector3.one * 1f; val4.AddComponent<AppleMarker>(); Renderer[] componentsInChildren = val4.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = true; } LemonizePlugin.Log.LogDebug((object)"Enemy apple parented to moving root (CenterTransform/Enemy.transform). Done."); } } catch (Exception arg) { LemonizePlugin.Log.LogWarning((object)$"Failed to apple-ize enemy: {arg}"); } } private static T GetField<T>(Type t, object inst, string name) { FieldInfo fieldInfo = AccessTools.Field(t, name); if (fieldInfo == null) { return default(T); } if (fieldInfo.GetValue(inst) is T result) { return result; } return default(T); } } }