Files
BepInEx/Projects/BanquetForFools/BanquetForCyka/Class1.cs

149 lines
6.3 KiB
C#

using System;
using System.Linq;
using System.Collections.Generic;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using HarmonyLib.Tools;
using UnityEngine;
using UnityEngine.UI;
namespace BanquetForCyka {
[BepInPlugin(PluginGuid, PluginName, PluginVersion)]
public class Main : BaseUnityPlugin {
private const string PluginGuid = "BanquetForCyka";
private const string PluginName = "BanquetForCyka";
private const string PluginVersion = "1.0.0";
public static ConfigEntry<bool> debug;
public static ConfigEntry<bool> debugXp;
public static ConfigEntry<bool> debugDodgeWindow;
public static ConfigEntry<bool> debugStatEntry;
public static ConfigEntry<bool> debugSkillEntry;
public static ConfigEntry<bool> debugLevelUpEntry;
public static ExpressionConfigEntry xpMultiplier;
public static ExpressionConfigEntry dodgeWindow;
public static ExpressionConfigEntry levelUpStatEntry;
public static ExpressionConfigEntry levelUpSkillEntry;
public void Awake() {
debug = Config.Bind("Debug", "Global Debug", false);
debugXp = Config.Bind("Debug", "XP Debug", false);
debugDodgeWindow = Config.Bind("Debug", "Dodge Window Debug", false);
debugStatEntry = Config.Bind("Debug", "Stat Entry Debug", false);
debugSkillEntry = Config.Bind("Debug", "Skill Entry Debug", false);
debugLevelUpEntry = Config.Bind("Debug", "Level Up Entry Debug", false);
xpMultiplier = new ExpressionConfigEntry(
Config, "General", "XP Multiplier", "v*1",
"XP Multiplier expression. Use 'v' to represent the original value.", debugXp);
dodgeWindow = new ExpressionConfigEntry(Config, "General", "Dodge Window", "v*1",
"Dodge Window expression. Use 'v' to represent the original value.",
debugDodgeWindow);
levelUpStatEntry = new ExpressionConfigEntry(
Config, "General", "Level Up Stat Entry", "v*1",
"Stat Entry expression. Use 'v' to represent the original value.", debugStatEntry);
levelUpSkillEntry = new ExpressionConfigEntry(
Config, "General", "Level Up Skill Entry", "v*1",
"Skill Entry expression. Use 'v' to represent the original value.", debugSkillEntry);
Logger.LogInfo("BanquetForCyka loaded");
HarmonyFileLog.Enabled = true;
Harmony harmony = new Harmony(PluginGuid);
harmony.PatchAll();
var originalMethods = harmony.GetPatchedMethods();
Logger.LogInfo("Patched " + originalMethods.Count() + " methods");
}
public static void LogDebug(string message, ConfigEntry<bool> debugFlag = null) {
if (debug.Value || (debugFlag != null && debugFlag.Value))
Console.WriteLine(message);
}
}
[HarmonyPatch(typeof(Stats), "AddXP")]
public class Stats_AddXP {
public static void Prefix(ref int amt) {
Main.LogDebug("Original XP amount: " + amt, Main.debugXp);
float result = Main.xpMultiplier.Evaluate(amt);
amt = (int)result;
Main.LogDebug("Modified XP amount: " + amt, Main.debugXp);
}
}
[HarmonyPatch(typeof(Actions), "DodgeCalculation")]
public class Actions_DodgeCalculation {
public static void Postfix(ref float __result) {
Main.LogDebug("Original dodge window: " + __result, Main.debugDodgeWindow);
float result = Main.dodgeWindow.Evaluate(__result);
__result = result;
Main.LogDebug("Modified dodge window: " + __result, Main.debugDodgeWindow);
}
}
[HarmonyPatch(typeof(LevelUp), "ClickedStat")]
public class Actions_ClickedStat {
public static bool Prefix(ref LevelUp __instance, GameObject go) {
if (__instance.levelUpSkills || !__instance.open) {
return true; // Let original method handle this case
}
string name = go.name;
if (__instance.statChosen1 != "" || name == __instance.statChosen1) {
return true; // Let original method handle this case
}
float num = 0f;
if (name == "Strength") {
num = __instance.savedStr;
}
if (name == "Agility") {
num = __instance.savedAgl;
}
if (name == "Dexterity") {
num = __instance.savedDex;
}
if (name == "Aura") {
num = __instance.savedAur;
}
if (name == "Pagan") {
num = __instance.savedPag;
}
if (name == "Sensory") {
num = __instance.savedSen;
}
Main.LogDebug("Original stat value: " + num, Main.debugStatEntry);
float result = Main.levelUpStatEntry.Evaluate(1f); // Evaluate the increase amount
Main.LogDebug("Modified increase amount: " + result, Main.debugStatEntry);
// Set the stat with the modified increase
__instance.character.stats.SetStat(name, num + result);
Links.x.characterSheet.GetStatNums();
Links.x.characterSheet.GetOutput();
// Update UI elements like the original method would
__instance.statTokenUse1.enabled = true;
__instance.statTokenCounter1.enabled = false;
__instance.statTokenUse1RT.anchoredPosition =
__instance.skillTrs[__instance.GetTransformIndex(name, true)].anchoredPosition;
__instance.statChosen1 = name;
__instance.dragIndicator.SetActive(false);
__instance.draggingToken = false;
__instance.dragToken = null;
return false; // Skip original method
}
}
[HarmonyPatch(typeof(LevelUp), "IncreaseAmt")]
public class Actions_IncreaseAmount {
public static void Postfix(ref int __result) {
Main.LogDebug("Original amount: " + __result, Main.debugLevelUpEntry);
float result = Main.levelUpSkillEntry.Evaluate(__result);
__result = (int)result;
Main.LogDebug("Modified amount: " + __result, Main.debugLevelUpEntry);
}
}
}