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 VikingHorse v1.0.1
VikingHorse.dll
Decompiled a week agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using M2Horse.Horse; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_guiutils")] [assembly: IgnoresAccessChecksTo("assembly_utils")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("VikingHorse")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("VikingHorse")] [assembly: AssemblyTitle("VikingHorse")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace M2Horse { [BepInPlugin("M2Valheim.VikingHorse", "Viking Horse", "1.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "M2Valheim.VikingHorse"; public const string PluginName = "Viking Horse"; public const string PluginVersion = "1.0.1"; internal static ManualLogSource Log; internal static ConfigEntry<bool> EnableRunChopDamage; internal static ConfigEntry<bool> SuppressRunChopWood; internal static ConfigEntry<KeyCode> CycleSaddlePartsKey; private ButtonConfig _cycleSaddlePartsButton; private void Awake() { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; EnableRunChopDamage = ((BaseUnityPlugin)this).Config.Bind<bool>("Horse", "EnableRunChopDamage", true, "Enables the horse's run-chop damage (clears small vegetation while riding at speed, Asksvin-style). Disable to stop the horse from damaging/destroying vegetation entirely."); SuppressRunChopWood = ((BaseUnityPlugin)this).Config.Bind<bool>("Horse", "SuppressRunChopWood", true, "Suppresses wood/item drops from bushes etc. destroyed by the horse's run-chop damage while riding. Vegetation is still destroyed (path stays clear), just without loot."); CycleSaddlePartsKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Client", "CycleSaddlePartsKey", (KeyCode)103, "Key to cycle through the horse's optional saddle parts (fur carpet / pad) while looking at the saddle, next to the existing Use/Remove saddle prompts."); _cycleSaddlePartsButton = new ButtonConfig { Name = "M2Horse_CycleSaddleParts", Config = CycleSaddlePartsKey }; InputManager.Instance.AddButton("M2Valheim.VikingHorse", _cycleSaddlePartsButton); new Harmony("M2Valheim.VikingHorse").PatchAll(); HorseCreature.Register(); } private void Update() { if (!ZInput.GetButtonDown(_cycleSaddlePartsButton.Name) || (Object)(object)Player.m_localPlayer == (Object)null) { return; } GameObject hoverObject = ((Humanoid)Player.m_localPlayer).GetHoverObject(); Sadle val = (((Object)(object)hoverObject != (Object)null) ? hoverObject.GetComponentInParent<Sadle>() : null); if (!((Object)(object)val == (Object)null)) { ZNetView componentInParent = ((Component)val).GetComponentInParent<ZNetView>(); if ((Object)(object)componentInParent != (Object)null && componentInParent.IsValid()) { componentInParent.InvokeRPC("M2Horse_RequestCycleSaddleVariant", Array.Empty<object>()); } } } } } namespace M2Horse.Horse { internal static class HorseCoatVariants { private static readonly (string Body, string Hair)[] Profiles = new(string, string)[25] { ("Viking_Body_Base", "Viking_Hair_White"), ("Viking_Body_Base", "Viking_Hair_Blond"), ("Viking_Body_Brown", "Viking_Hair_Black"), ("Viking_Body_Brown", "Viking_Hair_Brown"), ("Viking_Body_Brown", "Viking_Hair_Blond"), ("Viking_Body_DarkHead", "Viking_Hair_Black"), ("Viking_Body_DarkHead", "Viking_Hair_White"), ("Viking_Body_DirtyGray", "Viking_Hair_White"), ("Viking_Body_DirtyGray", "Viking_Hair_Black"), ("Viking_Body_DirtyGray", "Viking_Hair_Blond"), ("Viking_Body_Gray", "Viking_Hair_White"), ("Viking_Body_Gray", "Viking_Hair_Black"), ("Viking_Body_Gray", "Viking_Hair_Blond"), ("Viking_Body_Palmolino", "Viking_Hair_White"), ("Viking_Body_Palmolino", "Viking_Hair_Blond"), ("Viking_Body_Palmolino", "Viking_Hair_Black"), ("Viking_Body_Palmolino", "Viking_Hair_Brown"), ("Viking_Body_Palmolino", "Viking_Hair_Red"), ("Viking_Body_Red", "Viking_Hair_Brown"), ("Viking_Body_Red", "Viking_Hair_Red"), ("Viking_Body_Red", "Viking_Hair_Black"), ("Viking_Body_Red", "Viking_Hair_Blond"), ("Viking_Body_Red", "Viking_Hair_White"), ("Viking_Body_Spotted", "Viking_Hair_White"), ("Viking_Body_Spotted", "Viking_Hair_Blond") }; private const string BodyRendererName = "Viking_Horse_LOD0"; private const string HairMatPrefix = "Viking_Hair_"; private static readonly int s_coatProfileHash = StringExtensionMethods.GetStableHashCode("m2horse_coatprofile"); private static Dictionary<string, Material> s_bodyMats; private static Dictionary<string, Material> s_hairMats; private const string ReinsRopeMaterialName = "ReinsRope"; public static Material ReinsRopeMaterial { get; private set; } public static void LoadMaterials(AssetBundle bundle) { s_bodyMats = LoadUnique(bundle, Profiles.Select(((string Body, string Hair) p) => p.Body), "Coat"); s_hairMats = LoadUnique(bundle, Profiles.Select(((string Body, string Hair) p) => p.Hair), "Hair"); ReinsRopeMaterial = bundle.LoadAsset<Material>("ReinsRope"); if ((Object)(object)ReinsRopeMaterial == (Object)null) { Plugin.Log.LogError((object)"[M2Horse] Reins-Material 'ReinsRope' nicht im Bundle gefunden."); } } private static Dictionary<string, Material> LoadUnique(AssetBundle bundle, IEnumerable<string> names, string kind) { Dictionary<string, Material> dictionary = new Dictionary<string, Material>(); foreach (string item in names.Distinct()) { Material val = bundle.LoadAsset<Material>(item); if ((Object)(object)val == (Object)null) { Plugin.Log.LogError((object)("[M2Horse] " + kind + "-Material '" + item + "' nicht im Bundle gefunden.")); } else { dictionary[item] = val; } } return dictionary; } public static void Apply(Character character) { ZNetView component = ((Component)character).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || !component.IsValid()) { return; } ZDO zDO = component.GetZDO(); int? num = GetIndex(zDO); if (!num.HasValue) { if (!component.IsOwner()) { return; } num = Random.Range(0, Profiles.Length); SetIndex(zDO, num.Value); } ApplyToRenderers(((Component)character).transform.Find("Visual"), num.Value); } public static void ApplyToRagdoll(Ragdoll ragdoll, int index) { ApplyToRenderers(((Component)ragdoll).transform, index); } public static int? GetIndex(ZDO zdo) { if (zdo == null) { return null; } int num = zdo.GetInt(s_coatProfileHash, -1); if (num >= 0) { return num; } return null; } public static void SetIndex(ZDO zdo, int index) { if (zdo != null) { zdo.Set(s_coatProfileHash, index, false); } } private static void ApplyToRenderers(Transform root, int index) { if ((Object)(object)root == (Object)null || s_bodyMats == null || s_hairMats == null || index < 0 || index >= Profiles.Length) { return; } (string, string) tuple = Profiles[index]; if (!s_bodyMats.TryGetValue(tuple.Item1, out var value) || !s_hairMats.TryGetValue(tuple.Item2, out var value2)) { return; } SkinnedMeshRenderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<SkinnedMeshRenderer>(); foreach (SkinnedMeshRenderer val in componentsInChildren) { if (((Object)val).name == "Viking_Horse_LOD0") { Material[] sharedMaterials = ((Renderer)val).sharedMaterials; sharedMaterials[0] = value; ((Renderer)val).sharedMaterials = sharedMaterials; continue; } Material[] sharedMaterials2 = ((Renderer)val).sharedMaterials; bool flag = false; for (int j = 0; j < sharedMaterials2.Length; j++) { if ((Object)(object)sharedMaterials2[j] != (Object)null && ((Object)sharedMaterials2[j]).name.StartsWith("Viking_Hair_")) { sharedMaterials2[j] = value2; flag = true; } } if (flag) { ((Renderer)val).sharedMaterials = sharedMaterials2; } } } } internal static class HorseCreature { private const string BundleName = "m2horse"; private const string PrefabName = "M2Horse"; private const string CreatureName = "$m2_horse"; private const string SaddlePrefabName = "SaddleM2Horse"; private const string RagdollPrefabName = "M2Horse_Ragdoll"; public static void Register() { CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); string text = "English"; localization.AddTranslation(ref text, new Dictionary<string, string> { { "m2_horse", "Horse" }, { "item_saddlem2horse", "Horse Saddle" }, { "item_saddlem2horse_description", "A saddle for riding your horse." }, { "m2horse_cyclesaddleparts", "Toggle saddle parts" } }); text = "German"; localization.AddTranslation(ref text, new Dictionary<string, string> { { "m2_horse", "Pferd" }, { "item_saddlem2horse", "Pferdesattel" }, { "item_saddlem2horse_description", "Ein Sattel, um dein Pferd zu reiten." }, { "m2horse_cyclesaddleparts", "Sattelteile umschalten" } }); CreatureManager.OnVanillaCreaturesAvailable += AddCreature; } private static void AddCreature() { //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Expected O, but got Unknown //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Expected O, but got Unknown //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Expected O, but got Unknown //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019d: 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_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Expected O, but got Unknown //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Expected O, but got Unknown CreatureManager.OnVanillaCreaturesAvailable -= AddCreature; Assembly executingAssembly = Assembly.GetExecutingAssembly(); string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string n) => n.EndsWith("m2horse")); if (text == null) { Plugin.Log.LogError((object)"[M2Horse] Embedded resource 'm2horse' nicht gefunden."); return; } AssetBundle val; using (Stream stream = executingAssembly.GetManifestResourceStream(text)) { byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); val = AssetBundle.LoadFromMemory(array); } if ((Object)(object)val == (Object)null) { Plugin.Log.LogError((object)"[M2Horse] AssetBundle konnte nicht geladen werden."); return; } GameObject val2 = val.LoadAsset<GameObject>("M2Horse"); if ((Object)(object)val2 == (Object)null) { Plugin.Log.LogError((object)"[M2Horse] Prefab 'M2Horse' nicht im Bundle gefunden."); val.Unload(false); return; } CreatureConfig val3 = new CreatureConfig(); val3.Name = "$m2_horse"; val3.Faction = (Faction)1; val3.AddConsumable("Dandelion"); val3.AddDropConfig(new DropConfig { Item = "DeerMeat", Chance = 100f, MinAmount = 1, MaxAmount = 2, LevelMultiplier = false }); val3.AddDropConfig(new DropConfig { Item = "DeerHide", Chance = 100f, MinAmount = 1, MaxAmount = 2, LevelMultiplier = false }); val3.AddSpawnConfig(new SpawnConfig { Name = "M2Horse_MeadowsSpawn", SpawnChance = 5f, SpawnInterval = 600f, SpawnDistance = 30f, MaxSpawned = 1, Biome = (Biome)1 }); CreatureManager.Instance.AddCreature(new CustomCreature(val2, true, val3)); RegisterSaddleItem(val); RegisterRagdollPrefab(val); HorseCoatVariants.LoadMaterials(val); val.Unload(false); } private static void RegisterSaddleItem(AssetBundle bundle) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_0061: 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_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown //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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Expected O, but got Unknown GameObject val = bundle.LoadAsset<GameObject>("SaddleM2Horse"); if ((Object)(object)val == (Object)null) { Plugin.Log.LogError((object)"[M2Horse] Prefab 'SaddleM2Horse' nicht im Bundle gefunden."); return; } ItemConfig val2 = new ItemConfig(); val2.CraftingStation = "piece_workbench"; val2.MinStationLevel = 3; val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[3] { new RequirementConfig { Item = "LeatherScraps", Amount = 10 }, new RequirementConfig { Item = "DeerHide", Amount = 5 }, new RequirementConfig { Item = "Bronze", Amount = 3 } }; ItemConfig val3 = val2; ItemManager.Instance.AddItem(new CustomItem(val, true, val3)); } private static void RegisterRagdollPrefab(AssetBundle bundle) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown GameObject val = bundle.LoadAsset<GameObject>("M2Horse_Ragdoll"); if ((Object)(object)val == (Object)null) { Plugin.Log.LogError((object)"[M2Horse] Prefab 'M2Horse_Ragdoll' nicht im Bundle gefunden."); } else { PrefabManager.Instance.AddPrefab(new CustomPrefab(val, true)); } } } [DefaultExecutionOrder(10000)] internal class HorseReinsLine : MonoBehaviour { private Transform _bitL; private Transform _bitR; private Transform _handL; private Transform _handR; private Transform _horse; private LineRenderer _line; private const int PointsPerSegment = 10; private const float SagBitHand = 0.3f; private const float SagHandHand = 0.04f; private const float Width = 0.02f; private const float HandOutward = 0.06f; private const float SideBow = 0.1f; private const float Smoothness = 0.26f; private static readonly Color ReinsTint = new Color(0.502f, 0.1804f, 0f, 1f); public Transform HorseRoot => _horse; public static void Setup(GameObject playerGo, Transform horseRoot, Transform handL, Transform handR) { //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) if ((Object)(object)playerGo == (Object)null || (Object)(object)horseRoot == (Object)null || (Object)(object)handL == (Object)null || (Object)(object)handR == (Object)null || (Object)(object)playerGo.GetComponent<HorseReinsLine>() != (Object)null) { return; } Transform val = Find(horseRoot, "Reins_Root_L") ?? Find(horseRoot, "DEF-Bit_L"); Transform val2 = Find(horseRoot, "Reins_Root_R") ?? Find(horseRoot, "DEF-Bit_R"); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { Plugin.Log.LogWarning((object)"[M2Horse] Bit-Anker fuer Zuegel nicht gefunden -- LineRenderer-Zuegel deaktiviert."); return; } HorseReinsLine horseReinsLine = playerGo.AddComponent<HorseReinsLine>(); horseReinsLine._bitL = val; horseReinsLine._bitR = val2; horseReinsLine._handL = handL; horseReinsLine._handR = handR; horseReinsLine._horse = horseRoot; GameObject val3 = new GameObject("M2Horse_ReinsLine"); val3.transform.SetParent(playerGo.transform, false); LineRenderer val4 = val3.AddComponent<LineRenderer>(); val4.useWorldSpace = true; val4.alignment = (LineAlignment)0; val4.textureMode = (LineTextureMode)0; val4.numCornerVertices = 2; val4.numCapVertices = 2; val4.widthMultiplier = 0.02f; ((Renderer)val4).shadowCastingMode = (ShadowCastingMode)1; ((Renderer)val4).receiveShadows = true; val4.generateLightingData = true; Material val5 = CreateReinsMaterial(horseRoot); if ((Object)(object)val5 != (Object)null) { ((Renderer)val4).material = val5; } horseReinsLine._line = val4; } private void LateUpdate() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0092: 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_0097: 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_00a1: 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) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0175: 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_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: 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_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: 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_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_bitL == (Object)null || (Object)(object)_bitR == (Object)null || (Object)(object)_handL == (Object)null || (Object)(object)_handR == (Object)null || (Object)(object)_line == (Object)null) { return; } Vector3 position = _bitL.position; Vector3 position2 = _handL.position; Vector3 position3 = _handR.position; Vector3 position4 = _bitR.position; Vector3 val = (((Object)(object)_horse != (Object)null) ? _horse.right : Vector3.right); float num = 0.06f; position2 -= val * num; position3 += val * num; int num2 = 31; if (_line.positionCount != num2) { _line.positionCount = num2; } _line.widthMultiplier = 0.02f; Material material = ((Renderer)_line).material; if ((Object)(object)material != (Object)null) { if (material.HasProperty("_Color")) { material.color = ReinsTint; } float num3 = 0.26f; if (material.HasProperty("_Glossiness")) { material.SetFloat("_Glossiness", num3); } if (material.HasProperty("_Smoothness")) { material.SetFloat("_Smoothness", num3); } } float num4 = 0.3f; float num5 = 0.1f; Vector3 bulge = Vector3.down * num4 - val * num5; Vector3 bulge2 = Vector3.down * num4 + val * num5; Vector3 bulge3 = Vector3.down * 0.04f; int idx = 0; idx = WriteSegment(idx, position, position2, bulge, includeStart: true); idx = WriteSegment(idx, position2, position3, bulge3, includeStart: false); idx = WriteSegment(idx, position3, position4, bulge2, includeStart: false); } private int WriteSegment(int idx, Vector3 a, Vector3 b, Vector3 bulge, bool includeStart) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) for (int i = ((!includeStart) ? 1 : 0); i <= 10; i++) { float num = (float)i / 10f; Vector3 val = Vector3.Lerp(a, b, num); float num2 = 1f - Mathf.Pow(Mathf.Abs(0.5f - num) * 2f, 2f); val += bulge * num2; _line.SetPosition(idx++, val); } return idx; } private void OnDestroy() { if ((Object)(object)_line != (Object)null) { if ((Object)(object)((Renderer)_line).material != (Object)null) { Object.Destroy((Object)(object)((Renderer)_line).material); } Object.Destroy((Object)(object)((Component)_line).gameObject); } } private static Transform Find(Transform root, string name) { if ((Object)(object)root == (Object)null) { return null; } Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (((Object)val).name == name) { return val; } } return null; } private static Material CreateReinsMaterial(Transform horseRoot) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown if ((Object)(object)HorseCoatVariants.ReinsRopeMaterial != (Object)null) { return new Material(HorseCoatVariants.ReinsRopeMaterial); } Plugin.Log.LogWarning((object)"[M2Horse] ReinsRope-Material fehlt -- falle auf Belt-Material zurueck."); Material val = FindBeltMaterial(horseRoot); if (!((Object)(object)val != (Object)null)) { return null; } return new Material(val); } private static Material FindBeltMaterial(Transform root) { Renderer val = null; Renderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { if (((Object)val2).name.IndexOf("Belt", StringComparison.OrdinalIgnoreCase) >= 0) { return val2.sharedMaterial; } if ((Object)(object)val == (Object)null && (((Object)val2).name.IndexOf("Bridle", StringComparison.OrdinalIgnoreCase) >= 0 || ((Object)val2).name.IndexOf("Saddle", StringComparison.OrdinalIgnoreCase) >= 0)) { val = val2; } } if (!((Object)(object)val != (Object)null)) { return null; } return val.sharedMaterial; } } internal static class HorseSaddleVariant { private const string FurCarpetRendererName = "Fur_Carpet_LOD0"; private const string PadRendererName = "Pad_LOD0"; private static readonly int s_variantHash = StringExtensionMethods.GetStableHashCode("m2horse_saddlevariant"); private static readonly (bool furCarpet, bool pad)[] Variants = new(bool, bool)[4] { (true, true), (true, false), (false, true), (false, false) }; public static int GetVariant(ZDO zdo) { if (zdo != null) { return zdo.GetInt(s_variantHash, 0); } return 0; } public static int NextVariant(ZDO zdo) { return (GetVariant(zdo) + 1) % Variants.Length; } public static void SetVariant(ZDO zdo, int variant) { if (zdo != null) { zdo.Set(s_variantHash, variant, false); } } public static void Apply(Character character) { ZNetView component = ((Component)character).GetComponent<ZNetView>(); ZDO zdo = ((component != null) ? component.GetZDO() : null); ApplyVariant(((Component)character).transform, GetVariant(zdo)); } public static void ApplyVariant(Transform characterRoot, int variant) { Transform val = characterRoot.Find("Visual"); if (!((Object)(object)val == (Object)null)) { int num = (variant % Variants.Length + Variants.Length) % Variants.Length; var (active, active2) = Variants[num]; SetActiveByName(val, "Fur_Carpet_LOD0", active); SetActiveByName(val, "Pad_LOD0", active2); } } private static void SetActiveByName(Transform root, string name, bool active) { Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (((Object)val).name == name) { ((Component)val).gameObject.SetActive(active); break; } } } } } namespace M2Horse.Horse.Patches { [HarmonyPatch(typeof(Character), "Awake")] internal static class HorseCoatVariantsPatch { private const string PrefabName = "M2Horse"; private const string RequestCycleSaddleVariantRpc = "M2Horse_RequestCycleSaddleVariant"; private const string SetSaddleVariantRpc = "M2Horse_SetSaddleVariant"; private static void Postfix(Character __instance) { if (!(Utils.GetPrefabName(((Component)__instance).gameObject) != "M2Horse")) { HorseCoatVariants.Apply(__instance); RegisterSaddleVariantRpcs(__instance); HorseSaddleVariant.Apply(__instance); } } private static void RegisterSaddleVariantRpcs(Character character) { ZNetView nview = ((Component)character).GetComponent<ZNetView>(); if ((Object)(object)nview == (Object)null || !nview.IsValid() || nview.m_functions.ContainsKey(StringExtensionMethods.GetStableHashCode("M2Horse_RequestCycleSaddleVariant"))) { return; } nview.Register("M2Horse_RequestCycleSaddleVariant", (Action<long>)delegate { if (nview.IsOwner()) { ZDO zDO = nview.GetZDO(); int num = HorseSaddleVariant.NextVariant(zDO); HorseSaddleVariant.SetVariant(zDO, num); nview.InvokeRPC(ZNetView.Everybody, "M2Horse_SetSaddleVariant", new object[1] { num }); } }); nview.Register<int>("M2Horse_SetSaddleVariant", (Action<long, int>)delegate(long sender, int variant) { HorseSaddleVariant.ApplyVariant(((Component)character).transform, variant); }); } } [HarmonyPatch(typeof(EffectList), "Create")] internal static class HorseRagdollColorPatch { private const string PrefabName = "M2Horse_Ragdoll"; private static void Postfix(GameObject[] __result, Transform baseParent) { if ((Object)(object)baseParent == (Object)null || __result == null) { return; } foreach (GameObject val in __result) { Ragdoll component = val.GetComponent<Ragdoll>(); if (!((Object)(object)component == (Object)null) && !(Utils.GetPrefabName(val) != "M2Horse_Ragdoll")) { ZNetView component2 = ((Component)baseParent).GetComponent<ZNetView>(); int? index = HorseCoatVariants.GetIndex((component2 != null) ? component2.GetZDO() : null); if (index.HasValue) { ZNetView component3 = ((Component)component).GetComponent<ZNetView>(); HorseCoatVariants.SetIndex((component3 != null) ? component3.GetZDO() : null, index.Value); HorseCoatVariants.ApplyToRagdoll(component, index.Value); } } } } } [HarmonyPatch(typeof(Ragdoll), "Awake")] internal static class HorseRagdollColorAwakePatch { private const string PrefabName = "M2Horse_Ragdoll"; private static void Postfix(Ragdoll __instance) { if (!(Utils.GetPrefabName(((Component)__instance).gameObject) != "M2Horse_Ragdoll")) { ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); int? index = HorseCoatVariants.GetIndex((component != null) ? component.GetZDO() : null); if (index.HasValue) { HorseCoatVariants.ApplyToRagdoll(__instance, index.Value); } } } } internal static class HorseRidingShared { internal static readonly bool PlayerEffectsEnabled = true; internal static readonly FieldInfo f_shipCameraTilt = AccessTools.Field(typeof(GameCamera), "m_shipCameraTilt"); internal static bool s_originalCameraTilt; } [HarmonyPatch(typeof(Player), "AttachStart")] internal static class HorseAttachStartPatch { private static void Postfix(Player __instance, Transform attachPoint) { if (HorseRidingShared.PlayerEffectsEnabled && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !((Object)(object)attachPoint == (Object)null) && !((Object)(object)((Component)((Component)attachPoint).transform.root).GetComponentInChildren<Sadle>() == (Object)null)) { GameCamera instance = GameCamera.instance; if (Object.op_Implicit((Object)(object)instance)) { HorseRidingShared.s_originalCameraTilt = (bool)HorseRidingShared.f_shipCameraTilt.GetValue(instance); HorseRidingShared.f_shipCameraTilt.SetValue(instance, false); } Transform root = ((Component)attachPoint).transform.root; VisEquipment component = ((Component)__instance).GetComponent<VisEquipment>(); if (!((Object)(object)component == (Object)null)) { HorseReinsLine.Setup(((Component)__instance).gameObject, root, component.m_leftHand, component.m_rightHand); } } } } [HarmonyPatch(typeof(Player), "AttachStop")] internal static class HorseAttachStopPatch { private static void Postfix(Player __instance) { if (HorseRidingShared.PlayerEffectsEnabled && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { GameCamera instance = GameCamera.instance; if ((Object)(object)instance != (Object)null) { HorseRidingShared.f_shipCameraTilt.SetValue(instance, HorseRidingShared.s_originalCameraTilt); } HorseReinsLine component = ((Component)__instance).GetComponent<HorseReinsLine>(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } } } } [HarmonyPatch(typeof(Sadle), "GetHoverText")] internal static class SadleSaddlePartsHintPatch { private const string PrefabName = "M2Horse"; private static void Postfix(Sadle __instance, ref string __result) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) if (!(Utils.GetPrefabName(((Component)((Component)__instance).transform.root).gameObject) != "M2Horse") && !((Object)(object)Player.m_localPlayer == (Object)null) && !(Vector3.Distance(((Component)__instance).transform.position, ((Component)Player.m_localPlayer).transform.position) > __instance.m_maxUseRange)) { string text = ((object)Plugin.CycleSaddlePartsKey.Value/*cast due to .constrained prefix*/).ToString(); __result += Localization.instance.Localize("\n[<color=yellow><b>" + text + "</b></color>] $m2horse_cyclesaddleparts"); } } } [HarmonyPatch(typeof(Destructible), "Destroy")] internal static class HorseRunChopNoDropPatch { private const string HorsePrefabNamePrefix = "M2Horse"; internal static bool s_suppressDrop; private static void Prefix(HitData hit) { s_suppressDrop = false; if (Plugin.SuppressRunChopWood.Value) { Character val = ((hit != null) ? hit.GetAttacker() : null); s_suppressDrop = (Object)(object)val != (Object)null && ((Object)val).name.StartsWith("M2Horse"); } } private static void Postfix() { s_suppressDrop = false; } } [HarmonyPatch(typeof(DropOnDestroyed), "OnDestroyed")] internal static class HorseRunChopNoDropOnDestroyedPatch { private static bool Prefix() { return !HorseRunChopNoDropPatch.s_suppressDrop; } } [HarmonyPatch(typeof(MovementDamage), "Update")] internal static class HorseRunChopEnabledPatch { private const string HorsePrefabNamePrefix = "M2Horse"; private static void Postfix(MovementDamage __instance) { if (!Plugin.EnableRunChopDamage.Value && ((Object)((Component)__instance).gameObject).name.StartsWith("M2Horse") && (Object)(object)__instance.m_runDamageObject != (Object)null) { __instance.m_runDamageObject.SetActive(false); } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }