|
1 | 1 | using BepInEx; |
2 | | -using KBEngine; |
3 | 2 | using HarmonyLib; |
4 | | -using System; |
5 | 3 |
|
6 | 4 | namespace InstantlyForgeAndRefine |
7 | 5 | { |
8 | 6 | [BepInPlugin("cn.shabywu.michangsheng.InstantlyForgeAndRefine", "瞬间炼器和炼丹", "0.1.0")] |
9 | 7 | public class Plugin : BaseUnityPlugin |
10 | 8 | { |
| 9 | + |
| 10 | + public delegate void Log(object data); |
| 11 | + public static Log LogDebug; |
11 | 12 | private void Awake() |
12 | 13 | { |
13 | 14 | // Plugin startup logic |
14 | 15 | Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!"); |
15 | 16 | Harmony.CreateAndPatchAll(typeof(InstantlyRefine)); |
16 | 17 | Harmony.CreateAndPatchAll(typeof(InstanlyForge)); |
17 | | - } |
18 | 18 |
|
19 | | - } |
| 19 | + LogDebug = Logger.LogDebug; |
| 20 | + } |
20 | 21 |
|
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 | + } |
28 | 30 | } |
29 | | - } |
30 | 31 |
|
| 32 | + [HarmonyPatch(typeof(LianDanResultManager), "lianDanJieSuan")] |
| 33 | + public class InstantlyRefine { |
| 34 | + static readonly object _object = new object(); |
31 | 35 |
|
32 | | - [HarmonyPatch(typeof(LianDanResultManager), "lianDanJieSuan")] |
33 | | - public class InstantlyRefine { |
34 | | - static readonly object _object = new object(); |
| 36 | + static Harmony singleton; |
35 | 37 |
|
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 | + } |
37 | 49 |
|
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 | + } |
46 | 61 | } |
| 62 | + LogDebug("after lianDanJieSuan"); |
47 | 63 | } |
48 | 64 | } |
49 | 65 |
|
50 | | - [HarmonyPostfix] |
51 | | - static void Postfix() |
| 66 | + public class AvatarPatcher |
52 | 67 | { |
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; |
61 | 73 | } |
62 | | - Console.WriteLine("after lianDanJieSuan"); |
63 | 74 | } |
64 | | - } |
65 | 75 |
|
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 | | - } |
74 | 76 | } |
75 | 77 | } |
0 commit comments