-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
118 lines (102 loc) · 4.34 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using BattleImprove.Patcher.BattleFeedback;
using BattleImprove.Patcher.QOL;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using PerfectRandom.Sulfur.Core;
using PerfectRandom.Sulfur.Core.Input;
using PerfectRandom.Sulfur.Core.Units;
using UnityEngine;
namespace BattleImprove;
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin {
internal new static ManualLogSource Logger;
internal static AssetBundle AssetBundle;
private bool isInitialized = false;
private bool debugMode = false;
public void Awake() {
this.gameObject.hideFlags = HideFlags.HideAndDontSave;
Logger = base.Logger;
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loading!");
// Config
BattleImprove.Config.InitConifg(this.Config);
// Harmony patching
Patching();
// Load asset bundle
// var sAssemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
// AssetBundle = AssetBundle.LoadFromFile(Path.Combine(sAssemblyLocation, "battle_improve"));
// if (AssetBundle == null) {
// Logger.LogError("Failed to load custom assets.");
// return;
// }
AssetBundle = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly()
.GetManifestResourceStream("BattleImprove.Assets.battle_improve"));
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!");
#if DEBUG
debugMode = true;
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} debug mode is enable!");
#endif
}
private void Start() {
this.Print("Plugin is starting...");
StartCoroutine(Init());
}
private IEnumerator Init() {
while (!isInitialized) {
this.Print("GameManager not found! Wait for 3 seconds...", true);
yield return new WaitForSeconds(3);
if (StaticInstance<GameManager>.Instance != null) {
isInitialized = true;
StaticInstance.AddBattleImprove();
this.Print("GameManager found! Start Init!", true);
}
}
}
private void Patching() {
Harmony.CreateAndPatchAll(typeof(StaticInstance));
// QOL
if (BattleImprove.Config.EnableExpShare.Value) Harmony.CreateAndPatchAll(typeof(ExpSharePatch));
if (BattleImprove.Config.EnableHealthBar.Value) Harmony.CreateAndPatchAll(typeof(HealthBarPatch));
// BF
if (BattleImprove.Config.EnableSoundFeedback.Value) Harmony.CreateAndPatchAll(typeof(SoundPatch));
if (BattleImprove.Config.EnableDeadUnitCollision.Value) Harmony.CreateAndPatchAll(typeof(DeadUnitCollisionPatch));
Harmony.CreateAndPatchAll(typeof(AttackFeedbackPatch));
}
public void Print(string info, bool needDebug = false) {
switch (needDebug) {
case true when debugMode:
Logger.LogInfo("Debug info: " + info);
break;
case false:
Logger.LogInfo(info);
break;
}
}
public class StaticInstance {
internal static GameObject PluginInstance;
internal static Npc[] Enemies;
internal static List<Unit> KilledEnemies;
internal static HitSoundEffect HitSoundClips;
internal static xCrossHair CrossHair;
internal static KillMessage KillMessage;
internal static DamageInfo DamageInfo;
public static void AddBattleImprove() {
PluginInstance = Instantiate(AssetBundle.LoadAsset<GameObject>("BattleImprove"));
HitSoundClips = PluginInstance.GetComponentInChildren<HitSoundEffect>();
CrossHair = PluginInstance.GetComponentInChildren<xCrossHair>();
KillMessage = PluginInstance.GetComponentInChildren<KillMessage>();
DamageInfo = PluginInstance.GetComponentInChildren<DamageInfo>();
}
[HarmonyPrefix]
[HarmonyPriority(Priority.First)]
[HarmonyPatch(typeof(InputReader), "LoadingContinue")]
private static void AddFrame() {
Enemies = StaticInstance<UnitManager>.Instance.GetAllEnemies();
KilledEnemies = new List<Unit>();
}
}
}