using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using HarmonyLib; using MelonLoader; using MelonLoader.Preferences; using damagediff; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: MelonInfo(typeof(Main), "damagediff", "1.1.0", "你的名字", null)] [assembly: MelonGame("ReLUGames", "MIMESIS")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("damagediff")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("damagediff")] [assembly: AssemblyTitle("damagediff")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace damagediff; public class Main : MelonMod { public static MelonPreferences_Category ModCategory; public static MelonPreferences_Entry DamageMultiplierConfig; public override void OnInitializeMelon() { ModCategory = MelonPreferences.CreateCategory("damagediff"); DamageMultiplierConfig = ModCategory.CreateEntry("DamageMultiplier", 0.3f, "Damage Multiplier (傷害倍率)", "玩家受到的傷害倍率。0.3 代表只承受 30% 傷害(減傷 70%),0.0 代表完全無敵。", false, false, (ValueValidator)null, (string)null); MelonPreferences.Save(); ((MelonBase)this).LoggerInstance.Msg($"\ud83c\udf89 damagediff 重新出發!當前減傷倍率為: {DamageMultiplierConfig.Value}"); } } [HarmonyPatch(typeof(StatManager), "OnDamaged")] public class StatManagerPatch { public static void Prefix(StatManager __instance, ApplyDamageArgs args) { if (args == null || args.Victim == null || (!(args.Victim is VPlayer) && !((object)args.Victim).GetType().Name.Contains("Player"))) { return; } long damage = args.Damage; if (damage <= 0) { return; } float num = Main.DamageMultiplierConfig.Value; if (num < 0f) { num = 0f; } long num2 = (long)((float)damage * num); try { AccessTools.Field(typeof(ApplyDamageArgs), "Damage").SetValue(args, num2); int num3 = (int)((1f - num) * 100f); MelonLogger.Msg($"[damagediff] 減傷 {num3}% 運作中!原本傷害:{damage} -> 最終傷害:{args.Damage}"); } catch (Exception ex) { MelonLogger.Error("[damagediff 錯誤] 改寫唯讀欄位失敗: " + ex.Message); } } }