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 Rideable Boars v1.0.2
BepInEx/plugins/RideableBoars.dll
Decompiled 6 days agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("1.0.2.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 BoarRiding { [BepInPlugin("valheim.boarriding", "Rideable Boars", "1.0.2")] public sealed class BoarRidingPlugin : BaseUnityPlugin { public const string PluginGuid = "valheim.boarriding"; public const string PluginName = "Rideable Boars"; public const string PluginVersion = "1.0.2"; internal static bool HeadlessServer; internal const string ItemPrefabName = "BoarSaddle"; internal static BoarRidingPlugin Instance; internal static GameObject SaddleItemPrefab; internal static Recipe SaddleRecipe; internal static AssetBundle SaddleAssetBundle; internal static readonly GameObject[] CustomSaddleVisuals = (GameObject[])(object)new GameObject[3]; private static readonly HashSet<int> WildBarebackRides = new HashSet<int>(); internal ConfigEntry<float> OneStarSpeed; internal ConfigEntry<float> TwoStarSpeed; internal ConfigEntry<float> SaddleX; internal ConfigEntry<float> SaddleY; internal ConfigEntry<float> SaddleZ; internal ConfigEntry<float> SaddleScale; internal ConfigEntry<float> RiderX; internal ConfigEntry<float> RiderY; internal ConfigEntry<float> RiderZ; internal ConfigEntry<float> RiderForwardCorrection; internal ConfigEntry<float> RiderExtraForwardOffset; internal ConfigEntry<float> NormalBoarSaddleYOffset; internal ConfigEntry<float> NormalBoarSaddleScale; internal ConfigEntry<float> CustomSaddleSizeMultiplier; internal ConfigEntry<float> CustomSaddleZ; internal ConfigEntry<float> CustomSaddleYNoStars; internal ConfigEntry<float> CustomSaddleYOneStar; internal ConfigEntry<float> CustomSaddleYTwoStars; internal ConfigEntry<float> CustomSaddlePitchOneStar; internal ConfigEntry<bool> AllowMountedPortalTravel; private Harmony _harmony; internal static void RegisterLocalization() { if (Localization.instance != null) { string selectedLanguage = Localization.instance.GetSelectedLanguage(); bool flag = string.Equals(selectedLanguage, "Russian", StringComparison.OrdinalIgnoreCase) || string.Equals(selectedLanguage, "Русский", StringComparison.OrdinalIgnoreCase); bool flag2 = string.Equals(selectedLanguage, "German", StringComparison.OrdinalIgnoreCase) || string.Equals(selectedLanguage, "Deutsch", StringComparison.OrdinalIgnoreCase); AddLocalizedWord("boarriding_saddle_name", flag ? "Седло для кабана" : (flag2 ? "Wildschweinsattel" : "Boar Saddle")); AddLocalizedWord("boarriding_saddle_description", flag ? "Прочное седло для верховой езды на приручённых кабанах." : (flag2 ? "Ein robuster Sattel zum Reiten gezähmter Wildschweine." : "A sturdy saddle for riding tamed boars.")); AddLocalizedWord("boarriding_ride_bareback", flag ? "Ехать без седла" : (flag2 ? "Ohne Sattel reiten" : "Ride bareback")); } } private static void AddLocalizedWord(string key, string text) { AccessTools.Method(typeof(Localization), "AddWord", (Type[])null, (Type[])null).Invoke(Localization.instance, new object[2] { key, text }); } private void Awake() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 //IL_059f: Unknown result type (might be due to invalid IL or missing references) //IL_05a9: Expected O, but got Unknown Instance = this; HeadlessServer = (int)SystemInfo.graphicsDeviceType == 4; LoadCustomSaddleAssets(); OneStarSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Speed", "One Star", 1.2f, "Speed multiplier for a one-star boar."); TwoStarSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Speed", "Two Stars", 1.4f, "Speed multiplier for a two-star boar."); SaddleX = ((BaseUnityPlugin)this).Config.Bind<float>("Saddle Position", "X", 0f, "Horizontal saddle position."); SaddleY = ((BaseUnityPlugin)this).Config.Bind<float>("Saddle Position", "Y", 1.02f, "Saddle height."); SaddleZ = ((BaseUnityPlugin)this).Config.Bind<float>("Saddle Position", "Z", 0.35f, "Forward/backward saddle position."); SaddleScale = ((BaseUnityPlugin)this).Config.Bind<float>("Saddle Position", "Scale", 0.36f, "Scale of the visible saddle."); RiderX = ((BaseUnityPlugin)this).Config.Bind<float>("Rider Position", "X", 0f, "Horizontal rider position."); RiderY = ((BaseUnityPlugin)this).Config.Bind<float>("Rider Position", "Y", 0.25f, "Rider height relative to the saddle."); RiderZ = ((BaseUnityPlugin)this).Config.Bind<float>("Rider Position", "Z", 0.25f, "Forward/backward rider position."); RiderForwardCorrection = ((BaseUnityPlugin)this).Config.Bind<float>("Rider Position", "Custom Saddle Forward Correction", 0.32f, "Moves the rider toward the boar's head so the character sits in the custom saddle centre."); RiderExtraForwardOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Rider Position", "Extra Forward Offset", 0.12f, "Additional forward rider offset for all star levels, with or without a saddle. Does not move the saddle or interaction area."); NormalBoarSaddleYOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Saddle Position", "No-Star Boar Height Offset", -0.16f, "Additional height correction for no-star boars only."); NormalBoarSaddleScale = ((BaseUnityPlugin)this).Config.Bind<float>("Saddle Position", "No-Star Boar Scale", 0.84f, "Additional scale multiplier for no-star boars only."); CustomSaddleSizeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Saddle Position", "Custom Model Scale", 0.68f, "Shared size multiplier for the custom saddle models."); CustomSaddleZ = ((BaseUnityPlugin)this).Config.Bind<float>("Custom Saddle Fit", "Back Position", -0.05f, "Forward/backward position of the custom saddle models."); CustomSaddleYNoStars = ((BaseUnityPlugin)this).Config.Bind<float>("Custom Saddle Fit", "No-Star Height", 0.95f, "Back height of the custom saddle on a no-star boar."); CustomSaddleYOneStar = ((BaseUnityPlugin)this).Config.Bind<float>("Custom Saddle Fit", "One-Star Height", 1.015f, "Back height of the custom saddle on a one-star boar."); CustomSaddleYTwoStars = ((BaseUnityPlugin)this).Config.Bind<float>("Custom Saddle Fit", "Two-Star Height", 1.11f, "Back height of the custom saddle on a two-star boar."); CustomSaddlePitchOneStar = ((BaseUnityPlugin)this).Config.Bind<float>("Custom Saddle Fit", "One-Star Back Pitch", 0.75f, "Tilts the one-star saddle to follow the rising shoulder line without clipping through the back."); AllowMountedPortalTravel = ((BaseUnityPlugin)this).Config.Bind<bool>("Portal Travel", "Allow Mounted Boars", true, "Allows a player who is riding a boar to take the boar through a portal."); if (Mathf.Approximately(SaddleY.Value, 0.68f) && Mathf.Approximately(SaddleZ.Value, -0.08f) && Mathf.Approximately(SaddleScale.Value, 0.55f)) { SaddleY.Value = 0.9f; SaddleZ.Value = 0.1f; SaddleScale.Value = 0.42f; ((BaseUnityPlugin)this).Config.Save(); } if (Mathf.Approximately(SaddleY.Value, 0.9f) && Mathf.Approximately(SaddleZ.Value, 0.1f) && Mathf.Approximately(SaddleScale.Value, 0.42f)) { SaddleY.Value = 0.84f; SaddleZ.Value = -0.35f; SaddleScale.Value = 0.32f; ((BaseUnityPlugin)this).Config.Save(); } if (Mathf.Approximately(SaddleY.Value, 0.84f) && Mathf.Approximately(SaddleZ.Value, -0.35f) && Mathf.Approximately(SaddleScale.Value, 0.32f)) { SaddleY.Value = 1.02f; SaddleZ.Value = 0.35f; SaddleScale.Value = 0.36f; if (Mathf.Approximately(RiderZ.Value, 0f)) { RiderZ.Value = 0.25f; } ((BaseUnityPlugin)this).Config.Save(); } if (Mathf.Approximately(CustomSaddleYNoStars.Value, 0.9f)) { CustomSaddleYNoStars.Value = 0.95f; ((BaseUnityPlugin)this).Config.Save(); } if (Mathf.Approximately(CustomSaddleYOneStar.Value, 1f) || Mathf.Approximately(CustomSaddleYOneStar.Value, 1.03f)) { CustomSaddleYOneStar.Value = 1.015f; ((BaseUnityPlugin)this).Config.Save(); } if (Mathf.Approximately(CustomSaddlePitchOneStar.Value, -3f) || Mathf.Approximately(CustomSaddlePitchOneStar.Value, -0.5f)) { CustomSaddlePitchOneStar.Value = 0.75f; ((BaseUnityPlugin)this).Config.Save(); } if (Mathf.Approximately(RiderForwardCorrection.Value, 0.22f)) { RiderForwardCorrection.Value = 0.32f; ((BaseUnityPlugin)this).Config.Save(); } _harmony = new Harmony("valheim.boarriding"); _harmony.PatchAll(typeof(BoarRidingPlugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Rideable Boars 1.0.2 loaded for Valheim 1.0."); } private void OnDestroy() { if (_harmony != null) { _harmony.UnpatchSelf(); } if ((Object)(object)SaddleAssetBundle != (Object)null) { SaddleAssetBundle.Unload(false); } } private void LoadCustomSaddleAssets() { if (HeadlessServer) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Headless server: skipping saddle graphics; riding and saddle registration remain enabled."); return; } try { string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "RideableBoars", "rideableboars_saddles"); if (!File.Exists(text)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Custom saddle AssetBundle was not found: " + text)); return; } SaddleAssetBundle = AssetBundle.LoadFromFile(text); if ((Object)(object)SaddleAssetBundle == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"Custom saddle AssetBundle could not be loaded."); return; } GameObject[] array = SaddleAssetBundle.LoadAllAssets<GameObject>(); foreach (GameObject val in array) { if (((Object)val).name == "BoarSaddle_NoStars") { CustomSaddleVisuals[0] = val; } else if (((Object)val).name == "BoarSaddle_OneStar") { CustomSaddleVisuals[1] = val; } else if (((Object)val).name == "BoarSaddle_TwoStars") { CustomSaddleVisuals[2] = val; } } int num = 0; array = CustomSaddleVisuals; for (int i = 0; i < array.Length; i++) { if (Object.op_Implicit((Object)(object)array[i])) { num++; } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("Loaded custom boar saddle models: " + num + "/3.")); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Custom saddle assets failed to load: " + ex)); } } internal static void LogInfo(string message) { if (!message.StartsWith("Boar Saddle visible:") && !message.StartsWith("Selected custom saddle model") && !message.StartsWith("Boar saddle animation anchor:") && !message.StartsWith("BOAR_MEASURE ")) { ((BaseUnityPlugin)Instance).Logger.LogInfo((object)message); } } internal static void LogError(string message) { ((BaseUnityPlugin)Instance).Logger.LogError((object)message); } internal static bool StartBarebackRide(Tameable tameable, Humanoid user) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //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) Player val = (Player)(object)((user is Player) ? user : null); if (!Object.op_Implicit((Object)(object)tameable) || !Object.op_Implicit((Object)(object)tameable.m_saddle) || !Object.op_Implicit((Object)(object)val)) { return false; } ZNetView val2 = (ZNetView)AccessTools.Field(typeof(Sadle), "m_nview").GetValue(tameable.m_saddle); if (!Object.op_Implicit((Object)(object)val2) || !val2.IsValid()) { return false; } ZDOID zDOID = ((Character)val).GetZDOID(); long userID = ((ZDOID)(ref zDOID)).UserID; val2.InvokeRPC("RequestControl", new object[1] { userID }); if (!tameable.IsTamed()) { ((MonoBehaviour)Instance).StartCoroutine(BuckOffWildBoar(tameable.m_saddle, val, userID)); } return true; } private static IEnumerator BuckOffWildBoar(Sadle saddle, Player player, long userId) { int id = ((Object)saddle).GetInstanceID(); if (!WildBarebackRides.Add(id)) { yield break; } yield return (object)new WaitForSeconds(10f); if (Object.op_Implicit((Object)(object)saddle)) { ZNetView val = (ZNetView)AccessTools.Field(typeof(Sadle), "m_nview").GetValue(saddle); if (Object.op_Implicit((Object)(object)val) && val.IsValid()) { val.InvokeRPC("ReleaseControl", new object[1] { userId }); } } if (Object.op_Implicit((Object)(object)player) && (Object)/*isinst with value type is only supported in some contexts*/ == (Object)(object)saddle) { player.StopDoodadControl(); if (((Character)player).IsAttached()) { ((Character)player).AttachStop(); } } WildBarebackRides.Remove(id); LogInfo("The wild boar threw off its rider after 10 seconds."); } internal static void RegisterNetworkAndBoar(ZNetScene scene) { try { GameObject prefab = scene.GetPrefab("SaddleLox"); GameObject prefab2 = scene.GetPrefab("Boar"); GameObject prefab3 = scene.GetPrefab("Lox"); if (!Object.op_Implicit((Object)(object)prefab) || !Object.op_Implicit((Object)(object)prefab2) || !Object.op_Implicit((Object)(object)prefab3)) { ((BaseUnityPlugin)Instance).Logger.LogError((object)"Boar, Lox, or SaddleLox was not found."); return; } if (!Object.op_Implicit((Object)(object)SaddleItemPrefab)) { bool activeSelf = prefab.activeSelf; prefab.SetActive(false); SaddleItemPrefab = Object.Instantiate<GameObject>(prefab); prefab.SetActive(activeSelf); ((Object)SaddleItemPrefab).name = "BoarSaddle"; Object.DontDestroyOnLoad((Object)(object)SaddleItemPrefab); ItemDrop component = SaddleItemPrefab.GetComponent<ItemDrop>(); component.m_itemData.m_shared.m_name = "$boarriding_saddle_name"; component.m_itemData.m_shared.m_description = "$boarriding_saddle_description"; } if (!scene.m_prefabs.Contains(SaddleItemPrefab)) { scene.m_prefabs.Add(SaddleItemPrefab); } ((Dictionary<int, GameObject>)AccessTools.Field(typeof(ZNetScene), "m_namedPrefabs").GetValue(scene))[StringExtensionMethods.GetStableHashCode("BoarSaddle")] = SaddleItemPrefab; ConfigureBoarPrefab(prefab2, prefab3); } catch (Exception ex) { ((BaseUnityPlugin)Instance).Logger.LogError((object)("Registration failed: " + ex)); } } private static void ConfigureBoarPrefab(GameObject boar, GameObject lox) { //IL_00e9: 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_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Expected O, but got Unknown //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) Tameable component = boar.GetComponent<Tameable>(); Tameable component2 = lox.GetComponent<Tameable>(); if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component2) || !Object.op_Implicit((Object)(object)component2.m_saddle)) { ((BaseUnityPlugin)Instance).Logger.LogError((object)"Saddle components are missing from the Boar or Lox prefab."); return; } Transform val = boar.transform.Find("BoarSaddleMount"); Sadle component3; if (Object.op_Implicit((Object)(object)val)) { component3 = ((Component)val).GetComponent<Sadle>(); } else { GameObject gameObject = ((Component)component2.m_saddle).gameObject; bool activeSelf = gameObject.activeSelf; gameObject.SetActive(false); GameObject val2 = Object.Instantiate<GameObject>(gameObject); gameObject.SetActive(activeSelf); val2.transform.SetParent(boar.transform, false); ((Object)val2).name = "BoarSaddleMount"; val2.SetActive(false); val2.transform.localPosition = new Vector3(Instance.SaddleX.Value, Instance.SaddleY.Value, Instance.SaddleZ.Value); val2.transform.localRotation = Quaternion.identity; val2.transform.localScale = Vector3.one * Instance.SaddleScale.Value; component3 = val2.GetComponent<Sadle>(); if (Object.op_Implicit((Object)(object)component3)) { GameObject val3 = new GameObject("BoarRiderAttachPoint"); val3.transform.SetParent(boar.transform, false); val3.transform.localPosition = new Vector3(Instance.RiderX.Value, 0.7f + Instance.RiderY.Value, Instance.RiderZ.Value); val3.transform.localRotation = Quaternion.identity; component3.m_attachPoint = val3.transform; component3.m_detachOffset = new Vector3(1.5f, 0.5f, 0f); component3.m_hoverText = "$boarriding_saddle_name"; } AddVisibleSaddleModel(val2); ConfigureSaddleInteractionCollider(val2); } if (!Object.op_Implicit((Object)(object)component3)) { ((BaseUnityPlugin)Instance).Logger.LogError((object)"The copied Lox saddle has no saddle component."); return; } component3.m_maxUseRange = 10f; component.m_saddle = component3; component.m_saddleItem = SaddleItemPrefab.GetComponent<ItemDrop>(); component.m_dropSaddleOnDeath = true; ConfigureBarebackInteraction(boar, ((Component)component3).gameObject); if (!Object.op_Implicit((Object)(object)boar.GetComponent<BoarStarSpeed>())) { boar.AddComponent<BoarStarSpeed>(); } ((BaseUnityPlugin)Instance).Logger.LogInfo((object)"Boars can now be ridden."); } private static void ConfigureBarebackInteraction(GameObject boar, GameObject mount) { //IL_001e: 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_0054: 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_00a0: 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) Transform val = mount.transform.Find("BoarBarebackInteraction"); GameObject val2 = (GameObject)(Object.op_Implicit((Object)(object)val) ? ((object)((Component)val).gameObject) : ((object)new GameObject("BoarBarebackInteraction"))); val2.transform.SetParent(mount.transform, false); val2.transform.localPosition = Vector3.zero; val2.transform.localRotation = Quaternion.identity; val2.transform.localScale = Vector3.one; val2.layer = boar.layer; BoxCollider val3 = val2.GetComponent<BoxCollider>(); if (!Object.op_Implicit((Object)(object)val3)) { val3 = val2.AddComponent<BoxCollider>(); } val3.center = new Vector3(0f, 0.56f, 0.04f); val3.size = new Vector3(2.8f, 1.16f, 1.52f); ((Collider)val3).isTrigger = true; if (!Object.op_Implicit((Object)(object)val2.GetComponent<BoarBarebackInteraction>())) { val2.AddComponent<BoarBarebackInteraction>(); } } private static void ConfigureSaddleInteractionCollider(GameObject mount) { //IL_0045: 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) Collider[] componentsInChildren = mount.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } BoxCollider val = mount.GetComponent<BoxCollider>(); if (!Object.op_Implicit((Object)(object)val)) { val = mount.AddComponent<BoxCollider>(); } val.center = new Vector3(0f, 0.78f, 0.02f); val.size = new Vector3(2.35f, 0.78f, 1.52f); ((Collider)val).isTrigger = true; ((Collider)val).enabled = false; } private static void AddVisibleSaddleModel(GameObject mount) { //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0225: 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_00fe: 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_0131: 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) if (HeadlessServer || !Object.op_Implicit((Object)(object)SaddleItemPrefab) || Object.op_Implicit((Object)(object)mount.transform.Find("BoarSaddleVisual"))) { return; } bool flag = true; GameObject[] customSaddleVisuals = CustomSaddleVisuals; for (int i = 0; i < customSaddleVisuals.Length; i++) { if (!Object.op_Implicit((Object)(object)customSaddleVisuals[i])) { flag = false; } } if (flag) { float num = Mathf.Max(0.001f, Instance.SaddleScale.Value); float num2 = Mathf.Max(0.001f, Instance.NormalBoarSaddleScale.Value); float num3 = Mathf.Clamp(Instance.CustomSaddleSizeMultiplier.Value, 0.3f, 1.5f); for (int j = 0; j < CustomSaddleVisuals.Length; j++) { GameObject obj = Object.Instantiate<GameObject>(CustomSaddleVisuals[j]); ((Object)obj).name = "BoarSaddleVisual_Custom_" + j; obj.transform.SetParent(mount.transform, false); obj.transform.localPosition = Vector3.zero; obj.transform.localRotation = Quaternion.identity; float num4 = ((j == 0) ? num2 : 1f); obj.transform.localScale = CustomSaddleVisuals[j].transform.localScale * num3 / (num * num4); obj.SetActive(j == 0); } ((BaseUnityPlugin)Instance).Logger.LogInfo((object)"Added three custom star-sized Boar Saddle models."); return; } GameObject val = Object.Instantiate<GameObject>(SaddleItemPrefab); ((Object)val).name = "BoarSaddleVisual"; val.SetActive(false); Component[] componentsInChildren = val.GetComponentsInChildren<Component>(true); foreach (Component val2 in componentsInChildren) { if (Object.op_Implicit((Object)(object)val2) && !(val2 is Transform) && !(val2 is MeshFilter) && !(val2 is Renderer)) { Object.DestroyImmediate((Object)(object)val2); } } val.transform.SetParent(mount.transform, false); val.transform.localPosition = Vector3.zero; val.transform.localRotation = Quaternion.Euler(0f, 90f, 0f); val.transform.localScale = Vector3.one; val.SetActive(true); ((BaseUnityPlugin)Instance).Logger.LogInfo((object)("Added visible Boar Saddle model (renderers: " + val.GetComponentsInChildren<Renderer>(true).Length + ").")); } internal static void RegisterItemAndRecipe(ObjectDB db) { try { if (Object.op_Implicit((Object)(object)SaddleItemPrefab) && !((Object)(object)db == (Object)null) && db.m_items.Count != 0) { if (!db.m_items.Contains(SaddleItemPrefab)) { db.m_items.Add(SaddleItemPrefab); } if (!Object.op_Implicit((Object)(object)SaddleRecipe)) { GameObject prefab = ZNetScene.instance.GetPrefab("piece_workbench"); SaddleRecipe = ScriptableObject.CreateInstance<Recipe>(); ((Object)SaddleRecipe).name = "Recipe_BoarSaddle"; SaddleRecipe.m_item = SaddleItemPrefab.GetComponent<ItemDrop>(); SaddleRecipe.m_amount = 1; SaddleRecipe.m_enabled = true; SaddleRecipe.m_craftingStation = prefab.GetComponent<CraftingStation>(); SaddleRecipe.m_minStationLevel = 2; SaddleRecipe.m_resources = (Requirement[])(object)new Requirement[3] { Requirement(db, "LeatherScraps", 5), Requirement(db, "DeerHide", 2), Requirement(db, "BronzeNails", 4) }; } if (!db.m_recipes.Contains(SaddleRecipe)) { db.m_recipes.Add(SaddleRecipe); } AccessTools.Method(typeof(ObjectDB), "UpdateRegisters", (Type[])null, (Type[])null).Invoke(db, null); } } catch (Exception ex) { ((BaseUnityPlugin)Instance).Logger.LogError((object)("Item or recipe could not be registered: " + ex)); } } private static Requirement Requirement(ObjectDB db, string prefabName, int amount) { //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_002d: 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_003c: Expected O, but got Unknown GameObject val = db.GetItemPrefab(prefabName); if (!Object.op_Implicit((Object)(object)val)) { val = ZNetScene.instance.GetPrefab(prefabName); } return new Requirement { m_resItem = val.GetComponent<ItemDrop>(), m_amount = amount, m_recover = true }; } } public sealed class BoarStarSpeed : MonoBehaviour { private static readonly HashSet<int> LoggedMeasurementLevels = new HashSet<int>(); private Character _character; private float _walk; private float _speed; private float _run; private float _swim; private Transform _saddleMount; private Transform _seat; private Vector3 _mountBasePosition; private Vector3 _mountBaseScale; private Vector3 _seatBasePosition; private Quaternion _mountBaseRotation; private Quaternion _seatBaseRotation; private Quaternion _targetMountLocalRotation; private Quaternion _targetSeatLocalRotation; private Vector3 _targetMountLocalPosition; private Vector3 _targetSeatLocalPosition; private bool _mountCached; private Transform _animationBone; private Vector3 _animationRestBoneLocalPosition; private Quaternion _animationRestBoneLocalRotation; private bool _animationAnchorReady; private int _animationAnchorFrames; private int _pendingMeasurementLevel = -1; private int _measurementFrames; private int _activeVisualIndex = -1; private void Awake() { _character = ((Component)this).GetComponent<Character>(); if (Object.op_Implicit((Object)(object)_character)) { _walk = _character.m_walkSpeed; _speed = _character.m_speed; _run = _character.m_runSpeed; _swim = _character.m_swimSpeed; } } private void FixedUpdate() { if (Object.op_Implicit((Object)(object)_character) && !((Object)(object)BoarRidingPlugin.Instance == (Object)null)) { int level = _character.GetLevel(); float num = ((level >= 3) ? BoarRidingPlugin.Instance.TwoStarSpeed.Value : ((level == 2) ? BoarRidingPlugin.Instance.OneStarSpeed.Value : 1f)); _character.m_walkSpeed = _walk * num; _character.m_speed = _speed * num; _character.m_runSpeed = _run * num; _character.m_swimSpeed = _swim * num; UpdateSaddleFit(level); UpdateCustomSaddleVisual(level); TryLogMeasurement(level); } } private void LateUpdate() { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_008f: 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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //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_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_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: 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_00d4: 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_00e9: 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_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0113: 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_0123: 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_0138: 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_013f: Unknown result type (might be due to invalid IL or missing references) if (_mountCached && Object.op_Implicit((Object)(object)_saddleMount) && Object.op_Implicit((Object)(object)_seat)) { TryInitializeAnimationAnchor(); if (!_animationAnchorReady || !Object.op_Implicit((Object)(object)_animationBone)) { _saddleMount.localPosition = _targetMountLocalPosition; _saddleMount.localRotation = _targetMountLocalRotation; _seat.localPosition = _targetSeatLocalPosition; _seat.localRotation = _targetSeatLocalRotation; } else { Vector3 val = ((Component)this).transform.InverseTransformPoint(_animationBone.position); Quaternion val2 = Quaternion.Inverse(((Component)this).transform.rotation) * _animationBone.rotation * Quaternion.Inverse(_animationRestBoneLocalRotation); _saddleMount.localPosition = val + val2 * (_targetMountLocalPosition - _animationRestBoneLocalPosition); _saddleMount.localRotation = val2 * _targetMountLocalRotation; _seat.localPosition = val + val2 * (_targetSeatLocalPosition - _animationRestBoneLocalPosition); _seat.localRotation = val2 * _targetSeatLocalRotation; } } } private void TryInitializeAnimationAnchor() { //IL_0181: 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_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: 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_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) if (_animationAnchorReady || ++_animationAnchorFrames < 30) { return; } Transform val = null; float num = float.MaxValue; SkinnedMeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<SkinnedMeshRenderer>(true); foreach (SkinnedMeshRenderer val2 in componentsInChildren) { if (!Object.op_Implicit((Object)(object)val2) || (Object.op_Implicit((Object)(object)_saddleMount) && ((Component)val2).transform.IsChildOf(_saddleMount))) { continue; } Transform[] bones = val2.bones; foreach (Transform val3 in bones) { if (!Object.op_Implicit((Object)(object)val3)) { continue; } string text = ((Object)val3).name.ToLowerInvariant(); float num2; if (text.Contains("spine")) { num2 = 0f; } else if (text.Contains("back")) { num2 = 0.1f; } else if (text.Contains("chest")) { num2 = 0.2f; } else if (text.Contains("body")) { num2 = 0.35f; } else { if (!text.Contains("hip")) { continue; } num2 = 0.5f; } float num3 = Vector3.Distance(((Component)this).transform.InverseTransformPoint(val3.position), _targetMountLocalPosition) + num2; if (!(num3 >= num)) { num = num3; val = val3; } } } if (!Object.op_Implicit((Object)(object)val)) { BoarRidingPlugin.LogError("No animated back bone was found; saddle will follow the boar root."); _animationAnchorReady = true; return; } _animationBone = val; _animationRestBoneLocalPosition = ((Component)this).transform.InverseTransformPoint(val.position); _animationRestBoneLocalRotation = Quaternion.Inverse(((Component)this).transform.rotation) * val.rotation; _animationAnchorReady = true; BoarRidingPlugin.LogInfo("Boar saddle animation anchor: " + ((Object)val).name); } private void TryLogMeasurement(int level) { //IL_0041: 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_00e9: 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_00ee: 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_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_0123: 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_0167: 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_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_019c: 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_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: 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_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) if (LoggedMeasurementLevels.Contains(level)) { return; } if (_pendingMeasurementLevel != level) { _pendingMeasurementLevel = level; _measurementFrames = 0; } else { if (++_measurementFrames < 20) { return; } Bounds val = default(Bounds); bool flag = false; Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { if (Object.op_Implicit((Object)(object)val2) && val2.enabled && ((Component)val2).gameObject.activeInHierarchy && (!Object.op_Implicit((Object)(object)_saddleMount) || !((Component)val2).transform.IsChildOf(_saddleMount))) { if (!flag) { val = val2.bounds; flag = true; } else { ((Bounds)(ref val)).Encapsulate(val2.bounds); } } } LevelEffects componentInChildren = ((Component)this).GetComponentInChildren<LevelEffects>(true); Vector3 value = (flag ? ((Component)this).transform.InverseTransformPoint(((Bounds)(ref val)).center) : Vector3.zero); float num = (flag ? ((Component)this).transform.InverseTransformPoint(new Vector3(((Bounds)(ref val)).center.x, ((Bounds)(ref val)).max.y, ((Bounds)(ref val)).center.z)).y : 0f); string message = string.Format(CultureInfo.InvariantCulture, "BOAR_MEASURE level={0} stars={1} rootLocalScale={2} rootLossyScale={3} levelVisualLocalScale={4} levelVisualLossyScale={5} boundsWorldSize={6} boundsCenterLocal={7} backTopLocalY={8:0.000} saddleLocalPosition={9} saddleLocalScale={10} seatLocalPosition={11}", level, Mathf.Max(0, level - 1), FormatVector(((Component)this).transform.localScale), FormatVector(((Component)this).transform.lossyScale), FormatVector(Object.op_Implicit((Object)(object)componentInChildren) ? ((Component)componentInChildren).transform.localScale : Vector3.one), FormatVector(Object.op_Implicit((Object)(object)componentInChildren) ? ((Component)componentInChildren).transform.lossyScale : Vector3.one), FormatVector(flag ? ((Bounds)(ref val)).size : Vector3.zero), FormatVector(value), num, FormatVector(Object.op_Implicit((Object)(object)_saddleMount) ? _saddleMount.localPosition : Vector3.zero), FormatVector(Object.op_Implicit((Object)(object)_saddleMount) ? _saddleMount.localScale : Vector3.zero), FormatVector(Object.op_Implicit((Object)(object)_seat) ? _seat.localPosition : Vector3.zero)); LoggedMeasurementLevels.Add(level); BoarRidingPlugin.LogInfo(message); } } private static string FormatVector(Vector3 value) { //IL_000a: 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_0020: Unknown result type (might be due to invalid IL or missing references) return string.Format(CultureInfo.InvariantCulture, "({0:0.000},{1:0.000},{2:0.000})", value.x, value.y, value.z); } private void UpdateSaddleFit(int level) { //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_006a: 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_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_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) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_030e: 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_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: 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_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0212: 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_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) if (!_mountCached) { _saddleMount = ((Component)this).transform.Find("BoarSaddleMount"); _seat = ((Component)this).transform.Find("BoarRiderAttachPoint"); if (!Object.op_Implicit((Object)(object)_saddleMount) || !Object.op_Implicit((Object)(object)_seat)) { return; } _mountBasePosition = _saddleMount.localPosition; _mountBaseScale = _saddleMount.localScale; _seatBasePosition = _seat.localPosition; _mountBaseRotation = _saddleMount.localRotation; _seatBaseRotation = _seat.localRotation; _targetMountLocalPosition = _mountBasePosition; _targetSeatLocalPosition = _seatBasePosition; _targetMountLocalRotation = _mountBaseRotation; _targetSeatLocalRotation = _seatBaseRotation; _mountCached = true; } bool flag = level <= 1; float num = (flag ? BoarRidingPlugin.Instance.NormalBoarSaddleScale.Value : 1f); if (BoarRidingPlugin.HeadlessServer || (Object.op_Implicit((Object)(object)BoarRidingPlugin.CustomSaddleVisuals[0]) && Object.op_Implicit((Object)(object)BoarRidingPlugin.CustomSaddleVisuals[1]) && Object.op_Implicit((Object)(object)BoarRidingPlugin.CustomSaddleVisuals[2]))) { float num2 = ((level >= 3) ? BoarRidingPlugin.Instance.CustomSaddleYTwoStars.Value : ((level == 2) ? BoarRidingPlugin.Instance.CustomSaddleYOneStar.Value : BoarRidingPlugin.Instance.CustomSaddleYNoStars.Value)); Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(_mountBasePosition.x, num2, BoarRidingPlugin.Instance.CustomSaddleZ.Value); Vector3 val2 = val - _mountBasePosition; _targetMountLocalPosition = val; float num3 = ((level == 2) ? BoarRidingPlugin.Instance.CustomSaddlePitchOneStar.Value : 0f); _targetMountLocalRotation = _mountBaseRotation * Quaternion.Euler(num3, 0f, 0f); _saddleMount.localScale = _mountBaseScale * num; UpdateInteractionColliderScale(num); _targetSeatLocalPosition = _seatBasePosition + val2 + Vector3.forward * (BoarRidingPlugin.Instance.RiderForwardCorrection.Value + BoarRidingPlugin.Instance.RiderExtraForwardOffset.Value); _targetSeatLocalRotation = _seatBaseRotation * Quaternion.Euler(num3, 0f, 0f); } else { float num4 = (flag ? BoarRidingPlugin.Instance.NormalBoarSaddleYOffset.Value : 0f); _targetMountLocalPosition = _mountBasePosition + Vector3.up * num4; _targetMountLocalRotation = _mountBaseRotation; _saddleMount.localScale = _mountBaseScale * num; UpdateInteractionColliderScale(num); _targetSeatLocalPosition = _seatBasePosition + Vector3.up * num4 + Vector3.forward * BoarRidingPlugin.Instance.RiderExtraForwardOffset.Value; _targetSeatLocalRotation = _seatBaseRotation; } } private void UpdateInteractionColliderScale(float mountFitScale) { //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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: 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_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) float num = 1f / Mathf.Max(0.001f, mountFitScale); BoxCollider component = ((Component)_saddleMount).GetComponent<BoxCollider>(); if (Object.op_Implicit((Object)(object)component)) { component.center = new Vector3(0f, 0.78f, 0.02f) * num; component.size = new Vector3(2.35f, 0.78f, 1.52f) * num; } Transform val = _saddleMount.Find("BoarBarebackInteraction"); BoxCollider val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<BoxCollider>() : null); if (Object.op_Implicit((Object)(object)val2)) { val2.center = new Vector3(0f, 0.56f, 0.04f) * num; val2.size = new Vector3(2.8f, 1.16f, 1.52f) * num; } } private void UpdateCustomSaddleVisual(int level) { if (BoarRidingPlugin.HeadlessServer || !Object.op_Implicit((Object)(object)_saddleMount)) { return; } int num = ((level >= 3) ? 2 : ((level == 2) ? 1 : 0)); if (_activeVisualIndex == num) { return; } for (int i = 0; i < 3; i++) { Transform val = _saddleMount.Find("BoarSaddleVisual_Custom_" + i); if (Object.op_Implicit((Object)(object)val)) { ((Component)val).gameObject.SetActive(i == num); } } _activeVisualIndex = num; BoarRidingPlugin.LogInfo("Selected custom saddle model for " + Mathf.Max(0, level - 1) + " star(s)."); } } public sealed class BoarBarebackInteraction : MonoBehaviour, Hoverable, Interactable { private static readonly MethodInfo HaveSaddleMethod = AccessTools.Method(typeof(Tameable), "HaveSaddle", (Type[])null, (Type[])null); private Tameable _tameable; private Collider _collider; private void Awake() { _tameable = ((Component)this).GetComponentInParent<Tameable>(); _collider = ((Component)this).GetComponent<Collider>(); } private void LateUpdate() { if (Object.op_Implicit((Object)(object)_collider)) { _collider.enabled = Object.op_Implicit((Object)(object)_tameable) && !HasSaddle(); } } private bool HasSaddle() { if (Object.op_Implicit((Object)(object)_tameable) && Object.op_Implicit((Object)(object)_tameable.m_saddle)) { return (bool)HaveSaddleMethod.Invoke(_tameable, null); } return false; } public string GetHoverName() { if (!Object.op_Implicit((Object)(object)_tameable)) { return "Wildschwein"; } return _tameable.GetHoverName(); } public string GetHoverText() { if (!Object.op_Implicit((Object)(object)_tameable) || HasSaddle()) { return string.Empty; } return GetHoverName() + "\n[<color=yellow><b>E</b></color>] " + Localization.instance.Localize("$boarriding_ride_bareback"); } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold || !Object.op_Implicit((Object)(object)_tameable) || HasSaddle()) { return false; } return BoarRidingPlugin.StartBarebackRide(_tameable, user); } public bool UseItem(Humanoid user, ItemData item) { if (Object.op_Implicit((Object)(object)_tameable) && !HasSaddle()) { return _tameable.UseItem(user, item); } return false; } public float GetHoverOffset() { return 0f; } } [HarmonyPatch(typeof(ZNetScene), "Awake")] internal static class ZNetSceneAwakePatch { private static void Postfix(ZNetScene __instance) { BoarRidingPlugin.RegisterLocalization(); BoarRidingPlugin.RegisterNetworkAndBoar(__instance); } } [HarmonyPatch(typeof(ZNetScene), "CreateObject")] internal static class BoarSaddleNetworkCreatePatch { private static bool Prefix(ZNetScene __instance, ZDO zdo, ref GameObject __result) { //IL_0047: 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) if ((Object)(object)__instance == (Object)null || zdo == null || zdo.GetPrefab() != StringExtensionMethods.GetStableHashCode("BoarSaddle")) { return true; } GameObject prefab = __instance.GetPrefab(zdo.GetPrefab()); if (!Object.op_Implicit((Object)(object)prefab)) { return true; } try { ZNetView.m_useInitZDO = true; ZNetView.m_initZDO = zdo; __result = Object.Instantiate<GameObject>(prefab, zdo.GetPosition(), zdo.GetRotation()); if (Object.op_Implicit((Object)(object)__result) && !__result.activeSelf) { __result.SetActive(true); } if (ZNetView.m_initZDO != null) { if (Object.op_Implicit((Object)(object)__result)) { Object.Destroy((Object)(object)__result); } __result = null; return true; } return false; } finally { ZNetView.m_initZDO = null; ZNetView.m_useInitZDO = false; } } } [HarmonyPatch(typeof(ObjectDB), "Awake")] internal static class ObjectDBAwakePatch { private static void Postfix(ObjectDB __instance) { BoarRidingPlugin.RegisterItemAndRecipe(__instance); } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] internal static class ObjectDBCopyPatch { private static void Postfix(ObjectDB __instance) { BoarRidingPlugin.RegisterItemAndRecipe(__instance); } } [HarmonyPatch(typeof(Tameable), "Awake")] internal static class BoarInstanceAwakePatch { private static void Prefix(Tameable __instance) { if ((Object)(object)__instance == (Object)null || !((Object)((Component)__instance).gameObject).name.StartsWith("Boar", StringComparison.OrdinalIgnoreCase)) { return; } Sadle[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Sadle>(true); if (componentsInChildren.Length == 0) { BoarRidingPlugin.LogError("Spawned boar has no saddle mount."); return; } __instance.m_saddle = componentsInChildren[0]; if (Object.op_Implicit((Object)(object)BoarRidingPlugin.SaddleItemPrefab)) { __instance.m_saddleItem = BoarRidingPlugin.SaddleItemPrefab.GetComponent<ItemDrop>(); } } } [HarmonyPatch(typeof(Tameable), "SetSaddle")] internal static class BoarSetSaddlePatch { private static void Postfix(Tameable __instance, bool enabled) { if ((Object)(object)__instance == (Object)null || !((Object)((Component)__instance).gameObject).name.StartsWith("Boar", StringComparison.OrdinalIgnoreCase)) { return; } Sadle[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Sadle>(true); if (componentsInChildren.Length == 0) { return; } __instance.m_saddle = componentsInChildren[0]; ((Component)componentsInChildren[0]).gameObject.SetActive(true); Renderer[] componentsInChildren2 = ((Component)componentsInChildren[0]).GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].enabled = enabled; } Collider[] componentsInChildren3 = ((Component)componentsInChildren[0]).GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { componentsInChildren3[i].enabled = enabled; } Transform val = ((Component)componentsInChildren[0]).transform.Find("BoarBarebackInteraction"); if (Object.op_Implicit((Object)(object)val)) { Collider component = ((Component)val).GetComponent<Collider>(); if (Object.op_Implicit((Object)(object)component)) { component.enabled = !enabled; } } BoarRidingPlugin.LogInfo("Boar Saddle visible: " + enabled); } } [HarmonyPatch(typeof(Sadle), "InUseDistance")] internal static class BoarSaddleDistancePatch { private static void Postfix(Sadle __instance, Humanoid human, ref bool __result) { //IL_0046: 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 (!__result && !((Object)(object)__instance == (Object)null) && !((Object)(object)human == (Object)null)) { Character componentInParent = ((Component)__instance).GetComponentInParent<Character>(); if (Object.op_Implicit((Object)(object)componentInParent) && ((Object)((Component)componentInParent).gameObject).name.StartsWith("Boar", StringComparison.OrdinalIgnoreCase)) { __result = Vector3.Distance(((Component)human).transform.position, ((Component)componentInParent).transform.position) <= 6f; } } } } [HarmonyPatch(typeof(Sadle), "ApplyControlls")] internal static class BoarHoldToMovePatch { private static void Prefix(Sadle __instance, Vector3 moveDir, bool run, bool autoRun, ref bool block) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)__instance == (Object)null)) { Character componentInParent = ((Component)__instance).GetComponentInParent<Character>(); if (Object.op_Implicit((Object)(object)componentInParent) && ((Object)((Component)componentInParent).gameObject).name.StartsWith("Boar", StringComparison.OrdinalIgnoreCase) && Mathf.Abs(moveDir.z) < 0.1f && !run && !autoRun) { block = true; } } } } [HarmonyPatch(typeof(Player), "SetControls")] internal static class BoarMountedJumpPatch { private static void Prefix(Player __instance, ref bool jump) { if (!jump || (Object)(object)__instance == (Object)null) { return; } IDoodadController doodadController = __instance.GetDoodadController(); Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); if (Object.op_Implicit((Object)(object)val)) { Character componentInParent = ((Component)val).GetComponentInParent<Character>(); if (Object.op_Implicit((Object)(object)componentInParent) && ((Object)((Component)componentInParent).gameObject).name.StartsWith("Boar", StringComparison.OrdinalIgnoreCase)) { float num = (float)AccessTools.Method(typeof(Sadle), "GetRiderSkill", (Type[])null, (Type[])null).Invoke(val, null); float jumpForce = componentInParent.m_jumpForce; componentInParent.m_jumpForce = jumpForce * Mathf.Lerp(0.75f, 1.25f, num); AccessTools.Method(typeof(Character), "Jump", (Type[])null, (Type[])null).Invoke(componentInParent, new object[1] { true }); componentInParent.m_jumpForce = jumpForce; jump = false; } } } } [HarmonyPatch(typeof(Player), "UpdateHover")] internal static class BoarMountedInteractionPatch { private static Player _suppressedPlayer; private static Sadle _suppressedSaddle; internal static Sadle GetSuppressedSaddle(Player player) { if (!((Object)(object)player == (Object)(object)_suppressedPlayer)) { return null; } return _suppressedSaddle; } private static void Prefix(Player __instance, ref IDoodadController __state) { __state = null; if ((Object)(object)__instance == (Object)null) { return; } IDoodadController doodadController = __instance.GetDoodadController(); Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); if (Object.op_Implicit((Object)(object)val)) { Character componentInParent = ((Component)val).GetComponentInParent<Character>(); if (Object.op_Implicit((Object)(object)componentInParent) && ((Object)((Component)componentInParent).gameObject).name.StartsWith("Boar", StringComparison.OrdinalIgnoreCase)) { __state = (IDoodadController)(object)val; _suppressedPlayer = __instance; _suppressedSaddle = val; AccessTools.Field(typeof(Player), "m_doodadController").SetValue(__instance, null); } } } private static void Postfix(Player __instance, IDoodadController __state) { if (__state != null && __instance.GetDoodadController() == null) { AccessTools.Field(typeof(Player), "m_doodadController").SetValue(__instance, __state); } if ((Object)(object)__instance == (Object)(object)_suppressedPlayer) { _suppressedPlayer = null; _suppressedSaddle = null; } } } internal sealed class MountedBoarPortalState { internal Player Player; internal Character Boar; internal Vector3 SourcePosition; internal Quaternion SourceRotation; internal Vector3 TargetPlayerPosition; internal Quaternion TargetRotation; internal Vector3 TargetBoarPosition; internal bool BoarMoved; internal Rigidbody Body; internal RigidbodyConstraints PreviousConstraints; internal bool MovementLocked; } [HarmonyPatch(typeof(Player), "TeleportTo")] internal static class MountedBoarPortalStartPatch { internal static MountedBoarPortalState Pending; private static void Postfix(Player __instance, Vector3 pos, Quaternion rot, bool distantTeleport, bool __result) { //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_0091: 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_009d: 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_00b2: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: 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_00f4: 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_00ff: Unknown result type (might be due to invalid IL or missing references) if (!__result || (Object)(object)__instance == (Object)null || (Object)(object)__instance != (Object)(object)Player.m_localPlayer || (Object)(object)BoarRidingPlugin.Instance == (Object)null || !BoarRidingPlugin.Instance.AllowMountedPortalTravel.Value) { return; } IDoodadController doodadController = __instance.GetDoodadController(); Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); if (!Object.op_Implicit((Object)(object)val)) { val = BoarMountedInteractionPatch.GetSuppressedSaddle(__instance); } if (Object.op_Implicit((Object)(object)val)) { Character componentInParent = ((Component)val).GetComponentInParent<Character>(); if (Object.op_Implicit((Object)(object)componentInParent) && ((Object)((Component)componentInParent).gameObject).name.StartsWith("Boar", StringComparison.OrdinalIgnoreCase)) { Quaternion rotation = ((Component)componentInParent).transform.rotation; Vector3 val2 = Quaternion.Inverse(rotation) * (((Component)__instance).transform.position - ((Component)componentInParent).transform.position); Pending = new MountedBoarPortalState { Player = __instance, Boar = componentInParent, SourcePosition = ((Component)componentInParent).transform.position, SourceRotation = rotation, TargetPlayerPosition = pos, TargetRotation = rot, TargetBoarPosition = pos - rot * val2, BoarMoved = false }; LockBoar(Pending); BoarRidingPlugin.LogInfo("Mounted boar portal travel prepared."); } } } internal static void LockBoar(MountedBoarPortalState state) { //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_0078: 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) if (state != null && Object.op_Implicit((Object)(object)state.Boar) && !state.MovementLocked) { ZNetView component = ((Component)state.Boar).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component) && component.IsValid() && !component.IsOwner()) { component.ClaimOwnership(); } state.Body = ((Component)state.Boar).GetComponent<Rigidbody>(); if (Object.op_Implicit((Object)(object)state.Body)) { state.PreviousConstraints = state.Body.constraints; state.Body.linearVelocity = Vector3.zero; state.Body.angularVelocity = Vector3.zero; state.Body.constraints = (RigidbodyConstraints)126; } state.MovementLocked = true; } } internal static void UnlockBoar(MountedBoarPortalState state) { //IL_001f: 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_0040: Unknown result type (might be due to invalid IL or missing references) if (state != null && state.MovementLocked) { if (Object.op_Implicit((Object)(object)state.Body)) { state.Body.linearVelocity = Vector3.zero; state.Body.angularVelocity = Vector3.zero; state.Body.constraints = state.PreviousConstraints; } state.MovementLocked = false; } } } [HarmonyPatch(typeof(Player), "UpdateTeleport")] internal static class MountedBoarPortalUpdatePatch { private static void Postfix(Player __instance) { //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_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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: 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) MountedBoarPortalState pending = MountedBoarPortalStartPatch.Pending; if (pending == null || (Object)(object)pending.Player != (Object)(object)__instance) { return; } if (!Object.op_Implicit((Object)(object)pending.Boar)) { MountedBoarPortalStartPatch.UnlockBoar(pending); MountedBoarPortalStartPatch.Pending = null; return; } if (!pending.BoarMoved && ((Character)__instance).IsTeleporting() && Vector3.Distance(((Component)__instance).transform.position, pending.TargetPlayerPosition) < 1.5f) { MoveBoar(pending.Boar, pending.TargetBoarPosition, pending.TargetRotation); pending.BoarMoved = true; BoarRidingPlugin.LogInfo("Mounted boar travelled through the portal."); } if (!((Character)__instance).IsTeleporting()) { if (pending.BoarMoved && Vector3.Distance(((Component)__instance).transform.position, pending.TargetPlayerPosition) >= 4f) { MoveBoar(pending.Boar, pending.SourcePosition, pending.SourceRotation); BoarRidingPlugin.LogInfo("Mounted boar portal travel was rolled back."); } MountedBoarPortalStartPatch.UnlockBoar(pending); MountedBoarPortalStartPatch.Pending = null; } } private static void MoveBoar(Character boar, Vector3 position, Quaternion rotation) { //IL_005e: 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_0035: 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_0043: 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_0080: 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) ZNetView component = ((Component)boar).GetComponent<ZNetView>(); if (Object.op_Implicit((Object)(object)component) && component.IsValid() && !component.IsOwner()) { component.ClaimOwnership(); } Rigidbody component2 = ((Component)boar).GetComponent<Rigidbody>(); if (Object.op_Implicit((Object)(object)component2)) { component2.position = position; component2.rotation = rotation; component2.linearVelocity = Vector3.zero; component2.angularVelocity = Vector3.zero; } ((Component)boar).transform.SetPositionAndRotation(position, rotation); if (Object.op_Implicit((Object)(object)component) && component.IsValid()) { ZDO zDO = component.GetZDO(); if (zDO != null) { zDO.SetPosition(position); zDO.SetRotation(rotation); } ZSyncTransform component3 = ((Component)boar).GetComponent<ZSyncTransform>(); if (Object.op_Implicit((Object)(object)component3)) { component3.SyncNow(); } } } } [HarmonyPatch(typeof(Tameable), "SpawnSaddle")] internal static class BoarSaddleDropPatch { private static bool Prefix(Tameable __instance, Vector3 flyDirection) { //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_0051: 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_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_00ac: 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_00a3: 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_00a5: 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) if ((Object)(object)__instance == (Object)null || !((Object)((Component)__instance).gameObject).name.StartsWith("Boar", StringComparison.OrdinalIgnoreCase) || !Object.op_Implicit((Object)(object)BoarRidingPlugin.SaddleItemPrefab)) { return true; } Vector3 position = ((Component)__instance).transform.TransformPoint(__instance.m_dropSaddleOffset); GameObject obj = Object.Instantiate<GameObject>(BoarRidingPlugin.SaddleItemPrefab); obj.transform.position = position; obj.transform.rotation = Quaternion.identity; obj.SetActive(true); Rigidbody component = obj.GetComponent<Rigidbody>(); if (Object.op_Implicit((Object)(object)component)) { Vector3 val = Vector3.up; if (((Vector3)(ref flyDirection)).magnitude > 0.1f) { flyDirection.y = 0f; ((Vector3)(ref flyDirection)).Normalize(); val += flyDirection; } component.AddForce(val * __instance.m_dropItemVel, (ForceMode)2); } BoarRidingPlugin.LogInfo("Removed Boar Saddle was dropped into the world."); return false; } } [HarmonyPatch(typeof(Terminal), "TryRunCommand")] internal static class BoarSaddleSpawnCommandPatch { private static bool Prefix(string text) { //IL_008e: 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_009e: 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_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_00b2: 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_00ca: 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_00ed: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrWhiteSpace(text)) { return true; } string[] array = text.Trim().Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length < 2 || !array[0].Equals("spawn", StringComparison.OrdinalIgnoreCase) || !array[1].Equals("BoarSaddle", StringComparison.OrdinalIgnoreCase)) { return true; } if (!Object.op_Implicit((Object)(object)BoarRidingPlugin.SaddleItemPrefab) || (Object)(object)Player.m_localPlayer == (Object)null) { return true; } int result = 1; if (array.Length >= 3) { int.TryParse(array[2], out result); } result = Mathf.Clamp(result, 1, 100); Transform transform = ((Component)Player.m_localPlayer).transform; Vector3 val = transform.position + transform.forward * 2f + Vector3.up; for (int i = 0; i < result; i++) { GameObject obj = Object.Instantiate<GameObject>(BoarRidingPlugin.SaddleItemPrefab); obj.transform.position = val + transform.right * ((float)i * 0.25f); obj.transform.rotation = Quaternion.identity; obj.SetActive(true); } if ((Object)(object)Console.instance != (Object)null) { Console.instance.Print("Spawned " + result + " BoarSaddle"); } return false; } } }