Skip to content

Commit

Permalink
整理代码,优化性能
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiroNeri4u committed Aug 12, 2024
1 parent 1976dfa commit 9d98736
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 62 deletions.
129 changes: 69 additions & 60 deletions Ricca_Uncensor_Plugin/CheatPatch.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using APP;
using HarmonyLib;
using BepInEx.Logging;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Events;
Expand Down Expand Up @@ -71,24 +72,24 @@ public static void Prefix(ref int sub)
public class Armor_Cheat
{
[HarmonyPrefix]
public static void Prefix(ref int levelIndex)
public static void Prefix(ACT.CharacterArmorBreaker __instance, ref int levelIndex)
{
if (bArmorCheat)
if (bArmorCheat && __instance.parentActor.IsPlayerActor)
{
levelIndex = ArmorLevel;
}
}
}

[HarmonyPatch(typeof(ACT.CharacterArmorBreaker), "InternalSetArmorLevel")]
public class InternalArmor_Cheat
[HarmonyPatch(typeof(ACT.CharacterArmorBreaker), "Initialize")]
public class Initialize
{
[HarmonyPrefix]
public static void Prefix(ref int level)
[HarmonyPostfix]
public static void Postfix(ACT.CharacterArmorBreaker __instance)
{
if (bArmorCheat)
if (__instance.parentActor.IsPlayerActor)
{
level = ArmorLevel;
ArmorLevel = __instance.CurrentArmorLevelIndex;
}
}
}
Expand All @@ -97,12 +98,14 @@ public static void Prefix(ref int level)

private static bool bHelpShow = true;

public static string toast_txt = "";
public static string toast_txt;

private static DateTime dtStart;

public static DateTime? dtStartToast = null;

public static bool bNoMosaic = true;

private static bool bPlayerCheat = false;

private static bool bSkillCheat = false;
Expand All @@ -113,18 +116,22 @@ public static void Prefix(ref int level)

private static bool bArmorCheat = false;

private static int ArmorLevel = -2;
private static int ArmorLevel;

private static string[] ArmorStatus = {"关闭","崭新如初","轻微破损","严重破损","完全破损"};
private enum ArmorStatus
{
Perfect = -1,
Torn = 0,
ripped = 1,
Shredded = 2
}

public GameObject CharacterActor;

private static Action<ACT.CharacterArmorBreaker, int, ACT.CharacterArmorBreaker.CostumeUpdateMode> delegate_characterArmorBreaker_SetArmorLevel;

public void Awake()
{
Harmony harmony = new Harmony("moe.KazamataNeri.ricca_uncensor_plugin.patch");
harmony.PatchAll();
dtStart = DateTime.Now;
}

