using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using Glimuleikar.Configs; using HarmonyLib; using Jotunn; using Jotunn.Entities; using Jotunn.Managers; using UnityEngine; using WizshBoneTwitchIntegration.Harmony; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("Glimuleikar")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Glimuleikar")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("0.0.1")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.1.0")] namespace WizshBoneTwitchIntegration.Harmony { [HarmonyPatch] public class DamagePatchesWBTI { [HarmonyPrefix] [HarmonyPatch(typeof(WearNTear), "Damage")] public static bool WearNTearDamage_Prefix(WearNTear __instance, HitData hit) { try { if ((Object)(object)__instance == (Object)null || hit == null) { return true; } Logger.LogWarning((object)PluginConfig.configDamageStructuresEnable.Value); return PluginConfig.configDamageStructuresEnable.Value; } catch (Exception ex) { Logger.LogError((object)("Something went wrong in WearNTearDamage_Prefix: " + ex)); return true; } } [HarmonyPrefix] [HarmonyPatch(typeof(Character), "Damage")] public static bool CharacterDamage_Prefix(Character __instance, ref HitData hit) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Invalid comparison between Unknown and I4 //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Invalid comparison between Unknown and I4 //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Invalid comparison between Unknown and I4 //IL_0164: Unknown result type (might be due to invalid IL or missing references) try { if ((int)hit.m_hitType == 3) { Logger.LogWarning((object)("Fall damage: " + PluginConfig.configDamageFallEnable.Value)); return PluginConfig.configDamageFallEnable.Value; } Character attacker = hit.GetAttacker(); if ((Object)(object)attacker == (Object)null) { return true; } Logger.LogWarning((object)("Hit type: " + ((object)(HitType)(ref hit.m_hitType)).ToString())); Logger.LogWarning((object)("Ignore PVP: " + hit.m_ignorePVP)); Logger.LogWarning((object)("Total damage: " + hit.GetTotalDamage())); Logger.LogWarning((object)("Attacker name: " + ((Object)attacker).name)); Logger.LogWarning((object)("Attacker type: " + ((object)attacker).GetType())); Faction faction = attacker.GetFaction(); Logger.LogWarning((object)("Attacker faction: " + ((object)(Faction)(ref faction)).ToString())); if ((int)hit.m_hitType == 2 && !PluginConfig.configDamagePlayersEnable.Value) { Logger.LogWarning((object)("Player hit: " + PluginConfig.configDamagePlayersEnable.Value)); hit.m_damage = default(DamageTypes); return true; } if ((int)hit.m_hitType == 1) { Logger.LogWarning((object)("Monster hit: " + PluginConfig.configDamageMonstersEnable.Value)); return PluginConfig.configDamageMonstersEnable.Value; } return true; } catch (Exception ex) { Logger.LogError((object)("Something went wrong in CharacterDamage_Prefix: " + ex)); return true; } } } [HarmonyPatch] public class LoxPatchesWBTI { private const string LoxName = "Lox"; private const string RunHitDamagerName = "RunHitDamager"; [HarmonyPostfix] [HarmonyPatch(typeof(Character), "Awake")] public static void Character_Awake_Postfix(Character __instance) { try { if (IsLox(__instance)) { ApplyHitFriendly(__instance); } } catch (Exception ex) { Logger.LogError((object)("Something went wrong in Character_Awake_Postfix: " + ex)); } } [HarmonyPostfix] [HarmonyPatch(typeof(Tameable), "Tame")] public static void Tameable_Tame_Postfix(Tameable __instance) { try { Character component = ((Component)__instance).GetComponent(); if (!((Object)(object)component == (Object)null) && IsLox(component)) { ApplyHitFriendly(component); } } catch (Exception ex) { Logger.LogError((object)("Something went wrong in Tameable_Tame_Postfix: " + ex)); } } public static void OnTamedLoxDamageSettingChanged() { try { List allCharacters = Character.GetAllCharacters(); foreach (Character item in allCharacters) { if (IsLox(item) && item.IsTamed()) { ApplyHitFriendly(item); } } } catch (Exception ex) { Logger.LogError((object)("Something went wrong in OnTamedLoxDamageSettingChanged: " + ex)); } } private static void ApplyHitFriendly(Character lox) { if (lox.IsTamed()) { Aoe runHitDamagerAoe = GetRunHitDamagerAoe(lox); if ((Object)(object)runHitDamagerAoe == (Object)null) { Logger.LogWarning((object)("Could not find Aoe component on RunHitDamager of " + ((Object)lox).name + ".")); return; } runHitDamagerAoe.m_hitFriendly = PluginConfig.configDamageTamedLoxEnable.Value; Logger.LogWarning((object)$"Set m_hitFriendly to {runHitDamagerAoe.m_hitFriendly} on {((Object)lox).name}."); } } private static Aoe GetRunHitDamagerAoe(Character lox) { Aoe[] componentsInChildren = ((Component)lox).GetComponentsInChildren(true); Aoe[] array = componentsInChildren; foreach (Aoe val in array) { if (((Object)((Component)val).gameObject).name == "RunHitDamager") { return val; } } return null; } private static bool IsLox(Character character) { return (Object)(object)character != (Object)null && ((Object)character).name.Contains("Lox"); } } } namespace Glimuleikar { [BepInPlugin("DeathWizsh.Glimuleikar", "Glimuleikar", "0.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] internal class Glimuleikar : BaseUnityPlugin { public const string PluginGUID = "DeathWizsh.Glimuleikar"; public const string PluginName = "Glimuleikar"; public const string PluginVersion = "0.0.1"; public static Glimuleikar Instance; private static readonly Harmony harmony = new Harmony("DeathWizsh.Glimuleikar"); public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization(); private void Awake() { Instance = this; PluginConfig.Init(); harmony.PatchAll(Assembly.GetExecutingAssembly()); } } } namespace Glimuleikar.Configs { internal static class PluginConfig { public static string sectionDamage = "Damage"; public static ConfigEntry configDamageStructuresEnable; public static ConfigEntry configDamagePlayersEnable; public static ConfigEntry configDamageFallEnable; public static ConfigEntry configDamageMonstersEnable; public static ConfigEntry configDamageTamedLoxEnable; public static ConfigEntry configHarpoonMaxRopeLength; public static ConfigEntry configHarpoonPullDuration; private static int entryCount = 1000; public static void Init() { InitGeneralConfig(); } public static void InitGeneralConfig() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Expected O, but got Unknown //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Expected O, but got Unknown //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Expected O, but got Unknown //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Expected O, but got Unknown //IL_0192: 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_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Expected O, but got Unknown //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Expected O, but got Unknown //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Expected O, but got Unknown //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Expected O, but got Unknown configDamageStructuresEnable = ((BaseUnityPlugin)Glimuleikar.Instance).Config.Bind(sectionDamage, "Enable damage to structures", true, new ConfigDescription("Whether the damage to structures is enabled", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); configDamageStructuresEnable.SettingChanged += delegate { Logger.LogWarning((object)("Structure damage setting changed to: " + configDamageStructuresEnable.Value)); }; configDamagePlayersEnable = ((BaseUnityPlugin)Glimuleikar.Instance).Config.Bind(sectionDamage, "Enable player damage", true, new ConfigDescription("Whether the damage from players is enabled", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); configDamagePlayersEnable.SettingChanged += delegate { Logger.LogWarning((object)("Player damage setting changed to: " + configDamagePlayersEnable.Value)); }; configDamageFallEnable = ((BaseUnityPlugin)Glimuleikar.Instance).Config.Bind(sectionDamage, "Enable fall damage", true, new ConfigDescription("Whether fall damage is enabled", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); configDamageFallEnable.SettingChanged += delegate { Logger.LogWarning((object)("Fall damage setting changed to: " + configDamageFallEnable.Value)); }; configDamageMonstersEnable = ((BaseUnityPlugin)Glimuleikar.Instance).Config.Bind(sectionDamage, "Enable monster damage", true, new ConfigDescription("Whether the damage from monsters is enabled", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); configDamageMonstersEnable.SettingChanged += delegate { Logger.LogWarning((object)("Monster damage setting changed to: " + configDamageMonstersEnable.Value)); }; configDamageTamedLoxEnable = ((BaseUnityPlugin)Glimuleikar.Instance).Config.Bind(sectionDamage, "Enable tamed Lox damage to players", false, new ConfigDescription("Whether tamed Lox can damage players by running into them", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true, Order = HandleOrder() } })); configDamageTamedLoxEnable.SettingChanged += delegate { Logger.LogWarning((object)("Tamed Lox damage setting changed to: " + configDamageTamedLoxEnable.Value)); LoxPatchesWBTI.OnTamedLoxDamageSettingChanged(); }; } private static int HandleOrder() { entryCount--; return (entryCount >= 0) ? entryCount : 0; } } }