Skip to content

Commit dd66fd4

Browse files
committed
enhance: 调整输出日志的方法
1 parent 83e5106 commit dd66fd4

File tree

8 files changed

+129
-98
lines changed

8 files changed

+129
-98
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ dotnet new bepinex5plugin -T netstandard2.0 -U 2018.4.36 -n {Your-Mod-Name}
4343

4444
调整悟道的收益, 悟道点的获取倍率、降低感悟灵感的时间消耗、提高灵感提供的经验值
4545

46+
### ForgetWuDaoSkill(遗忘悟道技能)
47+
48+
可在学习悟道技能的界面中直接遗忘悟道技能。
49+
4650
## FAQ
4751
1. 如何开发新的 Mod
4852
```bash

michangsheng/BattleGains/Plugin.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using BepInEx;
43
using BepInEx.Configuration;
54
using HarmonyLib;
@@ -11,6 +10,9 @@ namespace BattleGains
1110
public class Plugin : BaseUnityPlugin
1211
{
1312

13+
public delegate void Log(object data);
14+
public static Log LogDebug;
15+
1416
static ConfigEntry<int> EquipmentDropMultiplier;
1517
static ConfigEntry<int> ItemDropMultiplier;
1618

@@ -26,13 +28,15 @@ private void Awake()
2628

2729
MoneyDropMultipiler = Config.Bind("BattleGains", "MoneyDropMultipiler", 5f, "金钱掉落倍率");
2830
Harmony.CreateAndPatchAll(typeof(Plugin));
31+
32+
LogDebug = Logger.LogDebug;
2933
}
3034

3135
// 掉落金钱
3236
[HarmonyPatch(typeof(FightVictory), "addMoney")] // Specify target method with HarmonyPatch attribute
3337
[HarmonyPrefix] // There are different patch types. Prefix code runs before original code
3438
static bool patchAddMoney(ref NpcDrop __instance, ref float percent){
35-
Console.WriteLine("calling patched FightVictory::addMoney");
39+
LogDebug("calling patched FightVictory::addMoney");
3640
percent = MoneyDropMultipiler.Value;
3741
return true;
3842
}
@@ -42,7 +46,7 @@ static bool patchAddMoney(ref NpcDrop __instance, ref float percent){
4246
[HarmonyPatch(typeof(NpcDrop), "dropReward")] // Specify target method with HarmonyPatch attribute
4347
[HarmonyPrefix] // There are different patch types. Prefix code runs before original code
4448
static bool dropReward(ref NpcDrop __instance, ref float equipLv, ref float packLv, int NPCID){
45-
Console.WriteLine("calling patched NpcDrop:dropReward");
49+
LogDebug("calling patched NpcDrop:dropReward");
4650
equipLv = 1;
4751
packLv = 1;
4852
return true;
@@ -53,7 +57,7 @@ static bool dropReward(ref NpcDrop __instance, ref float equipLv, ref float pack
5357
[HarmonyPrefix] // There are different patch types. Prefix code runs before original code
5458
static bool dropEquip(ref NpcDrop __instance, ref JSONObject ___npcDate, ref JSONObject addItemList, int NPCID)
5559
{
56-
Console.WriteLine("calling patched NpcDrop:dropEquip " + NPCID);
60+
LogDebug("calling patched NpcDrop:dropEquip " + NPCID);
5761
if (NPCID >= 20000) {
5862
JSONObject jsonobject = ___npcDate[NPCID.ToString()]["equipList"];
5963
foreach(string key in jsonobject.keys) {

michangsheng/BetterShoppingExperience/Plugin.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ public class Plugin : BaseUnityPlugin
1515
{
1616

1717
static UnityAction closeAction;
18+
public delegate void Log(object data);
19+
public static Log LogDebug;
1820

1921
private void Awake()
2022
{
2123
// Plugin startup logic
2224
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
2325

2426
Harmony.CreateAndPatchAll(typeof(Plugin));
27+
28+
LogDebug = Logger.LogDebug;
2529
}
2630

2731
private void Update() {
@@ -66,7 +70,7 @@ private void Update() {
6670
}
6771

6872
int next = findNext(o, currentId);;
69-
Console.WriteLine("Current" + currentId + ", next id = " + next);
73+
LogDebug("Current" + currentId + ", next id = " + next);
7074

7175
// stop closeAction
7276
closeAction = __instance.CloseAction;
@@ -86,7 +90,7 @@ static int findNext(List<int> list, int target) {
8690
index = list.FindIndex(delegate(int i){
8791
return i == target;
8892
});
89-
} catch (ArgumentNullException) {
93+
} catch (Exception) {
9094
return -1;
9195
}
9296

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,68 @@
11
using BepInEx;
2-
using KBEngine;
3-
using CaiJi;
42
using HarmonyLib;
5-
using System;
63

74
namespace CollectGains
85
{
96
[BepInPlugin("cn.shabywu.michangsheng.CollectGains", "采集耗时调整", "0.1.0")]
107
public class Plugin : BaseUnityPlugin
118
{
9+
public delegate void Log(object data);
10+
public static Log LogDebug;
11+
1212
private void Awake()
1313
{
1414
// Plugin startup logic
1515
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
1616

1717
Harmony.CreateAndPatchAll(typeof(CollectGains));
18+
19+
LogDebug = Logger.LogDebug;
1820
}
19-
}
2021

21-
[HarmonyPatch(typeof(CaiJiUIMag), "StartCaiJi")]
22-
public class CollectGains {
23-
static readonly object _object = new object();
22+
[HarmonyPatch(typeof(CaiJi.CaiJiUIMag), "StartCaiJi")]
23+
public class CollectGains {
24+
static readonly object _object = new object();
2425

25-
static Harmony singleton;
26+
static Harmony singleton;
2627

27-
static void Prefix()
28-
{
29-
Console.WriteLine("before StartCaiJi");
30-
if (singleton == null) {
31-
lock (_object) {
32-
Console.WriteLine("patch PatchContext");
33-
singleton = Harmony.CreateAndPatchAll(typeof(PatchContext));
28+
static void Prefix()
29+
{
30+
LogDebug("before StartCaiJi");
31+
if (singleton == null) {
32+
lock (_object) {
33+
LogDebug("patch PatchContext");
34+
singleton = Harmony.CreateAndPatchAll(typeof(PatchContext));
35+
}
36+
}
37+
}
38+
39+
static void Postfix()
40+
{
41+
if (singleton != null) {
42+
lock (_object) {
43+
if (singleton != null) {
44+
singleton.UnpatchSelf();
45+
singleton = null;
46+
LogDebug("unpatch PatchContext");
47+
}
48+
}
3449
}
50+
LogDebug("after StartCaiJi");
3551
}
3652
}
3753

38-
static void Postfix()
54+
public class PatchContext
3955
{
40-
if (singleton != null) {
41-
lock (_object) {
42-
if (singleton != null) {
43-
singleton.UnpatchSelf();
44-
singleton = null;
45-
Console.WriteLine("unpatch PatchContext");
46-
}
47-
}
56+
[HarmonyPatch(typeof(KBEngine.Avatar), "AddTime")] // Specify target method with HarmonyPatch attribute
57+
[HarmonyPrefix] // There are different patch types. Prefix code runs before original code
58+
static bool patchAvatarAddTime(ref int addday, ref int addMonth, ref int Addyear){
59+
// 减少采集的耗时, 将月修改成日, 年修改成月
60+
addday = addMonth;
61+
addMonth = Addyear;
62+
Addyear = 0;
63+
return true;
4864
}
49-
Console.WriteLine("after StartCaiJi");
5065
}
5166
}
5267

53-
public class PatchContext
54-
{
55-
[HarmonyPatch(typeof(Avatar), "AddTime")] // Specify target method with HarmonyPatch attribute
56-
[HarmonyPrefix] // There are different patch types. Prefix code runs before original code
57-
static bool patchAvatarAddTime(ref int addday, ref int addMonth, ref int Addyear){
58-
// 减少采集的耗时, 将月修改成日, 年修改成月
59-
addday = addMonth;
60-
addMonth = Addyear;
61-
Addyear = 0;
62-
return true;
63-
}
64-
}
6568
}

michangsheng/ForgetWuDaoSkill/Plugin.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using UnityEngine.UI;
44
using HarmonyLib;
55
using System.Collections.Generic;
6-
using System;
76

87

98
namespace ForgetWuDaoSkill
@@ -12,13 +11,18 @@ namespace ForgetWuDaoSkill
1211
public class Plugin : BaseUnityPlugin
1312
{
1413

14+
public delegate void Log(object data);
15+
public static Log LogDebug;
16+
1517
private void Awake()
1618
{
1719
// Plugin startup logic
1820
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
1921

2022
Harmony.CreateAndPatchAll(typeof(PatchWuDaoTooltipShow));
2123
Harmony.CreateAndPatchAll(typeof(Plugin));
24+
25+
LogDebug = Logger.LogDebug;
2226
}
2327

2428
[HarmonyPatch(typeof(Tab.WuDaoTooltip), "Show")]
@@ -28,7 +32,7 @@ public class PatchWuDaoTooltipShow {
2832

2933
static void Prefix(ref int wudaoId)
3034
{
31-
Console.WriteLine("before WuDaoTooltip::Show");
35+
LogDebug("before WuDaoTooltip::Show");
3236
if (wudaoId > 0) {
3337
flags[wudaoId] = false;
3438
return;
@@ -42,7 +46,7 @@ static void Prefix(ref int wudaoId)
4246

4347
static void Postfix(ref int wudaoId, ref Text ____cost, ref FpBtn ____btn)
4448
{
45-
Console.WriteLine("after WuDaoTooltip::Show");
49+
LogDebug("after WuDaoTooltip::Show");
4650
if (flags[wudaoId]) {
4751
____cost.text = ____cost.text.Replace("【需求点数】", "【返还点数】");
4852
____btn.GetComponentInChildren<Text>().text = "遗忘";
@@ -66,7 +70,7 @@ static bool patchWuDaoSlotSetState(ref Tab.WuDaoSlot __instance, ref int state,
6670
____go.GetComponent<Tab.TabListener>().mouseUpEvent.AddListener(delegate()
6771
{
6872
WuDaoTooltip.Show(icon.sprite, -instance.Id, delegate(){
69-
Console.WriteLine("calling Forget");
73+
LogDebug("calling Forget");
7074
Forget(instance);
7175
});
7276

@@ -77,7 +81,7 @@ static bool patchWuDaoSlotSetState(ref Tab.WuDaoSlot __instance, ref int state,
7781
____go.GetComponent<Tab.TabListener>().mouseUpEvent.AddListener(delegate()
7882
{
7983
WuDaoTooltip.Show(icon.sprite, instance.Id, delegate(){
80-
Console.WriteLine("calling Study");
84+
LogDebug("calling Study");
8185
Study(instance);
8286
});
8387
});
Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,77 @@
11
using BepInEx;
2-
using KBEngine;
32
using HarmonyLib;
4-
using System;
53

64
namespace InstantlyForgeAndRefine
75
{
86
[BepInPlugin("cn.shabywu.michangsheng.InstantlyForgeAndRefine", "瞬间炼器和炼丹", "0.1.0")]
97
public class Plugin : BaseUnityPlugin
108
{
9+
10+
public delegate void Log(object data);
11+
public static Log LogDebug;
1112
private void Awake()
1213
{
1314
// Plugin startup logic
1415
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
1516
Harmony.CreateAndPatchAll(typeof(InstantlyRefine));
1617
Harmony.CreateAndPatchAll(typeof(InstanlyForge));
17-
}
1818

19-
}
19+
LogDebug = Logger.LogDebug;
20+
}
2021

21-
public class InstanlyForge {
22-
[HarmonyPatch(typeof(LianQiResultManager), "getCostTime")]
23-
[HarmonyPrefix]
24-
static bool patchGetCostTime(ref int __result){
25-
Console.WriteLine("calling patched LianQiResultManager::getCostTime");
26-
__result = 0;
27-
return false;
22+
public class InstanlyForge {
23+
[HarmonyPatch(typeof(LianQiResultManager), "getCostTime")]
24+
[HarmonyPrefix]
25+
static bool patchGetCostTime(ref int __result){
26+
LogDebug("calling patched LianQiResultManager::getCostTime");
27+
__result = 0;
28+
return false;
29+
}
2830
}
29-
}
3031

32+
[HarmonyPatch(typeof(LianDanResultManager), "lianDanJieSuan")]
33+
public class InstantlyRefine {
34+
static readonly object _object = new object();
3135

32-
[HarmonyPatch(typeof(LianDanResultManager), "lianDanJieSuan")]
33-
public class InstantlyRefine {
34-
static readonly object _object = new object();
36+
static Harmony singleton;
3537

36-
static Harmony singleton;
38+
[HarmonyPrefix]
39+
static void Prefix()
40+
{
41+
LogDebug("before lianDanJieSuan");
42+
if (singleton == null) {
43+
lock (_object) {
44+
LogDebug("patch Avatar::AddTime");
45+
singleton = Harmony.CreateAndPatchAll(typeof(AvatarPatcher));
46+
}
47+
}
48+
}
3749

38-
[HarmonyPrefix]
39-
static void Prefix()
40-
{
41-
Console.WriteLine("before lianDanJieSuan");
42-
if (singleton == null) {
43-
lock (_object) {
44-
Console.WriteLine("patch Avatar::AddTime");
45-
singleton = Harmony.CreateAndPatchAll(typeof(AvatarPatcher));
50+
[HarmonyPostfix]
51+
static void Postfix()
52+
{
53+
if (singleton != null) {
54+
lock (_object) {
55+
if (singleton != null) {
56+
singleton.UnpatchSelf();
57+
singleton = null;
58+
LogDebug("unpatch Avatar::AddTime");
59+
}
60+
}
4661
}
62+
LogDebug("after lianDanJieSuan");
4763
}
4864
}
4965

50-
[HarmonyPostfix]
51-
static void Postfix()
66+
public class AvatarPatcher
5267
{
53-
if (singleton != null) {
54-
lock (_object) {
55-
if (singleton != null) {
56-
singleton.UnpatchSelf();
57-
singleton = null;
58-
Console.WriteLine("unpatch Avatar::AddTime");
59-
}
60-
}
68+
[HarmonyPatch(typeof(KBEngine.Avatar), "AddTime")] // Specify target method with HarmonyPatch attribute
69+
[HarmonyPrefix] // There are different patch types. Prefix code runs before original code
70+
static bool patchAvatarAddTime(){
71+
LogDebug("Avatar::AddTime, skip add any time.");
72+
return false;
6173
}
62-
Console.WriteLine("after lianDanJieSuan");
6374
}
64-
}
6575

66-
public class AvatarPatcher
67-
{
68-
[HarmonyPatch(typeof(Avatar), "AddTime")] // Specify target method with HarmonyPatch attribute
69-
[HarmonyPrefix] // There are different patch types. Prefix code runs before original code
70-
static bool patchAvatarAddTime(){
71-
Console.WriteLine("Avatar::AddTime, skip add any time.");
72-
return false;
73-
}
7476
}
7577
}

0 commit comments

Comments
 (0)