Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ResizePlayer v1.0.1
plugins/ResizePlayer.dll
Decompiled 3 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: AssemblyCompany("ResizePlayer")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1+f998c7f8e8179ad1eabd18e98ee36ace20828a24")] [assembly: AssemblyProduct("ResizePlayer")] [assembly: AssemblyTitle("ResizePlayer")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Oddhatter.ResizePlayer { internal enum Part { Overall, Head, Neck, Chest, Belly, Hips, Arms, Hands, Legs, Feet } internal static class BodyParts { public const float Min = 0.25f; public const float Max = 10f; public static readonly Part[] All = (Part[])Enum.GetValues(typeof(Part)); public const float AimRange = 1000f; public static float Clamp(float v) { if (float.IsNaN(v) || float.IsInfinity(v)) { return 1f; } return Math.Min(10f, Math.Max(0.25f, v)); } public static string ZdoKey(Part p) { return "oddhatter.resizeplayer." + p.ToString().ToLowerInvariant(); } public static float LocalFactor(float own, float parent) { return own / parent; } public static float StrideFactor(float overall, float legs) { return Clamp(overall * legs); } public static float GravityFactor(float stride) { if (!(stride >= 1f)) { return (float)Math.Sqrt(stride); } return stride; } public static float ExtraGravity(float stride) { return GravityFactor(stride) - 1f; } public static float JumpHeight(float stride) { return Math.Max(1f, stride); } public static float JumpFactor(float stride) { return (float)Math.Sqrt(GravityFactor(stride) * JumpHeight(stride)); } public static float FootIkDistance(float original, float footScale) { return original * footScale; } public static float MaxFallSpeed(float cap, float stride, bool onGround) { return cap * (onGround ? stride : ((float)Math.Sqrt(stride))); } public static float ProjectileSpawnOffset(float offset, float overall) { return offset * overall; } public static float AimDistance(float hitBeyondSpawn, float sideOffset) { return Math.Max(Math.Min(hitBeyondSpawn, 1000f), 2f * sideOffset); } public static float LandingAltitude(float maxAirAltitude, float y, float stride) { return y + Math.Max(0f, maxAirAltitude - y) / JumpHeight(stride); } public static float CurrentVertical(IReadOnlyList<(float vertical, float parentFactor)> chain) { float num = 0f; foreach (var item2 in chain) { float item = item2.vertical; num += item; } return num; } public static float VanillaVertical(IReadOnlyList<(float vertical, float parentFactor)> chain) { float num = 0f; foreach (var item3 in chain) { float item = item3.vertical; float item2 = item3.parentFactor; num += ((item2 > 0f) ? (item / item2) : item); } return num; } public static float GroundOffset(IReadOnlyList<(float current, float vanilla)> soles) { if (soles.Count == 0) { return 0f; } float num = float.MaxValue; float num2 = float.MaxValue; foreach (var sole in soles) { float item = sole.current; float item2 = sole.vanilla; num = Math.Min(num, item); num2 = Math.Min(num2, item2); } return num2 - num; } public static float ReachFactor(float overall) { return Math.Max(1f, overall); } public static float Reach(float original, float overall, float eyeLift) { return original * ReachFactor(overall) + Math.Max(0f, eyeLift); } public static float HideDistance(float overall) { return 2f * Math.Min(1f, overall); } public static float SwimThreshold(float swimDepth, float overall) { return Math.Max(0f, swimDepth - 0.4f * overall); } public static float SmoothToward(float current, float target, float dt, float timeConstant) { if (!(timeConstant <= 0f)) { return current + (target - current) * (1f - (float)Math.Exp((0f - dt) / timeConstant)); } return target; } public static float WadingSpeed(float speed, float depth, float colliderHeight, float drag, float stride, float overall) { if (depth <= 0f) { return speed; } float num = speed / stride; float num2 = Math.Min(1f, Math.Max(0f, depth / (colliderHeight * overall / 3f))); return (num - num * num * num2 * drag) * stride; } public static float EffectScale(float itemSize, int scaledAbove, bool localScaling) { if (!localScaling) { return EffectOffset(itemSize, scaledAbove); } return itemSize; } public static float EffectOffset(float itemSize, int scaledAbove) { return (float)Math.Pow(itemSize, -scaledAbove); } public static float StretchLength(float lengthScale, float itemSize, bool worldSimulation) { if (!worldSimulation) { return lengthScale; } return lengthScale / itemSize; } public static float RestSoleDepth(float ankleHeight) { if (!(ankleHeight > 0f) || !(ankleHeight <= 0.5f)) { return 0f; } return ankleHeight; } } internal sealed class PartValues { private const float Tolerance = 0.0001f; private readonly float[] _values = new float[BodyParts.All.Length]; public float this[Part p] { get { return _values[(int)p]; } set { _values[(int)p] = value; } } public static PartValues Identity() { PartValues partValues = new PartValues(); for (int i = 0; i < partValues._values.Length; i++) { partValues._values[i] = 1f; } return partValues; } public bool ApproximatelyEquals(PartValues other) { if (other == null) { return false; } for (int i = 0; i < _values.Length; i++) { if (Math.Abs(_values[i] - other._values[i]) > 0.0001f) { return false; } } return true; } public void CopyFrom(PartValues other) { Array.Copy(other._values, _values, _values.Length); } } internal sealed class ItemEffects { private readonly struct Node { public readonly Transform T; public readonly Vector3 Scale; public readonly Vector3 Position; public readonly int ScaledAbove; public readonly bool Local; public readonly ParticleSystemRenderer Stretch; public readonly float Length; public readonly bool World; public Node(Transform t, int scaledAbove, ParticleSystem local) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Invalid comparison between Unknown and I4 //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Invalid comparison between Unknown and I4 T = t; Scale = t.localScale; Position = t.localPosition; ScaledAbove = scaledAbove; Local = (Object)(object)local != (Object)null; ParticleSystemRenderer val = (((Object)(object)local != (Object)null) ? ((Component)t).GetComponent<ParticleSystemRenderer>() : null); Stretch = (((Object)(object)val != (Object)null && (int)val.renderMode == 1) ? val : null); Length = (((Object)(object)Stretch != (Object)null) ? Stretch.lengthScale : 0f); int world; if ((Object)(object)local != (Object)null) { MainModule main = local.main; world = (((int)((MainModule)(ref main)).simulationSpace == 1) ? 1 : 0); } else { world = 0; } World = (byte)world != 0; } } private readonly Transform _item; private readonly Transform _joint; private readonly List<Node> _nodes; private float _applied = 1f; public int Count => _nodes.Count; public bool Destroyed { get { if (!((Object)(object)_item == (Object)null)) { return (Object)(object)_joint == (Object)null; } return true; } } public Transform Joint => _joint; private ItemEffects(Transform item, Transform joint, List<Node> nodes) { _item = item; _joint = joint; _nodes = nodes; } public static ItemEffects Capture(Transform item, Transform joint) { List<Node> list = new List<Node>(); for (int i = 0; i < item.childCount; i++) { Collect(item.GetChild(i), 0, list); } if (list.Count <= 0) { return null; } return new ItemEffects(item, joint, list); } private static void Collect(Transform t, int scaledAbove, List<Node> nodes) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Invalid comparison between Unknown and I4 ParticleSystem component = ((Component)t).GetComponent<ParticleSystem>(); int num; if ((Object)(object)component != (Object)null) { MainModule main = component.main; num = (((int)((MainModule)(ref main)).scalingMode == 1) ? 1 : 0); } else { num = 0; } bool flag = (byte)num != 0; if (flag || scaledAbove > 0) { nodes.Add(new Node(t, scaledAbove, flag ? component : null)); } int scaledAbove2 = (flag ? (scaledAbove + 1) : 0); for (int i = 0; i < t.childCount; i++) { Collect(t.GetChild(i), scaledAbove2, nodes); } } public void Apply(float itemSize) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) if (Mathf.Abs(itemSize - _applied) < 0.0001f) { return; } foreach (Node node in _nodes) { if ((Object)(object)node.T != (Object)null) { node.T.localScale = node.Scale * BodyParts.EffectScale(itemSize, node.ScaledAbove, node.Local); node.T.localPosition = node.Position * BodyParts.EffectOffset(itemSize, node.ScaledAbove); } if ((Object)(object)node.Stretch != (Object)null) { node.Stretch.lengthScale = BodyParts.StretchLength(node.Length, itemSize, node.World); } } _applied = itemSize; } } [HarmonyPatch(typeof(Player), "Awake")] internal static class Player_Awake_Patch { private static void Postfix(Player __instance) { ((Component)__instance).gameObject.AddComponent<PlayerScaler>(); } } [HarmonyPatch(typeof(GameCamera), "UpdateCamera")] internal static class GameCamera_UpdateCamera_Patch { private static GameCamera s_camera; private static float s_minDistance; private static float s_maxDistance; private static float s_maxDistanceBoat; private static float s_zoomSens; private static float s_nearClipMin; private static float s_nearClipMax; private static float s_factor = 1f; private static void Prefix(GameCamera __instance) { if ((Object)(object)__instance != (Object)(object)s_camera) { s_camera = __instance; s_minDistance = __instance.m_minDistance; s_maxDistance = __instance.m_maxDistance; s_maxDistanceBoat = __instance.m_maxDistanceBoat; s_zoomSens = __instance.m_zoomSens; s_nearClipMin = __instance.m_nearClipPlaneMin; s_nearClipMax = __instance.m_nearClipPlaneMax; s_factor = 1f; } float localOverall = PlayerScaler.LocalOverall; if (localOverall != s_factor) { __instance.m_distance *= localOverall / s_factor; s_factor = localOverall; __instance.m_minDistance = s_minDistance * localOverall; __instance.m_maxDistance = s_maxDistance * localOverall; __instance.m_maxDistanceBoat = s_maxDistanceBoat * localOverall; __instance.m_zoomSens = s_zoomSens * localOverall; float num = Mathf.Min(1f, localOverall); __instance.m_nearClipPlaneMin = s_nearClipMin * num; __instance.m_nearClipPlaneMax = s_nearClipMax * num; } } } [HarmonyPatch(typeof(VisEquipment), "AttachItem")] internal static class VisEquipment_AttachItem_Patch { private static void Postfix(VisEquipment __instance, GameObject __result, int itemHash, Transform joint) { if (!((Object)(object)__result == (Object)null) && !((Object)(object)joint == (Object)null)) { if ((Object)(object)__result.transform.parent == (Object)(object)joint) { AttachedItemScaling.ScaleToJoint(__instance, __result.transform); } AttachedItemScaling.TrackEffects(__instance, __result.transform, joint, itemHash); } } } [HarmonyPatch(typeof(VisEquipment), "AttachArmor")] internal static class VisEquipment_AttachArmor_Patch { private static void Postfix(VisEquipment __instance, List<GameObject> __result, int itemHash) { if (__result == null || (Object)(object)__instance.m_bodyModel == (Object)null) { return; } Transform parent = ((Component)__instance.m_bodyModel).transform.parent; foreach (GameObject item in __result) { if (!((Object)(object)item == (Object)null)) { if ((Object)(object)item.transform.parent != (Object)(object)parent) { AttachedItemScaling.ScaleToJoint(__instance, item.transform); } AttachedItemScaling.TrackEffects(__instance, item.transform, item.transform.parent, itemHash); } } } } internal static class AttachedItemScaling { internal static void ScaleToJoint(VisEquipment equipment, Transform item) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) PlayerScaler componentInParent = ((Component)equipment).GetComponentInParent<PlayerScaler>(); if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)item.parent == (Object)null)) { float num = componentInParent.ScaleFactorAt(item.parent); if (Mathf.Abs(num - 1f) > 0.0001f) { item.localScale *= num; } } } internal static void TrackEffects(VisEquipment equipment, Transform item, Transform joint, int itemHash) { PlayerScaler componentInParent = ((Component)equipment).GetComponentInParent<PlayerScaler>(); if ((Object)(object)componentInParent != (Object)null && (Object)(object)joint != (Object)null) { GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(itemHash) : null); componentInParent.TrackEffects(item, joint, ((Object)(object)val != (Object)null) ? ((Object)val).name : ((Object)item).name); } } } [HarmonyPatch(typeof(Character), "UpdateGroundContact")] internal static class Character_UpdateGroundContact_Patch { private static void Prefix(Character __instance) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) if (PlayerScaler.LocalStride != 1f && __instance.m_groundContact && (Object)(object)__instance == (Object)(object)Player.m_localPlayer) { __instance.m_maxAirAltitude = BodyParts.LandingAltitude(__instance.m_maxAirAltitude, ((Component)__instance).transform.position.y, PlayerScaler.LocalStride); } } } [HarmonyPatch(typeof(Character), "OnCollisionStay")] internal static class Character_GroundContact_Patch { private static readonly MethodInfo s_radius = AccessTools.PropertyGetter(typeof(CapsuleCollider), "radius"); private static readonly MethodInfo s_center = AccessTools.PropertyGetter(typeof(CapsuleCollider), "center"); private static readonly MethodInfo s_scaledRadius = AccessTools.Method(typeof(Character_GroundContact_Patch), "Radius", (Type[])null, (Type[])null); private static readonly MethodInfo s_scaledCenter = AccessTools.Method(typeof(Character_GroundContact_Patch), "Center", (Type[])null, (Type[])null); internal static float Radius(CapsuleCollider collider) { return collider.radius * FactorOf(collider); } internal static Vector3 Center(CapsuleCollider collider) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) return collider.center * FactorOf(collider); } private static float FactorOf(CapsuleCollider collider) { Player localPlayer = Player.m_localPlayer; if (localPlayer == null || collider != ((Character)localPlayer).m_collider) { return 1f; } return PlayerScaler.LocalOverall; } private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { int radii = 0; int centers = 0; foreach (CodeInstruction instruction in instructions) { if (CodeInstructionExtensions.Calls(instruction, s_radius)) { instruction.opcode = OpCodes.Call; instruction.operand = s_scaledRadius; radii++; } else if (CodeInstructionExtensions.Calls(instruction, s_center)) { instruction.opcode = OpCodes.Call; instruction.operand = s_scaledCenter; centers++; } yield return instruction; } if (radii != 1 || centers != 1) { ResizePlayerPlugin.Log.LogWarning((object)$"Expected one collider radius and one centre in Character.OnCollisionStay, found {radii} and {centers}; a giant may keep losing the ground."); } } } [HarmonyPatch(typeof(Character), "ApplyLiquidResistance")] internal static class Character_LiquidResistance_Patch { private static bool Prefix(Character __instance, ref float speed) { if ((PlayerScaler.LocalStride == 1f && PlayerScaler.LocalOverall == 1f) || (Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return true; } float num = __instance.InLiquidDepth(); if (num <= 0f || __instance.m_seman.HaveStatusEffect(SEMan.s_statusEffectTared)) { return false; } float drag = ((__instance.m_tarLevel > __instance.m_waterLevel) ? 0.1f : 0.05f); speed = BodyParts.WadingSpeed(speed, num, __instance.m_collider.height, drag, PlayerScaler.LocalStride, PlayerScaler.LocalOverall); return false; } } [HarmonyPatch(typeof(SE_Stats), "ModifyWalkVelocity")] internal static class SE_Stats_MaxFallSpeed_Patch { private static bool Prefix(SE_Stats __instance, ref Vector3 vel) { if (PlayerScaler.LocalStride == 1f || __instance.m_maxMaxFallSpeed <= 0f || (Object)(object)((StatusEffect)__instance).m_character == (Object)null || (Object)(object)((StatusEffect)__instance).m_character != (Object)(object)Player.m_localPlayer) { return true; } float num = BodyParts.MaxFallSpeed(__instance.m_maxMaxFallSpeed, PlayerScaler.LocalStride, ((StatusEffect)__instance).m_character.IsOnGround()); if (vel.y < 0f - num) { vel.y = 0f - num; } return false; } } [HarmonyPatch] internal static class Player_CameraRay_Patch { private const float VanillaRayLength = 50f; private static readonly MethodInfo s_rayLength = AccessTools.Method(typeof(Player_CameraRay_Patch), "RayLength", (Type[])null, (Type[])null); private static IEnumerable<MethodBase> TargetMethods() { yield return AccessTools.Method(typeof(Player), "FindHoverObject", (Type[])null, (Type[])null); yield return AccessTools.Method(typeof(Player), "PieceRayTest", (Type[])null, (Type[])null); yield return AccessTools.Method(typeof(Player), "RemovePiece", (Type[])null, (Type[])null); yield return AccessTools.Method(typeof(Player), "CopyPiece", (Type[])null, (Type[])null); yield return AccessTools.Method(typeof(Player), "UpdateWearNTearHover", (Type[])null, (Type[])null); } internal static float RayLength() { return 50f * Mathf.Max(1f, PlayerScaler.LocalOverall); } private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod) { int replaced = 0; foreach (CodeInstruction instruction in instructions) { if (instruction.opcode == OpCodes.Ldc_R4 && instruction.operand is float num && num == 50f) { instruction.opcode = OpCodes.Call; instruction.operand = s_rayLength; replaced++; } yield return instruction; } if (replaced != 1) { ResizePlayerPlugin.Log.LogWarning((object)$"Expected one 50 m camera ray in Player.{__originalMethod.Name}, found {replaced}; giants may not reach far from the camera."); } } } [HarmonyPatch(typeof(Player), "FixedUpdate")] internal static class Player_HideNearCamera_Patch { private const float VanillaHideDistance = 2f; private static readonly MethodInfo s_distance = AccessTools.Method(typeof(Vector3), "Distance", (Type[])null, (Type[])null); private static readonly MethodInfo s_hideDistance = AccessTools.Method(typeof(Player_HideNearCamera_Patch), "HideDistance", (Type[])null, (Type[])null); internal static float HideDistance() { return BodyParts.HideDistance(PlayerScaler.LocalOverall); } private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { int replaced = 0; CodeInstruction previous = null; foreach (CodeInstruction instruction in instructions) { if (previous != null && CodeInstructionExtensions.Calls(previous, s_distance) && instruction.opcode == OpCodes.Ldc_R4 && instruction.operand is float num && num == 2f) { instruction.opcode = OpCodes.Call; instruction.operand = s_hideDistance; replaced++; } previous = instruction; yield return instruction; } if (replaced != 1) { ResizePlayerPlugin.Log.LogWarning((object)$"Expected one camera hide distance in Player.FixedUpdate, found {replaced}; a tiny player may be invisible."); } } } [HarmonyPatch(typeof(Character))] internal static class Character_SwimThreshold_Patch { [HarmonyPrefix] [HarmonyPatch("InLiquidSwimDepth", new Type[] { })] private static bool Current(Character __instance, ref bool __result) { if (!IsScaledLocal(__instance)) { return true; } __result = __instance.InLiquidDepth() > Threshold(__instance); return false; } [HarmonyPrefix] [HarmonyPatch("InLiquidSwimDepth", new Type[] { typeof(float) })] private static bool AtDepth(Character __instance, float depth, ref bool __result) { if (!IsScaledLocal(__instance)) { return true; } __result = depth > Threshold(__instance); return false; } private static bool IsScaledLocal(Character character) { if (PlayerScaler.LocalOverall != 1f) { return (Object)(object)character == (Object)(object)Player.m_localPlayer; } return false; } private static float Threshold(Character character) { return BodyParts.SwimThreshold(character.m_swimDepth, PlayerScaler.LocalOverall); } } [HarmonyPatch(typeof(Character))] internal static class Character_Size_Patch { [HarmonyPostfix] [HarmonyPatch("GetRadius")] private static void Radius(Character __instance, ref float __result) { __result *= OverallOf(__instance); } [HarmonyPostfix] [HarmonyPatch("GetHeight")] private static void Height(Character __instance, ref float __result) { __result *= OverallOf(__instance); } private static float OverallOf(Character character) { PlayerScaler playerScaler = default(PlayerScaler); if (!(character is Player) || !((Component)character).TryGetComponent<PlayerScaler>(ref playerScaler)) { return 1f; } return playerScaler.RootFactor; } } [HarmonyPatch(typeof(Attack), "GetProjectileSpawnPoint")] internal static class Attack_GetProjectileSpawnPoint_Patch { private static int s_aimMask; private static void Postfix(Attack __instance, ref Vector3 spawnPoint, ref Vector3 aimDir) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (PlayerScaler.LocalResized && !((Object)(object)localPlayer == (Object)null) && !((Object)(object)__instance.m_character != (Object)(object)localPlayer)) { if (PlayerScaler.LocalOverall != 1f) { Vector3 position = __instance.GetAttackOrigin().position; Vector3 val = spawnPoint - position; spawnPoint = position + ((Vector3)(ref val)).normalized * BodyParts.ProjectileSpawnOffset(((Vector3)(ref val)).magnitude, PlayerScaler.LocalOverall); } if (!__instance.m_useCharacterFacing && (Object)(object)GameCamera.instance != (Object)null) { aimDir = AimAtCrosshair(localPlayer, ((Component)GameCamera.instance).transform, spawnPoint); } } } private static Vector3 AimAtCrosshair(Player player, Transform camera, Vector3 spawnPoint) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: 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_012e: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) if (s_aimMask == 0) { s_aimMask = LayerMask.GetMask(new string[12] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character", "character_net", "character_ghost", "hitbox", "character_noenv", "vehicle" }); } Vector3 position = camera.position; Vector3 forward = camera.forward; float num = Mathf.Max(0f, Vector3.Dot(spawnPoint - position, forward)); Vector3 val = position + forward * num; float sideOffset = Vector3.Distance(spawnPoint, val); float num2 = float.PositiveInfinity; RaycastHit[] array = Physics.RaycastAll(position, forward, num + 1000f, s_aimMask, (QueryTriggerInteraction)1); for (int i = 0; i < array.Length; i++) { RaycastHit val2 = array[i]; if (((RaycastHit)(ref val2)).distance > num && ((RaycastHit)(ref val2)).distance - num < num2 && !((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(((Component)player).transform)) { num2 = ((RaycastHit)(ref val2)).distance - num; } } Vector3 val3 = val + forward * BodyParts.AimDistance(num2, sideOffset) - spawnPoint; return ((Vector3)(ref val3)).normalized; } } [HarmonyPatch(typeof(ZSyncAnimation), "SetFloat", new Type[] { typeof(int), typeof(float) })] internal static class ZSyncAnimation_SetFloat_Patch { private static readonly int s_forwardSpeed = ZSyncAnimation.GetHash("forward_speed"); private static readonly int s_sidewaySpeed = ZSyncAnimation.GetHash("sideway_speed"); private static void Prefix(ZSyncAnimation __instance, int hash, ref float value) { if ((Object)(object)__instance == (Object)(object)PlayerScaler.LocalZAnim && PlayerScaler.LocalStride != 1f && (hash == s_forwardSpeed || hash == s_sidewaySpeed)) { value /= PlayerScaler.LocalStride; } } } internal sealed class PlayerScaler : MonoBehaviour { private sealed class Bone { public Transform T; public Part Part; public Part? ParentPart; public Transform ParentT; public Vector3 Original; } internal static float LocalOverall = 1f; internal static float LocalStride = 1f; internal static bool LocalResized; internal static ZSyncAnimation LocalZAnim; private static readonly (HumanBodyBones bone, Part part)[] BoneMap = new(HumanBodyBones, Part)[20] { ((HumanBodyBones)0, Part.Hips), ((HumanBodyBones)7, Part.Belly), ((HumanBodyBones)8, Part.Chest), ((HumanBodyBones)54, Part.Chest), ((HumanBodyBones)9, Part.Neck), ((HumanBodyBones)10, Part.Head), ((HumanBodyBones)13, Part.Arms), ((HumanBodyBones)14, Part.Arms), ((HumanBodyBones)15, Part.Arms), ((HumanBodyBones)16, Part.Arms), ((HumanBodyBones)17, Part.Hands), ((HumanBodyBones)18, Part.Hands), ((HumanBodyBones)1, Part.Legs), ((HumanBodyBones)2, Part.Legs), ((HumanBodyBones)3, Part.Legs), ((HumanBodyBones)4, Part.Legs), ((HumanBodyBones)5, Part.Feet), ((HumanBodyBones)6, Part.Feet), ((HumanBodyBones)19, Part.Feet), ((HumanBodyBones)20, Part.Feet) }; private static readonly int s_inWater = ZSyncAnimation.GetHash("inWater"); private static readonly HashSet<string> s_logged = new HashSet<string>(); private readonly List<Bone> _bones = new List<Bone>(); private readonly Dictionary<Transform, Vector3> _originals = new Dictionary<Transform, Vector3>(); private readonly PartValues _localTarget = PartValues.Identity(); private static readonly PartValues s_identity = PartValues.Identity(); private static readonly int[] s_zdoHashes = Array.ConvertAll(BodyParts.All, (Part p) => StringExtensionMethods.GetStableHashCode(BodyParts.ZdoKey(p))); private PartValues _lastPublished; private readonly PartValues _remote = PartValues.Identity(); private bool _haveRemote; private uint _lastRevision; private Player _player; private ZNetView _nview; private Animator _cachedAnimator; private bool _rootOriginalKnown; private Vector3 _rootOriginal = Vector3.one; private Transform _hips; private Transform _head; private Transform _armature; private Vector3 _armatureOriginal; private bool _armatureMoved; private readonly Transform[] _feet = (Transform[])(object)new Transform[2]; private readonly Vector3[] _soleLocal = (Vector3[])(object)new Vector3[2]; private readonly bool[] _soleKnown = new bool[2]; private readonly List<(float vertical, float parentFactor)> _chain = new List<(float, float)>(); private readonly List<(float current, float vanilla)> _soles = new List<(float, float)>(); private CharacterAnimEvent _animEvent; private Vector3 _ikOriginal; private Vector3[] _ikFootOriginals; private float _ikFactor = 1f; private readonly List<ItemEffects> _effects = new List<ItemEffects>(); private Transform _eye; private Vector3 _eyeOriginal; private bool _eyeMoved; private float _eyeLift; private const float EyeSmoothing = 0.5f; private bool _applied; private bool _wasLocal; private bool _reachOriginalsKnown; private float _interactOriginal; private float _placeOriginal; private float _swimDepthOriginal; private float _walkSpeedOriginal; private float _jogSpeedOriginal; private float _runSpeedOriginal; private float _crouchSpeedOriginal; private float _swimSpeedOriginal; private float _accelerationOriginal; private float _jumpForceOriginal; private float _jumpForwardOriginal; internal float RootFactor { get { //IL_0026: Unknown result type (might be due to invalid IL or missing references) if (!_rootOriginalKnown || _rootOriginal.x == 0f) { return 1f; } return ((Component)this).transform.localScale.x / _rootOriginal.x; } } private void Awake() { _player = ((Component)this).GetComponent<Player>(); _nview = ((Component)this).GetComponent<ZNetView>(); } private void LateUpdate() { if ((Object)(object)_player == (Object)null || (Object)(object)_nview == (Object)null || !_nview.IsValid()) { return; } if (!_rootOriginalKnown) { CaptureRootOriginal(); } if (!_reachOriginalsKnown) { _interactOriginal = _player.m_maxInteractDistance; _placeOriginal = _player.m_maxPlaceDistance; _swimDepthOriginal = ((Character)_player).m_swimDepth; _walkSpeedOriginal = ((Character)_player).m_walkSpeed; _jogSpeedOriginal = ((Character)_player).m_speed; _runSpeedOriginal = ((Character)_player).m_runSpeed; _crouchSpeedOriginal = ((Character)_player).m_crouchSpeed; _swimSpeedOriginal = ((Character)_player).m_swimSpeed; _accelerationOriginal = ((Character)_player).m_acceleration; _jumpForceOriginal = ((Character)_player).m_jumpForce; _jumpForwardOriginal = ((Character)_player).m_jumpForceForward; _reachOriginalsKnown = true; } if (!EnsureBones()) { return; } bool value = ResizePlayerPlugin.Enabled.Value; if ((Object)(object)_player == (Object)(object)Player.m_localPlayer) { _wasLocal = true; PartValues partValues = (value ? LocalTarget() : null); Apply(partValues); LocalOverall = partValues?[Part.Overall] ?? 1f; LocalResized = partValues != null && !partValues.ApproximatelyEquals(s_identity); ApplyReach(LocalOverall); LocalStride = ((partValues != null) ? BodyParts.StrideFactor(partValues[Part.Overall], partValues[Part.Legs]) : 1f); ApplySpeed(LocalStride); LocalZAnim = ((Character)_player).m_zanim; LogSyncFlagsOnce(); if (_nview.IsOwner()) { Publish(_nview.GetZDO(), partValues ?? s_identity); } } else { if (value) { RefreshRemote(_nview.GetZDO()); } Apply(value ? _remote : null); } UpdateEffects(); } internal void TrackEffects(Transform item, Transform joint, string label) { ItemEffects itemEffects = ItemEffects.Capture(item, joint); if (itemEffects != null) { itemEffects.Apply(ScaleFactorAt(joint)); _effects.Add(itemEffects); if (s_logged.Add("effects:" + label)) { ResizePlayerPlugin.Log.LogInfo((object)$"Item effects: {label} on {((Object)joint).name}, size {ScaleFactorAt(joint):0.###}, {itemEffects.Count} transforms"); } } } private void UpdateEffects() { for (int num = _effects.Count - 1; num >= 0; num--) { if (_effects[num].Destroyed) { _effects.RemoveAt(num); } else { _effects[num].Apply(ScaleFactorAt(_effects[num].Joint)); } } } private void FixedUpdate() { //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) if (_wasLocal && LocalStride != 1f && !((Object)(object)_player != (Object)(object)Player.m_localPlayer)) { Rigidbody body = ((Character)_player).m_body; if (!((Object)(object)body == (Object)null) && body.useGravity && !body.isKinematic && !body.IsSleeping() && !((Character)_player).IsSwimming() && !((Character)_player).IsAttached() && !((Character)_player).IsDebugFlying() && !((Character)_player).IsTeleporting() && !((Character)_player).IsDead()) { body.AddForce(Physics.gravity * BodyParts.ExtraGravity(LocalStride), (ForceMode)5); } } } private void Publish(ZDO zdo, PartValues values) { if (values.ApproximatelyEquals(_lastPublished)) { return; } Part[] all = BodyParts.All; foreach (Part part in all) { if (_lastPublished == null || Mathf.Abs(_lastPublished[part] - values[part]) > 0.0001f) { zdo.Set(s_zdoHashes[(int)part], values[part]); } } if (_lastPublished == null) { _lastPublished = PartValues.Identity(); } _lastPublished.CopyFrom(values); } private void RefreshRemote(ZDO zdo) { if (!_haveRemote || zdo.DataRevision != _lastRevision) { Part[] all = BodyParts.All; foreach (Part part in all) { _remote[part] = BodyParts.Clamp(zdo.GetFloat(s_zdoHashes[(int)part], 1f)); } _lastRevision = zdo.DataRevision; _haveRemote = true; } } private void OnDestroy() { if (_wasLocal) { LocalOverall = 1f; LocalStride = 1f; LocalResized = false; LocalZAnim = null; } } private void CaptureRootOriginal() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("Player") : null); _rootOriginal = (((Object)(object)val != (Object)null) ? val.transform.localScale : Vector3.one); _rootOriginalKnown = true; } private unsafe bool EnsureBones() { //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012a: 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) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) Animator animator = ((Character)_player).m_animator; if ((Object)(object)animator == (Object)null || !animator.isHuman) { LogOnce("no-humanoid", "Player has no humanoid animator; body parts can't be resized."); return false; } if ((Object)(object)animator == (Object)(object)_cachedAnimator && _bones.Count > 0 && AllBonesAlive()) { return true; } _cachedAnimator = animator; _bones.Clear(); Dictionary<Transform, Part> dictionary = new Dictionary<Transform, Part>(); (HumanBodyBones, Part)[] boneMap = BoneMap; for (int i = 0; i < boneMap.Length; i++) { (HumanBodyBones, Part) tuple = boneMap[i]; HumanBodyBones item = tuple.Item1; Part item2 = tuple.Item2; Transform boneTransform = animator.GetBoneTransform(item); if ((Object)(object)boneTransform == (Object)null) { LogOnce("bone-" + ((object)(*(HumanBodyBones*)(&item))/*cast due to .constrained prefix*/).ToString(), $"Bone {item} not found on the player; it is skipped ({item2})."); continue; } if (!_originals.TryGetValue(boneTransform, out var value)) { value = boneTransform.localScale; _originals[boneTransform] = value; } dictionary[boneTransform] = item2; _bones.Add(new Bone { T = boneTransform, Part = item2, Original = value }); } foreach (Bone bone in _bones) { Transform parent = bone.T.parent; while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)((Component)animator).transform) { if (dictionary.TryGetValue(parent, out var value2)) { bone.ParentPart = value2; bone.ParentT = parent; break; } parent = parent.parent; } } CacheLegData(animator); CacheEye(); CacheFootIk(animator); return _bones.Count > 0; } private void CacheEye() { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_eye == (Object)null && (Object)(object)((Character)_player).m_eye != (Object)null && !_applied) { _eye = ((Character)_player).m_eye; _eyeOriginal = _eye.localPosition; _eyeMoved = false; } } private void CacheFootIk(Animator animator) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_animEvent != (Object)null || _applied) { return; } _animEvent = ((Component)animator).GetComponent<CharacterAnimEvent>(); if ((Object)(object)_animEvent == (Object)null) { LogOnce("foot-ik", "No CharacterAnimEvent on the player's animator; a tiny player's feet may look lifted."); return; } _ikOriginal = new Vector3(_animEvent.m_footOffset, _animEvent.m_footStepHeight, _animEvent.m_stabalizeDistance); Foot[] feets = _animEvent.m_feets; _ikFootOriginals = (Vector3[])(object)new Vector3[feets.Length]; for (int i = 0; i < feets.Length; i++) { _ikFootOriginals[i] = new Vector3(feets[i].m_footOffset, feets[i].m_footStepHeight, feets[i].m_stabalizeDistance); } _ikFactor = 1f; if (s_logged.Add("foot-ik-values")) { ResizePlayerPlugin.Log.LogInfo((object)($"Foot IK: enabled={_animEvent.m_footIK}, per-foot values={_animEvent.m_useFeetValues}, " + $"ankle offset={_animEvent.m_footOffset:F3} m, step height={_animEvent.m_footStepHeight:F3} m, feet={feets.Length}")); } } private void ApplyFootIk(float factor) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_animEvent == (Object)null) && !(Mathf.Abs(factor - _ikFactor) < 0.0001f)) { _ikFactor = factor; SetFootIk(ref _animEvent.m_footOffset, ref _animEvent.m_footStepHeight, ref _animEvent.m_stabalizeDistance, _ikOriginal, factor); Foot[] feets = _animEvent.m_feets; for (int i = 0; i < feets.Length && i < _ikFootOriginals.Length; i++) { SetFootIk(ref feets[i].m_footOffset, ref feets[i].m_footStepHeight, ref feets[i].m_stabalizeDistance, _ikFootOriginals[i], factor); } } } private static void SetFootIk(ref float offset, ref float stepHeight, ref float stabilize, Vector3 original, float factor) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) offset = BodyParts.FootIkDistance(original.x, factor); stepHeight = BodyParts.FootIkDistance(original.y, factor); stabilize = BodyParts.FootIkDistance(original.z, factor); } private bool AllBonesAlive() { foreach (Bone bone in _bones) { if ((Object)(object)bone.T == (Object)null) { return false; } } return true; } private void CacheLegData(Animator animator) { //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_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) _hips = animator.GetBoneTransform((HumanBodyBones)0); _head = animator.GetBoneTransform((HumanBodyBones)10); _feet[0] = animator.GetBoneTransform((HumanBodyBones)5); _feet[1] = animator.GetBoneTransform((HumanBodyBones)6); for (int i = 0; i < _feet.Length; i++) { if ((Object)(object)_feet[i] != (Object)null && !_soleKnown[i]) { _soleLocal[i] = RestSoleLocal(_feet[i]); _soleKnown[i] = true; } } if ((Object)(object)_hips == (Object)null || (!_soleKnown[0] && !_soleKnown[1])) { LogOnce("legs", "Couldn't find the hips or feet; feet may sink or float when Legs, Hips or Feet isn't 1."); } Transform val = (((Object)(object)_hips != (Object)null) ? _hips.parent : null); if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)((Component)animator).transform || (Object)(object)val.parent == (Object)null) { LogOnce("armature", "No separate skeleton root above the hips; feet may sink or float when Legs, Hips or Feet isn't 1."); val = null; } if ((Object)(object)val != (Object)(object)_armature) { _armature = val; _armatureMoved = false; if ((Object)(object)val != (Object)null) { _armatureOriginal = val.localPosition; } } } private Vector3 RestSoleLocal(Transform foot) { //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) string text = ((Object)foot).name; Transform parent = foot.parent; while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)((Component)this).transform) { text = ((Object)parent).name + "/" + text; parent = parent.parent; } GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("Player") : null); Transform val2 = (((Object)(object)val != (Object)null) ? val.transform.Find(text) : null); if ((Object)(object)val2 == (Object)null) { LogOnce("rest-foot", "Couldn't find " + text + " in the Player prefab; big feet stand on their ankles."); return Vector3.zero; } Transform transform = val.transform; float num = ((transform.lossyScale.y != 0f) ? transform.lossyScale.y : 1f); float num2 = Vector3.Dot(val2.position - transform.position, transform.up) / num; float num3 = BodyParts.RestSoleDepth(num2); if (s_logged.Add("rest-sole")) { ResizePlayerPlugin.Log.LogInfo((object)$"Ankle height in the Player prefab's rest pose: {num2:F3} m (sole depth used: {num3:F3} m)."); } return val2.InverseTransformPoint(val2.position - transform.up * (num3 * num)); } private PartValues LocalTarget() { Part[] all = BodyParts.All; foreach (Part part in all) { _localTarget[part] = BodyParts.Clamp(ResizePlayerPlugin.Sizes[part].Value); } return _localTarget; } private void Apply(PartValues target) { //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) if (target == null) { if (_applied) { Restore(); } return; } foreach (Bone bone in _bones) { float parent = (bone.ParentPart.HasValue ? target[bone.ParentPart.Value] : 1f); bone.T.localScale = bone.Original * BodyParts.LocalFactor(target[bone.Part], parent); } Vector3 val = _rootOriginal * target[Part.Overall]; if (((Component)this).transform.localScale != val) { ((Component)this).transform.localScale = val; } ApplyFootIk(((Object)(object)_feet[0] != (Object)null) ? ScaleFactorAt(_feet[0]) : RootFactor); Vector3 up = ((Component)this).transform.up; float num = 0f; if ((Object)(object)_armature != (Object)null) { _soles.Clear(); bool flag = (Object)(object)((Character)_player).m_animator != (Object)null && ((Character)_player).m_animator.GetBool(s_inWater); for (int i = 0; i < _feet.Length; i++) { if (flag) { break; } if ((Object)(object)_feet[i] != (Object)null && _soleKnown[i] && CollectChain(_feet[i], _feet[i].TransformPoint(_soleLocal[i]), up)) { _soles.Add((BodyParts.CurrentVertical(_chain), BodyParts.VanillaVertical(_chain))); } } num = BodyParts.GroundOffset(_soles); if (Mathf.Abs(num) > 0.0001f || _armatureMoved) { _armature.localPosition = _armatureOriginal + _armature.parent.InverseTransformVector(up * num); _armatureMoved = Mathf.Abs(num) > 0.0001f; } } if ((Object)(object)_eye != (Object)null) { float num2 = num; if ((Object)(object)_head != (Object)null && (Object)(object)_head.parent != (Object)null && CollectChain(_head.parent, _head.position, up)) { num2 += BodyParts.CurrentVertical(_chain) - BodyParts.VanillaVertical(_chain); } _eyeLift = BodyParts.SmoothToward(_eyeLift, num2, Time.deltaTime, 0.5f); if (Mathf.Abs(_eyeLift) > 0.0001f || _eyeMoved) { _eye.localPosition = _eyeOriginal + _eye.parent.InverseTransformVector(up * _eyeLift); _eyeMoved = Mathf.Abs(_eyeLift) > 0.0001f; } } _applied = true; } private void ApplyReach(float overall) { _player.m_maxInteractDistance = BodyParts.Reach(_interactOriginal, overall, _eyeLift); _player.m_maxPlaceDistance = BodyParts.Reach(_placeOriginal, overall, _eyeLift); ((Character)_player).m_swimDepth = _swimDepthOriginal * overall; } private void ApplySpeed(float stride) { ((Character)_player).m_walkSpeed = _walkSpeedOriginal * stride; ((Character)_player).m_speed = _jogSpeedOriginal * stride; ((Character)_player).m_runSpeed = _runSpeedOriginal * stride; ((Character)_player).m_crouchSpeed = _crouchSpeedOriginal * stride; ((Character)_player).m_swimSpeed = _swimSpeedOriginal * stride; ((Character)_player).m_acceleration = _accelerationOriginal * stride; float num = BodyParts.JumpFactor(stride); ((Character)_player).m_jumpForce = _jumpForceOriginal * num; ((Character)_player).m_jumpForceForward = _jumpForwardOriginal * num; } internal float ScaleFactorAt(Transform t) { return PartFactorAt(t) * RootFactor; } private float PartFactorAt(Transform t) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) float num = 1f; Transform val = t; while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)((Component)this).transform) { if (_originals.TryGetValue(val, out var value) && value.x != 0f) { num *= val.localScale.x / value.x; } val = val.parent; } return num; } private bool CollectChain(Transform from, Vector3 tip, Vector3 up) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) _chain.Clear(); Vector3 val = tip; Transform val2 = from; while ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)((Component)this).transform) { _chain.Add((Vector3.Dot(val - val2.position, up), PartFactorAt(val2))); if ((Object)(object)val2 == (Object)(object)_hips) { return true; } val = val2.position; val2 = val2.parent; } _chain.Clear(); return false; } private void Restore() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) foreach (Bone bone in _bones) { if ((Object)(object)bone.T != (Object)null) { bone.T.localScale = bone.Original; } } ((Component)this).transform.localScale = _rootOriginal; if ((Object)(object)_armature != (Object)null) { _armature.localPosition = _armatureOriginal; } _armatureMoved = false; if ((Object)(object)_eye != (Object)null) { _eye.localPosition = _eyeOriginal; } ApplyFootIk(1f); _eyeMoved = false; _eyeLift = 0f; _applied = false; } private void LogSyncFlagsOnce() { if (s_logged.Add("sync-flags")) { ZSyncTransform component = ((Component)this).GetComponent<ZSyncTransform>(); string arg = (((Object)(object)component != (Object)null) ? component.m_syncScale.ToString() : "no ZSyncTransform"); ResizePlayerPlugin.Log.LogInfo((object)$"Player scale sync in vanilla: ZSyncTransform.m_syncScale={arg}, ZNetView.m_syncInitialScale={_nview.m_syncInitialScale}"); } } private static void LogOnce(string key, string message) { if (s_logged.Add(key)) { ResizePlayerPlugin.Log.LogWarning((object)message); } } } [BepInPlugin("com.oddhatter.resizeplayer", "ResizePlayer", "1.0.1")] [BepInProcess("valheim.exe")] public sealed class ResizePlayerPlugin : BaseUnityPlugin { public const string Guid = "com.oddhatter.resizeplayer"; public const string Name = "ResizePlayer"; public const string Version = "1.0.1"; internal static ManualLogSource Log; internal static ConfigEntry<bool> Enabled; internal static readonly Dictionary<Part, ConfigEntry<float>> Sizes = new Dictionary<Part, ConfigEntry<float>>(); private static readonly Dictionary<Part, string> SizeDescriptions = new Dictionary<Part, string> { [Part.Overall] = "Whole body, including hitbox, collision, equipment, movement speed, jumps, reach, swim depth and camera.", [Part.Head] = "Head (with hair, beard and helmet).", [Part.Neck] = "Neck.", [Part.Chest] = "Chest and shoulders area.", [Part.Belly] = "Belly and lower back.", [Part.Hips] = "Pelvis and butt. Your legs are kept on the ground.", [Part.Arms] = "Upper and lower arms.", [Part.Hands] = "Hands.", [Part.Legs] = "Upper and lower legs. Your body is raised or lowered to keep your feet on the ground, and longer legs move you faster and jump higher (both = Overall x Legs).", [Part.Feet] = "Feet. You stand on their soles." }; private const float ConfigReloadDelay = 0.5f; private Harmony _harmony; private FileSystemWatcher _configWatcher; private volatile bool _configFileChanged; private float _configReloadAt = -1f; private bool _configLockedLogged; private void Awake() { //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "true: your character uses the sizes below, and you see other players' sizes (if they have the mod). false: everyone looks vanilla, and other players see you at normal size."); Part[] all = BodyParts.All; for (int i = 0; i < all.Length; i++) { Part key = all[i]; Sizes[key] = ((BaseUnityPlugin)this).Config.Bind<float>("Size", key.ToString(), 1f, new ConfigDescription(SizeDescriptions[key] + " 1 = normal size.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 10f), Array.Empty<object>())); } _harmony = new Harmony("com.oddhatter.resizeplayer"); _harmony.PatchAll(typeof(ResizePlayerPlugin).Assembly); foreach (MethodBase patchedMethod in _harmony.GetPatchedMethods()) { Log.LogInfo((object)("Patched " + patchedMethod.DeclaringType?.Name + "." + patchedMethod.Name)); } WatchConfigFile(); Log.LogInfo((object)"ResizePlayer 1.0.1 loaded."); } private void Update() { if (_configFileChanged) { _configFileChanged = false; _configReloadAt = Time.realtimeSinceStartup + 0.5f; } if (_configReloadAt >= 0f && Time.realtimeSinceStartup >= _configReloadAt) { _configReloadAt = -1f; ReloadConfigFromDisk(); } } private void OnDestroy() { _configWatcher?.Dispose(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void WatchConfigFile() { string configFilePath = ((BaseUnityPlugin)this).Config.ConfigFilePath; _configWatcher = new FileSystemWatcher(Path.GetDirectoryName(configFilePath), Path.GetFileName(configFilePath)) { NotifyFilter = (NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite), IncludeSubdirectories = false }; _configWatcher.Changed += OnConfigFileEvent; _configWatcher.Created += OnConfigFileEvent; _configWatcher.Renamed += OnConfigFileEvent; _configWatcher.EnableRaisingEvents = true; } private void OnConfigFileEvent(object sender, FileSystemEventArgs e) { _configFileChanged = true; } private void ReloadConfigFromDisk() { if (!File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath)) { return; } bool saveOnConfigSet = ((BaseUnityPlugin)this).Config.SaveOnConfigSet; ((BaseUnityPlugin)this).Config.SaveOnConfigSet = false; try { ((BaseUnityPlugin)this).Config.Reload(); _configLockedLogged = false; Log.LogInfo((object)"Configuration reloaded from disk."); } catch (IOException ex) { if (!_configLockedLogged) { _configLockedLogged = true; Log.LogWarning((object)("Config file busy, will retry: " + ex.Message)); } _configReloadAt = Time.realtimeSinceStartup + 0.5f; } catch (Exception ex2) { Log.LogError((object)("Failed to reload configuration: " + ex2.Message)); } finally { ((BaseUnityPlugin)this).Config.SaveOnConfigSet = saveOnConfigSet; } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { internal IgnoresAccessChecksToAttribute(string assemblyName) { } } }