Decompiled source of The Book Of Stones v1.0.0
plugins/OvrSlepr_TheBookOfStones.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using HarmonyLib; using Microsoft.CodeAnalysis; using PEAKLib.Core; using Peak; using Peak.Afflictions; using Photon.Pun; using Photon.Realtime; using The_Book_Of_Stones; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("OvrSlepr_TheBookOfStones")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("OvrSlepr_TheBookOfStones")] [assembly: AssemblyTitle("OvrSlepr_TheBookOfStones")] [assembly: AssemblyVersion("1.0.0.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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; } } } public class Action_BecomeStone : ItemAction { public override void RunAction() { Debug.Log((object)"[Book Of Stones] Action_BecomeStone.RunAction called!"); Character character = ((ItemActionBase)this).character; if ((Object)(object)character == (Object)null) { Debug.LogError((object)"[Book Of Stones] Character is NULL!"); } else if (character.IsLocal) { StoneTransformationSync component = ((Component)character).GetComponent<StoneTransformationSync>(); if ((Object)(object)component == (Object)null) { Debug.LogError((object)"[Book Of Stones] StoneTransformationSync not found!"); return; } bool isStone = !StoneTransformation.IsTransformed(character); component.RequestSetStoneState(isStone); } } } public class Action_BookOfStonesAnim : MonoBehaviour { public Animator? anim; public Item? item; public AudioSource? bookAudioSource; private bool usingLocal; private bool usingOnSkeleton; private void Update() { if (!((Object)(object)anim == (Object)null) && !((Object)(object)item == (Object)null) && (!Object.op_Implicit((Object)(object)item.holderCharacter) || item.holderCharacter.IsLocal) && !usingOnSkeleton) { if ((item.isUsingPrimary || item.isUsingSecondary) && !usingLocal) { Open(usingOnSkeleton: false); } else if (!item.isUsingPrimary && !item.isUsingSecondary && usingLocal) { Close(); } } } public void Open(bool usingOnSkeleton) { if (!((Object)(object)item == (Object)null)) { this.usingOnSkeleton = usingOnSkeleton; if (!usingOnSkeleton && (Object)(object)item.holderCharacter != (Object)null && item.holderCharacter.IsLocal && (Object)(object)bookAudioSource != (Object)null) { bookAudioSource.Stop(); bookAudioSource.Play(); } ((MonoBehaviourPun)item).photonView.RPC("BookOfStonesAnimRPC", (RpcTarget)0, new object[1] { true }); } } public void Close() { if (!((Object)(object)item == (Object)null)) { usingOnSkeleton = false; if ((Object)(object)item.holderCharacter != (Object)null && item.holderCharacter.IsLocal && (Object)(object)bookAudioSource != (Object)null) { bookAudioSource.Stop(); } ((MonoBehaviourPun)item).photonView.RPC("BookOfStonesAnimRPC", (RpcTarget)0, new object[1] { false }); } } [PunRPC] private void BookOfStonesAnimRPC(bool isUsing) { if (!((Object)(object)anim == (Object)null)) { anim.SetBool("Using", isUsing); usingLocal = isUsing; } } } [HarmonyPatch(typeof(Item), "CanUsePrimary")] public static class BookUsageCanUsePrimaryPatch { [HarmonyPrefix] public static bool Prefix(Item __instance, ref bool __result) { if (!BookUsageRestrictions.ShouldBlockPrimary(__instance)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(Item), "StartUsePrimary")] public static class BookUsageStartPrimaryPatch { [HarmonyPrefix] public static bool Prefix(Item __instance) { return !BookUsageRestrictions.ShouldBlockPrimary(__instance); } } public static class BookUsageRestrictions { private const ushort BookOfBonesID = 115; private const ushort BookOfStonesID = 15027; private const string UnnamedPluginGUID = "com.github.MiiMii1205.UnnamedProducts"; private const string UnnamedBookName = "UnnamedBookOfBones"; private static MethodInfo? isUnnamedMethod; private static bool unnamedMethodSearched; public static bool ShouldBlockPrimary(Item item) { if ((Object)(object)item == (Object)null) { return false; } Character holderCharacter = item.holderCharacter; if ((Object)(object)holderCharacter == (Object)null) { return false; } if (item.itemID == 15027 && holderCharacter.data.isSkeleton) { return true; } if (item.itemID == 115 && StoneTransformation.IsTransformed(holderCharacter)) { return true; } if (IsUnnamedBookOfBones(item) && StoneTransformation.IsTransformed(holderCharacter)) { return true; } return false; } private static bool IsUnnamedBookOfBones(Item item) { if ((Object)(object)item == (Object)null) { return false; } if (!Chainloader.PluginInfos.ContainsKey("com.github.MiiMii1205.UnnamedProducts")) { return false; } string name = ((Object)((Component)item).gameObject).name; if (string.IsNullOrEmpty(name) || name.IndexOf("UnnamedBookOfBones", StringComparison.OrdinalIgnoreCase) < 0) { return false; } if (!unnamedMethodSearched) { unnamedMethodSearched = true; Type type = AccessTools.TypeByName("UnnamedProducts.UnnamedPlugin"); if (type != null) { isUnnamedMethod = AccessTools.Method(type, "IsUnnamed", new Type[1] { typeof(GameObject) }, (Type[])null); } } if (isUnnamedMethod == null) { return false; } try { object obj = isUnnamedMethod.Invoke(null, new object[1] { ((Component)item).gameObject }); bool flag = default(bool); int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } catch (Exception ex) { Debug.LogWarning((object)("[Book Of Stones] Failed to check Unnamed Book of Bones: " + ex)); return false; } } } public sealed class StoneAmuletCooldownManager : MonoBehaviour { public enum AmuletType { Jump, InfiniteStamina, Healing, Clone } private class AmuletState { public int MaxCharges; public int CurrentCharges; public float CooldownEndTime; } private class CrystalVisual { public Item? Item; public Renderer? Renderer; public Material[]? OriginalMaterials; public Material? GreyMaterial; } private const float CooldownDuration = 300f; private const int CrystalMaterialIndex = 1; private readonly Dictionary<AmuletType, AmuletState> states = new Dictionary<AmuletType, AmuletState>(); private readonly Dictionary<AmuletType, List<CrystalVisual>> visuals = new Dictionary<AmuletType, List<CrystalVisual>>(); private static int GetMaxCharges(AmuletType type) { return type switch { AmuletType.Jump => 4, AmuletType.InfiniteStamina => 1, AmuletType.Healing => 2, AmuletType.Clone => 2, _ => 1, }; } private static StoneAmuletCooldownManager? GetManager(Character character) { if ((Object)(object)character == (Object)null) { return null; } StoneAmuletCooldownManager stoneAmuletCooldownManager = ((Component)character).GetComponent<StoneAmuletCooldownManager>(); if ((Object)(object)stoneAmuletCooldownManager == (Object)null) { stoneAmuletCooldownManager = ((Component)character).gameObject.AddComponent<StoneAmuletCooldownManager>(); } return stoneAmuletCooldownManager; } private AmuletState GetState(AmuletType type) { if (!states.TryGetValue(type, out AmuletState value) || value == null) { int maxCharges = GetMaxCharges(type); value = new AmuletState { MaxCharges = maxCharges, CurrentCharges = maxCharges, CooldownEndTime = 0f }; states.Add(type, value); } return value; } private void RegisterItem(AmuletType type, Item item) { if ((Object)(object)item == (Object)null) { return; } if (!visuals.TryGetValue(type, out List<CrystalVisual> value) || value == null) { value = new List<CrystalVisual>(); visuals[type] = value; } foreach (CrystalVisual item2 in value) { if ((Object)(object)item2.Item == (Object)(object)item) { return; } } Renderer[] componentsInChildren = ((Component)item).GetComponentsInChildren<Renderer>(true); Renderer[] array = componentsInChildren; foreach (Renderer val in array) { if ((Object)(object)val == (Object)null) { continue; } Material[] sharedMaterials = val.sharedMaterials; if (sharedMaterials == null || sharedMaterials.Length <= 1) { continue; } Material val2 = sharedMaterials[1]; if (!((Object)(object)val2 == (Object)null)) { CrystalVisual crystalVisual = new CrystalVisual { Item = item, Renderer = val, OriginalMaterials = sharedMaterials }; value.Add(crystalVisual); AmuletState state = GetState(type); if (state.CurrentCharges <= 0 && state.CooldownEndTime > Time.time && IsHeldByStoneCharacter(item)) { ApplyGrey(crystalVisual); } } } } private static void SetGreyProperty(Material material, string propertyName, float brightness) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0058: 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) if (material.HasProperty(propertyName)) { Color color = material.GetColor(propertyName); float num = color.r * 0.299f + color.g * 0.587f + color.b * 0.114f; num = Mathf.Clamp(num * brightness, 0.55f, 1.2f); material.SetColor(propertyName, new Color(num, num, num, color.a)); } } private static void ApplyGrey(CrystalVisual visual) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected O, but got Unknown if (visual == null || (Object)(object)visual.Renderer == (Object)null || visual.OriginalMaterials == null) { return; } Material[] originalMaterials = visual.OriginalMaterials; if (originalMaterials.Length <= 1) { return; } Material val = originalMaterials[1]; if (!((Object)(object)val == (Object)null)) { if ((Object)(object)visual.GreyMaterial == (Object)null) { Material val2 = new Material(val); ((Object)val2).name = ((Object)val).name + "_CooldownGrey"; SetGreyProperty(val2, "_Tint", 1.2f); SetGreyProperty(val2, "_BaseColor", 1.2f); SetGreyProperty(val2, "_Color1", 1.2f); SetGreyProperty(val2, "_Color2", 0.8f); SetGreyProperty(val2, "_Color3", 1.2f); SetGreyProperty(val2, "_Color", 1.2f); visual.GreyMaterial = val2; } Material[] sharedMaterials = visual.Renderer.sharedMaterials; if (sharedMaterials == null || sharedMaterials.Length <= 1 || !((Object)(object)sharedMaterials[1] == (Object)(object)visual.GreyMaterial)) { Material[] array = (Material[])originalMaterials.Clone(); array[1] = visual.GreyMaterial; visual.Renderer.sharedMaterials = array; } } } private static void RestoreCrystal(CrystalVisual visual) { if (visual != null && (Object)(object)visual.Renderer != (Object)null && visual.OriginalMaterials != null) { visual.Renderer.sharedMaterials = visual.OriginalMaterials; } } private void SetCrystalCooldown(AmuletType type, bool grey) { if (!visuals.TryGetValue(type, out List<CrystalVisual> value) || value == null) { return; } foreach (CrystalVisual item in value) { if (!((Object)(object)item.Item == (Object)null)) { if (grey && IsHeldByStoneCharacter(item.Item)) { ApplyGrey(item); } else { RestoreCrystal(item); } } } } public static bool TryUse(Character character, AmuletType type, Item item) { if ((Object)(object)character == (Object)null) { return false; } if (!character.IsLocal) { return true; } if (!StoneTransformation.IsTransformed(character)) { return true; } StoneAmuletCooldownManager manager = GetManager(character); if ((Object)(object)manager == (Object)null) { return false; } manager.RegisterItem(type, item); AmuletState state = manager.GetState(type); if (state.CooldownEndTime > 0f && Time.time >= state.CooldownEndTime) { state.CurrentCharges = state.MaxCharges; state.CooldownEndTime = 0f; manager.SetCrystalCooldown(type, grey: false); Debug.Log((object)("[Book Of Stones] Amulet recharged: " + type)); } if (state.CurrentCharges <= 0) { float num = Mathf.Max(0f, state.CooldownEndTime - Time.time); Debug.Log((object)("[Book Of Stones] Amulet is recharging: " + type.ToString() + " | Remaining: " + num.ToString("F0") + " sec")); return false; } state.CurrentCharges--; Debug.Log((object)("[Book Of Stones] Amulet charge used: " + type.ToString() + " | Charges: " + state.CurrentCharges + "/" + state.MaxCharges)); if (state.CurrentCharges <= 0) { state.CooldownEndTime = Time.time + 300f; manager.SetCrystalCooldown(type, grey: true); Debug.Log((object)("[Book Of Stones] Amulet cooldown started: " + type.ToString() + " | 300 seconds")); } return true; } private bool IsHeldByStoneCharacter(Item item) { if ((Object)(object)item == (Object)null) { return false; } Character component = ((Component)this).GetComponent<Character>(); if ((Object)(object)component == (Object)null) { return false; } return (Object)(object)item.holderCharacter == (Object)(object)component; } private void Update() { Character component = ((Component)this).GetComponent<Character>(); if ((Object)(object)component == (Object)null) { return; } foreach (KeyValuePair<AmuletType, AmuletState> state2 in states) { AmuletState value = state2.Value; if (value.CurrentCharges <= 0 && value.CooldownEndTime > 0f && Time.time >= value.CooldownEndTime) { value.CurrentCharges = value.MaxCharges; value.CooldownEndTime = 0f; SetCrystalCooldown(state2.Key, grey: false); Debug.Log((object)("[Book Of Stones] Amulet recharged: " + state2.Key)); } } foreach (KeyValuePair<AmuletType, List<CrystalVisual>> visual in visuals) { AmuletState state = GetState(visual.Key); bool flag = state.CurrentCharges <= 0 && state.CooldownEndTime > Time.time; foreach (CrystalVisual item in visual.Value) { if ((Object)(object)item.Item == (Object)null || (Object)(object)item.Renderer == (Object)null) { continue; } if (!IsHeldByStoneCharacter(item.Item)) { if ((Object)(object)item.GreyMaterial != (Object)null) { RestoreCrystal(item); } } else if (flag) { ApplyGrey(item); } else if ((Object)(object)item.GreyMaterial != (Object)null) { RestoreCrystal(item); } } } } public static void Reset(Character character) { if ((Object)(object)character == (Object)null) { return; } StoneAmuletCooldownManager manager = GetManager(character); if ((Object)(object)manager == (Object)null) { return; } foreach (List<CrystalVisual> value in manager.visuals.Values) { foreach (CrystalVisual item in value) { RestoreCrystal(item); } } manager.visuals.Clear(); manager.states.Clear(); Debug.Log((object)("[Book Of Stones] All amulet charges, cooldowns and visuals reset: " + ((Object)character).name)); } private void OnDestroy() { foreach (List<CrystalVisual> value in visuals.Values) { foreach (CrystalVisual item in value) { RestoreCrystal(item); } } visuals.Clear(); states.Clear(); } } public static class StoneBindPoseUV { public static void InspectCharacter(Character character) { if ((Object)(object)character == (Object)null) { return; } SkinnedMeshRenderer[] componentsInChildren = ((Component)character).GetComponentsInChildren<SkinnedMeshRenderer>(true); Debug.Log((object)("[Book Of Stones] Bind Pose inspection started. Renderers: " + componentsInChildren.Length)); SkinnedMeshRenderer[] array = componentsInChildren; foreach (SkinnedMeshRenderer val in array) { if (!((Object)(object)val == (Object)null) && !((Object)(object)val.sharedMesh == (Object)null)) { Mesh sharedMesh = val.sharedMesh; Debug.Log((object)("[Book Of Stones] MESH: " + ((Object)val).name + " | Vertices: " + sharedMesh.vertexCount + " | UV0: " + HasUV(sharedMesh, 0) + " | UV1: " + HasUV(sharedMesh, 1) + " | UV2: " + HasUV(sharedMesh, 2) + " | UV3: " + HasUV(sharedMesh, 3) + " | UV4: " + HasUV(sharedMesh, 4) + " | UV5: " + HasUV(sharedMesh, 5) + " | UV6: " + HasUV(sharedMesh, 6) + " | UV7: " + HasUV(sharedMesh, 7))); } } Debug.Log((object)"[Book Of Stones] Bind Pose inspection completed!"); } private static bool HasUV(Mesh mesh, int channel) { List<Vector4> list = new List<Vector4>(); mesh.GetUVs(channel, list); return list.Count == mesh.vertexCount; } } public static class StoneCameraVisibility { private const float FirstPersonDistance = 1.5f; private const string StoneShaderName = "TheBookOfStones/URP Petrified Character"; private const string FullBodyPluginGuid = "yourname.fullbodyvisible"; private static readonly int VertexGhost = Shader.PropertyToID("_VertexGhost"); private static bool initialized; private static Character cachedCharacter; private static readonly List<Material> stoneMaterials = new List<Material>(); private static readonly HashSet<Material> fullBodyStoneMaterials = new HashSet<Material>(); private static readonly Dictionary<int, bool> cameraStates = new Dictionary<int, bool>(); private static bool fullBodyReflectionInitialized; private static bool fullBodyPluginDetected; private static object fullBodyConfigEntry; private static PropertyInfo fullBodyConfigValueProperty; private static bool fullBodyRenderersFound; public static void Initialize() { if (!initialized) { RenderPipelineManager.beginCameraRendering += OnBeginCameraRendering; initialized = true; Debug.Log((object)"[Book Of Stones] Camera visibility system initialized!"); } } public static void Shutdown() { if (initialized) { RenderPipelineManager.beginCameraRendering -= OnBeginCameraRendering; } initialized = false; stoneMaterials.Clear(); fullBodyStoneMaterials.Clear(); cameraStates.Clear(); cachedCharacter = null; fullBodyRenderersFound = false; fullBodyReflectionInitialized = false; fullBodyPluginDetected = false; fullBodyConfigEntry = null; fullBodyConfigValueProperty = null; } private static void OnBeginCameraRendering(ScriptableRenderContext context, Camera camera) { //IL_0065: 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) if ((Object)(object)camera == (Object)null) { return; } Character localCharacter = Character.localCharacter; if ((Object)(object)localCharacter == (Object)null || !StoneTransformation.IsTransformed(localCharacter)) { ClearCache(); return; } RefreshMaterialsIfNeeded(localCharacter); if (stoneMaterials.Count == 0) { return; } float num = Vector3.Distance(((Component)camera).transform.position, localCharacter.Head); bool flag = num <= 1.5f; bool flag2 = flag && fullBodyRenderersFound && IsFullBodyVisibleEnabled(); float num2 = (flag ? 1f : 0f); foreach (Material stoneMaterial in stoneMaterials) { if (!((Object)(object)stoneMaterial == (Object)null)) { float num3 = num2; if (flag2 && fullBodyStoneMaterials.Contains(stoneMaterial)) { num3 = 0f; } stoneMaterial.SetFloat(VertexGhost, num3); } } int instanceID = ((Object)camera).GetInstanceID(); if (!cameraStates.TryGetValue(instanceID, out var value) || value != flag) { cameraStates[instanceID] = flag; Debug.Log((object)("[Book Of Stones] CAMERA RENDER | Camera: " + ((Object)camera).name + " | Distance: " + num + " | FirstPerson: " + flag + " | FullBodyVisible: " + flag2 + " | Ghost: " + num2)); } } private static void RefreshMaterialsIfNeeded(Character character) { bool flag = (Object)(object)cachedCharacter != (Object)(object)character || stoneMaterials.Count == 0; if (!flag) { bool flag2 = false; foreach (Material stoneMaterial in stoneMaterials) { if ((Object)(object)stoneMaterial != (Object)null) { flag2 = true; break; } } flag = !flag2; } if (!flag) { return; } stoneMaterials.Clear(); fullBodyStoneMaterials.Clear(); cachedCharacter = character; fullBodyRenderersFound = false; Renderer[] componentsInChildren = ((Component)character).GetComponentsInChildren<Renderer>(true); Renderer[] array = componentsInChildren; foreach (Renderer renderer in array) { AddStoneMaterials(renderer, stoneMaterials); } HideTheBody[] componentsInChildren2 = ((Component)character).GetComponentsInChildren<HideTheBody>(true); HideTheBody[] array2 = componentsInChildren2; foreach (HideTheBody val in array2) { if ((Object)(object)val == (Object)null) { continue; } bool flag3 = false; flag3 |= AddFullBodyRenderer((Renderer)(object)val.body); flag3 |= AddFullBodyRenderer((Renderer)(object)val.sash); flag3 |= AddFullBodyRenderer(val.medal); if (val.costumes != null) { SkinnedMeshRenderer[] costumes = val.costumes; foreach (SkinnedMeshRenderer renderer2 in costumes) { flag3 |= AddFullBodyRenderer((Renderer)(object)renderer2); } } if (flag3) { fullBodyRenderersFound = true; } } Debug.Log((object)("[Book Of Stones] Cached stone materials: " + stoneMaterials.Count + " | FullBody materials: " + fullBodyStoneMaterials.Count)); } private static bool AddFullBodyRenderer(Renderer renderer) { if ((Object)(object)renderer == (Object)null) { return false; } int count = fullBodyStoneMaterials.Count; AddStoneMaterials(renderer, fullBodyStoneMaterials); return fullBodyStoneMaterials.Count > count; } private static void AddStoneMaterials(Renderer renderer, List<Material> destination) { if ((Object)(object)renderer == (Object)null) { return; } Material[] sharedMaterials = renderer.sharedMaterials; foreach (Material val in sharedMaterials) { if (!((Object)(object)val == (Object)null) && !((Object)(object)val.shader == (Object)null) && !(((Object)val.shader).name != "TheBookOfStones/URP Petrified Character") && val.HasProperty(VertexGhost) && !destination.Contains(val)) { destination.Add(val); } } } private static void AddStoneMaterials(Renderer renderer, HashSet<Material> destination) { if ((Object)(object)renderer == (Object)null) { return; } Material[] sharedMaterials = renderer.sharedMaterials; foreach (Material val in sharedMaterials) { if (!((Object)(object)val == (Object)null) && !((Object)(object)val.shader == (Object)null) && !(((Object)val.shader).name != "TheBookOfStones/URP Petrified Character") && val.HasProperty(VertexGhost)) { destination.Add(val); } } } private static bool IsFullBodyVisibleEnabled() { if (!fullBodyReflectionInitialized) { fullBodyReflectionInitialized = true; try { if (!Chainloader.PluginInfos.ContainsKey("yourname.fullbodyvisible")) { return false; } Type type = AccessTools.TypeByName("FullBodyMod.FullBodyPlugin"); if (type == null) { return false; } FieldInfo field = type.GetField("ModEnabled", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { return false; } fullBodyConfigEntry = field.GetValue(null); if (fullBodyConfigEntry == null) { return false; } fullBodyConfigValueProperty = fullBodyConfigEntry.GetType().GetProperty("Value"); fullBodyPluginDetected = fullBodyConfigValueProperty != null; } catch (Exception ex) { Debug.LogWarning((object)("[Book Of Stones] FullBodyVisible detection failed: " + ex.Message)); fullBodyPluginDetected = false; } } if (!fullBodyPluginDetected) { return false; } try { object value = fullBodyConfigValueProperty.GetValue(fullBodyConfigEntry); return value is bool && (bool)value; } catch { return false; } } private static void ClearCache() { cachedCharacter = null; stoneMaterials.Clear(); fullBodyStoneMaterials.Clear(); cameraStates.Clear(); fullBodyRenderersFound = false; } } [HarmonyPatch(typeof(Character), "Awake")] public static class StoneCameraVisibility_InitializePatch { [HarmonyPostfix] public static void Postfix() { StoneCameraVisibility.Initialize(); } [HarmonyPostfix] public static void Postfix(Character __instance) { StoneCameraVisibility.Initialize(); if ((Object)(object)__instance != (Object)null && __instance.IsLocal) { StoneBindPoseUV.InspectCharacter(__instance); } } } [HarmonyPatch(typeof(Character), "GetMaxStamina")] public static class StoneCurseStaminaPatch { [HarmonyPostfix] public static void Postfix(Character __instance, ref float __result) { if (!((Object)(object)__instance == (Object)null) && StoneTransformation.IsTransformed(__instance)) { StoneTransformationSync component = ((Component)__instance).GetComponent<StoneTransformationSync>(); if (!((Object)(object)component == (Object)null)) { __result = Mathf.Max(0f, __result - component.StoneCurse); } } } } public static class StoneMirrorVisibility { private class SavedMaterial { public Material Material; public float OriginalGhost; } private static readonly List<SavedMaterial> savedMaterials = new List<SavedMaterial>(); private static int renderDepth; public static void BeginMirrorRender() { Character localCharacter = Character.localCharacter; if ((Object)(object)localCharacter == (Object)null || !StoneTransformation.IsTransformed(localCharacter)) { return; } if (renderDepth > 0) { renderDepth++; return; } renderDepth = 1; savedMaterials.Clear(); Renderer[] componentsInChildren = ((Component)localCharacter).GetComponentsInChildren<Renderer>(true); Renderer[] array = componentsInChildren; foreach (Renderer val in array) { if ((Object)(object)val == (Object)null) { continue; } Material[] materials = val.materials; Material[] array2 = materials; foreach (Material val2 in array2) { if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null) && !(((Object)val2.shader).name != "TheBookOfStones/URP Petrified Character") && val2.HasProperty("_VertexGhost")) { float originalGhost = val2.GetFloat("_VertexGhost"); savedMaterials.Add(new SavedMaterial { Material = val2, OriginalGhost = originalGhost }); val2.SetFloat("_VertexGhost", 0f); } } } Debug.Log((object)("[Book Of Stones] MIRROR BEGIN | Materials: " + savedMaterials.Count)); } public static void EndMirrorRender() { if (renderDepth <= 0) { return; } renderDepth--; if (renderDepth > 0) { return; } foreach (SavedMaterial savedMaterial in savedMaterials) { if (!((Object)(object)savedMaterial.Material == (Object)null) && savedMaterial.Material.HasProperty("_VertexGhost")) { savedMaterial.Material.SetFloat("_VertexGhost", savedMaterial.OriginalGhost); } } Debug.Log((object)("[Book Of Stones] MIRROR END | Restored materials: " + savedMaterials.Count)); savedMaterials.Clear(); } } [HarmonyPatch(typeof(Mirror), "OnPreRender")] public static class Mirror_OnPreRender_Patch { [HarmonyPrefix] public static void Prefix() { StoneMirrorVisibility.BeginMirrorRender(); } } [HarmonyPatch(typeof(Mirror), "OnPostRender")] public static class Mirror_OnPostRender_Patch { [HarmonyPostfix] public static void Postfix() { StoneMirrorVisibility.EndMirrorRender(); } } [HarmonyPatch(typeof(MirrorCameraScript), "RenderMirror")] public static class MirrorCameraScript_RenderMirror_Patch { [HarmonyPrefix] public static void Prefix() { StoneMirrorVisibility.BeginMirrorRender(); } [HarmonyFinalizer] public static Exception Finalizer(Exception __exception) { StoneMirrorVisibility.EndMirrorRender(); return __exception; } } [HarmonyPatch(typeof(MirrorReflection), "OnWillRenderObject")] public static class MirrorReflection_OnWillRenderObject_Patch { [HarmonyPrefix] public static void Prefix() { StoneMirrorVisibility.BeginMirrorRender(); } [HarmonyFinalizer] public static Exception Finalizer(Exception __exception) { StoneMirrorVisibility.EndMirrorRender(); return __exception; } } [HarmonyPatch(typeof(CharacterAfflictions), "AddAffliction")] public static class StoneShieldPatch { [HarmonyPrefix] public static bool Prefix(CharacterAfflictions __instance, Affliction affliction) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Invalid comparison between Unknown and I4 if (affliction == null) { return true; } Character character = __instance.character; if ((Object)(object)character == (Object)null) { return true; } if (!StoneTransformation.IsTransformed(character)) { return true; } if ((int)affliction.GetAfflictionType() == 14) { Debug.Log((object)("[Book Of Stones] Bing Bong Shield blocked: " + ((Object)character).name + " is stone.")); return false; } return true; } } [HarmonyPatch(typeof(StaminaBar), "Update")] public static class StoneStaminaBarEffect { private static readonly Color StoneColor = new Color(0.33f, 0.61f, 0.61f, 1f); private static readonly Color BrightStoneColor = new Color(0.48f, 0.82f, 0.8f, 1f); private static readonly Color StoneBacking = new Color(0.055f, 0.13f, 0.14f, 1f); private static readonly Color StoneOutline = new Color(0.22f, 0.42f, 0.43f, 1f); private static readonly Color BrightStoneOutline = new Color(0.65f, 0.92f, 0.88f, 1f); private static Character? lastCharacter; private static bool? lastStoneState; [HarmonyPostfix] [HarmonyPriority(0)] private static void Postfix(StaminaBar __instance) { //IL_015a: 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_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: 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_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.staminaBar == (Object)null) { return; } Character observedCharacter = Character.observedCharacter; bool flag = (Object)(object)observedCharacter != (Object)null && StoneTransformation.IsTransformed(observedCharacter); if ((Object)(object)observedCharacter != (Object)(object)lastCharacter || lastStoneState != flag) { Debug.Log((object)("[Book Of Stones] Stamina UI state: " + (((Object)(object)observedCharacter != (Object)null) ? ((Object)observedCharacter).name : "NULL") + " | Stone: " + flag)); lastCharacter = observedCharacter; lastStoneState = flag; } if (!flag) { return; } Image val = ((Component)__instance.staminaBar).GetComponent<Image>(); if ((Object)(object)val == (Object)null) { val = ((Component)__instance.staminaBar).GetComponentInChildren<Image>(true); } if (!((Object)(object)val == (Object)null)) { Transform obj = ((Component)__instance).transform.Find("OutlineMask/Outline/OutlineImage"); Image val2 = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null); Transform obj2 = ((Component)__instance).transform.Find("OutlineMask/Outline/OutlineCap"); Image val3 = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null); float num = (Mathf.Sin(Time.time * 2.5f) + 1f) * 0.5f; Color color = Color.Lerp(StoneColor, BrightStoneColor, num); Color color2 = Color.Lerp(StoneOutline, BrightStoneOutline, num); ((Graphic)val).color = color; if ((Object)(object)__instance.backing != (Object)null) { ((Graphic)__instance.backing).color = StoneBacking; } if ((Object)(object)val2 != (Object)null) { ((Graphic)val2).color = color2; } if ((Object)(object)val3 != (Object)null) { ((Graphic)val3).color = color2; } } } } [HarmonyPatch(typeof(Character), "UseStamina", new Type[] { typeof(float), typeof(bool), typeof(bool) })] public static class StoneStaminaMechanics { [HarmonyPrefix] private static void Prefix(Character __instance, ref float usage) { if (!((Object)(object)__instance == (Object)null) && StoneTransformation.IsTransformed(__instance)) { usage *= 0.5f; } } } [HarmonyPatch] public static class StoneStatusPatch { [HarmonyPatch(typeof(CharacterAfflictions), "AddStatus")] [HarmonyPrefix] private static bool AddStatusPrefix(CharacterAfflictions __instance, STATUSTYPE statusType) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Invalid comparison between Unknown and I4 //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Invalid comparison between Unknown and I4 //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Invalid comparison between Unknown and I4 if ((Object)(object)__instance == (Object)null) { return true; } Character value = Traverse.Create((object)__instance).Field("character").GetValue<Character>(); if ((Object)(object)value == (Object)null) { return true; } if (!StoneTransformation.IsTransformed(value)) { return true; } return (int)statusType == 13 || (int)statusType == 11 || (int)statusType == 14; } [HarmonyPatch(typeof(CharacterAfflictions), "SetStatus")] [HarmonyPrefix] private static bool SetStatusPrefix(CharacterAfflictions __instance, STATUSTYPE statusType, float amount) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Invalid comparison between Unknown and I4 if ((Object)(object)__instance == (Object)null || amount <= 0f) { return true; } Character value = Traverse.Create((object)__instance).Field("character").GetValue<Character>(); if ((Object)(object)value == (Object)null) { return true; } if (!StoneTransformation.IsTransformed(value)) { return true; } return (int)statusType == 13; } } public static class StoneTransformation { private class SavedRenderer { public Renderer Renderer; public Material[] OriginalMaterials; public bool OriginalEnabled; public MaterialPropertyBlock OriginalPropertyBlock; public List<MaterialPropertyBlock> OriginalMaterialPropertyBlocks = new List<MaterialPropertyBlock>(); } private class SavedAppearance { public List<SavedRenderer> Renderers = new List<SavedRenderer>(); public List<Material> CreatedMaterials = new List<Material>(); } [HarmonyPatch] private static class CharacterCustomizationPatch { private static MethodBase TargetMethod() { return AccessTools.Method(typeof(CharacterCustomization), "OnPlayerDataChange", (Type[])null, (Type[])null); } [HarmonyPrefix] private static void Prefix(CharacterCustomization __instance) { if (!((Object)(object)__instance == (Object)null)) { Character component = ((Component)__instance).GetComponent<Character>(); if (!((Object)(object)component == (Object)null)) { PrepareAppearanceRefresh(component); } } } [HarmonyPostfix] private static void Postfix(CharacterCustomization __instance) { if (!((Object)(object)__instance == (Object)null)) { Character component = ((Component)__instance).GetComponent<Character>(); if (!((Object)(object)component == (Object)null)) { FinishAppearanceRefresh(component); } } } } [HarmonyPatch(typeof(Character), "RPCA_ReviveAtPosition", new Type[] { typeof(Vector3), typeof(bool), typeof(int) })] private static class CharacterRevivePatch { [HarmonyPostfix] private static void Postfix(Character __instance) { RestoreStoneFormAfterRevive(__instance); } } private const float CurseReduction = 0.1f; private static readonly int CharacterRootWorldToLocalID = Shader.PropertyToID("_CharacterRootWorldToLocal"); private static readonly int StoneUVScaleID = Shader.PropertyToID("_StoneUVScale"); private static readonly int CharacterRootLocalToWorldID = Shader.PropertyToID("_CharacterRootLocalToWorld"); private static readonly Dictionary<Character, SavedAppearance> transformedPlayers = new Dictionary<Character, SavedAppearance>(); private static readonly Dictionary<Character, float> savedCurses = new Dictionary<Character, float>(); private static readonly Dictionary<Character, Dictionary<STATUSTYPE, float>> savedStatuses = new Dictionary<Character, Dictionary<STATUSTYPE, float>>(); private static readonly HashSet<Character> pendingAppearanceRefresh = new HashSet<Character>(); private static void SetCharacterRootMatrices(Renderer renderer, Transform characterRoot) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_002f: 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) if (!((Object)(object)renderer == (Object)null) && !((Object)(object)characterRoot == (Object)null)) { MaterialPropertyBlock val = new MaterialPropertyBlock(); renderer.GetPropertyBlock(val); val.SetMatrix(CharacterRootWorldToLocalID, characterRoot.worldToLocalMatrix); val.SetMatrix(CharacterRootLocalToWorldID, characterRoot.localToWorldMatrix); renderer.SetPropertyBlock(val); } } public static void RestoreStoneFormAfterRevive(Character character) { if (!((Object)(object)character == (Object)null) && character.IsLocal && !((Object)(object)character.data == (Object)null) && IsTransformed(character)) { StoneTransformationSync component = ((Component)character).GetComponent<StoneTransformationSync>(); if ((Object)(object)component != (Object)null) { component.ResetStoneCurseAfterRevive(); } character.data.SetPetrify(0); character.SetExtraStamina(0f); character.AddStamina(1f); character.ClampStamina(); if ((Object)(object)GUIManager.instance != (Object)null && (Object)(object)GUIManager.instance.bar != (Object)null) { GUIManager.instance.bar.ChangeBar(); } Debug.Log((object)("[Book Of Stones] Stone player restored after revive: " + ((Object)character).name)); } } public static void UpdateCharacterRootMatrices(Character character) { if ((Object)(object)character == (Object)null || !transformedPlayers.TryGetValue(character, out var value)) { return; } foreach (SavedRenderer renderer in value.Renderers) { if ((Object)(object)renderer.Renderer != (Object)null) { SetCharacterRootMatrices(renderer.Renderer, ((Component)character).transform); } } } private static void DebugCharacterRenderers(Character character) { if ((Object)(object)character == (Object)null || character.refs == null || (Object)(object)character.refs.customization == (Object)null) { return; } Renderer[] componentsInChildren = ((Component)character.refs.customization).GetComponentsInChildren<Renderer>(true); Debug.Log((object)"[Book Of Stones] ===== CHARACTER RENDERERS ====="); Renderer[] array = componentsInChildren; foreach (Renderer val in array) { if ((Object)(object)val == (Object)null) { continue; } SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((val is SkinnedMeshRenderer) ? val : null); string text = "No Mesh"; int num = 0; int num2 = 0; if ((Object)(object)val2 != (Object)null && (Object)(object)val2.sharedMesh != (Object)null) { text = ((Object)val2.sharedMesh).name; num = val2.sharedMesh.vertexCount; if (val2.bones != null) { num2 = val2.bones.Length; } } Debug.Log((object)("[Book Of Stones] Renderer: " + ((Object)val).name + " | Type: " + ((object)val).GetType().Name + " | Mesh: " + text + $" | Vertices: {num}" + $" | Bones: {num2}" + $" | Enabled: {val.enabled}")); } } public static void Toggle(Character character) { if (!((Object)(object)character == (Object)null)) { SetStoneState(character, !IsTransformed(character)); } } public static bool IsTransformed(Character character) { return (Object)(object)character != (Object)null && transformedPlayers.ContainsKey(character); } public static void SetStoneState(Character character, bool isStone) { if ((Object)(object)character == (Object)null) { return; } bool flag = IsTransformed(character); if (flag == isStone) { return; } if (!isStone) { pendingAppearanceRefresh.Remove(character); if (transformedPlayers.TryGetValue(character, out var value)) { RestoreAppearance(value); transformedPlayers.Remove(character); Debug.Log((object)("[Book Of Stones] Transformation removed: " + ((Object)character).name)); } if (character.IsLocal) { RestoreCurse(character); RestoreStatuses(character); RecalculateWeight(character); } return; } if ((Object)(object)Plugin.StoneMaterial == (Object)null) { Debug.LogError((object)"[Book Of Stones] Stone material is NULL!"); return; } RemoveBingBongShield(character); float value2 = 0f; bool flag2 = character.IsLocal && character.refs != null && (Object)(object)character.refs.afflictions != (Object)null; if (flag2) { value2 = character.refs.afflictions.GetCurrentStatus((STATUSTYPE)5); } ApplyAppearance(character); if (IsTransformed(character) && flag2) { savedCurses[character] = value2; SaveAndClearStatuses(character); character.refs.afflictions.SetStatus((STATUSTYPE)5, 0f, true); character.refs.afflictions.SetStatus((STATUSTYPE)7, 0f, true); Debug.Log((object)("[Book Of Stones] Curse saved and cleared: " + value2)); } } private static void RemoveBingBongShield(Character character) { if (!((Object)(object)character == (Object)null) && character.IsLocal && character.refs != null && !((Object)(object)character.refs.afflictions == (Object)null)) { CharacterAfflictions afflictions = character.refs.afflictions; Affliction val = default(Affliction); if (afflictions.HasAfflictionType((AfflictionType)14, ref val)) { afflictions.RemoveAffliction(val, false, true); Debug.Log((object)("[Book Of Stones] Bing Bong Shield removed: " + ((Object)character).name)); } } } private static void SaveAndClearStatuses(Character character) { //IL_0067: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Invalid comparison between Unknown and I4 //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Invalid comparison between Unknown and I4 //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Invalid comparison between Unknown and I4 //IL_0098: 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_0083: Invalid comparison between Unknown and I4 //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_0089: Invalid comparison between Unknown and I4 if ((Object)(object)character == (Object)null || !character.IsLocal || character.refs == null || (Object)(object)character.refs.afflictions == (Object)null) { return; } CharacterAfflictions afflictions = character.refs.afflictions; Dictionary<STATUSTYPE, float> dictionary = new Dictionary<STATUSTYPE, float>(); foreach (STATUSTYPE value in Enum.GetValues(typeof(STATUSTYPE))) { if ((int)value != 5 && (int)value != 13 && (int)value != 7 && (int)value != 9 && (int)value != 12) { float currentStatus = afflictions.GetCurrentStatus(value); if (currentStatus > 0f) { dictionary[value] = currentStatus; } afflictions.SetStatus(value, 0f, false); } } savedStatuses[character] = dictionary; afflictions.PushStatuses((Player)null); Debug.Log((object)("[Book Of Stones] Ordinary statuses saved: " + dictionary.Count)); } private static void RestoreStatuses(Character character) { //IL_0080: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)character == (Object)null || !character.IsLocal || character.refs == null || (Object)(object)character.refs.afflictions == (Object)null || !savedStatuses.TryGetValue(character, out var value)) { return; } savedStatuses.Remove(character); CharacterAfflictions afflictions = character.refs.afflictions; foreach (KeyValuePair<STATUSTYPE, float> item in value) { afflictions.SetStatus(item.Key, item.Value, false); } afflictions.PushStatuses((Player)null); character.ClampStamina(); if ((Object)(object)GUIManager.instance != (Object)null && (Object)(object)GUIManager.instance.bar != (Object)null) { GUIManager.instance.bar.ChangeBar(); } Debug.Log((object)("[Book Of Stones] Ordinary statuses restored: " + value.Count)); } private static void RestoreCurse(Character character) { if (!((Object)(object)character == (Object)null) && character.refs != null && !((Object)(object)character.refs.afflictions == (Object)null) && savedCurses.TryGetValue(character, out var value)) { savedCurses.Remove(character); float num = Mathf.Max(0f, value - 0.1f); character.refs.afflictions.SetStatus((STATUSTYPE)5, num, true); Debug.Log((object)("[Book Of Stones] Curse restored: " + num)); } } private static void RecalculateWeight(Character character) { if (!((Object)(object)character == (Object)null) && character.refs != null && !((Object)(object)character.refs.afflictions == (Object)null)) { MethodInfo methodInfo = AccessTools.Method(typeof(CharacterAfflictions), "UpdateWeight", (Type[])null, (Type[])null); if (methodInfo == null) { Debug.LogError((object)"[Book Of Stones] UpdateWeight not found!"); } else { methodInfo.Invoke(character.refs.afflictions, null); } } } private static List<Renderer> GetTargetRenderers(Character character) { List<Renderer> result = new List<Renderer>(); if ((Object)(object)character == (Object)null || character.refs == null || (Object)(object)character.refs.customization == (Object)null) { return result; } CustomizationRefs refs = character.refs.customization.refs; if ((Object)(object)refs == (Object)null) { return result; } HashSet<Renderer> processed = new HashSet<Renderer>(); HideTheBody hideTheBody = character.refs.hideTheBody; if ((Object)(object)hideTheBody != (Object)null) { AddRenderer((Renderer)(object)hideTheBody.body, result, processed); AddRenderer(hideTheBody.headRend, result, processed); } AddRenderer(refs.shorts, result, processed); AddRenderer(refs.skirt, result, processed); return result; } private static void AddRenderer(Renderer renderer, List<Renderer> result, HashSet<Renderer> processed) { if (!((Object)(object)renderer == (Object)null) && processed.Add(renderer)) { result.Add(renderer); } } private static void ApplyAppearance(Character character) { if ((Object)(object)character == (Object)null) { return; } SavedAppearance savedAppearance = new SavedAppearance(); List<Renderer> targetRenderers = GetTargetRenderers(character); Renderer referenceRenderer = null; if (character.refs != null && (Object)(object)character.refs.customization != (Object)null && (Object)(object)character.refs.customization.refs != (Object)null) { referenceRenderer = (Renderer)(object)character.refs.customization.refs.mainRenderer; } foreach (Renderer item in targetRenderers) { ApplyStoneMaterial(item, savedAppearance, ((Component)character).transform, referenceRenderer); } if (savedAppearance.Renderers.Count == 0) { Debug.LogError((object)("[Book Of Stones] No target Renderers found: " + ((Object)character).name)); DestroyCreatedMaterials(savedAppearance); return; } transformedPlayers[character] = savedAppearance; StoneMatrixUpdater stoneMatrixUpdater = ((Component)character).GetComponent<StoneMatrixUpdater>(); if ((Object)(object)stoneMatrixUpdater == (Object)null) { stoneMatrixUpdater = ((Component)character).gameObject.AddComponent<StoneMatrixUpdater>(); } stoneMatrixUpdater.Initialize(character); Debug.Log((object)("[Book Of Stones] Stone appearance applied: " + ((Object)character).name + " | Renderers: " + savedAppearance.Renderers.Count)); } private static float CalculateUVScale(Renderer renderer, Renderer referenceRenderer, Transform characterRoot) { //IL_0170: 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_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0180: 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_0188: 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_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) string text = (((Object)(object)renderer != (Object)null) ? ((Object)renderer).name : "NULL"); if ((Object)(object)renderer == (Object)null) { Debug.LogWarning((object)"[Book Of Stones] UV Scale fallback: Renderer is NULL"); return 1f; } if ((Object)(object)referenceRenderer == (Object)null) { Debug.LogWarning((object)("[Book Of Stones] UV Scale fallback: " + text + " | Reference Renderer is NULL")); return 1f; } if ((Object)(object)characterRoot == (Object)null) { Debug.LogWarning((object)("[Book Of Stones] UV Scale fallback: " + text + " | Character Root is NULL")); return 1f; } Mesh rendererMesh = GetRendererMesh(renderer); Mesh rendererMesh2 = GetRendererMesh(referenceRenderer); if ((Object)(object)rendererMesh == (Object)null) { Debug.LogWarning((object)("[Book Of Stones] UV Scale fallback: " + text + " | Mesh is NULL")); return 1f; } if ((Object)(object)rendererMesh2 == (Object)null) { Debug.LogWarning((object)("[Book Of Stones] UV Scale fallback: " + text + " | Reference Mesh is NULL")); return 1f; } if (!rendererMesh.isReadable) { Debug.LogWarning((object)("[Book Of Stones] UV Scale fallback: " + text + " | Mesh is NOT READABLE")); return 1f; } if (!rendererMesh2.isReadable) { Debug.LogWarning((object)("[Book Of Stones] UV Scale fallback: " + text + " | Reference Mesh is NOT READABLE")); return 1f; } Matrix4x4 meshMatrix = characterRoot.worldToLocalMatrix * renderer.localToWorldMatrix; Matrix4x4 meshMatrix2 = characterRoot.worldToLocalMatrix * referenceRenderer.localToWorldMatrix; float num = CalculateMeshDensity(rendererMesh, meshMatrix); float num2 = CalculateMeshDensity(rendererMesh2, meshMatrix2); Debug.Log((object)("[Book Of Stones] UV Density: " + text + " | " + $"Mesh: {num:F6} | " + $"Reference ({((Object)referenceRenderer).name}): {num2:F6}")); if (num <= 0f) { Debug.LogWarning((object)("[Book Of Stones] UV Scale fallback: " + text + " | Mesh Density is ZERO or INVALID")); return 1f; } if (num2 <= 0f) { Debug.LogWarning((object)("[Book Of Stones] UV Scale fallback: " + text + " | Reference Density is ZERO or INVALID")); return 1f; } float num3 = Mathf.Sqrt(num / num2); num3 = Mathf.Clamp(num3, 0.25f, 8f); Debug.Log((object)$"[Book Of Stones] UV Scale calculated: {text} = {num3:F6}"); return num3; } private static Mesh GetRendererMesh(Renderer renderer) { if ((Object)(object)renderer == (Object)null) { return null; } SkinnedMeshRenderer val = (SkinnedMeshRenderer)(object)((renderer is SkinnedMeshRenderer) ? renderer : null); if (val != null) { return val.sharedMesh; } MeshFilter component = ((Component)renderer).GetComponent<MeshFilter>(); return ((Object)(object)component != (Object)null) ? component.sharedMesh : null; } private static float CalculateMeshDensity(Mesh mesh, Matrix4x4 meshMatrix) { //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_00b5: 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_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: 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_00dc: 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_00e3: 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_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: 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) Vector3[] vertices = mesh.vertices; Vector2[] uv = mesh.uv; int[] triangles = mesh.triangles; if (vertices.Length == 0 || uv.Length != vertices.Length || triangles.Length < 3) { return 0f; } double num = 0.0; double num2 = 0.0; for (int i = 0; i < triangles.Length; i += 3) { int num3 = triangles[i]; int num4 = triangles[i + 1]; int num5 = triangles[i + 2]; if (num3 >= 0 && num4 >= 0 && num5 >= 0 && num3 < vertices.Length && num4 < vertices.Length && num5 < vertices.Length) { Vector3 val = ((Matrix4x4)(ref meshMatrix)).MultiplyPoint3x4(vertices[num3]); Vector3 val2 = ((Matrix4x4)(ref meshMatrix)).MultiplyPoint3x4(vertices[num4]); Vector3 val3 = ((Matrix4x4)(ref meshMatrix)).MultiplyPoint3x4(vertices[num5]); double num6 = num; Vector3 val4 = Vector3.Cross(val2 - val, val3 - val); num = num6 + (double)((Vector3)(ref val4)).magnitude * 0.5; num2 += (double)Mathf.Abs((uv[num4].x - uv[num3].x) * (uv[num5].y - uv[num3].y) - (uv[num5].x - uv[num3].x) * (uv[num4].y - uv[num3].y)) * 0.5; } } if (num <= 1E-06 || num2 <= 1E-06) { return 0f; } return (float)(num / num2); } private static void ApplyStoneMaterial(Renderer renderer, SavedAppearance appearance, Transform characterRoot, Renderer referenceRenderer) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown if ((Object)(object)renderer == (Object)null || (Object)(object)Plugin.StoneMaterial == (Object)null) { return; } Material[] sharedMaterials = renderer.sharedMaterials; if (sharedMaterials != null && sharedMaterials.Length != 0) { SavedRenderer item = CaptureRenderer(renderer); appearance.Renderers.Add(item); Material val = new Material(Plugin.StoneMaterial); ((Object)val).name = "BookOfStones_" + ((Object)renderer).name; appearance.CreatedMaterials.Add(val); float num = 1f; if ((Object)(object)renderer != (Object)null && (Object)(object)referenceRenderer != (Object)null && (Object)(object)renderer != (Object)(object)referenceRenderer) { num = CalculateUVScale(renderer, referenceRenderer, characterRoot); } val.SetFloat(StoneUVScaleID, num); Debug.Log((object)$"[Book Of Stones] UV Scale: {((Object)renderer).name} = {num:F3}"); Material[] array = (Material[])(object)new Material[sharedMaterials.Length]; for (int i = 0; i < array.Length; i++) { array[i] = val; } renderer.sharedMaterials = array; renderer.SetPropertyBlock((MaterialPropertyBlock)null); for (int j = 0; j < array.Length; j++) { renderer.SetPropertyBlock((MaterialPropertyBlock)null, j); } SetCharacterRootMatrices(renderer, characterRoot); } } private static SavedRenderer CaptureRenderer(Renderer renderer) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown SavedRenderer savedRenderer = new SavedRenderer { Renderer = renderer, OriginalMaterials = renderer.sharedMaterials, OriginalEnabled = renderer.enabled, OriginalPropertyBlock = new MaterialPropertyBlock() }; renderer.GetPropertyBlock(savedRenderer.OriginalPropertyBlock); for (int i = 0; i < savedRenderer.OriginalMaterials.Length; i++) { MaterialPropertyBlock val = new MaterialPropertyBlock(); renderer.GetPropertyBlock(val, i); savedRenderer.OriginalMaterialPropertyBlocks.Add(val); } return savedRenderer; } private static void PrepareAppearanceRefresh(Character character) { if (IsTransformed(character) && !pendingAppearanceRefresh.Contains(character) && transformedPlayers.TryGetValue(character, out var value)) { RestoreRendererEntries(value); value.Renderers.Clear(); pendingAppearanceRefresh.Add(character); } } private static void FinishAppearanceRefresh(Character character) { if ((Object)(object)character == (Object)null || !pendingAppearanceRefresh.Remove(character) || !transformedPlayers.TryGetValue(character, out var value)) { return; } DestroyCreatedMaterials(value); List<Renderer> targetRenderers = GetTargetRenderers(character); Renderer referenceRenderer = null; if (character.refs != null && (Object)(object)character.refs.customization != (Object)null && (Object)(object)character.refs.customization.refs != (Object)null) { referenceRenderer = (Renderer)(object)character.refs.customization.refs.mainRenderer; } foreach (Renderer item in targetRenderers) { ApplyStoneMaterial(item, value, ((Component)character).transform, referenceRenderer); } Debug.Log((object)("[Book Of Stones] Appearance refreshed: " + ((Object)character).name + " | Renderers: " + value.Renderers.Count)); } private static void RestoreAppearance(SavedAppearance appearance) { if (appearance != null) { RestoreRendererEntries(appearance); DestroyCreatedMaterials(appearance); appearance.Renderers.Clear(); } } private static void RestoreRendererEntries(SavedAppearance appearance) { if (appearance == null) { return; } foreach (SavedRenderer renderer in appearance.Renderers) { if ((Object)(object)renderer.Renderer == (Object)null) { continue; } renderer.Renderer.sharedMaterials = renderer.OriginalMaterials; renderer.Renderer.enabled = renderer.OriginalEnabled; renderer.Renderer.SetPropertyBlock((MaterialPropertyBlock)null); for (int i = 0; i < renderer.OriginalMaterialPropertyBlocks.Count; i++) { renderer.Renderer.SetPropertyBlock(renderer.OriginalMaterialPropertyBlocks[i], i); } if (!((Object)renderer.Renderer).name.ToLower().Contains("head")) { continue; } Debug.Log((object)("[Book Of Stones] HEAD RESTORE: " + ((Object)renderer.Renderer).name)); Material[] sharedMaterials = renderer.Renderer.sharedMaterials; foreach (Material val in sharedMaterials) { if ((Object)(object)val == (Object)null) { Debug.LogError((object)"[Book Of Stones] HEAD MATERIAL IS NULL!"); continue; } Debug.Log((object)("[Book Of Stones] HEAD MATERIAL: " + ((Object)val).name + " | Shader: " + (((Object)(object)val.shader != (Object)null) ? ((Object)val.shader).name : "NULL") + " | Shader Supported: " + ((Object)(object)val.shader != (Object)null && val.shader.isSupported))); } } } private static void DestroyCreatedMaterials(SavedAppearance appearance) { if (appearance == null) { return; } foreach (Material createdMaterial in appearance.CreatedMaterials) { if ((Object)(object)createdMaterial != (Object)null) { Object.Destroy((Object)(object)createdMaterial); } } appearance.CreatedMaterials.Clear(); } } public sealed class StoneMatrixUpdater : MonoBehaviour { private Character character; public void Initialize(Character target) { character = target; } private void LateUpdate() { if ((Object)(object)character == (Object)null) { Object.Destroy((Object)(object)this); } else if (!StoneTransformation.IsTransformed(character)) { Object.Destroy((Object)(object)this); } else { StoneTransformation.UpdateCharacterRootMatrices(character); } } } public class StoneTransformationSync : MonoBehaviourPunCallbacks { [HarmonyPatch(typeof(Character), "Awake")] public static class StoneTransformationSyncPatch { [HarmonyPostfix] private static void Postfix(Character __instance) { if (!((Object)(object)__instance == (Object)null) && !((Object)(object)((MonoBehaviourPun)__instance).photonView == (Object)null) && (Object)(object)((Component)__instance).GetComponent<StoneTransformationSync>() == (Object)null) { ((Component)__instance).gameObject.AddComponent<StoneTransformationSync>(); Debug.Log((object)("[Book Of Stones] StoneTransformationSync added to: " + ((Object)__instance).name)); } } } [HarmonyPatch(typeof(CharacterAfflictions), "AddPetrify", new Type[] { typeof(int) })] public static class StonePetrifyPatch { [HarmonyPrefix] private static bool Prefix(CharacterAfflictions __instance, int petrify) { if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.character == (Object)null) { return true; } Character character = __instance.character; if (!StoneTransformation.IsTransformed(character)) { return true; } StoneTransformationSync component = ((Component)character).GetComponent<StoneTransformationSync>(); if ((Object)(object)component == (Object)null) { return true; } component.HandleStonePetrify((float)petrify / 100f); if (petrify > 0) { component.PlayVanillaPetrifyEffects(); } return false; } } [HarmonyPatch(typeof(Action_SuperJumpAmulet), "RunAction")] public static class StoneSuperJumpAmuletPatch { private static readonly FieldInfo? ItemField = AccessTools.Field(typeof(ItemActionBase), "item"); [HarmonyPrefix] private static bool Prefix(Action_SuperJumpAmulet __instance) { if ((Object)(object)__instance == (Object)null) { return true; } if (ItemField == null) { Debug.LogError((object)"[Book Of Stones] Could not find ItemActionBase.item!"); return true; } object? value = ItemField.GetValue(__instance); Item val = (Item)((value is Item) ? value : null); if ((Object)(object)val == (Object)null || (Object)(object)val.holderCharacter == (Object)null) { return true; } Character holderCharacter = val.holderCharacter; Debug.Log((object)("[Book Of Stones][DEBUG] SuperJump called! | Item: " + ((Object)((Component)val).gameObject).name + " | IsStone: " + StoneTransformation.IsTransformed(holderCharacter))); if (!StoneTransformation.IsTransformed(holderCharacter)) { return true; } StoneTransformationSync component = ((Component)holderCharacter).GetComponent<StoneTransformationSync>(); if ((Object)(object)component == (Object)null) { Debug.LogError((object)"[Book Of Stones] StoneTransformationSync not found!"); return false; } if (!StoneAmuletCooldownManager.TryUse(holderCharacter, StoneAmuletCooldownManager.AmuletType.Jump, val)) { return false; } if (UnnamedAmuletSupport.IsUnnamedAmulet(val, "UnnamedAmulet_SuperJump")) { float petrifyAmount = Random.Range(0.02f, 0.1f); component.HandleStonePetrify(petrifyAmount); } else { component.HandleStonePetrify(0.075f); } return false; } } [HarmonyPatch(typeof(Action_ModifyStatus), "RunAction")] public static class StoneModifyStatusPatch { private static readonly FieldInfo? ItemField = AccessTools.Field(typeof(ItemActionBase), "item"); [HarmonyPrefix] private static bool Prefix(Action_ModifyStatus __instance) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Invalid comparison between Unknown and I4 if ((Object)(object)__instance == (Object)null) { return true; } if (ItemField == null) { Debug.LogError((object)"[Book Of Stones] Could not find ItemActionBase.item!"); return true; } object? value = ItemField.GetValue(__instance); Item val = (Item)((value is Item) ? value : null); if ((Object)(object)val == (Object)null || (Object)(object)val.holderCharacter == (Object)null) { return true; } Character holderCharacter = val.holderCharacter; if (!StoneTransformation.IsTransformed(holderCharacter)) { return true; } if ((int)__instance.statusType == 13 && __instance.changeAmount > 0f) { StoneTransformationSync component = ((Component)holderCharacter).GetComponent<StoneTransformationSync>(); if ((Object)(object)component == (Object)null) { Debug.LogError((object)"[Book Of Stones] StoneTransformationSync not found!"); return false; } if (!StoneAmuletCooldownManager.TryUse(holderCharacter, StoneAmuletCooldownManager.AmuletType.InfiniteStamina, val)) { return false; } if (UnnamedAmuletSupport.IsUnnamedAmulet(val, "UnnamedAmulet_InfiniteStamina")) { float petrifyAmount = Random.Range(0.02f, 0.5f); component.HandleStonePetrify(petrifyAmount); } else { component.HandleStonePetrify(0.3f); } } return false; } } [HarmonyPatch(typeof(Action_HealingGem), "RunAction")] public static class StoneHealingGemPatch { private static readonly FieldInfo? ItemField = AccessTools.Field(typeof(ItemActionBase), "item"); [HarmonyPrefix] private static bool Prefix(Action_HealingGem __instance) { if ((Object)(object)__instance == (Object)null) { return true; } if (ItemField == null) { Debug.LogError((object)"[Book Of Stones] Could not find ItemActionBase.item!"); return true; } object? value = ItemField.GetValue(__instance); Item val = (Item)((value is Item) ? value : null); if ((Object)(object)val == (Object)null || (Object)(object)val.holderCharacter == (Object)null) { return true; } Character holderCharacter = val.holderCharacter; Debug.Log((object)("[Book Of Stones][DEBUG] HealingGem called! | Item: " + ((Object)((Component)val).gameObject).name + " | IsStone: " + StoneTransformation.IsTransformed(holderCharacter))); if (!StoneTransformation.IsTransformed(holderCharacter)) { return true; } StoneTransformationSync component = ((Component)holderCharacter).GetComponent<StoneTransformationSync>(); if ((Object)(object)component == (Object)null) { Debug.LogError((object)"[Book Of Stones] StoneTransformationSync not found!"); return false; } if (!StoneAmuletCooldownManager.TryUse(holderCharacter, StoneAmuletCooldownManager.AmuletType.Healing, val)) { return false; } if (UnnamedAmuletSupport.IsUnnamedAmulet(val, "UnnamedAmulet_Healing")) { float petrifyAmount = Random.Range(0.02f, 0.6f); component.HandleStonePetrify(petrifyAmount); } else { component.HandleStonePetrify(0.1f); } return false; } } [HarmonyPatch(typeof(Action_ApplyAffliction), "RunAction")] public static class StoneApplyAfflictionPatch { private static readonly FieldInfo? ItemField = AccessTools.Field(typeof(ItemActionBase), "item"); [HarmonyPrefix] private static bool Prefix(Action_ApplyAffliction __instance) { if ((Object)(object)__instance == (Object)null) { return true; } object? obj = ItemField?.GetValue(__instance); Item val = (Item)((obj is Item) ? obj : null); if ((Object)(object)val == (Object)null || (Object)(object)val.holderCharacter == (Object)null) { return true; } Character holderCharacter = val.holderCharacter; if (!StoneTransformation.IsTransformed(holderCharacter)) { return true; } string name = ((Object)((Component)val).gameObject).name; if (name.IndexOf("Amulet_InfiniteStamina", StringComparison.OrdinalIgnoreCase) >= 0) { Debug.Log((object)("[Book Of Stones] Infinite Stamina aura blocked: " + name)); return false; } return true; } } [HarmonyPatch(typeof(Action_CloneSelectedItem), "RunAction")] public static class StoneCloneSelectedItemPatch { private const string UnnamedPluginGUID = "com.github.MiiMii1205.UnnamedProducts"; private static readonly FieldInfo? ItemField = AccessTools.Field(typeof(ItemActionBase), "item"); public static void PatchUnnamedClone(Harmony harmony) { //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown if (!Chainloader.PluginInfos.ContainsKey("com.github.MiiMii1205.UnnamedProducts")) { Debug.Log((object)"[Book Of Stones] Unnamed Products not found. Patch skipped."); return; } Type type = AccessTools.TypeByName("UnnamedProducts.Behaviours.Action_UnnamedCloneSelectedItem"); if (type == null) { Debug.LogWarning((object)"[Book Of Stones] Unnamed Clone type not found!"); return; } MethodInfo methodInfo = AccessTools.DeclaredMethod(type, "RunAction", (Type[])null, (Type[])null); if (methodInfo == null) { Debug.LogWarning((object)"[Book Of Stones] Unnamed Clone RunAction not found!"); return; } harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(StoneCloneSelectedItemPatch), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Debug.Log((object)"[Book Of Stones] Unnamed Clone patch installed!"); } [HarmonyPrefix] private static bool Prefix(Action_CloneSelectedItem __instance) { //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_020f: 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_0256: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_029e: 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_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0143: 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_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null) { return true; } object? obj = ItemField?.GetValue(__instance); Item val = (Item)((obj is Item) ? obj : null); if ((Object)(object)val == (Object)null || (Object)(object)val.holderCharacter == (Object)null) { return true; } Character holderCharacter = val.holderCharacter; Debug.Log((object)("[Book Of Stones][DEBUG] CloneSelectedItem called! | Item: " + ((Object)((Component)val).gameObject).name + " | IsStone: " + StoneTransformation.IsTransformed(holderCharacter))); if (!StoneTransformation.IsTransformed(holderCharacter)) { return true; } bool flag = false; Vector3 val2 = Vector3.zero; if (holderCharacter.IsLocal) { IInteractible val3 = default(IInteractible); Interaction.instance.DoInteractableRaycasts(ref val3, __instance.range, false); if (val3 != null) { Item val4 = (Item)(object)((val3 is Item) ? val3 : null); if ((Object)(object)val4 != (Object)null) { if (((Enum)val4.itemTags).HasFlag((Enum)(object)(ItemTags)512) || ((Enum)val4.itemTags).HasFlag((Enum)(object)(ItemTags)2048)) { return false; } int num = (((Enum)val4.itemTags).HasFlag((Enum)(object)(ItemTags)1) ? __instance.petrifyMystical : __instance.petrify); StoneTransformationSync component = ((Component)holderCharacter).GetComponent<StoneTransformationSync>(); if ((Object)(object)component == (Object)null) { Debug.LogError((object)"[Book Of Stones] StoneTransformationSync not found!"); return false; } if (!StoneAmuletCooldownManager.TryUse(holderCharacter, StoneAmuletCooldownManager.AmuletType.Clone, val)) { return false; } component.HandleStonePetrify((float)num / 100f); flag = true; val2 = val4.rig.worldCenterOfMass - ((Component)MainCamera.instance).transform.forward * 0.5f; } } } if (!flag) { Transform transform = ((Component)MainCamera.instance).transform; int num2 = -2; RaycastHit val5 = default(RaycastHit); val2 = ((!Physics.Raycast(transform.position, transform.forward, ref val5, 1000f, num2)) ? (transform.position + transform.forward * 4f) : ((!(Vector3.Distance(((RaycastHit)(ref val5)).point, transform.position) < 4f)) ? (transform.position + transform.forward * 4f) : ((RaycastHit)(ref val5)).point)); } ((MonoBehaviourPun)val).photonView.RPC("RPCA_Shoot", (RpcTarget)0, new object[2] { val2, flag }); return false; } } public const float InitialStoneCurse = 0.1f; private AudioSource? stoneCurseAudioSource; private AudioSource? stoneTransformationAudioSource; private Coroutine? stoneTransformationSoundFollowRoutine; private const float StoneCurseIncrease = 0.2f; private const float NormalStoneCurseInterval = 115f; private const float HighStoneCurseInterval = 75f; private float stoneCurse = 0f; private Coroutine? stoneCurseRoutine; private static readonly MethodInfo StatusSFXMethod = AccessTools.Method(typeof(CharacterAfflictions), "StatusSFX", (Type[])null, (Type[])null); private float StoneCurseInterval => (Ascents.currentAscent >= 6) ? 75f : 115f; public float StoneCurse => stoneCurse; public void RequestSetStoneState(bool isStone) { if ((Object)(object)((MonoBehaviourPun)this).photonView == (Object)null) { Debug.LogError((object)"[Book Of Stones] PhotonView is NULL!"); return; } if (!((MonoBehaviourPun)this).photonView.IsMine) { Debug.LogWarning((object)"[Book Of Stones] Cannot change stone state: this client does not own the character."); return; } Character component = ((Component)this).GetComponent<Character>(); if ((Object)(object)component == (Object)null) { Debug.LogError((object)"[Book Of Stones] Character not found!"); return; } bool flag = StoneTransformation.IsTransformed(component); if (flag && (Object)(object)component.data != (Object)null && component.data.petrifyAmount > 0) { int petrifyAmount = component.data.petrifyAmount; component.data.SetPetrify(0); Debug.Log((object)("[Book Of Stones] Cleared normal Petrify from stone character: " + ((Object)component).name + " | Previous Petrify: " + petrifyAmount)); } if (isStone && !flag && component.IsLocal) { PlayStoneTransformationSound(); } if (isStone && !flag) { SetStoneCurse(0.1f); } Debug.Log((object)("[Book Of Stones] Sending stone state: " + isStone)); if (isStone) { PlayStoneTransformationScreenFX(reverse: false); } ((MonoBehaviourPun)this).photonView.RPC("RPC_SetStoneState", (RpcTarget)0, new object[1] { isStone }); } private void CheckMaximumStoneCurse() { if (!(stoneCurse < 1f) && !((Object)(object)((MonoBehaviourPun)this).photonView == (Object)null) && ((MonoBehaviourPun)this).photonView.IsMine) { Character component = ((Component)this).GetComponent<Character>(); if (!((Object)(object)component == (Object)null) && StoneTransformation.IsTransformed(component) && !((Object)(object)component.data == (Object)null) && component.data.petrifyAmount < 100) { Debug.Log((object)("[StoneCurse] Maximum reached! Applying 100% Petrify to " + ((Object)component).name)); component.data.SetPetrify(100); PlayVanillaPetrifyEffects(); } } } private void PlayVanillaPetrifyEffects() { Character component = ((Component)this).GetComponent<Character>(); if ((Object)(object)component == (Object)null || !component.IsLocal) { return; } CharacterAfflictions afflictions = component.refs.afflictions; if (!((Object)(object)afflictions == (Object)null)) { if (StatusSFXMethod == null) { Debug.LogError((object)"[Book Of Stones] StatusSFX method not found!"); return; } StatusSFXMethod.Invoke(afflictions, new object[2] { (object)(STATUSTYPE)13, 1f }); afflictions.PlayParticle((STATUSTYPE)13); } } private void PlayStoneTransformationSound() { //IL_0104: 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_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Expected O, but got Unknown Character component = ((Component)this).GetComponent<Character>(); if ((Object)(object)component == (Object)null || !component.IsLocal) { return; } AudioClip stoneTransformationSound = Plugin.StoneTransformationSound; if ((Object)(object)stoneTransformationSound == (Object)null) { Debug.LogWarning((object)"[Book Of Stones] Transformation sound is not loaded!"); return; } Bodypart val = component.refs.ragdoll.partDict[(BodypartType)2]; if ((Object)(object)val == (Object)null || (Object)(object)val.Rig == (Object)null) { Debug.LogError((object)"[Book Of Stones] Could not find Torso Rigidbody!"); return; } if (stoneTransformationSoundFollowRoutine != null) { ((MonoBehaviour)this).StopCoroutine(stoneTransformationSoundFollowRoutine); stoneTransformationSoundFollowRoutine = null; } if ((Object)(object)stoneTransformationAudioSource == (Object)null) { GameObject val2 = new GameObject("StoneTransformationAudio"); stoneTransformationAudioSource = val2.AddComponent<AudioSource>(); } AudioSource val3 = stoneTransformationAudioSource; ((Component)val3).transform.SetParent((Transform)null); ((Component)val3).transform.position = val.Rig.position; ((Component)val3).transform.rotation = Quaternion.identity; val3.playOnAwake = false; val3.loop = false; val3.spatialBlend = 1f; val3.volume = 1f; val3.pitch = 1f; val3.rolloffMode = (AudioRolloffMode)0; val3.minDistance = 5f; val3.maxDistance = 50f; val3.Stop(); val3.PlayOneShot(stoneTransformationSound); stoneTransformationSoundFollowRoutine = ((MonoBehaviour)this).StartCoroutine(FollowStoneTransformationSound(val3, val, stoneTransformationSound.length)); Debug.Log((object)("[Book Of Stones] Transformation sound following: " + ((Object)component).name)); } private IEnumerator FollowStoneTransformationSound(AudioSource source, Bodypart torso, float duration) { float elapsed = 0f; while (elapsed < duration && (Object)(object)source != (Object)null && (Object)(object)torso != (Object)null && (Object)(object)torso.Rig != (Object)null) { ((Component)source).transform.position = torso.Rig.position; elapsed += Time.deltaTime; yield return null; } stoneTransformationSoundFollowRoutine = null; } private void PlayStoneCurseApplySound(Character character) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown if (!character.IsLocal) { return; } AudioClip stoneCurseApplySound = Plugin.StoneCurseApplySound; if ((Object)(object)stoneCurseApplySound == (Object)null) { Debug.LogWarning((object)"[Book Of Stones] StoneCurse sound is not loaded!"); return; } if ((Object)(object)stoneCurseAudioSource == (Object)null) { GameObject val = new GameObject("StoneCurseApplyAudio"); stoneCurseAudioSource = val.AddComponent<AudioSource>(); } AudioSource val2 = stoneCurseAudioSource; ((Component)val2).transform.position = Vector3.zero; val2.playOnAwake = false; val2.loop = false; val2.spatialBlend = 0f; val2.volume = 0.1f; val2.pitch = 1f; val2.Stop(); val2.PlayOneShot(stoneCurseApplySound); } private IEnumerator FollowStoneCurseSound(AudioSource source, Bodypart torso, float duration) { float elapsed = 0f; while (elapsed < duration && (Object)(object)source != (Object)null && (Object)(object)torso != (Object)null) { ((Component)source).transform.position = torso.Rig.position; elapsed += Time.deltaTime; yield return null; } } private void PlayStoneTransformationScreenFX(bool reverse) { Character component = ((Component)this).GetComponent<Character>(); if ((Object)(object)component == (Object)null || !component.IsLocal) { return; } GUIManager instance = GUIManager.instance; if (!((Object)(object)instance == (Object)null)) { if ((Object)(object)instance.petrifySVFXFull == (Object)null || (Object)(object)instance.petrifySVFX2Full == (Object)null) { Debug.LogError((object)"[Book Of Stones] Petrify ScreenVFX references are missing!"); } else if (reverse) { instance.petrifySVFXFull.EndFX(); instance.petrifySVFX2Full.EndFX(); } else { instance.petrifySVFXFull.Play(1f, true); instance.petrifySVFX2Full.Play(1f, true); } } } [PunRPC] public void RPC_SetStoneState(bool isStone) { Character component = ((Component)this).GetComponent<Character>(); if ((Object)(object)component == (Object)null) { Debug.LogError((object)"[Book Of Stones] Character not found on sync component!"); return; } bool flag = StoneTransformation.IsTransformed(component); Debug.Log((object)("[Book Of Stones] Received stone state: " + isStone + " | Character: " + ((Object)component).name)); StoneTransformation.SetStoneState(component, isStone); if (!((Object)(object)((MonoBehaviourPun)this).photonView == (Object)null) && ((MonoBehaviourPun)this).photonView.IsMine) { if (isStone && !flag) { StoneAmuletCooldownManager.Reset(component); StartStoneCurseTimer(); } else if (!isStone && flag) { StopStoneCurseTimer(); StoneAmuletCooldownManager.Reset(component); Debug.Log((object)("[StoneCurse] Timer stopped: " + ((Object)component).name)); } } } private void StartStoneCurseTimer() { StopStoneCurseTimer(); Character component = ((Component)this).GetComponent<Character>(); if (!((Object)(object)component == (Object)null) && !((Object)(object)component.data == (Object)null) && !component.data.dead && !(stoneCurse >= 1f)) { stoneCurseRoutine = ((MonoBehaviour)this).StartCoroutine(StoneCurseTimer()); Debug.Log((object)("[StoneCurse] Timer started: " + ((Object)((Component)this).gameObject).name)); } } private void StopStoneCurseTimer() { if (stoneCurseRoutine != null) { ((MonoBehaviour)this).StopCoroutine(stoneCurseRoutine); stoneCurseRoutine = null; } } private void Update() { if (!((Object)(object)((MonoBehaviourPun)this).photonView == (Object)null) && ((MonoBehaviourPun)this).photonView.IsMine) { Character component = ((Component)this).GetComponent<Character>(); if (!((Object)(object)component == (Object)null) && !((Object)(object)component.data == (Object)null) && component.data.dead && stoneCurseRoutine != null) { StopStoneCurseTimer(); Debug.Log((object)"[StoneCurse] Timer stopped: player is dead."); } } } private IEnumerator StoneCurseTimer() { Character character = ((Component)this).GetComponent<Character>(); while ((Object)(object)character != (Object)null && (Object)(object)character.data != (Object)null && !character.data.dead && StoneTransformation.IsTransformed(character) && stoneCurse < 1f) { yield return (object)new WaitForSeconds(StoneCurseInterval); if ((Object)(object)character == (Object)null || (Object)(object)character.data == (Object)null || character.data.dead || !StoneTransformation.IsTransformed(character) || stoneCurse >= 1f) { break; } ChangeStoneCurse(0.2f); if (stoneCurse >= 1f) { break; } Debug.Log((object)("[StoneCurse] Increased to: " + (stoneCurse * 100f).ToString("F0") + "% | Character: " + ((Object)character).name)); } stoneCurseRoutine = null; } public void SetStoneCurse(float value) { if ((Object)(object)((MonoBehaviourPun)this).photonView == (Object)null || !((MonoBehaviourPun)this).photonView.IsMine) { return; } Character component = ((Component)this).GetComponent<Character>(); float num = stoneCurse; stoneCurse = Mathf.Clamp01(value); if (stoneCurse > num && (Object)(object)component != (Object)null && StoneTransformation.IsTransformed(component)) { PlayStoneCurseApplySound(component); } ((MonoBehaviourPun)this).photonView.RPC("RPC_SyncStoneCurse", (RpcTarget)1, new object[1] { stoneCurse }); if ((Object)(object)component != (Object)null && StoneTransformation.IsTransformed(component)) { component.ClampStamina(); if (component.IsLocal && (Object)(object)GUIManager.instance != (Object)null) { GUIManager.instance.bar.ChangeBar(); } } CheckMaximumStoneCurse(); } public void ResetStoneCurseAfterRevive() { if (!((Object)(object)((MonoBehaviourPun)this).photonView == (Object)null) && ((MonoBehaviourPun)this).photonView.IsMine) { SetStoneCurse(0f); StartStoneCurseTimer(); } } public void ChangeStoneCurse(float amount) { if (!((Object)(object)((MonoBehaviourPun)this).photonView == (Object)null) && ((MonoBehaviourPun)this).photonView.IsMine) { SetStoneCurse(stoneCurse + amount); } } [PunRPC] public void RPC_SyncStoneCurse(float value) { stoneCurse = Mathf.Clamp01(value); Debug.Log((object)("[StoneCurse] Received: " + stoneCurse + " | Character: " + ((Object)((Component)this).gameObject).name)); } public bool HandleStonePetrify(float petrifyAmount) { Character component = ((Component)this).GetComponent<Character>(); if ((Object)(object)component == (Object)null) { return false; } if (!StoneTransformation.IsTransformed(component)) { return false; } if ((Object)(object)((MonoBehaviourPun)this).photonView == (Object)null || !((MonoBehaviourPun)this).photonView.IsMine) { return true; } petrifyAmount = Mathf.Max(0f, petrifyAmount); if (petrifyAmount <= 0f) { return true; } float num = Mathf.Min(StoneCurse, petrifyAmount); if (num > 0f) { ChangeStoneCurse(0f - num); } float num2 = petrifyAmount - num; if (num2 > 0f && (Object)(object)component.data != (Object)null) { int num3 = Mathf.RoundToInt(num2 * 100f); int petrify = Mathf.Clamp(component.data.petrifyAmount + num3, 0, 100); component.data.SetPetrify(petrify); } if (num > 0f) { component.AddStamina(num); } Debug.Log((object)("[StoneTransformation] " + ((Object)component).name + ": " + $"Received Petrify: {petrifyAmount:F3}, " + $"Removed StoneCurse: {num:F3}, " + $"Remaining Petrify: {num2:F3}")); return true; } public bool HandleSunPetrify(float petrifyAmount) { Character component = ((Component)this).GetComponent<Character>(); if ((Object)(object)component == (Object)null) { return false; } if (!StoneTransformation.IsTransformed(component)) { return false; } if ((Object)(object)((MonoBehaviourPun)this).photonView == (Object)null || !((MonoBehaviourPun)this).photonView.IsMine) { return true; } petrifyAmount = Mathf.Max(0f, petrifyAmount); if (petrifyAmount <= 0f) { return true; } float num = Mathf.Min(StoneCurse, petrifyAmount); if (num > 0f) { ChangeStoneCurse(0f - num); } if (num > 0f) { component.AddStamina(num); } Debug.Log((object)("[StoneTransformation] " + ((Object)component).name + ": " + $"Petrify Sun: {petrifyAmount:F3}, " + $"Removed StoneCurse: {num:F3}, " + $"Remaining StoneCurse: {StoneCurse:F3}")); return true; } public override void OnPlayerEnteredRoom(Player newPlayer) { ((MonoBehaviourPunCallbacks)this).OnPlayerEnteredRoom(newPlayer); if (!((Object)(object)((MonoBehaviourPun)this).photonView == (Object)null) && ((MonoBehaviourPun)this).photonView.IsMine) { ((MonoBehaviourPun)this).photonView.RPC("RPC_SyncStoneCurse", newPlayer, new object[1] { stoneCurse }); } } private void OnDestroy() { StopStoneCurseTimer(); if (stoneTransformationSoundFollowRoutine != null) { ((MonoBehaviour)this).StopCoroutine(stoneTransformationSoundFollowRoutine); stoneTransformationSoundFollowRoutine = null; } if ((Object)(object)stoneTransformationAudioSource != (Object)null) { Object.Destroy((Object)(object)((Component)stoneTransformationAudioSource).gameObject); stoneTransformationAudioSource = null; } if ((Object)(object)stoneCurseAudioSource != (Object)null) { Object.Destroy((Object)(object)((Component)stoneCurseAudioSource).gameObject); stoneCurseAudioSource = null; } } } [HarmonyPatch(typeof(CharacterAfflictions), "AddAffliction", new Type[] { typeof(Affliction), typeof(bool) })] public static class StoneRadiateInfiniteStamPatch { [HarmonyPrefix] private static bool Prefix(CharacterAfflictions __instance, Affliction affliction, bool fromRPC) { if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.character == (Object)null || affliction == null) { return true; } if (!(affliction is Affliction_RadiateInfiniteStam)) { return true; } Character character = __instance.character; if (!StoneTransformation.IsTransformed(character)) { return true; } Debug.Log((object)("[Book Of Stones] RadiateInfiniteStam BLOCKED for stone character: " + ((Object)character).name)); return false; } } [HarmonyPatch(typeof(CharacterAfflictions), "AddAffliction", new Type[] { typeof(Affliction), typeof(bool) })] public static class StoneHealingAfflictionPatch { [HarmonyPrefix] private static bool Prefix(CharacterAfflictions __instance, Affliction affliction, bool fromRPC) { if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.character == (Object)null || affliction == null) { return true; } Character character = __instance.character; if (!StoneTransformation.IsTransformed(character)) { return true; } if ((Object)(object)character.data != (Object)null && character.data.dead) { return true; } if (affliction is Affliction_HealAll || affliction is Affliction_Invincibility) { Debug.Log((object)("[Book Of Stones] Healing affliction blocked: " + ((object)affliction).GetType().Name)); return false; } return true; } } namespace TheBookOfStones { internal static class StoneFallDamageTracker { internal sealed class FallContext { public Character? Character; public FallContext? Previous; public bool CurseApplied; } [ThreadStatic] internal static FallContext? CurrentContext; private static FieldInfo? GetCharacterField(Type type) { return AccessTools.Field(type, "character"); } internal static FallContext Begin(object instance) { FallContext fallContext = new FallContext { Previous = CurrentContext }; FieldInfo characterField = GetCharacterField(instance.GetType()); if (characterField == null) { Debug.LogWarning((object)"[StoneFallDamage] Could not find character field!"); } else { ref Character? character = ref fallContext.Character; object? value = characterField.GetValue(instance); character = (Character?)((value is Character) ? value : null); } CurrentContext = fallContext; return fallContext; } internal static void End(FallContext? context) { if (context != null) { CurrentContext = context.Previous; } } internal static void ApplyFallDamage(Character character, float amount) { if ((Object)(object)character == (Object)null || !character.IsLocal || !StoneTransformation.IsTransformed(character)) { return; } StoneTransformationSync component = ((Component)character).GetComponent<StoneTransformationSync>(); if ((Object)(object)component == (Object)null) { Debug.LogWarning((object)"[StoneFallDamage] StoneTransformationSync not found!"); return; } float num = ((Ascents.currentAscent >= 1) ? 0.85f : 0.45f); float num2 = amount * Ascents.etcDamageMultiplier; float num3 = Mathf.Clamp01(num2) * num; if (!(num3 <= 0f)) { component.ChangeStoneCurse(num3); Debug.Log((object)($"[StoneFallDamage] StoneCurse increased by {num3:F4} " + $"(Damage: {num2:F4}, Max: {num:F2}, " + $"Ascent: {Ascents.currentAscent})")); } } } [HarmonyPatch(typeof(CharacterMovement), "CheckFallDamage")] internal static class StoneFallDamageMovementPatch { private static void Prefix(object __instance, out StoneFallDamageTracker.FallContext __state) { __state = StoneFallDamageTracker.Begin(__instance); } private static Exception? Finalizer(Exception? __exception, StoneFallDamageTracker.FallContext __state) { StoneFallDamageTracker.End(__state); return __exception; } } [HarmonyPatch(typeof(CharacterClimbing), "CheckFallDamage")] internal static class StoneFallDamageClimbingPatch { private static void Prefix(object __instance, out StoneFallDamageTracker.FallContext __state) { __state = StoneFallDamageTracker.Begin(__instance); } private static Exception? Finalizer(Exception? __exception, StoneFallDamageTracker.FallContext __state) { StoneFallDamageTracker.End(__state); return __exception; } } [HarmonyPatch(typeof(CharacterAfflictions), "AddStatus")] internal static class StoneFallDamageAddStatusPatch { private static bool Prefix(CharacterAfflictions __instance, STATUSTYPE statusType, float amount, ref bool __result) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Invalid comparison between Unknown and I4 if ((int)statusType > 0) { return true; } StoneFallDamageTracker.FallContext currentContext = StoneFallDamageTracker.CurrentContext; if (currentContext == null || (Object)(object)currentContext.Character == (Object)null) { return true; } if (currentContext.CurseApplied) { return true; } Character character = currentContext.Character; if (!character.IsLocal) { return true; } if (!StoneTransformation.IsTransformed(character)) { return true; } currentContext.CurseApplied = true; StoneFallDamageTracker.ApplyFallDamage(character, amount); __result = false; Debug.Log((object)"[StoneFallDamage] Fall Injury blocked and replaced with StoneCurse."); return false; } } } namespace The_Book_Of_Stones { [BepInPlugin("OvrSlepr.TheBookOfStones", "The Book Of Stones", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { private Harmony? harmony; public static AudioClip? StoneCurseApplySound { get; private set; } public static AudioClip? StoneTransformationSound { get; private set; } public static AudioClip? StoneBookSound { get; private set; } public static Material? StoneMaterial { get; private set; } public static Sprite? StoneCurseIcon { get; private set; } public static Texture2D? StoneTextureCrack { get; private set; } public static Texture2D? StoneTexture13 { get; private set; } public static Texture2D? StoneTexture60 { get; private set; } public static Texture2D? StoneTexture77 { get; private set; } private void Awake() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Book Of Stones] Plugin is loading!"); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Book Of Stones] TEST: New DLL is running!"); harmony = new Harmony("OvrSlepr.TheBookOfStones"); harmony.PatchAll(); StoneTransformationSync.StoneCloneSelectedItemPatch.PatchUnnamedClone(harmony); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Book Of Stones] Harmony patches installed!"); BundleLoader.LoadBundleWithName((BaseUnityPlugin)(object)this, "thebookofstones.peakbundle", (Action<PeakBundle>)delegate(PeakBundle peakBundle) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Book Of Stones] AssetBundle callback started!"); peakBundle.Mod.RegisterContent(); RegisterBookNameTranslations(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Book Of Stones] Listing bundle assets:"); string[] allAssetNames = peakBundle.GetAllAssetNames(); foreach (string text in allAssetNames) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("[Book Of Stones] Asset: " + text)); } string text2 = null; string[] allAssetNames2 = peakBundle.GetAllAssetNames(); foreach (string text3 in allAssetNames2) { if (text3.EndsWith("petrify-build.ogg", StringComparison.OrdinalIgnoreCase)) { text2 = text3; break; } } if (text2 != null) { StoneTransformationSou