using System; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("PetPeace")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+e91e5e16ec8005680031e013bcc38046f24b916c")] [assembly: AssemblyProduct("PetPeace")] [assembly: AssemblyTitle("PetPeace")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace PetPeace { internal static class PetPeaceCharacters { internal static readonly string[] PetPrefixes = new string[2] { "DG_Dog", "CT_Cat" }; internal static bool IsPetName(string prefabName) { if (string.IsNullOrWhiteSpace(prefabName)) { return false; } return PetPrefixes.Any((string prefix) => prefabName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)); } internal static string PrefabName(GameObject go) { if ((Object)(object)go == (Object)null) { return null; } string text = ((Object)go).name ?? string.Empty; if (text.EndsWith("(Clone)", StringComparison.Ordinal)) { text = text.Substring(0, text.Length - "(Clone)".Length); } return text.Trim(); } internal static Character TryGetAttacker(HitData hit) { try { return (hit != null) ? hit.GetAttacker() : null; } catch { return null; } } internal static bool IsPlayerAttacker(Character attacker) { return attacker is Player; } } internal static class PetPeaceHitData { internal static DamageTypes TransformDamage(DamageTypes damage, Func transform) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) object obj = damage; FieldInfo[] fields = typeof(DamageTypes).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (!(fieldInfo.FieldType != typeof(float)) && !fieldInfo.IsInitOnly) { float arg = (float)(fieldInfo.GetValue(obj) ?? ((object)0f)); fieldInfo.SetValue(obj, transform(arg)); } } return (DamageTypes)obj; } internal static void ScaleAllDamage(ref HitData hit, float factor) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) hit.m_damage = TransformDamage(hit.m_damage, (float value) => value * factor); } internal static void ZeroAllDamage(ref HitData hit) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) hit.m_damage = TransformDamage(hit.m_damage, (float _) => 0f); hit.m_pushForce = 0f; hit.m_backstabBonus = 1f; } } [HarmonyPatch(typeof(Character), "RPC_Damage", new Type[] { typeof(long), typeof(HitData) })] internal static class CharacterRpcDamagePatch { private static void Prefix(Character __instance, long sender, ref HitData hit) { if ((Object)(object)__instance == (Object)null || hit == null) { return; } string prefabName = PetPeaceCharacters.PrefabName(((Component)__instance).gameObject); Character val = PetPeaceCharacters.TryGetAttacker(hit); string prefabName2 = (((Object)(object)val != (Object)null) ? PetPeaceCharacters.PrefabName(((Component)val).gameObject) : null); bool flag = PetPeaceCharacters.IsPetName(prefabName); bool flag2 = PetPeaceCharacters.IsPetName(prefabName2); if (!flag && !flag2) { return; } if (flag) { if (!PetPeaceCharacters.IsPlayerAttacker(val)) { PetPeaceHitData.ZeroAllDamage(ref hit); } } else if (flag2) { float value = PetPeacePlugin.PetOutgoingDamageMultiplier.Value; PetPeaceHitData.ScaleAllDamage(ref hit, value); } } } [BepInPlugin("godmin.petpeace", "PetPeace", "1.0.0")] public sealed class PetPeacePlugin : BaseUnityPlugin { public const string PluginGuid = "godmin.petpeace"; public const string PluginName = "PetPeace"; public const string PluginVersion = "1.0.0"; private Harmony _harmony; internal static PetPeacePlugin Instance { get; private set; } internal static ConfigEntry PetOutgoingDamageMultiplier { get; private set; } private void Awake() { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown Instance = this; PetOutgoingDamageMultiplier = ((BaseUnityPlugin)this).Config.Bind("General", "PetOutgoingDamageMultiplier", 0.01f, "Multiplier for outgoing combat damage from Marlthon dogs and cats (DG_*, CT_* prefabs). 0.01 = one hundredth of normal damage."); _harmony = new Harmony("godmin.petpeace"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"PetPeace 1.0.0 loaded."); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } Instance = null; } } }