Expand Down Expand Up @@ -177,62 +184,64 @@ public void OnGUI()
}
if (Event.current.type == EventType.KeyUp)
{
if (Event.current.keyCode == KeyCode.F1)
{
bPlayerCheat = !bPlayerCheat;
toast_txt = "※HP/MP锁定 " + (bPlayerCheat ? "开启" : "关闭");
dtStartToast = DateTime.Now;
}
else if (Event.current.keyCode == KeyCode.F2)
switch (Event.current.keyCode)
{
bSkillCheat = !bSkillCheat;
toast_txt = "※技能无冷却 " + (bSkillCheat ? "开启" : "关闭");
dtStartToast = DateTime.Now;
}
else if (Event.current.keyCode == KeyCode.F3)
{
bKillCheat = !bKillCheat;
toast_txt = "※一击必杀" + (bKillCheat ? "开启" : "关闭");
dtStartToast = DateTime.Now;
}
else if (Event.current.keyCode == KeyCode.F4)
{
bCrystalCheat = !bCrystalCheat;
toast_txt = "※魔法石不消耗 " + (bCrystalCheat ? "开启" : "关闭");
dtStartToast = DateTime.Now;
}
else if (Event.current.keyCode == KeyCode.F5)
{
if (ArmorLevel < 2){
ArmorLevel++;
}
else
{
ArmorLevel = -2;
}
if (ArmorLevel == -2)
{
bArmorCheat = false;
}
else
{
bArmorCheat = true;
}
SetCharacterArmorLevelImmediate();
string text = ArmorStatus[ArmorLevel + 2];
bCrystalCheat = !bCrystalCheat;
toast_txt = "※衣服破损值锁定 " + text;
dtStartToast = DateTime.Now;
case KeyCode.F1:
bPlayerCheat = !bPlayerCheat;
toast_txt = "※HP/MP锁定 " + (bPlayerCheat ? "开启" : "关闭");
dtStartToast = DateTime.Now;
break;
case KeyCode.F2:
bSkillCheat = !bSkillCheat;
toast_txt = "※技能无冷却 " + (bSkillCheat ? "开启" : "关闭");
dtStartToast = DateTime.Now;
break;
case KeyCode.F3:
bKillCheat = !bKillCheat;
toast_txt = "※一击必杀" + (bKillCheat ? "开启" : "关闭");
dtStartToast = DateTime.Now;
break;
case KeyCode.F4:
bCrystalCheat = !bCrystalCheat;
toast_txt = "※魔法石不消耗 " + (bCrystalCheat ? "开启" : "关闭");
dtStartToast = DateTime.Now;
break;
case KeyCode.F5:
bArmorCheat = !bArmorCheat;
toast_txt = "※衣服破损程度锁定 " + (bArmorCheat ? "开启" : "关闭");
dtStartToast = DateTime.Now;
break;
case KeyCode.F6:
if(ArmorLevel > -1)
{
ArmorLevel--;
SetCharacterArmorLevelImmediate();
}
toast_txt = "※衣服破损程度 " + Enum.GetName(typeof(ArmorStatus), ArmorLevel);
break;
case KeyCode.F7:
if(ArmorLevel < 2)
{
ArmorLevel++;
SetCharacterArmorLevelImmediate();
}
toast_txt = "※衣服破损程度 " + Enum.GetName(typeof(ArmorStatus), ArmorLevel);
break;
}
}
}

private void SetCharacterArmorLevelImmediate()
{
delegate_characterArmorBreaker_SetArmorLevel ??=
AccessTools.Method(typeof(ACT.CharacterArmorBreaker), "SetArmorLevel", [typeof(int), typeof(ACT.CharacterArmorBreaker.CostumeUpdateMode)], null)
AccessTools.Method(typeof(ACT.CharacterArmorBreaker), "SetArmorLevel",new [] { typeof(int), typeof(ACT.CharacterArmorBreaker.CostumeUpdateMode) }, null)
.CreateDelegate<Action<ACT.CharacterArmorBreaker, int, ACT.CharacterArmorBreaker.CostumeUpdateMode>>();
foreach (var breaker in GameObject.FindObjectsOfType<ACT.CharacterArmorBreaker>())
delegate_characterArmorBreaker_SetArmorLevel.Invoke(breaker, ArmorLevel, ACT.CharacterArmorBreaker.CostumeUpdateMode.Force);
{
if(breaker.parentActor.IsPlayerActor)
{
delegate_characterArmorBreaker_SetArmorLevel.Invoke(breaker, ArmorLevel, ACT.CharacterArmorBreaker.CostumeUpdateMode.Normal);
}
}
}
}
7 changes: 5 additions & 2 deletions Ricca_Uncensor_Plugin/NoMosaic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ private void Start()

public void Update()
{
MosaicRemove();
if(CheatPatch.bNoMosaic)
{
MosaicRemove();
}
}

private static bool bMosaicCheck = false;
Expand All @@ -38,7 +41,7 @@ public void Update()

private static string mod = "mod_";

private string OldSceneName = "";
private string OldSceneName;

private Renderer[] Renderers;

Expand Down

0 comments on commit 9d98736

Please sign in to comment.