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 Fitness v0.1.1
plugins/Jarki-Fitness/Fitness.dll
Decompiled 3 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; 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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Fitness")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.1.0")] [assembly: AssemblyInformationalVersion("0.1.1+2938c9dd02f3094aa5fca675d8183992fb87a5df")] [assembly: AssemblyProduct("Fitness")] [assembly: AssemblyTitle("Fitness")] [assembly: AssemblyVersion("0.1.1.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 Fitness { [BepInPlugin("jarki.fitness", "Fitness", "0.1.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string Guid = "jarki.fitness"; internal static readonly int[] StrainHashes = new int[4] { 0, StringExtensionMethods.GetStableHashCode("FitnessRunStrain1"), StringExtensionMethods.GetStableHashCode("FitnessRunStrain2"), StringExtensionMethods.GetStableHashCode("FitnessRunStrain3") }; private static ConfigEntry<float> trainingMultiplier; private static ConfigEntry<float> staminaMultiplier; private static ConfigEntry<float> strainMultiplier; private static ConfigEntry<float> onset; private static ConfigEntry<float> recovery; private static ConfigEntry<float> immuneSkill; private Harmony patches; internal static float TrainingMultiplier => trainingMultiplier.Value; internal static float StaminaMultiplier => staminaMultiplier.Value; internal static float StrainMultiplier => strainMultiplier.Value; internal static float OnsetSeconds => onset.Value; internal static float RecoverySeconds => recovery.Value; internal static float ImmuneSkill => immuneSkill.Value; private void Awake() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Expected O, but got Unknown //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Expected O, but got Unknown //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Expected O, but got Unknown trainingMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Treadmill", "RunExperienceMultiplier", 1.5f, new ConfigDescription("Run XP multiplier while actively training; ordinary running is unchanged.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>())); staminaMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Treadmill", "StaminaConsumptionMultiplier", 1f, new ConfigDescription("Final native running stamina cost multiplier while actively training; ordinary running is unchanged.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 5f), Array.Empty<object>())); strainMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Treadmill", "StrainBuildupMultiplier", 1f, new ConfigDescription("Sprint effort multiplier for treadmill strain buildup only; ordinary running and recovery are unchanged.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 5f), Array.Empty<object>())); onset = ((BaseUnityPlugin)this).Config.Bind<float>("Muscle strain", "SecondsPerLevel", 90f, new ConfigDescription("Cumulative sprint seconds per strain level at Run 0. Higher Run skill slows buildup.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 3600f), Array.Empty<object>())); recovery = ((BaseUnityPlugin)this).Config.Bind<float>("Muscle strain", "RecoverySecondsPerLevel", 180f, new ConfigDescription("Non-sprinting, alive seconds to recover one full strain level. No offline recovery.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 3600f), Array.Empty<object>())); immuneSkill = ((BaseUnityPlugin)this).Config.Bind<float>("Muscle strain", "StrainFreeRunSkill", 75f, new ConfigDescription("Run skill at which new strain stops building; susceptibility decreases linearly up to this skill.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f), Array.Empty<object>())); patches = new Harmony("jarki.fitness"); patches.PatchAll(); PrefabManager.OnVanillaPrefabsAvailable += Register; } private void Register() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Invalid comparison between Unknown and I4 //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Expected O, but got Unknown Skills component = PrefabManager.Instance.GetPrefab("Player").GetComponent<Skills>(); Sprite val = null; foreach (SkillDef skill in component.m_skills) { if ((int)skill.m_skill == 102) { val = skill.m_icon; break; } } if (!Object.op_Implicit((Object)(object)val)) { throw new InvalidOperationException("Fitness requires the native Run skill icon"); } string[] array = new string[4] { "", "I — mild", "II — moderate", "III — severe" }; for (int i = 1; i <= 3; i++) { SE_Stats val2 = ScriptableObject.CreateInstance<SE_Stats>(); ((Object)val2).name = "FitnessRunStrain" + i; ((StatusEffect)val2).m_name = "Muscle strain " + array[i]; ((StatusEffect)val2).m_icon = val; ((StatusEffect)val2).m_tooltip = "Overworked running muscles. Stop sprinting to recover.\nPartial fatigue persists between runs and across saves."; val2.m_runStaminaDrainModifier = StrainState.StaminaPenalty(i); if (!ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)val2, false))) { throw new InvalidOperationException("Could not register " + ((Object)val2).name); } } Treadmill.Register(); PrefabManager.OnVanillaPrefabsAvailable -= Register; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Fitness registered: treadmill training and three running muscle-strain levels."); } private void OnDestroy() { PrefabManager.OnVanillaPrefabsAvailable -= Register; Treadmill.Shutdown(); StrainController.Shutdown(); Harmony obj = patches; if (obj != null) { obj.UnpatchSelf(); } } } internal static class StrainController { [HarmonyPatch(typeof(Player), "CheckRun")] private static class SprintEffort { private static void Postfix(Player __instance, float dt, bool __result) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && __result && !((Character)__instance).IsDead()) { float seconds = (Treadmill.IsTrainingRun(__instance) ? (dt * Plugin.StrainMultiplier) : dt); Advance(__instance, seconds, sprinting: true); } } } [HarmonyPatch(typeof(Character), "CustomFixedUpdate")] private static class Recover { private static void Postfix(Character __instance, float dt) { Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer) && !((Object)(object)__instance != (Object)(object)localPlayer) && !((Character)localPlayer).IsDead() && !((Character)localPlayer).IsTeleporting()) { if (!((Character)localPlayer).IsRunning() && !Treadmill.IsTraining(localPlayer)) { Advance(localPlayer, dt, sprinting: false); } else { Apply(localPlayer, State(localPlayer).Level); } } } } [HarmonyPatch(typeof(Player), "Save")] private static class Save { private static void Prefix(Player __instance) { Persist(__instance); } } [HarmonyPatch(typeof(Player), "Load")] private static class Load { private static void Postfix(Player __instance) { States.Remove(__instance); State(__instance); } } private const string SaveKey = "jarki.fitness.runStrain"; private static readonly ConditionalWeakTable<Player, StrainState> States = new ConditionalWeakTable<Player, StrainState>(); private const string LevelSaveKey = "jarki.fitness.runStrainLevel"; private static StrainState State(Player player) { return States.GetValue(player, CreateState); } private static StrainState CreateState(Player player) { StrainState strainState = new StrainState(); if (player.m_customData.TryGetValue("jarki.fitness.runStrain", out var value) && float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { int result2 = 0; if (player.m_customData.TryGetValue("jarki.fitness.runStrainLevel", out var value2)) { int.TryParse(value2, NumberStyles.Integer, CultureInfo.InvariantCulture, out result2); } strainState.Restore(result, result2); } return strainState; } private static void Advance(Player player, float seconds, bool sprinting) { StrainState strainState = State(player); strainState.Advance(seconds, sprinting, ((Character)player).GetSkills().GetSkillLevel((SkillType)102), Plugin.OnsetSeconds, Plugin.RecoverySeconds, Plugin.ImmuneSkill); Apply(player, strainState.Level); } private static void Apply(Player player, int level) { SEMan sEMan = ((Character)player).GetSEMan(); for (int i = 1; i <= 3; i++) { int num = Plugin.StrainHashes[i]; if (i != level) { if (sEMan.HaveStatusEffect(num)) { sEMan.RemoveStatusEffect(num, true); } } else if (!sEMan.HaveStatusEffect(num)) { sEMan.AddStatusEffect(num, false, 0, 0f, (short)(-1)); } } } internal static void Shutdown() { Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer)) { Persist(localPlayer); Apply(localPlayer, 0); } } private static void Persist(Player player) { if (States.TryGetValue(player, out var value)) { player.m_customData["jarki.fitness.runStrain"] = value.Load.ToString("R", CultureInfo.InvariantCulture); player.m_customData["jarki.fitness.runStrainLevel"] = value.Level.ToString(CultureInfo.InvariantCulture); } } } public sealed class StrainState { private double load; public float Load => (float)load; public int Level { get; private set; } public void Advance(float seconds, bool sprinting, float runSkill, float onsetSeconds, float recoverySeconds, float immuneSkill) { if (seconds <= 0f || float.IsNaN(seconds) || float.IsInfinity(seconds)) { return; } if (sprinting) { float num = Math.Max(0f, 1f - Math.Max(0f, runSkill) / immuneSkill); load = Math.Min(3.999, load + (double)seconds * (double)num / (double)onsetSeconds); Level = Math.Max(Level, Math.Min(3, (int)(load + 1E-06))); return; } load = Math.Max(0.0, load - (double)seconds / (double)recoverySeconds); while (Level > 0 && load <= (double)(Level - 1) + 1E-06) { int level = Level - 1; Level = level; } } public void Restore(float load) { this.load = ((float.IsNaN(load) || float.IsInfinity(load)) ? 0.0 : Math.Max(0.0, Math.Min(3.999, load))); Level = Math.Min(3, (int)this.load); } public void Restore(float load, int level) { Restore(load); Level = Math.Max(Level, Math.Min(Math.Min(3, (int)Math.Ceiling(this.load)), level)); } public static float StaminaPenalty(int level) { if (level <= 0) { return 0f; } return level switch { 1 => 0.15f, 2 => 0.3f, _ => 0.5f, }; } } internal sealed class Treadmill : MonoBehaviour, Interactable, Hoverable { private delegate bool RunCheck(Player player, Vector3 direction, float dt); [HarmonyPatch(typeof(Character), "CustomFixedUpdate")] private static class TrainingTick { [HarmonyPostfix] private static void Postfix(Character __instance, float dt) { if (Object.op_Implicit((Object)(object)active) && (Object)(object)__instance == (Object)(object)active.runner) { active.Train(active.runner, dt); } } } [HarmonyPatch(typeof(Player), "UseStamina")] private static class TrainingStamina { [HarmonyPrefix] private static void Prefix(Player __instance, ref float v) { if (IsTrainingRun(__instance)) { v *= Plugin.StaminaMultiplier; } } } [HarmonyPatch(typeof(Player), "RaiseSkill")] private static class TrainingExperience { [HarmonyPrefix] private static void Prefix(Player __instance, SkillType skill, ref float value) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Invalid comparison between Unknown and I4 if ((int)skill == 102 && IsTrainingRun(__instance)) { value *= Plugin.TrainingMultiplier; } } } [HarmonyPatch(typeof(Player), "AttachStop")] private static class NativeDetach { [HarmonyPostfix] private static void Postfix(Player __instance) { if (Object.op_Implicit((Object)(object)active) && (Object)(object)active.runner == (Object)(object)__instance && (Object)(object)__instance.GetAttachPoint() != (Object)(object)active.attachPoint) { active.StopTraining(); } } } [HarmonyPatch(typeof(Player), "OnDestroy")] private static class PlayerDestroyed { [HarmonyPrefix] private static void Prefix(Player __instance) { if (Object.op_Implicit((Object)(object)active) && (Object)(object)active.runner == (Object)(object)__instance) { active.StopTraining(); } if (Object.op_Implicit((Object)(object)pending) && (Object)(object)pending.requestingPlayer == (Object)(object)__instance) { pending.CancelRequest(); } } } private const string PrefabName = "FitnessTreadmill"; private const string RequestRpc = "FitnessRequestTreadmill"; private const string HeartbeatRpc = "FitnessTreadmillHeartbeat"; private const string LeaseRpc = "FitnessTreadmillLease"; private const string ReleaseRpc = "FitnessReleaseTreadmill"; private const float UseDistance = 3f; private const long LeaseTicks = 50000000L; private static readonly KeyValuePair<int, int> UserKey = ZDO.GetHashZDOID("FitnessTreadmillUser"); private static readonly int PeerKey = StringExtensionMethods.GetStableHashCode("FitnessTreadmillPeer"); private static readonly int TokenKey = StringExtensionMethods.GetStableHashCode("FitnessTreadmillToken"); private static readonly int LeaseKey = StringExtensionMethods.GetStableHashCode("FitnessTreadmillLease"); private static readonly int ForwardSpeed = ZSyncAnimation.GetHash("forward_speed"); private static readonly int SideSpeed = ZSyncAnimation.GetHash("sideway_speed"); private static readonly int TurnSpeed = ZSyncAnimation.GetHash("turn_speed"); private static readonly int OnGround = ZSyncAnimation.GetHash("onGround"); private static readonly int InWater = ZSyncAnimation.GetHash("inWater"); private static readonly int Flying = ZSyncAnimation.GetHash("flying"); private static readonly int Encumbered = ZSyncAnimation.GetHash("encumbered"); private static readonly List<Treadmill> instances = new List<Treadmill>(); private static readonly FieldRef<Character, bool> RunInput = AccessTools.FieldRefAccess<Character, bool>("m_run"); private static readonly FieldRef<Character, bool> Running = AccessTools.FieldRefAccess<Character, bool>("m_running"); private static readonly RunCheck CheckRun = AccessTools.MethodDelegate<RunCheck>(AccessTools.DeclaredMethod(typeof(Player), "CheckRun", (Type[])null, (Type[])null), (object)null, true); private static readonly Func<Player, bool> TakeInput = AccessTools.MethodDelegate<Func<Player, bool>>(AccessTools.DeclaredMethod(typeof(Player), "TakeInput", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<Player> UpdateAttach = AccessTools.MethodDelegate<Action<Player>>(AccessTools.DeclaredMethod(typeof(Player), "UpdateAttach", (Type[])null, (Type[])null), (object)null, true); private static readonly Action<Player> StopEmote = AccessTools.MethodDelegate<Action<Player>>(AccessTools.DeclaredMethod(typeof(Player), "StopEmote", (Type[])null, (Type[])null), (object)null, true); private static readonly Func<Player, float> RunSpeedFactor = AccessTools.MethodDelegate<Func<Player, float>>(AccessTools.DeclaredMethod(typeof(Player), "GetRunSpeedFactor", (Type[])null, (Type[])null), (object)null, true); private static CustomPiece registeredPiece; private static Treadmill active; private static Treadmill pending; private static int nextToken; private static bool checkingRun; [SerializeField] private Transform attachPoint; private ZNetView view; private TreadmillVisual visual; private Player runner; private Player requestingPlayer; private ZDOID userId; private int token; private long confirmedLease; private float requestTimeout; private float nextHeartbeat; private object[] userArguments; private bool initialized; private static long NetworkTicks { get { if (!Object.op_Implicit((Object)(object)ZNet.instance)) { return 0L; } return ZNet.instance.GetTime().Ticks; } } internal static void Register() { //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Expected O, but got Unknown //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Expected O, but got Unknown //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Expected O, but got Unknown //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Expected O, but got Unknown //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Expected O, but got Unknown //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Expected O, but got Unknown //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Expected O, but got Unknown //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_0384: Unknown result type (might be due to invalid IL or missing references) //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_0399: Unknown result type (might be due to invalid IL or missing references) //IL_03df: Unknown result type (might be due to invalid IL or missing references) //IL_03e6: Expected O, but got Unknown //IL_0410: Unknown result type (might be due to invalid IL or missing references) if (registeredPiece != null) { return; } GameObject prefab = PrefabManager.Instance.GetPrefab("wood_floor"); if (!Object.op_Implicit((Object)(object)prefab)) { throw new InvalidOperationException("Fitness requires the vanilla wood_floor prefab."); } WearNTear component = prefab.GetComponent<WearNTear>(); if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.m_new)) { throw new InvalidOperationException("Fitness requires wood_floor's intact wood visual."); } Material val = null; MeshRenderer[] componentsInChildren = component.m_new.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val2 in componentsInChildren) { if ((Object)(object)val2 != (Object)(object)component.m_snow && (Object)(object)val2 != (Object)(object)component.m_snowWorn && (Object)(object)val2 != (Object)(object)component.m_snowBroken && Object.op_Implicit((Object)(object)((Renderer)val2).sharedMaterial)) { val = ((Renderer)val2).sharedMaterial; break; } } if (!Object.op_Implicit((Object)(object)val)) { throw new InvalidOperationException("Fitness could not find the vanilla wood floor material."); } GameObject prefab2 = PrefabManager.Instance.GetPrefab("rug_deer"); if (!Object.op_Implicit((Object)(object)prefab2)) { throw new InvalidOperationException("Fitness requires the vanilla deer-hide rug prefab."); } Material val3 = null; componentsInChildren = prefab2.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val4 in componentsInChildren) { if (Object.op_Implicit((Object)(object)((Renderer)val4).sharedMaterial) && ((Object)((Renderer)val4).sharedMaterial).name == "deerhide_rug") { val3 = ((Renderer)val4).sharedMaterial; break; } } if (!Object.op_Implicit((Object)(object)val3)) { throw new InvalidOperationException("Fitness could not find the native deer-hide rug material."); } PieceConfig val5 = new PieceConfig(); val5.Name = "Wooden treadmill"; val5.Description = "Run in place to train Run. Uses normal running stamina and causes muscle strain. Move or jump to stop."; val5.PieceTable = "Hammer"; val5.Category = "Furniture"; val5.CraftingStation = "piece_workbench"; val5.Requirements = (RequirementConfig[])(object)new RequirementConfig[5] { new RequirementConfig("Wood", 20, 0, true), new RequirementConfig("RoundLog", 10, 0, true), new RequirementConfig("BronzeNails", 10, 0, true), new RequirementConfig("DeerHide", 6, 0, true), new RequirementConfig("LeatherScraps", 10, 0, true) }; CustomPiece val6 = new CustomPiece("FitnessTreadmill", "wood_floor", val5); GameObject piecePrefab = val6.PiecePrefab; if (!Object.op_Implicit((Object)(object)piecePrefab)) { throw new InvalidOperationException("Fitness could not clone wood_floor."); } for (int num = piecePrefab.transform.childCount - 1; num >= 0; num--) { Object.DestroyImmediate((Object)(object)((Component)piecePrefab.transform.GetChild(num)).gameObject); } Component[] components = piecePrefab.GetComponents<Component>(); foreach (Component val7 in components) { if (!(val7 is Transform) && !(val7 is Piece) && !(val7 is WearNTear) && !(val7 is ZNetView) && !(val7 is ZSyncTransform)) { Object.DestroyImmediate((Object)(object)val7); } } piecePrefab.transform.localScale = Vector3.one; GameObject val8 = TreadmillVisual.Build(piecePrefab, val, val3); WearNTear component2 = piecePrefab.GetComponent<WearNTear>(); if (!Object.op_Implicit((Object)(object)component2) || !Object.op_Implicit((Object)(object)piecePrefab.GetComponent<ZNetView>())) { Object.DestroyImmediate((Object)(object)piecePrefab); TreadmillVisual.Shutdown(); throw new InvalidOperationException("Fitness wood_floor clone lacks construction networking."); } component2.m_new = (component2.m_worn = (component2.m_broken = val8)); component2.m_wet = null; component2.m_snow = (component2.m_snowWorn = (component2.m_snowBroken = null)); component2.m_nonSolidRenderers.Clear(); component2.m_fragmentRoots = (GameObject[])(object)new GameObject[1] { val8 }; component2.m_comOffset = new Vector3(0f, 0.65f, 0f); val6.Piece.m_usage = (UsageTagFlags)128; val6.Piece.m_clipEverything = false; val6.Piece.m_clipGround = false; val6.Piece.m_noClipping = true; val6.Piece.m_notOnTiltingSurface = true; val6.Piece.m_noInWater = true; GameObject val9 = new GameObject("FitnessRunPoint"); val9.transform.SetParent(piecePrefab.transform, false); val9.transform.localPosition = new Vector3(0f, 0.5f, -0.25f); piecePrefab.AddComponent<Treadmill>().attachPoint = val9.transform; if (!PieceManager.Instance.AddPiece(val6)) { Object.DestroyImmediate((Object)(object)piecePrefab); TreadmillVisual.Shutdown(); throw new InvalidOperationException("Fitness treadmill registration failed."); } registeredPiece = val6; } private void Start() { view = ((Component)this).GetComponent<ZNetView>(); if (!Object.op_Implicit((Object)(object)view) || !view.IsValid()) { ((Behaviour)this).enabled = false; return; } visual = ((Component)this).GetComponentInChildren<TreadmillVisual>(true); view.Register<ZDOID, int>("FitnessRequestTreadmill", (Action<long, ZDOID, int>)RequestUse); view.Register<ZDOID, int>("FitnessTreadmillHeartbeat", (Action<long, ZDOID, int>)RenewUse); view.Register<ZDOID, int, long>("FitnessTreadmillLease", (Action<long, ZDOID, int, long>)ReceiveLease); view.Register<ZDOID, int>("FitnessReleaseTreadmill", (Action<long, ZDOID, int>)ReleaseUse); initialized = true; instances.Add(this); } internal static bool IsTraining(Player player) { if (Object.op_Implicit((Object)(object)active) && ((Behaviour)active).isActiveAndEnabled && (Object)(object)active.runner == (Object)(object)player && Object.op_Implicit((Object)(object)player) && ((Behaviour)player).isActiveAndEnabled && !((Character)player).IsDead() && !((Character)player).IsTeleporting()) { return (Object)(object)player.GetAttachPoint() == (Object)(object)active.attachPoint; } return false; } internal static bool IsTrainingRun(Player player) { if (checkingRun) { return IsTraining(player); } return false; } public string GetHoverName() { return "Wooden treadmill"; } public float GetHoverOffset() { return 0.7f; } public string GetHoverText() { if (Object.op_Implicit((Object)(object)runner) && IsTraining(runner)) { return Localization.instance.Localize("Wooden treadmill\n[<color=yellow><b>$KEY_Use</b></color>] Stop training\nMove or jump to stop"); } if (HasOccupant()) { return "Wooden treadmill\nIn use"; } if (Object.op_Implicit((Object)(object)requestingPlayer)) { return "Wooden treadmill\nWaiting for treadmill owner…"; } return Localization.instance.Localize("Wooden treadmill\n[<color=yellow><b>$KEY_Use</b></color>] Train Run\nUses stamina; causes muscle strain"); } public bool Interact(Humanoid user, bool hold, bool alt) { //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) if (hold || !initialized || !view.IsValid()) { return false; } Player val = (Player)(object)((user is Player) ? user : null); if (!Object.op_Implicit((Object)(object)val) || (Object)(object)val != (Object)(object)Player.m_localPlayer) { return false; } if ((Object)(object)runner == (Object)(object)val) { StopTraining(); return true; } if (!CanStart(val)) { return false; } if (HasOccupant()) { ((Character)val).Message((MessageType)2, "This treadmill is in use.", 0, (Sprite)null, false); return false; } if (Object.op_Implicit((Object)(object)active)) { active.StopTraining(); } if (Object.op_Implicit((Object)(object)pending)) { pending.CancelRequest(); } requestingPlayer = val; pending = this; userId = ((Character)val).GetZDOID(); token = ++nextToken; if (token == 0) { token = ++nextToken; } userArguments = new object[2] { userId, token }; requestTimeout = Time.time + 3f; view.InvokeRPC("FitnessRequestTreadmill", userArguments); return true; } public bool UseItem(Humanoid user, ItemData item) { return false; } private bool CanStart(Player player) { //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) if (((Behaviour)this).isActiveAndEnabled && Object.op_Implicit((Object)(object)player) && ((Behaviour)player).isActiveAndEnabled && (Object)(object)player == (Object)(object)Player.m_localPlayer && !((Character)player).IsDead() && !((Character)player).IsTeleporting() && !((Character)player).IsAttached() && !((Character)player).IsEncumbered() && !((Character)player).IsCrouching() && !((Character)player).InDodge() && !((Character)player).InAttack() && !((Character)player).InPlaceMode() && !((Character)player).IsSwimming() && !((Character)player).IsFlying() && !((Character)player).IsDebugFlying() && ((Character)player).CanMove() && ((Character)player).HaveStamina(0f) && TakeInput(player)) { Vector3 val = ((Component)player).transform.position - attachPoint.position; return ((Vector3)(ref val)).sqrMagnitude < 9f; } return false; } private bool HasOccupant() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (initialized && Object.op_Implicit((Object)(object)view) && view.IsValid() && view.GetZDO().GetZDOID(UserKey) != ZDOID.None) { return view.GetZDO().GetLong(LeaseKey, 0L) > NetworkTicks; } return false; } private bool VerifyUser(long sender, ZDOID id) { //IL_0005: 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) //IL_0050: 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) ZDO zDO = ZDOMan.instance.GetZDO(id); if (zDO == null || zDO.GetOwner() != sender) { return false; } List<Player> allPlayers = Player.GetAllPlayers(); for (int i = 0; i < allPlayers.Count; i++) { Player val = allPlayers[i]; if (!(((Character)val).GetZDOID() != id)) { if (!((Character)val).IsDead() && !((Character)val).IsTeleporting()) { Vector3 val2 = ((Component)val).transform.position - attachPoint.position; return ((Vector3)(ref val2)).sqrMagnitude < 9f; } return false; } } return false; } private bool MatchesReservation(long sender, ZDOID id, int requestToken) { //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) ZDO zDO = view.GetZDO(); if (zDO.GetZDOID(UserKey) == id && zDO.GetLong(PeerKey, 0L) == sender) { return zDO.GetInt(TokenKey, 0) == requestToken; } return false; } private void RequestUse(long sender, ZDOID id, int requestToken) { //IL_009d: 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) //IL_0052: 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) if (initialized && view.IsOwner()) { long num = 0L; if (((Behaviour)this).isActiveAndEnabled && requestToken != 0 && VerifyUser(sender, id) && (!HasOccupant() || MatchesReservation(sender, id, requestToken))) { ZDO zDO = view.GetZDO(); zDO.Set(UserKey, id); zDO.Set(PeerKey, sender); zDO.Set(TokenKey, requestToken, false); num = NetworkTicks + 50000000; zDO.Set(LeaseKey, num); } view.InvokeRPC(sender, "FitnessTreadmillLease", new object[3] { id, requestToken, num }); } } private void RenewUse(long sender, ZDOID id, int requestToken) { //IL_0075: 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) if (initialized && view.IsOwner()) { long num = 0L; if (((Behaviour)this).isActiveAndEnabled && HasOccupant() && MatchesReservation(sender, id, requestToken) && VerifyUser(sender, id)) { num = NetworkTicks + 50000000; view.GetZDO().Set(LeaseKey, num); } view.InvokeRPC(sender, "FitnessTreadmillLease", new object[3] { id, requestToken, num }); } } private void ReceiveLease(long sender, ZDOID id, int requestToken, long lease) { //IL_0029: 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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: 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) if (!initialized || !view.IsValid() || sender != view.GetZDO().GetOwner()) { return; } if (id != userId || requestToken != token) { if (lease > 0) { view.InvokeRPC("FitnessReleaseTreadmill", new object[2] { id, requestToken }); } return; } if (Object.op_Implicit((Object)(object)runner)) { if (lease <= NetworkTicks) { StopTraining(); } else { confirmedLease = lease; } return; } Player val = requestingPlayer; if ((Object)(object)pending != (Object)(object)this || !Object.op_Implicit((Object)(object)val) || Time.time > requestTimeout || !CanStart(val) || lease <= NetworkTicks) { if (Object.op_Implicit((Object)(object)val) && lease <= NetworkTicks) { ((Character)val).Message((MessageType)2, "The treadmill is unavailable.", 0, (Sprite)null, false); } if (lease > 0 && (Object)(object)pending != (Object)(object)this) { view.InvokeRPC("FitnessReleaseTreadmill", new object[2] { id, requestToken }); } CancelRequest(); return; } confirmedLease = lease; requestingPlayer = null; pending = null; if (Object.op_Implicit((Object)(object)active)) { active.StopTraining(); } active = this; runner = val; Player obj = runner; ((Character)obj).m_onDamaged = (Action<float, Character>)Delegate.Combine(((Character)obj).m_onDamaged, new Action<float, Character>(OnRunnerDamaged)); Player obj2 = runner; ((Character)obj2).m_onDeath = (Action)Delegate.Combine(((Character)obj2).m_onDeath, new Action(OnRunnerDeath)); runner.m_autoRun = false; ((Character)runner).SetMoveDir(Vector3.zero); ((Character)runner).SetRun(false); StopEmote(runner); ((Character)runner).AttachStart(attachPoint, ((Component)this).gameObject, true, false, false, "onGround", new Vector3(-1.45f, -0.45f, 0f), (Transform)null); nextHeartbeat = Time.time + 1f; if ((Object)(object)runner.GetAttachPoint() != (Object)(object)attachPoint) { StopTraining(); } } private void ReleaseUse(long sender, ZDOID id, int requestToken) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (initialized && view.IsOwner() && MatchesReservation(sender, id, requestToken)) { ClearReservation(); } } private void ClearReservation() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) ZDO zDO = view.GetZDO(); zDO.Set(UserKey, ZDOID.None); zDO.Set(PeerKey, 0L); zDO.Set(TokenKey, 0, false); zDO.Set(LeaseKey, 0L); } private void Update() { //IL_004c: 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 (!initialized || !Object.op_Implicit((Object)(object)view) || !view.IsValid()) { StopTraining(); CancelRequest(); return; } if (view.IsOwner() && view.GetZDO().GetZDOID(UserKey) != ZDOID.None && !HasOccupant()) { ClearReservation(); } if (Object.op_Implicit((Object)(object)requestingPlayer) && (Time.time > requestTimeout || !CanStart(requestingPlayer))) { CancelRequest(); } if (Object.op_Implicit((Object)(object)runner) && (!IsTraining(runner) || !CanContinueTraining(runner) || !((Character)runner).HaveStamina(0f) || confirmedLease <= NetworkTicks)) { StopTraining(); } if (Object.op_Implicit((Object)(object)runner) && Time.time >= nextHeartbeat) { nextHeartbeat = Time.time + 1f; view.InvokeRPC("FitnessTreadmillHeartbeat", userArguments); } if (Object.op_Implicit((Object)(object)visual) && HasOccupant()) { visual.Advance(Object.op_Implicit((Object)(object)runner) ? (((Character)runner).m_runSpeed * RunSpeedFactor(runner)) : 6f, Time.deltaTime); } } private static bool CanContinueTraining(Player player) { if (TakeInput(player)) { return true; } if (InventoryGui.IsVisible() && !((Character)player).IsDead() && !((Character)player).InCutscene() && !((Character)player).IsTeleporting() && (!Object.op_Implicit((Object)(object)Chat.instance) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible() && !StoreGui.IsVisible() && !Menu.IsVisible() && (!Object.op_Implicit((Object)(object)TextViewer.instance) || !TextViewer.instance.IsVisible()) && !Minimap.IsOpen() && !GameCamera.InFreeFly() && !PlayerCustomizaton.IsBarberGuiVisible() && Object.op_Implicit((Object)(object)Hud.instance)) { return !Hud.instance.m_buildUi.SearchFieldFocused; } return false; } private void Train(Player player, float dt) { //IL_00af: Unknown result type (might be due to invalid IL or missing references) if (!IsTraining(player) || !Object.op_Implicit((Object)(object)view) || !view.IsValid() || confirmedLease <= NetworkTicks || !CanContinueTraining(player) || !((Character)player).HaveStamina(0f) || ((Character)player).IsEncumbered() || ((Character)player).IsCrouching() || ((Character)player).InDodge() || !((Character)player).CanMove() || ((Character)player).IsSwimming() || ((Character)player).IsFlying() || ((Character)player).IsDebugFlying()) { StopTraining(); return; } bool flag = RunInput.Invoke((Character)(object)player); bool flag2; try { checkingRun = true; RunInput.Invoke((Character)(object)player) = true; flag2 = CheckRun(player, attachPoint.forward, dt); } finally { RunInput.Invoke((Character)(object)player) = flag; checkingRun = false; } if (!flag2) { StopTraining(); return; } Running.Invoke((Character)(object)player) = true; UpdateAttach(player); ZSyncAnimation zAnim = ((Character)player).GetZAnim(); zAnim.SetFloat(ForwardSpeed, ((Character)player).m_runSpeed * RunSpeedFactor(player)); zAnim.SetFloat(SideSpeed, 0f); zAnim.SetFloat(TurnSpeed, 0f); zAnim.SetBool(OnGround, true); zAnim.SetBool(InWater, false); zAnim.SetBool(Flying, false); zAnim.SetBool(Encumbered, false); } private void OnRunnerDamaged(float damage, Character attacker) { if (damage > 0f) { StopTraining(); } } private void OnRunnerDeath() { StopTraining(); } private void CancelRequest() { if (!((Object)(object)pending != (Object)(object)this) || requestingPlayer != null) { if ((Object)(object)pending == (Object)(object)this) { pending = null; } requestingPlayer = null; if (Object.op_Implicit((Object)(object)view) && view.IsValid() && userArguments != null) { view.InvokeRPC("FitnessReleaseTreadmill", userArguments); } if (!Object.op_Implicit((Object)(object)runner)) { userArguments = null; } } } private void StopTraining() { Player val = runner; runner = null; if ((Object)(object)active == (Object)(object)this) { active = null; } if (val != null) { ((Character)val).m_onDamaged = (Action<float, Character>)Delegate.Remove(((Character)val).m_onDamaged, new Action<float, Character>(OnRunnerDamaged)); ((Character)val).m_onDeath = (Action)Delegate.Remove(((Character)val).m_onDeath, new Action(OnRunnerDeath)); if (Object.op_Implicit((Object)(object)val)) { Running.Invoke((Character)(object)val) = false; if ((Object)(object)val.GetAttachPoint() == (Object)(object)attachPoint) { ((Character)val).AttachStop(); } ZSyncAnimation zAnim = ((Character)val).GetZAnim(); if (Object.op_Implicit((Object)(object)zAnim)) { zAnim.SetFloat(ForwardSpeed, 0f); zAnim.SetFloat(SideSpeed, 0f); zAnim.SetFloat(TurnSpeed, 0f); } } if (Object.op_Implicit((Object)(object)view) && view.IsValid() && userArguments != null) { view.InvokeRPC("FitnessReleaseTreadmill", userArguments); } userArguments = null; } confirmedLease = 0L; } private void OnDisable() { StopTraining(); CancelRequest(); if (initialized && Object.op_Implicit((Object)(object)view) && view.IsValid() && view.IsOwner()) { ClearReservation(); } } private void OnDestroy() { StopTraining(); CancelRequest(); instances.Remove(this); } internal static void Shutdown() { if (Object.op_Implicit((Object)(object)pending)) { pending.CancelRequest(); } if (Object.op_Implicit((Object)(object)active)) { active.StopTraining(); } for (int num = instances.Count - 1; num >= 0; num--) { if (Object.op_Implicit((Object)(object)instances[num])) { ((Behaviour)instances[num]).enabled = false; } } if (registeredPiece != null) { GameObject piecePrefab = registeredPiece.PiecePrefab; if (Object.op_Implicit((Object)(object)piecePrefab)) { PieceTable pieceTable = PieceManager.Instance.GetPieceTable("Hammer"); if (Object.op_Implicit((Object)(object)pieceTable)) { pieceTable.m_pieces.Remove(piecePrefab); } PieceManager.Instance.RemovePiece(registeredPiece); Object.Destroy((Object)(object)piecePrefab); } registeredPiece = null; } TreadmillVisual.Shutdown(); } } internal sealed class TreadmillVisual : MonoBehaviour { private sealed class Geometry { private readonly List<Vector3> vertices = new List<Vector3>(); private readonly List<Vector3> normals = new List<Vector3>(); private readonly List<Vector2> uv = new List<Vector2>(); private readonly List<int> triangles = new List<int>(); private void Quad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Vector3 normal, float width, float height) { //IL_0012: 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_002a: 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_0047: 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_0073: 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_009e: Unknown result type (might be due to invalid IL or missing references) int count = vertices.Count; vertices.Add(a); vertices.Add(b); vertices.Add(c); vertices.Add(d); for (int i = 0; i < 4; i++) { normals.Add(normal); } uv.Add(Vector2.zero); uv.Add(new Vector2(width, 0f)); uv.Add(new Vector2(width, height)); uv.Add(new Vector2(0f, height)); triangles.Add(count); triangles.Add(count + 1); triangles.Add(count + 2); triangles.Add(count); triangles.Add(count + 2); triangles.Add(count + 3); } internal void Box(Vector3 center, Vector3 size) { //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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0012: 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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_0031: 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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_0059: 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_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_0070: 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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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_0098: 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_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_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_00e3: 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_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: 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_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0117: 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) //IL_0128: 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_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0145: 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_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0156: 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_0162: 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_016c: 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_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_0190: 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_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: 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_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: 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_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01df: 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_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: 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_0208: Unknown result type (might be due to invalid IL or missing references) //IL_020e: 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_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0225: 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_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_028d: 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_0298: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02bb: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) Vector3 val = center - size * 0.5f; Vector3 val2 = center + size * 0.5f; Quad(new Vector3(val.x, val2.y, val.z), new Vector3(val.x, val2.y, val2.z), new Vector3(val2.x, val2.y, val2.z), new Vector3(val2.x, val2.y, val.z), Vector3.up, size.z, size.x); Quad(new Vector3(val.x, val.y, val2.z), new Vector3(val.x, val.y, val.z), new Vector3(val2.x, val.y, val.z), new Vector3(val2.x, val.y, val2.z), Vector3.down, size.z, size.x); Quad(new Vector3(val.x, val.y, val.z), new Vector3(val.x, val2.y, val.z), new Vector3(val2.x, val2.y, val.z), new Vector3(val2.x, val.y, val.z), Vector3.back, size.y, size.x); Quad(new Vector3(val2.x, val.y, val2.z), new Vector3(val2.x, val2.y, val2.z), new Vector3(val.x, val2.y, val2.z), new Vector3(val.x, val.y, val2.z), Vector3.forward, size.y, size.x); Quad(new Vector3(val.x, val.y, val2.z), new Vector3(val.x, val2.y, val2.z), new Vector3(val.x, val2.y, val.z), new Vector3(val.x, val.y, val.z), Vector3.left, size.y, size.z); Quad(new Vector3(val2.x, val.y, val.z), new Vector3(val2.x, val2.y, val.z), new Vector3(val2.x, val2.y, val2.z), new Vector3(val2.x, val.y, val2.z), Vector3.right, size.y, size.z); } internal void MapBoxUV(Rect region) { //IL_001c: 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_005e: 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) for (int i = 0; i < uv.Count; i += 4) { uv[i] = new Vector2(((Rect)(ref region)).xMin, ((Rect)(ref region)).yMin); uv[i + 1] = new Vector2(((Rect)(ref region)).xMax, ((Rect)(ref region)).yMin); uv[i + 2] = new Vector2(((Rect)(ref region)).xMax, ((Rect)(ref region)).yMax); uv[i + 3] = new Vector2(((Rect)(ref region)).xMin, ((Rect)(ref region)).yMax); } } internal void CylinderX(float length, float radius, int sides) { //IL_006b: 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_007c: 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_0080: 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_0090: 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_00bc: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: 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_00e9: 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_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_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) Vector3 val = default(Vector3); Vector3 val2 = default(Vector3); Vector3 normal = default(Vector3); for (int i = 0; i < sides; i++) { float num = (float)i * 2f * MathF.PI / (float)sides; float num2 = (float)(i + 1) * 2f * MathF.PI / (float)sides; ((Vector3)(ref val))..ctor((0f - length) * 0.5f, Mathf.Cos(num) * radius, Mathf.Sin(num) * radius); ((Vector3)(ref val2))..ctor((0f - length) * 0.5f, Mathf.Cos(num2) * radius, Mathf.Sin(num2) * radius); Vector3 val3 = val + Vector3.right * length; Vector3 c = val2 + Vector3.right * length; ((Vector3)(ref normal))..ctor(0f, Mathf.Cos((num + num2) * 0.5f), Mathf.Sin((num + num2) * 0.5f)); Quad(val, val2, c, val3, normal, radius * (num2 - num), length); Triangle(new Vector3((0f - length) * 0.5f, 0f, 0f), val2, val, Vector3.left); Triangle(new Vector3(length * 0.5f, 0f, 0f), val3, c, Vector3.right); } } private void Triangle(Vector3 a, Vector3 b, Vector3 c, Vector3 normal) { //IL_0012: 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_002a: 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_0043: 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_0067: 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_007d: 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_0093: 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_009f: Unknown result type (might be due to invalid IL or missing references) int count = vertices.Count; vertices.Add(a); vertices.Add(b); vertices.Add(c); normals.Add(normal); normals.Add(normal); normals.Add(normal); uv.Add(new Vector2(0.5f, 0.5f)); uv.Add(new Vector2(b.y, b.z)); uv.Add(new Vector2(c.y, c.z)); triangles.Add(count); triangles.Add(count + 1); triangles.Add(count + 2); } internal Mesh Finish(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_004b: Expected O, but got Unknown Mesh val = new Mesh { name = name }; val.SetVertices(vertices); val.SetNormals(normals); val.SetUVs(0, uv); val.SetTriangles(triangles, 0); val.RecalculateTangents(); val.RecalculateBounds(); return val; } } private const float HalfLength = 1.15f; private const float RollerRadius = 0.15f; private const float RollerHeight = 0.32f; private const int SlatCount = 40; private const float LoopLength = 5.5424776f; private static Mesh frameMesh; private static Mesh slatMesh; private static Mesh rollerMesh; private static int liveVisuals; private static bool releaseRequested; [SerializeField] private Transform[] slats = Array.Empty<Transform>(); [SerializeField] private Transform[] rollers = Array.Empty<Transform>(); private bool counted; private float travel; internal static GameObject Build(GameObject prefab, Material wood, Material hide) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_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_0101: 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_00d3: 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_013b: 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_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) releaseRequested = false; EnsureMeshes(); GameObject val = new GameObject("FitnessWoodwork"); val.transform.SetParent(prefab.transform, false); AddMesh(val.transform, "Frame", frameMesh, wood, Vector3.zero, Vector3.one); TreadmillVisual treadmillVisual = val.AddComponent<TreadmillVisual>(); treadmillVisual.slats = (Transform[])(object)new Transform[40]; for (int i = 0; i < 40; i++) { treadmillVisual.slats[i] = AddMesh(val.transform, "BeltSlat", slatMesh, hide, Vector3.zero, Vector3.one); } treadmillVisual.rollers = (Transform[])(object)new Transform[2]; for (int j = 0; j < 2; j++) { treadmillVisual.rollers[j] = AddMesh(val.transform, "WoodenRoller", rollerMesh, wood, new Vector3(0f, 0.32f, (j == 0) ? (-1.15f) : 1.15f), Vector3.one); } treadmillVisual.PoseBelt(); AddCollider(prefab, new Vector3(0f, 0.23f, 0f), new Vector3(1.5f, 0.46f, 2.65f)); for (int k = -1; k <= 1; k += 2) { AddCollider(prefab, new Vector3((float)k * 0.83f, 0.4f, 0f), new Vector3(0.18f, 0.3f, 2.95f)); AddCollider(prefab, new Vector3((float)k * 0.83f, 1.08f, 0.95f), new Vector3(0.14f, 1.4f, 0.14f)); AddCollider(prefab, new Vector3((float)k * 0.83f, 1.56f, 0.2f), new Vector3(0.12f, 0.12f, 1.65f)); } AddCollider(prefab, new Vector3(0f, 1.76f, 0.95f), new Vector3(1.8f, 0.14f, 0.14f)); return val; } private static Transform AddMesh(Transform parent, string name, Mesh mesh, Material wood, Vector3 position, Vector3 scale) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0013: 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_0020: 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) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetParent(parent, false); val.transform.localPosition = position; val.transform.localScale = scale; val.AddComponent<MeshFilter>().sharedMesh = mesh; ((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = wood; return val.transform; } private static void AddCollider(GameObject root, Vector3 center, Vector3 size) { //IL_0007: 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) BoxCollider obj = root.AddComponent<BoxCollider>(); obj.center = center; obj.size = size; } private void Awake() { counted = true; liveVisuals++; } internal void Advance(float speed, float dt) { //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) travel = Mathf.Repeat(travel + speed * dt, 5.5424776f); PoseBelt(); float num = (0f - travel) / 0.15f * 57.29578f; for (int i = 0; i < rollers.Length; i++) { rollers[i].localRotation = Quaternion.AngleAxis(num, Vector3.right); } } private void PoseBelt() { //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < slats.Length; i++) { float num = Mathf.Repeat((float)i * 5.5424776f / 40f + travel, 5.5424776f); float num2 = 2.3f; float num3 = 0.47123894f; float num4; float num5; float num6; if (num < num2) { num4 = 1.15f - num; num5 = 0.47f; num6 = 0f; } else if (num < num2 + num3) { float num7 = (num - num2) / 0.15f; num4 = -1.15f - Mathf.Sin(num7) * 0.15f; num5 = 0.32f + Mathf.Cos(num7) * 0.15f; num6 = num7 * 57.29578f; } else if (num < 2f * num2 + num3) { num4 = -1.15f + num - num2 - num3; num5 = 0.16999999f; num6 = 180f; } else { float num8 = (num - 2f * num2 - num3) / 0.15f; num4 = 1.15f + Mathf.Sin(num8) * 0.15f; num5 = 0.32f - Mathf.Cos(num8) * 0.15f; num6 = 180f + num8 * 57.29578f; } slats[i].localPosition = new Vector3(0f, num5, num4); slats[i].localRotation = Quaternion.AngleAxis(0f - num6, Vector3.right); } } private static void EnsureMeshes() { //IL_002d: 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_0139: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0167: 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_0195: 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_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: 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_0079: 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_00b2: 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_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)frameMesh)) { return; } Geometry geometry = new Geometry(); for (int i = -1; i <= 1; i += 2) { geometry.Box(new Vector3((float)i * 0.83f, 0.4f, 0f), new Vector3(0.18f, 0.26f, 2.95f)); for (int j = -1; j <= 1; j += 2) { geometry.Box(new Vector3((float)i * 0.83f, 0.13f, (float)j * 1.08f), new Vector3(0.26f, 0.26f, 0.42f)); } geometry.Box(new Vector3((float)i * 0.83f, 1.08f, 0.95f), new Vector3(0.14f, 1.4f, 0.14f)); geometry.Box(new Vector3((float)i * 0.83f, 1.56f, 0.2f), new Vector3(0.12f, 0.12f, 1.65f)); geometry.Box(new Vector3((float)i * 0.83f, 1.01f, -0.56f), new Vector3(0.1f, 1.1f, 0.1f)); } geometry.Box(new Vector3(0f, 1.76f, 0.95f), new Vector3(1.8f, 0.14f, 0.14f)); geometry.Box(new Vector3(0f, 0.2f, -1.05f), new Vector3(1.7f, 0.14f, 0.18f)); geometry.Box(new Vector3(0f, 0.2f, 1.05f), new Vector3(1.7f, 0.14f, 0.18f)); frameMesh = geometry.Finish("FitnessOriginalWoodFrame"); Geometry geometry2 = new Geometry(); geometry2.Box(Vector3.zero, new Vector3(1.42f, 0.055f, 0.115f)); geometry2.MapBoxUV(new Rect(9f / 32f, 0.1875f, 0.4375f, 0.5f)); slatMesh = geometry2.Finish("FitnessOriginalBeltSlat"); Geometry geometry3 = new Geometry(); geometry3.CylinderX(1.55f, 0.15f, 16); rollerMesh = geometry3.Finish("FitnessOriginalWoodRoller"); } internal static void Shutdown() { releaseRequested = true; ReleaseUnusedMeshes(); } private void OnDestroy() { if (counted) { counted = false; liveVisuals--; } ReleaseUnusedMeshes(); } private static void ReleaseUnusedMeshes() { if (releaseRequested && liveVisuals == 0) { if (Object.op_Implicit((Object)(object)frameMesh)) { Object.Destroy((Object)(object)frameMesh); } if (Object.op_Implicit((Object)(object)slatMesh)) { Object.Destroy((Object)(object)slatMesh); } if (Object.op_Implicit((Object)(object)rollerMesh)) { Object.Destroy((Object)(object)rollerMesh); } frameMesh = (slatMesh = (rollerMesh = null)); } } } }