From 9907a155b2f86b9283538fc8ec240786911a4887 Mon Sep 17 00:00:00 2001 From: Pokachi Date: Sun, 30 May 2021 00:18:02 -0700 Subject: [PATCH 1/4] Moved patching to a separate class. Also added check to make sure not to use mod when the game is public lobby --- DifficultyMod/Core/DifficultyPatcher.cs | 115 +++++++++++++++++++++++ DifficultyMod/Core/DifficultySettings.cs | 86 +---------------- DifficultyMod/DifficultyMod.cs | 5 +- DifficultyMod/DifficultyMod.csproj | 1 + 4 files changed, 120 insertions(+), 87 deletions(-) create mode 100644 DifficultyMod/Core/DifficultyPatcher.cs diff --git a/DifficultyMod/Core/DifficultyPatcher.cs b/DifficultyMod/Core/DifficultyPatcher.cs new file mode 100644 index 0000000..4a5740e --- /dev/null +++ b/DifficultyMod/Core/DifficultyPatcher.cs @@ -0,0 +1,115 @@ +using Boardgame; +using Boardgame.BoardEntities; +using Boardgame.Networking; +using HarmonyLib; +using System.Collections.Generic; +using System.Reflection; +using System.Reflection.Emit; +using UnityEngine; + +namespace DemeoMods.DifficultyMod.Core +{ + class DifficultyPatcher + { + private static GameStateMachine StateMachine { get; set; } + + public DifficultyPatcher() + { + StateMachine = GameObject.Find("GameLogic").GetComponent(); + } + + public static int ModifyEnemyHPMultiplier(int defaultHP, PieceConfig pieceConfig) + { + // Do not modify the HP if the game is public (i.e. anyone can join without room code) + if (!IsPrivateGame()) + { + return defaultHP; + } + + if (pieceConfig.HasPieceType(DataKeys.PieceType.Enemy)) + { + return (int)(defaultHP * DifficultySettings.EnemyHPMultiplier); + } + + return defaultHP; + } + + public static int ModifyEnemyAttackMultiplier(int defaultAttack, PieceConfig pieceConfig) + { + + // Do not modify the Attack if the game is public (i.e. anyone can join without room code) + if (!IsPrivateGame()) + { + return defaultAttack; + } + + if (pieceConfig.HasPieceType(DataKeys.PieceType.Enemy)) + { + return (int)(defaultAttack * DifficultySettings.EnemyAttackMultiplier); + } + + return defaultAttack; + } + + private static bool IsPrivateGame() + { + CreateGameMode gameMode = (CreateGameMode)(typeof(GameStateMachine).GetField("createGameMode", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(StateMachine)); + return gameMode == CreateGameMode.Private; + } + + [HarmonyPatch(typeof(Piece), "CreatePiece")] + public static class EnemyHPMultiplierPatcher + { + static MethodInfo m_MyExtraMethod = AccessTools.Method(typeof(DifficultyPatcher), nameof(ModifyEnemyHPMultiplier), new[] { typeof(int), typeof(PieceConfig) }); + + static IEnumerable Transpiler(IEnumerable instructions) + { + foreach (CodeInstruction instruction in instructions) + { + if (instruction.opcode == OpCodes.Callvirt) + { + string strOperand = instruction.operand.ToString(); + if (strOperand.Contains("get_StartHealth")) + { + yield return instruction; + + yield return new CodeInstruction(OpCodes.Ldarg_0); + yield return new CodeInstruction(OpCodes.Call, m_MyExtraMethod); + + continue; + } + } + + yield return instruction; + } + } + } + + [HarmonyPatch(typeof(Piece), "CreatePiece")] + public static class EnemyAttackMultiplierPatcher + { + static MethodInfo m_MyExtraMethod = AccessTools.Method(typeof(DifficultyPatcher), nameof(ModifyEnemyAttackMultiplier), new[] { typeof(int), typeof(PieceConfig) }); + + static IEnumerable Transpiler(IEnumerable instructions) + { + foreach (CodeInstruction instruction in instructions) + { + if (instruction.opcode == OpCodes.Callvirt) + { + string strOperand = instruction.operand.ToString(); + if (strOperand.Contains("get_AttackDamage")) + { + yield return instruction; + + yield return new CodeInstruction(OpCodes.Ldarg_0); + yield return new CodeInstruction(OpCodes.Call, m_MyExtraMethod); + + continue; + } + } + yield return instruction; + } + } + } + } +} diff --git a/DifficultyMod/Core/DifficultySettings.cs b/DifficultyMod/Core/DifficultySettings.cs index 3dad923..17750b7 100644 --- a/DifficultyMod/Core/DifficultySettings.cs +++ b/DifficultyMod/Core/DifficultySettings.cs @@ -1,10 +1,4 @@ -using Boardgame; -using Boardgame.BoardEntities; -using HarmonyLib; -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Reflection.Emit; +using System; namespace DemeoMods.DifficultyMod.Core { @@ -38,17 +32,6 @@ public static void IncreaseEnemyHPMultiplier(Action callBack) callBack(EnemyHPMultiplier); } - public static int ModifyEnemyHPMultiplier(int defaultHP, PieceConfig pieceConfig) - { - if (pieceConfig.HasPieceType(DataKeys.PieceType.Enemy)) - { - return (int)(defaultHP * EnemyHPMultiplier); - } - - return defaultHP; - } - - public static void DecreaseEnemyAttackMultiplier(Action callBack) { if (EnemyAttackMultiplier > ENEMY_ATTACK_MULTIPLIER_MIN) @@ -68,72 +51,5 @@ public static void IncreaseEnemyAttackMultiplier(Action callBack) callBack(EnemyAttackMultiplier); } - - public static int ModifyEnemyAttackMultiplier(int defaultAttack, PieceConfig pieceConfig) - { - if (pieceConfig.HasPieceType(DataKeys.PieceType.Enemy)) - { - return (int)(defaultAttack * EnemyAttackMultiplier); - } - - return defaultAttack; - } - - [HarmonyPatch(typeof(Piece), "CreatePiece")] - public static class EnemyHPMultiplierPatcher - { - private const int numInstructionToWait = 1; - static MethodInfo m_MyExtraMethod = AccessTools.Method(typeof(DifficultySettings), nameof(ModifyEnemyHPMultiplier), new[] { typeof(int), typeof(PieceConfig) }); - - static IEnumerable Transpiler(IEnumerable instructions) - { - foreach (CodeInstruction instruction in instructions) - { - if (instruction.opcode == OpCodes.Callvirt) - { - string strOperand = instruction.operand.ToString(); - if (strOperand.Contains("get_StartHealth")) - { - yield return instruction; - - yield return new CodeInstruction(OpCodes.Ldarg_0); - yield return new CodeInstruction(OpCodes.Call, m_MyExtraMethod); - - continue; - } - } - - yield return instruction; - } - } - } - - [HarmonyPatch(typeof(Piece), "CreatePiece")] - public static class EnemyAttackMultiplierPatcher - { - private const int numInstructionToWait = 1; - static MethodInfo m_MyExtraMethod = AccessTools.Method(typeof(DifficultySettings), nameof(ModifyEnemyAttackMultiplier), new[] { typeof(int), typeof(PieceConfig) }); - - static IEnumerable Transpiler(IEnumerable instructions) - { - foreach (CodeInstruction instruction in instructions) - { - if (instruction.opcode == OpCodes.Callvirt) - { - string strOperand = instruction.operand.ToString(); - if (strOperand.Contains("get_AttackDamage")) - { - yield return instruction; - - yield return new CodeInstruction(OpCodes.Ldarg_0); - yield return new CodeInstruction(OpCodes.Call, m_MyExtraMethod); - - continue; - } - } - yield return instruction; - } - } - } } } \ No newline at end of file diff --git a/DifficultyMod/DifficultyMod.cs b/DifficultyMod/DifficultyMod.cs index 13e22b9..f12347a 100644 --- a/DifficultyMod/DifficultyMod.cs +++ b/DifficultyMod/DifficultyMod.cs @@ -1,4 +1,5 @@ -using DemeoMods.DifficultyMod.UI; +using DemeoMods.DifficultyMod.Core; +using DemeoMods.DifficultyMod.UI; using MelonLoader; using UnityEngine; @@ -14,7 +15,7 @@ public override void OnSceneWasLoaded(int buildIndex, string sceneName) { MelonLogger.Msg("Initializing..."); new GameObject("Difficulty Menu", typeof(DifficultyMenu)); - + new DifficultyPatcher(); MelonLogger.Msg("Completed Loading DifficultyMod"); } } diff --git a/DifficultyMod/DifficultyMod.csproj b/DifficultyMod/DifficultyMod.csproj index 1a9aebf..2e37c46 100644 --- a/DifficultyMod/DifficultyMod.csproj +++ b/DifficultyMod/DifficultyMod.csproj @@ -72,6 +72,7 @@ + From 3d0ac60228399b60c473b8eeba2bad4d3be3d694 Mon Sep 17 00:00:00 2001 From: Pokachi Date: Sun, 30 May 2021 00:23:06 -0700 Subject: [PATCH 2/4] some small changes --- DifficultyMod/Core/DifficultyPatcher.cs | 4 ++-- DifficultyMod/DifficultyMod.cs | 6 ++++-- DifficultyMod/UI/DifficultyMenu.cs | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/DifficultyMod/Core/DifficultyPatcher.cs b/DifficultyMod/Core/DifficultyPatcher.cs index 4a5740e..b7d1810 100644 --- a/DifficultyMod/Core/DifficultyPatcher.cs +++ b/DifficultyMod/Core/DifficultyPatcher.cs @@ -9,11 +9,11 @@ namespace DemeoMods.DifficultyMod.Core { - class DifficultyPatcher + static class DifficultyPatcher { private static GameStateMachine StateMachine { get; set; } - public DifficultyPatcher() + public static void SetGameStateMachine() { StateMachine = GameObject.Find("GameLogic").GetComponent(); } diff --git a/DifficultyMod/DifficultyMod.cs b/DifficultyMod/DifficultyMod.cs index f12347a..e1c6379 100644 --- a/DifficultyMod/DifficultyMod.cs +++ b/DifficultyMod/DifficultyMod.cs @@ -14,9 +14,11 @@ public override void OnSceneWasLoaded(int buildIndex, string sceneName) if (LOBBY_SCENE_NAME.Equals(sceneName)) { MelonLogger.Msg("Initializing..."); + new GameObject("Difficulty Menu", typeof(DifficultyMenu)); - new DifficultyPatcher(); - MelonLogger.Msg("Completed Loading DifficultyMod"); + DifficultyPatcher.SetGameStateMachine(); + + MelonLogger.Msg("Initialized."); } } } diff --git a/DifficultyMod/UI/DifficultyMenu.cs b/DifficultyMod/UI/DifficultyMenu.cs index 3374444..0a2bce1 100644 --- a/DifficultyMod/UI/DifficultyMenu.cs +++ b/DifficultyMod/UI/DifficultyMenu.cs @@ -16,7 +16,7 @@ private void Awake() public void Initialize() { - MelonLogger.Msg("Creating UI Elements..."); + MelonLogger.Msg("Initializing UI Elements..."); gameObject.SetActive(false); gameObject.layer = 5; //UI layer @@ -68,7 +68,7 @@ public void Initialize() CreateButton(enemyHPMultiplier.transform, new Vector3(-1f, 0.15f, -1.6f), "Enemy Attack Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseEnemyAttackMultiplier(text => { UpdateText(_EnemyAttackMultiplier, text); }); }); CreateButton(enemyHPMultiplier.transform, new Vector3(1f, 0.15f, -1.6f), "Enemy Attack Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseEnemyAttackMultiplier(text => { UpdateText(_EnemyAttackMultiplier, text); }); }); - MelonLogger.Msg("Completed Creating UI Elements."); + MelonLogger.Msg("Initialized UI Elements."); } private static void UpdateText(TextMeshPro textMeshPro, float text) From 88498cebacf294a1d8186384a31dbd878c5af57d Mon Sep 17 00:00:00 2001 From: Pokachi Date: Sun, 30 May 2021 01:43:43 -0700 Subject: [PATCH 3/4] save difficulty setting in melon pref and added energy multiplier --- DifficultyMod/Core/DifficultyPatcher.cs | 16 ++++- DifficultyMod/Core/DifficultySettings.cs | 84 ++++++++++++++++++++++-- DifficultyMod/DifficultyMod.cs | 9 ++- DifficultyMod/UI/DifficultyMenu.cs | 41 +++++++++--- 4 files changed, 129 insertions(+), 21 deletions(-) diff --git a/DifficultyMod/Core/DifficultyPatcher.cs b/DifficultyMod/Core/DifficultyPatcher.cs index b7d1810..99eb734 100644 --- a/DifficultyMod/Core/DifficultyPatcher.cs +++ b/DifficultyMod/Core/DifficultyPatcher.cs @@ -58,7 +58,7 @@ private static bool IsPrivateGame() } [HarmonyPatch(typeof(Piece), "CreatePiece")] - public static class EnemyHPMultiplierPatcher + class EnemyHPMultiplierPatcher { static MethodInfo m_MyExtraMethod = AccessTools.Method(typeof(DifficultyPatcher), nameof(ModifyEnemyHPMultiplier), new[] { typeof(int), typeof(PieceConfig) }); @@ -86,7 +86,7 @@ static IEnumerable Transpiler(IEnumerable inst } [HarmonyPatch(typeof(Piece), "CreatePiece")] - public static class EnemyAttackMultiplierPatcher + class EnemyAttackMultiplierPatcher { static MethodInfo m_MyExtraMethod = AccessTools.Method(typeof(DifficultyPatcher), nameof(ModifyEnemyAttackMultiplier), new[] { typeof(int), typeof(PieceConfig) }); @@ -111,5 +111,17 @@ static IEnumerable Transpiler(IEnumerable inst } } } + + [HarmonyPatch(typeof(CardPowder), "GetPowderScale")] + class EnergyGainMultiplierPatcher + { + static void Postfix(ref float __result) + { + if (IsPrivateGame()) + { + __result *= DifficultySettings.EnergyGainMultiplier; + } + } + } } } diff --git a/DifficultyMod/Core/DifficultySettings.cs b/DifficultyMod/Core/DifficultySettings.cs index 17750b7..7f9bed5 100644 --- a/DifficultyMod/Core/DifficultySettings.cs +++ b/DifficultyMod/Core/DifficultySettings.cs @@ -1,22 +1,72 @@ -using System; +using MelonLoader; +using System; namespace DemeoMods.DifficultyMod.Core { public static class DifficultySettings { + private const string MELON_PREF_NAME = "DemeoDifficultyMod"; + private const string MELON_PREF_ENEMY_HP_MULTIPLIER_NAME = "EnemyHpMultiplier"; + private const string MELON_PREF_ENEMY_ATTACK_MULTIPLIER_NAME = "EnemyAttackMultiplier"; + private const string MELON_PREF_ENERGY_GAIN_MULTIPLIER_NAME = "EnergyGainMultiplier"; + private const float ENEMY_HP_MULTIPLIER_MIN = 0.25f; private const float ENEMY_HP_MULTIPLIER_MAX = 5f; private const float ENEMY_ATTACK_MULTIPLIER_MIN = 0.25f; private const float ENEMY_ATTACK_MULTIPLIER_MAX = 5f; + private const float ENERGY_GAIN_MULTIPLIER_MIN = 0.1f; + private const float ENERGY_GAIN_MULTIPLIER_MAX = 5f; - public static float EnemyHPMultiplier { get; set; } = 2; - public static float EnemyAttackMultiplier { get; set; } = 2; + public static void RegisterSettings() + { + MelonPreferences.CreateCategory(MELON_PREF_NAME, "Demeo Difficulty Settings"); + MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ENEMY_HP_MULTIPLIER_NAME, 1f, "Enemy HP Multiplier"); + MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ENEMY_ATTACK_MULTIPLIER_NAME, 1f, "Enemy Attack Multiplier"); + MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ENERGY_GAIN_MULTIPLIER_NAME, 1f, "Energy Gain Multiplier"); + } + + public static float EnemyHPMultiplier + { + get + { + return MelonPreferences.GetEntryValue(MELON_PREF_NAME, MELON_PREF_ENEMY_HP_MULTIPLIER_NAME); + } + set + { + MelonPreferences.SetEntryValue(MELON_PREF_NAME, MELON_PREF_ENEMY_HP_MULTIPLIER_NAME, value); + } + } + + public static float EnemyAttackMultiplier + { + get + { + return MelonPreferences.GetEntryValue(MELON_PREF_NAME, MELON_PREF_ENEMY_ATTACK_MULTIPLIER_NAME); + } + set + { + MelonPreferences.SetEntryValue(MELON_PREF_NAME, MELON_PREF_ENEMY_ATTACK_MULTIPLIER_NAME, value); + } + } + + public static float EnergyGainMultiplier + { + get + { + return MelonPreferences.GetEntryValue(MELON_PREF_NAME, MELON_PREF_ENERGY_GAIN_MULTIPLIER_NAME); + } + set + { + MelonPreferences.SetEntryValue(MELON_PREF_NAME, MELON_PREF_ENERGY_GAIN_MULTIPLIER_NAME, value); + } + + } public static void DecreaseEnemyHPMultiplier(Action callBack) { if (EnemyHPMultiplier > ENEMY_HP_MULTIPLIER_MIN) { - EnemyHPMultiplier -= 0.25f; + EnemyHPMultiplier = (float) Math.Round(EnemyHPMultiplier - 0.25f, 2); } callBack(EnemyHPMultiplier); @@ -26,7 +76,7 @@ public static void IncreaseEnemyHPMultiplier(Action callBack) { if (EnemyHPMultiplier < ENEMY_HP_MULTIPLIER_MAX) { - EnemyHPMultiplier += 0.25f; + EnemyHPMultiplier = (float)Math.Round(EnemyHPMultiplier + 0.25f, 2); } callBack(EnemyHPMultiplier); @@ -36,7 +86,7 @@ public static void DecreaseEnemyAttackMultiplier(Action callBack) { if (EnemyAttackMultiplier > ENEMY_ATTACK_MULTIPLIER_MIN) { - EnemyAttackMultiplier -= 0.25f; + EnemyAttackMultiplier = (float)Math.Round(EnemyAttackMultiplier - 0.25f, 2); } callBack(EnemyAttackMultiplier); @@ -46,10 +96,30 @@ public static void IncreaseEnemyAttackMultiplier(Action callBack) { if (EnemyAttackMultiplier < ENEMY_ATTACK_MULTIPLIER_MAX) { - EnemyAttackMultiplier += 0.25f; + EnemyAttackMultiplier = (float)Math.Round(EnemyAttackMultiplier + 0.25f, 2); } callBack(EnemyAttackMultiplier); } + + public static void DecreaseEnergyGainMultiplier(Action callBack) + { + if (EnergyGainMultiplier > ENERGY_GAIN_MULTIPLIER_MIN) + { + EnergyGainMultiplier = (float)Math.Round(EnergyGainMultiplier - 0.1f, 2); + } + + callBack(EnergyGainMultiplier); + } + + public static void IncreaseEnergyGainMultiplier(Action callBack) + { + if (EnergyGainMultiplier < ENERGY_GAIN_MULTIPLIER_MAX) + { + EnergyGainMultiplier = (float)Math.Round(EnergyGainMultiplier + 0.1f, 2); + } + + callBack(EnergyGainMultiplier); + } } } \ No newline at end of file diff --git a/DifficultyMod/DifficultyMod.cs b/DifficultyMod/DifficultyMod.cs index e1c6379..1d03e49 100644 --- a/DifficultyMod/DifficultyMod.cs +++ b/DifficultyMod/DifficultyMod.cs @@ -9,11 +9,16 @@ public class DifficultyMod : MelonMod { private const string LOBBY_SCENE_NAME = "LobbySteamVR"; - public override void OnSceneWasLoaded(int buildIndex, string sceneName) + public override void OnApplicationStart() + { + MelonLogger.Msg("Initializing..."); + DifficultySettings.RegisterSettings(); + } + + public override void OnSceneWasLoaded(int buildIndex, string sceneName) { if (LOBBY_SCENE_NAME.Equals(sceneName)) { - MelonLogger.Msg("Initializing..."); new GameObject("Difficulty Menu", typeof(DifficultyMenu)); DifficultyPatcher.SetGameStateMachine(); diff --git a/DifficultyMod/UI/DifficultyMenu.cs b/DifficultyMod/UI/DifficultyMenu.cs index 0a2bce1..0cef63a 100644 --- a/DifficultyMod/UI/DifficultyMenu.cs +++ b/DifficultyMod/UI/DifficultyMenu.cs @@ -57,16 +57,37 @@ public void Initialize() enemyHPMultiplier.transform.localPosition = Vector3.zero; enemyHPMultiplier.SetActive(true); - CreateText(enemyHPMultiplier.transform, new Vector3(0.036f, 0.15f, 1.4f), 3.5f, new Color(0.0392f, 0.0157f, 0, 1), "Enemy HP Multiplier", TextAlignmentOptions.Center, FontStyles.Normal); - TextMeshPro _EnemyHPMultiplier = CreateText(enemyHPMultiplier.transform, new Vector3(0.036f, 0.15f, 0.4f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Enemy HP Multiplier Text", DifficultySettings.EnemyHPMultiplier.ToString(), TextAlignmentOptions.Center, FontStyles.Normal); - CreateButton(enemyHPMultiplier.transform, new Vector3(-1f, 0.15f, 0.4f), "Enemy HP Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseEnemyHPMultiplier(text => { UpdateText(_EnemyHPMultiplier, text); }); }); - CreateButton(enemyHPMultiplier.transform, new Vector3(1f, 0.15f, 0.4f), "Enemy HP Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseEnemyHPMultiplier(text => { UpdateText(_EnemyHPMultiplier, text); }); }); - - - CreateText(enemyHPMultiplier.transform, new Vector3(0.036f, 0.15f, -.6f), 3.5f, new Color(0.0392f, 0.0157f, 0, 1), "Enemy Attack Multiplier", TextAlignmentOptions.Center, FontStyles.Normal); - TextMeshPro _EnemyAttackMultiplier = CreateText(enemyHPMultiplier.transform, new Vector3(0.036f, 0.15f, -1.6f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Enemy Attack Multiplier Text", DifficultySettings.EnemyAttackMultiplier.ToString(), TextAlignmentOptions.Center, FontStyles.Normal); - CreateButton(enemyHPMultiplier.transform, new Vector3(-1f, 0.15f, -1.6f), "Enemy Attack Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseEnemyAttackMultiplier(text => { UpdateText(_EnemyAttackMultiplier, text); }); }); - CreateButton(enemyHPMultiplier.transform, new Vector3(1f, 0.15f, -1.6f), "Enemy Attack Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseEnemyAttackMultiplier(text => { UpdateText(_EnemyAttackMultiplier, text); }); }); + CreateText(enemyHPMultiplier.transform, new Vector3(0.036f, 0.15f, 1.4f), 3.25f, new Color(0.0392f, 0.0157f, 0, 1), "Enemy HP Multiplier", TextAlignmentOptions.Center, FontStyles.Normal); + TextMeshPro enemyHPMultiplierValue = CreateText(enemyHPMultiplier.transform, new Vector3(0.036f, 0.15f, 0.4f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Enemy HP Multiplier Text", DifficultySettings.EnemyHPMultiplier.ToString(), TextAlignmentOptions.Center, FontStyles.Normal); + CreateButton(enemyHPMultiplier.transform, new Vector3(-1f, 0.15f, 0.4f), "Enemy HP Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseEnemyHPMultiplier(text => { UpdateText(enemyHPMultiplierValue, text); }); }); + CreateButton(enemyHPMultiplier.transform, new Vector3(1.1f, 0.15f, 0.4f), "Enemy HP Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseEnemyHPMultiplier(text => { UpdateText(enemyHPMultiplierValue, text); }); }); + + // Enemy Attack Multiplier + GameObject enemyAttackMultiplier = new GameObject("Enemy Attack Multiplier"); + enemyAttackMultiplier.transform.SetParent(difficultySettingsPageOne.transform); + enemyAttackMultiplier.transform.localScale = Vector3.one; + enemyAttackMultiplier.transform.localRotation = Quaternion.Euler(0, 0, 0); + enemyAttackMultiplier.transform.localPosition = Vector3.zero; + enemyAttackMultiplier.SetActive(true); + + CreateText(enemyAttackMultiplier.transform, new Vector3(0.036f, 0.15f, -.6f), 3.25f, new Color(0.0392f, 0.0157f, 0, 1), "Enemy Attack Multiplier", TextAlignmentOptions.Center, FontStyles.Normal); + TextMeshPro enemyAttackMultiplierValue = CreateText(enemyAttackMultiplier.transform, new Vector3(0.036f, 0.15f, -1.6f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Enemy Attack Multiplier Text", DifficultySettings.EnemyAttackMultiplier.ToString(), TextAlignmentOptions.Center, FontStyles.Normal); + CreateButton(enemyAttackMultiplier.transform, new Vector3(-1f, 0.15f, -1.6f), "Enemy Attack Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseEnemyAttackMultiplier(text => { UpdateText(enemyAttackMultiplierValue, text); }); }); + CreateButton(enemyAttackMultiplier.transform, new Vector3(1.1f, 0.15f, -1.6f), "Enemy Attack Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseEnemyAttackMultiplier(text => { UpdateText(enemyAttackMultiplierValue, text); }); }); + + + // Energy Gain Multiplier + GameObject energyGainMultiplier = new GameObject("Energy Gain Multiplier"); + energyGainMultiplier.transform.SetParent(difficultySettingsPageOne.transform); + energyGainMultiplier.transform.localScale = Vector3.one; + energyGainMultiplier.transform.localRotation = Quaternion.Euler(0, 0, 0); + energyGainMultiplier.transform.localPosition = Vector3.zero; + energyGainMultiplier.SetActive(true); + + CreateText(energyGainMultiplier.transform, new Vector3(0.036f, 0.15f, -2.6f), 3.25f, new Color(0.0392f, 0.0157f, 0, 1), "Energy Gain Multiplier", TextAlignmentOptions.Center, FontStyles.Normal); + TextMeshPro energyGainMultiplierValue = CreateText(energyGainMultiplier.transform, new Vector3(0.036f, 0.15f, -3.6f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Energy Gain Multiplier Text", DifficultySettings.EnergyGainMultiplier.ToString(), TextAlignmentOptions.Center, FontStyles.Normal); + CreateButton(energyGainMultiplier.transform, new Vector3(-1f, 0.15f, -3.6f), "Energy Gain Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseEnergyGainMultiplier(text => { UpdateText(energyGainMultiplierValue, text); }); }); + CreateButton(energyGainMultiplier.transform, new Vector3(1.1f, 0.15f, -3.6f), "Energy Gain Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseEnergyGainMultiplier(text => { UpdateText(energyGainMultiplierValue, text); }); }); MelonLogger.Msg("Initialized UI Elements."); } From 1c6a1276fc1daea59fcccd2c086b0f5838bf746c Mon Sep 17 00:00:00 2001 From: Pokachi Date: Sun, 30 May 2021 02:58:41 -0700 Subject: [PATCH 4/4] Added Gold Pile Multiplier and Pages to Difficulty Menu --- DifficultyMod/Core/DifficultyPatcher.cs | 14 +++ DifficultyMod/Core/DifficultySettings.cs | 37 ++++++++ DifficultyMod/UI/DifficultyMenu.cs | 110 ++++++++++++++++------- 3 files changed, 129 insertions(+), 32 deletions(-) diff --git a/DifficultyMod/Core/DifficultyPatcher.cs b/DifficultyMod/Core/DifficultyPatcher.cs index 99eb734..89beeff 100644 --- a/DifficultyMod/Core/DifficultyPatcher.cs +++ b/DifficultyMod/Core/DifficultyPatcher.cs @@ -1,6 +1,8 @@ using Boardgame; using Boardgame.BoardEntities; +using Boardgame.Data; using Boardgame.Networking; +using Boardgame.SerializableEvents; using HarmonyLib; using System.Collections.Generic; using System.Reflection; @@ -123,5 +125,17 @@ static void Postfix(ref float __result) } } } + + [HarmonyPatch(typeof(SerializableEventPickup), MethodType.Constructor, typeof(int), typeof(IntPoint2D), typeof(bool))] + class GoldPileGainMultiplierPatcher + { + static void Postfix(SerializableEventPickup __instance) + { + if (IsPrivateGame()) + { + __instance.goldAmount = (int) (__instance.goldAmount * DifficultySettings.GoldPileGainMultiplier); + } + } + } } } diff --git a/DifficultyMod/Core/DifficultySettings.cs b/DifficultyMod/Core/DifficultySettings.cs index 7f9bed5..f688a0f 100644 --- a/DifficultyMod/Core/DifficultySettings.cs +++ b/DifficultyMod/Core/DifficultySettings.cs @@ -9,6 +9,7 @@ public static class DifficultySettings private const string MELON_PREF_ENEMY_HP_MULTIPLIER_NAME = "EnemyHpMultiplier"; private const string MELON_PREF_ENEMY_ATTACK_MULTIPLIER_NAME = "EnemyAttackMultiplier"; private const string MELON_PREF_ENERGY_GAIN_MULTIPLIER_NAME = "EnergyGainMultiplier"; + private const string MELON_PREF_GOLD_PILE_GAIN_MULTIPLIER_NAME = "GoldGainMultiplier"; private const float ENEMY_HP_MULTIPLIER_MIN = 0.25f; private const float ENEMY_HP_MULTIPLIER_MAX = 5f; @@ -16,6 +17,8 @@ public static class DifficultySettings private const float ENEMY_ATTACK_MULTIPLIER_MAX = 5f; private const float ENERGY_GAIN_MULTIPLIER_MIN = 0.1f; private const float ENERGY_GAIN_MULTIPLIER_MAX = 5f; + private const float GOLD_PILE_GAIN_MULTIPLIER_MIN = 0.1f; + private const float GOLD_PILE_GAIN_MULTIPLIER_MAX = 5f; public static void RegisterSettings() { @@ -23,6 +26,7 @@ public static void RegisterSettings() MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ENEMY_HP_MULTIPLIER_NAME, 1f, "Enemy HP Multiplier"); MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ENEMY_ATTACK_MULTIPLIER_NAME, 1f, "Enemy Attack Multiplier"); MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ENERGY_GAIN_MULTIPLIER_NAME, 1f, "Energy Gain Multiplier"); + MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_GOLD_PILE_GAIN_MULTIPLIER_NAME, 1f, "Gold Pile Gain Multiplier"); } public static float EnemyHPMultiplier @@ -62,6 +66,19 @@ public static float EnergyGainMultiplier } + public static float GoldPileGainMultiplier + { + get + { + return MelonPreferences.GetEntryValue(MELON_PREF_NAME, MELON_PREF_GOLD_PILE_GAIN_MULTIPLIER_NAME); + } + set + { + MelonPreferences.SetEntryValue(MELON_PREF_NAME, MELON_PREF_GOLD_PILE_GAIN_MULTIPLIER_NAME, value); + } + + } + public static void DecreaseEnemyHPMultiplier(Action callBack) { if (EnemyHPMultiplier > ENEMY_HP_MULTIPLIER_MIN) @@ -121,5 +138,25 @@ public static void IncreaseEnergyGainMultiplier(Action callBack) callBack(EnergyGainMultiplier); } + + public static void DecreaseGoldPileGainMultiplier(Action callBack) + { + if (GoldPileGainMultiplier > GOLD_PILE_GAIN_MULTIPLIER_MIN) + { + GoldPileGainMultiplier = (float)Math.Round(GoldPileGainMultiplier - 0.1f, 2); + } + + callBack(EnergyGainMultiplier); + } + + public static void IncreaseGoldPileGainMultiplier(Action callBack) + { + if (GoldPileGainMultiplier < GOLD_PILE_GAIN_MULTIPLIER_MAX) + { + GoldPileGainMultiplier = (float)Math.Round(GoldPileGainMultiplier + 0.1f, 2); + } + + callBack(GoldPileGainMultiplier); + } } } \ No newline at end of file diff --git a/DifficultyMod/UI/DifficultyMenu.cs b/DifficultyMod/UI/DifficultyMenu.cs index 0cef63a..6cd5dd0 100644 --- a/DifficultyMod/UI/DifficultyMenu.cs +++ b/DifficultyMod/UI/DifficultyMenu.cs @@ -9,6 +9,12 @@ namespace DemeoMods.DifficultyMod.UI { class DifficultyMenu : MonoBehaviour { + private const int TOTAL_PAGES = 2; + private static int currentPage = 1; + + private static GameObject difficultySettingsPageOne; + private static GameObject difficultySettingsPageTwo; + private void Awake() { Initialize(); @@ -37,67 +43,107 @@ public void Initialize() gameObject.SetActive(true); - + #region First_Page // First Page - GameObject difficultySettingsPageOne = new GameObject("Difficulty Settings 1"); - difficultySettingsPageOne.transform.SetParent(transform); - difficultySettingsPageOne.transform.localScale = Vector3.one; - difficultySettingsPageOne.transform.localRotation = Quaternion.Euler(0, 0, 0); - difficultySettingsPageOne.transform.localPosition = Vector3.zero; - difficultySettingsPageOne.SetActive(true); - - // Header + difficultySettingsPageOne = CreateContainer(transform, "Difficulty Settings 1"); + + // Header CreateText(difficultySettingsPageOne.transform, new Vector3(0.036f, 0.15f, 2.4f), 3f, new Color(0.878f, 0.752f, 0.384f, 1), "Difficulty Menu", TextAlignmentOptions.Center, FontStyles.UpperCase); // Enemy HP Multiplier - GameObject enemyHPMultiplier = new GameObject("Enemy HP Multiplier"); - enemyHPMultiplier.transform.SetParent(difficultySettingsPageOne.transform); - enemyHPMultiplier.transform.localScale = Vector3.one; - enemyHPMultiplier.transform.localRotation = Quaternion.Euler(0, 0, 0); - enemyHPMultiplier.transform.localPosition = Vector3.zero; - enemyHPMultiplier.SetActive(true); - + GameObject enemyHPMultiplier = CreateContainer(difficultySettingsPageOne.transform, "Enemy HP Multiplier"); CreateText(enemyHPMultiplier.transform, new Vector3(0.036f, 0.15f, 1.4f), 3.25f, new Color(0.0392f, 0.0157f, 0, 1), "Enemy HP Multiplier", TextAlignmentOptions.Center, FontStyles.Normal); TextMeshPro enemyHPMultiplierValue = CreateText(enemyHPMultiplier.transform, new Vector3(0.036f, 0.15f, 0.4f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Enemy HP Multiplier Text", DifficultySettings.EnemyHPMultiplier.ToString(), TextAlignmentOptions.Center, FontStyles.Normal); CreateButton(enemyHPMultiplier.transform, new Vector3(-1f, 0.15f, 0.4f), "Enemy HP Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseEnemyHPMultiplier(text => { UpdateText(enemyHPMultiplierValue, text); }); }); CreateButton(enemyHPMultiplier.transform, new Vector3(1.1f, 0.15f, 0.4f), "Enemy HP Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseEnemyHPMultiplier(text => { UpdateText(enemyHPMultiplierValue, text); }); }); // Enemy Attack Multiplier - GameObject enemyAttackMultiplier = new GameObject("Enemy Attack Multiplier"); - enemyAttackMultiplier.transform.SetParent(difficultySettingsPageOne.transform); - enemyAttackMultiplier.transform.localScale = Vector3.one; - enemyAttackMultiplier.transform.localRotation = Quaternion.Euler(0, 0, 0); - enemyAttackMultiplier.transform.localPosition = Vector3.zero; - enemyAttackMultiplier.SetActive(true); - + GameObject enemyAttackMultiplier = CreateContainer(difficultySettingsPageOne.transform, "Enemy Attack Multiplier"); CreateText(enemyAttackMultiplier.transform, new Vector3(0.036f, 0.15f, -.6f), 3.25f, new Color(0.0392f, 0.0157f, 0, 1), "Enemy Attack Multiplier", TextAlignmentOptions.Center, FontStyles.Normal); TextMeshPro enemyAttackMultiplierValue = CreateText(enemyAttackMultiplier.transform, new Vector3(0.036f, 0.15f, -1.6f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Enemy Attack Multiplier Text", DifficultySettings.EnemyAttackMultiplier.ToString(), TextAlignmentOptions.Center, FontStyles.Normal); CreateButton(enemyAttackMultiplier.transform, new Vector3(-1f, 0.15f, -1.6f), "Enemy Attack Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseEnemyAttackMultiplier(text => { UpdateText(enemyAttackMultiplierValue, text); }); }); CreateButton(enemyAttackMultiplier.transform, new Vector3(1.1f, 0.15f, -1.6f), "Enemy Attack Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseEnemyAttackMultiplier(text => { UpdateText(enemyAttackMultiplierValue, text); }); }); - // Energy Gain Multiplier - GameObject energyGainMultiplier = new GameObject("Energy Gain Multiplier"); - energyGainMultiplier.transform.SetParent(difficultySettingsPageOne.transform); - energyGainMultiplier.transform.localScale = Vector3.one; - energyGainMultiplier.transform.localRotation = Quaternion.Euler(0, 0, 0); - energyGainMultiplier.transform.localPosition = Vector3.zero; - energyGainMultiplier.SetActive(true); - + GameObject energyGainMultiplier = CreateContainer(difficultySettingsPageOne.transform, "Energy Gain Multiplier"); CreateText(energyGainMultiplier.transform, new Vector3(0.036f, 0.15f, -2.6f), 3.25f, new Color(0.0392f, 0.0157f, 0, 1), "Energy Gain Multiplier", TextAlignmentOptions.Center, FontStyles.Normal); TextMeshPro energyGainMultiplierValue = CreateText(energyGainMultiplier.transform, new Vector3(0.036f, 0.15f, -3.6f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Energy Gain Multiplier Text", DifficultySettings.EnergyGainMultiplier.ToString(), TextAlignmentOptions.Center, FontStyles.Normal); CreateButton(energyGainMultiplier.transform, new Vector3(-1f, 0.15f, -3.6f), "Energy Gain Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseEnergyGainMultiplier(text => { UpdateText(energyGainMultiplierValue, text); }); }); CreateButton(energyGainMultiplier.transform, new Vector3(1.1f, 0.15f, -3.6f), "Energy Gain Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseEnergyGainMultiplier(text => { UpdateText(energyGainMultiplierValue, text); }); }); + // Navigation Button + GameObject pageOneNavigationButtons = CreateContainer(difficultySettingsPageOne.transform, "Navigation Buttons"); + CreateButton(pageOneNavigationButtons.transform, new Vector3(-1.5f, 0.15f, -5.6f), "Previous Page", "DreadArrowDown", () => { ChangePage((currentPage - 1) % TOTAL_PAGES); }, new Vector3 (0.7f, 0.7f, 0.7f)); + CreateText(pageOneNavigationButtons.transform, new Vector3(0.036f, 0.15f, -5.6f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Page 1", TextAlignmentOptions.Center, FontStyles.Normal); + CreateButton(pageOneNavigationButtons.transform, new Vector3(1.6f, 0.15f, -5.6f), "Next Page", "DreadArrowUp", () => { ChangePage((currentPage + 1) % TOTAL_PAGES); }, new Vector3(0.7f, 0.7f, 0.7f)); + #endregion First_Page + + #region Second_Page + // First Page + difficultySettingsPageTwo = CreateContainer(transform, "Difficulty Settings 2"); + difficultySettingsPageTwo.SetActive(false); + + // Header + CreateText(difficultySettingsPageTwo.transform, new Vector3(0.036f, 0.15f, 2.4f), 3f, new Color(0.878f, 0.752f, 0.384f, 1), "Difficulty Menu", TextAlignmentOptions.Center, FontStyles.UpperCase); + + // Navigation Button + GameObject pageTwoNavigationButtons = CreateContainer(difficultySettingsPageTwo.transform, "Navigation Buttons"); + CreateButton(pageTwoNavigationButtons.transform, new Vector3(-1.5f, 0.15f, -5.6f), "Previous Page", "DreadArrowDown", () => { ChangePage((currentPage - 1) % TOTAL_PAGES); }, new Vector3(0.7f, 0.7f, 0.7f)); + CreateText(pageTwoNavigationButtons.transform, new Vector3(0.036f, 0.15f, -5.6f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Page 2", TextAlignmentOptions.Center, FontStyles.Normal); + CreateButton(pageTwoNavigationButtons.transform, new Vector3(1.6f, 0.15f, -5.6f), "Next Page", "DreadArrowUp", () => { ChangePage((currentPage + 1) % TOTAL_PAGES); }, new Vector3(0.7f, 0.7f, 0.7f)); + + // Gold Pile Multiplier + GameObject goldPileMultiplier = CreateContainer(difficultySettingsPageTwo.transform, "Gold Pile Multiplier"); + CreateText(goldPileMultiplier.transform, new Vector3(0.036f, 0.15f, 1.4f), 3.25f, new Color(0.0392f, 0.0157f, 0, 1), "Gold Pile Multiplier", TextAlignmentOptions.Center, FontStyles.Normal); + TextMeshPro goldPileMultiplierValue = CreateText(goldPileMultiplier.transform, new Vector3(0.036f, 0.15f, 0.4f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Gold Pile Multiplier Text", DifficultySettings.GoldPileGainMultiplier.ToString(), TextAlignmentOptions.Center, FontStyles.Normal); + CreateButton(goldPileMultiplier.transform, new Vector3(-1f, 0.15f, 0.4f), "Gold Pile Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseGoldPileGainMultiplier(text => { UpdateText(goldPileMultiplierValue, text); }); }); + CreateButton(goldPileMultiplier.transform, new Vector3(1.1f, 0.15f, 0.4f), "Gold Pile Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseGoldPileGainMultiplier(text => { UpdateText(goldPileMultiplierValue, text); }); }); + #endregion Second_Page + MelonLogger.Msg("Initialized UI Elements."); } + private static void ChangePage(int newPage) + { + currentPage = newPage == 0 ? TOTAL_PAGES : newPage; + + switch (currentPage) + { + case 1: + difficultySettingsPageOne.SetActive(true); + difficultySettingsPageTwo.SetActive(false); + break; + case 2: + difficultySettingsPageOne.SetActive(false); + difficultySettingsPageTwo.SetActive(true); + break; + } + } + private static void UpdateText(TextMeshPro textMeshPro, float text) { textMeshPro.SetText(text.ToString()); } + private static GameObject CreateContainer(Transform parent, string containerName) + { + GameObject gameObject = new GameObject(containerName); + gameObject.SetActive(false); + gameObject.transform.SetParent(parent); + gameObject.transform.localScale = Vector3.one; + gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0); + gameObject.transform.localPosition = Vector3.zero; + gameObject.SetActive(true); + + return gameObject; + } + private static ClickableButton CreateButton(Transform parent, Vector3 position, string buttonName, string meshName, Action callback) + { + return CreateButton(parent, position, buttonName, meshName, callback, new Vector3(0.5f, 0.5f, 0.5f)); + } + + private static ClickableButton CreateButton(Transform parent, Vector3 position, string buttonName, string meshName, Action callback, Vector3 scale) { GameObject gameObject = new GameObject(buttonName, typeof(MeshFilter), typeof(MeshRenderer), typeof(MenuButtonHoverEffect), typeof(ClickableButton)); gameObject.SetActive(false); @@ -109,7 +155,7 @@ private static ClickableButton CreateButton(Transform parent, Vector3 position, transform.SetParent(parent, false); transform.localRotation = Quaternion.Euler(0, 90, 0); transform.localPosition = position; - transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); + transform.localScale = scale; // Mesh Filter MeshFilter meshFilter = gameObject.GetComponent();