using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("RavenwoodToys")] [assembly: AssemblyDescription("A Valheim mod that adds interactive Ravenwood toys.")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Caenos")] [assembly: AssemblyProduct("Ravenwood Toys")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e0a8f6d4-7e9e-4d49-8e68-295305083162")] [assembly: AssemblyFileVersion("1.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] namespace Ravenwood.Toys; [DisallowMultipleComponent] public class ElephantKeyInteract : MonoBehaviour, Hoverable, Interactable { private sealed class BulbMaterialState { public Material Material; public string ColorProperty; public Color OriginalColor; public bool HasEmission; public Color OriginalEmission; public bool EmissionKeywordEnabled; public MaterialGlobalIlluminationFlags OriginalGlobalIlluminationFlags; } private sealed class BulbLightState { public Light Light; public bool OriginalEnabled; public Color OriginalColor; public float OriginalIntensity; } private const string KeyRpcName = "RavenwoodToys_TurnElephantKey"; private const string InteractionObjectName = "ElephantKeyInteraction"; private const float DegreesPerSecond = 18f; private const float FullTurn = 360f; private const float RainbowCyclesPerSecond = 0.12f; private const float BlinkCyclesPerSecond = 0.35f; private const float EmissionIntensity = 1.5f; private const float DefaultLightRange = 3f; private const float DefaultLightIntensity = 1.8f; private static GameObject elephantSoundPrefab; private static GameObject eggSoundPrefab; private Piece piece; private ZNetView networkView; private Transform keyPivot; private Quaternion restLocalRotation; private Vector3 rotationAxis = Vector3.forward; private float degreesTravelled; private float bulbElapsed; private float lastStartTime = -100f; private BulbMaterialState[] bulbMaterials = new BulbMaterialState[0]; private BulbLightState[] bulbLights = new BulbLightState[0]; private bool interactionReady; private bool isMoving; public static void ConfigureElephantSound(GameObject soundPrefab) { elephantSoundPrefab = soundPrefab; } public static void ConfigureEggSound(GameObject soundPrefab) { eggSoundPrefab = soundPrefab; } private void Awake() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0084: 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) piece = ((Component)this).GetComponent(); networkView = ((Component)this).GetComponent(); rotationAxis = (((Object)this).name.StartsWith("RWtoys_Robot_Egg", StringComparison.OrdinalIgnoreCase) ? Vector3.right : Vector3.forward); Transform val = FindDeepChild(((Component)this).transform, "TrackCenter"); keyPivot = (((Object)(object)val != (Object)null) ? FindDeepChild(val, "Sphere") : null); if ((Object)(object)keyPivot != (Object)null) { restLocalRotation = keyPivot.localRotation; } else { Debug.LogWarning((object)("[Ravenwood Toys] TrackCenter/Sphere was not found on: " + ((Object)this).name)); } SetupBulb(); if ((Object)(object)networkView != (Object)null) { networkView.Register("RavenwoodToys_TurnElephantKey", (Action)RpcTurnKey); } } private void Update() { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) if (!interactionReady) { TryCreateInteractionTarget(); } if (isMoving && !((Object)(object)keyPivot == (Object)null)) { degreesTravelled = Mathf.Min(degreesTravelled + 18f * Time.deltaTime, 360f); keyPivot.localRotation = restLocalRotation * Quaternion.AngleAxis(0f - degreesTravelled, rotationAxis); UpdateRainbowBulb(Time.deltaTime); if (degreesTravelled >= 360f) { StopKey(); } } } private void TryCreateInteractionTarget() { //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown if ((Object)(object)networkView == (Object)null || !networkView.IsValid()) { return; } Transform val = ((Component)this).transform.Find("ElephantKeyInteraction"); if ((Object)(object)val != (Object)null) { ElephantKeyInteractionProxy elephantKeyInteractionProxy = ((Component)val).GetComponent(); if ((Object)(object)elephantKeyInteractionProxy == (Object)null) { elephantKeyInteractionProxy = ((Component)val).gameObject.AddComponent(); } elephantKeyInteractionProxy.Configure(this); interactionReady = true; return; } GameObject val2 = new GameObject("ElephantKeyInteraction"); val2.transform.SetParent(((Component)this).transform, false); int num = LayerMask.NameToLayer("piece_nonsolid"); if (num < 0) { num = LayerMask.NameToLayer("piece"); } val2.layer = ((num >= 0) ? num : ((Component)this).gameObject.layer); BoxCollider val3 = val2.AddComponent(); ((Collider)val3).isTrigger = false; ApplyInteractionBounds(val3); ElephantKeyInteractionProxy elephantKeyInteractionProxy2 = val2.AddComponent(); elephantKeyInteractionProxy2.Configure(this); interactionReady = true; } private void ApplyInteractionBounds(BoxCollider interactionCollider) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: 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_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: 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) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)interactionCollider == (Object)null) { return; } Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren(true); bool flag = false; Vector3 val = Vector3.zero; Vector3 val2 = Vector3.zero; foreach (Renderer val3 in componentsInChildren) { if ((Object)(object)val3 == (Object)null) { continue; } Bounds bounds = val3.bounds; for (int j = -1; j <= 1; j += 2) { for (int k = -1; k <= 1; k += 2) { for (int l = -1; l <= 1; l += 2) { Vector3 val4 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)j, (float)k, (float)l)); Vector3 val5 = ((Component)this).transform.InverseTransformPoint(val4); if (!flag) { val = val5; val2 = val5; flag = true; } else { val = Vector3.Min(val, val5); val2 = Vector3.Max(val2, val5); } } } } } if (!flag) { interactionCollider.center = new Vector3(0f, 0.5f, 0f); interactionCollider.size = new Vector3(2f, 2f, 2f); } else { interactionCollider.center = (val + val2) * 0.5f; interactionCollider.size = val2 - val + new Vector3(0.2f, 0.2f, 0.2f); } } private void OnDisable() { StopKey(); } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold || (Object)(object)keyPivot == (Object)null || isMoving) { return false; } StartKey(); if ((Object)(object)networkView != (Object)null && networkView.IsValid()) { networkView.InvokeRPC(ZNetView.Everybody, "RavenwoodToys_TurnElephantKey", Array.Empty()); } return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } public string GetHoverText() { if (isMoving) { return GetHoverName() + "\nKey is turning"; } return GetHoverName() + "\n[E] Wind key"; } public string GetHoverName() { return ((Object)(object)piece != (Object)null && !string.IsNullOrWhiteSpace(piece.m_name)) ? piece.m_name : "Wind-Up Elephant"; } private void RpcTurnKey(long sender) { if (!isMoving && Time.time - lastStartTime > 0.1f) { StartKey(); } } private void StartKey() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)keyPivot == (Object)null) && !isMoving) { keyPivot.localRotation = restLocalRotation; degreesTravelled = 0f; bulbElapsed = 0f; lastStartTime = Time.time; isMoving = true; PlayElephantSound(); PlayEggSound(); } } private void PlayElephantSound() { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) if (!((Object)this).name.StartsWith("RWtoys_Robot_Egg", StringComparison.OrdinalIgnoreCase) && !((Object)(object)elephantSoundPrefab == (Object)null) && !((Object)(object)keyPivot == (Object)null)) { GameObject val = Object.Instantiate(elephantSoundPrefab, keyPivot.position, Quaternion.identity); AudioSource component = val.GetComponent(); if ((Object)(object)component != (Object)null) { component.Stop(); component.playOnAwake = false; component.loop = false; component.Play(); Object.Destroy((Object)(object)val, ((Object)(object)component.clip != (Object)null) ? (component.clip.length + 0.1f) : 21f); } else { Object.Destroy((Object)(object)val, 21f); } } } private void PlayEggSound() { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) if (((Object)this).name.StartsWith("RWtoys_Robot_Egg", StringComparison.OrdinalIgnoreCase) && !((Object)(object)eggSoundPrefab == (Object)null) && !((Object)(object)keyPivot == (Object)null)) { GameObject val = Object.Instantiate(eggSoundPrefab, keyPivot.position, Quaternion.identity); AudioSource component = val.GetComponent(); if ((Object)(object)component != (Object)null) { component.Stop(); component.playOnAwake = false; component.loop = false; component.Play(); Object.Destroy((Object)(object)val, ((Object)(object)component.clip != (Object)null) ? (component.clip.length + 0.1f) : 21f); } else { Object.Destroy((Object)(object)val, 21f); } } } private void StopKey() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)keyPivot != (Object)null) { keyPivot.localRotation = restLocalRotation; } degreesTravelled = 0f; bulbElapsed = 0f; isMoving = false; RestoreBulb(); } private void SetupBulb() { //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: 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) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) Transform val = FindDeepChild(((Component)this).transform, "Bulb"); if ((Object)(object)val == (Object)null) { return; } List list = new List(); HashSet hashSet = new HashSet(); Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren(true); foreach (Renderer val2 in componentsInChildren) { if ((Object)(object)val2 == (Object)null) { continue; } Material[] materials = val2.materials; foreach (Material val3 in materials) { if (!((Object)(object)val3 == (Object)null) && hashSet.Add(val3)) { string text = null; if (val3.HasProperty("_Color")) { text = "_Color"; } else if (val3.HasProperty("_BaseColor")) { text = "_BaseColor"; } bool flag = val3.HasProperty("_EmissionColor"); list.Add(new BulbMaterialState { Material = val3, ColorProperty = text, OriginalColor = ((text != null) ? val3.GetColor(text) : Color.white), HasEmission = flag, OriginalEmission = (flag ? val3.GetColor("_EmissionColor") : Color.black), EmissionKeywordEnabled = val3.IsKeywordEnabled("_EMISSION"), OriginalGlobalIlluminationFlags = val3.globalIlluminationFlags }); } } } bulbMaterials = list.ToArray(); Light[] array = ((Component)val).GetComponentsInChildren(true); if (array.Length == 0) { Light val4 = ((Component)val).gameObject.AddComponent(); val4.type = (LightType)2; val4.range = 3f; val4.intensity = 0f; val4.shadows = (LightShadows)0; ((Behaviour)val4).enabled = false; array = (Light[])(object)new Light[1] { val4 }; } bulbLights = new BulbLightState[array.Length]; for (int k = 0; k < array.Length; k++) { Light val5 = array[k]; bulbLights[k] = new BulbLightState { Light = val5, OriginalEnabled = ((Object)(object)val5 != (Object)null && ((Behaviour)val5).enabled), OriginalColor = (((Object)(object)val5 != (Object)null) ? val5.color : Color.white), OriginalIntensity = (((Object)(object)val5 != (Object)null) ? val5.intensity : 1f) }; } } private void UpdateRainbowBulb(float deltaTime) { //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_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: 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_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) if (bulbMaterials.Length == 0 && bulbLights.Length == 0) { return; } bulbElapsed += deltaTime; float num = Mathf.Repeat(bulbElapsed * 0.12f, 1f); float num2 = (Mathf.Sin(bulbElapsed * (float)Math.PI * 2f * 0.35f - (float)Math.PI / 2f) + 1f) * 0.5f; float num3 = Mathf.Lerp(0.05f, 1f, num2); Color val = Color.HSVToRGB(num, 1f, 1f); for (int i = 0; i < bulbMaterials.Length; i++) { BulbMaterialState bulbMaterialState = bulbMaterials[i]; if (bulbMaterialState != null && !((Object)(object)bulbMaterialState.Material == (Object)null)) { if (bulbMaterialState.ColorProperty != null) { bulbMaterialState.Material.SetColor(bulbMaterialState.ColorProperty, Color.Lerp(bulbMaterialState.OriginalColor, val, num3)); } if (bulbMaterialState.HasEmission) { bulbMaterialState.Material.EnableKeyword("_EMISSION"); bulbMaterialState.Material.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1; bulbMaterialState.Material.SetColor("_EmissionColor", val * 1.5f * num3); } } } for (int j = 0; j < bulbLights.Length; j++) { BulbLightState bulbLightState = bulbLights[j]; if (bulbLightState != null && !((Object)(object)bulbLightState.Light == (Object)null)) { ((Behaviour)bulbLightState.Light).enabled = true; bulbLightState.Light.color = val; bulbLightState.Light.intensity = Mathf.Max(bulbLightState.OriginalIntensity, 1.8f) * num3; } } } private void RestoreBulb() { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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) for (int i = 0; i < bulbMaterials.Length; i++) { BulbMaterialState bulbMaterialState = bulbMaterials[i]; if (bulbMaterialState == null || (Object)(object)bulbMaterialState.Material == (Object)null) { continue; } if (bulbMaterialState.ColorProperty != null) { bulbMaterialState.Material.SetColor(bulbMaterialState.ColorProperty, bulbMaterialState.OriginalColor); } if (bulbMaterialState.HasEmission) { bulbMaterialState.Material.SetColor("_EmissionColor", bulbMaterialState.OriginalEmission); bulbMaterialState.Material.globalIlluminationFlags = bulbMaterialState.OriginalGlobalIlluminationFlags; if (bulbMaterialState.EmissionKeywordEnabled) { bulbMaterialState.Material.EnableKeyword("_EMISSION"); } else { bulbMaterialState.Material.DisableKeyword("_EMISSION"); } } } for (int j = 0; j < bulbLights.Length; j++) { BulbLightState bulbLightState = bulbLights[j]; if (bulbLightState != null && !((Object)(object)bulbLightState.Light == (Object)null)) { ((Behaviour)bulbLightState.Light).enabled = bulbLightState.OriginalEnabled; bulbLightState.Light.color = bulbLightState.OriginalColor; bulbLightState.Light.intensity = bulbLightState.OriginalIntensity; } } } private static Transform FindDeepChild(Transform parent, string childName) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown if ((Object)(object)parent == (Object)null) { return null; } foreach (Transform item in parent) { Transform val = item; if (string.Equals(((Object)val).name, childName, StringComparison.OrdinalIgnoreCase)) { return val; } Transform val2 = FindDeepChild(val, childName); if ((Object)(object)val2 != (Object)null) { return val2; } } return null; } } [DisallowMultipleComponent] public class ElephantKeyInteractionProxy : MonoBehaviour, Hoverable, Interactable { private ElephantKeyInteract elephantKey; private void Awake() { if ((Object)(object)elephantKey == (Object)null) { elephantKey = ((Component)this).GetComponentInParent(); } } public void Configure(ElephantKeyInteract target) { elephantKey = target; } public bool Interact(Humanoid user, bool hold, bool alt) { return (Object)(object)elephantKey != (Object)null && elephantKey.Interact(user, hold, alt); } public bool UseItem(Humanoid user, ItemData item) { return (Object)(object)elephantKey != (Object)null && elephantKey.UseItem(user, item); } public string GetHoverText() { return ((Object)(object)elephantKey != (Object)null) ? elephantKey.GetHoverText() : string.Empty; } public string GetHoverName() { return ((Object)(object)elephantKey != (Object)null) ? elephantKey.GetHoverName() : string.Empty; } } [BepInPlugin("Ravenwood.Toys", "Ravenwood Toys", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class RavenwoodToys : BaseUnityPlugin { public const string PluginGUID = "Ravenwood.Toys"; public const string PluginName = "Ravenwood Toys"; public const string PluginVersion = "1.0.0"; internal static ConfigFile ModConfig; private AssetBundle toysBundle; private Harmony harmony; private bool prefabEventRegistered; private void Awake() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_008c: Unknown result type (might be due to invalid IL or missing references) ModConfig = ((BaseUnityPlugin)this).Config; harmony = new Harmony("Ravenwood.Toys"); harmony.PatchAll(); string platformBundleResourcePath = GetPlatformBundleResourcePath(); toysBundle = EmbeddedAssetBundleLoader.LoadBundle(platformBundleResourcePath); if ((Object)(object)toysBundle == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load embedded AssetBundle: " + platformBundleResourcePath)); return; } ToyRegistrar.InitConfig(((BaseUnityPlugin)this).Config); foreach (string allCategory in ToyRegistrar.GetAllCategories()) { PieceManager.Instance.AddPieceCategory(allCategory); } PrefabManager.OnPrefabsRegistered += OnPrefabsRegistered; prefabEventRegistered = true; } private static string GetPlatformBundleResourcePath() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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_000b: Invalid comparison between Unknown and I4 RuntimePlatform platform = Application.platform; RuntimePlatform val = platform; if ((int)val <= 1) { return "Ravenwood.Toys.ravenwoodtoys_mac"; } return "Ravenwood.Toys.ravenwoodtoys_windows"; } private void OnDestroy() { if (prefabEventRegistered) { PrefabManager.OnPrefabsRegistered -= OnPrefabsRegistered; prefabEventRegistered = false; } if (harmony != null) { harmony.UnpatchSelf(); } } private void OnPrefabsRegistered() { ((MonoBehaviour)this).StartCoroutine(DelayedRegister(toysBundle)); } private IEnumerator DelayedRegister(AssetBundle bundle) { while ((Object)(object)ZNetScene.instance == (Object)null) { yield return null; } ToyRegistrar.RegisterAllToys(bundle); } } public static class EmbeddedAssetBundleLoader { public static AssetBundle LoadBundle(string resourcePath) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); using Stream stream = executingAssembly.GetManifestResourceStream(resourcePath); if (stream == null) { Debug.LogError((object)("AssetBundle resource not found: " + resourcePath)); return null; } using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); return AssetBundle.LoadFromMemory(memoryStream.ToArray()); } } [DisallowMultipleComponent] public class RockingHorseInteract : MonoBehaviour, Hoverable, Interactable { private const string RockRpcName = "RavenwoodToys_RockHorse"; private const string InteractionObjectName = "RockingHorseInteraction"; private static GameObject rockingSoundPrefab; private Piece piece; private ZNetView networkView; private Transform rockingPivot; private Quaternion restLocalRotation; private float elapsed; private float lastStartTime = -100f; private bool interactionReady; private bool isRocking; private bool isYoyo; public static void ConfigureRockingSound(GameObject soundPrefab) { rockingSoundPrefab = soundPrefab; } private void Awake() { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) piece = ((Component)this).GetComponent(); networkView = ((Component)this).GetComponent(); isYoyo = ((Object)this).name.StartsWith("RWtoys_yoyo", StringComparison.OrdinalIgnoreCase); rockingPivot = FindDeepChild(((Component)this).transform, "RockingPivot"); if ((Object)(object)rockingPivot != (Object)null) { restLocalRotation = rockingPivot.localRotation; } else { Debug.LogWarning((object)("[Ravenwood Toys] RockingPivot was not found on: " + ((Object)this).name)); } if ((Object)(object)networkView != (Object)null) { networkView.Register("RavenwoodToys_RockHorse", (Action)RpcRockHorse); } } private void Update() { //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) if (!interactionReady) { TryCreateInteractionTarget(); } if (isRocking && !((Object)(object)rockingPivot == (Object)null)) { elapsed += Time.deltaTime; if (elapsed >= 5f) { StopRocking(); return; } float num = Mathf.Clamp01(elapsed / 5f); float num2 = Mathf.Clamp01(elapsed / 0.2f); float num3 = 1f - num; float num4 = Mathf.Sin(elapsed * (float)Math.PI * 2f * 0.8f) * 8f * num2 * num3; rockingPivot.localRotation = restLocalRotation * Quaternion.AngleAxis(num4, Vector3.forward); } } private void TryCreateInteractionTarget() { //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown if ((Object)(object)networkView == (Object)null || !networkView.IsValid()) { return; } Transform val = ((Component)this).transform.Find("RockingHorseInteraction"); if ((Object)(object)val != (Object)null) { RockingHorseInteractionProxy rockingHorseInteractionProxy = ((Component)val).GetComponent(); if ((Object)(object)rockingHorseInteractionProxy == (Object)null) { rockingHorseInteractionProxy = ((Component)val).gameObject.AddComponent(); } rockingHorseInteractionProxy.Configure(this); interactionReady = true; return; } GameObject val2 = new GameObject("RockingHorseInteraction"); val2.transform.SetParent(((Component)this).transform, false); int num = LayerMask.NameToLayer("piece_nonsolid"); if (num < 0) { num = LayerMask.NameToLayer("piece"); } val2.layer = ((num >= 0) ? num : ((Component)this).gameObject.layer); BoxCollider val3 = val2.AddComponent(); ((Collider)val3).isTrigger = false; ApplyInteractionBounds(val3); RockingHorseInteractionProxy rockingHorseInteractionProxy2 = val2.AddComponent(); rockingHorseInteractionProxy2.Configure(this); interactionReady = true; } private void ApplyInteractionBounds(BoxCollider interactionCollider) { //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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_0162: 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_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0093: 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_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: 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_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)interactionCollider == (Object)null) { return; } Renderer[] array = (((Object)(object)rockingPivot != (Object)null) ? ((Component)rockingPivot).GetComponentsInChildren(true) : ((Component)this).GetComponentsInChildren(true)); bool flag = false; Vector3 val = Vector3.zero; Vector3 val2 = Vector3.zero; foreach (Renderer val3 in array) { if ((Object)(object)val3 == (Object)null) { continue; } Bounds bounds = val3.bounds; for (int j = -1; j <= 1; j += 2) { for (int k = -1; k <= 1; k += 2) { for (int l = -1; l <= 1; l += 2) { Vector3 val4 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)j, (float)k, (float)l)); Vector3 val5 = ((Component)this).transform.InverseTransformPoint(val4); if (!flag) { val = val5; val2 = val5; flag = true; } else { val = Vector3.Min(val, val5); val2 = Vector3.Max(val2, val5); } } } } } if (!flag) { interactionCollider.center = new Vector3(0f, 1f, 0f); interactionCollider.size = new Vector3(2f, 2f, 2f); } else { interactionCollider.center = (val + val2) * 0.5f; interactionCollider.size = val2 - val + new Vector3(0.2f, 0.2f, 0.2f); } } private void OnDisable() { StopRocking(); } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold || (Object)(object)rockingPivot == (Object)null) { return false; } StartRocking(); if ((Object)(object)networkView != (Object)null && networkView.IsValid()) { networkView.InvokeRPC(ZNetView.Everybody, "RavenwoodToys_RockHorse", Array.Empty()); } return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } public string GetHoverText() { return GetHoverName() + (isYoyo ? "\n[E] Wiggle" : "\n[E] Rock"); } public string GetHoverName() { return ((Object)(object)piece != (Object)null && !string.IsNullOrWhiteSpace(piece.m_name)) ? piece.m_name : "Wooden Rocking Horse"; } private void RpcRockHorse(long sender) { if (Time.time - lastStartTime > 0.1f) { StartRocking(); } } private void StartRocking() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)rockingPivot == (Object)null)) { rockingPivot.localRotation = restLocalRotation; elapsed = 0f; lastStartTime = Time.time; isRocking = true; PlayRockingSound(); } } private void PlayRockingSound() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)rockingSoundPrefab == (Object)null) && !((Object)(object)rockingPivot == (Object)null)) { GameObject val = Object.Instantiate(rockingSoundPrefab, rockingPivot.position, Quaternion.identity); AudioSource component = val.GetComponent(); if ((Object)(object)component != (Object)null) { component.Stop(); component.playOnAwake = false; component.loop = false; component.Play(); Object.Destroy((Object)(object)val, ((Object)(object)component.clip != (Object)null) ? (component.clip.length + 0.1f) : 6f); } else { Object.Destroy((Object)(object)val, 6f); } } } private void StopRocking() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)rockingPivot != (Object)null) { rockingPivot.localRotation = restLocalRotation; } elapsed = 0f; isRocking = false; } private static Transform FindDeepChild(Transform parent, string childName) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown if ((Object)(object)parent == (Object)null) { return null; } foreach (Transform item in parent) { Transform val = item; if (string.Equals(((Object)val).name, childName, StringComparison.OrdinalIgnoreCase)) { return val; } Transform val2 = FindDeepChild(val, childName); if ((Object)(object)val2 != (Object)null) { return val2; } } return null; } } [DisallowMultipleComponent] public class RockingHorseInteractionProxy : MonoBehaviour, Hoverable, Interactable { private RockingHorseInteract rockingHorse; private void Awake() { if ((Object)(object)rockingHorse == (Object)null) { rockingHorse = ((Component)this).GetComponentInParent(); } } public void Configure(RockingHorseInteract target) { rockingHorse = target; } public bool Interact(Humanoid user, bool hold, bool alt) { return (Object)(object)rockingHorse != (Object)null && rockingHorse.Interact(user, hold, alt); } public bool UseItem(Humanoid user, ItemData item) { return (Object)(object)rockingHorse != (Object)null && rockingHorse.UseItem(user, item); } public string GetHoverText() { return ((Object)(object)rockingHorse != (Object)null) ? rockingHorse.GetHoverText() : string.Empty; } public string GetHoverName() { return ((Object)(object)rockingHorse != (Object)null) ? rockingHorse.GetHoverName() : string.Empty; } } public class ToyRegistration { public string PrefabName; public string DisplayName; public RequirementConfig[] Requirements; public string Description; public int Comfort; public string CraftingStation; public ToyRegistration(string prefab, string display, RequirementConfig[] reqs, string desc, int comfort = 0, string craftingStation = "piece_workbench") { PrefabName = prefab; DisplayName = display; Requirements = reqs; Description = desc; Comfort = comfort; CraftingStation = craftingStation; } } public static class ToyRegistrar { private static bool wasAlreadyRegistered = false; private const string BoxMoveSoundPrefabName = "sfx_RWtoys_Box_Move"; private const string RockingHorseSoundPrefabName = "sfx_RWtoys_RockingHorse_Creak"; private const string RobotBlueSoundPrefabName = "sfx_RWtoys_Robot_Blue"; private const string ElephantSoundPrefabName = "sfx_RWtoys_Elephant"; private const string EggSoundPrefabName = "sfx_RWtoys_Egg"; private const string PlaneSoundPrefabName = "sfx_RWtoys_Plane"; private const string TrainSoundPrefabName = "sfx_RWtoys_Train"; private const string DefaultHammerTab = "Ravenwood"; private static ConfigEntry hammerTabConfig; private static readonly Dictionary> toyVisibilityConfigs = new Dictionary>(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary> toyComfortConfigs = new Dictionary>(StringComparer.OrdinalIgnoreCase); public static readonly List AllRegistrations = new List { new ToyRegistration("RWtoys_Wooden_Horse", "Wooden Rocking Horse", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 75, 0, true) }, "An interactive wooden rocking horse."), new ToyRegistration("RWtoys_train", "Toy Train", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Wolf", 5, 0, true) }, "An interactive toy train that circles its track."), new ToyRegistration("RWtoys_elephant", "Wind-Up Elephant", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 30, 0, true) }, "An interactive wind-up toy elephant."), new ToyRegistration("RWtoys_Yellow_Box", "A/B/C/D/E/F YELLOW BOX", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 5, 0, true) }, "Place the box down, then rotate."), new ToyRegistration("RWtoys_Blue_Box", "G/H/I/J/K/L BLUE BOX", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 5, 0, true) }, "Place the box down, then rotate."), new ToyRegistration("RWtoys_Green_Box", "M/N/O/P/Q/R GREEN BOX", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 5, 0, true) }, "Place the box down, then rotate."), new ToyRegistration("RWtoys_Orange_Box", "S/T/U/V/W/X ORANGE BOX", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 5, 0, true) }, "Place the box down, then rotate."), new ToyRegistration("RWtoys_LightOrange_Box", "Y/Z/!/?/,/. LIGHT-ORANGE BOX", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 5, 0, true) }, "Place the box down, then rotate."), new ToyRegistration("RWtoys_Robot", "It's Me, Mario, the Little Robot", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 15, 0, true) }, "Just a robot toy."), new ToyRegistration("RWtoys_Robot_Egg", "Wind-Up Robot Egg", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 40, 0, true) }, "An interactive wind-up robot toy."), new ToyRegistration("RWtoys_cone", "Rainbow Ring Stacker Toy", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 5, 0, true) }, "A colorful rainbow ring stacker toy."), new ToyRegistration("RWtoys_Rocket", "Rocket Toy", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 10, 0, true) }, "A futuristic toy."), new ToyRegistration("RWtoys_Robot_Blue", "Blue Robot Toy", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 40, 0, true) }, "A futuristic robot toy."), new ToyRegistration("RWtoys_Boat", "Toy Boat", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 10, 0, true) }, "A futuristic boat toy."), new ToyRegistration("RWtoys_Plane", "Toy Plane", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 25, 0, true) }, "A futuristic plane toy."), new ToyRegistration("RWtoys_yoyo", "Toy Yo-Yo", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 20, 0, true) }, "An interactive yo-yo toy."), new ToyRegistration("RWtoys_Little_Girl", "Doll", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 80, 0, true) }, "A little girl doll."), new ToyRegistration("RWtoys_Little_Sitting_Girl", "Sitting Doll", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 80, 0, true) }, "A little girl doll sitting down."), new ToyRegistration("RWtoys_Dog", "Little Dog on Wheels", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 60, 0, true) }, "A cute little dog on wheels."), new ToyRegistration("RWtoys_Clown", "Scary Clown", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 100, 0, true) }, "I know what you did last year!"), new ToyRegistration("RWtoys_Cat", "Cute Cat Toy", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 50, 0, true) }, "An adorable little cat toy."), new ToyRegistration("RWtoys_Bear", "Cute Bear Toy", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 50, 0, true) }, "An adorable little bear toy.", 1), new ToyRegistration("RWtoys_Telescope", "Toy Telescope", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 15, 0, true) }, "A toy telescope."), new ToyRegistration("RWtoys_musketeer", "Toy Musketeer", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 10, 0, true) }, "A toy musketeer."), new ToyRegistration("RWtoys_SmallBear", "Small Bear Toy", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 5, 0, true) }, "A small toy."), new ToyRegistration("RWtoys_DeerGlobe", "Deer Globe", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Bear", 10, 0, true) }, "A small DeerGlobe.", 1), new ToyRegistration("RWtoys_HotAirBalloon", "Wooden Hot Air Balloon", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Bear", 12, 0, true) }, "A Hot Air Balloon."), new ToyRegistration("RWtoys_WitchCat", "A purr-fect spooky companion", (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig("RWc_Deer", 8, 0, true), new RequirementConfig("RWc_Bear", 8, 0, true), new RequirementConfig("RWc_Snake", 8, 0, true) }, "A mischievous little witch cat sitting on a carved pumpkin, bringing spooky magic to your home.", 1), new ToyRegistration("RWtoys_WoodenBear", "A cute wooden bear toy", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Deer", 15, 0, true) }, "A mischievous little witch cat sitting on a carved pumpkin, bringing spooky magic to your home."), new ToyRegistration("RWtoys_IndianHat", "A toy Indian Hat", (RequirementConfig[])(object)new RequirementConfig[2] { new RequirementConfig("RWc_Deer", 5, 0, true), new RequirementConfig("RWc_Bear", 5, 0, true) }, "Not a real hat."), new ToyRegistration("RWtoys_SpaceHat", "A toy Kosmonaut Hat", (RequirementConfig[])(object)new RequirementConfig[1] { new RequirementConfig("RWc_Wolf", 2, 0, true) }, "Not a real hat."), new ToyRegistration("RWtoys_PirateHat", "A toy Pirate Hat", (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig("RWc_Deer", 2, 0, true), new RequirementConfig("RWc_Bear", 2, 0, true), new RequirementConfig("RWc_Snake", 2, 0, true) }, "Not a real hat.") }; public static void InitConfig(ConfigFile config) { if (config == null || hammerTabConfig != null) { return; } hammerTabConfig = config.Bind("General", "CustomHammerTab", "Ravenwood", "Hammer build-menu tab used for every Ravenwood Toys prefab. Restart Valheim after changing this setting."); foreach (ToyRegistration allRegistration in AllRegistrations) { toyVisibilityConfigs[allRegistration.PrefabName] = config.Bind("Toy Visibility", allRegistration.PrefabName, true, "Set to false to hide this toy from the hammer build menu. Restart Valheim after changing this setting."); toyComfortConfigs[allRegistration.PrefabName] = config.Bind("Comfort Levels", allRegistration.PrefabName, allRegistration.Comfort, "Comfort provided by this toy. Set to 0 to disable comfort. Restart Valheim after changing this setting."); } } public static IEnumerable GetAllCategories() { return new string[1] { GetConfiguredHammerTab() }; } public static void RegisterAllToys(AssetBundle bundle) { if (wasAlreadyRegistered) { return; } if ((Object)(object)bundle == (Object)null) { Debug.LogError((object)"[Ravenwood Toys] AssetBundle is null. Registration stopped."); return; } int num = 0; int num2 = 0; GameObject val = bundle.LoadAsset("sfx_RWtoys_Box_Move"); YellowBoxInteract.ConfigureRotationSound(val); if ((Object)(object)val == (Object)null) { Debug.LogWarning((object)"[Ravenwood Toys] Missing sound prefab in AssetBundle: sfx_RWtoys_Box_Move"); } GameObject val2 = bundle.LoadAsset("sfx_RWtoys_RockingHorse_Creak"); RockingHorseInteract.ConfigureRockingSound(val2); if ((Object)(object)val2 == (Object)null) { Debug.LogWarning((object)"[Ravenwood Toys] Missing sound prefab in AssetBundle: sfx_RWtoys_RockingHorse_Creak"); } GameObject val3 = bundle.LoadAsset("sfx_RWtoys_Robot_Blue"); ToyTrainInteract.ConfigureRobotSound(val3); if ((Object)(object)val3 == (Object)null) { Debug.LogWarning((object)"[Ravenwood Toys] Missing sound prefab in AssetBundle: sfx_RWtoys_Robot_Blue"); } GameObject val4 = bundle.LoadAsset("sfx_RWtoys_Elephant"); ElephantKeyInteract.ConfigureElephantSound(val4); if ((Object)(object)val4 == (Object)null) { Debug.LogWarning((object)"[Ravenwood Toys] Missing sound prefab in AssetBundle: sfx_RWtoys_Elephant"); } GameObject val5 = bundle.LoadAsset("sfx_RWtoys_Egg"); ElephantKeyInteract.ConfigureEggSound(val5); if ((Object)(object)val5 == (Object)null) { Debug.LogWarning((object)"[Ravenwood Toys] Missing sound prefab in AssetBundle: sfx_RWtoys_Egg"); } GameObject val6 = bundle.LoadAsset("sfx_RWtoys_Plane"); ToyTrainInteract.ConfigurePlaneSound(val6); if ((Object)(object)val6 == (Object)null) { Debug.LogWarning((object)"[Ravenwood Toys] Missing sound prefab in AssetBundle: sfx_RWtoys_Plane"); } GameObject val7 = bundle.LoadAsset("sfx_RWtoys_Train"); ToyTrainInteract.ConfigureTrainSound(val7); if ((Object)(object)val7 == (Object)null) { Debug.LogWarning((object)"[Ravenwood Toys] Missing sound prefab in AssetBundle: sfx_RWtoys_Train"); } foreach (ToyRegistration allRegistration in AllRegistrations) { if (RegisterToy(bundle, allRegistration)) { num++; } else { num2++; } } wasAlreadyRegistered = true; Debug.Log((object)("[Ravenwood Toys] Registered " + num + "/" + AllRegistrations.Count + " toys. Failed: " + num2 + ".")); } private static bool RegisterToy(AssetBundle bundle, ToyRegistration registration) { //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Expected O, but got Unknown //IL_0312: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Expected O, but got Unknown if ((Object)(object)bundle == (Object)null || registration == null || string.IsNullOrWhiteSpace(registration.PrefabName)) { return false; } GameObject val = bundle.LoadAsset(registration.PrefabName); if ((Object)(object)val == (Object)null) { Debug.LogWarning((object)("[Ravenwood Toys] Missing prefab in AssetBundle: " + registration.PrefabName)); return false; } ((Object)val).name = registration.PrefabName; ZNetView val2 = val.GetComponent(); if ((Object)(object)val2 == (Object)null) { val2 = val.AddComponent(); } val2.m_persistent = true; val2.m_syncInitialScale = true; Piece val3 = val.GetComponent(); if ((Object)(object)val3 == (Object)null) { val3 = val.AddComponent(); } val3.m_name = registration.DisplayName; val3.m_description = registration.Description; val3.m_groundOnly = false; val3.m_canBeRemoved = true; val3.m_comfort = GetConfiguredComfort(registration); ApplyWoodPlacementAndRemovalEffects(val3, val); if ((string.Equals(registration.PrefabName, "RWtoys_Wooden_Horse", StringComparison.OrdinalIgnoreCase) || string.Equals(registration.PrefabName, "RWtoys_yoyo", StringComparison.OrdinalIgnoreCase)) && (Object)(object)val.GetComponent() == (Object)null) { val.AddComponent(); } if ((string.Equals(registration.PrefabName, "RWtoys_Robot_Blue", StringComparison.OrdinalIgnoreCase) || string.Equals(registration.PrefabName, "RWtoys_Plane", StringComparison.OrdinalIgnoreCase) || string.Equals(registration.PrefabName, "RWtoys_train", StringComparison.OrdinalIgnoreCase)) && (Object)(object)val.GetComponent() == (Object)null) { val.AddComponent(); } if ((string.Equals(registration.PrefabName, "RWtoys_Robot_Egg", StringComparison.OrdinalIgnoreCase) || string.Equals(registration.PrefabName, "RWtoys_elephant", StringComparison.OrdinalIgnoreCase)) && (Object)(object)val.GetComponent() == (Object)null) { val.AddComponent(); } if ((string.Equals(registration.PrefabName, "RWtoys_Yellow_Box", StringComparison.OrdinalIgnoreCase) || string.Equals(registration.PrefabName, "RWtoys_Blue_Box", StringComparison.OrdinalIgnoreCase) || string.Equals(registration.PrefabName, "RWtoys_Green_Box", StringComparison.OrdinalIgnoreCase) || string.Equals(registration.PrefabName, "RWtoys_LightOrange_Box", StringComparison.OrdinalIgnoreCase) || string.Equals(registration.PrefabName, "RWtoys_Orange_Box", StringComparison.OrdinalIgnoreCase)) && (Object)(object)val.GetComponent() == (Object)null) { val.AddComponent(); } Sprite val4 = bundle.LoadAsset(registration.PrefabName); if ((Object)(object)val4 != (Object)null) { val3.m_icon = val4; } else { Debug.LogWarning((object)("[Ravenwood Toys] Icon not found for prefab: " + registration.PrefabName)); } RequirementConfig[] configuredRequirements = GetConfiguredRequirements(registration); if (configuredRequirements == null || configuredRequirements.Length == 0) { Debug.LogError((object)("[Ravenwood Toys] No valid build requirements are available for " + registration.PrefabName + ". Toy registration skipped to prevent an invalid Piece requirement.")); return false; } PieceConfig val5 = new PieceConfig { PieceTable = "Hammer", Category = GetConfiguredHammerTab(), CraftingStation = registration.CraftingStation, Requirements = configuredRequirements, Enabled = IsToyEnabled(registration) }; PieceManager.Instance.AddPiece(new CustomPiece(val, true, val5)); return true; } private static void ApplyWoodPlacementAndRemovalEffects(Piece piece, GameObject prefab) { //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_00b0: Expected O, but got Unknown //IL_00dd: 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_00f4: Expected O, but got Unknown //IL_00c2: 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_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Expected O, but got Unknown //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Expected O, but got Unknown //IL_0199: 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_01b0: Expected O, but got Unknown //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Expected O, but got Unknown GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("vfx_Place_wood") : null); GameObject val2 = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("sfx_build_hammer_wood") : null); GameObject val3 = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("vfx_destroyed") : null); GameObject val4 = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("sfx_wood_break") : null); List list = new List(); if ((Object)(object)val != (Object)null) { list.Add(new EffectData { m_prefab = val, m_enabled = true }); } if ((Object)(object)val2 != (Object)null) { list.Add(new EffectData { m_prefab = val2, m_enabled = true }); } piece.m_placeEffect = new EffectList { m_effectPrefabs = list.ToArray() }; WearNTear val5 = prefab.GetComponent(); if ((Object)(object)val5 == (Object)null) { val5 = prefab.AddComponent(); } val5.m_health = Mathf.Max(val5.m_health, 1000f); val5.m_noRoofWear = true; val5.m_noSupportWear = false; List list2 = new List(); if ((Object)(object)val3 != (Object)null) { list2.Add(new EffectData { m_prefab = val3, m_enabled = true }); } if ((Object)(object)val4 != (Object)null) { list2.Add(new EffectData { m_prefab = val4, m_enabled = true }); } val5.m_destroyedEffect = new EffectList { m_effectPrefabs = list2.ToArray() }; } private static string GetConfiguredHammerTab() { string text = ((hammerTabConfig != null) ? hammerTabConfig.Value : null); return string.IsNullOrWhiteSpace(text) ? "Ravenwood" : text.Trim(); } private static bool IsToyEnabled(ToyRegistration registration) { if (registration == null || string.IsNullOrWhiteSpace(registration.PrefabName)) { return true; } ConfigEntry value; return !toyVisibilityConfigs.TryGetValue(registration.PrefabName, out value) || value == null || value.Value; } private static int GetConfiguredComfort(ToyRegistration registration) { if (registration == null || string.IsNullOrWhiteSpace(registration.PrefabName)) { return 0; } ConfigEntry value; return (toyComfortConfigs.TryGetValue(registration.PrefabName, out value) && value != null) ? Math.Max(0, value.Value) : Math.Max(0, registration.Comfort); } private static RequirementConfig[] GetConfiguredRequirements(ToyRegistration registration) { if (registration.Requirements == null) { return (RequirementConfig[])(object)new RequirementConfig[0]; } if (RavenwoodToys.ModConfig == null) { return registration.Requirements; } string text = FormatRequirements(registration.Requirements); ConfigEntry val = RavenwoodToys.ModConfig.Bind("Build Costs", registration.PrefabName, text, "Build cost format: [Valheim prefab name][amount]. Up to four requirements."); if (TryParseRequirements(val.Value, out var requirements)) { if (AreRequirementsAvailable(requirements, out var missingItem)) { return requirements; } Debug.LogWarning((object)("[Ravenwood Toys] Build cost for " + registration.PrefabName + " references a missing or invalid item prefab: " + missingItem + ". Using the default value: " + text)); } else { Debug.LogWarning((object)("[Ravenwood Toys] Invalid build cost for " + registration.PrefabName + ". Using the default value: " + text)); } if (AreRequirementsAvailable(registration.Requirements, out var missingItem2)) { return registration.Requirements; } Debug.LogError((object)("[Ravenwood Toys] Default build cost for " + registration.PrefabName + " references a missing or invalid item prefab: " + missingItem2 + ".")); return (RequirementConfig[])(object)new RequirementConfig[0]; } private static bool AreRequirementsAvailable(RequirementConfig[] requirements, out string missingItem) { missingItem = null; if (requirements == null || requirements.Length == 0) { missingItem = ""; return false; } foreach (RequirementConfig val in requirements) { if (val == null || string.IsNullOrWhiteSpace(val.Item)) { missingItem = ""; return false; } GameObject val2 = PrefabManager.Instance.GetPrefab(val.Item); if ((Object)(object)val2 == (Object)null && (Object)(object)ObjectDB.instance != (Object)null) { val2 = ObjectDB.instance.GetItemPrefab(val.Item); } if ((Object)(object)val2 == (Object)null && (Object)(object)ZNetScene.instance != (Object)null) { val2 = ZNetScene.instance.GetPrefab(val.Item); } if ((Object)(object)val2 == (Object)null || (Object)(object)val2.GetComponent() == (Object)null) { missingItem = val.Item; return false; } } return true; } private static string FormatRequirements(RequirementConfig[] requirements) { if (requirements == null || requirements.Length == 0) { return string.Empty; } return string.Join(string.Empty, requirements.Select((RequirementConfig requirement) => "[" + requirement.Item + "][" + requirement.Amount + "]").ToArray()); } private static bool TryParseRequirements(string value, out RequirementConfig[] requirements) { //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Expected O, but got Unknown List list = new List(); requirements = (RequirementConfig[])(object)new RequirementConfig[0]; if (string.IsNullOrWhiteSpace(value)) { return false; } int i = 0; while (i < value.Length) { for (; i < value.Length && char.IsWhiteSpace(value[i]); i++) { } if (i >= value.Length) { break; } if (value[i] != '[') { return false; } int num = value.IndexOf(']', i + 1); if (num < 0) { return false; } string text = value.Substring(i + 1, num - i - 1).Trim(); for (i = num + 1; i < value.Length && char.IsWhiteSpace(value[i]); i++) { } if (i >= value.Length || value[i] != '[') { return false; } int num2 = value.IndexOf(']', i + 1); if (num2 < 0) { return false; } string s = value.Substring(i + 1, num2 - i - 1).Trim(); if (string.IsNullOrWhiteSpace(text) || !int.TryParse(s, out var result) || result <= 0 || list.Count >= 4) { return false; } list.Add(new RequirementConfig(text, result, 0, true)); i = num2 + 1; } if (list.Count == 0) { return false; } requirements = list.ToArray(); return true; } } [DisallowMultipleComponent] public class ToyTrainInteract : MonoBehaviour, Hoverable, Interactable { private const string TrainRpcName = "RavenwoodToys_RunTrain"; private const string InteractionObjectName = "ToyTrainInteraction"; private const float DegreesPerSecond = 18f; private const float RobotDegreesPerSecond = 360f; private const float RobotJumpHeight = 0.3f; private const float RobotJumpDuration = 0.3f; private const float FullTurn = 360f; private const float PlaneSpinDuration = 7f; private const float PlaneFullTurns = 50f; private const float PlaneTotalDegrees = 18000f; private const float PlaneDegreesPerSecond = 2571.4285f; private static GameObject robotSoundPrefab; private static GameObject planeSoundPrefab; private static GameObject trainSoundPrefab; private Piece piece; private ZNetView networkView; private Transform trainPivot; private Quaternion restWorldRotation; private Quaternion restLocalRotation; private Vector3 restLocalPosition; private float degreesTravelled; private float robotJumpElapsed; private float lastStartTime = -100f; private bool interactionReady; private bool isMoving; private bool isPlane; private bool isRobot; private bool isRobotJumping; public static void ConfigureRobotSound(GameObject soundPrefab) { robotSoundPrefab = soundPrefab; } public static void ConfigurePlaneSound(GameObject soundPrefab) { planeSoundPrefab = soundPrefab; } public static void ConfigureTrainSound(GameObject soundPrefab) { trainSoundPrefab = soundPrefab; } private void Awake() { //IL_009c: 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_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) piece = ((Component)this).GetComponent(); networkView = ((Component)this).GetComponent(); isPlane = ((Object)this).name.StartsWith("RWtoys_Plane", StringComparison.OrdinalIgnoreCase); isRobot = ((Object)this).name.StartsWith("RWtoys_Robot_Blue", StringComparison.OrdinalIgnoreCase); Transform val = FindDeepChild(((Component)this).transform, "TrackCenter"); trainPivot = (((Object)(object)val != (Object)null) ? FindDeepChild(val, isPlane ? "Sphere" : "pivot") : null); if ((Object)(object)trainPivot != (Object)null) { restWorldRotation = trainPivot.rotation; restLocalRotation = trainPivot.localRotation; restLocalPosition = trainPivot.localPosition; } else { Debug.LogWarning((object)("[Ravenwood Toys] TrackCenter/" + (isPlane ? "Sphere" : "pivot") + " was not found on: " + ((Object)this).name)); } if ((Object)(object)networkView != (Object)null) { networkView.Register("RavenwoodToys_RunTrain", (Action)RpcRunTrain); } } private void Update() { //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: 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_00d3: 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_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0152: 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_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) if (!interactionReady) { TryCreateInteractionTarget(); } if (!isMoving || (Object)(object)trainPivot == (Object)null) { return; } if (isRobot && isRobotJumping) { robotJumpElapsed = Mathf.Min(robotJumpElapsed + Time.deltaTime, 0.3f); float num = robotJumpElapsed / 0.3f; float num2 = Mathf.Sin(num * (float)Math.PI) * 0.3f; trainPivot.localPosition = restLocalPosition + Vector3.up * num2; if (robotJumpElapsed >= 0.3f) { trainPivot.localPosition = restLocalPosition; isRobotJumping = false; } return; } float num3 = (isPlane ? 2571.4285f : (isRobot ? 360f : 18f)); float num4 = (isPlane ? 18000f : 360f); degreesTravelled = Mathf.Min(degreesTravelled + num3 * Time.deltaTime, num4); if (isPlane) { trainPivot.localRotation = restLocalRotation * Quaternion.AngleAxis(0f - degreesTravelled, Vector3.forward); } else { trainPivot.rotation = Quaternion.AngleAxis(0f - degreesTravelled, Vector3.up) * restWorldRotation; } if (degreesTravelled >= num4) { StopTrain(); } } private void TryCreateInteractionTarget() { //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown if ((Object)(object)networkView == (Object)null || !networkView.IsValid()) { return; } Transform val = ((Component)this).transform.Find("ToyTrainInteraction"); if ((Object)(object)val != (Object)null) { ToyTrainInteractionProxy toyTrainInteractionProxy = ((Component)val).GetComponent(); if ((Object)(object)toyTrainInteractionProxy == (Object)null) { toyTrainInteractionProxy = ((Component)val).gameObject.AddComponent(); } toyTrainInteractionProxy.Configure(this); interactionReady = true; return; } GameObject val2 = new GameObject("ToyTrainInteraction"); val2.transform.SetParent(((Component)this).transform, false); int num = LayerMask.NameToLayer("piece_nonsolid"); if (num < 0) { num = LayerMask.NameToLayer("piece"); } val2.layer = ((num >= 0) ? num : ((Component)this).gameObject.layer); BoxCollider val3 = val2.AddComponent(); ((Collider)val3).isTrigger = false; ApplyInteractionBounds(val3); ToyTrainInteractionProxy toyTrainInteractionProxy2 = val2.AddComponent(); toyTrainInteractionProxy2.Configure(this); interactionReady = true; } private void ApplyInteractionBounds(BoxCollider interactionCollider) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: 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_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: 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) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)interactionCollider == (Object)null) { return; } Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren(true); bool flag = false; Vector3 val = Vector3.zero; Vector3 val2 = Vector3.zero; foreach (Renderer val3 in componentsInChildren) { if ((Object)(object)val3 == (Object)null) { continue; } Bounds bounds = val3.bounds; for (int j = -1; j <= 1; j += 2) { for (int k = -1; k <= 1; k += 2) { for (int l = -1; l <= 1; l += 2) { Vector3 val4 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)j, (float)k, (float)l)); Vector3 val5 = ((Component)this).transform.InverseTransformPoint(val4); if (!flag) { val = val5; val2 = val5; flag = true; } else { val = Vector3.Min(val, val5); val2 = Vector3.Max(val2, val5); } } } } } if (!flag) { interactionCollider.center = new Vector3(0f, 0.5f, 0f); interactionCollider.size = new Vector3(4f, 1f, 4f); } else { interactionCollider.center = (val + val2) * 0.5f; interactionCollider.size = val2 - val + new Vector3(0.2f, 0.2f, 0.2f); } } private void OnDisable() { StopTrain(); } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold || (Object)(object)trainPivot == (Object)null || isMoving) { return false; } StartTrain(); if ((Object)(object)networkView != (Object)null && networkView.IsValid()) { networkView.InvokeRPC(ZNetView.Everybody, "RavenwoodToys_RunTrain", Array.Empty()); } return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } public string GetHoverText() { if (isMoving) { return GetHoverName() + (isPlane ? "\nPropeller is spinning" : (isRobot ? "\nRobot is moving" : "\nTrain is moving")); } return GetHoverName() + (isPlane ? "\n[E] Spin propeller" : (isRobot ? "\n[E] Start robot" : "\n[E] Start train")); } public string GetHoverName() { return ((Object)(object)piece != (Object)null && !string.IsNullOrWhiteSpace(piece.m_name)) ? piece.m_name : "Toy Train"; } private void RpcRunTrain(long sender) { if (!isMoving && Time.time - lastStartTime > 0.1f) { StartTrain(); } } private void StartTrain() { //IL_004a: 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_0068: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)trainPivot == (Object)null) && !isMoving) { if (isPlane) { trainPivot.localRotation = restLocalRotation; } else { trainPivot.rotation = restWorldRotation; } if (isRobot) { trainPivot.localPosition = restLocalPosition; } degreesTravelled = 0f; robotJumpElapsed = 0f; lastStartTime = Time.time; isMoving = true; isRobotJumping = isRobot; PlayRobotSound(); PlayPlaneSound(); PlayTrainSound(); } } private void PlayRobotSound() { //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) if (isRobot && !((Object)(object)robotSoundPrefab == (Object)null) && !((Object)(object)trainPivot == (Object)null)) { GameObject val = Object.Instantiate(robotSoundPrefab, trainPivot.position, Quaternion.identity); AudioSource component = val.GetComponent(); if ((Object)(object)component != (Object)null) { component.Stop(); component.playOnAwake = false; component.loop = false; component.Play(); Object.Destroy((Object)(object)val, ((Object)(object)component.clip != (Object)null) ? (component.clip.length + 0.1f) : 8f); } else { Object.Destroy((Object)(object)val, 8f); } } } private void PlayPlaneSound() { //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) if (isPlane && !((Object)(object)planeSoundPrefab == (Object)null) && !((Object)(object)trainPivot == (Object)null)) { GameObject val = Object.Instantiate(planeSoundPrefab, trainPivot.position, Quaternion.identity); AudioSource component = val.GetComponent(); if ((Object)(object)component != (Object)null) { component.Stop(); component.playOnAwake = false; component.loop = false; component.Play(); Object.Destroy((Object)(object)val, ((Object)(object)component.clip != (Object)null) ? (component.clip.length + 0.1f) : 8f); } else { Object.Destroy((Object)(object)val, 8f); } } } private void PlayTrainSound() { //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) if (!isPlane && !isRobot && !((Object)(object)trainSoundPrefab == (Object)null) && !((Object)(object)trainPivot == (Object)null)) { GameObject val = Object.Instantiate(trainSoundPrefab, trainPivot.position, Quaternion.identity); AudioSource component = val.GetComponent(); if ((Object)(object)component != (Object)null) { component.Stop(); component.playOnAwake = false; component.loop = false; component.Play(); Object.Destroy((Object)(object)val, ((Object)(object)component.clip != (Object)null) ? (component.clip.length + 0.1f) : 21f); } else { Object.Destroy((Object)(object)val, 21f); } } } private void StopTrain() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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) if ((Object)(object)trainPivot != (Object)null) { if (isPlane) { trainPivot.localRotation = restLocalRotation; } else { trainPivot.rotation = restWorldRotation; } if (isRobot) { trainPivot.localPosition = restLocalPosition; } } degreesTravelled = 0f; robotJumpElapsed = 0f; isMoving = false; isRobotJumping = false; } private static Transform FindDeepChild(Transform parent, string childName) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown if ((Object)(object)parent == (Object)null) { return null; } foreach (Transform item in parent) { Transform val = item; if (string.Equals(((Object)val).name, childName, StringComparison.OrdinalIgnoreCase)) { return val; } Transform val2 = FindDeepChild(val, childName); if ((Object)(object)val2 != (Object)null) { return val2; } } return null; } } [DisallowMultipleComponent] public class ToyTrainInteractionProxy : MonoBehaviour, Hoverable, Interactable { private ToyTrainInteract toyTrain; private void Awake() { if ((Object)(object)toyTrain == (Object)null) { toyTrain = ((Component)this).GetComponentInParent(); } } public void Configure(ToyTrainInteract target) { toyTrain = target; } public bool Interact(Humanoid user, bool hold, bool alt) { return (Object)(object)toyTrain != (Object)null && toyTrain.Interact(user, hold, alt); } public bool UseItem(Humanoid user, ItemData item) { return (Object)(object)toyTrain != (Object)null && toyTrain.UseItem(user, item); } public string GetHoverText() { return ((Object)(object)toyTrain != (Object)null) ? toyTrain.GetHoverText() : string.Empty; } public string GetHoverName() { return ((Object)(object)toyTrain != (Object)null) ? toyTrain.GetHoverName() : string.Empty; } } [DisallowMultipleComponent] public class YellowBoxInteract : MonoBehaviour, Hoverable, Interactable { private const string AdvanceRpcName = "RavenwoodToys_AdvanceYellowBox"; private const string InteractionObjectName = "YellowBoxInteraction"; private const string StateKey = "RavenwoodToys_YellowBoxState"; private const int StateCount = 8; private const float RotationDuration = 0.5f; private Piece piece; private ZNetView networkView; private Transform boxPivot; private Quaternion initialLocalRotation; private Quaternion rotationStart; private Quaternion rotationTarget; private uint lastDataRevision = uint.MaxValue; private float rotationTime; private float lastAdvanceTime = -100f; private int currentState; private bool interactionReady; private bool networkStateReady; private bool isRotating; private static GameObject rotationSoundPrefab; public static void ConfigureRotationSound(GameObject soundPrefab) { rotationSoundPrefab = soundPrefab; } private void Awake() { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) piece = ((Component)this).GetComponent(); networkView = ((Component)this).GetComponent(); Transform val = FindDeepChild(((Component)this).transform, "TrackCenter"); boxPivot = (((Object)(object)val != (Object)null) ? FindDeepChild(val, "pivot") : null); if ((Object)(object)boxPivot != (Object)null) { initialLocalRotation = boxPivot.localRotation; } else { Debug.LogWarning((object)("[Ravenwood Toys] TrackCenter/pivot was not found on: " + ((Object)this).name)); } if ((Object)(object)networkView != (Object)null) { networkView.Register("RavenwoodToys_AdvanceYellowBox", (Action)RpcAdvanceState); } } private void Update() { if (!interactionReady) { TryCreateInteractionTarget(); } UpdateNetworkState(); UpdateRotation(); } private void TryCreateInteractionTarget() { //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown if ((Object)(object)networkView == (Object)null || !networkView.IsValid()) { return; } Transform val = ((Component)this).transform.Find("YellowBoxInteraction"); if ((Object)(object)val != (Object)null) { YellowBoxInteractionProxy yellowBoxInteractionProxy = ((Component)val).GetComponent(); if ((Object)(object)yellowBoxInteractionProxy == (Object)null) { yellowBoxInteractionProxy = ((Component)val).gameObject.AddComponent(); } yellowBoxInteractionProxy.Configure(this); interactionReady = true; return; } GameObject val2 = new GameObject("YellowBoxInteraction"); val2.transform.SetParent(((Component)this).transform, false); int num = LayerMask.NameToLayer("piece_nonsolid"); if (num < 0) { num = LayerMask.NameToLayer("piece"); } val2.layer = ((num >= 0) ? num : ((Component)this).gameObject.layer); BoxCollider val3 = val2.AddComponent(); ((Collider)val3).isTrigger = false; ApplyInteractionBounds(val3); YellowBoxInteractionProxy yellowBoxInteractionProxy2 = val2.AddComponent(); yellowBoxInteractionProxy2.Configure(this); interactionReady = true; } private void ApplyInteractionBounds(BoxCollider interactionCollider) { //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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_0162: 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_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0093: 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_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: 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_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)interactionCollider == (Object)null) { return; } Renderer[] array = (((Object)(object)boxPivot != (Object)null) ? ((Component)boxPivot).GetComponentsInChildren(true) : ((Component)this).GetComponentsInChildren(true)); bool flag = false; Vector3 val = Vector3.zero; Vector3 val2 = Vector3.zero; foreach (Renderer val3 in array) { if ((Object)(object)val3 == (Object)null) { continue; } Bounds bounds = val3.bounds; for (int j = -1; j <= 1; j += 2) { for (int k = -1; k <= 1; k += 2) { for (int l = -1; l <= 1; l += 2) { Vector3 val4 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)j, (float)k, (float)l)); Vector3 val5 = ((Component)this).transform.InverseTransformPoint(val4); if (!flag) { val = val5; val2 = val5; flag = true; } else { val = Vector3.Min(val, val5); val2 = Vector3.Max(val2, val5); } } } } } if (!flag) { interactionCollider.center = new Vector3(0f, 0.5f, 0f); interactionCollider.size = new Vector3(2f, 2f, 2f); } else { interactionCollider.center = (val + val2) * 0.5f; interactionCollider.size = val2 - val + new Vector3(0.2f, 0.2f, 0.2f); } } private void UpdateNetworkState() { //IL_00b2: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)networkView == (Object)null || !networkView.IsValid() || networkView.GetZDO() == null || (Object)(object)boxPivot == (Object)null) { return; } uint dataRevision = networkView.GetZDO().DataRevision; if (!networkStateReady || lastDataRevision != dataRevision) { lastDataRevision = dataRevision; int num = Mathf.Clamp(networkView.GetZDO().GetInt("RavenwoodToys_YellowBoxState", 0), 0, 7); if (!networkStateReady) { currentState = num; boxPivot.localRotation = GetRotationForState(num); networkStateReady = true; } else if (num != currentState) { BeginRotation(num); } } } private void UpdateRotation() { //IL_0061: 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_006d: 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) if (isRotating && !((Object)(object)boxPivot == (Object)null)) { rotationTime = Mathf.Min(rotationTime + Time.deltaTime, 0.5f); float num = Mathf.SmoothStep(0f, 1f, rotationTime / 0.5f); boxPivot.localRotation = Quaternion.Slerp(rotationStart, rotationTarget, num); if (rotationTime >= 0.5f) { boxPivot.localRotation = rotationTarget; isRotating = false; } } } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold || (Object)(object)boxPivot == (Object)null || isRotating || (Object)(object)networkView == (Object)null || !networkView.IsValid() || networkView.GetZDO() == null) { return false; } networkView.InvokeRPC("RavenwoodToys_AdvanceYellowBox", Array.Empty()); return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } public string GetHoverText() { if (isRotating) { return GetHoverName() + "\nBox is rotating"; } return GetHoverName() + "\n[E] Rotate"; } public string GetHoverName() { return ((Object)(object)piece != (Object)null && !string.IsNullOrWhiteSpace(piece.m_name)) ? piece.m_name : "A/B/C/D/E/F YELLOW BOX"; } private void RpcAdvanceState(long sender) { if (!((Object)(object)networkView == (Object)null) && networkView.IsValid() && networkView.GetZDO() != null && !(Time.time - lastAdvanceTime < 0.5f)) { int num = Mathf.Clamp(networkView.GetZDO().GetInt("RavenwoodToys_YellowBoxState", 0), 0, 7); int num2 = (num + 1) % 8; lastAdvanceTime = Time.time; networkView.GetZDO().Set("RavenwoodToys_YellowBoxState", num2); UpdateNetworkState(); } } private void BeginRotation(int state) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_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) if (!((Object)(object)boxPivot == (Object)null)) { currentState = Mathf.Clamp(state, 0, 7); rotationStart = boxPivot.localRotation; rotationTarget = GetRotationForState(currentState); rotationTime = 0f; isRotating = true; PlayRotationSound(); } } private void PlayRotationSound() { //IL_002f: 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) if (!((Object)(object)rotationSoundPrefab == (Object)null) && !((Object)(object)boxPivot == (Object)null)) { GameObject val = Object.Instantiate(rotationSoundPrefab, boxPivot.position, Quaternion.identity); AudioSource component = val.GetComponent(); if ((Object)(object)component != (Object)null) { component.loop = false; component.Play(); Object.Destroy((Object)(object)val, ((Object)(object)component.clip != (Object)null) ? (component.clip.length + 0.1f) : 2f); } else { Object.Destroy((Object)(object)val, 2f); } } } private Quaternion GetRotationForState(int state) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_004c: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) if (state <= 4) { return initialLocalRotation * Quaternion.AngleAxis((float)state * 90f, Vector3.up); } return initialLocalRotation * Quaternion.AngleAxis((float)(state - 4) * 90f, Vector3.right); } private static Transform FindDeepChild(Transform parent, string childName) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown if ((Object)(object)parent == (Object)null) { return null; } foreach (Transform item in parent) { Transform val = item; if (string.Equals(((Object)val).name, childName, StringComparison.OrdinalIgnoreCase)) { return val; } Transform val2 = FindDeepChild(val, childName); if ((Object)(object)val2 != (Object)null) { return val2; } } return null; } } [DisallowMultipleComponent] public class YellowBoxInteractionProxy : MonoBehaviour, Hoverable, Interactable { private YellowBoxInteract yellowBox; private void Awake() { if ((Object)(object)yellowBox == (Object)null) { yellowBox = ((Component)this).GetComponentInParent(); } } public void Configure(YellowBoxInteract target) { yellowBox = target; } public bool Interact(Humanoid user, bool hold, bool alt) { return (Object)(object)yellowBox != (Object)null && yellowBox.Interact(user, hold, alt); } public bool UseItem(Humanoid user, ItemData item) { return (Object)(object)yellowBox != (Object)null && yellowBox.UseItem(user, item); } public string GetHoverText() { return ((Object)(object)yellowBox != (Object)null) ? yellowBox.GetHoverText() : string.Empty; } public string GetHoverName() { return ((Object)(object)yellowBox != (Object)null) ? yellowBox.GetHoverName() : string.Empty; } }