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 YapYap Valuables v1.0.0
YapYapValuables.dll
Decompiled a week agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using REPOLib.Modules; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Empress")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+5f1b735e473ca4ccf3b383128fbebd889cb564da")] [assembly: AssemblyProduct("YapYapValuables")] [assembly: AssemblyTitle("YapYapValuables")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Empress.REPO.YapYapValuables { internal static class RepoValuableAccess { private static readonly FieldRef<LevelValuables, List<PrefabRef>> TinyRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("tiny"); private static readonly FieldRef<LevelValuables, List<PrefabRef>> SmallRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("small"); private static readonly FieldRef<LevelValuables, List<PrefabRef>> MediumRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("medium"); private static readonly FieldRef<LevelValuables, List<PrefabRef>> BigRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("big"); private static readonly FieldRef<LevelValuables, List<PrefabRef>> WideRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("wide"); private static readonly FieldRef<LevelValuables, List<PrefabRef>> TallRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("tall"); private static readonly FieldRef<LevelValuables, List<PrefabRef>> VeryTallRef = AccessTools.FieldRefAccess<LevelValuables, List<PrefabRef>>("veryTall"); private static readonly FieldRef<ValuableObject, Value> ValuePresetRef = AccessTools.FieldRefAccess<ValuableObject, Value>("valuePreset"); private static readonly FieldRef<ValuableObject, Durability> DurabilityPresetRef = AccessTools.FieldRefAccess<ValuableObject, Durability>("durabilityPreset"); private static readonly FieldRef<ValuableObject, PhysAttribute> PhysAttributePresetRef = AccessTools.FieldRefAccess<ValuableObject, PhysAttribute>("physAttributePreset"); private static readonly FieldRef<ValuableObject, Type> VolumeTypeRef = AccessTools.FieldRefAccess<ValuableObject, Type>("volumeType"); private static readonly FieldRef<ValuableObject, int> DollarValueOverrideRef = AccessTools.FieldRefAccess<ValuableObject, int>("dollarValueOverride"); private static readonly FieldRef<ValuableObject, bool> DebugVolumeRef = AccessTools.FieldRefAccess<ValuableObject, bool>("debugVolume"); private static readonly FieldRef<ValuableObject, Gradient> ParticleColorsRef = AccessTools.FieldRefAccess<ValuableObject, Gradient>("particleColors"); private static readonly FieldRef<Value, float> ValueMinRef = AccessTools.FieldRefAccess<Value, float>("valueMin"); private static readonly FieldRef<Value, float> ValueMaxRef = AccessTools.FieldRefAccess<Value, float>("valueMax"); private static readonly FieldRef<Durability, float> FragilityRef = AccessTools.FieldRefAccess<Durability, float>("fragility"); private static readonly FieldRef<Durability, float> DurabilityRef = AccessTools.FieldRefAccess<Durability, float>("durability"); private static readonly FieldRef<PhysAttribute, float> MassRef = AccessTools.FieldRefAccess<PhysAttribute, float>("mass"); private static readonly FieldRef<PhysGrabObject, bool> GrabbedRef = AccessTools.FieldRefAccess<PhysGrabObject, bool>("grabbed"); private static readonly FieldRef<PhysGrabObject, bool> GrabbedLocalRef = AccessTools.FieldRefAccess<PhysGrabObject, bool>("grabbedLocal"); private static readonly FieldRef<PhysGrabObject, bool> HeldByLocalPlayerRef = AccessTools.FieldRefAccess<PhysGrabObject, bool>("heldByLocalPlayer"); private static readonly FieldRef<PhysGrabObject, List<PhysGrabber>> PlayerGrabbingRef = AccessTools.FieldRefAccess<PhysGrabObject, List<PhysGrabber>>("playerGrabbing"); public static List<PrefabRef> GetList(LevelValuables preset, Type type) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected I4, but got Unknown return (int)type switch { 0 => TinyRef.Invoke(preset), 1 => SmallRef.Invoke(preset), 2 => MediumRef.Invoke(preset), 3 => BigRef.Invoke(preset), 4 => WideRef.Invoke(preset), 5 => TallRef.Invoke(preset), 6 => VeryTallRef.Invoke(preset), _ => MediumRef.Invoke(preset), }; } public static void ConfigureValuable(ValuableObject valuable, YapYapValuableDefinition definition) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected I4, but got Unknown ValuePresetRef.Invoke(valuable) = CreateValuePreset(definition); DurabilityPresetRef.Invoke(valuable) = CreateDurabilityPreset(definition); PhysAttributePresetRef.Invoke(valuable) = CreatePhysAttributePreset(definition); VolumeTypeRef.Invoke(valuable) = (Type)(int)definition.VolumeType; DollarValueOverrideRef.Invoke(valuable) = 0; DebugVolumeRef.Invoke(valuable) = false; ParticleColorsRef.Invoke(valuable) = CreateParticleGradient(definition); } public static bool IsGrabbed(PhysGrabObject physGrabObject) { return GrabbedRef.Invoke(physGrabObject); } public static bool IsGrabbedForVoice(PhysGrabObject physGrabObject) { List<PhysGrabber> list = PlayerGrabbingRef.Invoke(physGrabObject); if (!GrabbedRef.Invoke(physGrabObject) && !GrabbedLocalRef.Invoke(physGrabObject) && !HeldByLocalPlayerRef.Invoke(physGrabObject)) { if (list != null) { return list.Count > 0; } return false; } return true; } private static Value CreateValuePreset(YapYapValuableDefinition definition) { Value val = ScriptableObject.CreateInstance<Value>(); ((Object)val).hideFlags = (HideFlags)61; ((Object)val).name = "Value - " + definition.DisplayName; ValueMinRef.Invoke(val) = definition.ValueMin; ValueMaxRef.Invoke(val) = definition.ValueMax; return val; } private static Durability CreateDurabilityPreset(YapYapValuableDefinition definition) { Durability val = ScriptableObject.CreateInstance<Durability>(); ((Object)val).hideFlags = (HideFlags)61; ((Object)val).name = "Durability - " + definition.DisplayName; FragilityRef.Invoke(val) = Mathf.Clamp(definition.Fragility + StableJitter(definition.PrefabName, "fragility", 5.5f), 5f, 95f); DurabilityRef.Invoke(val) = Mathf.Clamp(definition.Durability + StableJitter(definition.PrefabName, "durability", 5.5f), 5f, 100f); return val; } private static PhysAttribute CreatePhysAttributePreset(YapYapValuableDefinition definition) { PhysAttribute val = ScriptableObject.CreateInstance<PhysAttribute>(); ((Object)val).hideFlags = (HideFlags)61; ((Object)val).name = "PhysAttribute - " + definition.DisplayName; MassRef.Invoke(val) = definition.Mass; return val; } private static float StableJitter(string name, string salt, float radius) { uint num = 2166136261u; string text = name + ":" + salt; for (int i = 0; i < text.Length; i++) { num ^= text[i]; num *= 16777619; } return ((float)(num & 0xFFFFu) / 65535f * 2f - 1f) * radius; } private static Gradient CreateParticleGradient(YapYapValuableDefinition definition) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_002d: 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) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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_00a0: 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) Gradient val = new Gradient(); val.SetKeys((GradientColorKey[])(object)new GradientColorKey[3] { new GradientColorKey(definition.Accent, 0f), new GradientColorKey(Color.Lerp(definition.Primary, definition.Secondary, 0.6f), 0.55f), new GradientColorKey(definition.Secondary, 1f) }, (GradientAlphaKey[])(object)new GradientAlphaKey[3] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(0.8f, 0.75f), new GradientAlphaKey(0f, 1f) }); return val; } } internal static class YapYapValuableBundleVisuals { private const string BundleFileName = "yapyapvaluablesassets"; private static readonly Dictionary<string, GameObject?> VisualPrefabs = new Dictionary<string, GameObject>(); private static readonly List<AudioClip> AudioClips = new List<AudioClip>(); private static ManualLogSource? _log; private static AssetBundle? _bundle; private static bool _loadAttempted; private static bool _audioLoaded; public static void Initialize(string pluginDirectory, ManualLogSource log) { _log = log; if (_loadAttempted) { return; } _loadAttempted = true; string text = Path.Combine(pluginDirectory, "yapyapvaluablesassets"); if (!File.Exists(text)) { log.LogWarning((object)("Generated valuable asset bundle was not found at " + text + ". Falling back to procedural visuals.")); return; } try { foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles()) { if (string.Equals(((Object)allLoadedAssetBundle).name, "yapyapvaluablesassets", StringComparison.OrdinalIgnoreCase)) { _bundle = allLoadedAssetBundle; log.LogInfo((object)"Using already-loaded generated valuable asset bundle: yapyapvaluablesassets"); return; } } _bundle = AssetBundle.LoadFromFile(text); if ((Object)(object)_bundle == (Object)null) { log.LogWarning((object)("Unity returned null when loading " + text + ". Falling back to procedural visuals.")); } else { log.LogInfo((object)("Loaded generated valuable asset bundle: " + text)); } } catch (Exception arg) { log.LogWarning((object)$"Failed to load generated valuable asset bundle {text}: {arg}"); _bundle = null; } } public static bool TryAttach(Transform parent, YapYapValuableDefinition definition) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) GameObject val = LoadVisualPrefab(definition.PrefabName); if ((Object)(object)val == (Object)null) { return false; } GameObject val2 = Object.Instantiate<GameObject>(val, parent, false); ((Object)val2).name = "YapYapValuableVisual"; val2.transform.localPosition = Vector3.zero; val2.transform.localRotation = Quaternion.identity; val2.transform.localScale = Vector3.one; ((Object)val2).hideFlags = (HideFlags)52; SetLayerRecursively(val2.transform, ((Component)parent).gameObject.layer); Collider[] componentsInChildren = val2.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.Destroy((Object)(object)componentsInChildren[i]); } StripParticleEffects(val2); return true; } public static AudioClip[] LoadAllAudioClips() { //IL_0051: Unknown result type (might be due to invalid IL or missing references) if (_audioLoaded) { return AudioClips.ToArray(); } _audioLoaded = true; if ((Object)(object)_bundle == (Object)null) { return Array.Empty<AudioClip>(); } try { AudioClip[] array = _bundle.LoadAllAssets<AudioClip>(); foreach (AudioClip val in array) { if ((Object)(object)val != (Object)null && IsGrabSoundCandidate(val)) { if ((int)val.loadState == 0) { val.LoadAudioData(); } AudioClips.Add(val); } } } catch (Exception arg) { ManualLogSource? log = _log; if (log != null) { log.LogWarning((object)$"Failed to load grab audio clips from generated bundle: {arg}"); } } return AudioClips.ToArray(); } private static bool IsGrabSoundCandidate(AudioClip clip) { if (clip.length > 6f) { return false; } string text = ((Object)clip).name.ToLowerInvariant(); if (!text.Contains("hiss") && !text.Contains("music")) { return !text.Contains("sound-test"); } return false; } private static GameObject? LoadVisualPrefab(string prefabName) { if (VisualPrefabs.TryGetValue(prefabName, out GameObject value)) { return value; } if ((Object)(object)_bundle == (Object)null) { VisualPrefabs[prefabName] = null; return null; } try { GameObject val = _bundle.LoadAsset<GameObject>(prefabName); if ((Object)(object)val == (Object)null) { val = _bundle.LoadAsset<GameObject>("Assets/YapYapValuables/Prefabs/" + prefabName + ".prefab"); } if ((Object)(object)val == (Object)null) { ManualLogSource? log = _log; if (log != null) { log.LogWarning((object)("Generated bundle is missing valuable visual prefab '" + prefabName + "'.")); } } VisualPrefabs[prefabName] = val; return val; } catch (Exception arg) { ManualLogSource? log2 = _log; if (log2 != null) { log2.LogWarning((object)$"Failed to load visual prefab '{prefabName}' from generated bundle: {arg}"); } VisualPrefabs[prefabName] = null; return null; } } private static void SetLayerRecursively(Transform root, int layer) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown ((Component)root).gameObject.layer = layer; foreach (Transform item in root) { SetLayerRecursively(item, layer); } } private static void StripParticleEffects(GameObject root) { ParticleSystem[] componentsInChildren = root.GetComponentsInChildren<ParticleSystem>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.Destroy((Object)(object)componentsInChildren[i]); } ParticleSystemRenderer[] componentsInChildren2 = root.GetComponentsInChildren<ParticleSystemRenderer>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { Object.Destroy((Object)(object)componentsInChildren2[i]); } TrailRenderer[] componentsInChildren3 = root.GetComponentsInChildren<TrailRenderer>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { Object.Destroy((Object)(object)componentsInChildren3[i]); } LineRenderer[] componentsInChildren4 = root.GetComponentsInChildren<LineRenderer>(true); for (int i = 0; i < componentsInChildren4.Length; i++) { Object.Destroy((Object)(object)componentsInChildren4[i]); } } } internal sealed class YapYapValuableDefinition { public string PrefabName { get; } public string DisplayName { get; } public string SourceReference { get; } public Type VolumeType { get; } public int ValueMin { get; } public int ValueMax { get; } public float Fragility { get; } public float Durability { get; } public float Mass { get; } public Color Primary { get; } public Color Secondary { get; } public Color Accent { get; } public Vector3 GrabBoundsCenter { get; } public Vector3 GrabBoundsSize { get; } public bool GrabGlow { get; } public bool PlayAnimationsOnGrab { get; } public bool PlaySoundsOnGrab { get; } public YapYapValuableDefinition(string prefabName, string displayName, string sourceReference, Type volumeType, int valueMin, int valueMax, float fragility, float durability, float mass, Color primary, Color secondary, Color accent, Vector3 grabBoundsCenter, Vector3 grabBoundsSize, bool playAnimationsOnGrab, bool playSoundsOnGrab) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: 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_004e: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_006c: 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) PrefabName = prefabName; DisplayName = displayName; SourceReference = sourceReference; VolumeType = volumeType; ValueMin = valueMin; ValueMax = valueMax; Fragility = fragility; Durability = durability; Mass = mass; Primary = primary; Secondary = secondary; Accent = accent; GrabBoundsCenter = grabBoundsCenter; GrabBoundsSize = grabBoundsSize; GrabGlow = true; PlayAnimationsOnGrab = playAnimationsOnGrab; PlaySoundsOnGrab = playSoundsOnGrab; } } internal static class YapYapValuableDefinitions { public static readonly YapYapValuableDefinition[] All = new YapYapValuableDefinition[20] { new YapYapValuableDefinition("YapYapValuable_BirdGoblet", "Bird Goblet", "GameObject/Valuable_Bird_Goblet_01_phys.prefab", (Type)2, 4400, 8100, 10f, 106f, 1.9f, new Color(0.671f, 0.443f, 0.352f), new Color(0.231f, 0.428f, 0.491f), new Color(0.208f, 0.858f, 0.468f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_FrogVase", "Frog Vase", "GameObject/Valuable_Frog_Vase_01_phys.prefab", (Type)2, 1500, 7100, 22f, 104f, 1.9f, new Color(0.584f, 0.835f, 0.604f), new Color(0.409f, 0.296f, 0.378f), new Color(0.307f, 0.183f, 0.341f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_MoonGlobe", "Moon Globe", "GameObject/Valuable_Moon_Globe_01_phys.prefab", (Type)2, 2000, 6400, 20f, 104f, 1.9f, new Color(0.745f, 0.824f, 0.211f), new Color(0.338f, 0.688f, 0.496f), new Color(0.428f, 0.231f, 0.242f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_SkeletonBust", "Skeleton Bust", "GameObject/Valuable_Skeleton_Bust_01_phys.prefab", (Type)2, 4800, 7700, 18f, 106f, 1.9f, new Color(0.188f, 0.632f, 0.513f), new Color(0.443f, 0.451f, 0.443f), new Color(0.567f, 0.815f, 0.685f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_StarryTeapot", "Starry Teapot", "GameObject/Valuable_Starry_Teapot_01_phys.prefab", (Type)2, 4900, 9100, 11f, 92f, 1.9f, new Color(0.779f, 0.892f, 0.77f), new Color(0.666f, 0.623f, 0.488f), new Color(0.53f, 0.451f, 0.508f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_GoldCoin", "Gold Coin", "GameObject/PropGoldCoin.prefab", (Type)2, 4500, 7900, 17f, 119f, 1.9f, new Color(0.702f, 0.57f, 0.688f), new Color(0.471f, 0.756f, 0.801f), new Color(0.663f, 0.892f, 0.457f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_ArcaneGem", "Arcane Gem", "GameObject/PropGem.prefab", (Type)2, 1500, 5700, 14f, 89f, 1.9f, new Color(0.544f, 0.858f, 0.753f), new Color(0.629f, 0.268f, 0.683f), new Color(0.188f, 0.231f, 0.44f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_YapOrb", "Yap Orb", "GameObject/PropOrb.prefab", (Type)2, 4100, 8600, 26f, 115f, 1.9f, new Color(0.55f, 0.835f, 0.733f), new Color(0.804f, 0.29f, 0.79f), new Color(0.205f, 0.889f, 0.728f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_PonderingOrb", "Pondering Orb", "GameObject/Pondering Orb.prefab", (Type)2, 2200, 4800, 16f, 96f, 1.9f, new Color(0.558f, 0.321f, 0.259f), new Color(0.344f, 0.265f, 0.479f), new Color(0.592f, 0.796f, 0.488f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_BottledFairy", "Bottled Fairy", "GameObject/PropBottleFairy.prefab", (Type)2, 1900, 5900, 21f, 98f, 1.9f, new Color(0.256f, 0.719f, 0.725f), new Color(0.375f, 0.282f, 0.513f), new Color(0.77f, 0.75f, 0.282f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_Grimoire", "Grimoire", "GameObject/Book_Grimoire.prefab", (Type)2, 5200, 8400, 15f, 89f, 1.9f, new Color(0.691f, 0.242f, 0.29f), new Color(0.844f, 0.719f, 0.708f), new Color(0.629f, 0.626f, 0.18f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_Bestiary", "Bestiary", "GameObject/Book_Bestiary.prefab", (Type)2, 1500, 6000, 24f, 94f, 1.9f, new Color(0.282f, 0.886f, 0.389f), new Color(0.44f, 0.389f, 0.236f), new Color(0.485f, 0.18f, 0.445f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_PotionBook", "Potion Book", "GameObject/Book_Potions.prefab", (Type)2, 2700, 5400, 17f, 118f, 1.9f, new Color(0.533f, 0.355f, 0.852f), new Color(0.279f, 0.589f, 0.793f), new Color(0.877f, 0.883f, 0.838f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_AstralWand", "Astral Wand", "GameObject/PropWandOfAstral.prefab", (Type)2, 4200, 7100, 26f, 109f, 1.9f, new Color(0.214f, 0.671f, 0.307f), new Color(0.508f, 0.234f, 0.564f), new Color(0.282f, 0.225f, 0.451f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_FireWand", "Fire Wand", "GameObject/PropWandOfFire.prefab", (Type)2, 1300, 5000, 21f, 106f, 1.9f, new Color(0.601f, 0.745f, 0.225f), new Color(0.211f, 0.389f, 0.203f), new Color(0.358f, 0.643f, 0.604f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_TelekinesisWand", "Telekinesis Wand", "GameObject/PropWandOfTelekinesis.prefab", (Type)2, 2000, 6500, 25f, 102f, 1.9f, new Color(0.612f, 0.663f, 0.42f), new Color(0.561f, 0.742f, 0.448f), new Color(0.392f, 0.764f, 0.784f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_ExplosivePotion", "Explosive Potion", "GameObject/PropPotion_Explosive_T3.prefab", (Type)2, 3900, 9700, 11f, 94f, 1.9f, new Color(0.595f, 0.832f, 0.27f), new Color(0.759f, 0.208f, 0.892f), new Color(0.341f, 0.541f, 0.784f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_RevivePotion", "Revive Potion", "GameObject/PropPotion_Revive_T3.prefab", (Type)2, 2800, 6200, 24f, 92f, 1.9f, new Color(0.217f, 0.708f, 0.657f), new Color(0.595f, 0.649f, 0.578f), new Color(0.652f, 0.697f, 0.796f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_PowderedCrystal", "Powdered Crystal", "GameObject/PropPowderedCrystal.prefab", (Type)2, 4300, 8400, 18f, 105f, 1.9f, new Color(0.299f, 0.4f, 0.736f), new Color(0.242f, 0.516f, 0.824f), new Color(0.536f, 0.9f, 0.875f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true), new YapYapValuableDefinition("YapYapValuable_Hourglass", "Hourglass", "GameObject/Hourglass_01_phys.prefab", (Type)2, 4200, 8700, 10f, 111f, 1.9f, new Color(0.829f, 0.832f, 0.657f), new Color(0.796f, 0.236f, 0.595f), new Color(0.683f, 0.66f, 0.86f), new Vector3(0f, 0.38f, 0f), new Vector3(0.82f, 0.78f, 0.66f), playAnimationsOnGrab: true, playSoundsOnGrab: true) }; public static YapYapValuableDefinition? FindByPrefabName(string prefabName) { YapYapValuableDefinition[] all = All; foreach (YapYapValuableDefinition yapYapValuableDefinition in all) { if (string.Equals(yapYapValuableDefinition.PrefabName, prefabName, StringComparison.OrdinalIgnoreCase)) { return yapYapValuableDefinition; } } return null; } } internal static class YapYapValuableGrabBounds { private const int MaxColliderTriangles = 40; private const float MinColliderExtent = 0.015f; public static void Add(Transform root, YapYapValuableDefinition definition) { RemoveTemplateColliders(root); if (AddMeshColliders(root) == 0) { AddFallbackBox(root, definition); YapYapValuablesPlugin.Log.LogWarning((object)(definition.DisplayName + " had no usable renderer meshes for grab colliders; using fitted fallback bounds.")); } } private static int AddMeshColliders(Transform root) { int num = 0; Renderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (val.enabled && !(val is ParticleSystemRenderer)) { Mesh val2 = CreateCollisionMesh(val); if ((Object)(object)val2 == (Object)null || !HasValidCollisionShape(val2)) { DestroyMesh(val2); continue; } MeshCollider obj = ((Component)val).gameObject.AddComponent<MeshCollider>(); obj.cookingOptions = (MeshColliderCookingOptions)14; obj.convex = true; ((Collider)obj).isTrigger = false; obj.sharedMesh = val2; ConfigureColliderObject(((Component)val).gameObject); ((Component)val).gameObject.AddComponent<PhysGrabObjectCollider>(); ((Component)val).gameObject.AddComponent<PhysGrabObjectMeshCollider>().showGizmo = false; num++; } } return num; } private static Mesh? CreateCollisionMesh(Renderer renderer) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) Mesh val = null; Mesh val2 = null; SkinnedMeshRenderer val3 = (SkinnedMeshRenderer)(object)((renderer is SkinnedMeshRenderer) ? renderer : null); if (val3 != null && (Object)(object)val3.sharedMesh != (Object)null) { val2 = new Mesh { name = ((Object)renderer).name + "_YapYapGrabCollider", hideFlags = (HideFlags)61 }; try { val3.BakeMesh(val2); val = val2; } catch { val = val3.sharedMesh; } } else { MeshFilter component = ((Component)renderer).GetComponent<MeshFilter>(); if ((Object)(object)component != (Object)null && (Object)(object)component.sharedMesh != (Object)null) { val = component.sharedMesh; } } Mesh val4 = CreateReducedMesh(val, ((Object)renderer).name + "_YapYapGrabCollider"); if ((Object)(object)val4 == (Object)null && (Object)(object)val != (Object)null) { val4 = CreateBoxMesh(val.bounds, ((Object)renderer).name + "_YapYapGrabCollider"); } DestroyMesh(val2); return val4; } private static Mesh? CreateReducedMesh(Mesh? sourceMesh, string name) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: 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_0111: Expected O, but got Unknown //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_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: 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_00cb: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)sourceMesh == (Object)null) { return null; } if (!sourceMesh.isReadable) { return null; } Vector3[] vertices = sourceMesh.vertices; int[] triangles = sourceMesh.triangles; if (!HasValidVertexSet(vertices, sourceMesh.bounds) || triangles.Length < 3) { return null; } int num = triangles.Length / 3; int num2 = Mathf.Min(num, 40); Vector3[] array = (Vector3[])(object)new Vector3[num2 * 3]; int[] array2 = new int[num2 * 3]; for (int i = 0; i < num2; i++) { int num3 = ((num2 > 1) ? Mathf.RoundToInt((float)i * ((float)num - 1f) / ((float)num2 - 1f)) : 0) * 3; int num4 = i * 3; array[num4] = vertices[triangles[num3]]; array[num4 + 1] = vertices[triangles[num3 + 1]]; array[num4 + 2] = vertices[triangles[num3 + 2]]; array2[num4] = num4; array2[num4 + 1] = num4 + 1; array2[num4 + 2] = num4 + 2; } Mesh val = new Mesh { name = name, hideFlags = (HideFlags)61 }; val.vertices = array; val.triangles = array2; val.RecalculateBounds(); if (!HasValidCollisionShape(val)) { DestroyMesh(val); return null; } return val; } private static Mesh? CreateBoxMesh(Bounds bounds, string name) { //IL_0002: 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_0010: 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_0022: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: 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_00cd: 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_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0138: 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_0157: 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_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Expected O, but got Unknown Vector3 size = ((Bounds)(ref bounds)).size; if (Mathf.Max(new float[3] { size.x, size.y, size.z }) < 0.015f) { return null; } Vector3 min = ((Bounds)(ref bounds)).min; Vector3 max = ((Bounds)(ref bounds)).max; Vector3[] vertices = (Vector3[])(object)new Vector3[8] { new Vector3(min.x, min.y, min.z), new Vector3(max.x, min.y, min.z), new Vector3(max.x, max.y, min.z), new Vector3(min.x, max.y, min.z), new Vector3(min.x, min.y, max.z), new Vector3(max.x, min.y, max.z), new Vector3(max.x, max.y, max.z), new Vector3(min.x, max.y, max.z) }; int[] triangles = new int[36] { 0, 2, 1, 0, 3, 2, 4, 5, 6, 4, 6, 7, 0, 1, 5, 0, 5, 4, 2, 3, 7, 2, 7, 6, 1, 2, 6, 1, 6, 5, 3, 0, 4, 3, 4, 7 }; Mesh val = new Mesh { name = name, hideFlags = (HideFlags)61, vertices = vertices, triangles = triangles }; val.RecalculateBounds(); return val; } private static bool HasValidCollisionShape(Mesh mesh) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) if (mesh.isReadable && mesh.vertexCount >= 3) { return HasValidVertexSet(mesh.vertices, mesh.bounds); } return false; } private static bool HasValidVertexSet(IReadOnlyList<Vector3> vertices, Bounds bounds) { //IL_0002: 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_0010: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) Vector3 size = ((Bounds)(ref bounds)).size; if (Mathf.Max(new float[3] { size.x, size.y, size.z }) < 0.015f) { return false; } HashSet<Vector3Int> hashSet = new HashSet<Vector3Int>(); for (int i = 0; i < vertices.Count; i++) { Vector3 val = vertices[i]; hashSet.Add(new Vector3Int(Mathf.RoundToInt(val.x * 10000f), Mathf.RoundToInt(val.y * 10000f), Mathf.RoundToInt(val.z * 10000f))); if (hashSet.Count >= 3) { return true; } } return false; } private static void AddFallbackBox(Transform root, YapYapValuableDefinition definition) { //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_000c: 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_001e: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_0067: 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) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0110: 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_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Expected O, but got Unknown //IL_0136: Unknown result type (might be due to invalid IL or missing references) Bounds val = CalculateVisualBounds(root); GameObject val2 = new GameObject("YapYapValuableFallbackGrabBounds"); val2.transform.SetParent(root, false); val2.transform.localPosition = root.InverseTransformPoint(((Bounds)(ref val)).center); val2.transform.localRotation = Quaternion.identity; val2.transform.localScale = Vector3.one; Vector3 size = ((Bounds)(ref val)).size; Vector3 lossyScale = root.lossyScale; size.x = ((lossyScale.x == 0f) ? definition.GrabBoundsSize.x : (size.x / Mathf.Abs(lossyScale.x))); size.y = ((lossyScale.y == 0f) ? definition.GrabBoundsSize.y : (size.y / Mathf.Abs(lossyScale.y))); size.z = ((lossyScale.z == 0f) ? definition.GrabBoundsSize.z : (size.z / Mathf.Abs(lossyScale.z))); BoxCollider obj = val2.AddComponent<BoxCollider>(); obj.center = Vector3.zero; obj.size = Vector3.Max(size, Vector3.one * 0.12f); ((Collider)obj).isTrigger = false; ConfigureColliderObject(val2); val2.AddComponent<PhysGrabObjectCollider>(); val2.AddComponent<PhysGrabObjectBoxCollider>().drawGizmos = false; } private static void ConfigureColliderObject(GameObject gameObject) { gameObject.tag = "Phys Grab Object"; int num = LayerMask.NameToLayer("PhysGrabObject"); if (num >= 0) { gameObject.layer = num; } } private static Bounds CalculateVisualBounds(Transform root) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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) Renderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<Renderer>(true); Bounds bounds = default(Bounds); ((Bounds)(ref bounds))..ctor(root.position, Vector3.one * 0.3f); bool flag = false; Renderer[] array = componentsInChildren; foreach (Renderer val in array) { if (val.enabled && !(val is ParticleSystemRenderer)) { if (flag) { ((Bounds)(ref bounds)).Encapsulate(val.bounds); continue; } bounds = val.bounds; flag = true; } } return bounds; } private static void RemoveTemplateColliders(Transform root) { PhysGrabObjectCollider[] componentsInChildren = ((Component)root).GetComponentsInChildren<PhysGrabObjectCollider>(true); for (int i = 0; i < componentsInChildren.Length; i++) { DestroyComponent((Component)(object)componentsInChildren[i]); } PhysGrabObjectBoxCollider[] componentsInChildren2 = ((Component)root).GetComponentsInChildren<PhysGrabObjectBoxCollider>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { DestroyComponent((Component)(object)componentsInChildren2[i]); } PhysGrabObjectMeshCollider[] componentsInChildren3 = ((Component)root).GetComponentsInChildren<PhysGrabObjectMeshCollider>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { DestroyComponent((Component)(object)componentsInChildren3[i]); } Collider[] componentsInChildren4 = ((Component)root).GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren4.Length; i++) { DestroyComponent((Component)(object)componentsInChildren4[i]); } } private static void DestroyComponent(Component component) { if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } } private static void DestroyMesh(Mesh? mesh) { //IL_000a: 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) if ((Object)(object)mesh != (Object)null && (((Object)mesh).hideFlags & 0x3D) != 0) { Object.DestroyImmediate((Object)(object)mesh); } } } internal sealed class YapYapValuableGrabFeedback : MonoBehaviour { private readonly List<Animator> _animators = new List<Animator>(); private readonly List<Animation> _legacyAnimations = new List<Animation>(); private YapYapValuableDefinition? _definition; private YapYapValuableEffectKind _effectKind; private AudioClip[] _audioClips = Array.Empty<AudioClip>(); private AudioSource? _audioSource; private PhysGrabObject? _physGrabObject; private Transform? _visualRoot; private Light? _heldLight; private Vector3 _visualBasePosition; private Quaternion _visualBaseRotation; private Vector3 _visualBaseScale = Vector3.one; private Color _effectColor = Color.cyan; private bool _playAnimations; private bool _playSounds; private bool _wasGrabbed; private int _grabCount; private float _nextSoundTime; private float _proceduralGrabUntil; private float _customEffectUntil; private float _seed; [SerializeField] private string _prefabName = ""; public void Configure(AudioClip[] audioClips, bool playAnimations, bool playSounds) { _playAnimations = playAnimations; _playSounds = playSounds; _prefabName = ((Object)((Component)this).gameObject).name; } private void Start() { //IL_0014: 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_007d: 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) //IL_008e: 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_009f: 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) ResolveDefinition(); _effectKind = DetermineEffectKind(); _effectColor = DetermineEffectColor(); _audioClips = YapYapValuableProceduralAudio.GetClips(_effectKind); _seed = Stable01(_prefabName) * 10f; _physGrabObject = ((Component)this).GetComponent<PhysGrabObject>(); _visualRoot = ((Component)this).transform.Find("YapYapValuableVisual"); if ((Object)(object)_visualRoot != (Object)null) { _visualBasePosition = _visualRoot.localPosition; _visualBaseRotation = _visualRoot.localRotation; _visualBaseScale = _visualRoot.localScale; } if (_playAnimations) { _animators.AddRange(((Component)this).GetComponentsInChildren<Animator>(true)); _legacyAnimations.AddRange(((Component)this).GetComponentsInChildren<Animation>(true)); } if (_playSounds && _audioClips.Length != 0) { _audioSource = ((Component)this).gameObject.GetComponent<AudioSource>() ?? ((Component)this).gameObject.AddComponent<AudioSource>(); _audioSource.playOnAwake = false; _audioSource.spatialBlend = 1f; _audioSource.rolloffMode = (AudioRolloffMode)1; _audioSource.minDistance = 1.5f; _audioSource.maxDistance = 22f; _audioSource.dopplerLevel = 0f; _audioSource.volume = 0.9f; } CreateHeldLightIfUseful(); } private void Update() { if (!((Object)(object)_physGrabObject == (Object)null)) { bool flag = RepoValuableAccess.IsGrabbedForVoice(_physGrabObject); if (flag && !_wasGrabbed) { OnGrabbed(); } _wasGrabbed = flag; UpdateProceduralAnimation(flag); UpdateHeldLight(flag); } } private void OnGrabbed() { _grabCount++; _proceduralGrabUntil = Time.time + 0.72f; _customEffectUntil = Time.time + CustomEffectDuration(); PlayGrabAnimation(); PlayGrabSound(); TriggerCustomGrabLogic(); } private void PlayGrabAnimation() { //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown if (!_playAnimations) { return; } foreach (Animator animator in _animators) { if (!((Object)(object)animator == (Object)null)) { RuntimeAnimatorController runtimeAnimatorController = animator.runtimeAnimatorController; AnimationClip[] array = (((Object)(object)runtimeAnimatorController == (Object)null) ? Array.Empty<AnimationClip>() : runtimeAnimatorController.animationClips); if (array.Length == 0) { animator.Rebind(); animator.Update(0f); continue; } AnimationClip val = array[Mathf.Abs(_grabCount) % array.Length]; ((Behaviour)animator).enabled = true; animator.speed = 1f; animator.Rebind(); animator.Play(((Object)val).name, 0, 0f); animator.Update(0f); } } foreach (Animation legacyAnimation in _legacyAnimations) { if ((Object)(object)legacyAnimation == (Object)null) { continue; } { IEnumerator enumerator3 = legacyAnimation.GetEnumerator(); try { if (enumerator3.MoveNext()) { AnimationState val2 = (AnimationState)enumerator3.Current; legacyAnimation.Stop(); legacyAnimation.Play(val2.name); } } finally { IDisposable disposable = enumerator3 as IDisposable; if (disposable != null) { disposable.Dispose(); } } } } } private void UpdateProceduralAnimation(bool grabbed) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0061: 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_00ea: 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_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: 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_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_021d: 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_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_02bb: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //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_01a3: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_visualRoot == (Object)null) { return; } float num = _proceduralGrabUntil - Time.time; bool flag = num > 0f; bool flag2 = grabbed && HasHeldMotion(); if (!flag && !flag2) { _visualRoot.localPosition = _visualBasePosition; _visualRoot.localRotation = _visualBaseRotation; _visualRoot.localScale = _visualBaseScale; return; } float num2 = (flag ? Mathf.Clamp01(num / 0.72f) : 0f); float num3 = (flag ? (Mathf.Sin((1f - num2) * MathF.PI * 7f) * num2) : 0f); float num4 = (flag2 ? Mathf.Sin(Time.time * HeldMotionSpeed() + _seed) : 0f); Vector3 val = _visualBasePosition + new Vector3(0f, Mathf.Abs(num3) * 0.035f, 0f); Quaternion val2 = _visualBaseRotation * Quaternion.Euler(num3 * 9f, num3 * 14f, num3 * -7f); Vector3 val3 = _visualBaseScale * (1f + Mathf.Abs(num3) * 0.035f); switch (_effectKind) { case YapYapValuableEffectKind.Coin: val2 *= Quaternion.Euler(0f, flag ? ((1f - num2) * 720f) : 0f, 0f); break; case YapYapValuableEffectKind.Gem: case YapYapValuableEffectKind.Orb: case YapYapValuableEffectKind.Fairy: val += new Vector3(0f, num4 * 0.025f, 0f); val2 *= Quaternion.Euler(num4 * 3f, num4 * 10f, num4 * -4f); break; case YapYapValuableEffectKind.Wand: val2 *= Quaternion.Euler(num4 * 5f, 0f, num3 * 18f); break; case YapYapValuableEffectKind.Potion: val += new Vector3(0f, Mathf.Abs(num3) * 0.025f, 0f); val3 *= 1f + Mathf.Abs(num3) * 0.025f; break; case YapYapValuableEffectKind.Hourglass: val2 *= Quaternion.Euler(0f, num4 * 5f, num4 * 3f); break; case YapYapValuableEffectKind.Book: val2 *= Quaternion.Euler(num3 * -8f, 0f, num3 * 12f); break; } _visualRoot.localPosition = val; _visualRoot.localRotation = val2; _visualRoot.localScale = val3; } private void TriggerCustomGrabLogic() { //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_00ce: 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) switch (_effectKind) { case YapYapValuableEffectKind.Wand: SpawnFlash(new Vector3(0f, 0.42f, 0.2f), 3.4f, 1.8f, 0.42f); break; case YapYapValuableEffectKind.Gem: case YapYapValuableEffectKind.Orb: case YapYapValuableEffectKind.Fairy: SpawnFlash(new Vector3(0f, 0.28f, 0f), 2.6f, 1.45f, 0.55f); break; case YapYapValuableEffectKind.Potion: SpawnFlash(new Vector3(0f, 0.34f, 0f), 2.3f, 1.2f, 0.34f); break; case YapYapValuableEffectKind.Hourglass: SpawnFlash(new Vector3(0f, 0.32f, 0f), 1.8f, 1.1f, 0.48f); break; case YapYapValuableEffectKind.Coin: case YapYapValuableEffectKind.Teapot: case YapYapValuableEffectKind.Goblet: SpawnFlash(new Vector3(0f, 0.26f, 0f), 1.7f, 1.05f, 0.28f); break; case YapYapValuableEffectKind.Book: SpawnFlash(new Vector3(0f, 0.22f, 0f), 1.3f, 0.9f, 0.28f); break; case YapYapValuableEffectKind.Skeleton: case YapYapValuableEffectKind.Frog: SpawnFlash(new Vector3(0f, 0.3f, 0f), 1.6f, 1f, 0.35f); break; } } private void PlayGrabSound() { if (_playSounds && !((Object)(object)_audioSource == (Object)null) && _audioClips.Length != 0 && !(Time.time < _nextSoundTime)) { _nextSoundTime = Time.time + 0.2f; AudioClip val = _audioClips[Random.Range(0, _audioClips.Length)]; _audioSource.pitch = Random.Range(0.96f, 1.04f); _audioSource.PlayOneShot(val, 0.92f); } } private void CreateHeldLightIfUseful() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_003b: 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) if (HasHeldLight()) { GameObject val = new GameObject("YapYap Held Grab Glow"); val.transform.SetParent(((Component)this).transform, false); val.transform.localPosition = new Vector3(0f, 0.35f, 0f); _heldLight = val.AddComponent<Light>(); _heldLight.type = (LightType)2; _heldLight.color = _effectColor; _heldLight.range = 1.45f; _heldLight.intensity = 0f; ((Behaviour)_heldLight).enabled = false; } } private void UpdateHeldLight(bool grabbed) { if (!((Object)(object)_heldLight == (Object)null)) { float num = Mathf.Clamp01((_customEffectUntil - Time.time) / CustomEffectDuration()); float num2 = (grabbed ? (0.35f + Mathf.Sin(Time.time * 6.5f + _seed) * 0.12f) : 0f) + num * 1.2f; ((Behaviour)_heldLight).enabled = num2 > 0.02f; _heldLight.intensity = num2; _heldLight.range = 1.05f + num * 0.45f; } } private void SpawnFlash(Vector3 localPosition, float intensity, float range, float duration) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("YapYap Grab Flash"); val.transform.SetParent(((Component)this).transform, false); val.transform.localPosition = localPosition; Light val2 = val.AddComponent<Light>(); val2.type = (LightType)2; val2.color = _effectColor; val2.intensity = intensity; val2.range = range; val.AddComponent<YapYapValuableLightFade>().Configure(val2, duration); } private void ResolveDefinition() { if (string.IsNullOrWhiteSpace(_prefabName)) { _prefabName = ((Object)((Component)this).gameObject).name; } _definition = YapYapValuableDefinitions.FindByPrefabName(_prefabName) ?? YapYapValuableDefinitions.FindByPrefabName(((Object)((Component)this).gameObject).name); if (_definition != null) { _prefabName = _definition.PrefabName; _playAnimations = _definition.PlayAnimationsOnGrab; _playSounds = _definition.PlaySoundsOnGrab; } } private YapYapValuableEffectKind DetermineEffectKind() { string text = (_prefabName + " " + _definition?.DisplayName).ToLowerInvariant(); if (text.Contains("coin")) { return YapYapValuableEffectKind.Coin; } if (text.Contains("fairy")) { return YapYapValuableEffectKind.Fairy; } if (text.Contains("book") || text.Contains("grimoire") || text.Contains("bestiary")) { return YapYapValuableEffectKind.Book; } if (text.Contains("wand")) { return YapYapValuableEffectKind.Wand; } if (text.Contains("potion")) { return YapYapValuableEffectKind.Potion; } if (text.Contains("hourglass")) { return YapYapValuableEffectKind.Hourglass; } if (text.Contains("skeleton")) { return YapYapValuableEffectKind.Skeleton; } if (text.Contains("frog")) { return YapYapValuableEffectKind.Frog; } if (text.Contains("teapot")) { return YapYapValuableEffectKind.Teapot; } if (text.Contains("goblet")) { return YapYapValuableEffectKind.Goblet; } if (text.Contains("gem") || text.Contains("crystal")) { return YapYapValuableEffectKind.Gem; } if (text.Contains("orb") || text.Contains("globe")) { return YapYapValuableEffectKind.Orb; } return YapYapValuableEffectKind.Default; } private Color DetermineEffectColor() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_000a: 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_0068: 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_00c6: 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_0110: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) Color result = _definition?.Accent ?? Color.cyan; string text = (_prefabName + " " + _definition?.DisplayName).ToLowerInvariant(); if (text.Contains("fire") || text.Contains("explosive")) { return new Color(1f, 0.38f, 0.08f); } if (text.Contains("revive") || text.Contains("fairy")) { return new Color(0.35f, 1f, 0.75f); } if (text.Contains("coin") || text.Contains("goblet")) { return new Color(1f, 0.78f, 0.22f); } if (text.Contains("skeleton")) { return new Color(0.86f, 0.92f, 1f); } if (text.Contains("frog")) { return new Color(0.4f, 1f, 0.28f); } return result; } private bool HasHeldMotion() { switch (_effectKind) { case YapYapValuableEffectKind.Gem: case YapYapValuableEffectKind.Orb: case YapYapValuableEffectKind.Fairy: case YapYapValuableEffectKind.Wand: case YapYapValuableEffectKind.Hourglass: return true; default: return false; } } private bool HasHeldLight() { YapYapValuableEffectKind effectKind = _effectKind; if ((uint)(effectKind - 2) <= 2u || (uint)(effectKind - 6) <= 2u) { return true; } return false; } private float HeldMotionSpeed() { return _effectKind switch { YapYapValuableEffectKind.Fairy => 8.5f, YapYapValuableEffectKind.Wand => 7.5f, YapYapValuableEffectKind.Hourglass => 2.8f, _ => 4.2f, }; } private float CustomEffectDuration() { return _effectKind switch { YapYapValuableEffectKind.Fairy => 1.15f, YapYapValuableEffectKind.Orb => 1.05f, YapYapValuableEffectKind.Gem => 0.95f, YapYapValuableEffectKind.Wand => 0.75f, _ => 0.55f, }; } private static float Stable01(string value) { uint num = 2166136261u; for (int i = 0; i < value.Length; i++) { num ^= value[i]; num *= 16777619; } return (float)(num & 0xFFFFu) / 65535f; } } internal sealed class YapYapValuableGrabGlow : MonoBehaviour { private readonly List<Material> _materials = new List<Material>(); private PhysGrabObject? _physGrabObject; [SerializeField] private Color _glowColor = Color.cyan; private bool _wasGrabbed; public void Configure(Color glowColor) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) _glowColor = glowColor; } private void Start() { _physGrabObject = ((Component)this).GetComponent<PhysGrabObject>(); Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!val.enabled) { continue; } Material[] materials = val.materials; foreach (Material val2 in materials) { if ((Object)(object)val2 != (Object)null && val2.HasProperty("_EmissionColor")) { val2.EnableKeyword("_EMISSION"); _materials.Add(val2); } } } } private void Update() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_physGrabObject == (Object)null) { return; } bool flag = RepoValuableAccess.IsGrabbed(_physGrabObject); if (flag == _wasGrabbed) { return; } _wasGrabbed = flag; Color val = (flag ? (_glowColor * 1.35f) : Color.black); foreach (Material material in _materials) { if ((Object)(object)material != (Object)null) { material.SetColor("_EmissionColor", val); } } } } internal sealed class YapYapValuableLightFade : MonoBehaviour { private Light? _light; private float _startIntensity; private float _startRange; private float _duration = 0.4f; private float _startTime; public void Configure(Light lightSource, float duration) { _light = lightSource; _startIntensity = lightSource.intensity; _startRange = lightSource.range; _duration = Mathf.Max(0.05f, duration); _startTime = Time.time; } private void Update() { if ((Object)(object)_light == (Object)null) { Object.Destroy((Object)(object)((Component)this).gameObject); return; } float num = Mathf.Clamp01((Time.time - _startTime) / _duration); float num2 = 1f - num; _light.intensity = _startIntensity * num2; _light.range = Mathf.Lerp(_startRange * 0.35f, _startRange, num2); if (num >= 1f) { Object.Destroy((Object)(object)((Component)this).gameObject); } } } internal sealed class YapYapValuablePrefabFactory { private static readonly List<string> GenericPreset = new List<string> { "Valuables - Generic" }; private readonly ManualLogSource _log; private readonly Dictionary<Type, GameObject> _templates = new Dictionary<Type, GameObject>(); private GameObject? _prefabBank; public YapYapValuablePrefabFactory(ManualLogSource log) { _log = log; } public bool TryRegisterAll() { //IL_002a: 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) ResolveTemplates(); if (_templates.Count == 0) { return false; } int num = 0; YapYapValuableDefinition[] all = YapYapValuableDefinitions.All; foreach (YapYapValuableDefinition yapYapValuableDefinition in all) { GameObject template = GetTemplate(yapYapValuableDefinition.VolumeType); if ((Object)(object)template == (Object)null) { _log.LogWarning((object)$"Skipping {yapYapValuableDefinition.DisplayName}: no template valuable exists for {yapYapValuableDefinition.VolumeType}."); continue; } if (Valuables.RegisterValuable(CreatePrefab(yapYapValuableDefinition, template), GenericPreset) == null) { _log.LogWarning((object)("REPOLib rejected " + yapYapValuableDefinition.DisplayName + ".")); continue; } num++; _log.LogInfo((object)("Registered " + yapYapValuableDefinition.DisplayName + " from " + yapYapValuableDefinition.SourceReference + ".")); } return num > 0; } private void ResolveTemplates() { //IL_0031: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) _templates.Clear(); foreach (LevelValuables value in ValuablePresets.AllValuablePresets.Values) { Type[] volumeTypes = YapYapValuableVisuals.VolumeTypes; foreach (Type val in volumeTypes) { if (!_templates.ContainsKey(val)) { GameObject val2 = FindTemplateInList(RepoValuableAccess.GetList(value, val)); if ((Object)(object)val2 != (Object)null) { _templates.Add(val, val2); } } } } } private static GameObject? FindTemplateInList(List<PrefabRef>? prefabRefs) { if (prefabRefs == null) { return null; } foreach (PrefabRef prefabRef in prefabRefs) { if (prefabRef != null && prefabRef.IsValid()) { GameObject prefab = prefabRef.Prefab; if ((Object)(object)prefab != (Object)null && (Object)(object)prefab.GetComponent<ValuableObject>() != (Object)null) { return prefab; } } } return null; } private GameObject? GetTemplate(Type type) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) if (_templates.TryGetValue(type, out GameObject value) && (Object)(object)value != (Object)null) { return value; } if (_templates.TryGetValue((Type)2, out value) && (Object)(object)value != (Object)null) { return value; } foreach (GameObject value2 in _templates.Values) { if ((Object)(object)value2 != (Object)null) { return value2; } } return null; } private GameObject CreatePrefab(YapYapValuableDefinition definition, GameObject template) { //IL_0081: Unknown result type (might be due to invalid IL or missing references) GameObject val = EnsurePrefabBank(); GameObject val2 = Object.Instantiate<GameObject>(template, val.transform, false); ((Object)val2).name = definition.PrefabName; ((Object)val2).hideFlags = (HideFlags)61; val2.SetActive(true); RepoValuableAccess.ConfigureValuable(val2.GetComponent<ValuableObject>(), definition); DisableTemplateRenderers(val2); if (!YapYapValuableBundleVisuals.TryAttach(val2.transform, definition)) { YapYapValuableVisuals.Build(val2.transform, definition); } YapYapValuableGrabBounds.Add(val2.transform, definition); if (definition.GrabGlow) { (val2.GetComponent<YapYapValuableGrabGlow>() ?? val2.AddComponent<YapYapValuableGrabGlow>()).Configure(definition.Accent); } if (definition.PlayAnimationsOnGrab || definition.PlaySoundsOnGrab) { (val2.GetComponent<YapYapValuableGrabFeedback>() ?? val2.AddComponent<YapYapValuableGrabFeedback>()).Configure(YapYapValuableBundleVisuals.LoadAllAudioClips(), definition.PlayAnimationsOnGrab, definition.PlaySoundsOnGrab); } return val2; } private GameObject EnsurePrefabBank() { //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_002d: Expected O, but got Unknown if ((Object)(object)_prefabBank != (Object)null) { return _prefabBank; } _prefabBank = new GameObject("YapYapValuables Prefab Bank") { hideFlags = (HideFlags)61 }; _prefabBank.SetActive(false); Object.DontDestroyOnLoad((Object)(object)_prefabBank); return _prefabBank; } private static void DisableTemplateRenderers(GameObject prefab) { Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } } } internal enum YapYapValuableEffectKind { Default, Coin, Gem, Orb, Fairy, Book, Wand, Potion, Hourglass, Skeleton, Frog, Teapot, Goblet } internal static class YapYapValuableProceduralAudio { private const int SampleRate = 44100; private static readonly Dictionary<YapYapValuableEffectKind, AudioClip[]> Cache = new Dictionary<YapYapValuableEffectKind, AudioClip[]>(); public static AudioClip[] GetClips(YapYapValuableEffectKind kind) { if (Cache.TryGetValue(kind, out AudioClip[] value)) { return value; } value = kind switch { YapYapValuableEffectKind.Coin => (AudioClip[])(object)new AudioClip[2] { Coin("Coin A", 1f), Coin("Coin B", 1.12f) }, YapYapValuableEffectKind.Gem => (AudioClip[])(object)new AudioClip[2] { Bell("Gem A", 880f, 1318f), Bell("Gem B", 987f, 1568f) }, YapYapValuableEffectKind.Orb => (AudioClip[])(object)new AudioClip[2] { Arcane("Orb A", 420f, 940f), Arcane("Orb B", 360f, 820f) }, YapYapValuableEffectKind.Fairy => (AudioClip[])(object)new AudioClip[2] { Fairy("Fairy A", 1f), Fairy("Fairy B", 1.2f) }, YapYapValuableEffectKind.Book => (AudioClip[])(object)new AudioClip[2] { Page("Book A", 0), Page("Book B", 17) }, YapYapValuableEffectKind.Wand => (AudioClip[])(object)new AudioClip[2] { Wand("Wand A", 520f, 1500f), Wand("Wand B", 620f, 1780f) }, YapYapValuableEffectKind.Potion => (AudioClip[])(object)new AudioClip[2] { Potion("Potion A", 0), Potion("Potion B", 29) }, YapYapValuableEffectKind.Hourglass => (AudioClip[])(object)new AudioClip[2] { Sand("Hourglass A", 0), Sand("Hourglass B", 11) }, YapYapValuableEffectKind.Skeleton => (AudioClip[])(object)new AudioClip[2] { Bone("Skeleton A", 1f), Bone("Skeleton B", 0.86f) }, YapYapValuableEffectKind.Frog => (AudioClip[])(object)new AudioClip[2] { Pop("Frog A", 320f), Pop("Frog B", 380f) }, YapYapValuableEffectKind.Teapot => (AudioClip[])(object)new AudioClip[2] { Bell("Teapot A", 660f, 990f), Bell("Teapot B", 740f, 1110f) }, YapYapValuableEffectKind.Goblet => (AudioClip[])(object)new AudioClip[2] { Bell("Goblet A", 720f, 1440f), Bell("Goblet B", 810f, 1620f) }, _ => (AudioClip[])(object)new AudioClip[2] { Bell("Yap A", 620f, 1240f), Bell("Yap B", 700f, 1400f) }, }; Cache[kind] = value; return value; } private static AudioClip Coin(string name, float pitch) { return Create(name, 0.34f, (float t, int i) => Mathf.Exp((0f - t) * 8.5f) * (Sine(1120f * pitch, t) * 0.48f + Sine(2240f * pitch, t) * 0.22f)); } private static AudioClip Bell(string name, float f1, float f2) { return Create(name, 0.46f, (float t, int i) => Mathf.Exp((0f - t) * 5.7f) * (Sine(f1, t) * 0.34f + Sine(f2, t) * 0.18f + Sine(f2 * 1.5f, t) * 0.08f)); } private static AudioClip Arcane(string name, float f1, float f2) { return Create(name, 0.58f, delegate(float t, int i) { float num = Mathf.Lerp(f1, f2, Mathf.Clamp01(t / 0.58f)); return Mathf.Sin(Mathf.Clamp01(t / 0.58f) * MathF.PI) * 0.42f * (Sine(num, t) * 0.4f + Sine(num * 2.01f, t) * 0.12f); }); } private static AudioClip Fairy(string name, float pitch) { return Create(name, 0.52f, delegate(float t, int i) { float num = Mathf.Exp((0f - t) * 4.8f); float num2 = Mathf.Sin(t * 95f) * 0.06f; return num * (Sine(1320f * pitch + num2 * 400f, t) * 0.25f + Sine(1760f * pitch, t) * 0.16f); }); } private static AudioClip Page(string name, int seed) { return Create(name, 0.32f, delegate(float t, int i) { float num = Noise(i + seed) * Mathf.Sin(Mathf.Clamp01(t / 0.22f) * MathF.PI) * 0.18f; float num2 = Sine(155f, t) * Mathf.Exp((0f - Mathf.Max(0f, t - 0.18f)) * 28f) * ((t > 0.16f) ? 0.18f : 0f); return num + num2; }); } private static AudioClip Wand(string name, float f1, float f2) { return Create(name, 0.42f, delegate(float t, int i) { float num = Mathf.Clamp01(t / 0.42f); float num2 = f1 * t + (f2 - f1) * t * t / 0.84f; return Mathf.Sin(num * MathF.PI) * 0.44f * (Mathf.Sin(MathF.PI * 2f * num2) * 0.46f + Noise(i) * 0.04f); }); } private static AudioClip Potion(string name, int seed) { return Create(name, 0.38f, delegate(float t, int i) { float num = ((t < 0.05f) ? (Noise(i + seed) * (1f - t / 0.05f) * 0.34f) : 0f); float num2 = Mathf.Exp((0f - t) * 6f) * (Sine(430f, t) * 0.2f + Sine(710f, t) * 0.13f); return num + num2; }); } private static AudioClip Sand(string name, int seed) { return Create(name, 0.44f, delegate(float t, int i) { float num = Mathf.Sin(Mathf.Clamp01(t / 0.44f) * MathF.PI); return Noise(i + seed) * num * 0.11f + Sine(520f, t) * Mathf.Exp((0f - t) * 6f) * 0.12f; }); } private static AudioClip Bone(string name, float pitch) { return Create(name, 0.3f, (float t, int i) => Mathf.Exp((0f - t) * 13f) * (Sine(235f * pitch, t) * 0.3f + Sine(470f * pitch, t) * 0.14f)); } private static AudioClip Pop(string name, float baseFrequency) { return Create(name, 0.28f, (float t, int i) => Mathf.Exp((0f - t) * 9f) * (Sine(baseFrequency, t) * 0.28f + Sine(baseFrequency * 1.5f, t) * 0.1f)); } private static AudioClip Create(string name, float duration, Func<float, int, float> sample) { int num = Mathf.CeilToInt(duration * 44100f); float[] array = new float[num]; for (int i = 0; i < num; i++) { float arg = (float)i / 44100f; array[i] = Mathf.Clamp(sample(arg, i), -0.85f, 0.85f); } AudioClip obj = AudioClip.Create("YapYap " + name, num, 1, 44100, false); obj.SetData(array, 0); return obj; } private static float Sine(float frequency, float t) { return Mathf.Sin(MathF.PI * 2f * frequency * t); } private static float Noise(int value) { int num = (value ^ -1547330877) * -1640531527; int num2 = (num ^ (num >>> 16)) * -1640531527; return (float)(((uint)num2 ^ ((uint)num2 >> 16)) & 0xFFFFu) / 32767.5f - 1f; } } [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("Empress.REPO.YapYapValuables", "Yap Yap Valuables", "1.0.0")] public sealed class YapYapValuablesPlugin : BaseUnityPlugin { internal const string PluginGuid = "Empress.REPO.YapYapValuables"; internal const string PluginName = "Yap Yap Valuables"; internal const string PluginVersion = "1.0.0"; private static readonly Harmony Harmony = new Harmony("Empress.REPO.YapYapValuables"); private bool _registrationStarted; private bool _registered; internal static ManualLogSource Log { get; private set; } = null; private void Awake() { Log = ((BaseUnityPlugin)this).Logger; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); Harmony.PatchAll(typeof(YapYapValuablesPlugin).Assembly); ((MonoBehaviour)this).StartCoroutine(RegisterWhenREPOLibIsReady()); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Yap Yap Valuables v1.0.0 loaded."); } private IEnumerator RegisterWhenREPOLibIsReady() { if (!_registrationStarted) { _registrationStarted = true; while ((Object)(object)RunManager.instance == (Object)null || ValuablePresets.AllValuablePresets.Count == 0) { yield return null; } yield return null; YapYapValuableBundleVisuals.Initialize(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? string.Empty, ((BaseUnityPlugin)this).Logger); YapYapValuablePrefabFactory yapYapValuablePrefabFactory = new YapYapValuablePrefabFactory(((BaseUnityPlugin)this).Logger); _registered = yapYapValuablePrefabFactory.TryRegisterAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)(_registered ? ("Registered " + YapYapValuableDefinitions.All.Length + " generated valuables with REPOLib.") : "Generated valuables could not be registered because no vanilla valuable templates were available.")); } } } internal static class YapYapValuableVisuals { public static readonly Type[] VolumeTypes; public static void Build(Transform root, YapYapValuableDefinition definition) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_001e: 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_003e: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("YapYapValuableProceduralVisual"); val.transform.SetParent(root, false); val.transform.localPosition = Vector3.zero; val.transform.localRotation = Quaternion.identity; val.transform.localScale = Vector3.one; string text = definition.PrefabName.ToLowerInvariant(); if (text.Contains("dog")) { BuildDog(val.transform, definition); } else if (text.Contains("van")) { BuildVan(val.transform, definition); } else { BuildProp(val.transform, definition); } } private static void BuildDog(Transform root, YapYapValuableDefinition definition) { //IL_0011: 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_004f: 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) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: 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_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0107: 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) Material material = MaterialFor(definition.PrefabName + " Body", definition.Primary); Material material2 = MaterialFor(definition.PrefabName + " Accent", definition.Accent, emission: true); AddSphere(root, "Body", new Vector3(0f, 0.34f, 0f), new Vector3(0.34f, 0.2f, 0.2f), material); AddSphere(root, "Head", new Vector3(0f, 0.5f, -0.24f), new Vector3(0.18f, 0.16f, 0.16f), material); AddCube(root, "Ears", new Vector3(0f, 0.62f, -0.24f), new Vector3(0.34f, 0.06f, 0.08f), material2); AddCylinder(root, "Stand", new Vector3(0f, 0.035f, 0f), Quaternion.identity, new Vector3(0.56f, 0.035f, 0.56f), MaterialFor(definition.PrefabName + " Stand", definition.Secondary)); } private static void BuildVan(Transform root, YapYapValuableDefinition definition) { //IL_0011: 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_004b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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_00b5: 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_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_010b: 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_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0154: 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) //IL_017c: Unknown result type (might be due to invalid IL or missing references) Material material = MaterialFor(definition.PrefabName + " Body", definition.Primary); Material material2 = MaterialFor(definition.PrefabName + " Trim", definition.Secondary); Material material3 = MaterialFor(definition.PrefabName + " Lights", definition.Accent, emission: true); AddCube(root, "Body", new Vector3(0f, 0.35f, 0f), new Vector3(0.78f, 0.36f, 0.42f), material); AddCube(root, "Cabin", new Vector3(0.16f, 0.58f, 0f), new Vector3(0.4f, 0.22f, 0.38f), material2); AddCube(root, "Lights", new Vector3(0.4f, 0.36f, -0.22f), new Vector3(0.22f, 0.06f, 0.025f), material3); AddCylinder(root, "Front Wheel", new Vector3(0.26f, 0.14f, -0.25f), Quaternion.Euler(90f, 0f, 0f), new Vector3(0.13f, 0.08f, 0.13f), material2); AddCylinder(root, "Rear Wheel", new Vector3(-0.26f, 0.14f, -0.25f), Quaternion.Euler(90f, 0f, 0f), new Vector3(0.13f, 0.08f, 0.13f), material2); } private static void BuildProp(Transform root, YapYapValuableDefinition definition) { //IL_0011: 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_004b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) Material material = MaterialFor(definition.PrefabName + " Primary", definition.Primary); Material material2 = MaterialFor(definition.PrefabName + " Secondary", definition.Secondary); Material material3 = MaterialFor(definition.PrefabName + " Accent", definition.Accent, emission: true); AddCube(root, "Core", new Vector3(0f, 0.36f, 0f), new Vector3(0.5f, 0.52f, 0.38f), material); AddCube(root, "Face", new Vector3(0f, 0.42f, -0.2f), new Vector3(0.42f, 0.2f, 0.025f), material3); AddCylinder(root, "Base", new Vector3(0f, 0.035f, 0f), Quaternion.identity, new Vector3(0.58f, 0.035f, 0.58f), material2); } private static GameObject AddCube(Transform parent, string name, Vector3 localPosition, Vector3 localScale, Material material) { //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_0009: Unknown result type (might be due to invalid IL or missing references) return AddPrimitive(parent, name, (PrimitiveType)3, localPosition, Quaternion.identity, localScale, material); } private static GameObject AddSphere(Transform parent, string name, Vector3 localPosition, Vector3 localScale, Material material) { //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_0009: Unknown result type (might be due to invalid IL or missing references) return AddPrimitive(parent, name, (PrimitiveType)0, localPosition, Quaternion.identity, localScale, material); } private static GameObject AddCylinder(Transform parent, string name, Vector3 localPosition, Quaternion localRotation, Vector3 localScale, Material material) { //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_0005: Unknown result type (might be due to invalid IL or missing references) return AddPrimitive(parent, name, (PrimitiveType)2, localPosition, localRotation, localScale, material); } private static GameObject AddPrimitive(Transform parent, string name, PrimitiveType primitiveType, Vector3 localPosition, Quaternion localRotation, Vector3 localScale, Material material) { //IL_0000: 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_002c: 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) GameObject obj = GameObject.CreatePrimitive(primitiveType); ((Object)obj).name = name; obj.transform.SetParent(parent, false); obj.transform.localPosition = localPosition; obj.transform.localRotation = localRotation; obj.transform.localScale = localScale; Collider component = obj.GetComponent<Collider>(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } obj.GetComponent<Renderer>().sharedMaterial = material; return obj; } private static Material MaterialFor(string name, Color color, bool emission = false) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_003a: 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) Material val = new Material(Shader.Find("Standard")) { name = name, color = color, hideFlags = (HideFlags)61 }; if (emission) { val.EnableKeyword("_EMISSION"); val.SetColor("_EmissionColor", color * 0.85f); } return val; } static YapYapValuableVisuals() { Type[] array = new Type[7]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); VolumeTypes = (Type[])(object)array; } } }