Implement transpiler for level up stat evaluation in Actions_ClickedStat
This commit is contained in:
@@ -5,6 +5,7 @@ using BepInEx;
|
|||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using HarmonyLib.Tools;
|
using HarmonyLib.Tools;
|
||||||
|
using System.Reflection.Emit;
|
||||||
|
|
||||||
namespace BanquetForCyka {
|
namespace BanquetForCyka {
|
||||||
[BepInPlugin(PluginGuid, PluginName, PluginVersion)]
|
[BepInPlugin(PluginGuid, PluginName, PluginVersion)]
|
||||||
@@ -82,56 +83,23 @@ namespace BanquetForCyka {
|
|||||||
|
|
||||||
[HarmonyPatch(typeof(LevelUp), "ClickedStat")]
|
[HarmonyPatch(typeof(LevelUp), "ClickedStat")]
|
||||||
public class Actions_ClickedStat {
|
public class Actions_ClickedStat {
|
||||||
private static float originalStr;
|
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) {
|
||||||
private static float originalAgi;
|
var codes = new List<CodeInstruction>(instructions);
|
||||||
private static float originalDex;
|
|
||||||
private static float originalPag;
|
|
||||||
private static float originalSen;
|
|
||||||
|
|
||||||
public static void Prefix(ref LevelUp __instance) {
|
// Find the ldc.r4 1 instruction
|
||||||
Main.LogDebug("Original Str: " + __instance.character.stats.strength, Main.debugStatEntry);
|
for (int i = codes.Count - 1; i >= 0; i--) {
|
||||||
Main.LogDebug("Original Agi: " + __instance.character.stats.agility, Main.debugStatEntry);
|
if (codes[i].opcode == OpCodes.Ldc_R4 && (float)codes[i].operand == 1f) {
|
||||||
Main.LogDebug("Original Dex: " + __instance.character.stats.dexterity, Main.debugStatEntry);
|
// Replace with our expression evaluation
|
||||||
Main.LogDebug("Original Pag: " + __instance.character.stats.pagan, Main.debugStatEntry);
|
codes[i] = new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Main), "levelUpStatEntry"));
|
||||||
Main.LogDebug("Original Sen: " + __instance.character.stats.sensory, Main.debugStatEntry);
|
codes.Insert(i + 1, new CodeInstruction(OpCodes.Ldc_R4, 1f));
|
||||||
|
codes.Insert(i + 2,
|
||||||
|
new CodeInstruction(OpCodes.Callvirt,
|
||||||
|
AccessTools.Method(typeof(ExpressionConfigEntry), "Evaluate")));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
originalStr = __instance.character.stats.strength;
|
return codes;
|
||||||
originalAgi = __instance.character.stats.agility;
|
|
||||||
originalDex = __instance.character.stats.dexterity;
|
|
||||||
originalPag = __instance.character.stats.pagan;
|
|
||||||
originalSen = __instance.character.stats.sensory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Postfix(ref LevelUp __instance) {
|
|
||||||
float deltaStr = __instance.character.stats.strength - originalStr;
|
|
||||||
float deltaAgi = __instance.character.stats.agility - originalAgi;
|
|
||||||
float deltaDex = __instance.character.stats.dexterity - originalDex;
|
|
||||||
float deltaPag = __instance.character.stats.pagan - originalPag;
|
|
||||||
float deltaSen = __instance.character.stats.sensory - originalSen;
|
|
||||||
|
|
||||||
Main.LogDebug("Delta Str: " + deltaStr, Main.debugStatEntry);
|
|
||||||
Main.LogDebug("Delta Agi: " + deltaAgi, Main.debugStatEntry);
|
|
||||||
Main.LogDebug("Delta Dex: " + deltaDex, Main.debugStatEntry);
|
|
||||||
Main.LogDebug("Delta Pag: " + deltaPag, Main.debugStatEntry);
|
|
||||||
Main.LogDebug("Delta Sen: " + deltaSen, Main.debugStatEntry);
|
|
||||||
|
|
||||||
float resultStr = Main.levelUpStatEntry.Evaluate(deltaStr);
|
|
||||||
float resultAgi = Main.levelUpStatEntry.Evaluate(deltaAgi);
|
|
||||||
float resultDex = Main.levelUpStatEntry.Evaluate(deltaDex);
|
|
||||||
float resultPag = Main.levelUpStatEntry.Evaluate(deltaPag);
|
|
||||||
float resultSen = Main.levelUpStatEntry.Evaluate(deltaSen);
|
|
||||||
|
|
||||||
Main.LogDebug("Result Str: " + resultStr, Main.debugStatEntry);
|
|
||||||
Main.LogDebug("Result Agi: " + resultAgi, Main.debugStatEntry);
|
|
||||||
Main.LogDebug("Result Dex: " + resultDex, Main.debugStatEntry);
|
|
||||||
Main.LogDebug("Result Pag: " + resultPag, Main.debugStatEntry);
|
|
||||||
Main.LogDebug("Result Sen: " + resultSen, Main.debugStatEntry);
|
|
||||||
|
|
||||||
__instance.character.stats.strength = resultStr;
|
|
||||||
__instance.character.stats.agility = resultAgi;
|
|
||||||
__instance.character.stats.dexterity = resultDex;
|
|
||||||
__instance.character.stats.pagan = resultPag;
|
|
||||||
__instance.character.stats.sensory = resultSen;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user