using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using UnityEngine; using UnityEngine.AI; [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("REPOJP")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("zabuMod")] [assembly: AssemblyTitle("zabuMod")] [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 REPOJP.RandomSizeValuables { [BepInPlugin("REPOJP.RandomSizeValuables", "RandomSizeValuables", "4.0.0")] public class RandomSizeValuablesPlugin : BaseUnityPlugin { public const string PluginGuid = "REPOJP.RandomSizeValuables"; public const string PluginName = "RandomSizeValuables"; public const string PluginVersion = "4.0.0"; internal static RandomSizeValuablesPlugin Instance; internal static ManualLogSource Log; private Harmony harmony; internal static ConfigEntry ModEnabled; internal static ConfigEntry MaxVariantValuableCount; internal static ConfigEntry VariantValuableSpawnChance; internal static ConfigEntry BadLuckBonusPerEmptyLevel; internal static ConfigEntry SmallBandSelectChance; internal static ConfigEntry SmallBandScaleMin; internal static ConfigEntry SmallBandScaleMax; internal static ConfigEntry MediumBandSelectChance; internal static ConfigEntry MediumBandScaleMin; internal static ConfigEntry MediumBandScaleMax; internal static ConfigEntry LargeBandSelectChance; internal static ConfigEntry LargeBandScaleMin; internal static ConfigEntry LargeBandScaleMax; internal static ConfigEntry ValueMultiplierMin; internal static ConfigEntry ValueMultiplierMax; internal static ConfigEntry BreakResistanceMultiplier; internal static ConfigEntry DamageRelocationEnabled; internal static ConfigEntry RelocateOnValueLoss; internal static ConfigEntry RelocateOnDamaged; internal static ConfigEntry LevelPointSearchRange; internal static ConfigEntry UseFallbackLevelPoint; internal static ConfigEntry RestoreValueAfterRelocate; internal static ConfigEntry RestoreDamageStateAfterRelocate; internal static ConfigEntry MaxRelocateAttempts; private void Awake() { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown try { Instance = this; Log = ((BaseUnityPlugin)this).Logger; ((Component)this).transform.parent = null; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; BindConfig(); harmony = new Harmony("REPOJP.RandomSizeValuables"); harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"RandomSizeValuables v4.0.0 loaded."); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failure: Awake\n" + ex)); } } private void OnDestroy() { try { if (harmony != null) { harmony.UnpatchSelf(); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failure: OnDestroy\n" + ex)); } } private void BindConfig() { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Expected O, but got Unknown //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Expected O, but got Unknown //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Expected O, but got Unknown //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Expected O, but got Unknown //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Expected O, but got Unknown //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Expected O, but got Unknown //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Expected O, but got Unknown //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Expected O, but got Unknown //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Expected O, but got Unknown //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Expected O, but got Unknown //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Expected O, but got Unknown //IL_0361: Unknown result type (might be due to invalid IL or missing references) //IL_036b: Expected O, but got Unknown //IL_039e: Unknown result type (might be due to invalid IL or missing references) //IL_03a8: Expected O, but got Unknown //IL_043b: Unknown result type (might be due to invalid IL or missing references) //IL_0445: Expected O, but got Unknown //IL_04d1: Unknown result type (might be due to invalid IL or missing references) //IL_04db: Expected O, but got Unknown ModEnabled = ((BaseUnityPlugin)this).Config.Bind("General", "ModEnabled", true, "Enable this mod.このMODを有効にします。"); MaxVariantValuableCount = ((BaseUnityPlugin)this).Config.Bind("General", "MaxVariantValuableCount", 50, new ConfigDescription("Maximum number of scaled valuables per level.1レベル内でサイズ変更される貴重品の最大数です。", (AcceptableValueBase)(object)new AcceptableValueRange(1, 200), Array.Empty())); VariantValuableSpawnChance = ((BaseUnityPlugin)this).Config.Bind("General", "VariantValuableSpawnChance", 50f, new ConfigDescription("Spawn chance rolled once per maximum scaled valuable count.最大生成数の回数分だけ抽選されるサイズ変更貴重品の生成確率です。", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 100f), Array.Empty())); BadLuckBonusPerEmptyLevel = ((BaseUnityPlugin)this).Config.Bind("General", "BadLuckBonusPerEmptyLevel", 20f, new ConfigDescription("Chance bonus added after each level with zero scaled valuables.サイズ変更貴重品が0個だったレベルごとに加算される補填確率です。", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 100f), Array.Empty())); SmallBandSelectChance = ((BaseUnityPlugin)this).Config.Bind("Small Size Band", "SmallBandSelectChance", 100f, new ConfigDescription("Chance for Tiny and Small valuables to be eligible. Tiny/Smallの貴重品をサイズ変更候補にする確率です。", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 100f), Array.Empty())); SmallBandScaleMin = ((BaseUnityPlugin)this).Config.Bind("Small Size Band", "SmallBandScaleMin", 1.5f, new ConfigDescription("Minimum scale multiplier for Tiny and Small valuables. Tiny/Smallの最小サイズ倍率です。", (AcceptableValueBase)(object)new AcceptableValueRange(0.01f, 10f), Array.Empty())); SmallBandScaleMax = ((BaseUnityPlugin)this).Config.Bind("Small Size Band", "SmallBandScaleMax", 3f, new ConfigDescription("Maximum scale multiplier for Tiny and Small valuables. Tiny/Smallの最大サイズ倍率です。", (AcceptableValueBase)(object)new AcceptableValueRange(0.01f, 10f), Array.Empty())); MediumBandSelectChance = ((BaseUnityPlugin)this).Config.Bind("Medium Size Band", "MediumBandSelectChance", 100f, new ConfigDescription("Chance for Medium, Big, and Wide valuables to be eligible. Medium/Big/Wideの貴重品をサイズ変更候補にする確率です。", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 100f), Array.Empty())); MediumBandScaleMin = ((BaseUnityPlugin)this).Config.Bind("Medium Size Band", "MediumBandScaleMin", 0.5f, new ConfigDescription("Minimum scale multiplier for Medium, Big, and Wide valuables. Medium/Big/Wideの最小サイズ倍率です。", (AcceptableValueBase)(object)new AcceptableValueRange(0.01f, 10f), Array.Empty())); MediumBandScaleMax = ((BaseUnityPlugin)this).Config.Bind("Medium Size Band", "MediumBandScaleMax", 2f, new ConfigDescription("Maximum scale multiplier for Medium, Big, and Wide valuables. Medium/Big/Wideの最大サイズ倍率です。", (AcceptableValueBase)(object)new AcceptableValueRange(0.01f, 10f), Array.Empty())); LargeBandSelectChance = ((BaseUnityPlugin)this).Config.Bind("Large Size Band", "LargeBandSelectChance", 100f, new ConfigDescription("Chance for Tall and VeryTall valuables to be eligible. Tall/VeryTallの貴重品をサイズ変更候補にする確率です。", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 100f), Array.Empty())); LargeBandScaleMin = ((BaseUnityPlugin)this).Config.Bind("Large Size Band", "LargeBandScaleMin", 0.1f, new ConfigDescription("Minimum scale multiplier for Tall and VeryTall valuables. Tall/VeryTallの最小サイズ倍率です。", (AcceptableValueBase)(object)new AcceptableValueRange(0.01f, 10f), Array.Empty())); LargeBandScaleMax = ((BaseUnityPlugin)this).Config.Bind("Large Size Band", "LargeBandScaleMax", 0.5f, new ConfigDescription("Maximum scale multiplier for Tall and VeryTall valuables. Tall/VeryTallの最大サイズ倍率です。", (AcceptableValueBase)(object)new AcceptableValueRange(0.01f, 10f), Array.Empty())); ValueMultiplierMin = ((BaseUnityPlugin)this).Config.Bind("Value and Durability", "ValueMultiplierMin", 2f, new ConfigDescription("Minimum value multiplier for scaled valuables.サイズ変更貴重品の最小価値倍率です。", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 10f), Array.Empty())); ValueMultiplierMax = ((BaseUnityPlugin)this).Config.Bind("Value and Durability", "ValueMultiplierMax", 5f, new ConfigDescription("Maximum value multiplier for scaled valuables.サイズ変更貴重品の最大価値倍率です。", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 10f), Array.Empty())); BreakResistanceMultiplier = ((BaseUnityPlugin)this).Config.Bind("Value and Durability", "BreakResistanceMultiplier", 5f, new ConfigDescription("Break resistance multiplier. Set 10.01 to make scaled valuables unbreakable.壊れにくさ倍率です。10.01の場合のみサイズ変更貴重品が絶対に壊れなくなります。", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 10.01f), Array.Empty())); DamageRelocationEnabled = ((BaseUnityPlugin)this).Config.Bind("Damage Relocation", "DamageRelocationEnabled", true, "Relocate scaled valuables immediately when their value is reduced before being grabbed.掴まれる前に価値が減少したサイズ変更貴重品を即時再配置します。"); RelocateOnValueLoss = ((BaseUnityPlugin)this).Config.Bind("Damage Relocation", "RelocateOnValueLoss", true, "Relocate when value is reduced before being grabbed.掴まれる前に価値が減少した場合に再配置します。"); RelocateOnDamaged = ((BaseUnityPlugin)this).Config.Bind("Damage Relocation", "RelocateOnDamaged", true, "Treat value reduction as damage and restore damage state after relocation when possible.価値減少を破損扱いとして、再配置後に可能な範囲で破損状態を戻します。"); LevelPointSearchRange = ((BaseUnityPlugin)this).Config.Bind("Damage Relocation", "LevelPointSearchRange", 30f, new ConfigDescription("Search range for nearby level points.近くのレベルポイントを探す範囲です。", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 300f), Array.Empty())); UseFallbackLevelPoint = ((BaseUnityPlugin)this).Config.Bind("Damage Relocation", "UseFallbackLevelPoint", true, "Use another safe level point if no nearby level point is found.近くに有効なレベルポイントがない場合に代替地点へ再配置します。"); RestoreValueAfterRelocate = ((BaseUnityPlugin)this).Config.Bind("Damage Relocation", "RestoreValueAfterRelocate", true, "Restore value after relocation.再配置後に価値を元に戻します。"); RestoreDamageStateAfterRelocate = ((BaseUnityPlugin)this).Config.Bind("Damage Relocation", "RestoreDamageStateAfterRelocate", true, "Restore damage state after relocation when possible.再配置後に可能な範囲で破損状態を元に戻します。"); MaxRelocateAttempts = ((BaseUnityPlugin)this).Config.Bind("Damage Relocation", "MaxRelocateAttempts", 10, new ConfigDescription("Maximum relocation attempts per valuable.貴重品ごとの最大再配置試行回数です。", (AcceptableValueBase)(object)new AcceptableValueRange(1, 200), Array.Empty())); } internal static bool HasBeenGrabbedByPlayer(PhysGrabObject physGrabObject) { if ((Object)(object)physGrabObject == (Object)null) { return false; } if (physGrabObject.grabbed) { return true; } if (physGrabObject.playerGrabbing != null && physGrabObject.playerGrabbing.Count > 0) { return true; } FieldInfo fieldInfo = AccessTools.Field(typeof(PhysGrabObject), "hasNeverBeenGrabbed"); if (fieldInfo != null) { object value = fieldInfo.GetValue(physGrabObject); if (value is bool && !(bool)value) { return true; } } return false; } internal static void TryRelocateAfterUngrabbedValueLoss(ScaledValuableInfo info, float beforeValue, float afterValue) { if (DamageRelocationEnabled.Value && RelocateOnValueLoss.Value && info != null && !((Object)(object)info.ValuableObject == (Object)null) && !((Object)(object)info.PhysGrabObject == (Object)null) && SemiFunc.IsMasterClientOrSingleplayer()) { if (HasBeenGrabbedByPlayer(info.PhysGrabObject)) { VariantState.Unregister(info.PhysGrabObject); } else if (!(afterValue >= beforeValue - 0.01f)) { info.RestorableValue = Mathf.Max(info.RestorableValue, beforeValue); TryRelocate(info, "UngrabbedValueLoss"); } } } internal static void TryRelocate(ScaledValuableInfo info, string reason) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: 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_0106: 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_010d: Unknown result type (might be due to invalid IL or missing references) if (info.RelocateAttempts >= MaxRelocateAttempts.Value) { return; } info.RelocateAttempts++; if (!TryGetSafeRelocatePoint(info, out var targetPosition, out var targetRotation)) { Log.LogWarning((object)("Failed to find safe level point: name=" + info.NormalizedName + ", reason=" + reason)); return; } try { info.PhysGrabObject.Teleport(targetPosition, targetRotation); Rigidbody component = ((Component)info.PhysGrabObject).GetComponent(); if ((Object)(object)component != (Object)null) { component.velocity = Vector3.zero; component.angularVelocity = Vector3.zero; } if ((Object)(object)info.ImpactDetector != (Object)null) { info.ImpactDetector.ImpactDisable(1f); } if (RestoreValueAfterRelocate.Value) { RestoreValue(info); } if (RestoreDamageStateAfterRelocate.Value) { RestoreDamageState(info); } info.LastSafePosition = targetPosition; info.LastSafeRotation = targetRotation; Log.LogWarning((object)("Relocated ungrabbed value-loss valuable: name=" + info.NormalizedName + ", reason=" + reason + ", attempt=" + info.RelocateAttempts)); } catch (Exception ex) { Log.LogError((object)("Failure: TryRelocate " + info.NormalizedName + "\n" + ex)); } } private static bool TryGetSafeRelocatePoint(ScaledValuableInfo info, out Vector3 targetPosition, out Quaternion targetRotation) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0058: 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_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: 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_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: 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_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_014d: 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_016d: Unknown result type (might be due to invalid IL or missing references) targetPosition = info.InitialPosition; targetRotation = info.InitialRotation; if ((Object)(object)LevelGenerator.Instance == (Object)null || LevelGenerator.Instance.LevelPathPoints == null) { return false; } LevelPoint val = null; float num = float.MaxValue; Vector3 position = ((Component)info.PhysGrabObject).transform.position; float num2 = Mathf.Max(1f, LevelPointSearchRange.Value); foreach (LevelPoint levelPathPoint in LevelGenerator.Instance.LevelPathPoints) { if (!((Object)(object)levelPathPoint == (Object)null)) { float num3 = Vector3.Distance(position, ((Component)levelPathPoint).transform.position); if (num3 <= num2 && num3 < num && IsSafePoint(((Component)levelPathPoint).transform.position, info)) { val = levelPathPoint; num = num3; } } } if ((Object)(object)val == (Object)null && UseFallbackLevelPoint.Value) { foreach (LevelPoint levelPathPoint2 in LevelGenerator.Instance.LevelPathPoints) { if (!((Object)(object)levelPathPoint2 == (Object)null)) { float num4 = Vector3.Distance(position, ((Component)levelPathPoint2).transform.position); if (num4 < num && IsSafePoint(((Component)levelPathPoint2).transform.position, info)) { val = levelPathPoint2; num = num4; } } } } if ((Object)(object)val == (Object)null) { return false; } Bounds bounds = GetBounds(((Component)info.PhysGrabObject).gameObject); float num5 = Mathf.Max(0.5f, ((Bounds)(ref bounds)).extents.y + 0.25f); targetPosition = ((Component)val).transform.position + Vector3.up * num5; targetRotation = ((Component)val).transform.rotation; return true; } private static bool IsSafePoint(Vector3 position, ScaledValuableInfo info) { //IL_0001: 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_0031: 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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_0091: 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_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_00af: Unknown result type (might be due to invalid IL or missing references) NavMeshHit val = default(NavMeshHit); if (!NavMesh.SamplePosition(position, ref val, 5f, -1)) { return false; } Bounds bounds = GetBounds(((Component)info.PhysGrabObject).gameObject); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(Mathf.Clamp(((Bounds)(ref bounds)).extents.x, 0.25f, 4f), Mathf.Clamp(((Bounds)(ref bounds)).extents.y, 0.25f, 4f), Mathf.Clamp(((Bounds)(ref bounds)).extents.z, 0.25f, 4f)); Vector3 val3 = ((NavMeshHit)(ref val)).position + Vector3.up * (val2.y + 0.25f); return !Physics.CheckBox(val3, val2, Quaternion.identity, -1, (QueryTriggerInteraction)1); } private static Bounds GetBounds(GameObject gameObject) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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_0022: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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) //IL_005f: Unknown result type (might be due to invalid IL or missing references) Renderer[] componentsInChildren = gameObject.GetComponentsInChildren(); if (componentsInChildren.Length == 0) { return new Bounds(gameObject.transform.position, Vector3.one); } Bounds bounds = componentsInChildren[0].bounds; for (int i = 1; i < componentsInChildren.Length; i++) { ((Bounds)(ref bounds)).Encapsulate(componentsInChildren[i].bounds); } return bounds; } private static void RestoreValue(ScaledValuableInfo info) { ReflectionUtil.SetFloat(info.ValuableObject, "dollarValueOriginal", info.RestorableValue); ReflectionUtil.SetFloat(info.ValuableObject, "dollarValueCurrent", info.RestorableValue); ReflectionUtil.SetBool(info.ValuableObject, "dollarValueSet", value: true); PhotonView component = ((Component)info.ValuableObject).GetComponent(); if ((Object)(object)component != (Object)null && SemiFunc.IsMultiplayer()) { component.RPC("DollarValueSetRPC", (RpcTarget)1, new object[1] { info.RestorableValue }); } } private static void RestoreDamageState(ScaledValuableInfo info) { if ((Object)(object)info.PhysGrabObject != (Object)null) { info.PhysGrabObject.dead = false; } if ((Object)(object)info.ImpactDetector != (Object)null) { ReflectionUtil.SetBool(info.ImpactDetector, "destroyDisable", value: false); ReflectionUtil.SetBool(info.ImpactDetector, "isIndestructible", value: false); } } } internal static class VariantState { internal static int BadLuckEmptyLevelCount; internal static int PlannedVariantCount; internal static int AppliedVariantCount; internal static HashSet SelectedNames = new HashSet(); internal static Dictionary TrackedObjects = new Dictionary(); internal static bool HasPreviousLevelResult; internal static void BeginLevel() { if (HasPreviousLevelResult) { if (AppliedVariantCount > 0) { BadLuckEmptyLevelCount = 0; } else { BadLuckEmptyLevelCount++; } } HasPreviousLevelResult = true; PlannedVariantCount = 0; AppliedVariantCount = 0; SelectedNames.Clear(); TrackedObjects.Clear(); float num = RandomSizeValuablesPlugin.VariantValuableSpawnChance.Value + (float)BadLuckEmptyLevelCount * RandomSizeValuablesPlugin.BadLuckBonusPerEmptyLevel.Value; num = Mathf.Clamp(num, 0f, 100f); int num2 = Mathf.Max(0, RandomSizeValuablesPlugin.MaxVariantValuableCount.Value); for (int i = 0; i < num2; i++) { if (Random.Range(0f, 100f) < num) { PlannedVariantCount++; } } RandomSizeValuablesPlugin.Log.LogInfo((object)("Variant plan: planned=" + PlannedVariantCount + ", badLuck=" + BadLuckEmptyLevelCount + ", effectiveChance=" + num.ToString("0.##"))); } internal static void Register(ScaledValuableInfo info) { if (info != null && !((Object)(object)info.PhysGrabObject == (Object)null)) { TrackedObjects[info.PhysGrabObject] = info; } } internal static void Unregister(PhysGrabObject physGrabObject) { if (!((Object)(object)physGrabObject == (Object)null) && TrackedObjects.ContainsKey(physGrabObject)) { TrackedObjects.Remove(physGrabObject); } } internal static bool TryGet(PhysGrabObject physGrabObject, out ScaledValuableInfo info) { info = null; if ((Object)(object)physGrabObject == (Object)null) { return false; } return TrackedObjects.TryGetValue(physGrabObject, out info); } } internal class ScaledValuableInfo { internal ValuableObject ValuableObject; internal PhysGrabObject PhysGrabObject; internal PhysGrabObjectImpactDetector ImpactDetector; internal string NormalizedName; internal Type OriginalVolumeType; internal float ScaleMultiplier; internal float ValueMultiplier; internal float RestorableValue; internal Vector3 InitialPosition; internal Quaternion InitialRotation; internal Vector3 LastSafePosition; internal Quaternion LastSafeRotation; internal int RelocateAttempts; } internal static class VariantSelector { internal static bool TryCreateVariant(PrefabRef valuable, ValuableVolume volume, out float scaleMultiplier, out float valueMultiplier, out string normalizedName) { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) scaleMultiplier = 1f; valueMultiplier = 1f; normalizedName = NormalizeName(valuable); if (!RandomSizeValuablesPlugin.ModEnabled.Value) { return false; } if (!SemiFunc.IsMasterClientOrSingleplayer()) { return false; } if (VariantState.PlannedVariantCount <= VariantState.AppliedVariantCount) { return false; } if (string.IsNullOrEmpty(normalizedName) || VariantState.SelectedNames.Contains(normalizedName)) { return false; } if (!PassesBandChance(volume.VolumeType)) { return false; } scaleMultiplier = GetScaleMultiplier(volume.VolumeType); valueMultiplier = GetValueMultiplier(); VariantState.SelectedNames.Add(normalizedName); return true; } internal static string NormalizeName(PrefabRef valuable) { string text = string.Empty; try { if (valuable != null && !string.IsNullOrEmpty(valuable.PrefabName)) { text = valuable.PrefabName; } else if (valuable != null && !string.IsNullOrEmpty(valuable.ResourcePath)) { text = valuable.ResourcePath; } } catch { text = string.Empty; } if (string.IsNullOrEmpty(text)) { return string.Empty; } text = text.Replace("(Clone)", string.Empty).Trim(); int num = text.LastIndexOf('/'); if (num >= 0 && num < text.Length - 1) { text = text.Substring(num + 1); } return text.Trim().ToLowerInvariant(); } private static bool PassesBandChance(Type type) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) float bandChance = GetBandChance(type); return Random.Range(0f, 100f) < Mathf.Clamp(bandChance, 0f, 100f); } private static float GetBandChance(Type type) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Invalid comparison between Unknown and I4 //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Invalid comparison between Unknown and I4 if ((int)type == 0 || (int)type == 1) { return RandomSizeValuablesPlugin.SmallBandSelectChance.Value; } if ((int)type == 5 || (int)type == 6) { return RandomSizeValuablesPlugin.LargeBandSelectChance.Value; } return RandomSizeValuablesPlugin.MediumBandSelectChance.Value; } private static float GetScaleMultiplier(Type type) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Invalid comparison between Unknown and I4 //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Invalid comparison between Unknown and I4 float num; float num2; if ((int)type == 0 || (int)type == 1) { num = Mathf.Max(1f, RandomSizeValuablesPlugin.SmallBandScaleMin.Value); num2 = Mathf.Max(1f, RandomSizeValuablesPlugin.SmallBandScaleMax.Value); } else if ((int)type == 5 || (int)type == 6) { num = Mathf.Min(1f, RandomSizeValuablesPlugin.LargeBandScaleMin.Value); num2 = Mathf.Min(1f, RandomSizeValuablesPlugin.LargeBandScaleMax.Value); } else { num = RandomSizeValuablesPlugin.MediumBandScaleMin.Value; num2 = RandomSizeValuablesPlugin.MediumBandScaleMax.Value; } num = Mathf.Clamp(num, 0.01f, 10f); num2 = Mathf.Clamp(num2, 0.01f, 10f); if (num > num2) { float num3 = num; num = num2; num2 = num3; } return Random.Range(num, num2); } private static float GetValueMultiplier() { float num = Mathf.Clamp(RandomSizeValuablesPlugin.ValueMultiplierMin.Value, 1f, 10f); float num2 = Mathf.Clamp(RandomSizeValuablesPlugin.ValueMultiplierMax.Value, 1f, 10f); if (num > num2) { float num3 = num; num = num2; num2 = num3; } return Random.Range(num, num2); } } internal static class ReflectionUtil { internal static float GetFloat(object instance, string fieldName, float fallback) { if (instance == null) { return fallback; } FieldInfo fieldInfo = AccessTools.Field(instance.GetType(), fieldName); if (fieldInfo == null) { return fallback; } if (!(fieldInfo.GetValue(instance) is float result)) { return fallback; } return result; } internal static void SetFloat(object instance, string fieldName, float value) { if (instance != null) { FieldInfo fieldInfo = AccessTools.Field(instance.GetType(), fieldName); if (fieldInfo != null) { fieldInfo.SetValue(instance, value); } } } internal static void SetBool(object instance, string fieldName, bool value) { if (instance != null) { FieldInfo fieldInfo = AccessTools.Field(instance.GetType(), fieldName); if (fieldInfo != null) { fieldInfo.SetValue(instance, value); } } } internal static int GetInt(object instance, string fieldName, int fallback) { if (instance == null) { return fallback; } FieldInfo fieldInfo = AccessTools.Field(instance.GetType(), fieldName); if (fieldInfo == null) { return fallback; } if (!(fieldInfo.GetValue(instance) is int result)) { return fallback; } return result; } internal static void SetInt(object instance, string fieldName, int value) { if (instance != null) { FieldInfo fieldInfo = AccessTools.Field(instance.GetType(), fieldName); if (fieldInfo != null) { fieldInfo.SetValue(instance, value); } } } } [HarmonyPatch(typeof(ValuableDirector), "SetupHost")] internal static class ValuableDirectorSetupHostPatch { private static void Prefix() { try { if (RandomSizeValuablesPlugin.ModEnabled.Value && SemiFunc.IsMasterClientOrSingleplayer()) { VariantState.BeginLevel(); } } catch (Exception ex) { RandomSizeValuablesPlugin.Log.LogError((object)("Failure: SetupHost Prefix\n" + ex)); } } } [HarmonyPatch(typeof(ValuableDirector), "SpawnValuable")] internal static class ValuableDirectorSpawnValuablePatch { private static bool Prefix(ValuableDirector __instance, PrefabRef _valuable, ValuableVolume _volume, string _path) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: 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_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) if (!RandomSizeValuablesPlugin.ModEnabled.Value || !SemiFunc.IsMasterClientOrSingleplayer()) { return true; } try { float scaleMultiplier; float valueMultiplier; string normalizedName; bool flag = VariantSelector.TryCreateVariant(_valuable, _volume, out scaleMultiplier, out valueMultiplier, out normalizedName); Vector3 val = Vector3.one * scaleMultiplier; GameObject val2; if (GameManager.instance.gameMode == 0) { val2 = Object.Instantiate(_valuable.Prefab, ((Component)_volume).transform.position, ((Component)_volume).transform.rotation); if (flag) { val2.transform.localScale = val; } } else { object[] array = null; if (flag) { array = new object[3] { val.x, val.y, val.z }; } val2 = PhotonNetwork.InstantiateRoomObject(_valuable.ResourcePath, ((Component)_volume).transform.position, ((Component)_volume).transform.rotation, (byte)0, array); } ValuableObject component = val2.GetComponent(); if ((Object)(object)component != (Object)null) { component.DollarValueSetLogic(); if (flag) { ApplyVariantValue(component, valueMultiplier); RegisterVariant(val2, component, _volume, normalizedName, scaleMultiplier, valueMultiplier); } int value = ReflectionUtil.GetInt(__instance, "valuableTargetAmount", 0) + 1; ReflectionUtil.SetInt(__instance, "valuableTargetAmount", value); float @float = ReflectionUtil.GetFloat(__instance, "totalCurrentValue", 0f); float float2 = ReflectionUtil.GetFloat(component, "dollarValueCurrent", 0f); @float += float2 * 0.001f; ReflectionUtil.SetFloat(__instance, "totalCurrentValue", @float); float float3 = ReflectionUtil.GetFloat(__instance, "totalMaxValue", float.MaxValue); if (@float > float3) { ReflectionUtil.SetInt(__instance, "totalMaxAmount", value); } } return false; } catch (Exception ex) { RandomSizeValuablesPlugin.Log.LogError((object)("Failure: SpawnValuable Prefix\n" + ex)); return true; } } private static void ApplyVariantValue(ValuableObject valuableObject, float valueMultiplier) { float @float = ReflectionUtil.GetFloat(valuableObject, "dollarValueOriginal", 100f); float num = Mathf.Round(@float * valueMultiplier / 100f) * 100f; num = Mathf.Max(100f, num); ReflectionUtil.SetFloat(valuableObject, "dollarValueOriginal", num); ReflectionUtil.SetFloat(valuableObject, "dollarValueCurrent", num); ReflectionUtil.SetBool(valuableObject, "dollarValueSet", value: true); PhotonView component = ((Component)valuableObject).GetComponent(); if ((Object)(object)component != (Object)null && SemiFunc.IsMultiplayer()) { component.RPC("DollarValueSetRPC", (RpcTarget)1, new object[1] { num }); } } private static void RegisterVariant(GameObject gameObject, ValuableObject valuableObject, ValuableVolume volume, string normalizedName, float scaleMultiplier, float valueMultiplier) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_0080: 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_0091: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) PhysGrabObject component = gameObject.GetComponent(); PhysGrabObjectImpactDetector component2 = gameObject.GetComponent(); if (!((Object)(object)component == (Object)null)) { ScaledValuableInfo scaledValuableInfo = new ScaledValuableInfo(); scaledValuableInfo.ValuableObject = valuableObject; scaledValuableInfo.PhysGrabObject = component; scaledValuableInfo.ImpactDetector = component2; scaledValuableInfo.NormalizedName = normalizedName; scaledValuableInfo.OriginalVolumeType = volume.VolumeType; scaledValuableInfo.ScaleMultiplier = scaleMultiplier; scaledValuableInfo.ValueMultiplier = valueMultiplier; scaledValuableInfo.RestorableValue = ReflectionUtil.GetFloat(valuableObject, "dollarValueOriginal", 100f); scaledValuableInfo.InitialPosition = gameObject.transform.position; scaledValuableInfo.InitialRotation = gameObject.transform.rotation; scaledValuableInfo.LastSafePosition = scaledValuableInfo.InitialPosition; scaledValuableInfo.LastSafeRotation = scaledValuableInfo.InitialRotation; scaledValuableInfo.RelocateAttempts = 0; VariantState.AppliedVariantCount++; VariantState.Register(scaledValuableInfo); RandomSizeValuablesPlugin.Log.LogInfo((object)("Generated scaled valuable: name=" + normalizedName + ", originalSize=" + ((object)(Type)(ref volume.VolumeType)).ToString() + ", scale=" + scaleMultiplier.ToString("0.##") + ", valueMultiplier=" + valueMultiplier.ToString("0.##"))); } } } internal class BreakRpcValueState { internal bool Watch; internal float BeforeValue; } [HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "BreakRPC")] internal static class PhysGrabObjectImpactDetectorBreakRpcPatch { private static void Prefix(PhysGrabObjectImpactDetector __instance, out BreakRpcValueState __state) { __state = new BreakRpcValueState(); try { if (!RandomSizeValuablesPlugin.ModEnabled.Value || !RandomSizeValuablesPlugin.DamageRelocationEnabled.Value || !SemiFunc.IsMasterClientOrSingleplayer()) { return; } PhysGrabObject component = ((Component)__instance).GetComponent(); if (VariantState.TryGet(component, out ScaledValuableInfo info)) { if (RandomSizeValuablesPlugin.HasBeenGrabbedByPlayer(component)) { VariantState.Unregister(component); return; } __state.Watch = true; __state.BeforeValue = ReflectionUtil.GetFloat(info.ValuableObject, "dollarValueCurrent", info.RestorableValue); } } catch (Exception ex) { RandomSizeValuablesPlugin.Log.LogError((object)("Failure: BreakRPC Prefix\n" + ex)); } } private static void Postfix(PhysGrabObjectImpactDetector __instance, BreakRpcValueState __state) { try { if (__state == null || !__state.Watch || !RandomSizeValuablesPlugin.ModEnabled.Value || !RandomSizeValuablesPlugin.DamageRelocationEnabled.Value || !SemiFunc.IsMasterClientOrSingleplayer()) { return; } PhysGrabObject component = ((Component)__instance).GetComponent(); if (VariantState.TryGet(component, out ScaledValuableInfo info)) { if (RandomSizeValuablesPlugin.HasBeenGrabbedByPlayer(component)) { VariantState.Unregister(component); return; } float @float = ReflectionUtil.GetFloat(info.ValuableObject, "dollarValueCurrent", __state.BeforeValue); RandomSizeValuablesPlugin.TryRelocateAfterUngrabbedValueLoss(info, __state.BeforeValue, @float); } } catch (Exception ex) { RandomSizeValuablesPlugin.Log.LogError((object)("Failure: BreakRPC Postfix\n" + ex)); } } } [HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "Break")] internal static class PhysGrabObjectImpactDetectorBreakPatch { private static void Prefix(PhysGrabObjectImpactDetector __instance, ref float valueLost) { try { if (!RandomSizeValuablesPlugin.ModEnabled.Value) { return; } PhysGrabObject component = ((Component)__instance).GetComponent(); if (VariantState.TryGet(component, out ScaledValuableInfo _)) { float num = Mathf.Clamp(RandomSizeValuablesPlugin.BreakResistanceMultiplier.Value, 1f, 10.01f); if (num >= 10.01f) { valueLost = 0f; } else { valueLost /= num; } } } catch (Exception ex) { RandomSizeValuablesPlugin.Log.LogError((object)("Failure: Break Prefix\n" + ex)); } } } [HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "DestroyObject")] internal static class PhysGrabObjectImpactDetectorDestroyObjectPatch { private static bool Prefix(PhysGrabObjectImpactDetector __instance) { try { if (!RandomSizeValuablesPlugin.ModEnabled.Value) { return true; } PhysGrabObject component = ((Component)__instance).GetComponent(); if (!VariantState.TryGet(component, out ScaledValuableInfo _)) { return true; } float num = Mathf.Clamp(RandomSizeValuablesPlugin.BreakResistanceMultiplier.Value, 1f, 10.01f); if (num >= 10.01f) { return false; } } catch (Exception ex) { RandomSizeValuablesPlugin.Log.LogError((object)("Failure: DestroyObject Prefix\n" + ex)); } return true; } } }