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.7
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 TMPro; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [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("Debug")] [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 { internal enum ControllerButton { None, HideWeapon, SecondaryAttack, Run, A, B, X, Y, LeftBumper, RightBumper, LeftTrigger, RightTrigger, LeftStickPress, RightStickPress, DPadUp, DPadDown, DPadLeft, DPadRight, Select } internal sealed class ControllerBinding { public readonly ConfigEntry<ControllerButton> Button; public readonly ConfigEntry<bool> WithBlock; public string ZInputName { get { ControllerButton value = Button.Value; if (1 == 0) { } string result = value switch { ControllerButton.HideWeapon => "JoyHide", ControllerButton.SecondaryAttack => "JoySecondaryAttack", ControllerButton.Run => "JoyRun", ControllerButton.A => "JoyButtonA", ControllerButton.B => "JoyButtonB", ControllerButton.X => "JoyButtonX", ControllerButton.Y => "JoyButtonY", ControllerButton.LeftBumper => "JoyLBumper", ControllerButton.RightBumper => "JoyRBumper", ControllerButton.LeftTrigger => "JoyLTrigger", ControllerButton.RightTrigger => "JoyRTrigger", ControllerButton.LeftStickPress => "JoyLStick", ControllerButton.RightStickPress => "JoyRStick", ControllerButton.DPadUp => "JoyDPadUp", ControllerButton.DPadDown => "JoyDPadDown", ControllerButton.DPadLeft => "JoyDPadLeft", ControllerButton.DPadRight => "JoyDPadRight", ControllerButton.Select => "JoyBack", _ => null, }; if (1 == 0) { } return result; } } private ControllerBinding(ConfigEntry<ControllerButton> button, ConfigEntry<bool> withBlock) { Button = button; WithBlock = withBlock; } public static ControllerBinding Bind(ConfigFile config, string section, string name, string does, ControllerButton button, bool withBlock) { return new ControllerBinding(config.Bind<ControllerButton>(section, name + "Controller", button, "Controller button that " + does + ". HideWeapon, SecondaryAttack and Run are Valheim's own actions and follow the controller layout chosen in the game's settings; the others are fixed buttons, which may also do something else in the game. None: no controller button."), config.Bind<bool>(section, name + "ControllerWithBlock", withBlock, "Whether the block button has to be held together with the controller button above (the button Valheim uses for its own controller combinations).")); } public bool Down() { return Ready() && ZInput.GetButtonDown(ZInputName); } public bool Held() { return Ready() && ZInput.GetButton(ZInputName); } public void Consume() { string zInputName = ZInputName; if (WithBlock.Value && zInputName != null && ZInput.GetButtonDown(zInputName)) { ZInput.ResetButtonStatus(zInputName); } } public string Glyphs() { string zInputName = ZInputName; if (zInputName == null) { return string.Empty; } return WithBlock.Value ? GamepadHints.Glyphs(" + ", "JoyAltKeys", zInputName) : GamepadHints.Glyph(zInputName); } private bool Ready() { return ZInputName != null && ZInput.IsGamepadActive() && (!WithBlock.Value || ZInput.GetButton("JoyAltKeys")); } } internal static class GamepadHints { public static UIGamePad Bind(Button button, string zinputKey, string glyph = null, KeyCode keyCode = (KeyCode)0) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)button == (Object)null) { return null; } UIGamePad val = ((Component)button).GetComponent<UIGamePad>(); if ((Object)(object)val == (Object)null) { val = ((Component)button).gameObject.AddComponent<UIGamePad>(); } val.m_zinputKey = zinputKey ?? string.Empty; val.m_keyCode = keyCode; if ((Object)(object)val.m_hint == (Object)null) { val.m_hint = CreateHint(((Component)button).transform, glyph ?? zinputKey); } return val; } public static GameObject CreateHint(Transform parent, params string[] glyphs) { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown GameObject val = FindTemplate(); if ((Object)(object)val == (Object)null || (Object)(object)parent == (Object)null) { return null; } GameObject val2 = Object.Instantiate<GameObject>(val, parent, false); ((Object)val2).name = "gamepad_hint"; UIInputHint component = val2.GetComponent<UIInputHint>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } foreach (Transform item in val2.transform) { Transform val3 = item; ((Component)val3).gameObject.SetActive(true); } Graphic[] componentsInChildren = val2.GetComponentsInChildren<Graphic>(true); foreach (Graphic val4 in componentsInChildren) { val4.raycastTarget = false; } val2.AddComponent<GamepadGlyph>().Set(string.Empty, glyphs); val2.SetActive(false); return val2; } public static TMP_Text CreateText(Transform parent, string name) { GameObject val = FindTemplate(); TMP_Text val2 = (((Object)(object)val != (Object)null) ? val.GetComponentInChildren<TMP_Text>(true) : null); if ((Object)(object)val2 == (Object)null || (Object)(object)parent == (Object)null) { return null; } TMP_Text val3 = Object.Instantiate<TMP_Text>(val2, parent, false); ((Object)val3).name = name; ((Graphic)val3).raycastTarget = false; ((Component)val3).gameObject.SetActive(true); return val3; } public static string Glyphs(string separator, params string[] names) { if (names == null || names.Length == 0) { return string.Empty; } string[] array = new string[names.Length]; for (int i = 0; i < names.Length; i++) { array[i] = Glyph(names[i]); } return string.Join(separator, array); } public static string Glyph(string name) { if (ZInput.instance == null || string.IsNullOrEmpty(name)) { return string.Empty; } if (!ZInput.s_gamepadSpriteMap.TryGetValue(name, out var value)) { return ZInput.instance.GetBoundKeyString(name, true); } string[] array = ZInput.instance.GetBoundKeyString("JoyButtonA", true).Split(new char[1] { '"' }); string value2; return (array.Length > 1 && value.TryGetValue(array[1], out value2)) ? ("<sprite=\"" + array[1] + "\" name=\"" + value2 + "\">") : string.Empty; } private static GameObject FindTemplate() { SkillsDialog val = (((Object)(object)InventoryGui.instance != (Object)null) ? InventoryGui.instance.m_skillsDialog : null); if ((Object)(object)val == (Object)null) { return null; } UIGamePad[] componentsInChildren = ((Component)val).GetComponentsInChildren<UIGamePad>(true); foreach (UIGamePad val2 in componentsInChildren) { GameObject hint = val2.m_hint; if ((Object)(object)hint != (Object)null && (Object)(object)hint.GetComponent<UIInputHint>() != (Object)null && (Object)(object)hint.GetComponentInChildren<TMP_Text>(true) != (Object)null) { return hint; } } return null; } } internal sealed class GamepadGlyph : MonoBehaviour { private string _separator = string.Empty; private string[] _glyphs; private TMP_Text _text; public void Set(string separator, params string[] glyphs) { _separator = separator ?? string.Empty; _glyphs = glyphs; Refresh(); } private void OnEnable() { ZInput.OnInputLayoutChanged += Refresh; Refresh(); } private void OnDisable() { ZInput.OnInputLayoutChanged -= Refresh; } private void Refresh() { if (_glyphs != null) { if ((Object)(object)_text == (Object)null) { _text = ((Component)this).GetComponentInChildren<TMP_Text>(true); } if ((Object)(object)_text != (Object)null) { _text.text = GamepadHints.Glyphs(_separator, _glyphs); } } } } [BepInPlugin("M2Valheim.VikingHorse", "Viking Horse", "1.0.7")] [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.7"; internal static ManualLogSource Log; internal static ConfigEntry<bool> EnableRunChopDamage; internal static ConfigEntry<bool> SuppressRunChopWood; internal static ConfigEntry<KeyCode> CycleSaddlePartsKey; internal static ConfigEntry<KeyCode> CycleSaddlePartsModifier; internal static ControllerBinding CycleSaddlePartsController; private ButtonConfig _cycleSaddlePartsButton; private void Awake() { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_00f0: 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)113, "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."); CycleSaddlePartsModifier = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Client", "CycleSaddlePartsModifier", (KeyCode)304, "Modifier key that must be held together with CycleSaddlePartsKey. Set to 'None' to use CycleSaddlePartsKey alone."); CycleSaddlePartsController = ControllerBinding.Bind(((BaseUnityPlugin)this).Config, "Client", "CycleSaddleParts", "cycles through the horse's optional saddle parts while looking at the saddle", ControllerButton.HideWeapon, withBlock: true); _cycleSaddlePartsButton = new ButtonConfig { Name = "M2Horse_CycleSaddleParts", Config = CycleSaddlePartsKey }; InputManager.Instance.AddButton("M2Valheim.VikingHorse", _cycleSaddlePartsButton); new Harmony("M2Valheim.VikingHorse").PatchAll(); HorseCreature.Register(); } private void Update() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) bool flag = ZInput.GetButtonDown(_cycleSaddlePartsButton.Name) && ((int)CycleSaddlePartsModifier.Value == 0 || Input.GetKey(CycleSaddlePartsModifier.Value)); bool flag2 = CycleSaddlePartsController.Down(); if ((!flag && !flag2) || (Object)(object)Player.m_localPlayer == (Object)null || !((Character)Player.m_localPlayer).TakeInput()) { 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)) { if (flag2) { CycleSaddlePartsController.Consume(); } ZNetView componentInParent = ((Component)val).GetComponentInParent<ZNetView>(); if ((Object)(object)componentInParent != (Object)null && componentInParent.IsValid()) { componentInParent.InvokeRPC("M2Horse_RequestCycleSaddleVariant", Array.Empty<object>()); } } } internal static string FormatCycleSaddlePartsKey() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Invalid comparison between Unknown and I4 //IL_0056: Unknown result type (might be due to invalid IL or missing references) if (ZInput.IsGamepadActive()) { string text = CycleSaddlePartsController.Glyphs(); if (!string.IsNullOrEmpty(text)) { return text; } } string text2 = FormatKeyName(CycleSaddlePartsKey.Value); if ((int)CycleSaddlePartsModifier.Value == 0) { return text2; } return FormatKeyName(CycleSaddlePartsModifier.Value) + " + " + text2; } private unsafe static string FormatKeyName(KeyCode key) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected I4, but got Unknown KeyCode val = key; KeyCode val2 = val; switch (val2 - 303) { case 0: case 1: return "Shift"; case 2: case 3: return "Ctrl"; case 4: case 5: return "Alt"; default: return ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString(); } } } } 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); } Transform root = ((Component)character).transform.Find("Visual"); ApplyToRenderers(root, 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); return (num < 0) ? ((int?)null) : new int?(num); } 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" } }); text = "Chinese"; localization.AddTranslation(ref text, new Dictionary<string, string> { { "m2_horse", "马" }, { "item_saddlem2horse", "马鞍" }, { "item_saddlem2horse_description", "用来骑马的马鞍。" }, { "m2horse_cyclesaddleparts", "切换马鞍部件" } }); text = "Russian"; localization.AddTranslation(ref text, new Dictionary<string, string> { { "m2_horse", "Лошадь" }, { "item_saddlem2horse", "Седло для лошади" }, { "item_saddlem2horse_description", "Седло, чтобы ездить верхом на лошади." }, { "m2horse_cyclesaddleparts", "Переключить части седла" } }); Dictionary<string, string> dictionary = new Dictionary<string, string> { { "m2_horse", "Cavalo" }, { "item_saddlem2horse", "Sela de cavalo" }, { "item_saddlem2horse_description", "Uma sela para montar seu cavalo." }, { "m2horse_cyclesaddleparts", "Alternar partes da sela" } }; text = "Portuguese_Brazilian"; localization.AddTranslation(ref text, dictionary); text = "Portuguese_European"; localization.AddTranslation(ref text, dictionary); CreatureManager.OnVanillaCreaturesAvailable += AddCreature; } private static void AddCreature() { //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Expected O, but got Unknown //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_014f: 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_0163: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Expected O, but got Unknown //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: 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_01b5: Expected O, but got Unknown //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Expected O, but got Unknown //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_022a: 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, BiomeArea = (BiomeArea)2, MinAltitude = 2f }); 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_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown //IL_0051: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00be: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Expected O, but got Unknown 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_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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: 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_01a1: 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_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: 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_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: 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) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) 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_0018: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) int num = ((!includeStart) ? 1 : 0); for (int i = num; i <= 10; i++) { float num2 = (float)i / 10f; Vector3 val = Vector3.Lerp(a, b, num2); float num3 = 1f - Mathf.Pow(Mathf.Abs(0.5f - num2) * 2f, 2f); val += bulge * num3; _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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) 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); return (!((Object)(object)val != (Object)null)) ? ((Material)null) : 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; } } return ((Object)(object)val != (Object)null) ? val.sharedMaterial : null; } } 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) { return (zdo != null) ? zdo.GetInt(s_variantHash, 0) : 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>(); ZDO zdo = ((component2 != null) ? component2.GetZDO() : null); int? index = HorseCoatVariants.GetIndex(zdo); if (index.HasValue) { ZNetView component3 = ((Component)component).GetComponent<ZNetView>(); ZDO zdo2 = ((component3 != null) ? component3.GetZDO() : null); HorseCoatVariants.SetIndex(zdo2, 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>(); ZDO zdo = ((component != null) ? component.GetZDO() : null); int? index = HorseCoatVariants.GetIndex(zdo); 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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) 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 = Plugin.FormatCycleSaddlePartsKey(); __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) { } } }