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 Rider v1.0.5
plugins/RideableTames.FaiControls.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; using UnityEngine.Rendering; [assembly: AssemblyTitle("RideableTames Fai Controls")] [assembly: AssemblyFileVersion("1.4.12.0")] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("1.4.12.0")] namespace Fai.RideableTames.Controls; internal sealed class AttackChoice { internal ItemData Item; internal bool Secondary; internal static List<AttackChoice> For(Humanoid mount) { List<ItemData> list = (from i in mount.GetInventory().GetAllItems() where i != null && i.m_shared != null && i.HavePrimaryAttack() && (int)i.m_shared.m_aiTargetType == 0 && Damage(i) > 0f select i).ToList(); List<ItemData> list2 = list.Where((ItemData i) => (!((Character)mount).IsFlying()) ? i.m_shared.m_aiWhenWalking : i.m_shared.m_aiWhenFlying).ToList(); if (list2.Count == 0) { list2 = list; } List<ItemData> list3 = list2.OrderBy((ItemData i) => i.m_shared.m_aiAttackInterval).ThenBy(Damage).ThenBy<ItemData, string>((ItemData i) => i.m_shared.m_name, StringComparer.Ordinal) .ThenBy<ItemData, string>((ItemData i) => (!((Object)(object)i.m_dropPrefab != (Object)null)) ? string.Empty : ((Object)i.m_dropPrefab).name, StringComparer.Ordinal) .ToList(); List<AttackChoice> list4 = new List<AttackChoice>(); foreach (ItemData item in list3) { if (!list4.Any((AttackChoice c) => c.Item.m_shared == item.m_shared)) { list4.Add(new AttackChoice { Item = item }); if (list4.Count == 3) { break; } } } foreach (ItemData item2 in list3) { if (list4.Count == 3) { break; } if (item2.HaveSecondaryAttack() && !list4.Any((AttackChoice c) => c.Secondary && c.Item.m_shared == item2.m_shared)) { list4.Add(new AttackChoice { Item = item2, Secondary = true }); } } return list4; } private static float Damage(ItemData item) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) DamageTypes damages = item.m_shared.m_damages; return damages.m_damage + damages.m_blunt + damages.m_slash + damages.m_pierce + damages.m_fire + damages.m_frost + damages.m_lightning + damages.m_poison + damages.m_spirit; } } internal static class CollarPlacement { internal const float ForwardDistance = 0.1f; internal const float BaseForwardTiltDegrees = 30f; internal static Quaternion BaseRotation(Quaternion original) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) Quaternion val = original * Quaternion.AngleAxis(-30f, Vector3.right); return ((Quaternion)(ref val)).normalized; } internal static Vector3 LocalOffset(Transform neck, Transform root, Quaternion gripRotation) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_00a7: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) Transform val = neck.Find("Head"); Vector3 val2 = ((!((Object)(object)val == (Object)null)) ? (val.position - neck.position) : (neck.rotation * gripRotation * Vector3.forward)); if (((Vector3)(ref val2)).sqrMagnitude < 1E-06f) { val2 = neck.rotation * gripRotation * Vector3.forward; } float num = Math.Max(1E-06f, Math.Abs(root.lossyScale.x)); Vector3 val3 = ((Vector3)(ref val2)).normalized * (0.1f * num); return neck.InverseTransformPoint(neck.position + val3); } } internal static class ControlMath { internal const int Stop = 0; internal const int Walk = 1; internal const int Jog = 2; internal const int Run = 3; internal static int Mode(float ahead, float stickMagnitude, bool analog, bool sprint, int previous, float threshold) { if (!Finite(ahead) || !Finite(stickMagnitude) || ahead <= 0.05f) { return 0; } if (sprint) { return 3; } if (!analog) { return 1; } float num = ((previous != 1) ? threshold : Math.Min(0.98f, threshold + 0.06f)); return (stickMagnitude <= num) ? 1 : 2; } internal static bool Finite(float value) { return !float.IsNaN(value) && !float.IsInfinity(value); } internal static bool SenderAllowed(long sender, long rider, bool owner, bool validUser) { return owner && validUser && rider != 0 && sender == rider; } internal static float Cost(int slot, float maximum, float skill) { return Math.Max(0f, maximum) * ((slot != 0) ? 0.12f : 0.06f) * (1f - 0.5f * Math.Max(0f, Math.Min(1f, skill))); } } internal struct HarnessSample { internal Vector3 Point; internal Vector3 Normal; internal HarnessSample(Vector3 point, Vector3 normal) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) Point = point; Normal = normal; } } internal static class HarnessGeometry { internal const float RestHeight = 0.035f; internal const float Width = 0.036f; internal const float Thickness = 0.004f; internal const float ForwardTiltDegrees = 35f; internal static HarnessSample[] ChestLoop(int segments = 48) { //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_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) float num = (float)Math.Asin(0.3400000035762787); float num2 = (float)Math.Cos(num); float num3 = 0.02f / (1f + num2); float num4 = 0.0625f + num3 * num3; float num5 = (float)Math.PI / 36f; float num6 = (float)Math.Cos(num5); float num7 = (float)Math.Sin(num5); HarnessSample[] array = new HarnessSample[segments + 1]; Vector3 point = default(Vector3); Vector3 val = default(Vector3); for (int i = 0; i <= segments; i++) { float num8 = 0f - num - (float)(Math.PI * 2.0 - (double)(2f * num)) * (float)i / (float)segments; float num9 = (float)Math.Sin(num8); float num10 = (float)Math.Cos(num8); ((Vector3)(ref point))..ctor(0.225f * num9, 0.012f + 0.25f * (num10 - num2), num3 * (num2 - num10)); ((Vector3)(ref val))..ctor(num9 / 0.225f, 0.25f * num10 / num4, (0f - num3) * num10 / num4); Vector3 normalized = ((Vector3)(ref val)).normalized; if (i == 0) { ((Vector3)(ref point))..ctor(-0.085f, 0.012f, 0f); } if (i == segments) { ((Vector3)(ref point))..ctor(0.085f, 0.012f, 0f); } ((Vector3)(ref point))..ctor(point.x, 0.012f + (point.y - 0.012f) * num6 + point.z * num7, (0f - (point.y - 0.012f)) * num7 + point.z * num6); ((Vector3)(ref normalized))..ctor(normalized.x, normalized.y * num6 + normalized.z * num7, (0f - normalized.y) * num7 + normalized.z * num6); ref HarnessSample reference = ref array[i]; reference = new HarnessSample(point, normalized); } return array; } internal static void AddRibbon(HarnessSample[] points, List<Vector3> vertices, List<Vector2> uv, List<int> triangles) { //IL_0027: 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) //IL_0050: 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_0073: 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_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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_00ac: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: 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_0130: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) int count = vertices.Count; float num = 0f; float[] array = new float[points.Length]; for (int i = 1; i < points.Length; i++) { num = (array[i] = num + Vector3.Distance(points[i - 1].Point, points[i].Point)); } Vector3 val = Vector3.zero; for (int j = 0; j < points.Length; j++) { Vector3 val2 = points[Math.Min(j + 1, points.Length - 1)].Point - points[Math.Max(j - 1, 0)].Point; Vector3 normalized = ((Vector3)(ref points[j].Normal)).normalized; Vector3 val3 = Vector3.Cross(val2, normalized); Vector3 val4 = ((Vector3)(ref val3)).normalized; if (((Vector3)(ref val4)).sqrMagnitude < 0.01f) { Vector3 val5 = Vector3.Cross(normalized, Vector3.forward); val4 = ((Vector3)(ref val5)).normalized; } if (((Vector3)(ref val4)).sqrMagnitude < 0.01f) { val4 = Vector3.right; } if (((Vector3)(ref val)).sqrMagnitude > 0f && Vector3.Dot(val, val4) < 0f) { val4 *= -1f; } val = val4; float num2 = ((!(num > 0.001f)) ? 0f : (array[j] / num)); for (int k = 0; k < 4; k++) { float num3 = ((k != 0 && k != 3) ? 1f : (-1f)); float num4 = ((k >= 2) ? (-1f) : 1f); vertices.Add(points[j].Point + val4 * (0.018f * num3) + normalized * (0.002f * num4)); uv.Add(new Vector2(0.0009765625f + num2 * 0.9980469f, 0.37597656f + ((!(num3 < 0f)) ? 1f : 0f) * 0.123046875f)); } if (j != 0) { for (int l = 0; l < 4; l++) { int num5 = count + (j - 1) * 4 + l; int num6 = count + (j - 1) * 4 + (l + 1) % 4; int c = num6 + 4; int d = num5 + 4; Quad(triangles, num5, num6, c, d); } } } Quad(triangles, count + 3, count + 2, count + 1, count); int num7 = count + (points.Length - 1) * 4; Quad(triangles, num7, num7 + 1, num7 + 2, num7 + 3); } internal static bool IsCompact(IList<Vector3> vertices, Vector3 origin, float radius) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) foreach (Vector3 vertex in vertices) { if (!float.IsNaN(vertex.x) && !float.IsNaN(vertex.y) && !float.IsNaN(vertex.z) && !float.IsInfinity(vertex.x) && !float.IsInfinity(vertex.y) && !float.IsInfinity(vertex.z)) { Vector3 val = vertex - origin; if (!(((Vector3)(ref val)).sqrMagnitude > radius * radius)) { continue; } } return false; } return true; } private static void Quad(List<int> t, int a, int b, int c, int d) { t.Add(a); t.Add(b); t.Add(c); t.Add(a); t.Add(c); t.Add(d); } } internal sealed class MountControl : MonoBehaviour { private const string MoveRpc = "fai_rt_move_v130"; private const string AttackRpc = "fai_rt_attack_v130"; private static readonly Func<Sadle, long> User = AccessTools.MethodDelegate<Func<Sadle, long>>(AccessTools.Method(typeof(Sadle), "GetUser", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<Sadle, long, Vector3, int, float> NativeControls = AccessTools.MethodDelegate<Action<Sadle, long, Vector3, int, float>>(AccessTools.Method(typeof(Sadle), "RPC_Controls", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<Sadle, float> Spend = AccessTools.MethodDelegate<Action<Sadle, float>>(AccessTools.Method(typeof(Sadle), "UseStamina", (Type[])null, (Type[])null), (object)null, true); private static readonly FieldInfo WalkField = AccessTools.Field(typeof(Character), "m_walk"); private static readonly HashSet<MountControl> Active = new HashSet<MountControl>(); internal Sadle Saddle; internal Character Creature; internal MonsterAI AI; private ZNetView view; private bool registered; private bool changedWalk; private bool oldWalk; internal int Mode; private int sentMode = -1; private Vector3 sentDirection; private float sentAt = -1000f; private float receivedAt = -1000f; private float lastAttack = -1000f; private int localMode; internal static MountControl Attach(Sadle saddle) { if (!Plugin.Ours(saddle)) { return null; } MountControl mountControl = ((Component)saddle).GetComponent<MountControl>(); if ((Object)(object)mountControl == (Object)null) { mountControl = ((Component)saddle).gameObject.AddComponent<MountControl>(); } mountControl.Saddle = saddle; mountControl.Creature = saddle.GetCharacter(); if ((Object)(object)mountControl.Creature == (Object)null) { return mountControl; } mountControl.AI = ((Component)mountControl.Creature).GetComponent<MonsterAI>(); mountControl.view = ((Component)mountControl.Creature).GetComponent<ZNetView>(); if (!mountControl.registered && (Object)(object)mountControl.view != (Object)null && mountControl.view.IsValid()) { mountControl.view.Register<Vector3, int, float>("fai_rt_move_v130", (Action<long, Vector3, int, float>)mountControl.ReceiveMove); mountControl.view.Register<int, Vector3>("fai_rt_attack_v130", (Action<long, int, Vector3>)mountControl.ReceiveAttack); mountControl.registered = true; } Active.Add(mountControl); return mountControl; } private bool Accept(long sender) { return registered && (Object)(object)Saddle != (Object)null && (Object)(object)Creature != (Object)null && (Object)(object)view != (Object)null && view.IsValid() && ControlMath.SenderAllowed(sender, User(Saddle), view.IsOwner(), Saddle.HaveValidUser()) && Creature.IsTamed() && !Creature.IsDead(); } internal void SendMove(Vector3 move, Vector3 look, bool sprint) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) if (!registered) { return; } Vector2 joyLeftStick = ZInput.GetJoyLeftStick(); bool analog = !ZInput.GetButton("Forward") && !ZInput.GetButton("Backward") && !ZInput.GetButton("Left") && !ZInput.GetButton("Right") && ((Vector2)(ref joyLeftStick)).sqrMagnitude > 0.0025f; localMode = ControlMath.Mode(move.z, ((Vector2)(ref joyLeftStick)).magnitude, analog, sprint, localMode, Plugin.WalkThreshold.Value); Vector3 forward = default(Vector3); ((Vector3)(ref forward))..ctor(look.x, 0f, look.z); if (((Vector3)(ref forward)).sqrMagnitude < 0.0001f) { forward = ((Component)Creature).transform.forward; } ((Vector3)(ref forward)).Normalize(); if (localMode == sentMode) { Vector3 val = forward - sentDirection; if (((Vector3)(ref val)).sqrMagnitude < 0.0004f && Time.time - sentAt < 0.15f) { return; } } Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && !((Object)/*isinst with value type is only supported in some contexts*/ != (Object)(object)Saddle)) { view.InvokeRPC("fai_rt_move_v130", new object[3] { forward, localMode, ((Character)localPlayer).GetSkillFactor((SkillType)110) }); sentMode = localMode; sentDirection = forward; sentAt = Time.time; } } private void ReceiveMove(long sender, Vector3 direction, int mode, float skill) { //IL_001a: 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_005f: 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) if (Accept(sender) && mode >= 0 && mode <= 3 && Finite(direction) && ControlMath.Finite(skill)) { direction.y = 0f; if (((Vector3)(ref direction)).sqrMagnitude < 0.0001f) { direction = ((Component)Creature).transform.forward; } ((Vector3)(ref direction)).Normalize(); Mode = mode; receivedAt = Time.time; NativeControls(Saddle, sender, direction, mode switch { 0 => 0, 3 => 2, _ => 1, }, Math.Max(0f, Math.Min(1f, skill))); } } internal bool OverrideIdle(ref bool result) { if ((Object)(object)view == (Object)null || !view.IsValid() || !view.IsOwner() || (Object)(object)Saddle == (Object)null || !Saddle.HaveValidUser() || (Object)(object)Creature == (Object)null || Creature.IsDead() || !Creature.IsTamed()) { RestoreWalk(); return false; } if (!changedWalk) { oldWalk = WalkField != null && (bool)WalkField.GetValue(Creature); changedWalk = true; } if (Time.time - receivedAt > 0.9f) { Mode = 0; } Creature.SetWalk(Mode == 1); if (Mode != 0 || (Object)(object)AI == (Object)null) { return false; } ((BaseAI)AI).StopMoving(); Creature.SetRun(false); ((BaseAI)AI).ResetRandomMovement(); result = true; return true; } internal void RequestAttack(int slot, Vector3 look) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (registered && slot >= 0 && slot < 3 && (Object)(object)localPlayer != (Object)null && (Object)/*isinst with value type is only supported in some contexts*/ == (Object)(object)Saddle) { view.InvokeRPC("fai_rt_attack_v130", new object[2] { slot, look }); } } private void ReceiveAttack(long sender, int slot, Vector3 look) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) if (!Accept(sender) || slot < 0 || slot > 2 || !Finite(look) || Time.time - lastAttack < 0.12f || Creature.InAttack() || Creature.InDodge() || Creature.IsKnockedBack() || Creature.IsStaggering()) { return; } Character creature = Creature; Humanoid val = (Humanoid)(object)((creature is Humanoid) ? creature : null); if ((Object)(object)val == (Object)null || val.GetInventory() == null) { return; } List<AttackChoice> list = AttackChoice.For(val); if (slot >= list.Count) { return; } AttackChoice attackChoice = list[slot]; float num = ControlMath.Cost(slot, Saddle.GetMaxStamina(), Saddle.GetRiderSkill()); if (Saddle.GetStamina() + 0.01f < num || (val.GetCurrentWeapon() != attackChoice.Item && !val.EquipItem(attackChoice.Item, false)) || val.GetCurrentWeapon() != attackChoice.Item) { return; } Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(look.x, 0f, look.z); if (((Vector3)(ref val2)).sqrMagnitude > 0.0001f) { ((Vector3)(ref val2)).Normalize(); ((Character)val).SetLookDir(((Vector3)(ref look)).normalized, 0f); ((Component)val).transform.rotation = Quaternion.LookRotation(val2, Vector3.up); } if (((Character)val).StartAttack((Character)null, attackChoice.Secondary)) { lastAttack = Time.time; if (num > 0f) { Spend(Saddle, num); } } } private static bool Finite(Vector3 value) { return ControlMath.Finite(value.x) && ControlMath.Finite(value.y) && ControlMath.Finite(value.z); } private void RestoreWalk() { if (changedWalk && (Object)(object)Creature != (Object)null) { Creature.SetWalk(oldWalk); } changedWalk = false; Mode = 0; localMode = 0; sentMode = -1; } private void OnDisable() { RestoreWalk(); Active.Remove(this); } private void OnDestroy() { RestoreWalk(); Active.Remove(this); } internal static void RestoreAll() { foreach (MountControl item in Active) { if ((Object)(object)item != (Object)null) { item.RestoreWalk(); } } Active.Clear(); } } [HarmonyPatch(typeof(Sadle), "Awake")] internal static class RegisterControls { private static void Postfix(Sadle __instance) { MountControl.Attach(__instance); } } [HarmonyPatch(typeof(Sadle), "ApplyControlls")] internal static class HoldToMove { private static bool Prefix(Sadle __instance, Vector3 moveDir, Vector3 lookDir, bool run) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.Ours(__instance)) { return true; } MountControl mountControl = MountControl.Attach(__instance); if ((Object)(object)mountControl != (Object)null) { mountControl.SendMove(moveDir, lookDir, run); } return false; } } [HarmonyPatch(typeof(Sadle), "UpdateRiding")] internal static class TrueWalkAndIdle { private static bool Prefix(Sadle __instance, ref bool __result) { if (!Plugin.Ours(__instance)) { return true; } MountControl mountControl = MountControl.Attach(__instance); return (Object)(object)mountControl == (Object)null || !mountControl.OverrideIdle(ref __result); } } [HarmonyPatch(typeof(Player), "SetControls")] internal static class AttackInputs { [HarmonyPriority(800)] private static void Prefix(Player __instance, ref bool attack, ref bool attackHold, ref bool secondaryAttack, ref bool secondaryAttackHold, ref bool block, ref bool blockHold) { //IL_0070: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return; } IDoodadController doodadController = __instance.GetDoodadController(); Sadle saddle = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); if (!Plugin.Ours(saddle)) { return; } int num = ((!attack) ? (block ? 1 : ((!secondaryAttack) ? (-1) : 2)) : 0); if (num >= 0) { MountControl mountControl = MountControl.Attach(saddle); if ((Object)(object)mountControl != (Object)null) { mountControl.RequestAttack(num, ((Character)__instance).GetLookDir()); } } attack = (attackHold = (secondaryAttack = (secondaryAttackHold = (block = (blockHold = false))))); } } internal static class PaletteMath { internal static Color32 Saddle(Color32 p, bool cloth) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) if (p.a == 0) { return p; } float num = (int)p.r; float num2 = (int)p.g; float num3 = (int)p.b; if (cloth && num > num2 * 1.65f && num > num3 * 1.65f) { return Pixel(num * 0.2f, num * 0.34f, num * 0.56f, p.a); } if (num > num2 && num2 > num3 * 1.35f && num2 > 85f && num < num2 * 1.65f) { return Pixel(num * 0.56f, num2 * 0.44f, num3 * 0.36f, p.a); } return Pixel(num * 0.55f, num2 * 0.5f, num3 * 0.45f, p.a); } internal static Color32 Handle(Color32 p, bool metal) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) if (p.a == 0) { return p; } float num = (int)Math.Max(p.r, Math.Max(p.g, p.b)); return (!metal) ? Pixel(num * 0.58f, num * 0.35f, num * 0.19f, p.a) : Pixel(num * 0.28f, num * 0.28f, num * 0.28f, p.a); } private static Color32 Pixel(float r, float g, float b, byte a) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) return new Color32(Byte(r), Byte(g), Byte(b), a); } private static byte Byte(float n) { return (byte)Math.Max(0, Math.Min(255, (int)Math.Round(n))); } } internal static class Palette { private static readonly HashSet<Material> done = new HashSet<Material>(); internal static void Saddle(Material material) { Apply(material, 0); } internal static void Handles(Material[] materials) { if (materials != null) { if (materials.Length > 0) { Apply(materials[0], 2); } if (materials.Length > 1) { Apply(materials[1], 2); } if (materials.Length > 2) { Apply(materials[2], 1); } } } private static void Apply(Material material, int kind) { //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)material == (Object)null || done.Contains(material)) { return; } Texture mainTexture = material.mainTexture; Texture2D val = (Texture2D)(object)((mainTexture is Texture2D) ? mainTexture : null); if ((Object)(object)val == (Object)null) { return; } try { Color32[] pixels = val.GetPixels32(); for (int i = 0; i < ((Texture)val).height; i++) { for (int j = 0; j < ((Texture)val).width; j++) { int num = i * ((Texture)val).width + j; ref Color32 reference = ref pixels[num]; reference = ((kind != 0) ? PaletteMath.Handle(pixels[num], kind == 1) : PaletteMath.Saddle(pixels[num], j >= ((Texture)val).width / 2 && i >= ((Texture)val).height / 2)); } } Texture2D val2 = new Texture2D(((Texture)val).width, ((Texture)val).height, (TextureFormat)4, true); ((Object)val2).name = "fai_navy_brown_" + ((Object)val).name; ((Texture)val2).filterMode = ((Texture)val).filterMode; ((Texture)val2).wrapMode = ((Texture)val).wrapMode; ((Texture)val2).anisoLevel = ((Texture)val).anisoLevel; ((Object)val2).hideFlags = (HideFlags)32; Texture2D val3 = val2; val3.SetPixels32(pixels); val3.Apply(true, false); material.mainTexture = (Texture)(object)val3; done.Add(material); } catch (Exception ex) { done.Add(material); Plugin.Log.LogWarning((object)("Could not recolour saddle/handle material: " + ex.Message)); } } } [HarmonyPatch] internal static class SaddleColours { private static MethodBase TargetMethod() { return AccessTools.PropertyGetter(AccessTools.TypeByName("RideableTames.SaddleLook"), "Material"); } private static void Postfix(Material __result) { Palette.Saddle(__result); } } [HarmonyPatch] internal static class HandleColours { private static MethodBase TargetMethod() { return AccessTools.Method(AccessTools.TypeByName("Fai.RideableTames.HandleVisuals"), "MaterialsFor", (Type[])null, (Type[])null); } private static void Postfix(Material[] __result) { Palette.Handles(__result); } } [BepInPlugin("fai.rideabletames.controls", "RideableTames Fai Controls", "1.4.12")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { internal static Type Marker; internal static ConfigEntry<float> WalkThreshold; internal static ManualLogSource Log; private Harmony harmony; private void Awake() { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Marker = AccessTools.TypeByName("RideableTames.MountMarker"); if (Marker == null) { throw new InvalidOperationException("RideableTames mount marker is unavailable."); } WalkThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Movement", "AnalogWalkThreshold", 0.8f, new ConfigDescription("Up to this processed stick deflection uses true walking. A small hysteresis prevents animation flicker. Full push uses the original jog; the game's Run input sprints.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 0.95f), Array.Empty<object>())); harmony = new Harmony("fai.rideabletames.controls.v1412"); try { harmony.PatchAll(typeof(Plugin).Assembly); } catch { harmony.UnpatchSelf(); harmony = null; throw; } Sadle[] array = Resources.FindObjectsOfTypeAll<Sadle>(); foreach (Sadle saddle in array) { if (Ours(saddle)) { MountControl.Attach(saddle); WolfHarness.Refresh(saddle); } } ((BaseUnityPlugin)this).Logger.LogInfo((object)"V4.1 riding retained. Controls, a forward wolf neck collar and a low resting handle loaded."); } internal static bool Ours(Sadle saddle) { return (Object)(object)saddle != (Object)null && Marker != null && (Object)(object)((Component)saddle).GetComponent(Marker) != (Object)null; } private void OnDestroy() { MountControl.RestoreAll(); WolfHarness.Shutdown(); if (harmony != null) { harmony.UnpatchSelf(); } harmony = null; } } internal sealed class RestingHandle { private readonly Transform bar; private readonly Transform grip; private readonly Transform capL; private readonly Transform capR; private readonly Transform left; private readonly Transform right; private readonly float height; private bool rested; internal RestingHandle(Transform parts, float originalHeight) { bar = parts.Find("bar"); left = parts.Find("strapL"); right = parts.Find("strapR"); grip = bar.Find("grip"); capL = bar.Find("capL"); capR = bar.Find("capR"); height = originalHeight; } internal void Apply(bool occupied) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_008d: Unknown result type (might be due to invalid IL or missing references) if (occupied) { rested = false; } else if (!rested) { bar.localPosition = new Vector3(0f, 0.047f, 0f); bar.localRotation = Quaternion.identity; grip.localScale = Vector3.one; capL.localPosition = new Vector3(-0.112f, 0f, 0f); capR.localPosition = new Vector3(0.112f, 0f, 0f); Upright(left, -0.085f); Upright(right, 0.085f); rested = true; } } private void Upright(Transform upright, float x) { //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_0038: Unknown result type (might be due to invalid IL or missing references) upright.localPosition = new Vector3(x, 0.0295f, 0f); upright.localRotation = Quaternion.identity; upright.localScale = new Vector3(1f, 0.035f / height, 1f); } } internal sealed class WolfHarness : MonoBehaviour { private const string HandleName = "fai_packbeasts_handle"; private static readonly HashSet<WolfHarness> Active = new HashSet<WolfHarness>(); private Character creature; private Transform parts; private Transform left; private RestingHandle rest; private Mesh mesh; private GameObject display; private bool configured; private bool failed; private object movedFit; private FieldInfo gripLocalField; private FieldInfo gripRotationField; private Vector3 originalGripLocal; private Vector3 collarGripLocal; private Quaternion originalGripRotation; private Quaternion collarGripRotation; internal static WolfHarness Prepare(Sadle saddle) { if (!Plugin.Ours(saddle)) { return null; } Character componentInParent = ((Component)saddle).GetComponentInParent<Character>(); if ((Object)(object)componentInParent == (Object)null || Utils.GetPrefabName(((Component)componentInParent).gameObject) != "Wolf") { return null; } Transform val = ((Component)saddle).transform.Find("fai_packbeasts_handle"); if ((Object)(object)val == (Object)null) { return null; } WolfHarness wolfHarness = ((Component)val).GetComponent<WolfHarness>(); if ((Object)(object)wolfHarness == (Object)null) { wolfHarness = ((Component)val).gameObject.AddComponent<WolfHarness>(); } if (!wolfHarness.configured) { wolfHarness.Configure(saddle, componentInParent); } if (!wolfHarness.configured) { return null; } wolfHarness.MoveBaseToNeck(saddle); return wolfHarness; } internal static void Refresh(Sadle saddle) { WolfHarness wolfHarness = Prepare(saddle); if ((Object)(object)wolfHarness == (Object)null) { return; } wolfHarness.rest.Apply(saddle.HaveValidUser()); if ((Object)(object)wolfHarness.display != (Object)null) { wolfHarness.display.SetActive(((Component)wolfHarness).gameObject.activeInHierarchy); } if ((Object)(object)wolfHarness.mesh != (Object)null || wolfHarness.failed || !((Component)wolfHarness).gameObject.activeInHierarchy) { return; } ZNetView component = ((Component)wolfHarness.creature).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || !component.IsValid()) { return; } try { wolfHarness.Build(); } catch (Exception ex) { wolfHarness.failed = true; wolfHarness.ReleaseMesh(); Plugin.Log.LogWarning((object)("Wolf neck collar could not be created: " + ex.Message)); } } private void Configure(Sadle target, Character owner) { //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) parts = ((Component)this).transform.Find("parts"); if ((Object)(object)parts == (Object)null) { return; } Transform val = parts.Find("bar"); Transform val2 = parts.Find("strapR"); left = parts.Find("strapL"); if (!((Object)(object)val == (Object)null) && !((Object)(object)left == (Object)null) && !((Object)(object)val2 == (Object)null)) { Transform val3 = val.Find("grip"); Transform val4 = val.Find("capL"); Transform val5 = val.Find("capR"); MeshFilter component = ((Component)left).GetComponent<MeshFilter>(); if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val4 == (Object)null) && !((Object)(object)val5 == (Object)null) && !((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null)) { Transform obj = parts; Bounds bounds = component.sharedMesh.bounds; rest = new RestingHandle(obj, Math.Max(0.06f, ((Bounds)(ref bounds)).size.y)); creature = owner; configured = true; Active.Add(this); } } } private void MoveBaseToNeck(Sadle target) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) if (movedFit != null) { return; } Type type = AccessTools.TypeByName("Fai.RideableTames.MountedRig"); Component component = ((Component)target).GetComponent(type); if ((Object)(object)component == (Object)null) { return; } object obj = AccessTools.PropertyGetter(type, "Fit").Invoke(component, null); if (obj != null) { Type type2 = obj.GetType(); Transform val = (Transform)AccessTools.Field(type2, "GripBone").GetValue(obj); if (!((Object)(object)val == (Object)null)) { gripRotationField = AccessTools.Field(type2, "GripRotation"); originalGripRotation = (Quaternion)gripRotationField.GetValue(obj); gripLocalField = AccessTools.Field(type2, "GripLocal"); originalGripLocal = (Vector3)gripLocalField.GetValue(obj); collarGripLocal = originalGripLocal + CollarPlacement.LocalOffset(val, ((Component)creature).transform, originalGripRotation); collarGripRotation = CollarPlacement.BaseRotation(originalGripRotation); gripLocalField.SetValue(obj, collarGripLocal); gripRotationField.SetValue(obj, collarGripRotation); movedFit = obj; } } } private void RestoreBase() { //IL_002e: 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) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) if (movedFit != null && !(gripLocalField == null)) { Vector3 val = (Vector3)gripLocalField.GetValue(movedFit); Vector3 val2 = val - collarGripLocal; if (((Vector3)(ref val2)).sqrMagnitude < 1E-08f) { gripLocalField.SetValue(movedFit, originalGripLocal); } Quaternion val3 = (Quaternion)gripRotationField.GetValue(movedFit); if (Quaternion.Angle(val3, collarGripRotation) < 0.01f) { gripRotationField.SetValue(movedFit, originalGripRotation); } movedFit = null; } } private void Build() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Expected O, but got Unknown List<Vector3> list = new List<Vector3>(); List<Vector2> list2 = new List<Vector2>(); List<int> list3 = new List<int>(); HarnessGeometry.AddRibbon(HarnessGeometry.ChestLoop(), list, list2, list3); if (!HarnessGeometry.IsCompact(list, Vector3.zero, 1f)) { throw new InvalidOperationException("Collar geometry exceeds its local extent limit."); } display = new GameObject("fai_wolf_neck_collar"); display.layer = ((Component)parts).gameObject.layer; display.transform.SetParent(parts, false); Mesh val = new Mesh(); ((Object)val).name = "fai_wolf_neck_collar"; ((Object)val).hideFlags = (HideFlags)32; mesh = val; mesh.SetVertices(list); mesh.SetUVs(0, list2); mesh.SetTriangles(list3, 0); mesh.RecalculateNormals(); mesh.RecalculateBounds(); display.AddComponent<MeshFilter>().sharedMesh = mesh; MeshRenderer val2 = display.AddComponent<MeshRenderer>(); Transform val3 = ((Component)this).transform.parent.Find("model"); MeshRenderer val4 = ((!((Object)(object)val3 == (Object)null)) ? ((Component)val3).GetComponent<MeshRenderer>() : null); Material val5 = ((!((Object)(object)val4 == (Object)null)) ? ((Renderer)val4).sharedMaterial : null); if ((Object)(object)val5 == (Object)null) { val5 = (Material)AccessTools.PropertyGetter(AccessTools.TypeByName("RideableTames.SaddleLook"), "Material").Invoke(null, null); } ((Renderer)val2).sharedMaterial = val5; ((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)val2).enabled = true; AccessTools.Method(AccessTools.TypeByName("RideableTames.Mounts"), "AddToLods", (Type[])null, (Type[])null).Invoke(null, new object[2] { ((Component)creature).gameObject, val2 }); Plugin.Log.LogInfo((object)("Wolf neck collar 1.4.12 created: " + list.Count + " vertices; 10 cm offset / 30 deg base / 35 deg collar.")); } private void ReleaseMesh() { if ((Object)(object)display != (Object)null) { Object.Destroy((Object)(object)display); } display = null; if ((Object)(object)mesh != (Object)null) { Object.Destroy((Object)(object)mesh); } mesh = null; } private void OnEnable() { if ((Object)(object)display != (Object)null) { display.SetActive(true); } } private void OnDisable() { if ((Object)(object)display != (Object)null) { display.SetActive(false); } } private void OnDestroy() { RestoreBase(); ReleaseMesh(); Active.Remove(this); } internal static void Shutdown() { foreach (WolfHarness item in new List<WolfHarness>(Active)) { if ((Object)(object)item != (Object)null) { item.RestoreBase(); item.ReleaseMesh(); Object.Destroy((Object)(object)item); } } Active.Clear(); } } [HarmonyPatch] internal static class WolfHarnessVisuals { private static MethodBase TargetMethod() { return AccessTools.Method(AccessTools.TypeByName("Fai.RideableTames.MountedRig"), "Hold", (Type[])null, (Type[])null); } private static void Prefix(object __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) WolfHarness.Prepare(((Component)__instance).GetComponent<Sadle>()); } private static void Postfix(object __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) WolfHarness.Refresh(((Component)__instance).GetComponent<Sadle>()); } }
plugins/RideableTames.FaiExtensions.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Globalization; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; using UnityEngine.Rendering; [assembly: AssemblyTitle("RideableTames Fai Extensions")] [assembly: AssemblyDescription("PackBeasts handle model, jumping and riding camera transplanted into RideableTames")] [assembly: AssemblyFileVersion("1.2.0.0")] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("1.2.0.0")] namespace Fai.RideableTames; internal enum HandleMaterial { Leather, Dark, Brass } internal struct HandlePart { internal string Name; internal Vector3 Size; internal Vector3 Position; internal float Radius; internal HandleMaterial Material; internal HandlePart(string name, Vector3 size, float radius, Vector3 position, HandleMaterial material) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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) Name = name; Size = size; Radius = radius; Position = position; Material = material; } } internal sealed class MeshData { internal readonly List<Vector3> Vertices = new List<Vector3>(); internal readonly List<Vector3> Normals = new List<Vector3>(); internal readonly List<Vector2> UV = new List<Vector2>(); internal readonly List<int> Triangles = new List<int>(); } internal static class HandleGeometry { internal static HandlePart[] Parts(float height) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) height = PortMath.Clamp(height, 0.06f, 0.4f); return new HandlePart[8] { new HandlePart("pad", new Vector3(0.17f, 0.025f, 0.11f), 0.011f, new Vector3(0f, 0.0125f, 0f), HandleMaterial.Dark), new HandlePart("strapL", new Vector3(0.03f, height, 0.026f), 0.008f, new Vector3(-0.085f, height * 0.5f + 0.012f, 0f), HandleMaterial.Leather), new HandlePart("rivetL", new Vector3(0.018f, 0.018f, 0.03f), 0.008f, new Vector3(-0.085f, 0.04f, 0f), HandleMaterial.Brass), new HandlePart("strapR", new Vector3(0.03f, height, 0.026f), 0.008f, new Vector3(0.085f, height * 0.5f + 0.012f, 0f), HandleMaterial.Leather), new HandlePart("rivetR", new Vector3(0.018f, 0.018f, 0.03f), 0.008f, new Vector3(0.085f, 0.04f, 0f), HandleMaterial.Brass), new HandlePart("grip", new Vector3(0.23f, 0.036f, 0.04f), 0.016f, new Vector3(0f, height + 0.012f, 0f), HandleMaterial.Leather), new HandlePart("capL", new Vector3(0.016f, 0.04f, 0.044f), 0.007f, new Vector3(-0.112f, height + 0.012f, 0f), HandleMaterial.Brass), new HandlePart("capR", new Vector3(0.016f, 0.04f, 0.044f), 0.007f, new Vector3(0.112f, height + 0.012f, 0f), HandleMaterial.Brass) }; } internal static MeshData RoundedBox(Vector3 size, float radius, int segments = 6) { //IL_0012: 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_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: 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_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0106: 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_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_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_0177: 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_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_020f: 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_0219: 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_0233: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) if (segments < 1) { throw new ArgumentOutOfRangeException("segments"); } Vector3 val = size * 0.5f; radius = PortMath.Clamp(radius, 0f, Math.Min(val.x, Math.Min(val.y, val.z)) * 0.95f); Vector3 val2 = val - Vector3.one * radius; MeshData meshData = new MeshData(); Vector3[] array = (Vector3[])(object)new Vector3[6] { Vector3.right, Vector3.left, Vector3.up, Vector3.down, Vector3.forward, Vector3.back }; Vector3[] array2 = array; Vector3 val7 = default(Vector3); for (int i = 0; i < array2.Length; i++) { Vector3 val3 = array2[i]; Vector3 val4 = ((!(Math.Abs(val3.y) > 0.5f)) ? Vector3.up : Vector3.right); Vector3 val5 = Vector3.Cross(val3, val4); int count = meshData.Vertices.Count; for (int j = 0; j <= segments; j++) { for (int k = 0; k <= segments; k++) { float num = (float)k / (float)segments * 2f - 1f; float num2 = (float)j / (float)segments * 2f - 1f; Vector3 val6 = Vector3.Scale(val3 + val4 * num + val5 * num2, val); ((Vector3)(ref val7))..ctor(PortMath.Clamp(val6.x, 0f - val2.x, val2.x), PortMath.Clamp(val6.y, 0f - val2.y, val2.y), PortMath.Clamp(val6.z, 0f - val2.z, val2.z)); Vector3 val8 = val6 - val7; Vector3 val9 = ((!(((Vector3)(ref val8)).sqrMagnitude > 1E-10f)) ? val3 : ((Vector3)(ref val8)).normalized); meshData.Vertices.Add(val7 + val9 * radius); meshData.Normals.Add(((Vector3)(ref val9)).normalized); meshData.UV.Add(new Vector2((num + 1f) * 0.5f, (num2 + 1f) * 0.5f)); } } for (int l = 0; l < segments; l++) { for (int m = 0; m < segments; m++) { int num3 = count + l * (segments + 1) + m; int b = num3 + 1; int num4 = num3 + segments + 2; int c = num3 + segments + 1; AddTriangle(meshData, num3, b, num4); AddTriangle(meshData, num3, num4, c); } } } return meshData; } private static void AddTriangle(MeshData data, int a, int b, int c) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Vector3.Cross(data.Vertices[b] - data.Vertices[a], data.Vertices[c] - data.Vertices[a]); if (Vector3.Dot(val, data.Normals[a] + data.Normals[b] + data.Normals[c]) < 0f) { int num = b; b = c; c = num; } data.Triangles.Add(a); data.Triangles.Add(b); data.Triangles.Add(c); } internal static float SurfaceHeight(Vector3[] vertices, int[] triangles, float z) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) float num = float.NegativeInfinity; for (int i = 0; i + 2 < triangles.Length; i += 3) { Vector3 val = vertices[triangles[i]]; Vector3 val2 = vertices[triangles[i + 1]]; Vector3 val3 = vertices[triangles[i + 2]]; float num2 = (val2.z - val3.z) * (val.x - val3.x) + (val3.x - val2.x) * (val.z - val3.z); if (!(Math.Abs(num2) < 1E-09f)) { float num3 = ((val2.z - val3.z) * (0f - val3.x) + (val3.x - val2.x) * (z - val3.z)) / num2; float num4 = ((val3.z - val.z) * (0f - val3.x) + (val.x - val3.x) * (z - val3.z)) / num2; float num5 = 1f - num3 - num4; if (num3 >= -0.0001f && num4 >= -0.0001f && num5 >= -0.0001f) { num = Math.Max(num, num3 * val.y + num4 * val2.y + num5 * val3.y); } } } return (!float.IsNegativeInfinity(num)) ? num : 0f; } } internal sealed class HandleGrip { private readonly Transform parts; private readonly Transform bar; private readonly Transform grip; private readonly Transform capL; private readonly Transform capR; private readonly Transform strapL; private readonly Transform strapR; private readonly Vector3 barPos; private readonly Vector3 gripScale; private readonly Vector3 capLPos; private readonly Vector3 capRPos; private readonly Vector3 strapLPos; private readonly Vector3 strapRPos; private readonly Vector3 strapScale; private readonly Quaternion barRot; private readonly Quaternion strapRot; private readonly float strapRest; internal bool Held { get; private set; } internal HandleGrip(Transform root, float height) { //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: 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_00d5: 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_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_012a: 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) parts = root.Find("parts"); bar = parts.Find("bar"); grip = bar.Find("grip"); capL = bar.Find("capL"); capR = bar.Find("capR"); strapL = parts.Find("strapL"); strapR = parts.Find("strapR"); barPos = bar.localPosition; barRot = bar.localRotation; gripScale = grip.localScale; capLPos = capL.localPosition; capRPos = capR.localPosition; strapLPos = strapL.localPosition; strapRPos = strapR.localPosition; strapRot = strapL.localRotation; strapScale = strapL.localScale; strapRest = PortMath.Clamp(height, 0.06f, 0.4f); } internal bool Follow(Player rider) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) VisEquipment val = ((!((Object)(object)rider == (Object)null)) ? ((Component)rider).GetComponent<VisEquipment>() : null); if ((Object)(object)val == (Object)null || (Object)(object)val.m_leftHand == (Object)null || (Object)(object)val.m_rightHand == (Object)null) { Rest(); return false; } return Follow(val.m_leftHand.position, val.m_rightHand.position); } internal bool Follow(Vector3 left, Vector3 right) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: 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_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: 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_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0118: 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_013c: 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_014b: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: 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_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) float num = Math.Abs(parts.lossyScale.x); if (num < 0.0001f) { Rest(); return false; } Vector3 val = (left + right) * 0.5f; float num2 = Vector3.Distance(left, right); Vector3 val2 = parts.TransformPoint(new Vector3(0f, 0.012f, 0f)); if (num2 > 0.9f || Vector3.Distance(val, val2) > 1f) { Rest(); return false; } Vector3 val3 = ((!(num2 <= 0.02f)) ? ((right - left) / num2) : parts.right); Vector3 val4 = val - val2; val4 = ((!(((Vector3)(ref val4)).sqrMagnitude <= 0.0001f)) ? ((Vector3)(ref val4)).normalized : parts.up); Vector3 val5 = Vector3.Cross(val3, val4); if (((Vector3)(ref val5)).sqrMagnitude < 0.0001f) { val5 = Vector3.Cross(val3, parts.up); } if (((Vector3)(ref val5)).sqrMagnitude < 0.0001f) { Rest(); return false; } ((Vector3)(ref val5)).Normalize(); val4 = Vector3.Cross(val5, val3); bar.SetPositionAndRotation(val, Quaternion.LookRotation(val5, val4)); float num3 = PortMath.Clamp(num2 + 0.09f, 0.23f * num, 0.99f) / num; Transform obj = grip; Vector3 val6 = gripScale; float num4 = val6.x * num3 / 0.23f; Vector3 val7 = gripScale; float y = val7.y; Vector3 val8 = gripScale; obj.localScale = new Vector3(num4, y, val8.z); capL.localPosition = new Vector3(0f - (num3 * 0.5f - 0.003f), 0f, 0f); capR.localPosition = new Vector3(num3 * 0.5f - 0.003f, 0f, 0f); float num5 = PortMath.Clamp(num2 / num * 0.5f - 0.06f, 0.04f, 0.085f); Strap(strapL, parts.TransformPoint(new Vector3(-0.085f, 0.012f, 0f)), bar.TransformPoint(new Vector3(0f - num5, 0f, 0f)), num); Strap(strapR, parts.TransformPoint(new Vector3(0.085f, 0.012f, 0f)), bar.TransformPoint(new Vector3(num5, 0f, 0f)), num); Held = true; return true; } private void Strap(Transform strap, Vector3 from, Vector3 to, float scale) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_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_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0053: 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) Vector3 val = to - from; float magnitude = ((Vector3)(ref val)).magnitude; if (!(magnitude < 0.005f)) { Vector3 val2 = val / magnitude; Vector3 val3 = Vector3.ProjectOnPlane(parts.forward, val2); if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f) { val3 = Vector3.ProjectOnPlane(parts.right, val2); } strap.SetPositionAndRotation((from + to) * 0.5f, Quaternion.LookRotation(((Vector3)(ref val3)).normalized, val2)); Vector3 val4 = strapScale; float x = val4.x; Vector3 val5 = strapScale; float num = val5.y * magnitude / scale / strapRest; Vector3 val6 = strapScale; strap.localScale = new Vector3(x, num, val6.z); } } internal void Rest() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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_005e: 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_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) if (Held) { Held = false; bar.localPosition = barPos; bar.localRotation = barRot; grip.localScale = gripScale; capL.localPosition = capLPos; capR.localPosition = capRPos; strapL.localPosition = strapLPos; strapR.localPosition = strapRPos; strapL.localRotation = strapRot; strapR.localRotation = strapRot; strapL.localScale = strapScale; strapR.localScale = strapScale; } } } internal static class HandleVisuals { private const string RootName = "fai_packbeasts_handle"; private static readonly Dictionary<string, Mesh> meshes = new Dictionary<string, Mesh>(); private static readonly Dictionary<Material, Material[]> materials = new Dictionary<Material, Material[]>(); internal static void Ensure(Transform saddleTransform) { Sadle component = ((Component)saddleTransform).GetComponent<Sadle>(); if (Runtime.IsOurs(component)) { MountedRig.Ensure(component); } } internal static Transform Build(Sadle saddle, float height) { //IL_0055: 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_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Expected O, but got Unknown //IL_01ef: 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_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)saddle).transform; Transform val = transform.Find("model"); if ((Object)(object)val == (Object)null) { return null; } MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>(); if ((Object)(object)component == (Object)null) { return null; } Transform val2 = transform.Find("fai_packbeasts_handle"); if ((Object)(object)val2 != (Object)null) { return val2; } val2 = new GameObject("fai_packbeasts_handle").transform; ((Component)val2).gameObject.layer = ((Component)val).gameObject.layer; val2.SetParent(transform, false); ((Component)val2).gameObject.SetActive(Runtime.ShowHandle.Value); Transform transform2 = new GameObject("parts").transform; ((Component)transform2).gameObject.layer = ((Component)val).gameObject.layer; transform2.SetParent(val2, false); Transform transform3 = new GameObject("bar").transform; ((Component)transform3).gameObject.layer = ((Component)val).gameObject.layer; transform3.SetParent(transform2, false); transform3.localPosition = new Vector3(0f, height + 0.012f, 0f); Material[] array = MaterialsFor(((Renderer)component).sharedMaterial); Character componentInParent = ((Component)saddle).GetComponentInParent<Character>(); HandlePart[] array2 = HandleGeometry.Parts(height); for (int i = 0; i < array2.Length; i++) { HandlePart part = array2[i]; GameObject val3 = new GameObject(part.Name); val3.layer = ((Component)val).gameObject.layer; bool flag = part.Name == "grip" || part.Name == "capL" || part.Name == "capR"; val3.transform.SetParent((!flag) ? transform2 : transform3, false); val3.transform.localPosition = ((!flag) ? part.Position : (part.Position - transform3.localPosition)); val3.AddComponent<MeshFilter>().sharedMesh = MeshFor(part); MeshRenderer val4 = val3.AddComponent<MeshRenderer>(); ((Renderer)val4).sharedMaterial = array[(int)part.Material]; ((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0; if ((Object)(object)componentInParent != (Object)null && Runtime.AddToLods != null) { Runtime.AddToLods.Invoke(null, new object[2] { ((Component)componentInParent).gameObject, val4 }); } } return val2; } private static Mesh MeshFor(HandlePart part) { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Expected O, but got Unknown string key = string.Format(CultureInfo.InvariantCulture, "{0:R}/{1:R}/{2:R}/{3:R}", part.Size.x, part.Size.y, part.Size.z, part.Radius); if (meshes.TryGetValue(key, out var value) && (Object)(object)value != (Object)null) { return value; } MeshData meshData = HandleGeometry.RoundedBox(part.Size, part.Radius); Mesh val = new Mesh(); ((Object)val).name = "fai_packbeasts_" + part.Name; ((Object)val).hideFlags = (HideFlags)32; value = val; value.SetVertices(meshData.Vertices); value.SetNormals(meshData.Normals); value.SetUVs(0, meshData.UV); value.SetTriangles(meshData.Triangles, 0); value.RecalculateBounds(); meshes[key] = value; return value; } private static Material[] MaterialsFor(Material original) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)original != (Object)null && materials.TryGetValue(original, out var value)) { return value; } value = (Material[])(object)new Material[3] { Make(original, Leather(new Color(0.46f, 0.27f, 0.14f), new Color(0.78f, 0.6f, 0.38f))), Make(original, Leather(new Color(0.3f, 0.17f, 0.08f), new Color(0.55f, 0.4f, 0.22f))), Make(original, Solid(new Color(0.82f, 0.64f, 0.26f))) }; if ((Object)(object)original != (Object)null) { materials[original] = value; } return value; } private static Material Make(Material original, Texture2D texture) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_004d: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) Material val = ((!((Object)(object)original != (Object)null)) ? new Material(Shader.Find("Standard")) : new Material(original)); ((Object)val).name = "fai_packbeasts_" + ((Object)texture).name; ((Object)val).hideFlags = (HideFlags)32; val.mainTexture = (Texture)(object)texture; val.mainTextureScale = Vector2.one; val.mainTextureOffset = Vector2.zero; if (val.HasProperty("_Color")) { val.color = Color.white; } string[] array = new string[7] { "_BumpMap", "_MetallicGlossMap", "_EmissionMap", "_OcclusionMap", "_DetailAlbedoMap", "_DetailNormalMap", "_SpecGlossMap" }; foreach (string text in array) { if (val.HasProperty(text)) { val.SetTexture(text, (Texture)null); } } if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", Color.black); } val.DisableKeyword("_NORMALMAP"); val.DisableKeyword("_EMISSION"); return val; } private static Texture2D Leather(Color colour, Color stitch) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(64, 64, (TextureFormat)4, true); ((Object)val).name = "leather"; ((Texture)val).wrapMode = (TextureWrapMode)1; ((Texture)val).filterMode = (FilterMode)1; ((Object)val).hideFlags = (HideFlags)32; Texture2D val2 = val; Random random = new Random(5); Color[] array = (Color[])(object)new Color[4096]; for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { Color val3 = colour * (0.9f + (float)random.NextDouble() * 0.16f); int num = Math.Min(Math.Min(j, i), Math.Min(63 - j, 63 - i)); if (num < 2) { val3 *= 0.7f; } else if (num == 4 && (j + i) / 3 % 2 == 0) { val3 = stitch; } val3.a = 1f; array[i * 64 + j] = val3; } } val2.SetPixels(array); val2.Apply(true); return val2; } private static Texture2D Solid(Color colour) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(4, 4, (TextureFormat)4, false); ((Object)val).name = "brass"; ((Object)val).hideFlags = (HideFlags)32; Texture2D val2 = val; Color[] array = (Color[])(object)new Color[16]; for (int i = 0; i < array.Length; i++) { array[i] = colour; } val2.SetPixels(array); val2.Apply(false); return val2; } } internal sealed class MountFit { internal Transform Root; internal Transform SeatBone; internal Transform GripBone; internal Vector3 SeatLocal; internal Vector3 GripLocal; internal Quaternion GripRotation; internal float GripHeight = 0.25f; internal bool Exact; internal string Pose; private Quaternion facing; private bool haveFacing; private int turnFrame = -1; private Transform fallbackSeat; internal bool SaddleSeat104; internal Vector3 Spot => (!SaddleSeat104 && !Exact) ? fallbackSeat.position : SeatBone.TransformPoint(SeatLocal); internal static MountFit Find(Character creature, Sadle saddle, string kind) { //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_004a: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: 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_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: 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) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)creature).transform; MountFit mountFit = new MountFit(); mountFit.Root = transform; MountFit mountFit2 = mountFit; if (kind == "Wolf") { mountFit2.SeatBone = saddle.m_attachPoint.parent; mountFit2.SeatLocal = saddle.m_attachPoint.localPosition; mountFit2.SeatLocal += new Vector3(0f, 0f, 0.06f); mountFit2.GripBone = transform.Find("Visual/WolfSmooth/CG/Pelvis/Spine/Spine1/Spine2/Neck"); mountFit2.GripLocal = new Vector3(0.02184f, -0.11636f, 0f); Quaternion val = default(Quaternion); ((Quaternion)(ref val))..ctor(-0.69684f, 0.12003f, 0.69684f, 0.12004f); mountFit2.GripRotation = ((Quaternion)(ref val)).normalized; } else if (kind == "Boar") { mountFit2.SeatBone = transform.Find("Visual/CG/Pelvis/Spine/Spine1"); mountFit2.SeatLocal = new Vector3(0.0131f, -0.22318f, 3E-05f); mountFit2.GripBone = transform.Find("Visual/CG/Pelvis/Spine/Spine1/Spine2"); mountFit2.GripLocal = new Vector3(-0.20848f, -0.21987f, 5E-05f); Quaternion val2 = default(Quaternion); ((Quaternion)(ref val2))..ctor(-0.707f, 0.01252f, 0.707f, 0.01236f); mountFit2.GripRotation = ((Quaternion)(ref val2)).normalized; } mountFit2.Exact = (Object)(object)mountFit2.SeatBone != (Object)null && (Object)(object)mountFit2.GripBone != (Object)null; if (mountFit2.Exact) { mountFit2.Pose = "attach_asksvin"; } else { mountFit2.fallbackSeat = saddle.m_attachPoint; mountFit2.SeatBone = saddle.m_attachPoint.parent; mountFit2.SeatLocal = saddle.m_attachPoint.localPosition; mountFit2.GripBone = ((Component)saddle).transform; mountFit2.GripLocal = new Vector3(0f, 0.12f, 0.2f); mountFit2.GripRotation = Quaternion.identity; } SaddleSeatAlignment104.Configure(mountFit2, saddle, kind); return mountFit2; } internal void Place(Transform seat, Transform handle, float delta) { //IL_00a4: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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_00c6: 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_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) if (turnFrame != Time.frameCount) { Quaternion rotation = Root.rotation; if (!haveFacing) { facing = rotation; haveFacing = true; } else if (delta > 0f) { float num = 0.12f + -0.089999996f * PortMath.Clamp(Quaternion.Angle(facing, rotation) / 15f, 0f, 1f); facing = Quaternion.Slerp(facing, rotation, 1f - (float)Math.Exp((0f - delta) / num)); } turnFrame = Time.frameCount; } if (!SaddleSeatAlignment104.Place(this, seat, facing) && Exact) { seat.SetPositionAndRotation(Spot + facing * new Vector3(0f, -0.071f, -0.103f), facing); } PlaceHandle(handle); } internal void PlaceHandle(Transform handle) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)handle == (Object)null) && !((Object)(object)GripBone == (Object)null)) { handle.SetPositionAndRotation(GripBone.TransformPoint(GripLocal), GripBone.rotation * GripRotation); handle.localScale = Vector3.one * Scale(Root) / Scale(handle.parent); } } private static float Scale(Transform value) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) float num = Math.Abs(value.lossyScale.x); return (!(num > 1E-06f)) ? 1f : num; } } internal sealed class MountedRig : MonoBehaviour { private static readonly HashSet<MountedRig> active = new HashSet<MountedRig>(); private static bool hooked; private static int drawnFrame = -1; private Sadle saddle; private Character creature; private Transform visual; private HandleGrip hands; private bool reported; private bool failed; internal MountFit Fit { get; private set; } internal static MountedRig Ensure(Sadle target) { if (!Runtime.IsOurs(target)) { return null; } MountedRig mountedRig = ((Component)target).GetComponent<MountedRig>(); if ((Object)(object)mountedRig == (Object)null) { mountedRig = ((Component)target).gameObject.AddComponent<MountedRig>(); } mountedRig.Configure(target); return mountedRig; } private void Configure(Sadle target) { //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Expected O, but got Unknown //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Expected O, but got Unknown saddle = target; if ((Object)(object)creature == (Object)null) { creature = ((Component)target).GetComponentInParent<Character>(); } if ((Object)(object)creature == (Object)null || (Object)(object)saddle.m_attachPoint == (Object)null) { return; } if (Fit == null) { Fit = MountFit.Find(creature, saddle, Runtime.Kind(saddle)); if (!Fit.Exact && Runtime.Kind(saddle) != "Deer") { Runtime.Log.LogWarning((object)("PackBeasts fit bones are absent on " + Runtime.Kind(saddle) + "; using the existing saddle seat with animated hand-follow.")); } } if (Fit.Exact) { saddle.m_attachAnimation = Fit.Pose; } if (!Runtime.Headless && (Object)(object)visual == (Object)null) { visual = HandleVisuals.Build(saddle, Fit.GripHeight); if ((Object)(object)visual != (Object)null) { hands = new HandleGrip(visual, Fit.GripHeight); } } if ((Object)(object)visual != (Object)null) { ((Component)visual).gameObject.SetActive(Runtime.ShowHandle.Value); } Place(); if (((Component)this).gameObject.activeInHierarchy) { active.Add(this); } if (!hooked && !Runtime.Headless) { Camera.onPreCull = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(BeforeDrawing)); hooked = true; } } internal void Place() { if (Fit != null && (Object)(object)saddle != (Object)null && (Object)(object)saddle.m_attachPoint != (Object)null) { Fit.Place(saddle.m_attachPoint, visual, Time.deltaTime); } } private Player Rider() { //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)saddle == (Object)null || !saddle.HaveValidUser()) { return null; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && (Object)/*isinst with value type is only supported in some contexts*/ == (Object)(object)saddle) { return localPlayer; } Player result = null; float num = 1.2f; foreach (Player allPlayer in Player.GetAllPlayers()) { if (!((Object)(object)allPlayer == (Object)null) && !((Object)(object)allPlayer == (Object)(object)localPlayer) && !((Character)allPlayer).IsDead()) { IDoodadController doodadController = allPlayer.GetDoodadController(); if ((Object)(object)((doodadController is Sadle) ? doodadController : null) == (Object)(object)saddle || (Object)(object)allPlayer.GetAttachPoint() == (Object)(object)saddle.m_attachPoint) { return allPlayer; } float num2 = Vector3.Distance(((Component)allPlayer).transform.position, saddle.m_attachPoint.position); if (num2 < num) { result = allPlayer; num = num2; } } } return result; } private void Hold() { if (hands == null) { return; } if (!Runtime.ShowHandle.Value || (Object)(object)visual == (Object)null || !((Component)visual).gameObject.activeInHierarchy) { hands.Rest(); return; } Fit.PlaceHandle(visual); Player val = Rider(); if (hands.Follow(val) && !reported && (Object)(object)val == (Object)(object)Player.m_localPlayer) { reported = true; Runtime.Log.LogInfo((object)("PackBeasts hand-follow active on " + Runtime.Kind(saddle) + "; pose=" + saddle.m_attachAnimation + "; fit=" + ((!Fit.Exact) ? "existing saddle" : "PackBeasts Back") + ".")); } if ((Object)(object)val == (Object)null) { reported = false; } } private void LateUpdate() { try { if (Fit == null) { Configure(((Component)this).GetComponent<Sadle>()); } Place(); Hold(); } catch (Exception ex) { if (!failed) { failed = true; Runtime.Log.LogWarning((object)("PackBeasts riding rig: " + ex)); } } } private void OnEnable() { active.Add(this); } private void OnDisable() { active.Remove(this); if (hands != null) { hands.Rest(); } reported = false; } private void OnDestroy() { active.Remove(this); } private static void BeforeDrawing(Camera camera) { if (drawnFrame == Time.frameCount) { return; } drawnFrame = Time.frameCount; foreach (MountedRig item in new List<MountedRig>(active)) { if ((Object)(object)item == (Object)null) { active.Remove(item); continue; } try { item.Hold(); } catch (Exception ex) { if (!item.failed) { item.failed = true; Runtime.Log.LogWarning((object)("PackBeasts hand update: " + ex)); } } } } internal static void Shutdown() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown if (hooked) { Camera.onPreCull = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(BeforeDrawing)); } hooked = false; foreach (MountedRig item in active) { if ((Object)(object)item != (Object)null && item.hands != null) { item.hands.Rest(); } } active.Clear(); drawnFrame = -1; } } [HarmonyPatch(typeof(Player), "UpdateAttach")] internal static class PlaceRidingSeatPatch { private static void Prefix(Player __instance) { IDoodadController doodadController = __instance.GetDoodadController(); Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); if (Runtime.IsOurs(val)) { MountedRig mountedRig = MountedRig.Ensure(val); if ((Object)(object)mountedRig != (Object)null) { mountedRig.Place(); } } } } internal static class RidingHands { private static bool putAway; private static readonly MethodInfo ShowHands = AccessTools.Method(typeof(Humanoid), "ShowHandItems", new Type[2] { typeof(bool), typeof(bool) }, (Type[])null); internal static void Hide(Player player) { if (!((Object)(object)player != (Object)(object)Player.m_localPlayer) && Runtime.ShowHandle.Value && Runtime.IsOurs((Sadle)/*isinst with value type is only supported in some contexts*/) && ((Humanoid)player).HideHandItems(false, false)) { putAway = true; } } internal static void Restore(Player player) { if (!((Object)(object)player != (Object)(object)Player.m_localPlayer) && putAway) { putAway = false; if (ShowHands != null) { ShowHands.Invoke(player, new object[2] { false, false }); } } } } [HarmonyPatch(typeof(Player), "StartDoodadControl")] internal static class PutAwayRidingItemsPatch { private static void Postfix(Player __instance) { RidingHands.Hide(__instance); } } [HarmonyPatch(typeof(Player), "StopDoodadControl")] internal static class RestoreRidingItemsPatch { private static void Postfix(Player __instance) { RidingHands.Restore(__instance); } } internal static class PortMath { internal static float JumpCost(float percent, float maximum, float skill) { return Math.Max(0f, percent) / 100f * Math.Max(0f, maximum) * (1f - 0.5f * Clamp(skill, 0f, 1f)); } internal static float Clamp(float value, float minimum, float maximum) { return Math.Max(minimum, Math.Min(maximum, value)); } internal static bool CanPay(float stamina, float cost) { return cost <= 0f || stamina + 0.01f >= cost; } internal static Vector3 CameraStep(Vector3 camera, ref Vector3 velocity, Vector3 seat, float delta, float seconds) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: 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_0057: 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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007b: 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_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_0099: 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_009c: 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_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_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_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: 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_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_0113: 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_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) if (seconds <= 0f) { velocity = Vector3.zero; return seat; } if (delta <= 0f) { return camera; } float num = 2f / seconds; float num2 = num * delta; float num3 = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2); Vector3 val = camera - seat; Vector3 val2 = (velocity + num * val) * delta; velocity = (velocity - num * val2) * num3; Vector3 val3 = seat + (val + val2) * num3; if (Vector3.Dot(seat - camera, val3 - seat) > 0f) { val3 = seat; velocity = Vector3.zero; } Vector3 val4 = val3 - seat; float magnitude = ((Vector3)(ref val4)).magnitude; return (!(magnitude > 1.5f)) ? val3 : (seat + val4 * (1.5f / magnitude)); } internal static float ParseCameraDistance(string text, out bool invalid) { invalid = false; text = (text ?? string.Empty).Trim(); if (text.Length == 0 || text.Equals("Auto", StringComparison.OrdinalIgnoreCase)) { return float.NaN; } if (float.TryParse(text.Replace(',', '.'), NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out var result) && !float.IsNaN(result) && !float.IsInfinity(result)) { return (!(result > 0f)) ? 0f : Clamp(result, 1f, 100f); } invalid = true; return float.NaN; } internal static float CameraMaximum(float setting, float gameMaximum, float boatMaximum, float height) { if (setting == 0f) { return gameMaximum; } if (!float.IsNaN(setting)) { return setting; } float val = ((!(boatMaximum > gameMaximum)) ? 30f : boatMaximum); return Math.Max(gameMaximum, Math.Min(2.5f * Math.Max(0f, height), val)); } internal static float EaseCameraMaximum(float target, float distance, float delta) { if (distance <= target) { return target; } return (!(delta <= 0f)) ? (target + (distance - target) * (float)Math.Exp((0f - delta) / 0.4f)) : distance; } } internal static class RideCamera { private static readonly Action<Player> UpdateEye = AccessTools.MethodDelegate<Action<Player>>(AccessTools.DeclaredMethod(typeof(Player), "UpdateEyeRotation", (Type[])null, (Type[])null), (object)null, true); private static Sadle current; private static Rigidbody body; private static RigidbodyInterpolation oldInterpolation; private static bool changedBody; private static bool haveCamera; private static Vector3 camera; private static Vector3 velocity; private static Vector3 shift; private static int frame = -1; private static bool invalidLogged; private static Sadle reported; internal static Vector3 Shift => (!((Object)(object)current != (Object)null) || frame != Time.frameCount) ? Vector3.zero : shift; internal static Sadle Current(Player player) { if ((Object)(object)player == (Object)null || ((Character)player).IsDead() || !((Character)player).IsRiding()) { return null; } IDoodadController doodadController = player.GetDoodadController(); Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); return (!Runtime.IsOurs(val)) ? null : val; } internal static void Before(float delta) { //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0230: 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_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Invalid comparison between Unknown and I4 //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0291: 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_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02a2: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: 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_0172: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Sadle val = Current(localPlayer); if ((Object)(object)val == (Object)null) { Reset(); return; } if ((Object)(object)current != (Object)(object)val) { Reset(); current = val; } Character character = val.GetCharacter(); if ((Object)(object)character == (Object)null || (Object)(object)val.m_attachPoint == (Object)null) { Reset(); } else { if (frame == Time.frameCount) { return; } MountedRig mountedRig = MountedRig.Ensure(val); if (Runtime.SmoothRiding.Value) { Rigidbody component = ((Component)character).GetComponent<Rigidbody>(); if ((Object)(object)component != (Object)(object)body) { RestoreBody(); body = component; } if ((Object)(object)body != (Object)null && !body.isKinematic && !changedBody) { oldInterpolation = body.interpolation; changedBody = (int)oldInterpolation != 1; if (changedBody) { body.interpolation = (RigidbodyInterpolation)1; } } if ((Object)(object)mountedRig != (Object)null) { mountedRig.Place(); } Quaternion rotation = ((!((Object)(object)((Character)localPlayer).m_eye != (Object)null)) ? Quaternion.identity : ((Character)localPlayer).m_eye.rotation); Transform attachPoint = localPlayer.GetAttachPoint(); if ((Object)(object)attachPoint == (Object)null) { attachPoint = val.m_attachPoint; } ((Component)localPlayer).transform.SetPositionAndRotation(attachPoint.position, attachPoint.rotation); if (UpdateEye != null) { UpdateEye(localPlayer); } else if ((Object)(object)((Character)localPlayer).m_eye != (Object)null) { ((Character)localPlayer).m_eye.rotation = rotation; } } else { RestoreBody(); if ((Object)(object)mountedRig != (Object)null) { mountedRig.Place(); } } frame = Time.frameCount; Transform transform = ((Component)character).transform; Vector3 val2 = ((!((Object)(object)mountedRig != (Object)null) || mountedRig.Fit == null) ? val.m_attachPoint.position : mountedRig.Fit.Spot); Vector3 val3 = Quaternion.Inverse(transform.rotation) * (val2 - transform.position); float value = Runtime.SteadyCamera.Value; if (!haveCamera || value <= 0f) { camera = val3; velocity = Vector3.zero; haveCamera = value > 0f; } else { camera = PortMath.CameraStep(camera, ref velocity, val3, delta, value); } shift = ((!haveCamera) ? Vector3.zero : (transform.rotation * (camera - val3))); if ((Object)(object)reported != (Object)(object)val) { reported = val; Runtime.Log.LogInfo((object)("PackBeasts camera active: SmoothRiding=" + Runtime.SmoothRiding.Value + ", SteadyCamera=" + Runtime.SteadyCamera.Value + ", riding zoom=" + Runtime.CameraDistance.Value + ".")); } } } internal static float Maximum(Sadle saddle, float gameMaximum, float boatMaximum) { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) bool invalid; float setting = PortMath.ParseCameraDistance(Runtime.CameraDistance.Value, out invalid); if (invalid && !invalidLogged) { invalidLogged = true; Runtime.Log.LogWarning((object)"CameraDistanceWhileRiding must be Auto, 0, or a number; Auto is used."); } if (!invalid) { invalidLogged = false; } Character character = saddle.GetCharacter(); if ((Object)(object)character == (Object)null) { return gameMaximum; } float num = ((!((Object)(object)saddle.m_attachPoint == (Object)null)) ? (saddle.m_attachPoint.position.y - ((Component)character).transform.position.y) : 0f); CapsuleCollider component = ((Component)character).GetComponent<CapsuleCollider>(); if ((Object)(object)component != (Object)null) { float num2 = ((component.direction != 1) ? (2f * component.radius) : Math.Max(component.height, 2f * component.radius)); num = Math.Max(num, num2 * Math.Abs(((Component)character).transform.lossyScale.y)); } return PortMath.CameraMaximum(setting, gameMaximum, boatMaximum, num); } private static void RestoreBody() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (changedBody && (Object)(object)body != (Object)null && (int)body.interpolation == 1) { body.interpolation = oldInterpolation; } changedBody = false; body = null; } internal static void Reset() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) RestoreBody(); current = null; reported = null; haveCamera = false; shift = Vector3.zero; velocity = Vector3.zero; frame = -1; } } [HarmonyPatch(typeof(GameCamera), "LateUpdate")] internal static class RidingCameraPreparePatch { private static void Prefix() { RideCamera.Before(Time.deltaTime); } } [HarmonyPatch(typeof(GameCamera), "UpdateCamera")] internal static class RidingCameraPatch { private static GameCamera zoomCamera; private static bool returningFromOurMount; private static void Prefix(GameCamera __instance, float dt, float ___m_distance, out float __state) { __state = __instance.m_maxDistance; RideCamera.Before(dt); if ((Object)(object)zoomCamera != (Object)(object)__instance) { zoomCamera = __instance; returningFromOurMount = false; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsAttachedToShip()) { returningFromOurMount = false; return; } Sadle val = RideCamera.Current(localPlayer); float target = __state; if ((Object)(object)val != (Object)null) { returningFromOurMount = true; target = RideCamera.Maximum(val, __state, __instance.m_maxDistanceBoat); } else if (!returningFromOurMount || localPlayer.GetDoodadController() is Sadle || ___m_distance <= __state + 0.01f) { returningFromOurMount = false; return; } __instance.m_maxDistance = PortMath.EaseCameraMaximum(target, ___m_distance, dt); } private static void Finalizer(GameCamera __instance, float __state) { if ((Object)(object)__instance != (Object)null) { __instance.m_maxDistance = __state; } } } [HarmonyPatch(typeof(GameCamera), "GetOffsetedEyePos")] internal static class RidingCameraBobbingPatch { private static void Postfix(GameCamera __instance, float ___m_distance, ref Vector3 __result) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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) if (!(___m_distance <= 0f) && !((Object)(object)RideCamera.Current(Player.m_localPlayer) == (Object)null)) { __result += RideCamera.Shift; } } } internal sealed class MountJump : MonoBehaviour { internal const string RpcName = "fai_rt_jump_v1"; private static readonly Func<Sadle, long> GetUser = AccessTools.MethodDelegate<Func<Sadle, long>>(AccessTools.Method(typeof(Sadle), "GetUser", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<Sadle, float> UseStamina = AccessTools.MethodDelegate<Action<Sadle, float>>(AccessTools.Method(typeof(Sadle), "UseStamina", (Type[])null, (Type[])null), (object)null, true); private Sadle saddle; private ZNetView view; private bool registered; private float lastJump = -1000f; internal bool AllowJump; internal static MountJump Attach(Sadle target) { if (!Runtime.IsOurs(target)) { return null; } MountJump mountJump = ((Component)target).GetComponent<MountJump>(); if ((Object)(object)mountJump == (Object)null) { mountJump = ((Component)target).gameObject.AddComponent<MountJump>(); } mountJump.saddle = target; Character character = target.GetCharacter(); if ((Object)(object)character == (Object)null) { return mountJump; } mountJump.view = ((Component)character).GetComponent<ZNetView>(); if (!mountJump.registered && (Object)(object)mountJump.view != (Object)null && mountJump.view.IsValid()) { mountJump.view.Register("fai_rt_jump_v1", (Action<long>)mountJump.Receive); mountJump.registered = true; } return mountJump; } internal void Request(Player player) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) if (!registered || (Object)(object)player == (Object)null) { return; } long num = GetUser(saddle); ZDOID zDOID = ((Character)player).GetZDOID(); if (num == ((ZDOID)(ref zDOID)).UserID) { float cost = PortMath.JumpCost(Runtime.JumpStamina.Value, saddle.GetMaxStamina(), ((Character)player).GetSkillFactor((SkillType)110)); if (!PortMath.CanPay(saddle.GetStamina(), cost)) { ((Character)player).Message((MessageType)2, "坐騎耐力不足", 0, (Sprite)null, false); } else { view.InvokeRPC("fai_rt_jump_v1", Array.Empty<object>()); } } } private void Receive(long sender) { if (!registered || (Object)(object)view == (Object)null || !view.IsValid() || !view.IsOwner() || (Object)(object)saddle == (Object)null || !Runtime.JumpEnabled.Value || !saddle.HaveValidUser()) { return; } long num = GetUser(saddle); if (num == 0 || sender != num || Time.time - lastJump < 0.25f) { return; } Character character = saddle.GetCharacter(); if ((Object)(object)character == (Object)null || character.IsDead() || !character.IsTamed() || !character.IsOnGround() || character.InAttack() || character.IsEncumbered() || character.InDodge() || character.IsKnockedBack() || character.IsStaggering()) { return; } float num2 = PortMath.JumpCost(Runtime.JumpStamina.Value, saddle.GetMaxStamina(), saddle.GetRiderSkill()); if (!PortMath.CanPay(saddle.GetStamina(), num2)) { return; } float jumpForce = character.m_jumpForce; try { AllowJump = true; character.m_jumpForce = Math.Max(jumpForce, Runtime.MinimumJumpForce.Value); character.Jump(false); if (!character.IsOnGround()) { lastJump = Time.time; if (num2 > 0f) { UseStamina(saddle, num2); } } } finally { character.m_jumpForce = jumpForce; AllowJump = false; } } private void LateUpdate() { if (!registered) { Attach(((Component)this).GetComponent<Sadle>()); } } } [HarmonyPatch(typeof(Sadle), "Awake")] internal static class RegisterMountJumpPatch { private static void Postfix(Sadle __instance) { MountJump.Attach(__instance); MountedRig.Ensure(__instance); } } [HarmonyPatch(typeof(Player), "SetControls")] internal static class RidingJumpInputPatch { [HarmonyPriority(800)] private static void Prefix(Player __instance, ref bool jump, ref bool crouch) { if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || Runtime.JumpEnabled == null || !Runtime.JumpEnabled.Value) { return; } IDoodadController doodadController = __instance.GetDoodadController(); Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); if (!Runtime.IsOurs(val)) { return; } if (crouch) { crouch = false; jump = false; __instance.StopDoodadControl(); } else if (jump) { jump = false; MountJump mountJump = MountJump.Attach(val); if ((Object)(object)mountJump != (Object)null) { mountJump.Request(__instance); } } } } [HarmonyPatch(typeof(Character), "Jump")] internal static class NoAutomaticHopsPatch { private static bool Prefix(Character __instance) { if (Runtime.JumpEnabled == null || !Runtime.JumpEnabled.Value || __instance is Player) { return true; } Tameable component = ((Component)__instance).GetComponent<Tameable>(); if ((Object)(object)component == (Object)null || (Object)(object)component.m_saddle == (Object)null) { return true; } Sadle component2 = ((Component)component.m_saddle).GetComponent<Sadle>(); if (!Runtime.IsOurs(component2) || !component2.HaveValidUser()) { return true; } MountJump component3 = ((Component)component2).GetComponent<MountJump>(); return (Object)(object)component3 != (Object)null && component3.AllowJump; } } public static class Runtime { internal const string HarmonyId = "fai.rideabletames.transplants"; internal static BaseUnityPlugin Host; internal static ManualLogSource Log; internal static Type MarkerType; internal static Type MountsType; internal static MethodInfo AddToLods; internal static ConfigEntry<bool> JumpEnabled; internal static ConfigEntry<bool> ShowHandle; internal static ConfigEntry<bool> SmoothRiding; internal static ConfigEntry<float> JumpStamina; internal static ConfigEntry<float> MinimumJumpForce; internal static ConfigEntry<float> SteadyCamera; internal static ConfigEntry<string> CameraDistance; internal static bool Headless; private static volatile bool refreshVisuals; private static Harmony harmony; public static void Initialize(BaseUnityPlugin host) { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Invalid comparison between Unknown and I4 //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Expected O, but got Unknown if (harmony == null) { Host = host; Log = Logger.CreateLogSource("RideableTames Fai"); MarkerType = ((object)host).GetType().Assembly.GetType("RideableTames.MountMarker", throwOnError: true); MountsType = ((object)host).GetType().Assembly.GetType("RideableTames.Mounts", throwOnError: true); AddToLods = AccessTools.Method(MountsType, "AddToLods", (Type[])null, (Type[])null); Headless = (int)SystemInfo.graphicsDeviceType == 4; JumpEnabled = Rule("Riding", "JumpEnabled", value: true, "Jump makes the ridden RideableTames animal jump instead of dismounting. E or Crouch gets you off. Only affects RideableTames saddles."); JumpStamina = Rule("Riding", "JumpStaminaPercent", 4f, "PackBeasts jump cost: percent of maximum mount stamina; riding skill reduces it to half at skill 100.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f)); MinimumJumpForce = Rule("Riding", "MinimumJumpForce", 8f, "PackBeasts minimum jump impulse. A creature with a stronger own jump keeps it. Only changed during the jump call.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 20f)); ShowHandle = Local("Handle", "ShowHandle", value: true, "Add the PackBeasts handle on top of the original saddle. The original saddle remains visible."); ShowHandle.SettingChanged += LookChanged; SmoothRiding = Local("Camera", "SmoothRiding", value: true, "PackBeasts smooth riding: interpolate the ridden animal and place you on its animated saddle every render frame; preserve your mouse view."); SteadyCamera = Local("Camera", "SteadyCamera", 1.5f, "PackBeasts camera smoothing time in seconds. Removes animated seat bobbing while following the creature's actual movement and jumps. 0 follows exactly.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f)); CameraDistance = Local("Camera", "CameraDistanceWhileRiding", "Auto", "PackBeasts zoom limit: Auto = 2.5 times creature height, at least normal maximum, capped by ship maximum (or 30m). A number = 1-100 metres; 0 = normal. Scroll to zoom. Dismount eases back to the normal limit."); ConfigEntry<int> val = Local("PackBeasts Port", "PresetRevision", 0, "Automatic preset migration marker. No user setup is required."); if (val.Value < 120) { JumpEnabled.Value = true; JumpStamina.Value = 4f; MinimumJumpForce.Value = 8f; ShowHandle.Value = true; SmoothRiding.Value = true; SteadyCamera.Value = 1.5f; CameraDistance.Value = "Auto"; val.Value = 120; Host.Config.Save(); Log.LogInfo((object)"Applied PackBeasts 1.7.6 defaults automatically; old static handle offsets are no longer used."); } MigrateRiderJumpDefaults(); harmony = new Harmony("fai.rideabletames.transplants"); try { harmony.PatchAll(typeof(Runtime).Assembly); } catch { harmony.UnpatchSelf(); harmony = null; throw; } refreshVisuals = true; Log.LogInfo((object)"RideableTames Fai 1.2.0 loaded: PackBeasts fitted seat, animated hand-follow, original saddle, jumping and riding camera."); } } private static ConfigEntry<T> Rule<T>(string section, string key, T value, string description, AcceptableValueBase range = null) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown ConfigFile config = Host.Config; object[] array = new object[1]; ConfigurationManagerAttributes val = new ConfigurationManagerAttributes(); val.IsAdminOnly = true; array[0] = val; return config.Bind<T>(section, key, value, new ConfigDescription(description, range, array)); } private static ConfigEntry<T> Local<T>(string section, string key, T value, string description, AcceptableValueBase range = null) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown return Host.Config.Bind<T>(section, key, value, new ConfigDescription(description, range, Array.Empty<object>())); } private static void LookChanged(object sender, EventArgs args) { refreshVisuals = true; } internal static bool IsOurs(Sadle saddle) { return (Object)(object)saddle != (Object)null && MarkerType != null && (Object)(object)((Component)saddle).GetComponent(MarkerType) != (Object)null; } internal static string Kind(Sadle saddle) { Character componentInParent = ((Component)saddle).GetComponentInParent<Character>(); string text = ((!((Object)(object)componentInParent == (Object)null)) ? Utils.GetPrefabName(((Component)componentInParent).gameObject) : "Wolf"); object result; switch (text) { case "Wolf": case "Boar": case "Deer": result = text; break; default: result = "Wolf"; break; } return (string)result; } internal static void Tick() { if (!refreshVisuals) { return; } refreshVisuals = false; Sadle[] array = Resources.FindObjectsOfTypeAll<Sadle>(); foreach (Sadle val in array) { if (IsOurs(val)) { MountJump.Attach(val); HandleVisuals.Ensure(((Component)val).transform); } } } public static void Shutdown() { RideCamera.Reset(); MountedRig.Shutdown(); RidingHands.Restore(Player.m_localPlayer); if (harmony != null) { harmony.UnpatchSelf(); } harmony = null; } private static void MigrateRiderJumpDefaults() { ConfigEntry<int> val = Local("Riding", "RiderJumpPresetRevision", 0, "One-time Rider mounted-jump defaults migration."); if (val.Value < 101) { JumpEnabled.Value = true; JumpStamina.Value = 4f; MinimumJumpForce.Value = 8f; val.Value = 101; Host.Config.Save(); Log.LogInfo((object)"Rider 1.0.1 mounted jumping enabled with PackBeasts defaults."); } } } [HarmonyPatch] internal static class AddSaddleLookPatch { private static MethodBase TargetMethod() { return AccessTools.Method(Runtime.MountsType, "AddSaddle", (Type[])null, (Type[])null); } private static void Postfix(GameObject prefab) { if (Runtime.Headless) { return; } Sadle[] componentsInChildren = prefab.GetComponentsInChildren<Sadle>(true); foreach (Sadle val in componentsInChildren) { if (Runtime.IsOurs(val)) { HandleVisuals.Ensure(((Component)val).transform); } } } } [HarmonyPatch] internal static class ApplySaddleLookPatch { private static MethodBase TargetMethod() { return AccessTools.Method(Runtime.MountsType, "ApplyLookTo", (Type[])null, (Type[])null); } private static void Postfix(Transform saddle) { if (!Runtime.Headless) { HandleVisuals.Ensure(saddle); } } } [HarmonyPatch] internal static class BaseUpdatePatch { private static MethodBase TargetMethod() { return AccessTools.Method(((object)Runtime.Host).GetType(), "Update", (Type[])null, (Type[])null); } private static void Postfix() { Runtime.Tick(); } } [HarmonyPatch(typeof(Character), "GetSlideAngle")] internal static class MountedSlideAnglePatch { [HarmonyPostfix] internal static void Postfix(Character __instance, ref float __result) { if (!((Object)(object)__instance == (Object)null) && !(__instance is Player) && __instance.HaveRider()) { Tameable component = ((Component)__instance).GetComponent<Tameable>(); if (!((Object)(object)component == (Object)null) && Runtime.IsOurs(component.m_saddle)) { __result = 60f; } } } } internal static class SaddleSeatAlignment104 { internal static void Configure(MountFit fit, Sadle saddle, string kind) { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) if (!(kind != "Boar") || !(kind != "Deer")) { Transform attachPoint = saddle.m_attachPoint; if (!((Object)(object)attachPoint == (Object)null) && !((Object)(object)attachPoint.parent == (Object)null)) { fit.SeatBone = attachPoint.parent; fit.SeatLocal = attachPoint.localPosition + new Vector3(0f, 0f, -0.04f); fit.SaddleSeat104 = true; } } } internal static bool Place(MountFit fit, Transform seat, Quaternion facing) { //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_001f: Unknown result type (might be due to invalid IL or missing references) if (!fit.SaddleSeat104) { return false; } seat.SetPositionAndRotation(fit.SeatBone.TransformPoint(fit.SeatLocal), facing); return true; } }
plugins/RideableTames.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Fai.RideableTames; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("RideableTames")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.2.0")] [assembly: AssemblyInformationalVersion("1.2.0")] [assembly: AssemblyProduct("RideableTames")] [assembly: AssemblyTitle("RideableTames")] [assembly: AssemblyVersion("1.2.0.0")] [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 RideableTames { public class MountMarker : MonoBehaviour { public int Kind; } internal sealed class MountKind { public int Index; public MountShape Shape; public string Trophy; public ConfigEntry<bool> Enabled; public ConfigEntry<float> WalkSpeed; public ConfigEntry<float> RunSpeed; public ConfigEntry<float> Stamina; public ConfigEntry<Vector3> SaddleOffset; public ConfigEntry<Vector3> RiderOffset; public ConfigEntry<string> RiderPose; } internal static class Mounts { public const string SaddleObjectName = "q8rt_saddle"; private const string ModelName = "model"; private const string AttachName = "attach"; private const float RunStaminaDrain = 2.5f; private const float SwimStaminaDrain = 5f; private const float StaminaRegen = 1.5f; private const float StaminaRegenHungry = 0.5f; private static readonly string[] Poses = new string[3] { "attach_asksvin", "attach_moose", "attach_lox" }; public static readonly List<MountKind> Kinds = new List<MountKind>(); public static bool AnyEnabled { get { foreach (MountKind kind in Kinds) { if (kind.Enabled.Value) { return true; } } return false; } } public static void Bind(RideableTamesPlugin plugin) { Add(plugin, MountShapes.Boar, "TrophyBoar", 4f, 8.5f, 100f, "Tamed boars can wear the saddle and be ridden."); Add(plugin, MountShapes.Wolf, "TrophyWolf", 4.5f, 8f, 150f, "Tamed wolves can wear the saddle and be ridden."); Add(plugin, MountShapes.Deer, "TrophyDeer", 5f, 10f, 150f, "Tamed deer can wear the saddle and be ridden. In the base game deer cannot be tamed: that takes a taming mod such as LetMeTameYou."); MigrateWolfRunSpeed104(plugin); } private static void Add(RideableTamesPlugin plugin, MountShape shape, string trophy, float walk, float run, float stamina, string enabledText) { //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) string prefab = shape.Prefab; MountKind kind = new MountKind { Index = Kinds.Count, Shape = shape, Trophy = trophy }; kind.Enabled = plugin.Rule(prefab, "Enabled", value: true, enabledText + " If false, the saddle cannot be put on and a saddled animal cannot be mounted; the saddle can still be taken off."); kind.WalkSpeed = plugin.Rule(prefab, "WalkSpeed", walk, "Speed with a rider at a walk (W), metres per second. On its own the animal ambles at 1.5; a player jogs at 4.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 15f)); kind.RunSpeed = plugin.Rule(prefab, "RunSpeed", run, "Speed with a rider at a gallop (Shift), metres per second, before the riding skill bonus of up to +25%. A player runs at 7.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 25f)); kind.Stamina = plugin.Rule(prefab, "Stamina", stamina, "The animal's own stamina with a saddle on. A gallop costs 2.5 a second and swimming 5 (half that at riding skill 100); it comes back at 1.5 to 3 a second, a third of that when the animal is hungry.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 1000f)); kind.SaddleOffset = plugin.Look<Vector3>(prefab, "SaddleOffset", Vector3.zero, "Moves the saddle together with the rider, metres: X to the animal's right, Y up, Z forward. For fitting by eye; applied on the fly when this file is saved."); kind.RiderOffset = plugin.Look<Vector3>(prefab, "RiderOffset", Vector3.zero, "Moves only the rider, metres: X to the right, Y up, Z forward. Applied on the fly."); kind.RiderPose = plugin.Look(prefab, "RiderPose", Poses[0], "How the rider sits: one of the game's own riding poses, taken from the asksvin, the moose or the lox. Applies the next time someone mounts.", (AcceptableValueBase)(object)new AcceptableValueList<string>(Poses)); kind.Enabled.SettingChanged += delegate { SaddleItem.ApplyRecipe(); }; kind.SaddleOffset.SettingChanged += delegate { ApplyLook(kind); }; kind.RiderOffset.SettingChanged += delegate { ApplyLook(kind); }; kind.RiderPose.SettingChanged += delegate { ApplyLook(kind); }; Kinds.Add(kind); } public static MountKind KindOf(Sadle sadle) { if ((Object)(object)sadle == (Object)null) { return null; } MountMarker component = ((Component)sadle).GetComponent<MountMarker>(); if (!((Object)(object)component != (Object)null) || component.Kind < 0 || component.Kind >= Kinds.Count) { return null; } return Kinds[component.Kind]; } public static MountKind KindOf(Character character) { Tameable component = ((Component)character).GetComponent<Tameable>(); if (!((Object)(object)component != (Object)null)) { return null; } return KindOf(component.m_saddle); } private static MountKind KindOfPrefab(GameObject go) { string text = PrefabName(go); foreach (MountKind kind in Kinds) { if (kind.Shape.Prefab == text) { return kind; } } return null; } private static string PrefabName(GameObject go) { string name = ((Object)go).name; int num = name.IndexOf('('); return ((num >= 0) ? name.Substring(0, num) : name).Trim(); } private static Sadle FindSaddle(GameObject go) { Sadle[] componentsInChildren = go.GetComponentsInChildren<Sadle>(true); foreach (Sadle val in componentsInChildren) { if (((Object)((Component)val).gameObject).name == "q8rt_saddle") { return val; } } return null; } public static void SetupPrefabs(ZNetScene scene) { GameObject prefab = scene.GetPrefab("Lox"); Tameable val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Tameable>() : null); Sadle lox = (((Object)(object)val != (Object)null) ? val.m_saddle : null); List<string> list = new List<string>(); foreach (MountKind kind in Kinds) { GameObject prefab2 = scene.GetPrefab(kind.Shape.Prefab); if ((Object)(object)prefab2 == (Object)null) { RideableTamesPlugin.Log.LogWarning((object)("Prefab " + kind.Shape.Prefab + " not found, it cannot be ridden.")); continue; } if ((Object)(object)FindSaddle(prefab2) == (Object)null) { try { AddSaddle(prefab2, kind, lox); } catch (Exception ex) { RideableTamesPlugin.Log.LogError((object)("Could not put a saddle mount on " + kind.Shape.Prefab + ": " + ex)); continue; } } list.Add(kind.Shape.Prefab + (kind.Enabled.Value ? "" : " (off)")); } RideableTamesPlugin.Log.LogInfo((object)("Saddle mounts ready: " + string.Join(", ", list.ToArray()) + (SaddleLook.Headless ? " (no graphics)" : "") + (((Object)(object)SaddleItem.Drop == (Object)null) ? "; the saddle item is missing!" : ""))); } private static void AddSaddle(GameObject prefab, MountKind kind, Sadle lox) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_009f: 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_00bf: 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_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Expected O, but got Unknown //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) MountShape shape = kind.Shape; Transform val = FindDeep(prefab.transform, shape.Bone); if ((Object)(object)val == (Object)null) { RideableTamesPlugin.Log.LogWarning((object)(shape.Prefab + " has no bone " + shape.Bone + ", the saddle is fixed to the body.")); val = prefab.transform; } GameObject val2 = new GameObject("q8rt_saddle"); val2.SetActive(false); val2.layer = (((Object)(object)lox != (Object)null) ? ((Component)lox).gameObject.layer : LayerMask.NameToLayer("piece_nonsolid")); val2.transform.SetParent(prefab.transform, false); val2.transform.localPosition = shape.SaddleCenter; val2.transform.localRotation = Quaternion.identity; val2.transform.localScale = Vector3.one; val2.transform.SetParent(val, true); val2.AddComponent<MountMarker>().Kind = kind.Index; Sadle val3 = val2.AddComponent<Sadle>(); if ((Object)(object)lox != (Object)null) { val3.m_drownEffects = lox.m_drownEffects; } val3.m_hoverText = "$item_q8rt_saddle"; val3.m_maxUseRange = 6f; val3.m_maxStamina = kind.Stamina.Value; val3.m_runStaminaDrain = 2.5f; val3.m_swimStaminaDrain = 5f; val3.m_staminaRegen = 1.5f; val3.m_staminaRegenHungry = 0.5f; val3.m_detachOffset = new Vector3(shape.CapsuleRadius + 0.5f, 0.2f, 0f); val3.m_hoverOffset = 0f; SphereCollider obj = val2.AddComponent<SphereCollider>(); ((Collider)obj).isTrigger = true; obj.center = new Vector3(0f, 0.12f, 0f); obj.radius = shape.HoverRadius; GameObject val4 = new GameObject("attach"); val4.transform.SetParent(val2.transform, false); val3.m_attachPoint = val4.transform; if (!SaddleLook.Headless) { GameObject val5 = new GameObject("model"); SkinnedMeshRenderer componentInChildren = prefab.GetComponentInChildren<SkinnedMeshRenderer>(true); val5.layer = (((Object)(object)componentInChildren != (Object)null) ? ((Component)componentInChildren).gameObject.layer : prefab.layer); val5.transform.SetParent(val2.transform, false); val5.AddComponent<MeshFilter>().sharedMesh = SaddleLook.MountMesh(shape); MeshRenderer val6 = val5.AddComponent<MeshRenderer>(); ((Renderer)val6).sharedMaterial = SaddleLook.Material; AddToLods(prefab, (Renderer)(object)val6); } ApplyLookTo(val2.transform, kind); } private static void AddToLods(GameObject prefab, Renderer renderer) { LODGroup componentInChildren = prefab.GetComponentInChildren<LODGroup>(true); if (!((Object)(object)componentInChildren == (Object)null)) { LOD[] lODs = componentInChildren.GetLODs(); for (int i = 0; i < lODs.Length; i++) { Renderer[] array = (Renderer[])(((object)lODs[i].renderers) ?? ((object)new Renderer[0])); Renderer[] array2 = (Renderer[])(object)new Renderer[array.Length + 1]; array.CopyTo(array2, 0); array2[array.Length] = renderer; lODs[i].renderers = array2; } componentInChildren.SetLODs(lODs); } } public static void WireInstance(Tameable tameable) { if ((Object)(object)tameable.m_saddle != (Object)null || (Object)(object)SaddleItem.Drop == (Object)null) { return; } MountKind mountKind = KindOfPrefab(((Component)tameable).gameObject); if (mountKind == null) { return; } Sadle val = FindSaddle(((Component)tameable).gameObject); if (!((Object)(object)val == (Object)null)) { tameable.m_saddle = val; tameable.m_saddleItem = SaddleItem.Drop; tameable.m_dropSaddleOnDeath = true; if ((Object)(object)val.m_mountIcon == (Object)null) { val.m_mountIcon = TrophyIcon(mountKind); } } } private static Sprite TrophyIcon(MountKind kind) { GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(kind.Trophy) : null); ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null); if (!((Object)(object)val2 != (Object)null)) { return null; } return val2.m_itemData.GetIcon(); } public static string Pose(MountKind kind) { if (Array.IndexOf(Poses, kind.RiderPose.Value) < 0) { return Poses[0]; } return kind.RiderPose.Value; } private static void ApplyLook(MountKind kind) { if ((Object)(object)ZNetScene.instance != (Object)null) { GameObject prefab = ZNetScene.instance.GetPrefab(kind.Shape.Prefab); Sadle val = (((Object)(object)prefab != (Object)null) ? FindSaddle(prefab) : null); if ((Object)(object)val != (Object)null) { ApplyLookTo(((Component)val).transform, kind); } } foreach (Character allCharacter in Character.GetAllCharacters()) { Tameable val2 = (((Object)(object)allCharacter != (Object)null) ? ((Component)allCharacter).GetComponent<Tameable>() : null); if ((Object)(object)val2 != (Object)null && KindOf(val2.m_saddle) == kind) { ApplyLookTo(((Component)val2.m_saddle).transform, kind); } } } private static void ApplyLookTo(Transform saddle, MountKind kind) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_0074: 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) Vector3 value = kind.SaddleOffset.Value; Transform val = saddle.Find("model"); if ((Object)(object)val != (Object)null) { val.localPosition = value; } Transform val2 = saddle.Find("attach"); if ((Object)(object)val2 != (Object)null) { val2.localPosition = new Vector3(0f, SaddleShape.SeatHeight(kind.Shape.Fit) - 0.01f, 0f) + value + kind.RiderOffset.Value; val2.localRotation = Quaternion.identity; } Sadle component = ((Component)saddle).GetComponent<Sadle>(); if ((Object)(object)component != (Object)null) { component.m_attachAnimation = Pose(kind); } } private static Transform FindDeep(Transform root, string name) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown if (((Object)root).name == name) { return root; } foreach (Transform item in root) { Transform val = FindDeep(item, name); if ((Object)(object)val != (Object)null) { return val; } } return null; } private static void MigrateWolfRunSpeed104(RideableTamesPlugin plugin) { ConfigEntry<int> val = plugin.Look("Rider Updates", "WolfRunSpeedRevision104", 0, "One-time migration of Rider wolf base run speed to 8 m/s."); if (val.Value < 105) { Kinds[1].RunSpeed.Value = 8f; val.Value = 105; ((BaseUnityPlugin)plugin).Config.Save(); } } } internal sealed class MountShape { public string Prefab; public string Bone; public Vector3 SaddleCenter; public float CapsuleRadius; public float HoverRadius; public SaddleFit Fit; } internal static class MountShapes { public static readonly MountShape Boar = new MountShape { Prefab = "Boar", Bone = "Spine1", SaddleCenter = new Vector3(0f, 0.953f, 0f), CapsuleRadius = 0.5f, HoverRadius = 0.55f, Fit = new SaddleFit { BackA = 0.28f, BackB = 0.575f, Lift = 0.01f, BackLine = new float[13] { 0.025f, 0.02f, 0.014f, 0.008f, 0.003f, 0f, 0f, 0.006f, 0.011f, 0.017f, 0.021f, 0.025f, 0.029f }, BlanketHalfLength = 0.24f, BlanketDrape = 0.2f, SeatHalfLength = 0.17f, SeatDrape = 0.1f, GirthZ = 0.1f, GirthA = 0.246f, GirthB = 0.346f, GirthCenterY = -0.313f } }; public static readonly MountShape Wolf = new MountShape { Prefab = "Wolf", Bone = "Spine1", SaddleCenter = new Vector3(0f, 1.129f, -0.1f), CapsuleRadius = 0.65f, HoverRadius = 0.62f, Fit = new SaddleFit { BackA = 0.245f, BackB = 0.25f, Lift = 0.02f, BackLine = new float[13] { -0.023f, -0.019f, -0.016f, -0.012f, -0.009f, -0.005f, 0f, 0.005f, 0.009f, 0.015f, 0.028f, 0.042f, 0.058f }, BlanketHalfLength = 0.24f, BlanketDrape = 0.2f, SeatHalfLength = 0.17f, SeatDrape = 0.1f, GirthZ = 0.04f, GirthA = 0.23f, GirthB = 0.273f, GirthCenterY = -0.252f } }; public static readonly MountShape Deer = new MountShape { Prefab = "Deer", Bone = "Spine1", SaddleCenter = new Vector3(0f, 1.338f, -0.08f), CapsuleRadius = 0.8f, HoverRadius = 0.72f, Fit = new SaddleFit { BackA = 0.29f, BackB = 0.585f, Lift = 0.01f, BackLine = new float[13] { 0.024f, 0.02f, 0.016f, 0.011f, 0.007f, 0.003f, 0f, -0.002f, -0.005f, 0f, 0.011f, 0.022f, 0.033f }, BlanketHalfLength = 0.26f, BlanketDrape = 0.22f, SeatHalfLength = 0.18f, SeatDrape = 0.11f, GirthZ = 0.1f, GirthA = 0.274f, GirthB = 0.338f, GirthCenterY = -0.323f } }; public static readonly MountShape[] All = new MountShape[3] { Boar, Wolf, Deer }; } [HarmonyPatch(typeof(ZNetScene), "Awake")] internal static class ZNetSceneAwakePatch { private static void Postfix(ZNetScene __instance) { Mounts.SetupPrefabs(__instance); } } [HarmonyPatch(typeof(Tameable), "Awake")] internal static class TameableAwakePatch { private static void Prefix(Tameable __instance) { Mounts.WireInstance(__instance); } } [HarmonyPatch(typeof(Tameable), "UseItem")] internal static class TameableUseItemPatch { private static bool Prefix(Tameable __instance, Humanoid user, ItemData item, ref bool __result) { if (!SaddleItem.IsSaddle(item)) { return true; } MountKind mountKind = Mounts.KindOf(__instance.m_saddle); if (mountKind == null || mountKind.Enabled.Value) { return true; } ((Character)user).Message((MessageType)2, "$q8rt_msg_off", 0, (Sprite)null, false); __result = true; return false; } } [HarmonyPatch(typeof(Sadle), "Interact")] internal static class SadleInteractPatch { private static bool Prefix(Sadle __instance, Humanoid character, bool repeat, bool alt, ref bool __result) { if (repeat || alt) { return true; } MountKind mountKind = Mounts.KindOf(__instance); if (mountKind == null || mountKind.Enabled.Value) { return true; } ((Character)character).Message((MessageType)2, "$q8rt_msg_off", 0, (Sprite)null, false); __result = false; return false; } } [HarmonyPatch(typeof(Sadle), "GetMaxStamina")] internal static class SadleMaxStaminaPatch { private static void Postfix(Sadle __instance, ref float __result) { MountKind mountKind = Mounts.KindOf(__instance); if (mountKind != null) { __result = Mathf.Max(1f, mountKind.Stamina.Value); } } } [HarmonyPatch(typeof(Character), "GetJogSpeedFactor")] internal static class CharacterJogSpeedPatch { private static void Postfix(Character __instance, ref float __result) { if (__instance.HaveRider()) { MountKind mountKind = Mounts.KindOf(__instance); if (mountKind != null && __instance.m_speed > 0.01f) { __result *= mountKind.WalkSpeed.Value / __instance.m_speed; } } } } [HarmonyPatch(typeof(Character), "GetRunSpeedFactor")] internal static class CharacterRunSpeedPatch { private static void Postfix(Character __instance, ref float __result) { if (__instance.HaveRider()) { MountKind mountKind = Mounts.KindOf(__instance); if (mountKind != null && __instance.m_runSpeed > 0.01f) { __result *= mountKind.RunSpeed.Value / __instance.m_runSpeed; } } } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static class LegacyItemPatch { private static void Postfix(int hash, ref GameObject prefab, ref bool __result) { if (!__result && hash == SaddleItem.LegacyHash && (Object)(object)SaddleItem.Prefab != (Object)null) { prefab = SaddleItem.Prefab; __result = true; } } } [HarmonyPatch(typeof(ZNetScene), "GetPrefab", new Type[] { typeof(int) })] internal static class LegacyPrefabPatch { private static void Postfix(int hash, ref GameObject __result) { if ((Object)(object)__result == (Object)null && hash == SaddleItem.LegacyHash && (Object)(object)SaddleItem.Prefab != (Object)null) { __result = SaddleItem.Prefab; } } } [BepInPlugin("qua8ion.valheim.rideabletames", "RideableTames", "1.2.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInIncompatibility("xneliox.rideableboars")] [BepInIncompatibility("valheim.boarriding")] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] [BepInIncompatibility("anwo.PackBeasts")] public class RideableTamesPlugin : BaseUnityPlugin { public const string PluginGuid = "qua8ion.valheim.rideabletames"; public const string PluginName = "RideableTames"; public const string PluginVersion = "1.2.0"; internal static ManualLogSource Log; internal static ConfigEntry<string> Recipe; internal static ConfigEntry<string> Station; internal static ConfigEntry<int> StationLevel; private FileSystemWatcher configWatcher; private volatile bool configChanged; private void Awake() { //IL_013d: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; Recipe = Rule("Saddle", "Recipe", "LeatherScraps:5,DeerHide:2,BronzeNails:4", "What the saddle is made of: Item:amount pairs separated by commas (prefab names). One saddle fits a boar, a wolf and a deer alike."); Station = Rule("Saddle", "Station", "Workbench", "Where the saddle is made: Workbench, Forge, Stonecutter, ArtisanTable, BlackForge, GaldrTable, or a station prefab name."); StationLevel = Rule("Saddle", "StationLevel", 2, "Station level needed to make the saddle.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10)); Mounts.Bind(this); AddLocalization(); Recipe.SettingChanged += delegate { SaddleItem.ApplyRecipe(); }; Station.SettingChanged += delegate { SaddleItem.ApplyRecipe(); }; StationLevel.SettingChanged += delegate { SaddleItem.ApplyRecipe(); }; SynchronizationManager.OnConfigurationSynchronized += delegate { SaddleItem.ApplyRecipe(); }; PrefabManager.OnVanillaPrefabsAvailable += SaddleItem.Register; new Harmony("qua8ion.valheim.rideabletames").PatchAll(Assembly.GetExecutingAssembly()); WatchConfigFile(); Runtime.Initialize((BaseUnityPlugin)(object)this); } internal ConfigEntry<T> Rule<T>(string section, string key, T value, string description, AcceptableValueBase range = null) { //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_0022: Expected O, but got Unknown //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown return ((BaseUnityPlugin)this).Config.Bind<T>(section, key, value, new ConfigDescription(description, range, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); } internal ConfigEntry<T> Look<T>(string section, string key, T value, string description, AcceptableValueBase range = null) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown return ((BaseUnityPlugin)this).Config.Bind<T>(section, key, value, new ConfigDescription(description, range, Array.Empty<object>())); } private void WatchConfigFile() { try { configWatcher = new FileSystemWatcher(Path.GetDirectoryName(((BaseUnityPlugin)this).Config.ConfigFilePath), Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath)); configWatcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.CreationTime; configWatcher.Changed += delegate { configChanged = true; }; configWatcher.Created += delegate { configChanged = true; }; configWatcher.EnableRaisingEvents = true; } catch (Exception ex) { Log.LogWarning((object)("Config file will not be reloaded on the fly: " + ex.Message)); } } private void Update() { if (!configChanged) { return; } configChanged = false; try { ((BaseUnityPlugin)this).Config.Reload(); } catch (Exception ex) { Log.LogWarning((object)("Could not reload the config file: " + ex.Message)); } } private void OnDestroy() { if (configWatcher != null) { configWatcher.Dispose(); } Runtime.Shutdown(); } private static void AddLocalization() { CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); string text = "English"; localization.AddTranslation(ref text, new Dictionary<string, string> { { "item_q8rt_saddle", "Saddle" }, { "item_q8rt_saddle_desc", "A light leather saddle on a woollen blanket. Fits a tamed boar, wolf or deer: look at the animal and use the saddle from your hotbar." }, { "q8rt_msg_off", "Riding this animal is turned off" } }); text = "Russian"; localization.AddTranslation(ref text, new Dictionary<string, string> { { "item_q8rt_saddle", "Седло" }, { "item_q8rt_saddle_desc", "Лёгкое кожаное седло на шерстяной попоне. Подходит ручному кабану, волку и оленю: посмотрите на зверя и используйте седло с панели быстрого доступа." }, { "q8rt_msg_off", "Ездить на этом звере нельзя" } }); } } internal static class SaddleItem { public const string PrefabName = "Q8_TameSaddle"; public const string NameToken = "$item_q8rt_saddle"; public const string DescriptionToken = "$item_q8rt_saddle_desc"; private const string BasePrefabName = "SaddleLox"; public static readonly int LegacyHash = StringExtensionMethods.GetStableHashCode("BoarSaddle"); public static GameObject Prefab; public static ItemDrop Drop; public static bool IsSaddle(ItemData item) { if (item != null && item.m_shared != null) { return item.m_shared.m_name == "$item_q8rt_saddle"; } return false; } public static void Register() { //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Expected O, but got Unknown //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Expected O, but got Unknown PrefabManager.OnVanillaPrefabsAvailable -= Register; GameObject val = PrefabManager.Instance.CreateClonedPrefab("Q8_TameSaddle", "SaddleLox"); ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null); if ((Object)(object)val2 == (Object)null) { RideableTamesPlugin.Log.LogError((object)"Base prefab SaddleLox not found, the saddle is not added."); return; } bool headless = SaddleLook.Headless; if (!headless) { try { BuildVisuals(val); } catch (Exception ex) { RideableTamesPlugin.Log.LogWarning((object)("Could not build the saddle model: " + ex.Message)); } } val2.m_autoDestroy = false; SharedData shared = val2.m_itemData.m_shared; shared.m_name = "$item_q8rt_saddle"; shared.m_description = "$item_q8rt_saddle_desc"; shared.m_weight = 8f; shared.m_teleportable = true; shared.m_value = 0; val2.m_itemData.m_dropPrefab = val; ItemConfig val3 = new ItemConfig { Name = "$item_q8rt_saddle", Description = "$item_q8rt_saddle_desc" }; if (!headless) { val3.CraftingStation = RideableTamesPlugin.Station.Value; val3.MinStationLevel = RideableTamesPlugin.StationLevel.Value; val3.Amount = 1; val3.Enabled = Mounts.AnyEnabled; val3.Icons = (Sprite[])(object)new Sprite[1] { SaddleLook.Icon }; val3.Requirements = ParseRecipe(RideableTamesPlugin.Recipe.Value).ToArray(); } if (!ItemManager.Instance.AddItem(new CustomItem(val, false, val3))) { RideableTamesPlugin.Log.LogError((object)"Jotunn rejected the saddle item."); return; } Prefab = val; Drop = val2; } private static void BuildVisuals(GameObject prefab) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00da: 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_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) for (int num = prefab.transform.childCount - 1; num >= 0; num--) { Object.DestroyImmediate((Object)(object)((Component)prefab.transform.GetChild(num)).gameObject); } LODGroup component = prefab.GetComponent<LODGroup>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } Mesh itemMesh = SaddleLook.ItemMesh; Bounds bounds = itemMesh.bounds; GameObject val = new GameObject("model"); val.layer = prefab.layer; val.transform.SetParent(prefab.transform, false); val.transform.localPosition = new Vector3(0f, 0f - ((Bounds)(ref bounds)).min.y, 0f); val.AddComponent<MeshFilter>().sharedMesh = itemMesh; ((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = SaddleLook.Material; if ((Object)(object)prefab.GetComponentInChildren<Collider>(true) == (Object)null) { BoxCollider obj = prefab.AddComponent<BoxCollider>(); obj.center = ((Bounds)(ref bounds)).center + val.transform.localPosition; obj.size = ((Bounds)(ref bounds)).size; } } internal static List<RequirementConfig> ParseRecipe(string text) { //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Expected O, but got Unknown //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown List<RequirementConfig> list = new List<RequirementConfig>(); string[] array = (text ?? "").Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text2 in array) { string[] array2 = text2.Split(new char[1] { ':' }); if (array2.Length != 2 || array2[0].Trim().Length == 0 || !int.TryParse(array2[1].Trim(), out var result) || result < 1) { RideableTamesPlugin.Log.LogWarning((object)("Recipe entry '" + text2 + "' is ignored, expected Item:amount.")); } else { list.Add(new RequirementConfig(array2[0].Trim(), result, 0, true)); } } if (list.Count == 0) { list.Add(new RequirementConfig("LeatherScraps", 5, 0, true)); } return list; } internal static void ApplyRecipe() { //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_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Expected O, but got Unknown if ((Object)(object)ObjectDB.instance == (Object)null) { return; } Recipe val = ObjectDB.instance.m_recipes.Find((Recipe r) => (Object)(object)r != (Object)null && (Object)(object)r.m_item != (Object)null && ((Object)((Component)r.m_item).gameObject).name == "Q8_TameSaddle"); if ((Object)(object)val == (Object)null) { return; } val.m_enabled = Mounts.AnyEnabled; val.m_minStationLevel = Mathf.Max(1, RideableTamesPlugin.StationLevel.Value); string internalName = CraftingStations.GetInternalName(RideableTamesPlugin.Station.Value); if (string.IsNullOrEmpty(internalName)) { val.m_craftingStation = null; } else if ((Object)(object)ZNetScene.instance != (Object)null) { GameObject prefab = ZNetScene.instance.GetPrefab(internalName); CraftingStation val2 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<CraftingStation>() : null); if ((Object)(object)val2 != (Object)null) { val.m_craftingStation = val2; } else { RideableTamesPlugin.Log.LogWarning((object)("Crafting station '" + RideableTamesPlugin.Station.Value + "' does not exist, the station is left as it was.")); } } List<Requirement> list = new List<Requirement>(); foreach (RequirementConfig item in ParseRecipe(RideableTamesPlugin.Recipe.Value)) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(item.Item); ItemDrop val3 = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val3 == (Object)null) { RideableTamesPlugin.Log.LogWarning((object)("Recipe item '" + item.Item + "' does not exist and is ignored.")); continue; } list.Add(new Requirement { m_resItem = val3, m_amount = item.Amount, m_amountPerLevel = 0, m_recover = true }); } if (list.Count > 0) { val.m_resources = list.ToArray(); } } } internal static class SaddleLook { private static Material material; private static Sprite icon; private static Mesh itemMesh; private static readonly Dictionary<MountShape, Mesh> mountMeshes = new Dictionary<MountShape, Mesh>(); public static bool Headless => (int)SystemInfo.graphicsDeviceType == 4; public static Material Material { get { if ((Object)(object)material == (Object)null) { material = CreateMaterial(); } return material; } } public static Sprite Icon { get { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)icon == (Object)null) { Texture2D val = LoadTexture("icon.png"); icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f); ((Object)icon).name = "q8rt_saddle_icon"; } return icon; } } public static Mesh ItemMesh { get { if ((Object)(object)itemMesh == (Object)null) { itemMesh = ToMesh(SaddleShape.Build(MountShapes.Boar.Fit, withGirth: false), "q8rt_saddle_item"); } return itemMesh; } } public static Mesh MountMesh(MountShape shape) { if (!mountMeshes.TryGetValue(shape, out var value) || (Object)(object)value == (Object)null) { value = ToMesh(SaddleShape.Build(shape.Fit, withGirth: true), "q8rt_saddle_" + shape.Prefab); mountMeshes[shape] = value; } return value; } private static Mesh ToMesh(MeshData data, string name) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown Mesh val = new Mesh { name = name }; val.SetVertices(data.Vertices); val.SetNormals(data.Normals); val.SetUVs(0, data.Uv); val.SetTriangles(data.Triangles, 0); val.RecalculateBounds(); ((Object)val).hideFlags = (HideFlags)32; return val; } private static Material CreateMaterial() { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown GameObject prefab = PrefabManager.Instance.GetPrefab("SaddleLox"); MeshRenderer val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponentInChildren<MeshRenderer>(true) : null); Material val2; if ((Object)(object)val != (Object)null && (Object)(object)((Renderer)val).sharedMaterial != (Object)null) { val2 = new Material(((Renderer)val).sharedMaterial); } else { RideableTamesPlugin.Log.LogWarning((object)"The lox saddle material was not found, the saddle uses a plain one."); val2 = new Material(Shader.Find("Standard")); } ((Object)val2).name = "q8rt_saddle"; val2.mainTexture = (Texture)(object)LoadTexture("saddle.png"); val2.color = Color.white; string[] array = new string[3] { "_BumpMap", "_MetallicGlossMap", "_EmissionMap" }; foreach (string text in array) { if (val2.HasProperty(text)) { val2.SetTexture(text, (Texture)null); } } array = new string[3] { "_NORMALMAP", "_METALLICGLOSSMAP", "_EMISSION" }; foreach (string text2 in array) { val2.DisableKeyword(text2); } if (val2.HasProperty("_Metallic")) { val2.SetFloat("_Metallic", 0f); } if (val2.HasProperty("_Glossiness")) { val2.SetFloat("_Glossiness", 0.15f); } ((Object)val2).hideFlags = (HideFlags)32; return val2; } private static Texture2D LoadTexture(string resourceName) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Expected O, but got Unknown //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Expected O, but got Unknown //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012c: 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_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0137: 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_0140: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true); try { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); if (stream == null) { throw new FileNotFoundException("embedded resource is missing"); } byte[] array = new byte[stream.Length]; int num; for (int i = 0; i < array.Length; i += num) { num = stream.Read(array, i, array.Length - i); if (num <= 0) { break; } } Type type = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule"); MethodInfo methodInfo = ((type != null) ? type.GetMethod("LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) }) : null); if (methodInfo == null || !(bool)methodInfo.Invoke(null, new object[2] { val, array })) { throw new InvalidDataException("the image could not be decoded"); } } catch (Exception ex) { RideableTamesPlugin.Log.LogWarning((object)("Could not load " + resourceName + ": " + ex.Message)); val = new Texture2D(2, 2, (TextureFormat)4, false); Color32 val2 = default(Color32); ((Color32)(ref val2))..ctor((byte)110, (byte)70, (byte)38, byte.MaxValue); val.SetPixels32((Color32[])(object)new Color32[4] { val2, val2, val2, val2 }); val.Apply(); } ((Object)val).name = "q8rt_" + Path.GetFileNameWithoutExtension(resourceName); ((Texture)val).wrapMode = (TextureWrapMode)1; ((Texture)val).filterMode = (FilterMode)2; ((Texture)val).anisoLevel = 4; ((Object)val).hideFlags = (HideFlags)32; return val; } } internal sealed class SaddleFit { public float BackA; public float BackB; public float Lift; public float[] BackLine; public float BlanketHalfLength; public float BlanketDrape; public float SeatHalfLength; public float SeatDrape; public float GirthZ; public float GirthA; public float GirthB; public float GirthCenterY; public float BackLineAt(float z) { float num = (z + 0.3f) / 0.05f; int num2 = BackLine.Length - 1; if (num <= 0f) { return BackLine[0]; } if (num >= (float)num2) { return BackLine[num2]; } int num3 = (int)num; return Mathf.Lerp(BackLine[num3], BackLine[num3 + 1], num - (float)num3); } } internal sealed class MeshData { public readonly List<Vector3> Vertices = new List<Vector3>(); public readonly List<Vector3> Normals = new List<Vector3>(); public readonly List<Vector2> Uv = new List<Vector2>(); public readonly List<int> Triangles = new List<int>(); public void AddGrid(int nu, int nv, Func<int, int, Vector3> position, Func<int, int, Vector2> uv, Vector3 outward) { //IL_007e: 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_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) int count = Vertices.Count; for (int i = 0; i <= nv; i++) { for (int j = 0; j <= nu; j++) { Vertices.Add(position(j, i)); Uv.Add(uv(j, i)); Normals.Add(Vector3.zero); } } int num = nu / 2; int num2 = nv / 2; Vector3 val = Vertices[count + num2 * (nu + 1) + num]; Vector3 val2 = Vertices[count + (num2 + 1) * (nu + 1) + num]; Vector3 val3 = Vertices[count + num2 * (nu + 1) + num + 1]; bool flip = Vector3.Dot(Vector3.Cross(val2 - val, val3 - val), outward) < 0f; for (int k = 0; k < nv; k++) { for (int l = 0; l < nu; l++) { int num3 = count + k * (nu + 1) + l; int num4 = num3 + 1; int num5 = num3 + nu + 1; int c = num5 + 1; AddTriangle(num3, num5, num4, flip); AddTriangle(num4, num5, c, flip); } } for (int m = count; m < Vertices.Count; m++) { List<Vector3> normals = Normals; int index = m; Vector3 val4 = Normals[m]; normals[index] = ((Vector3)(ref val4)).normalized; } } private void AddTriangle(int a, int b, int c, bool flip) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0081: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) if (flip) { int num = b; b = c; c = num; } Triangles.Add(a); Triangles.Add(b); Triangles.Add(c); Vector3 val = Vector3.Cross(Vertices[b] - Vertices[a], Vertices[c] - Vertices[a]); List<Vector3> normals = Normals; int index = a; normals[index] += val; normals = Normals; index = b; normals[index] += val; normals = Normals; index = c; normals[index] += val; } } internal static class SaddleShape { private const float Gap = 0.008f; private const float BlanketThickness = 0.012f; private const float SeatGap = 0.002f; private const float SeatThickness = 0.028f; private const float CantleRise = 0.075f; private const float PommelRise = 0.05f; private const float GirthWidth = 0.045f; private const float GirthThickness = 0.008f; private const float GirthGap = 0.006f; private static readonly Rect Cloth = new Rect(0.5f, 0.5f, 0.5f, 0.5f); private static readonly Rect Leather = new Rect(0f, 0.5f, 0.5f, 0.5f); private static readonly Rect Strap = new Rect(0f, 0.375f, 1f, 0.125f); private static readonly Rect Dark = new Rect(0f, 0.25f, 1f, 0.125f); public static float SeatHeight(SaddleFit fit) { return fit.Lift + 0.008f + 0.012f + 0.002f + 0.028f; } public static MeshData Build(SaddleFit fit, bool withGirth) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: 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_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) MeshData meshData = new MeshData(); float num = PhiForDepth(fit, fit.BlanketDrape); float maxPhi = PhiForDepth(fit, fit.SeatDrape); Shell(meshData, fit, 14, 10, num, fit.BlanketHalfLength, (float u, float w) => 0.008f, (float u, float w) => 0.02f, Cloth, Cloth, Cloth); float seatBase = 0.022f; Shell(meshData, fit, 10, 12, maxPhi, fit.SeatHalfLength, (float u, float w) => seatBase, (float u, float w) => seatBase + 0.028f + SeatBump(u, w), Leather, Dark, Leather); if (withGirth) { Girth(meshData, fit, num); } return meshData; } private static Vector3 Surface(SaddleFit fit, float phi, float z, float h) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Sin(phi); float num2 = Mathf.Cos(phi); Vector3 val = new Vector3(fit.BackB * num, fit.BackA * num2, 0f); Vector3 normalized = ((Vector3)(ref val)).normalized; float num3 = fit.Lift - fit.BackB + fit.BackB * num2 + fit.BackLineAt(z); return new Vector3(fit.BackA * num, num3, z) + normalized * h; } private static float PhiForDepth(SaddleFit fit, float depth) { return Mathf.Acos(Mathf.Clamp((fit.BackB - fit.Lift - depth) / fit.BackB, -1f, 1f)); } private static float SeatBump(float u, float w) { float num = Mathf.Clamp01((0f - u - 0.35f) / 0.65f); float num2 = Mathf.Clamp01((u - 0.5f) / 0.5f); float num3 = Mathf.Cos(w * (float)Math.PI * 0.5f); num3 *= num3; return (0.075f * num * num + 0.05f * num2 * num2) * num3; } private static void Shell(MeshData mesh, SaddleFit fit, int nPhi, int nZ, float maxPhi, float halfLength, Func<float, float, float> inner, Func<float, float, float> outer, Rect top, Rect bottom, Rect edge) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_017f: 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) Func<int, float> w = (int i) => (float)i / (float)nPhi * 2f - 1f; Func<int, float> u = (int j) => (float)j / (float)nZ * 2f - 1f; Func<float, float, float, Vector3> at = (float num4, float num3, float h) => Surface(fit, num3 * maxPhi, num4 * halfLength, h); mesh.AddGrid(nPhi, nZ, (int i, int j) => at(u(j), w(i), outer(u(j), w(i))), (int i, int j) => Map(top, (float)i / (float)nPhi, (float)j / (float)nZ), Vector3.up); mesh.AddGrid(nPhi, nZ, (int i, int j) => at(u(j), w(i), inner(u(j), w(i))), (int i, int j) => Map(bottom, (float)i / (float)nPhi, (float)j / (float)nZ), Vector3.down); int[] array = new int[2] { -1, 1 }; Vector3 outward = default(Vector3); foreach (int side in array) { float uu = side; mesh.AddGrid(nPhi, 1, (int i, int k) => at(uu, w(i), (k == 0) ? inner(uu, w(i)) : outer(uu, w(i))), (int i, int k) => Map(edge, (float)i / (float)nPhi, (side > 0) ? (0.99f - (float)k * 0.02f) : (0.01f + (float)k * 0.02f)), new Vector3(0f, 0f, (float)side)); float ww = side; float num2 = ww * maxPhi; ((Vector3)(ref outward))..ctor((float)side * fit.BackA * Mathf.Cos(num2), (0f - fit.BackB) * Mathf.Sin(Mathf.Abs(num2)), 0f); mesh.AddGrid(1, nZ, (int k, int j) => at(u(j), ww, (k == 0) ? inner(u(j), ww) : outer(u(j), ww)), (int k, int j) => Map(edge, (side > 0) ? (0.99f - (float)k * 0.02f) : (0.01f + (float)k * 0.02f), (float)j / (float)nZ), outward); } } private static void Girth(MeshData mesh, SaddleFit fit, float blanketPhi) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) float a = fit.GirthA + 0.006f; float b = fit.GirthB + 0.006f; float num = Surface(fit, blanketPhi, fit.GirthZ, 0.008f).y + 0.02f; float start = Mathf.Acos(Mathf.Clamp((num - fit.GirthCenterY) / b, -1f, 1f)); float end = (float)Math.PI * 2f - start; Func<int, float> psi = (int i) => Mathf.Lerp(start, end, (float)i / 36f); Func<float, float, float, Vector3> at = delegate(float angle, float num6, float h) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: 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_0053: 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_005a: Unknown result type (might be due to invalid IL or missing references) float num4 = Mathf.Sin(angle); float num5 = Mathf.Cos(angle); Vector3 val = new Vector3(b * num4, a * num5, 0f); Vector3 normalized = ((Vector3)(ref val)).normalized; return new Vector3(a * num4, fit.GirthCenterY + b * num5, num6) + normalized * h; }; float z0 = fit.GirthZ - 0.0225f; float z1 = fit.GirthZ + 0.0225f; mesh.AddGrid(36, 1, (int i, int k) => at(psi(i), (k == 0) ? z0 : z1, 0.008f), (int i, int k) => Map(Strap, (float)i / 36f, k), Vector3.down); mesh.AddGrid(36, 1, (int i, int k) => at(psi(i), (k == 0) ? z0 : z1, 0f), (int i, int k) => Map(Dark, (float)i / 36f, k), Vector3.up); int[] array = new int[2] { -1, 1 }; foreach (int num3 in array) { float z2 = ((num3 > 0) ? z1 : z0); mesh.AddGrid(36, 1, (int i, int k) => at(psi(i), z2, (float)k * 0.008f), (int i, int k) => Map(Dark, (float)i / 36f, 0.5f), new Vector3(0f, 0f, (float)num3)); } } private static Vector2 Map(Rect area, float u, float v) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) return new Vector2(((Rect)(ref area)).xMin + 0.0009765625f + Mathf.Clamp01(u) * (((Rect)(ref area)).width - 0.001953125f), ((Rect)(ref area)).yMin + 0.0009765625f + Mathf.Clamp01(v) * (((Rect)(ref area)).height - 0.001953125f)); } } }