using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("BattleBoar")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("BattleBoar")] [assembly: AssemblyTitle("BattleBoar")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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 BattleBoar { public class BattleBoarController : MonoBehaviour { public enum BoarState { Following, Staying, Mounted } private Character character; private MonsterAI monsterAI; private Tameable tameable; private Sadle sadle; public BoarState CurrentState { get; private set; } = BoarState.Following; public Player Owner { get; private set; } public bool IsValid => (Object)(object)this != (Object)null && (Object)(object)((Component)this).gameObject != (Object)null && ((Component)this).gameObject.activeInHierarchy; private void Awake() { character = ((Component)this).GetComponent(); monsterAI = ((Component)this).GetComponent(); tameable = ((Component)this).GetComponent(); sadle = ((Component)this).GetComponentInChildren(); } public void Initialize(Player player) { Owner = player; CurrentState = BoarState.Following; if ((Object)(object)monsterAI == (Object)null) { monsterAI = ((Component)this).GetComponent(); } if ((Object)(object)sadle == (Object)null) { sadle = ((Component)this).GetComponentInChildren(); } } private void LateUpdate() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) if (CurrentState == BoarState.Staying) { Rigidbody component = ((Component)this).GetComponent(); if ((Object)(object)component != (Object)null) { component.linearVelocity = new Vector3(0f, component.linearVelocity.y, 0f); component.angularVelocity = Vector3.zero; } } } public void ToggleFollowStay() { //IL_006c: 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) if (!OwnerAlive()) { return; } if (CurrentState == BoarState.Following) { CurrentState = BoarState.Staying; if ((Object)(object)monsterAI != (Object)null) { monsterAI.SetFollowTarget((GameObject)null); ((BaseAI)monsterAI).SetPatrolPoint(); Rigidbody component = ((Component)this).GetComponent(); if ((Object)(object)component != (Object)null) { component.linearVelocity = Vector3.zero; component.angularVelocity = Vector3.zero; } } ((Character)Owner).Message((MessageType)2, "BattleBoar: Stay!", 0, (Sprite)null); BattleBoarPlugin.Log("BattleBoar set to Stay."); } else { CurrentState = BoarState.Following; if ((Object)(object)monsterAI != (Object)null) { monsterAI.SetFollowTarget(((Component)Owner).gameObject); } ((Character)Owner).Message((MessageType)2, "BattleBoar: Follow!", 0, (Sprite)null); BattleBoarPlugin.Log("BattleBoar set to Follow."); } } public void OnMounted() { CurrentState = BoarState.Mounted; if ((Object)(object)monsterAI != (Object)null) { monsterAI.SetFollowTarget((GameObject)null); } BattleBoarPlugin.Log("BattleBoar mounted."); } public void OnDismounted() { CurrentState = BoarState.Following; if ((Object)(object)monsterAI != (Object)null && OwnerAlive()) { monsterAI.SetFollowTarget(((Component)Owner).gameObject); } BattleBoarPlugin.Log("BattleBoar dismounted, resuming follow."); } public string GetCustomHoverText() { return CurrentState switch { BoarState.Mounted => "BattleBoar", BoarState.Following => "BattleBoar (Following)\n[E] Mount\n[Shift+E] Stay", BoarState.Staying => "BattleBoar (Staying)\n[E] Mount\n[Shift+E] Follow", _ => "BattleBoar", }; } public void ClearOwner() { Owner = null; } private bool OwnerAlive() { return (Object)(object)Owner != (Object)null && (Object)(object)((Component)Owner).gameObject != (Object)null && ((Component)Owner).gameObject.activeInHierarchy; } } public class BattleBoarSpawner : MonoBehaviour { [CompilerGenerated] private sealed class d__13 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public GameObject boarObj; public Player player; public Tameable tameable; public Character character; public ZNetView nview; public BattleBoarSpawner <>4__this; private Transform 5__1; private MonsterAI 5__2; private float 5__3; private Transform 5__4; private Transform 5__5; private GameObject 5__6; private SphereCollider 5__7; private GameObject 5__8; private Sadle 5__9; private FieldInfo 5__10; private FieldInfo 5__11; private FieldInfo 5__12; private FieldInfo 5__13; private BattleBoarController 5__14; private string 5__15; private FieldInfo 5__16; private MethodInfo 5__17; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__13(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { 5__1 = null; 5__2 = null; 5__4 = null; 5__5 = null; 5__6 = null; 5__7 = null; 5__8 = null; 5__9 = null; 5__10 = null; 5__11 = null; 5__12 = null; 5__13 = null; 5__14 = null; 5__15 = null; 5__16 = null; 5__17 = null; <>1__state = -2; } private bool MoveNext() { //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_038e: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Expected O, but got Unknown //IL_03c9: Unknown result type (might be due to invalid IL or missing references) //IL_03ee: Unknown result type (might be due to invalid IL or missing references) //IL_0413: Unknown result type (might be due to invalid IL or missing references) //IL_046a: Unknown result type (might be due to invalid IL or missing references) //IL_0474: Expected O, but got Unknown //IL_04a5: Unknown result type (might be due to invalid IL or missing references) //IL_04ca: Unknown result type (might be due to invalid IL or missing references) //IL_05a7: Unknown result type (might be due to invalid IL or missing references) //IL_05ac: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; if ((Object)(object)boarObj == (Object)null) { return false; } 5__1 = boarObj.transform.Find("Visual"); if ((Object)(object)5__1 != (Object)null && !((Component)5__1).gameObject.activeSelf) { ((Component)5__1).gameObject.SetActive(true); } 5__2 = boarObj.GetComponent(); if ((Object)(object)5__2 == (Object)null) { 5__2 = boarObj.AddComponent(); ((BaseAI)5__2).m_viewRange = 60f; ((BaseAI)5__2).m_viewAngle = 360f; ((BaseAI)5__2).m_hearRange = 60f; ((BaseAI)5__2).m_pathAgentType = (AgentType)1; ((BaseAI)5__2).m_smoothMovement = true; ((BaseAI)5__2).m_avoidFire = false; ((BaseAI)5__2).m_afraidOfFire = false; ((BaseAI)5__2).m_avoidWater = false; ((BaseAI)5__2).m_aggravatable = false; 5__2.m_fleeIfNotAlerted = false; 5__2.m_fleeIfLowHealth = 0f; 5__2.m_fleeIfHurtWhenTargetCantBeReached = false; 5__2.m_fleeInLava = false; ((BaseAI)5__2).m_avoidLava = false; ((BaseAI)5__2).m_avoidLavaFlee = false; ((BaseAI)5__2).m_fleeRange = 0f; 5__2.m_fleeTimeSinceHurt = 0f; } if ((Object)(object)tameable != (Object)null) { 5__16 = AccessTools.Field(typeof(Tameable), "m_monsterAI"); if (5__16 != null) { 5__16.SetValue(tameable, 5__2); } 5__16 = null; } <>2__current = null; <>1__state = 2; return true; case 2: <>1__state = -1; <>2__current = null; <>1__state = 3; return true; case 3: <>1__state = -1; <>2__current = null; <>1__state = 4; return true; case 4: <>1__state = -1; if ((Object)(object)boarObj == (Object)null) { return false; } if ((Object)(object)player == (Object)null || (Object)(object)((Component)player).gameObject == (Object)null) { return false; } 5__2.SetFollowTarget(((Component)player).gameObject); BattleBoarPlugin.Log("MonsterAI: follow target set."); 5__3 = BattleBoarPlugin.BoarScale.Value; 5__1 = boarObj.transform.Find("Visual"); 5__4 = null; if ((Object)(object)5__1 != (Object)null) { 5__4 = 5__1.Find("CG/Pelvis/Spine/Spine1"); } 5__5 = (((Object)(object)5__4 != (Object)null) ? 5__4 : boarObj.transform); if ((Object)(object)5__4 != (Object)null) { BattleBoarPlugin.Log("Found spine bone: CG/Pelvis/Spine/Spine1"); } else { BattleBoarPlugin.LogWarn("Spine bone not found — parenting saddle to root."); } 5__6 = new GameObject("BattleBoarSaddle"); 5__6.transform.SetParent(5__5); 5__6.transform.localPosition = new Vector3(0.0189f, -0.283f, 0f); 5__6.transform.localEulerAngles = new Vector3(0f, -90f, 180f); 5__6.transform.localScale = new Vector3(0.9f, 1f, 1f); 5__6.layer = boarObj.layer; 5__7 = 5__6.AddComponent(); 5__7.radius = 0.5f; ((Collider)5__7).isTrigger = false; 5__8 = new GameObject("MountPoint"); 5__8.transform.SetParent(5__5); 5__8.transform.localPosition = new Vector3(-0.01f, -0.22f, 0f); 5__8.transform.localEulerAngles = new Vector3(0f, 270f, 180f); <>4__this.mountPointTransform = 5__8.transform; 5__9 = 5__6.AddComponent(); 5__9.m_attachPoint = 5__8.transform; 5__9.m_maxUseRange = 10f; 5__9.m_hoverText = "BattleBoar"; 5__9.m_attachAnimation = "attach_asksvin"; 5__9.m_maxStamina = 9999f; 5__9.m_runStaminaDrain = 0f; 5__9.m_swimStaminaDrain = 0f; 5__9.m_staminaRegen = 100f; 5__9.m_staminaRegenHungry = 100f; 5__9.m_detachOffset = new Vector3(0f, 0.5f, -1f); 5__10 = AccessTools.Field(typeof(Sadle), "m_nview"); 5__11 = AccessTools.Field(typeof(Sadle), "m_character"); 5__12 = AccessTools.Field(typeof(Sadle), "m_tambable"); 5__13 = AccessTools.Field(typeof(Sadle), "m_monsterAI"); BattleBoarPlugin.Log($"Fresh Sadle: nview={5__10?.GetValue(5__9) != null}, " + $"char={5__11?.GetValue(5__9) != null}, " + $"tamb={5__12?.GetValue(5__9) != null}, " + $"ai={5__13?.GetValue(5__9) != null}"); <>4__this.AddSaddleVisual(5__6); if ((Object)(object)tameable != (Object)null) { tameable.m_saddle = 5__9; tameable.m_dropSaddleOnDeath = false; 5__17 = AccessTools.Method(typeof(Tameable), "SetSaddle", (Type[])null, (Type[])null); 5__17?.Invoke(tameable, new object[1] { true }); BattleBoarPlugin.Log($"SetSaddle(true). Active={5__6.activeSelf}"); 5__17 = null; } <>4__this.AttachArmorPieces(boarObj); 5__14 = boarObj.AddComponent(); 5__14.Initialize(player); <>4__this.ActiveBoar = 5__14; <>4__this.heartCoroutine = ((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.SpawnHeartEffects(boarObj, player, tameable)); 5__15 = "BattleBoar summoned!"; if ((Object)(object)player != (Object)null && (Object)(object)((Component)player).gameObject != (Object)null) { ((Character)player).Message((MessageType)2, 5__15, 0, (Sprite)null); } BattleBoarPlugin.Log(5__15); return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [CompilerGenerated] private sealed class d__34 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public GameObject boarObj; public Player player; public Tameable tameable; public BattleBoarSpawner <>4__this; private EffectList 5__1; private float 5__2; private FieldInfo 5__3; private FieldInfo 5__4; private float 5__5; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__34(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { 5__1 = null; 5__3 = null; 5__4 = null; <>1__state = -2; } private bool MoveNext() { //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Expected O, but got Unknown //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_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_01ac: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: <>1__state = -1; if ((Object)(object)boarObj == (Object)null || (Object)(object)player == (Object)null) { return false; } 5__1 = null; if ((Object)(object)tameable != (Object)null) { 5__3 = typeof(Tameable).GetField("m_petEffect", BindingFlags.Instance | BindingFlags.Public); if (5__3 != null) { ref EffectList reference = ref 5__1; object? value = 5__3.GetValue(tameable); reference = (EffectList)((value is EffectList) ? value : null); } if (5__1 == null) { 5__4 = typeof(Tameable).GetField("m_tamedEffect", BindingFlags.Instance | BindingFlags.Public); if (5__4 != null) { ref EffectList reference2 = ref 5__1; object? value2 = 5__4.GetValue(tameable); reference2 = (EffectList)((value2 is EffectList) ? value2 : null); } 5__4 = null; } 5__3 = null; } 5__2 = 0f; break; case 1: <>1__state = -1; break; } if (5__2 < 15f && (Object)(object)boarObj != (Object)null && (Object)(object)player != (Object)null && (Object)(object)((Component)player).gameObject != (Object)null && ((Component)player).gameObject.activeInHierarchy) { 5__5 = Vector3.Distance(boarObj.transform.position, ((Component)player).transform.position); if (!(5__5 < 5f)) { if (5__1 != null) { 5__1.Create(boarObj.transform.position + Vector3.up * 1.5f, boarObj.transform.rotation, boarObj.transform, 1f, -1); } 5__2 += 0.5f; <>2__current = (object)new WaitForSeconds(0.5f); <>1__state = 1; return true; } } <>4__this.heartCoroutine = null; return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private Coroutine heartCoroutine; private Coroutine setupCoroutine; public bool saddleAdjustMode = false; private int adjustTarget = 0; private float saddleCutoffY = -0.9f; private Transform saddleVisualTransform; private Transform mountPointTransform; private Transform leftShieldTransform; private Transform rightShieldTransform; private Transform headWeaponTransform; public float jumpForce = 30f; public static BattleBoarSpawner Instance { get; private set; } public BattleBoarController ActiveBoar { get; private set; } private void Awake() { Instance = this; } private void Update() { if ((Object)(object)ActiveBoar != (Object)null && !Object.op_Implicit((Object)(object)ActiveBoar)) { ActiveBoar = null; } } public void SummonOrRecall() { //IL_006e: 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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: 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_00e8: 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_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0151: 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_0190: 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_02c9: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ZNetScene.instance == (Object)null) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return; } if ((Object)(object)ActiveBoar != (Object)null) { DespawnBoar(); ((Character)localPlayer).Message((MessageType)2, "BattleBoar dismissed!", 0, (Sprite)null); return; } float value = BattleBoarPlugin.SpawnDistance.Value; Vector3 val = ((Component)localPlayer).transform.position + ((Component)localPlayer).transform.forward * value; float y = default(float); if ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGroundHeight(val, ref y)) { val.y = y; } GameObject prefab = ZNetScene.instance.GetPrefab("Boar"); if ((Object)(object)prefab == (Object)null) { BattleBoarPlugin.LogWarn("Boar prefab not found."); return; } GameObject val2 = Object.Instantiate(prefab, val, Quaternion.identity); Rigidbody component = val2.GetComponent(); if ((Object)(object)component != (Object)null) { component.interpolation = (RigidbodyInterpolation)1; } Vector3 val3 = ((Component)localPlayer).transform.position - val; val3.y = 0f; if (((Vector3)(ref val3)).sqrMagnitude > 0.1f) { val2.transform.rotation = Quaternion.LookRotation(((Vector3)(ref val3)).normalized); } float value2 = BattleBoarPlugin.BoarScale.Value; Transform val4 = val2.transform.Find("Visual"); if ((Object)(object)val4 != (Object)null) { val4.localScale = Vector3.one * value2; } ZNetView component2 = val2.GetComponent(); if ((Object)(object)component2 != (Object)null && component2.IsValid()) { component2.m_persistent = false; FieldInfo fieldInfo = AccessTools.Field(typeof(ZDO), "m_persistent") ?? AccessTools.Field(typeof(ZDO), "m_tempRemoveEarmark") ?? AccessTools.Field(typeof(ZDO), "m_noPersist"); if (fieldInfo != null && fieldInfo.FieldType == typeof(bool)) { fieldInfo.SetValue(component2.GetZDO(), (!fieldInfo.Name.Contains("persist")) ? true : false); } component2.GetZDO().Set("tamed", true); component2.GetZDO().Set(StringExtensionMethods.GetStableHashCode("haveSaddle"), true); component2.GetZDO().Set("TamedName", "BattleBoar"); } Character component3 = val2.GetComponent(); if ((Object)(object)component3 != (Object)null) { component3.m_faction = (Faction)0; float value3 = BattleBoarPlugin.BoarHealth.Value; component3.SetMaxHealth(value3); component3.SetHealth(value3); component3.m_speed = BattleBoarPlugin.BoarRunSpeed.Value * 0.5f; component3.m_runSpeed = BattleBoarPlugin.BoarRunSpeed.Value; component3.m_tolerateWater = true; component3.m_tolerateFire = true; component3.m_tolerateSmoke = true; } Tameable component4 = val2.GetComponent(); if ((Object)(object)component4 != (Object)null) { component4.m_tamingTime = 0f; component4.m_commandable = true; component4.m_fedDuration = 999999f; TryInvokeMethod(component4, "Tame"); ZNetView component5 = val2.GetComponent(); if ((Object)(object)component5 != (Object)null && component5.IsValid()) { component5.GetZDO().Set(StringExtensionMethods.GetStableHashCode("TameLastFeeding"), ZNet.instance.GetTime().Ticks); } } AnimalAI component6 = val2.GetComponent(); if ((Object)(object)component6 != (Object)null) { Object.Destroy((Object)(object)component6); } setupCoroutine = ((MonoBehaviour)this).StartCoroutine(SetupAI(val2, localPlayer, component4, component3, component2)); } [IteratorStateMachine(typeof(d__13))] private IEnumerator SetupAI(GameObject boarObj, Player player, Tameable tameable, Character character, ZNetView nview) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__13(0) { <>4__this = this, boarObj = boarObj, player = player, tameable = tameable, character = character, nview = nview }; } private void AddSaddleVisual(GameObject saddleGO) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) try { ZNetScene instance = ZNetScene.instance; GameObject val = ((instance != null) ? instance.GetPrefab("Asksvin") : null); if ((Object)(object)val != (Object)null) { GameObject val2 = Object.Instantiate(val, new Vector3(0f, -500f, 0f), Quaternion.identity); Sadle componentInChildren = val2.GetComponentInChildren(true); SkinnedMeshRenderer val3 = ((componentInChildren != null) ? ((Component)componentInChildren).GetComponentInChildren(true) : null); if ((Object)(object)val3 != (Object)null && (Object)(object)componentInChildren != (Object)null) { if (!string.IsNullOrEmpty(componentInChildren.m_attachAnimation)) { Sadle component = saddleGO.GetComponent(); if ((Object)(object)component != (Object)null) { component.m_attachAnimation = componentInChildren.m_attachAnimation; BattleBoarPlugin.Log("Using Asksvin attach animation: " + componentInChildren.m_attachAnimation); } } Mesh val4 = new Mesh(); val3.BakeMesh(val4); GameObject val5 = new GameObject("SaddleVisual"); val5.transform.SetParent(saddleGO.transform); saddleVisualTransform = val5.transform; val5.transform.localPosition = new Vector3(0f, 0f, -0.15f); val5.transform.localRotation = Quaternion.Euler(300f, 0f, 0f); float num = 0.6f; val5.transform.localScale = new Vector3(num, num, num); val5.layer = saddleGO.layer; Mesh val6 = SplitMeshAboveY(val4, saddleCutoffY); val5.AddComponent().sharedMesh = val6; ((Renderer)val5.AddComponent()).sharedMaterials = ((Renderer)val3).sharedMaterials; BattleBoarPlugin.Log($"Saddle visual: original={val4.vertexCount} verts, " + $"after cut(Y>{saddleCutoffY:F1})={val6.vertexCount} verts, " + $"bounds={val6.bounds}"); } ZNetView component2 = val2.GetComponent(); if ((Object)(object)component2 != (Object)null && component2.IsValid()) { component2.Destroy(); } else { Object.Destroy((Object)(object)val2); } } else { BattleBoarPlugin.LogWarn("Asksvin prefab not found — using cube placeholder."); AddCubePlaceholder(saddleGO); } } catch (Exception ex) { BattleBoarPlugin.LogWarn("Saddle visual failed: " + ex.Message + " — using cube placeholder."); AddCubePlaceholder(saddleGO); } } private void AttachArmorPieces(GameObject boarObj) { //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00af: 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_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) Transform val = boarObj.transform.Find("Visual"); if (!((Object)(object)val == (Object)null)) { Transform val2 = val.Find("CG/Pelvis/Spine/Spine1"); Transform val3 = val.Find("CG/Pelvis/Spine/Spine1/Neck/Head"); if ((Object)(object)val3 == (Object)null) { val3 = val.Find("CG/Pelvis/Spine/Spine1/Neck"); } if ((Object)(object)val3 == (Object)null) { val3 = val2; } Transform val4 = val2 ?? boarObj.transform; leftShieldTransform = AttachItemMesh("ShieldFlametal", val4, new Vector3(-0.4f, -0.1f, -0.25f), Quaternion.Euler(0f, 0f, 90f), new Vector3(0.4f, 0.4f, 0.4f), "LeftShield"); rightShieldTransform = AttachItemMesh("ShieldFlametal", val4, new Vector3(-0.35f, -0.1f, 0.25f), Quaternion.Euler(0f, 180f, 270f), new Vector3(0.4f, 0.4f, 0.4f), "RightShield"); headWeaponTransform = AttachItemMesh("SpearSplitner", val3 ?? val4, new Vector3(-0.5f, -0.25f, 0f), Quaternion.Euler(274.1f, 267.9f, 184.4f), new Vector3(0.5f, 0.5f, 0.5f), "HeadWeapon"); int num = (((Object)(object)leftShieldTransform != (Object)null) ? 1 : 0) + (((Object)(object)rightShieldTransform != (Object)null) ? 1 : 0) + (((Object)(object)headWeaponTransform != (Object)null) ? 1 : 0); BattleBoarPlugin.Log($"Armor pieces attached: {num}/3"); } } private Transform AttachItemMesh(string itemName, Transform parent, Vector3 localPos, Quaternion localRot, Vector3 localScale, string goName) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Expected O, but got Unknown //IL_0142: 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_015d: Unknown result type (might be due to invalid IL or missing references) try { ZNetScene instance = ZNetScene.instance; GameObject val = ((instance != null) ? instance.GetPrefab(itemName) : null); if ((Object)(object)val == (Object)null) { BattleBoarPlugin.LogWarn("Armor item '" + itemName + "' not found in ZNetScene."); return null; } MeshFilter val2 = null; MeshRenderer val3 = null; foreach (Transform item in val.transform) { Transform val4 = item; MeshFilter component = ((Component)val4).GetComponent(); MeshRenderer component2 = ((Component)val4).GetComponent(); if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null && (Object)(object)component.sharedMesh != (Object)null) { val2 = component; val3 = component2; break; } } if ((Object)(object)val2 == (Object)null) { val2 = val.GetComponentInChildren(true); val3 = val.GetComponentInChildren(true); } if ((Object)(object)val2 == (Object)null || (Object)(object)val2.sharedMesh == (Object)null) { BattleBoarPlugin.LogWarn("No mesh found on '" + itemName + "'."); return null; } GameObject val5 = new GameObject(goName); val5.transform.SetParent(parent); val5.transform.localPosition = localPos; val5.transform.localRotation = localRot; val5.transform.localScale = localScale; val5.layer = ((Component)parent).gameObject.layer; val5.AddComponent().sharedMesh = val2.sharedMesh; ((Renderer)val5.AddComponent()).sharedMaterials = ((Renderer)val3).sharedMaterials; BattleBoarPlugin.Log("Armor '" + goName + "': mesh=" + ((Object)val2.sharedMesh).name + " from " + itemName + ", " + $"verts={val2.sharedMesh.vertexCount}"); return val5.transform; } catch (Exception ex) { BattleBoarPlugin.LogWarn("Failed to attach '" + itemName + "': " + ex.Message); return null; } } private void AddCubePlaceholder(GameObject saddleGO) { //IL_002c: 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_005d: 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) GameObject val = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)val).name = "SaddleVisual"; val.transform.SetParent(saddleGO.transform); val.transform.localPosition = Vector3.zero; val.transform.localRotation = Quaternion.identity; val.transform.localScale = new Vector3(0.5f, 0.1f, 0.6f); val.layer = saddleGO.layer; Collider component = val.GetComponent(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } Renderer component2 = val.GetComponent(); if ((Object)(object)component2 != (Object)null && (Object)(object)component2.material != (Object)null) { component2.material.color = new Color(0.35f, 0.22f, 0.1f); } } public void ToggleSaddleAdjust() { adjustTarget = (adjustTarget + 1) % 10; saddleAdjustMode = adjustTarget != 0; string[] array = new string[10] { "Adjust OFF", "1: SADDLE VISUAL\nArrows=rot Alt+Arrows=pos Ctrl=fine", "2: MOUNT POINT\nAlt+Arrows=pos Ctrl=fine", "3: BOAR SIZE\nUp/Down=scale Ctrl=fine", "4: SADDLE SIZE\nUp/Down=scale Ctrl=fine", $"5: MESH CUTOFF (Y>{saddleCutoffY:F1})\nUp/Down=cut more/less Ctrl=fine\nRe-summon with N to apply", "6: LEFT SHIELD\nArrows=rot Alt+Arrows=pos Ctrl=fine", "7: RIGHT SHIELD\nArrows=rot Alt+Arrows=pos Ctrl=fine", "8: HEAD WEAPON\nArrows=rot Alt+Arrows=pos Ctrl=fine", $"9: JUMP POWER ({jumpForce:F1})\nUp/Down=more/less Ctrl=fine" }; Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, array[adjustTarget], 0, (Sprite)null); } } private Transform GetAdjustTarget() { return (Transform)(adjustTarget switch { 1 => saddleVisualTransform, 2 => mountPointTransform, 6 => leftShieldTransform, 7 => rightShieldTransform, 8 => headWeaponTransform, _ => null, }); } public void AdjustSaddleRotation(float dx, float dy, float dz) { if (adjustTarget >= 3 && adjustTarget != 6 && adjustTarget != 7 && adjustTarget != 8) { float num = ((dx > 0f) ? 0.05f : ((dx < 0f) ? (-0.05f) : 0f)); if (Input.GetKey((KeyCode)306)) { num *= 0.4f; } if (num == 0f) { return; } if (adjustTarget == 5) { saddleCutoffY += num; string text = $"Mesh Cutoff Y: {saddleCutoffY:F2} (re-summon with N to apply)"; BattleBoarPlugin.Log(text); Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)1, text, 0, (Sprite)null); } } else if (adjustTarget == 9) { float num2 = ((dx > 0f) ? 1f : (-1f)); if (Input.GetKey((KeyCode)306)) { num2 *= 0.2f; } jumpForce = Mathf.Clamp(jumpForce + num2, 1f, 30f); string text2 = $"Jump Power: {jumpForce:F1}"; BattleBoarPlugin.Log(text2); Player localPlayer2 = Player.m_localPlayer; if (localPlayer2 != null) { ((Character)localPlayer2).Message((MessageType)1, text2, 0, (Sprite)null); } } else { AdjustScale(num); } } else { Transform val = GetAdjustTarget(); if (!((Object)(object)val == (Object)null)) { val.Rotate(dx, dy, dz, (Space)1); LogAdjust(val); } } } public void AdjustSaddlePosition(float dx, float dy, float dz) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) Transform val = GetAdjustTarget(); if (!((Object)(object)val == (Object)null)) { val.localPosition += new Vector3(dx, dy, dz); LogAdjust(val); } } private void AdjustScale(float delta) { //IL_0050: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_010d: 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)(object)ActiveBoar == (Object)null) { return; } if (adjustTarget == 3) { Transform val = ((Component)ActiveBoar).transform.Find("Visual"); if (!((Object)(object)val == (Object)null)) { float x = val.localScale.x; float num = Mathf.Clamp(x + delta, 0.5f, 3f); val.localScale = Vector3.one * num; string text = $"Boar Scale: {num:F2}"; BattleBoarPlugin.Log(text); Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)1, text, 0, (Sprite)null); } } } else if (adjustTarget == 4 && !((Object)(object)saddleVisualTransform == (Object)null)) { float x2 = saddleVisualTransform.localScale.x; float num2 = Mathf.Clamp(x2 + delta, 0.1f, 2f); saddleVisualTransform.localScale = Vector3.one * num2; string text2 = $"Saddle Scale: {num2:F2}"; BattleBoarPlugin.Log(text2); Player localPlayer2 = Player.m_localPlayer; if (localPlayer2 != null) { ((Character)localPlayer2).Message((MessageType)1, text2, 0, (Sprite)null); } } } private static Mesh SplitMeshAboveY(Mesh source, float cutoffY) { //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Expected O, but got Unknown //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) Vector3[] vertices = source.vertices; Vector3[] normals = source.normals; Vector2[] uv = source.uv; Color[] colors = source.colors; Dictionary dictionary = new Dictionary(); List list = new List(); List list2 = new List(); List list3 = new List(); List list4 = new List(); int subMeshCount = source.subMeshCount; List> list5 = new List>(); for (int i = 0; i < subMeshCount; i++) { int[] triangles = source.GetTriangles(i); List list6 = new List(); for (int j = 0; j < triangles.Length; j += 3) { int num = triangles[j]; int num2 = triangles[j + 1]; int num3 = triangles[j + 2]; if (!(vertices[num].y > cutoffY) || !(vertices[num2].y > cutoffY) || !(vertices[num3].y > cutoffY)) { continue; } int[] array = new int[3] { num, num2, num3 }; foreach (int num4 in array) { if (!dictionary.ContainsKey(num4)) { dictionary[num4] = list.Count; list.Add(vertices[num4]); if (normals.Length > num4) { list2.Add(normals[num4]); } if (uv.Length > num4) { list3.Add(uv[num4]); } if (colors.Length > num4) { list4.Add(colors[num4]); } } list6.Add(dictionary[num4]); } } list5.Add(list6); } Mesh val = new Mesh(); val.vertices = list.ToArray(); if (list2.Count == list.Count) { val.normals = list2.ToArray(); } if (list3.Count == list.Count) { val.uv = list3.ToArray(); } if (list4.Count == list.Count) { val.colors = list4.ToArray(); } val.subMeshCount = subMeshCount; for (int l = 0; l < subMeshCount; l++) { val.SetTriangles(list5[l].ToArray(), l); } val.RecalculateBounds(); return val; } private void LogAdjust(Transform t) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0093: 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_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) Vector3 localEulerAngles = t.localEulerAngles; Vector3 localPosition = t.localPosition; string[] array = new string[9] { "", "Saddle", "MountPt", "BoarSz", "SadlSz", "Cut", "LShield", "RShield", "HeadWpn" }; string text = $"{array[adjustTarget]} Rot:({localEulerAngles.x:F1},{localEulerAngles.y:F1},{localEulerAngles.z:F1}) Pos:({localPosition.x:F2},{localPosition.y:F2},{localPosition.z:F2})"; BattleBoarPlugin.Log(text); Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)1, text, 0, (Sprite)null); } } [IteratorStateMachine(typeof(d__34))] private IEnumerator SpawnHeartEffects(GameObject boarObj, Player player, Tameable tameable) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__34(0) { <>4__this = this, boarObj = boarObj, player = player, tameable = tameable }; } public void DespawnBoar() { if (setupCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(setupCoroutine); setupCoroutine = null; } if (heartCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(heartCoroutine); heartCoroutine = null; } if ((Object)(object)ActiveBoar != (Object)null && (Object)(object)((Component)ActiveBoar).gameObject != (Object)null) { ActiveBoar.ClearOwner(); ZNetView component = ((Component)ActiveBoar).GetComponent(); if ((Object)(object)component != (Object)null && component.IsValid()) { component.ClaimOwnership(); component.Destroy(); } else { Object.Destroy((Object)(object)((Component)ActiveBoar).gameObject); } } ActiveBoar = null; } public void OnBoarDied() { if ((Object)(object)ActiveBoar != (Object)null) { ActiveBoar.ClearOwner(); } ActiveBoar = null; } private bool TryInvokeMethod(object target, string methodName) { MethodInfo method = target.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method == null) { BattleBoarPlugin.LogWarn(target.GetType().Name + "." + methodName + "() not found"); return false; } try { method.Invoke(target, null); return true; } catch (Exception ex) { BattleBoarPlugin.LogWarn(methodName + "(): " + (ex.InnerException?.Message ?? ex.Message)); return false; } } } public static class Patches { [HarmonyPatch(typeof(Sadle), "Interact")] public static class SadleInteract_Patch { private static bool Prefix(Sadle __instance, Humanoid character, bool alt, ref bool __result) { BattleBoarController componentInParent = ((Component)__instance).GetComponentInParent(); if ((Object)(object)componentInParent == (Object)null) { return true; } if (alt) { componentInParent.ToggleFollowStay(); __result = true; return false; } return true; } private static void Postfix(Sadle __instance, bool alt, bool __result) { if (!(!__result || alt)) { ((Component)__instance).GetComponentInParent()?.OnMounted(); } } } [HarmonyPatch(typeof(Sadle), "OnUseStop")] public static class SadleOnUseStop_Patch { private static void Postfix(Sadle __instance) { BattleBoarController componentInParent = ((Component)__instance).GetComponentInParent(); if ((Object)(object)componentInParent != (Object)null && componentInParent.CurrentState == BattleBoarController.BoarState.Mounted) { componentInParent.OnDismounted(); } } } [HarmonyPatch(typeof(Tameable), "Interact")] public static class TameableInteract_Patch { private static bool Prefix(Tameable __instance, Humanoid user, bool hold, bool alt, ref bool __result) { BattleBoarController component = ((Component)__instance).GetComponent(); if ((Object)(object)component == (Object)null) { return true; } if (hold) { __result = false; return false; } if (alt) { component.ToggleFollowStay(); __result = true; return false; } if ((Object)(object)__instance.m_saddle != (Object)null) { __instance.m_saddle.Interact(user, hold, alt); __result = true; return false; } BattleBoarPlugin.LogWarn("Tameable.Interact: m_saddle is null — mount failed!"); __result = false; return false; } } [HarmonyPatch(typeof(Tameable), "GetHoverText")] public static class TameableHoverText_Patch { private static bool Prefix(Tameable __instance, ref string __result) { BattleBoarController component = ((Component)__instance).GetComponent(); if ((Object)(object)component == (Object)null) { return true; } __result = component.GetCustomHoverText(); return false; } } [HarmonyPatch(typeof(Sadle), "GetHoverText")] public static class SadleHoverText_Patch { private static bool Prefix(Sadle __instance, ref string __result) { BattleBoarController componentInParent = ((Component)__instance).GetComponentInParent(); if ((Object)(object)componentInParent == (Object)null) { return true; } __result = componentInParent.GetCustomHoverText(); return false; } } [HarmonyPatch(typeof(Tameable), "GetHoverName")] public static class TameableHoverName_Patch { private static bool Prefix(Tameable __instance, ref string __result) { BattleBoarController component = ((Component)__instance).GetComponent(); if ((Object)(object)component == (Object)null) { return true; } __result = "BattleBoar"; return false; } } [HarmonyPatch(typeof(Character), "GetHoverName")] public static class CharacterHoverName_Patch { private static bool Prefix(Character __instance, ref string __result) { BattleBoarController component = ((Component)__instance).GetComponent(); if ((Object)(object)component == (Object)null) { return true; } __result = "BattleBoar"; return false; } } [HarmonyPatch(typeof(Sadle), "GetHoverName")] public static class SadleHoverName_Patch { private static bool Prefix(Sadle __instance, ref string __result) { BattleBoarController componentInParent = ((Component)__instance).GetComponentInParent(); if ((Object)(object)componentInParent == (Object)null) { return true; } __result = "BattleBoar"; return false; } } [HarmonyPatch(typeof(BaseAI), "IsEnemy", new Type[] { typeof(Character), typeof(Character) })] public static class IsEnemy_Patch { private static void Postfix(Character a, Character b, ref bool __result) { if (__result) { bool flag = (Object)(object)a != (Object)null && (Object)(object)((Component)a).GetComponent() != (Object)null; bool flag2 = (Object)(object)b != (Object)null && (Object)(object)((Component)b).GetComponent() != (Object)null; if (flag && b is Player) { __result = false; } else if (a is Player && flag2) { __result = false; } } } } [HarmonyPatch(typeof(Character), "Damage")] public static class NoDamageFromOwner_Patch { private static bool Prefix(Character __instance, HitData hit) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val != null && ((Character)val).IsRiding()) { IDoodadController doodadController = val.GetDoodadController(); Sadle val2 = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).GetComponentInParent() != (Object)null) { return false; } } if ((Object)(object)((Component)__instance).GetComponent() != (Object)null) { return false; } return true; } } [HarmonyPatch(typeof(CharacterDrop), "OnDeath")] public static class NoLootDrops_Patch { private static bool Prefix(CharacterDrop __instance) { if ((Object)(object)((Component)__instance).GetComponent() != (Object)null) { return false; } return true; } } [HarmonyPatch(typeof(Character), "OnDeath")] public static class BoarDeath_Patch { private static void Postfix(Character __instance) { BattleBoarController component = ((Component)__instance).GetComponent(); if (!((Object)(object)component == (Object)null)) { BattleBoarSpawner.Instance?.OnBoarDied(); Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { ((Character)localPlayer).Message((MessageType)2, "BattleBoar has fallen!", 0, (Sprite)null); } BattleBoarPlugin.Log("BattleBoar died."); } } } [HarmonyPatch(typeof(Game), "OnDestroy")] public static class GameCleanup_Patch { private static void Prefix() { BattleBoarSpawner.Instance?.DespawnBoar(); BattleBoarPlugin.Log("World unloading — BattleBoar despawned."); } } [HarmonyPatch(typeof(Game), "Start")] public static class GameStart_Cleanup_Patch { [CompilerGenerated] private sealed class d__1 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; private int 5__1; private List 5__2; private List.Enumerator <>s__3; private Character 5__4; private ZNetView 5__5; private ZDO 5__6; private string 5__7; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__1(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { 5__2 = null; <>s__3 = default(List.Enumerator); 5__4 = null; 5__5 = null; 5__6 = null; 5__7 = null; <>1__state = -2; } private bool MoveNext() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(5f); <>1__state = 1; return true; case 1: <>1__state = -1; 5__1 = 0; 5__2 = Character.GetAllCharacters(); <>s__3 = 5__2.GetEnumerator(); try { while (<>s__3.MoveNext()) { 5__4 = <>s__3.Current; if ((Object)(object)5__4 == (Object)null) { continue; } 5__5 = ((Component)5__4).GetComponent(); if ((Object)(object)5__5 == (Object)null || !5__5.IsValid()) { continue; } 5__6 = 5__5.GetZDO(); if (5__6 != null) { 5__7 = 5__6.GetString("TamedName", ""); if (5__7 == "BattleBoar") { 5__5.ClaimOwnership(); 5__5.Destroy(); 5__1++; } 5__5 = null; 5__6 = null; 5__7 = null; 5__4 = null; } } } finally { ((IDisposable)<>s__3).Dispose(); } <>s__3 = default(List.Enumerator); if (5__1 > 0) { BattleBoarPlugin.Log($"Cleaned up {5__1} leftover BattleBoar(s) from previous session."); } return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private static void Postfix() { BattleBoarPlugin instance = BattleBoarPlugin.Instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(CleanupLeftoverBoars()); } } [IteratorStateMachine(typeof(d__1))] private static IEnumerator CleanupLeftoverBoars() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__1(0); } } [HarmonyPatch(typeof(Player), "Update")] public static class PlayerUpdate_Riding_Patch { private static void Postfix(Player __instance) { //IL_0054: 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) if (!((Character)__instance).IsRiding()) { return; } FieldInfo fieldInfo = AccessTools.Field(typeof(Character), "m_attachPoint"); if (!(fieldInfo == null)) { object? value = fieldInfo.GetValue(__instance); Transform val = (Transform)((value is Transform) ? value : null); if ((Object)(object)val != (Object)null) { ((Component)__instance).transform.position = val.position; ((Component)__instance).transform.rotation = val.rotation; } } } } [HarmonyPatch(typeof(Player), "SetControls")] public static class PlayerSetControls_Patch { private static void Prefix(Player __instance, ref bool jump, ref bool crouch, ref bool attack, ref bool secondaryAttack) { //IL_00a4: 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_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: 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_0284: 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_00ff: 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_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010c: 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_0196: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Unknown result type (might be due to invalid IL or missing references) //IL_0717: Unknown result type (might be due to invalid IL or missing references) //IL_06a0: Unknown result type (might be due to invalid IL or missing references) //IL_06a7: Unknown result type (might be due to invalid IL or missing references) //IL_06b3: Unknown result type (might be due to invalid IL or missing references) //IL_06c7: Unknown result type (might be due to invalid IL or missing references) //IL_06ce: Unknown result type (might be due to invalid IL or missing references) //IL_06d8: Unknown result type (might be due to invalid IL or missing references) //IL_06e4: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_030c: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Expected O, but got Unknown //IL_0354: Unknown result type (might be due to invalid IL or missing references) //IL_0359: Unknown result type (might be due to invalid IL or missing references) //IL_0367: Unknown result type (might be due to invalid IL or missing references) //IL_036c: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) //IL_0373: Unknown result type (might be due to invalid IL or missing references) //IL_0377: Unknown result type (might be due to invalid IL or missing references) //IL_037c: Unknown result type (might be due to invalid IL or missing references) //IL_0516: Unknown result type (might be due to invalid IL or missing references) //IL_0518: Unknown result type (might be due to invalid IL or missing references) //IL_042c: Unknown result type (might be due to invalid IL or missing references) //IL_0433: Expected O, but got Unknown //IL_046f: Unknown result type (might be due to invalid IL or missing references) //IL_0474: Unknown result type (might be due to invalid IL or missing references) //IL_0482: Unknown result type (might be due to invalid IL or missing references) //IL_0487: Unknown result type (might be due to invalid IL or missing references) //IL_0489: Unknown result type (might be due to invalid IL or missing references) //IL_048e: Unknown result type (might be due to invalid IL or missing references) //IL_0492: Unknown result type (might be due to invalid IL or missing references) //IL_0497: Unknown result type (might be due to invalid IL or missing references) //IL_0588: Unknown result type (might be due to invalid IL or missing references) //IL_058a: Unknown result type (might be due to invalid IL or missing references) if (!((Character)__instance).IsRiding()) { return; } IDoodadController doodadController = __instance.GetDoodadController(); Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); if ((Object)(object)val == (Object)null) { return; } BattleBoarController componentInParent = ((Component)val).GetComponentInParent(); if ((Object)(object)componentInParent == (Object)null) { return; } if (attack) { try { ZNetScene instance = ZNetScene.instance; GameObject val2 = ((instance != null) ? instance.GetPrefab("staff_fireball_projectile") : null); if ((Object)(object)val2 != (Object)null) { Character sadleCharacter = GetSadleCharacter(val); if ((Object)(object)sadleCharacter != (Object)null) { Vector3 val3 = ((Component)sadleCharacter).transform.position + ((Component)sadleCharacter).transform.forward * 1.5f + Vector3.up * 1.5f; Vector3 val4 = (((Object)(object)GameCamera.instance != (Object)null) ? ((Component)GameCamera.instance).transform.forward : ((Component)sadleCharacter).transform.forward); GameObject val5 = Object.Instantiate(val2, val3, Quaternion.LookRotation(val4)); Projectile component = val5.GetComponent(); if ((Object)(object)component != (Object)null) { component.m_gravity = 0.3f; component.m_damage.m_fire = 120f; component.m_damage.m_blunt = 60f; component.m_damage.m_chop = 40f; component.m_damage.m_pickaxe = 40f; component.m_aoe = 4f; component.Setup((Character)(object)__instance, val4 * 25f, -1f, (HitData)null, (ItemData)null, (ItemData)null); } Rigidbody component2 = val5.GetComponent(); if ((Object)(object)component2 != (Object)null) { component2.useGravity = false; } } } } catch (Exception ex) { BattleBoarPlugin.LogWarn("Fireball failed: " + ex.Message); } attack = false; } if (secondaryAttack || ZInput.GetButtonDown("Block") || ZInput.GetButtonDown("JoyBlock")) { try { Character sadleCharacter2 = GetSadleCharacter(val); if ((Object)(object)sadleCharacter2 != (Object)null) { Animator componentInChildren = ((Component)sadleCharacter2).GetComponentInChildren(); if ((Object)(object)componentInChildren != (Object)null) { componentInChildren.SetTrigger("attack"); } ZSyncAnimation component3 = ((Component)sadleCharacter2).GetComponent(); if ((Object)(object)component3 != (Object)null) { component3.SetTrigger("attack"); } Vector3 position = ((Component)sadleCharacter2).transform.position; float num = 8f; float blunt = 120f; int num2 = 0; Vector3 val7; foreach (Character allCharacter in Character.GetAllCharacters()) { if (!((Object)(object)allCharacter == (Object)(object)sadleCharacter2) && !((Object)(object)allCharacter == (Object)(object)__instance) && !((Object)(object)((Component)allCharacter).GetComponent() != (Object)null) && !allCharacter.IsTamed() && !(Vector3.Distance(position, ((Component)allCharacter).transform.position) > num)) { HitData val6 = new HitData(); val6.m_damage.m_blunt = blunt; val6.m_damage.m_chop = 80f; val6.m_point = ((Component)allCharacter).transform.position; val7 = ((Component)allCharacter).transform.position - position; val6.m_dir = ((Vector3)(ref val7)).normalized; val6.m_pushForce = 20f; val6.SetAttacker((Character)(object)__instance); allCharacter.Damage(val6); num2++; } } Collider[] array = Physics.OverlapSphere(position, num); foreach (Collider val8 in array) { if (!((Object)(object)val8 == (Object)null) && !((Object)(object)((Component)val8).transform == (Object)null)) { IDestructible componentInParent2 = ((Component)val8).GetComponentInParent(); if (componentInParent2 != null && !(componentInParent2 is Character)) { HitData val9 = new HitData(); val9.m_damage.m_chop = 200f; val9.m_damage.m_pickaxe = 200f; val9.m_damage.m_blunt = 100f; val9.m_point = ((Component)val8).transform.position; val7 = ((Component)val8).transform.position - position; val9.m_dir = ((Vector3)(ref val7)).normalized; val9.SetAttacker((Character)(object)__instance); componentInParent2.Damage(val9); } } } string[] array2 = new string[3] { "fx_troll_groundslam", "vfx_troll_groundslam", "fx_eikthyr_stomp" }; foreach (string text in array2) { ZNetScene instance2 = ZNetScene.instance; GameObject val10 = ((instance2 != null) ? instance2.GetPrefab(text) : null); if ((Object)(object)val10 != (Object)null) { Object.Instantiate(val10, position, Quaternion.identity); break; } } string[] array3 = new string[3] { "sfx_troll_groundslam", "sfx_troll_attack_hit", "sfx_stone_hit" }; foreach (string text2 in array3) { ZNetScene instance3 = ZNetScene.instance; GameObject val11 = ((instance3 != null) ? instance3.GetPrefab(text2) : null); if ((Object)(object)val11 != (Object)null) { Object.Instantiate(val11, position, Quaternion.identity); break; } } } } catch (Exception ex2) { BattleBoarPlugin.LogWarn("Ground slam failed: " + ex2.Message); } secondaryAttack = false; } if (ZInput.GetButton("Jump") || ZInput.GetButtonDown("JoyJump")) { try { object? obj = AccessTools.Field(typeof(Sadle), "m_monsterAI")?.GetValue(val); MonsterAI val12 = (MonsterAI)((obj is MonsterAI) ? obj : null); if ((Object)(object)val12 != (Object)null) { object? obj2 = AccessTools.Field(typeof(BaseAI), "m_character")?.GetValue(val12); Character val13 = (Character)((obj2 is Character) ? obj2 : null); if ((Object)(object)val13 != (Object)null) { Rigidbody component4 = ((Component)val13).GetComponent(); if ((Object)(object)component4 != (Object)null) { float num3 = BattleBoarSpawner.Instance?.jumpForce ?? 15f; component4.AddForce(Vector3.up * num3 * component4.mass); component4.AddForce(((Component)val13).transform.forward * num3 * 0.3f * component4.mass); } AccessTools.Field(typeof(Character), "m_maxAirAltitude")?.SetValue(val13, ((Component)val13).transform.position.y); } } } catch { } } jump = false; } } private static Character GetSadleCharacter(Sadle sadle) { if ((Object)(object)sadle == (Object)null) { return null; } object? obj = AccessTools.Field(typeof(Sadle), "m_monsterAI")?.GetValue(sadle); MonsterAI val = (MonsterAI)((obj is MonsterAI) ? obj : null); if ((Object)(object)val == (Object)null) { return null; } object? obj2 = AccessTools.Field(typeof(BaseAI), "m_character")?.GetValue(val); return (Character)((obj2 is Character) ? obj2 : null); } } [BepInPlugin("com.mitch.battleboar", "BattleBoar", "1.0.0")] public class BattleBoarPlugin : BaseUnityPlugin { public const string PluginGUID = "com.mitch.battleboar"; public const string PluginName = "BattleBoar"; public const string PluginVersion = "1.0.0"; public static ConfigEntry SummonKey; public static ConfigEntry BoarHealth; public static ConfigEntry BoarScale; public static ConfigEntry BoarRunSpeed; public static ConfigEntry SpawnDistance; private Harmony harmony; public static BattleBoarPlugin Instance { get; private set; } private void Awake() { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Expected O, but got Unknown //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Expected O, but got Unknown Instance = this; SummonKey = ((BaseUnityPlugin)this).Config.Bind("Controls", "SummonKey", (KeyCode)110, "Key to summon or recall your BattleBoar."); BoarHealth = ((BaseUnityPlugin)this).Config.Bind("Stats", "BoarHealth", 500f, "Health of the BattleBoar."); BoarScale = ((BaseUnityPlugin)this).Config.Bind("Stats", "BoarScale", 1.5f, new ConfigDescription("Scale multiplier for the BattleBoar (1.5 = 50% larger than normal boar).", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 3f), Array.Empty())); BoarRunSpeed = ((BaseUnityPlugin)this).Config.Bind("Stats", "BoarRunSpeed", 8f, "Run speed of the BattleBoar."); SpawnDistance = ((BaseUnityPlugin)this).Config.Bind("General", "SpawnDistance", 15f, "How far ahead the BattleBoar spawns before running to you."); harmony = new Harmony("com.mitch.battleboar"); harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"BattleBoar v1.0.0 loaded!"); } private void Start() { ((Component)this).gameObject.AddComponent(); } private void Update() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer == (Object)null || IsGuiOpen()) { return; } if (Input.GetKeyDown(SummonKey.Value)) { bool flag = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303); bool flag2 = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305); if (flag && flag2) { BattleBoarSpawner.Instance?.ToggleSaddleAdjust(); } else { BattleBoarSpawner.Instance?.SummonOrRecall(); } } if (!((Object)(object)BattleBoarSpawner.Instance != (Object)null) || !BattleBoarSpawner.Instance.saddleAdjustMode) { return; } bool flag3 = Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307); float num = (Input.GetKey((KeyCode)306) ? 5f : 15f); float num2 = (Input.GetKey((KeyCode)306) ? 0.02f : 0.05f); if (flag3) { if (Input.GetKeyDown((KeyCode)273)) { BattleBoarSpawner.Instance.AdjustSaddlePosition(0f, 0f, num2); } if (Input.GetKeyDown((KeyCode)274)) { BattleBoarSpawner.Instance.AdjustSaddlePosition(0f, 0f, 0f - num2); } if (Input.GetKeyDown((KeyCode)276)) { BattleBoarSpawner.Instance.AdjustSaddlePosition(0f - num2, 0f, 0f); } if (Input.GetKeyDown((KeyCode)275)) { BattleBoarSpawner.Instance.AdjustSaddlePosition(num2, 0f, 0f); } if (Input.GetKeyDown((KeyCode)280)) { BattleBoarSpawner.Instance.AdjustSaddlePosition(0f, num2, 0f); } if (Input.GetKeyDown((KeyCode)281)) { BattleBoarSpawner.Instance.AdjustSaddlePosition(0f, 0f - num2, 0f); } } else { if (Input.GetKeyDown((KeyCode)273)) { BattleBoarSpawner.Instance.AdjustSaddleRotation(num, 0f, 0f); } if (Input.GetKeyDown((KeyCode)274)) { BattleBoarSpawner.Instance.AdjustSaddleRotation(0f - num, 0f, 0f); } if (Input.GetKeyDown((KeyCode)276)) { BattleBoarSpawner.Instance.AdjustSaddleRotation(0f, 0f - num, 0f); } if (Input.GetKeyDown((KeyCode)275)) { BattleBoarSpawner.Instance.AdjustSaddleRotation(0f, num, 0f); } if (Input.GetKeyDown((KeyCode)280)) { BattleBoarSpawner.Instance.AdjustSaddleRotation(0f, 0f, num); } if (Input.GetKeyDown((KeyCode)281)) { BattleBoarSpawner.Instance.AdjustSaddleRotation(0f, 0f, 0f - num); } } } private bool IsGuiOpen() { if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) { return true; } if (Console.IsVisible()) { return true; } if (TextInput.IsVisible()) { return true; } if (StoreGui.IsVisible()) { return true; } if (InventoryGui.IsVisible()) { return true; } if (Menu.IsVisible()) { return true; } if (Minimap.IsOpen()) { return true; } return false; } private void OnDestroy() { Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } public static void Log(string msg) { BattleBoarPlugin instance = Instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)msg); } } public static void LogWarn(string msg) { BattleBoarPlugin instance = Instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogWarning((object)msg); } } public static void LogErr(string msg) { BattleBoarPlugin instance = Instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogError((object)msg); } } } }