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 PiggyBank v1.0.0
PiggyBank.dll
Decompiled a day agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using REPOLib.Modules; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.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; } } } namespace PiggyBank { internal static class AssetLoader { private static AssetBundle _bundle; internal static void Load(string pluginDir) { string text = Path.Combine(pluginDir, "piggybank"); if (!File.Exists(text)) { throw new FileNotFoundException("Asset bundle not found. Reinstall the mod.", text); } _bundle = AssetBundle.LoadFromFile(text); if ((Object)(object)_bundle == (Object)null) { throw new InvalidDataException("Could not load the asset bundle " + text + ". It may be corrupt or built for a different Unity version."); } } internal static Mesh Mesh(string name) { return Get<Mesh>(name); } internal static Texture2D Texture(string name) { return Get<Texture2D>(name); } internal static AudioClip[] Clips(string prefix) { Regex regex = new Regex("^" + Regex.Escape(prefix) + "_\\d+$", RegexOptions.IgnoreCase); List<AudioClip> list = new List<AudioClip>(); AudioClip[] array = _bundle.LoadAllAssets<AudioClip>(); foreach (AudioClip val in array) { if (regex.IsMatch(((Object)val).name)) { list.Add(val); } } if (list.Count == 0) { throw new FileNotFoundException("No sounds named " + prefix + "_N in the asset bundle."); } return list.ToArray(); } private static T Get<T>(string name) where T : Object { T val = _bundle.LoadAsset<T>(name); if ((Object)(object)val == (Object)null) { throw new FileNotFoundException(typeof(T).Name + " \"" + name + "\" is missing from the asset bundle."); } return val; } } [HarmonyPatch(typeof(RunManager), "Awake")] internal static class RunManagerAwakePatch { [HarmonyPostfix] private static void Postfix() { PiggyBuilder.EnsureBuilt(); } } [HarmonyPatch(typeof(PlayerController), "Update")] internal static class PlayerUpdatePatch { [HarmonyPostfix] private static void Postfix() { Plugin.DebugTick(); } } [HarmonyPatch(typeof(ValuableDirector), "SetupHost")] internal static class SpawnWeightPatch { [HarmonyPrefix] private static void Prefix() { PrefabRef piggy = PiggyBuilder.PiggyRef; Level val = (((Object)(object)LevelGenerator.Instance != (Object)null) ? LevelGenerator.Instance.Level : null); if (piggy == null || (Object)(object)val == (Object)null || val.ValuablePresets == null) { return; } foreach (LevelValuables valuablePreset in val.ValuablePresets) { if ((Object)(object)valuablePreset != (Object)null) { valuablePreset.small.RemoveAll((PrefabRef r) => r != null && ((PrefabRef<GameObject>)(object)r).ResourcePath == ((PrefabRef<GameObject>)(object)piggy).ResourcePath); } } int value = Plugin.SpawnWeight.Value; if (value <= 0) { return; } LevelValuables val2 = ((IEnumerable<LevelValuables>)val.ValuablePresets).FirstOrDefault((Func<LevelValuables, bool>)((LevelValuables p) => (Object)(object)p != (Object)null && ((Object)p).name == "Valuables - Generic")) ?? ((IEnumerable<LevelValuables>)val.ValuablePresets).FirstOrDefault((Func<LevelValuables, bool>)((LevelValuables p) => (Object)(object)p != (Object)null)); if (!((Object)(object)val2 == (Object)null)) { for (int num = 0; num < value; num++) { val2.small.Add(piggy); } } } } [HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "BreakRPC")] internal static class BreakPatch { [HarmonyPrefix] private static void Prefix(PhysGrabObjectImpactDetector __instance) { PiggyBankObject component = ((Component)__instance).GetComponent<PiggyBankObject>(); if (!((Object)(object)component == (Object)null)) { ValuableObject valuable = component.Valuable; if (!((Object)(object)valuable == (Object)null)) { component.valueBeforeHit = valuable.dollarValueCurrent; component.hitFrame = Time.frameCount; } } } [HarmonyPostfix] private static void Postfix(PhysGrabObjectImpactDetector __instance, int breakLevel, bool _loseValue) { if (Plugin.HeavyHitsSmash.Value && _loseValue && SemiFunc.IsMasterClientOrSingleplayer()) { PiggyBankObject component = ((Component)__instance).GetComponent<PiggyBankObject>(); if (!((Object)(object)component == (Object)null) && !component.smashed && breakLevel == __instance.breakLevelHeavy) { __instance.DestroyObject(true); } } } } [HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "DestroyObject")] internal static class DestroyPatch { [HarmonyPrefix] private static void Prefix(PhysGrabObjectImpactDetector __instance) { if (SemiFunc.IsMasterClientOrSingleplayer()) { PiggyBankObject component = ((Component)__instance).GetComponent<PiggyBankObject>(); if (!((Object)(object)component == (Object)null) && !component.smashed && !__instance.destroyDisable && (!((Object)(object)__instance.physGrabObject != (Object)null) || !__instance.physGrabObject.dead)) { component.smashed = true; PiggySmash.Run(component); } } } } public class PiggyBankObject : MonoBehaviour { internal bool smashed; internal float valueBeforeHit = -1f; internal int hitFrame = -1; internal ValuableObject Valuable => ((Component)this).GetComponent<ValuableObject>(); internal float ValueAtSmash() { ValuableObject valuable = Valuable; if (hitFrame == Time.frameCount && valueBeforeHit >= 0f) { return valueBeforeHit; } if (!((Object)(object)valuable != (Object)null)) { return 0f; } return valuable.dollarValueCurrent; } } internal static class PiggySmash { internal static void Run(PiggyBankObject pig) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_0075: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0155: 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) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)pig).transform.position; PhysGrabObject component = ((Component)pig).GetComponent<PhysGrabObject>(); if (component != null) { val = component.centerPoint; } if (val.y < -40f) { return; } float num = pig.ValueAtSmash(); int value = Plugin.CoinBonusPercent.Value; int num2 = Mathf.RoundToInt(num * (float)value / 100f); float value2 = Plugin.NoiseRadius.Value; if (value2 > 0f && (Object)(object)EnemyDirector.instance != (Object)null) { EnemyDirector.instance.SetInvestigate(val, value2, false); } if (num2 <= 0 || PiggyBuilder.CoinRef == null) { return; } int num3 = Mathf.Min(Plugin.MinCoins.Value, Plugin.MaxCoins.Value); int num4 = Mathf.Max(Plugin.MinCoins.Value, Plugin.MaxCoins.Value); int num5 = Mathf.Min(Random.Range(num3, num4 + 1), num2); int[] array = Split(num2, num5); Plugin.Log.LogInfo((object)("Piggy bank smashed at $" + Mathf.RoundToInt(num) + " -> " + num5 + " coins worth $" + num2 + " in total.")); for (int i = 0; i < num5; i++) { float value3 = Plugin.PiggyScale.Value; Vector3 val2 = Random.insideUnitSphere * 0.12f * value3; val2.y = Mathf.Abs(val2.y) + 0.05f * value3; GameObject val3 = Valuables.SpawnValuable(PiggyBuilder.CoinRef, val + val2, Random.rotation); if (!((Object)(object)val3 == (Object)null)) { val3.GetComponent<ValuableObject>().dollarValueOverride = array[i]; ((MonoBehaviour)Plugin.Instance).StartCoroutine(Scatter(val3, val2)); } } } private static IEnumerator Scatter(GameObject coin, Vector3 offset) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) yield return (object)new WaitForFixedUpdate(); yield return (object)new WaitForFixedUpdate(); if ((Object)(object)coin == (Object)null) { yield break; } Rigidbody component = coin.GetComponent<Rigidbody>(); if (!((Object)(object)component == (Object)null) && !component.isKinematic) { Vector3 insideUnitSphere = default(Vector3); ((Vector3)(ref insideUnitSphere))..ctor(offset.x, 0f, offset.z); if (((Vector3)(ref insideUnitSphere)).sqrMagnitude < 0.0001f) { insideUnitSphere = Random.insideUnitSphere; } insideUnitSphere.y = 0f; component.velocity = ((Vector3)(ref insideUnitSphere)).normalized * Random.Range(1.2f, 3.2f) + Vector3.up * Random.Range(1.2f, 3f); component.angularVelocity = Random.insideUnitSphere * 12f; } } internal static int[] Split(int total, int count) { int[] array = new int[count]; if (count <= 1) { array[0] = total; return array; } int num = ((total / count < 50) ? 1 : 10); float[] array2 = new float[count]; float num2 = 0f; for (int i = 0; i < count; i++) { array2[i] = Random.Range(0.5f, 1.5f); num2 += array2[i]; } int num3 = 0; for (int j = 0; j < count - 1; j++) { int num4 = Mathf.RoundToInt((float)total * array2[j] / num2 / (float)num) * num; int num5 = count - 1 - j; num3 += (array[j] = Mathf.Clamp(num4, 1, total - num3 - num5)); } array[count - 1] = total - num3; return array; } } internal static class PiggyBuilder { internal const string PiggyName = "Valuable Piggy Bank"; internal const string CoinId = "PiggyBank/Piggy Bank Coin"; internal static GameObject PiggyPrefab; internal static GameObject CoinPrefab; internal static PrefabRef PiggyRef; internal static PrefabRef CoinRef; private static bool _built; private static Transform _holder; private static bool _loggedShader; internal static void EnsureBuilt() { if (_built) { return; } _built = true; try { Build(); } catch (Exception ex) { Plugin.Log.LogError((object)("Failed to build the piggy bank: " + ex)); } } private static void Build() { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown AssetLoader.Load(Plugin.PluginDir); GameObject val = FindDonor((Type)1); GameObject val2 = FindDonor((Type)0); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { Plugin.Log.LogError((object)"Could not find vanilla valuables to base the piggy bank on. Is this a supported game version?"); return; } Plugin.Log.LogInfo((object)("Piggy donor: " + ((Object)val).name + ", coin donor: " + ((Object)val2).name)); GameObject val3 = new GameObject("PiggyBank Prefabs") { hideFlags = (HideFlags)61 }; val3.SetActive(false); Object.DontDestroyOnLoad((Object)val3); _holder = val3.transform; PiggyPrefab = BuildPiggy(val); CoinPrefab = BuildCoin(val2); PiggyRef = Valuables.RegisterValuable(PiggyPrefab, new List<string> { "Valuables - Generic" }); CoinRef = NetworkPrefabs.RegisterNetworkPrefab("PiggyBank/Piggy Bank Coin", CoinPrefab); Plugin.Log.LogInfo((object)("Registered piggy bank (" + (PiggyRef != null) + ") and coin (" + (CoinRef != null) + ").")); } private static GameObject FindDonor(Type type) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) GameObject result = null; int num = int.MaxValue; List<Level> list = new List<Level>(); list.AddRange(RunManager.instance.levels); list.AddRange(RunManager.instance.levelArena); foreach (Level item in list) { if ((Object)(object)item == (Object)null || item.ValuablePresets == null) { continue; } foreach (LevelValuables valuablePreset in item.ValuablePresets) { if ((Object)(object)valuablePreset == (Object)null) { continue; } foreach (PrefabRef item2 in ((int)type == 0) ? valuablePreset.tiny : valuablePreset.small) { if (item2 == null || !((PrefabRef<GameObject>)(object)item2).IsValid()) { continue; } GameObject prefab = ((PrefabRef<GameObject>)(object)item2).Prefab; if (!((Object)(object)prefab == (Object)null) && !((Object)(object)prefab.GetComponent<ValuableObject>() == (Object)null) && !((Object)(object)prefab.GetComponentInChildren<BoxCollider>(true) == (Object)null) && prefab.GetComponent<ValuableObject>().volumeType == type) { int num2 = prefab.GetComponentsInChildren<MonoBehaviour>(true).Length * 4 + prefab.GetComponentsInChildren<Renderer>(true).Length + prefab.GetComponentsInChildren<Light>(true).Length * 10 + prefab.GetComponentsInChildren<Animator>(true).Length * 10; if (num2 < num) { num = num2; result = prefab; } } } } } return result; } private static GameObject BuildPiggy(GameObject donor) { //IL_001c: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: 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: 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) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_0181: 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) GameObject obj = Object.Instantiate<GameObject>(donor, _holder); ((Object)obj).name = "Valuable Piggy Bank"; obj.transform.localScale = Vector3.one; ValuableObject component = obj.GetComponent<ValuableObject>(); Material donorMat = FirstMaterial(obj); Mesh val = AssetLoader.Mesh("piggy"); Material mat = BuildMaterial(donorMat, "piggy", "PiggyBank Ceramic", 0.35f, 0.75f); float value = Plugin.PiggyScale.Value; ReplaceVisual(obj, val, mat, value); Bounds bounds = val.bounds; Vector3 val2 = ((Bounds)(ref bounds)).center * value; bounds = val.bounds; FitCollider(obj, new Bounds(val2, ((Bounds)(ref bounds)).size * value)); component.volumeType = (Type)1; component.audioPresetPitch = 1f; component.debugVolume = false; Value val3 = ScriptableObject.CreateInstance<Value>(); ((Object)val3).name = "Value - Piggy Bank"; val3.valueMin = Mathf.Min(Plugin.ValueMin.Value, Plugin.ValueMax.Value); val3.valueMax = Mathf.Max(Plugin.ValueMin.Value, Plugin.ValueMax.Value); component.valuePreset = val3; Durability val4 = ScriptableObject.CreateInstance<Durability>(); ((Object)val4).name = "Durability - Piggy Bank"; val4.fragility = Plugin.Fragility.Value; val4.durability = Plugin.Durability.Value; component.durabilityPreset = val4; component.physAttributePreset = MakeMass(component.physAttributePreset, 1.2f, "PhysAttribute - Piggy Bank"); component.particleColors = MakeGradient(new Color(0.96f, 0.86f, 0.84f), new Color(0.62f, 0.2f, 0.32f)); PhysAudio val5 = CloneAudio(component.audioPreset, "PhysAudio - Piggy Bank"); AudioClip[] clips = AssetLoader.Clips("rattle"); AudioClip[] clips2 = AssetLoader.Clips("rattle_heavy"); AudioClip[] clips3 = AssetLoader.Clips("crash"); SetSound(val5.impactLight, clips, 0.45f); SetSound(val5.impactMedium, clips, 0.65f); SetSound(val5.impactHeavy, clips2, 0.85f); SetSound(val5.breakLight, clips, 0.55f); SetSound(val5.breakMedium, clips2, 0.75f); SetSound(val5.breakHeavy, clips2, 0.9f); SetSound(val5.destroy, clips3, 1f); component.audioPreset = val5; obj.AddComponent<PiggyBankObject>(); return obj; } private static GameObject BuildCoin(GameObject donor) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007f: 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) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: 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) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: 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_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) GameObject obj = Object.Instantiate<GameObject>(donor, _holder); ((Object)obj).name = "Piggy Bank Coin"; obj.transform.localScale = Vector3.one; ValuableObject component = obj.GetComponent<ValuableObject>(); Mesh val = AssetLoader.Mesh("coin"); Material mat = BuildMaterial(FirstMaterial(obj), "coin", "PiggyBank Coin", 0.6f, 0.7f); float value = Plugin.CoinScale.Value; ReplaceVisual(obj, val, mat, value); Bounds bounds = val.bounds; Vector3 size = ((Bounds)(ref bounds)).size; size.y = Mathf.Max(size.y, 0.025f); bounds = val.bounds; FitCollider(obj, new Bounds(((Bounds)(ref bounds)).center * value, size * value)); component.volumeType = (Type)0; component.audioPresetPitch = 1f; component.debugVolume = false; Value val2 = ScriptableObject.CreateInstance<Value>(); ((Object)val2).name = "Value - Piggy Bank Coin"; val2.valueMin = 50f; val2.valueMax = 100f; component.valuePreset = val2; Durability val3 = ScriptableObject.CreateInstance<Durability>(); ((Object)val3).name = "Durability - Piggy Bank Coin"; val3.fragility = 25f; val3.durability = 100f; component.durabilityPreset = val3; component.physAttributePreset = MakeMass(component.physAttributePreset, 0.15f, "PhysAttribute - Piggy Bank Coin"); component.particleColors = MakeGradient(new Color(1f, 0.85f, 0.4f), new Color(0.8f, 0.55f, 0.15f)); PhysAudio val4 = CloneAudio(component.audioPreset, "PhysAudio - Piggy Bank Coin"); AudioClip[] clips = AssetLoader.Clips("coin"); SetSound(val4.impactLight, clips, 0.35f); SetSound(val4.impactMedium, clips, 0.5f); SetSound(val4.impactHeavy, clips, 0.65f); SetSound(val4.breakLight, clips, 0.4f); SetSound(val4.breakMedium, clips, 0.55f); SetSound(val4.breakHeavy, clips, 0.7f); SetSound(val4.destroy, clips, 0.7f); component.audioPreset = val4; return obj; } private static Material BuildMaterial(Material donorMat, string prefix, string name, float metallic, float smoothness) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_00c9: Unknown result type (might be due to invalid IL or missing references) Material val = new Material(donorMat.shader) { name = name }; LogShader(val); SetTexture(val, (Texture)(object)AssetLoader.Texture(prefix + "_albedo"), "_MainTex", "_BaseMap", "_BaseColorMap", "_Albedo"); if (SetTexture(val, (Texture)(object)AssetLoader.Texture(prefix + "_normal"), "_BumpMap", "_NormalMap", "_NormalTex")) { val.EnableKeyword("_NORMALMAP"); } if (SetTexture(val, (Texture)(object)AssetLoader.Texture(prefix + "_mask"), "_MetallicGlossMap")) { val.EnableKeyword("_METALLICGLOSSMAP"); } SetColor(val, Color.white); SetFloat(val, metallic, "_Metallic"); SetFloat(val, 1f, "_GlossMapScale"); SetFloat(val, smoothness, "_Glossiness", "_Smoothness"); return val; } private static Material FirstMaterial(GameObject go) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown MeshRenderer[] componentsInChildren = go.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val in componentsInChildren) { if ((Object)(object)((Renderer)val).sharedMaterial != (Object)null) { return ((Renderer)val).sharedMaterial; } } return new Material(Shader.Find("Standard")); } private static void ReplaceVisual(GameObject go, Mesh mesh, Material mat, float scale) { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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) Transform val = FindChildDeep(go.transform, "Object") ?? go.transform; MeshRenderer[] componentsInChildren = go.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer obj in componentsInChildren) { MeshFilter component = ((Component)obj).GetComponent<MeshFilter>(); Object.DestroyImmediate((Object)(object)obj); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } } SkinnedMeshRenderer[] componentsInChildren2 = go.GetComponentsInChildren<SkinnedMeshRenderer>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren2[i]); } GameObject val2 = new GameObject(((Object)mesh).name + " Mesh"); val2.transform.SetParent(val, false); val2.transform.localScale = Vector3.one * scale; val2.layer = ((Component)val).gameObject.layer; val2.AddComponent<MeshFilter>().sharedMesh = mesh; MeshRenderer obj2 = val2.AddComponent<MeshRenderer>(); ((Renderer)obj2).sharedMaterial = mat; ((Renderer)obj2).shadowCastingMode = (ShadowCastingMode)1; ((Renderer)obj2).receiveShadows = true; } private static void FitCollider(GameObject go, Bounds bounds) { //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_011a: 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_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) Collider[] array = (from c in go.GetComponentsInChildren<Collider>(true) where !c.isTrigger select c).ToArray(); BoxCollider val = array.OfType<BoxCollider>().FirstOrDefault(); if ((Object)(object)val == (Object)null) { throw new InvalidOperationException("Donor has no box collider"); } Collider[] array2 = array; foreach (Collider val2 in array2) { if (!((Object)(object)val2 == (Object)(object)val)) { Object.DestroyImmediate((Object)(((Object)(object)((Component)val2).gameObject != (Object)(object)go && ((Component)val2).transform.childCount == 0 && ((Component)val2).GetComponents<Component>().Length <= 2) ? ((object)((Component)val2).gameObject) : ((object)val2))); } } if ((Object)(object)((Component)val).gameObject != (Object)(object)go) { ((Component)val).transform.localPosition = Vector3.zero; ((Component)val).transform.localRotation = Quaternion.identity; ((Component)val).transform.localScale = Vector3.one; } val.center = ((Bounds)(ref bounds)).center; val.size = ((Bounds)(ref bounds)).size; RoomVolumeCheck component = go.GetComponent<RoomVolumeCheck>(); if ((Object)(object)component != (Object)null) { component.CheckPosition = ((Bounds)(ref bounds)).center; component.currentSize = ((Bounds)(ref bounds)).size; } } private static Transform FindChildDeep(Transform root, string name) { Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if ((Object)(object)val != (Object)(object)root && ((Object)val).name == name) { return val; } } return null; } private static PhysAttribute MakeMass(PhysAttribute donor, float mass, string name) { PhysAttribute obj = (((Object)(object)donor != (Object)null) ? Object.Instantiate<PhysAttribute>(donor) : ScriptableObject.CreateInstance<PhysAttribute>()); ((Object)obj).name = name; obj.mass = mass; return obj; } private static PhysAudio CloneAudio(PhysAudio donor, string name) { PhysAudio obj = (((Object)(object)donor != (Object)null) ? Object.Instantiate<PhysAudio>(donor) : ScriptableObject.CreateInstance<PhysAudio>()); ((Object)obj).name = name; return obj; } private static void SetSound(Sound sound, AudioClip[] clips, float volume) { sound.Sounds = clips; sound.Volume = volume; sound.VolumeDefault = volume; sound.Pitch = 1f; sound.PitchDefault = 1f; sound.PitchRandom = 0.08f; sound.VolumeRandom = 0.1f; } private static Gradient MakeGradient(Color a, Color b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_000f: 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) //IL_001a: 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_0027: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) Gradient val = new Gradient(); val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2] { new GradientColorKey(a, 0f), new GradientColorKey(b, 1f) }, (GradientAlphaKey[])(object)new GradientAlphaKey[2] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) }); return val; } private static bool SetTexture(Material m, Texture tex, params string[] names) { bool result = false; foreach (string text in names) { if (m.HasProperty(text)) { m.SetTexture(text, tex); result = true; } } return result; } private static void SetColor(Material m, Color c) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) string[] array = new string[2] { "_Color", "_BaseColor" }; foreach (string text in array) { if (m.HasProperty(text)) { m.SetColor(text, c); } } } private static void SetFloat(Material m, float v, params string[] names) { foreach (string text in names) { if (m.HasProperty(text)) { m.SetFloat(text, v); } } } private static void LogShader(Material m) { if (!_loggedShader) { _loggedShader = true; List<string> list = new List<string>(); for (int i = 0; i < m.shader.GetPropertyCount(); i++) { list.Add(m.shader.GetPropertyName(i)); } Plugin.Log.LogDebug((object)("Donor shader " + ((Object)m.shader).name + " properties: " + string.Join(", ", list))); } } } [BepInPlugin("repo.piggybank", "PiggyBank", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string Guid = "repo.piggybank"; public const string Name = "PiggyBank"; public const string Version = "1.0.0"; internal static Plugin Instance; internal static ManualLogSource Log; internal static string PluginDir; internal static ConfigEntry<int> ValueMin; internal static ConfigEntry<int> ValueMax; internal static ConfigEntry<int> SpawnWeight; internal static ConfigEntry<float> PiggyScale; internal static ConfigEntry<float> CoinScale; internal static ConfigEntry<int> Fragility; internal static ConfigEntry<int> Durability; internal static ConfigEntry<bool> HeavyHitsSmash; internal static ConfigEntry<int> CoinBonusPercent; internal static ConfigEntry<int> MinCoins; internal static ConfigEntry<int> MaxCoins; internal static ConfigEntry<float> NoiseRadius; internal static ConfigEntry<bool> DebugKeys; internal static ConfigEntry<Key> DebugSpawnKey; private static int _lastTickFrame = -1; private static bool _wasDown; private static bool _loggedHeartbeat; private void Awake() { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Expected O, but got Unknown //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Expected O, but got Unknown //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Expected O, but got Unknown //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Expected O, but got Unknown //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Expected O, but got Unknown //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Expected O, but got Unknown //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Expected O, but got Unknown //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Expected O, but got Unknown //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_0315: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) Instance = this; Log = ((BaseUnityPlugin)this).Logger; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; PluginDir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); ValueMin = ((BaseUnityPlugin)this).Config.Bind<int>("Piggy Bank", "Value Min", 1500, new ConfigDescription("Lowest value a freshly spawned piggy bank can have. Only the host's setting matters.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(100, 1000000), Array.Empty<object>())); ValueMax = ((BaseUnityPlugin)this).Config.Bind<int>("Piggy Bank", "Value Max", 3000, new ConfigDescription("Highest value a freshly spawned piggy bank can have. Only the host's setting matters.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(100, 1000000), Array.Empty<object>())); SpawnWeight = ((BaseUnityPlugin)this).Config.Bind<int>("Piggy Bank", "Spawn Weight", 2, new ConfigDescription("How many times the piggy bank is entered into the small-valuable pool each level. Higher = more common, 0 = never spawns. Roughly: weight / (weight + number of other small valuables).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 50), Array.Empty<object>())); PiggyScale = ((BaseUnityPlugin)this).Config.Bind<float>("Piggy Bank", "Scale", 3f, new ConfigDescription("Size multiplier for the piggy bank. 1 = about 0.4 m long, 3 = about 1.3 m long. Everyone in the lobby should use the same value.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f), Array.Empty<object>())); CoinScale = ((BaseUnityPlugin)this).Config.Bind<float>("Smash", "Coin Scale", 5f, new ConfigDescription("Size multiplier for the coins. 1 = a 9 cm coin. Everyone in the lobby should use the same value.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f), Array.Empty<object>())); Fragility = ((BaseUnityPlugin)this).Config.Bind<int>("Piggy Bank", "Fragility", 80, new ConfigDescription("How easily impacts register as knocks (0-100). Higher = loses value and smashes more easily.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); Durability = ((BaseUnityPlugin)this).Config.Bind<int>("Piggy Bank", "Durability", 60, new ConfigDescription("How much value each knock costs (0-100). Lower = each knock hurts more.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); HeavyHitsSmash = ((BaseUnityPlugin)this).Config.Bind<bool>("Smash", "Heavy Hits Smash", true, "If true, any heavy impact (hard throw, big fall, getting walloped) smashes the piggy bank outright. If false it only breaks the vanilla way, when its value falls below 15% of the original."); CoinBonusPercent = ((BaseUnityPlugin)this).Config.Bind<int>("Smash", "Coin Bonus Percent", 150, new ConfigDescription("Total coin value as a percentage of the piggy bank's value at the moment it smashes. 150 = coins are worth 1.5x.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())); MinCoins = ((BaseUnityPlugin)this).Config.Bind<int>("Smash", "Min Coins", 5, new ConfigDescription("Fewest coins a smash can release.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 30), Array.Empty<object>())); MaxCoins = ((BaseUnityPlugin)this).Config.Bind<int>("Smash", "Max Coins", 10, new ConfigDescription("Most coins a smash can release.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 30), Array.Empty<object>())); NoiseRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Smash", "Noise Radius", 25f, new ConfigDescription("Metres around the smash that monsters can hear and come to investigate.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); DebugKeys = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Enable Debug Keys", false, "Lets the host spawn a piggy bank in front of them with the key below. For testing only."); DebugSpawnKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Debug", "Spawn Key", (Key)101, "Key that spawns a piggy bank (host only)."); if (DebugKeys.Value) { Log.LogInfo((object)("Debug keys on: the host can press " + ((object)DebugSpawnKey.Value/*cast due to .constrained prefix*/).ToString() + " to spawn a piggy bank.")); } if (!File.Exists(Path.Combine(PluginDir, "piggybank"))) { Log.LogError((object)"Missing asset bundle 'piggybank' next to the plugin. The piggy bank will not be registered."); return; } new Harmony("repo.piggybank").PatchAll(typeof(Plugin).Assembly); Log.LogInfo((object)"PiggyBank 1.0.0 loaded."); } private void Update() { DebugTick(); } internal unsafe static void DebugTick() { //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: 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_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: 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_00fd: Unknown result type (might be due to invalid IL or missing references) if (Time.frameCount == _lastTickFrame) { return; } _lastTickFrame = Time.frameCount; if (!DebugKeys.Value || !DebugKeyPressed()) { return; } if (PiggyBuilder.PiggyRef == null) { Log.LogWarning((object)"Debug spawn: the piggy bank is not registered (see earlier errors)."); return; } if (!SemiFunc.IsMasterClientOrSingleplayer()) { Log.LogWarning((object)"Debug spawn: only the host can spawn valuables."); return; } Camera val = SemiFunc.MainCamera(); if ((Object)(object)val == (Object)null) { val = Camera.main; } if ((Object)(object)val == (Object)null) { Log.LogWarning((object)"Debug spawn: no camera found. Are you in a level?"); return; } Vector3 val2 = ((Component)val).transform.position + ((Component)val).transform.forward * (1.2f + 0.3f * PiggyScale.Value) + Vector3.up * 0.2f * PiggyScale.Value; GameObject val3 = Valuables.SpawnValuable(PiggyBuilder.PiggyRef, val2, Quaternion.identity); ManualLogSource log = Log; Vector3 val4 = val2; log.LogInfo((object)("Debug spawn at " + ((object)(*(Vector3*)(&val4))/*cast due to .constrained prefix*/).ToString() + ": " + (((Object)(object)val3 != (Object)null) ? "ok" : "FAILED (see REPOLib errors)"))); } private static bool DebugKeyPressed() { //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_004f: Unknown result type (might be due to invalid IL or missing references) if (!_loggedHeartbeat) { _loggedHeartbeat = true; Log.LogInfo((object)("Debug key polling started (keyboard: " + ((Keyboard.current != null) ? ((InputControl)Keyboard.current).displayName : "none") + ").")); } bool flag = false; try { Keyboard current = Keyboard.current; if (current != null) { flag = ((ButtonControl)current[DebugSpawnKey.Value]).isPressed; } } catch (Exception ex) { Log.LogWarning((object)("Input System key check failed: " + ex.Message)); } if (!flag) { try { flag = Input.GetKey(LegacyKey(DebugSpawnKey.Value)); } catch (Exception) { } } bool num = flag && !_wasDown; _wasDown = flag; if (num) { Log.LogInfo((object)"Debug spawn key pressed."); } return num; } private static KeyCode LegacyKey(Key key) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Invalid comparison between Unknown and I4 //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Invalid comparison between Unknown and I4 //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0012: 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) if ((int)key < 94 || (int)key > 105) { return (KeyCode)0; } return (KeyCode)(282 + (key - 94)); } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }