-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHarmony_Patch.cs
More file actions
378 lines (372 loc) · 15.2 KB
/
Harmony_Patch.cs
File metadata and controls
378 lines (372 loc) · 15.2 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
using CommandWindow;
using CreatureInfo;
using GlobalBullet;
using Harmony;
using HPHelper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using UnityEngine;
namespace BossAmiya
{
public class Note_For_Developers
{
public const string AAA_NOTE_CN = "如果你在使用Dnspy,ILSpy等工具解包,大可不必,你可以直接在 https://github.com/ZengXiaoPi/BossAmiya 获取源代码。本模组使用MIT协议开源。";
public const string AAA_NOTE_EN = "If you are using Dnspy, ILSpy or other decompilers, you can directly download the source code from https://github.com/ZengXiaoPi/BossAmiya. This mod is licensed under the MIT license.";
}
public class Harmony_Patch
{
public static readonly string VERSION = "1.2.2";
public static YKMTLog logger;
public static string path = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path));
public static Sprite RealDamage_Sprite = Extension.CreateSprite("Image/RealDamage.png", SpriteMeshType.FullRect);
public static Color RealDamage_Color = new Color32(184, 183, 183, byte.MaxValue);
public static List<UnitModel> RealDamage_TempList = [];
public Harmony_Patch()
{
logger = new YKMTLog(path + "/Logs", false);
HarmonyInstance harmony = HarmonyInstance.Create("BossAmiya.zxp");
logger.Info("—————————————————NEW GAME———————————————————");
try
{
// 初始化凋亡UI
ElementUI.Instance.InitAB();
// 读取配置
AwardConfigReader.ReadConfig();
HPPatcher.PatchAll(harmony, typeof(Harmony_Patch));
HPPatcher.PatchAll(harmony, typeof(AwardPatch));
}
catch (Exception ex)
{
logger.Error($"When patch, the error occurred.");
logger.Error(ex);
}
logger.Info($"Story started. BossAmiya v{VERSION} is loaded.");
logger.Info($"故事开始。魔王阿米娅 v{VERSION} 已加载。");
}
[HPHelper(typeof(CreatureInfoStatRoot), "WorkDamageListInit", true)]
[HPPostfix]
public static void CreatureInfoStatRoot_WorkDamageListInit(ref CreatureInfoStatRoot __instance)
{
if (__instance.CurrentModel != null)
{
if (__instance.CurrentModel.metaInfo.id == 521892L)
{
__instance.WorkDamageType.text = "C.E.";
__instance.WorkDamageType.color = RealDamage_Color;
__instance.WorkDamageFill.sprite = RealDamage_Sprite;
}
}
}
[HPHelper(typeof(WorkAllocateRegion), "OnObserved", typeof(CreatureModel))]
[HPPostfix]
public static void WorkAllocateRegion_OnObserved(ref WorkAllocateRegion __instance)
{
if (__instance.CurrentModel == null) return;
if (__instance.CurrentModel.metaInfo.id != 521892L) return;
__instance.WorkDamageType.text = "C.E.";
__instance.WorkDamageType.color = RealDamage_Color;
__instance.WorkDamageFill.sprite = RealDamage_Sprite;
}
[HPHelper(typeof(WorkerModel), nameof(WorkerModel.TakeDamage), typeof(UnitModel), typeof(DamageInfo))]
[HPPrefix]
public static void WorkerModel_TakeDamage(ref WorkerModel __instance, UnitModel actor, DamageInfo dmg)
{
if (actor is CreatureModel)
{
if ((actor as CreatureModel).metaInfo.id != 521892L) return;
if (RealDamage_TempList.Contains(__instance)) return;
RealDamage_TempList.Add(__instance);
}
else if (actor is AgentModel)
{
if ((actor as AgentModel).Equipment.armor.metaInfo.id == 52189301)
{
if (RealDamage_TempList.Contains(__instance)) return;
RealDamage_TempList.Add(__instance);
}
}
}
[HPHelper(typeof(CreatureModel), nameof(CreatureModel.TakeDamage), typeof(UnitModel), typeof(DamageInfo))]
[HPPrefix]
public static void CreatureModel_TakeDamage(ref CreatureModel __instance, UnitModel actor, DamageInfo dmg)
{
if (actor is CreatureModel)
{
if ((actor as CreatureModel).metaInfo.id != 521892L) return;
if (RealDamage_TempList.Contains(__instance)) return;
RealDamage_TempList.Add(__instance);
}
else if (actor is AgentModel)
{
if ((actor as AgentModel).Equipment.armor.metaInfo.id == 52189301)
{
if (RealDamage_TempList.Contains(__instance)) return;
RealDamage_TempList.Add(__instance);
}
}
}
[HPHelper(typeof(DamageEffect), "SetData", typeof(RwbpType), typeof(int), typeof(DefenseInfo.Type), typeof(UnitModel))]
[HPPostfix]
public static void DamageEffect_SetData(ref DamageEffect __instance, RwbpType type, int damage, DefenseInfo.Type defense, UnitModel unit)
{
if (type == RwbpType.N && RealDamage_TempList.Contains(unit))
{
RealDamage_TempList.Remove(unit);
__instance.DamageCount.color = RealDamage_Color;
__instance.DamageContext.color = RealDamage_Color;
__instance.Frame.color = RealDamage_Color;
__instance.IconOut.color = Color.grey;
__instance.DefenseTypeInner.color = Color.grey;
__instance.DefenseTypeText.color = RealDamage_Color;
__instance.Icon.sprite = RealDamage_Sprite;
}
}
[HPHelper(typeof(SoundEffectPlayer), nameof(SoundEffectPlayer.Stop))]
[HPPrefix]
public static void SoundEffectPlayer_Stop(ref SoundEffectPlayer __instance)
{
if (BossAmiya.fullBGMplayer == null) return;
if (__instance == BossAmiya.fullBGMplayer)
{
BossAmiya.loopBGMplayer = BossAmiya.PlayBGM(file: "bgm-loop.wav", loop: true);
}
}
[HPHelper(typeof(CreatureSuppressRegion), nameof(CreatureSuppressRegion.SetData), typeof(UnitModel))]
[HPPostfix]
public static void CreatureSuppressRegion_SetData(ref CreatureSuppressRegion __instance, UnitModel target)
{
CreatureModel fixcreature = target as CreatureModel;
if (fixcreature.script is Kaltsit)
{
__instance.Portrait.sprite = Sprites.KaltsitSprite;
}
else if (fixcreature.script is Mon2tr)
{
__instance.Portrait.sprite = Sprites.Mon2trSprite;
}
else if (fixcreature.script is LCP)
{
__instance.Portrait.sprite = Sprites.LCPSprite;
}
else if (fixcreature.script is Goria)
{
__instance.Portrait.sprite = Sprites.GoriaSprite;
}
else if (fixcreature.script is Lamalian)
{
__instance.Portrait.sprite = Sprites.LamalianSprite;
}
else if (fixcreature.script is TSLZ)
{
__instance.Portrait.sprite = Sprites.TSLZSprite;
}
else if (fixcreature.script is Reid)
{
__instance.Portrait.sprite = Sprites.ReidSprite;
}
}
[HPHelper(typeof(GameManager), nameof(GameManager.EndGame))]
[HPPostfix]
public static void GameManager_EndGame()
{
ElementManager.Instance.ClearDictionary();
}
[HPHelper(typeof(ConsoleScript), "GetHmmCommand", typeof(string))]
[HPPrefix]
public static bool ConsoleScript_GetHmmCommand(string cmd, ref string __result)
{
try
{
if (cmd == "")
{
return true;
}
string[] array = cmd.Split(new char[]
{
' '
});
string type1 = array[0].ToLower();
string type2 = "";
string type3 = "";
if (array.Length >= 2)
{
type2 = array[1].ToLower().Trim();
}
if (array.Length >= 3)
{
type3 = array[2].ToLower().Trim();
}
int value = 0;
if (array.Length >= 4)
{
value = Convert.ToInt32(array[3].ToLower().Trim());
}
int value2 = 0;
if (array.Length >= 5)
{
value2 = Convert.ToInt32(array[4].ToLower().Trim());
}
if (type1 == "zxp")
{
if (type2 == "element")
{
if (type3 == "damage")
{
var agent = AgentManager.instance.GetAgent(value);
if (agent != null)
{
ElementManager.Instance.GiveElementDamage(agent, value2);
__result = "";
return false;
}
else
{
logger.Error("Agent not found.");
}
}
}
if (type2 == "mode")
{
if (type3 == "switch")
{
if (HardModeManager.Instance.isHardMode())
{
Extension.ShowMessageBox("当前模式为:普通模式。");
HardModeManager.Instance.setIsHardMode(false);
__result = "";
return false;
}
else
{
Extension.ShowMessageBox("当前模式为:困难模式。");
HardModeManager.Instance.setIsHardMode(true);
__result = "";
return false;
}
}
}
}
if ((cmd == "creature cryofbanshee" || cmd == "rimi creature cryofbanshee") && BossAmiya.amiyaPhase == 2)
{
SefiraConversationController.Instance.UpdateConversation(Sprites.AmiyaSprite, Sprites.Amiya_Color, LocalizeTextDataModel.instance.GetText("BlockTT10_Amiya"));
__result = "";
return false;
}
}
catch (Exception ex)
{
logger.Error(ex);
}
return true;
}
[HPHelper(typeof(UnitModel), nameof(UnitModel.Attack), typeof(UnitModel))]
[HPPrefix]
public static bool UnitModel_Attack(UnitModel target, ref UnitModel __instance)
{
if (__instance is AgentModel)
{
if (ElementManager.Instance.ElementUnitIsBreaking.ContainsKey((AgentModel)__instance))
{
if (ElementManager.Instance.ElementUnitIsBreaking[(AgentModel)__instance])
{
return false;
}
}
}
return true;
}
[HPHelper(typeof(AgentModel), "Die")]
[HPPostfix]
public static void WorkerModel_Die(ref WorkerModel __instance)
{
if (__instance is AgentModel)
{
if (ElementUI.Instance.GetElementController((AgentModel)__instance) != null)
{
ElementUI.Instance.RemoveElementUIFromAgent((AgentModel)__instance);
}
}
}
[HPHelper(typeof(UnitModel), "GetDmgMultiplierByEgoLevel")]
[HPPrefix]
public static bool UnitModel_GetDmgMultiplierByEgoLevel(int attackLevel, int defenseLevel, ref float __result)
{
if (RealDamage_TempList.Count > 0)
{
__result = 1.0f;
return false;
}
return true;
}
[HPHelper(typeof(GlobalBulletManager), "SlowBullet")]
[HPPrefix]
public static void GlobalBulletManager_SlowBullet(UnitModel target)
{
if (target is CreatureModel && (target as CreatureModel).script is Reid)
{
Reid reid = (target as CreatureModel).script as Reid;
if (!HardModeManager.Instance.isHardMode())
{
target.AddUnitBuf(new Reid_weak(reid.speed / 5f * 1.5f, reid.speed / 5f * 30f));
}
else
{
target.AddUnitBuf(new Reid_weak(reid.speed / 7.5f * 4f, reid.speed / 5f * 60f));
}
reid.speed = 0f;
}
}
[HPHelper(typeof(GameManager), "UpdateGameSpeed")]
[HPPostfix]
public static void GameManager_UpdateGameSpeed()
{
if (BossAmiya.amiyaPhase == 2 && Time.timeScale > 2f)
{
SefiraConversationController.Instance.UpdateConversation(Sprites.AmiyaSprite, Sprites.Amiya_Color, LocalizeTextDataModel.instance.GetText("BlockTT10_Amiya"));
Time.timeScale = 1f;
Time.fixedDeltaTime = 0.02f;
}
}
[HPHelper(typeof(ChildCreatureModel), "Suppressed")]
[HPPrefix]
public static bool CreatureModel_Suppressed(ref ChildCreatureModel __instance)
{
if (__instance.script is Reid)
{
if (Reid.phase == ReidPhase.Phase2 || Reid.phase == ReidPhase.Suppressed)
{
return true;
}
else
{
Reid script = (Reid)__instance.script;
if (script.isChangingPhase && Reid.phase == ReidPhase.Phase1)
{
__instance.hp = 1f;
return false;
}
else
{
__instance.hp = 1f;
script.isChangingPhase = true;
__instance.commandQueue.Clear();
script.animscript.IntoChangingPhase();
return false;
}
}
}
return true;
}
[HPHelper(typeof(GlobalBulletManager), "SetMaxBullet")]
[HPPostfix]
public static void GlobalBulletManager_SetMaxBullet(ref int max)
{
if (AwardConfig.beatAmiya && AwardConfig.useAmiyaBullet)
{
max = (int)MathEx.RoundUp(max * 1.5f, 0);
}
}
}
}