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 FishTrap v1.1.4
plugins/FishTrap.dll
Decompiled 2 days agousing System; using System.Collections; using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace ValheimFishTrap; [BepInPlugin("com.valheim.fishtrap", "Fish Trap", "1.1.4")] public sealed class FishTrapPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(ZNetScene), "Awake")] private static class ScenePatch { private static void Postfix(ZNetScene __instance) { RegisterPrefabs(__instance); } } [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] private static class PlacementPatch { private static void Postfix(GameObject ___m_placementGhost, ref PlacementStatus ___m_placementStatus) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) if ((int)___m_placementStatus == 0 && !((Object)(object)___m_placementGhost == (Object)null) && !((Object)(object)___m_placementGhost.GetComponent<FishTrap>() == (Object)null) && !HasEnoughWater(___m_placementGhost.transform.position)) { ___m_placementStatus = (PlacementStatus)1; ___m_placementGhost.GetComponent<Piece>().SetInvalidPlacementHeightlight(true); } } } [HarmonyPatch(typeof(Piece), "DropResources")] private static class DropPatch { private static void Prefix(Piece __instance) { FishTrap component = ((Component)__instance).GetComponent<FishTrap>(); if ((Object)(object)component != (Object)null) { component.DropContents(); } } } [HarmonyPatch(typeof(WearNTear), "Destroy", new Type[] { typeof(HitData), typeof(bool) })] private static class DestroyDiagnosticPatch { private static Exception Finalizer(WearNTear __instance, Exception __exception) { if (__exception != null && (Object)(object)((Component)__instance).GetComponent<FishTrap>() != (Object)null) { Debug.LogError((object)("FishTrap: native trap destruction failed for " + ((Object)__instance).name + ": " + __exception)); } return __exception; } } internal const int MaxBait = 20; internal const int MaxFish = 4; internal const float MinimumWaterDepth = 0.25f; private const float MaximumStakeDiameter = 0.16f; internal static readonly long CatchInterval = TimeSpan.FromMinutes(20.0).Ticks; private static readonly string[] PrefabNames = new string[4] { "piece_fish_trap_1", "piece_fish_trap_2", "piece_fish_trap_3", "piece_fish_trap_4" }; internal static readonly GameObject[] Prefabs = (GameObject[])(object)new GameObject[PrefabNames.Length]; private static readonly FieldInfo NamedPrefabs = typeof(ZNetScene).GetField("m_namedPrefabs", BindingFlags.Instance | BindingFlags.NonPublic); private static readonly MethodInfo UpdateKnownRecipes = typeof(Player).GetMethod("UpdateKnownRecipesList", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly MethodInfo UpdateAvailablePieces = typeof(Player).GetMethod("UpdateAvailablePiecesList", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly string[][] Materials = new string[4][] { new string[4] { "Wood", "10", "Resin", "4" }, new string[4] { "RoundLog", "8", "BronzeNails", "6" }, new string[4] { "FineWood", "8", "IronNails", "6" }, new string[4] { "YggdrasilWood", "8", "BlackMetal", "6" } }; private static readonly Requirement[][] Recipes = new Requirement[4][]; private static Sprite fishIcon; private Player knownRecipesPlayer; private void Awake() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) new Harmony("com.valheim.fishtrap").PatchAll(); ((MonoBehaviour)this).InvokeRepeating("RefreshBuildPieces", 0f, 1f); } private void RefreshBuildPieces() { if ((Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ObjectDB.instance == (Object)null || (Object)(object)Prefabs[0] == (Object)null) { return; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Hammer"); if ((Object)(object)itemPrefab == (Object)null) { return; } PieceTable buildPieces = itemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_buildPieces; if ((Object)(object)buildPieces == (Object)null) { return; } if (buildPieces.m_pieces.Contains(Prefabs[0])) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && (Object)(object)localPlayer != (Object)(object)knownRecipesPlayer && UpdateKnownRecipes != null && UpdateAvailablePieces != null) { UpdateKnownRecipes.Invoke(localPlayer, null); UpdateAvailablePieces.Invoke(localPlayer, null); knownRecipesPlayer = localPlayer; } return; } for (int i = 0; i < Prefabs.Length; i++) { if ((Object)(object)Prefabs[i] == (Object)null || !ConfigurePiece(Prefabs[i].GetComponent<Piece>(), i + 1)) { return; } } buildPieces.m_pieces.RemoveAll((GameObject piece) => (Object)(object)piece != (Object)null && Array.IndexOf(PrefabNames, ((Object)piece).name) >= 0); for (int i = 0; i < Prefabs.Length; i++) { buildPieces.m_pieces.Add(Prefabs[i]); } knownRecipesPlayer = null; } internal static bool ConfigurePiece(Piece piece, int tier) { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Expected O, but got Unknown if ((Object)(object)piece == (Object)null || tier < 1 || tier > Recipes.Length) { return false; } piece.m_canBeRemoved = true; piece.m_craftingStation = null; if (Recipes[tier - 1] == null) { string[] array = Materials[tier - 1]; ItemDrop val = RecipeItem(array[0]); ItemDrop val2 = RecipeItem(array[2]); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return false; } Requirement[][] recipes = Recipes; int num = tier - 1; Requirement[] array2 = (Requirement[])(object)new Requirement[2]; Requirement val3 = new Requirement(); val3.m_resItem = val; val3.m_amount = int.Parse(array[1]); val3.m_recover = true; array2[0] = val3; Requirement val4 = new Requirement(); val4.m_resItem = val2; val4.m_amount = int.Parse(array[3]); val4.m_recover = true; array2[1] = val4; recipes[num] = array2; } piece.m_resources = Recipes[tier - 1]; if ((Object)(object)fishIcon == (Object)null) { ItemDrop val5 = RecipeItem("Fish1"); if ((Object)(object)val5 == (Object)null) { return false; } fishIcon = val5.m_itemData.GetIcon(); } if ((Object)(object)fishIcon == (Object)null) { return false; } piece.m_icon = fishIcon; return true; } private static ItemDrop RecipeItem(string name) { GameObject val = (((Object)(object)ZNetScene.instance == (Object)null) ? null : ZNetScene.instance.GetPrefab(name)); if ((Object)(object)val == (Object)null && (Object)(object)ObjectDB.instance != (Object)null) { val = ObjectDB.instance.GetItemPrefab(name); } return ((Object)(object)val == (Object)null) ? null : val.GetComponent<ItemDrop>(); } internal static void RegisterPrefabs(ZNetScene scene) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) GameObject prefab = scene.GetPrefab("piece_chest_wood"); if (!((Object)(object)prefab == (Object)null) && !(NamedPrefabs == null)) { Array.Clear(Recipes, 0, Recipes.Length); fishIcon = null; Dictionary<int, GameObject> dictionary = (Dictionary<int, GameObject>)NamedPrefabs.GetValue(scene); GameObject val = new GameObject("Fish Trap prefab holder"); val.SetActive(false); FindStakeVisual(scene, out var mesh, out var materials, out var source); if ((Object)(object)mesh == (Object)null) { Debug.LogWarning((object)"FishTrap: no vanilla stake mesh found; using the older stick visual."); } else { Debug.Log((object)("FishTrap: using " + source + "/" + ((Object)mesh).name + " for trap stakes.")); } for (int i = 0; i < Prefabs.Length; i++) { int num = i + 1; GameObject val2 = Object.Instantiate<GameObject>(prefab, val.transform); ((Object)val2).name = PrefabNames[i]; Object.DestroyImmediate((Object)(object)val2.GetComponent<Container>()); Piece component = val2.GetComponent<Piece>(); component.m_name = ((num == 1) ? "Stick Fish Trap" : ("Fish Trap " + num)); component.m_description = "Place in at least 0.25 m of water, then add bait to catch fish slowly."; component.m_category = (PieceCategory)0; component.m_usage = (UsageTagFlags)1; component.m_waterPiece = false; component.m_noInWater = false; component.m_groundOnly = true; component.m_clipGround = true; component.m_resources = (Requirement[])(object)new Requirement[0]; ConfigurePiece(component, num); FishTrap fishTrap = val2.AddComponent<FishTrap>(); fishTrap.Tier = num; MakeStickTrap(val2, num, mesh, materials, FindTierMetal(scene, num)); scene.m_prefabs.Add(val2); dictionary[StringExtensionMethods.GetStableHashCode(((Object)val2).name)] = val2; Prefabs[i] = val2; } } } private static void FindStakeVisual(ZNetScene scene, out Mesh mesh, out Material[] materials, out string source) { //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_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) mesh = null; materials = null; source = null; string[] array = new string[4] { "stake_wall", "wood_fence", "piece_sharpstakes", "dvergrtown_wood_stake" }; foreach (string text in array) { GameObject prefab = scene.GetPrefab(text); if ((Object)(object)prefab == (Object)null) { continue; } int num = -1; MeshFilter[] componentsInChildren = prefab.GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val in componentsInChildren) { Mesh sharedMesh = val.sharedMesh; MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>(); if ((Object)(object)sharedMesh == (Object)null || (Object)(object)component == (Object)null) { continue; } Bounds bounds = sharedMesh.bounds; Vector3 size = ((Bounds)(ref bounds)).size; float num2 = Mathf.Max(size.x, Mathf.Max(size.y, size.z)); float num3 = ((size.x == num2) ? Mathf.Max(size.y, size.z) : ((size.y == num2) ? Mathf.Max(size.x, size.z) : Mathf.Max(size.x, size.y))); if (num2 <= 0.01f || num2 < num3 * 2f) { continue; } Material[] sharedMaterials = ((Renderer)component).sharedMaterials; if (sharedMaterials.Length != 0 && Array.Exists(sharedMaterials, (Material material) => (Object)(object)material != (Object)null)) { int num4 = (((Object)sharedMesh).name.Equals("stake", StringComparison.OrdinalIgnoreCase) ? 2 : (Array.Exists(sharedMaterials, (Material material) => (Object)(object)material != (Object)null && ((Object)material).name.StartsWith("stake", StringComparison.OrdinalIgnoreCase)) ? 1 : 0)); if ((num4 != 0 || !(text != "dvergrtown_wood_stake")) && (num4 > num || (num4 == num && sharedMesh.vertexCount > mesh.vertexCount))) { mesh = sharedMesh; materials = sharedMaterials; source = text; num = num4; } } } if ((Object)(object)mesh != (Object)null) { break; } } } private static Material FindTierMetal(ZNetScene scene, int tier) { object obj; switch (tier) { case 1: return null; default: obj = "BlackMetal"; break; case 3: obj = "Iron"; break; case 2: obj = "Bronze"; break; } string text = (string)obj; GameObject prefab = scene.GetPrefab(text); Material val = null; if ((Object)(object)prefab != (Object)null) { MeshRenderer[] componentsInChildren = prefab.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val2 in componentsInChildren) { Material[] sharedMaterials = ((Renderer)val2).sharedMaterials; foreach (Material val3 in sharedMaterials) { if (!((Object)(object)val3 == (Object)null)) { if ((Object)(object)val == (Object)null) { val = val3; } if (((Object)val3).name.Equals(text, StringComparison.OrdinalIgnoreCase)) { return val3; } } } } } if ((Object)(object)val == (Object)null) { Debug.LogWarning((object)("FishTrap: no " + text + " material found for stake bands.")); } return val; } private static void MakeStickTrap(GameObject trap, int tier, Mesh stakeMesh, Material[] stakeMaterials, Material bandMetal) { //IL_008f: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: 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_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0141: 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_0169: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_049c: Unknown result type (might be due to invalid IL or missing references) //IL_04a1: Unknown result type (might be due to invalid IL or missing references) //IL_04ab: Unknown result type (might be due to invalid IL or missing references) //IL_04b0: Unknown result type (might be due to invalid IL or missing references) //IL_04b9: Unknown result type (might be due to invalid IL or missing references) //IL_04be: Unknown result type (might be due to invalid IL or missing references) //IL_04c8: Unknown result type (might be due to invalid IL or missing references) //IL_04cd: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_0333: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) //IL_04fc: Unknown result type (might be due to invalid IL or missing references) //IL_0501: Unknown result type (might be due to invalid IL or missing references) //IL_050b: Unknown result type (might be due to invalid IL or missing references) //IL_0510: Unknown result type (might be due to invalid IL or missing references) //IL_0519: Unknown result type (might be due to invalid IL or missing references) //IL_051e: Unknown result type (might be due to invalid IL or missing references) //IL_0528: Unknown result type (might be due to invalid IL or missing references) //IL_052d: Unknown result type (might be due to invalid IL or missing references) //IL_0442: Unknown result type (might be due to invalid IL or missing references) //IL_037b: Unknown result type (might be due to invalid IL or missing references) //IL_0384: Unknown result type (might be due to invalid IL or missing references) //IL_0392: Unknown result type (might be due to invalid IL or missing references) //IL_0397: Unknown result type (might be due to invalid IL or missing references) //IL_03d4: Unknown result type (might be due to invalid IL or missing references) //IL_03d9: Unknown result type (might be due to invalid IL or missing references) //IL_03e0: Unknown result type (might be due to invalid IL or missing references) //IL_03e5: Unknown result type (might be due to invalid IL or missing references) //IL_03ea: Unknown result type (might be due to invalid IL or missing references) //IL_03f2: Unknown result type (might be due to invalid IL or missing references) //IL_03f6: Unknown result type (might be due to invalid IL or missing references) //IL_0400: Unknown result type (might be due to invalid IL or missing references) //IL_0405: Unknown result type (might be due to invalid IL or missing references) //IL_040a: Unknown result type (might be due to invalid IL or missing references) //IL_040e: Unknown result type (might be due to invalid IL or missing references) //IL_0418: Unknown result type (might be due to invalid IL or missing references) //IL_041d: Unknown result type (might be due to invalid IL or missing references) //IL_058c: Unknown result type (might be due to invalid IL or missing references) //IL_0591: Unknown result type (might be due to invalid IL or missing references) //IL_059b: Unknown result type (might be due to invalid IL or missing references) //IL_05a0: Unknown result type (might be due to invalid IL or missing references) //IL_05a9: Unknown result type (might be due to invalid IL or missing references) //IL_05ae: Unknown result type (might be due to invalid IL or missing references) //IL_05b8: Unknown result type (might be due to invalid IL or missing references) //IL_05bd: Unknown result type (might be due to invalid IL or missing references) MeshRenderer[] componentsInChildren = trap.GetComponentsInChildren<MeshRenderer>(true); Material wood = ((componentsInChildren.Length > 0) ? ((Renderer)componentsInChildren[0]).sharedMaterial : null); MeshRenderer[] array = componentsInChildren; foreach (MeshRenderer val in array) { ((Renderer)val).enabled = false; } Collider[] componentsInChildren2 = trap.GetComponentsInChildren<Collider>(true); foreach (Collider val2 in componentsInChildren2) { Object.DestroyImmediate((Object)(object)val2); } List<Vector3> list = new List<Vector3>(); AddCurve(list, new Vector3(-0.22f, 0f, 0.23f), new Vector3(-0.38f, 0f, -0.1f), new Vector3(-0.95f, 0f, 0.19f), new Vector3(-0.88f, 0f, 0.35f), 3); AddCurve(list, new Vector3(-0.88f, 0f, 0.35f), new Vector3(-0.88f, 0f, 0.68f), new Vector3(-0.52f, 0f, 1.02f), new Vector3(0f, 0f, 1.02f), 5); AddCurve(list, new Vector3(0f, 0f, 1.02f), new Vector3(0.52f, 0f, 1.02f), new Vector3(0.88f, 0f, 0.68f), new Vector3(0.88f, 0f, 0.35f), 5); AddCurve(list, new Vector3(0.88f, 0f, 0.35f), new Vector3(0.95f, 0f, 0.19f), new Vector3(0.38f, 0f, -0.1f), new Vector3(0.22f, 0f, 0.23f), 3); int count = list.Count; for (int j = -1; j <= 1; j += 2) { Vector3 a = list[(j >= 0) ? (count - 1) : 0]; for (int k = 1; k <= 2; k++) { list.Add(Curve(a, new Vector3((float)j * 0.25f, 0f, -0.1f), new Vector3((float)j * 0.43f, 0f, -0.25f), new Vector3((float)j * 0.54f, 0f, -0.34f), (float)k / 2f)); } } Vector3 val4 = default(Vector3); for (int k = 0; k < list.Count; k++) { float num = 0.82f + (float)(k % 4) * 0.08f; float num2 = ((k == 0) ? (-3f) : ((k == count - 1) ? 3f : 0f)); float num3 = (((Object)(object)stakeMesh == (Object)null) ? ((float)(k % 3 - 1) * 0.04f) : 0f) - num * Mathf.Sin(num2 * ((float)Math.PI / 180f)); CapsuleCollider val3 = trap.AddComponent<CapsuleCollider>(); val3.center = list[k] + new Vector3(num3 * 0.5f, num * 0.5f, 0f); val3.height = num; val3.radius = StakeRadius(stakeMesh, num); if ((Object)(object)stakeMesh == (Object)null) { Beam(trap.transform, list[k], list[k] + new Vector3(num3, num, 0f), 0.045f, wood); if ((Object)(object)bandMetal != (Object)null) { ((Vector3)(ref val4))..ctor(num3, num, 0f); Vector3 val5 = list[k] + val4 * 0.6f; Beam(trap.transform, val5 - ((Vector3)(ref val4)).normalized * 0.0275f, val5 + ((Vector3)(ref val4)).normalized * 0.0275f, 0.051f, bandMetal, "Metal band"); } } else { Stake(trap.transform, list[k], num, k, num2, stakeMesh, stakeMaterials, bandMetal); } } if ((Object)(object)stakeMesh != (Object)null) { return; } for (int k = 1; k < count; k++) { Beam(trap.transform, list[k - 1] + Vector3.up * 0.24f, list[k] + Vector3.up * 0.24f, 0.027f, wood); if (tier > 1) { Beam(trap.transform, list[k - 1] + Vector3.up * 0.65f, list[k] + Vector3.up * 0.65f, 0.025f, wood); } } for (int j = 0; j < 2; j++) { int index = ((j != 0) ? (count - 1) : 0); for (int k = 0; k < 2; k++) { int num4 = count + j * 2 + k; Beam(trap.transform, list[index] + Vector3.up * 0.3f, list[num4] + Vector3.up * 0.3f, 0.027f, wood); index = num4; } } } private static void AddCurve(List<Vector3> points, Vector3 a, Vector3 b, Vector3 c, Vector3 d, int steps) { //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) //IL_0014: 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_001d: Unknown result type (might be due to invalid IL or missing references) for (int i = ((points.Count != 0) ? 1 : 0); i <= steps; i++) { points.Add(Curve(a, b, c, d, (float)i / (float)steps)); } } private static Vector3 Curve(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float t) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) float num = 1f - t; return a * (num * num * num) + b * (3f * num * num * t) + c * (3f * num * t * t) + d * (t * t * t); } private static float StakeRadius(Mesh mesh, float height) { //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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)mesh == (Object)null) { return 0.045f; } Bounds bounds = mesh.bounds; Vector3 size = ((Bounds)(ref bounds)).size; float num = Mathf.Max(size.x, Mathf.Max(size.y, size.z)); float num2 = ((size.x == num) ? Mathf.Max(size.y, size.z) : ((size.y == num) ? Mathf.Max(size.x, size.z) : Mathf.Max(size.x, size.y))); return Mathf.Max(0.045f, Mathf.Min(height * num2 / num, 0.16f) * 0.5f); } private static void Stake(Transform parent, Vector3 at, float height, int index, float inwardAngle, Mesh mesh, Material[] materials, Material bandMetal) { //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_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005a: 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_00e2: 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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_0178: 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_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02d5: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Expected O, but got Unknown //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_033b: Unknown result type (might be due to invalid IL or missing references) //IL_0340: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_0383: Unknown result type (might be due to invalid IL or missing references) //IL_0386: Unknown result type (might be due to invalid IL or missing references) //IL_038b: Unknown result type (might be due to invalid IL or missing references) //IL_0390: Unknown result type (might be due to invalid IL or missing references) //IL_03c3: Unknown result type (might be due to invalid IL or missing references) //IL_03c4: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_03e6: Unknown result type (might be due to invalid IL or missing references) //IL_03f8: Unknown result type (might be due to invalid IL or missing references) //IL_03f9: Unknown result type (might be due to invalid IL or missing references) //IL_0443: Unknown result type (might be due to invalid IL or missing references) Bounds bounds = mesh.bounds; Quaternion val = Quaternion.identity; Vector3 center = ((Bounds)(ref bounds)).center; float num = ((Bounds)(ref bounds)).min.y; float num2 = ((Bounds)(ref bounds)).size.y; if (((Bounds)(ref bounds)).size.x > ((Bounds)(ref bounds)).size.y && ((Bounds)(ref bounds)).size.x >= ((Bounds)(ref bounds)).size.z) { val = Quaternion.Euler(0f, 0f, 90f); ((Vector3)(ref center))..ctor(0f - ((Bounds)(ref bounds)).center.y, ((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).center.z); num = ((Bounds)(ref bounds)).min.x; num2 = ((Bounds)(ref bounds)).size.x; } else if (((Bounds)(ref bounds)).size.z > ((Bounds)(ref bounds)).size.y) { val = Quaternion.Euler(-90f, 0f, 0f); ((Vector3)(ref center))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).center.z, 0f - ((Bounds)(ref bounds)).center.y); num = ((Bounds)(ref bounds)).min.z; num2 = ((Bounds)(ref bounds)).size.z; } float num3 = height / num2; float num4 = ((((Bounds)(ref bounds)).size.x > ((Bounds)(ref bounds)).size.y && ((Bounds)(ref bounds)).size.x >= ((Bounds)(ref bounds)).size.z) ? Mathf.Max(((Bounds)(ref bounds)).size.y, ((Bounds)(ref bounds)).size.z) : ((((Bounds)(ref bounds)).size.z > ((Bounds)(ref bounds)).size.y) ? Mathf.Max(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.y) : Mathf.Max(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.z))); float num5 = Mathf.Min(num3, 0.16f / num4); Vector3 localScale = default(Vector3); ((Vector3)(ref localScale))..ctor(num5, num5, num5); if (((Bounds)(ref bounds)).size.x > ((Bounds)(ref bounds)).size.y && ((Bounds)(ref bounds)).size.x >= ((Bounds)(ref bounds)).size.z) { localScale.x = num3; } else if (((Bounds)(ref bounds)).size.z > ((Bounds)(ref bounds)).size.y) { localScale.z = num3; } else { localScale.y = num3; } Quaternion val2 = Quaternion.Euler(0f, 0f, inwardAngle) * Quaternion.Euler(0f, (float)index * 137f, 0f); GameObject val3 = new GameObject("Valheim stake"); val3.transform.SetParent(parent, false); val3.transform.localRotation = val2 * val; val3.transform.localScale = localScale; val3.transform.localPosition = at + val2 * new Vector3((0f - center.x) * num5, (0f - num) * num3, (0f - center.z) * num5); val3.AddComponent<MeshFilter>().sharedMesh = mesh; ((Renderer)val3.AddComponent<MeshRenderer>()).sharedMaterials = materials; if ((Object)(object)bandMetal != (Object)null) { Vector3 val4 = val * ((Bounds)(ref bounds)).size; GameObject val5 = GameObject.CreatePrimitive((PrimitiveType)2); ((Object)val5).name = "Metal band"; val5.transform.SetParent(val3.transform, false); val5.transform.localPosition = Quaternion.Inverse(val) * new Vector3(center.x, num + num2 * 0.6f, center.z); val5.transform.localRotation = Quaternion.Inverse(val); val5.transform.localScale = new Vector3(Mathf.Abs(val4.x) + 0.012f / num5, 0.055f / (2f * num3), Mathf.Abs(val4.z) + 0.012f / num5); ((Renderer)val5.GetComponent<MeshRenderer>()).sharedMaterial = bandMetal; Object.DestroyImmediate((Object)(object)val5.GetComponent<Collider>()); } } private static void Beam(Transform parent, Vector3 from, Vector3 to, float radius, Material wood, string name = "stake") { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_0082: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive((PrimitiveType)2); ((Object)val).name = name; val.transform.SetParent(parent, false); val.transform.localPosition = (from + to) * 0.5f; val.transform.localRotation = Quaternion.FromToRotation(Vector3.up, to - from); Transform transform = val.transform; float num = radius * 2f; Vector3 val2 = to - from; transform.localScale = new Vector3(num, ((Vector3)(ref val2)).magnitude * 0.5f, radius * 2f); if ((Object)(object)wood != (Object)null) { ((Renderer)val.GetComponent<MeshRenderer>()).sharedMaterial = wood; } Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>()); } internal static bool HasEnoughWater(Vector3 groundPosition) { //IL_0003: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) WaterVolume val = null; Vector3 val2 = groundPosition + Vector3.up * 0.25f; float num = Floating.GetWaterLevel(val2, ref val); if ((Object)(object)val != (Object)null) { num = val.GetWaterSurface(val2, 0f); } return num - groundPosition.y >= 0.25f; } } public sealed class FishTrap : MonoBehaviour, Interactable, Hoverable { private sealed class BaitRule { public readonly string Bait; public readonly string Name; public readonly int Tier; public readonly string[] Fish; public BaitRule(string bait, string name, int tier, params string[] fish) { Bait = bait; Name = name; Tier = tier; Fish = fish; } } private const string BaitKey = "fishtrap_bait"; private const string BaitCountKey = "fishtrap_bait_count"; private const string FishKey = "fishtrap_fish"; private const string TimeKey = "fishtrap_time"; private const string HarvestRpc = "FishTrap_Harvest"; private const string AddBaitRpc = "FishTrap_AddBait"; private static readonly FieldInfo RpcFunctions = AccessTools.Field(typeof(ZNetView), "m_functions"); private static readonly MethodInfo WearAwake = AccessTools.Method(typeof(WearNTear), "Awake", (Type[])null, (Type[])null); private static readonly string[] WearRpcs = new string[7] { "RPC_Damage", "RPC_Remove", "RPC_Repair", "RPC_HealthChanged", "RPC_ClearCachedSupport", "RPC_SetSnow", "RPC_CreateFragments" }; private static readonly BaitRule[] Rules = new BaitRule[9] { new BaitRule("FishingBait", "Fishing Bait", 1, "Fish1", "Fish2"), new BaitRule("FishingBaitForest", "Mossy Bait", 2, "Fish5"), new BaitRule("FishingBaitSwamp", "Sticky Bait", 2, "Fish6"), new BaitRule("FishingBaitCave", "Cold Bait", 2, "Fish4_cave"), new BaitRule("FishingBaitPlains", "Stingy Bait", 3, "Fish7"), new BaitRule("FishingBaitOcean", "Heavy Bait", 3, "Fish3", "Fish8"), new BaitRule("FishingBaitMistlands", "Misty Bait", 3, "Fish9", "Fish12"), new BaitRule("FishingBaitAshlands", "Hot Bait", 4, "Fish11"), new BaitRule("FishingBaitDeepNorth", "Frosty Bait", 4, "Fish10") }; public int Tier; private ZNetView view; private bool networkInitialized; private string hoverText; private float nextHoverUpdate; private void Awake() { view = ((Component)this).GetComponent<ZNetView>(); InitializeNetwork(); } private void Start() { InitializeNetwork(); if (!((Object)(object)view == (Object)null) && view.IsValid()) { RestoreWearInitialization(); if (!FishTrapPlugin.ConfigurePiece(((Component)this).GetComponent<Piece>(), Tier)) { ((MonoBehaviour)this).InvokeRepeating("InitializePiece", 1f, 1f); } } } private void InitializeNetwork() { if (!networkInitialized && !((Object)(object)view == (Object)null) && view.IsValid()) { view.Register<bool>("FishTrap_Harvest", (Action<long, bool>)RPC_Harvest); view.Register<string, int>("FishTrap_AddBait", (Action<long, string, int>)RPC_AddBait); ((MonoBehaviour)this).InvokeRepeating("Tick", 5f, 10f); networkInitialized = true; } } private void InitializePiece() { if ((Object)(object)view == (Object)null || !view.IsValid() || FishTrapPlugin.ConfigurePiece(((Component)this).GetComponent<Piece>(), Tier)) { ((MonoBehaviour)this).CancelInvoke("InitializePiece"); } } private void RestoreWearInitialization() { WearNTear component = ((Component)this).GetComponent<WearNTear>(); IDictionary dictionary = ((RpcFunctions == null) ? null : (RpcFunctions.GetValue(view) as IDictionary)); if ((Object)(object)component == (Object)null || dictionary == null || WearAwake == null) { Debug.LogWarning((object)("FishTrap: could not verify native damage/removal initialization for " + ((Object)this).name)); return; } int num = 0; string[] wearRpcs = WearRpcs; foreach (string text in wearRpcs) { if (dictionary.Contains(StringExtensionMethods.GetStableHashCode(text))) { num++; } } if (num == 0 && !WearNTear.GetAllInstances().Contains(component)) { WearAwake.Invoke(component, null); Debug.LogWarning((object)("FishTrap: restored missing native damage/removal handlers for " + ((Object)this).name)); } else if (!dictionary.Contains(StringExtensionMethods.GetStableHashCode("RPC_Damage")) || !dictionary.Contains(StringExtensionMethods.GetStableHashCode("RPC_Remove"))) { Debug.LogWarning((object)("FishTrap: incomplete native damage/removal handlers for " + ((Object)this).name)); } } private static BaitRule FindRule(string bait) { BaitRule[] rules = Rules; foreach (BaitRule baitRule in rules) { if (baitRule.Bait == bait) { return baitRule; } } return null; } private static GameObject Item(string name) { return ((Object)(object)ZNetScene.instance == (Object)null) ? null : ZNetScene.instance.GetPrefab(name); } private bool CanInteract() { //IL_0036: Unknown result type (might be due to invalid IL or missing references) return (Object)(object)view != (Object)null && view.IsValid() && view.GetZDO().GetOwner() != 0 && PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false); } private bool IsOwner() { return (Object)(object)view != (Object)null && view.IsValid() && view.IsOwner(); } private bool RequesterInRange(long sender) { //IL_0044: 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) foreach (Player allPlayer in Player.GetAllPlayers()) { ZNetView component = ((Component)allPlayer).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid() && component.GetZDO().GetOwner() == sender && Vector3.Distance(((Component)allPlayer).transform.position, ((Component)this).transform.position) <= allPlayer.m_maxInteractDistance + 1.5f) { return true; } } return false; } private bool InWater() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) return FishTrapPlugin.HasEnoughWater(((Component)this).transform.position); } private void Tick() { if (IsOwner() && !((Object)(object)ZNet.instance == (Object)null)) { Settle(view.GetZDO(), ZNet.instance.GetTime().Ticks); } } private void Settle(ZDO zdo, long now) { long num = zdo.GetLong("fishtrap_time", 0L); int num2 = zdo.GetInt("fishtrap_bait_count", 0); string text = zdo.GetString("fishtrap_fish", ""); int num3 = CatchMath.CountFish(text); string text2 = zdo.GetString("fishtrap_bait", ""); BaitRule baitRule = FindRule(text2); long nextTime; int num4 = CatchMath.Advance(now, num, num2, num3, 4, FishTrapPlugin.CatchInterval, num2 > 0 && num3 < 4 && baitRule != null && baitRule.Tier <= Tier && InWater(), out nextTime); if (num4 > 0) { for (int i = 0; i < num4; i++) { string prefab = baitRule.Fish[Random.Range(0, baitRule.Fish.Length)]; int quality = CatchMath.QualityForRoll(Random.Range(0, 100)); string text3 = CatchMath.EncodeFish(prefab, quality); text = ((text.Length == 0) ? text3 : (text + "," + text3)); } zdo.Set("fishtrap_fish", text); num2 -= num4; zdo.Set("fishtrap_bait_count", num2); } if (num2 <= 0 && text2 != "") { zdo.Set("fishtrap_bait", ""); } if (nextTime != num) { zdo.Set("fishtrap_time", nextTime); } } public string GetHoverName() { return (Tier == 1) ? "Stick Fish Trap" : ("Fish Trap " + Tier); } public float GetHoverOffset() { return 0.5f; } public string GetHoverText() { if ((Object)(object)view == (Object)null || !view.IsValid()) { return GetHoverName(); } float unscaledTime = Time.unscaledTime; if (hoverText != null && unscaledTime < nextHoverUpdate) { return hoverText; } ZDO zDO = view.GetZDO(); string bait = zDO.GetString("fishtrap_bait", ""); BaitRule baitRule = FindRule(bait); int num = zDO.GetInt("fishtrap_bait_count", 0); int num2 = CatchMath.CountFish(zDO.GetString("fishtrap_fish", "")); hoverText = GetHoverName() + "\nBait: " + num + "/20" + ((num == 0 || baitRule == null) ? "" : (" (" + baitRule.Name + ")")) + "\nFish: " + num2 + "/4" + (InWater() ? "" : " - needs at least 0.25m water") + "\n[E] Collect fish / add bait\n[Shift+E] Empty trap"; nextHoverUpdate = unscaledTime + 0.25f; return hoverText; } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold || !CanInteract()) { return false; } ZDO zDO = view.GetZDO(); if (alt || zDO.GetString("fishtrap_fish", "").Length > 0) { view.InvokeRPC("FishTrap_Harvest", new object[1] { alt }); return true; } Inventory inventory = user.GetInventory(); string text = ((zDO.GetInt("fishtrap_bait_count", 0) > 0) ? zDO.GetString("fishtrap_bait", "") : ""); foreach (ItemData allItem in inventory.GetAllItems()) { if (!((Object)(object)allItem.m_dropPrefab == (Object)null)) { string name = ((Object)allItem.m_dropPrefab).name; BaitRule baitRule = FindRule(name); if (baitRule != null && baitRule.Tier <= Tier && (text == "" || text == name)) { return OfferBait(inventory, allItem, zDO); } } } return false; } public bool UseItem(Humanoid user, ItemData item) { return CanInteract() && OfferBait(user.GetInventory(), item, view.GetZDO()); } private bool OfferBait(Inventory inventory, ItemData item, ZDO zdo) { if (item == null || (Object)(object)item.m_dropPrefab == (Object)null) { return false; } string name = ((Object)item.m_dropPrefab).name; BaitRule baitRule = FindRule(name); if (baitRule == null || baitRule.Tier > Tier) { return false; } int stored = zdo.GetInt("fishtrap_bait_count", 0); int num = CatchMath.AcceptBait(zdo.GetString("fishtrap_bait", ""), stored, name, item.m_stack, 20); if (num <= 0 || !inventory.RemoveItem(item, num)) { return false; } view.InvokeRPC("FishTrap_AddBait", new object[2] { name, num }); return true; } private void RPC_Harvest(long sender, bool empty) { if (IsOwner() && !((Object)(object)ZNet.instance == (Object)null) && RequesterInRange(sender)) { ZDO zDO = view.GetZDO(); long ticks = ZNet.instance.GetTime().Ticks; Settle(zDO, ticks); Collect(zDO); if (empty) { ReturnBait(zDO); } Settle(zDO, ticks); } } private void RPC_AddBait(long sender, string name, int amount) { if (!IsOwner() || (Object)(object)ZNet.instance == (Object)null || amount <= 0 || amount > 20) { return; } BaitRule baitRule = FindRule(name); if (baitRule != null) { ZDO zDO = view.GetZDO(); long ticks = ZNet.instance.GetTime().Ticks; Settle(zDO, ticks); int num = zDO.GetInt("fishtrap_bait_count", 0); int num2 = ((baitRule.Tier <= Tier && RequesterInRange(sender)) ? CatchMath.AcceptBait(zDO.GetString("fishtrap_bait", ""), num, name, amount, 20) : 0); if (num2 > 0) { zDO.Set("fishtrap_bait", name); zDO.Set("fishtrap_bait_count", num + num2); } if (num2 < amount) { Drop(name, amount - num2); } Settle(zDO, ticks); } } private bool Collect(ZDO zdo) { string text = zdo.GetString("fishtrap_fish", ""); if (text.Length == 0) { return false; } List<string> list = new List<string>(text.Split(new char[1] { ',' })); bool result = false; for (int num = list.Count - 1; num >= 0; num--) { if (CatchMath.TryReadFish(list[num], out var prefab, out var quality) && Drop(prefab, 1, (float)num * 0.25f, quality)) { list.RemoveAt(num); zdo.Set("fishtrap_fish", string.Join(",", list.ToArray())); result = true; } } return result; } private bool ReturnBait(ZDO zdo) { int num = zdo.GetInt("fishtrap_bait_count", 0); if (num <= 0) { if (zdo.GetString("fishtrap_bait", "") != "") { zdo.Set("fishtrap_bait", ""); } return false; } if (!Drop(zdo.GetString("fishtrap_bait", ""), num)) { return false; } zdo.Set("fishtrap_bait_count", 0); zdo.Set("fishtrap_bait", ""); return true; } public void DropContents() { if (IsOwner()) { ZDO zDO = view.GetZDO(); if ((Object)(object)ZNet.instance != (Object)null) { Settle(zDO, ZNet.instance.GetTime().Ticks); } Collect(zDO); ReturnBait(zDO); if (zDO.GetLong("fishtrap_time", 0L) != 0) { zDO.Set("fishtrap_time", 0L); } } } private bool Drop(string name, int amount, float heightOffset = 0f, int quality = 1) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_008f: 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_0099: 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_009f: Unknown result type (might be due to invalid IL or missing references) if (amount <= 0) { return false; } GameObject val = Item(name); ItemDrop val2 = (((Object)(object)val == (Object)null) ? null : val.GetComponent<ItemDrop>()); if ((Object)(object)val2 == (Object)null) { return false; } ItemData val3 = val2.m_itemData.Clone(); val3.m_dropPrefab = val; val3.m_quality = quality; Vector2 val4 = Random.insideUnitCircle * 0.2f; Vector3 val5 = ((Component)this).transform.TransformPoint(new Vector3(val4.x, 1.25f + heightOffset, 0.5f + val4.y)); return (Object)(object)ItemDrop.DropItem(val3, amount, val5, Quaternion.identity) != (Object)null; } } internal static class CatchMath { internal static int QualityForRoll(int roll) { if (roll < 0 || roll >= 100) { throw new ArgumentOutOfRangeException("roll"); } if (roll < 50) { return 1; } if (roll < 75) { return 2; } if (roll < 89) { return 3; } if (roll < 97) { return 4; } return 5; } internal static string EncodeFish(string prefab, int quality) { if (quality < 1 || quality > 5) { throw new ArgumentOutOfRangeException("quality"); } if (string.IsNullOrWhiteSpace(prefab) || prefab.IndexOf(':') >= 0 || prefab.IndexOf(',') >= 0) { throw new ArgumentException("Invalid fish prefab name", "prefab"); } return prefab + ":" + quality; } internal static bool TryReadFish(string stored, out string prefab, out int quality) { prefab = null; quality = 1; if (string.IsNullOrWhiteSpace(stored) || stored.IndexOf(',') >= 0) { return false; } int num = stored.IndexOf(':'); if (num < 0) { prefab = stored; return true; } if (num == 0 || stored.Length != num + 2 || stored[num + 1] < '1' || stored[num + 1] > '5' || string.IsNullOrWhiteSpace(stored.Substring(0, num))) { return false; } prefab = stored.Substring(0, num); quality = stored[num + 1] - 48; return true; } internal static int CountFish(string stored) { if (stored.Length == 0) { return 0; } int num = 1; for (int i = 0; i < stored.Length; i++) { if (stored[i] == ',') { num++; } } return num; } internal static int AcceptBait(string loaded, int stored, string offered, int amount, int capacity) { if (stored < 0 || stored >= capacity || amount <= 0 || string.IsNullOrEmpty(offered) || (stored > 0 && loaded != offered)) { return 0; } return Math.Min(amount, capacity - stored); } internal static int Advance(long now, long last, int bait, int fish, int capacity, long interval, bool enabled, out long nextTime) { nextTime = 0L; if (!enabled || bait <= 0 || fish >= capacity || interval <= 0) { return 0; } if (last <= 0 || last > now) { nextTime = now; return 0; } int num = Ready(now, last, bait, fish, capacity, interval); if (num < bait && fish + num < capacity) { nextTime = last + num * interval; } return num; } internal static int Ready(long now, long last, int bait, int fish, int capacity, long interval) { if (last <= 0 || now < last || bait <= 0 || fish >= capacity || interval <= 0) { return 0; } return (int)Math.Min(Math.Min(capacity - fish, bait), (now - last) / interval); } }