-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModEntry.cs
More file actions
165 lines (146 loc) · 9.31 KB
/
Copy pathModEntry.cs
File metadata and controls
165 lines (146 loc) · 9.31 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
using DXVision;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using TABModLoader;
using TABModLoader.Utils;
using static TABHelperMod.GamePatch;
namespace TABHelperMod
{
public class ModEntry : ModBase
{
internal static Harmony harmonyInstance = new Harmony("com.example.tabhelpermod");
public override void OnLoad(ModInfos modInfos)
{
try
{
ModOptions.Instance.Load(modInfos);
//Key Listener
Type type = AccessToolsEX.TypeByNameWithDecrypt("DXVision.DXGame");
MethodInfo originalMethod = AccessTools.Method(type, "ProcessKeyUp", new Type[] { typeof(DXKeys) });
HarmonyMethod postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnKeyUp)));
harmonyInstance.Patch(originalMethod, postfix: postfixMethod);
if (ModOptions.Instance.KeepDisplayAllLifeMeters)
{
//DisplayAllLifeMeters
//System.Void ZX.Components.CLife::OnUpdateSceneObjectParallel()
type = AccessToolsEX.TypeByNameWithDecrypt("ZX.Components.CLife");
originalMethod = AccessToolsEX.MethodWithDecrypt(type, "OnUpdateSceneObjectParallel");
postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnUpdateSceneObjectParallel)));
harmonyInstance.Patch(originalMethod, transpiler: postfixMethod);
}
if (ModOptions.Instance.FastAttack)
{
//FastAttack
type = AccessToolsEX.TypeByNameWithDecrypt("ZX.Commands.ZXCommand");
var ZXEntityType = AccessToolsEX.TypeByNameWithDecrypt("ZX.Entities.ZXEntity");
var ZXCommandTargetType = AccessToolsEX.TypeByNameWithDecrypt("ZX.Commands.ZXCommandTarget");
originalMethod = AccessToolsEX.MethodWithDecrypt(type, "PerformEffect", new Type[] { ZXEntityType, ZXCommandTargetType });
postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnPerformAttack)));
harmonyInstance.Patch(originalMethod, postfix: postfixMethod);
}
if (ModOptions.Instance.OptimizeTrainingSequence)
{
//Training Order Correction
type = AccessToolsEX.TypeByNameWithDecrypt("ZX.ZXSystem_GameLevel");
originalMethod = AccessToolsEX.MethodWithDecrypt(type, "_CommandsManager_OnOptionActivated", new Type[] { AccessToolsEX.TypeByNameWithDecrypt("ZX.GUI.ZXControlCommand") });
postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnOptionActivated)));
harmonyInstance.Patch(originalMethod, prefix: postfixMethod);
}
if (ModOptions.Instance.GameMenuEnhancer)
{
//GameMenuEnhancer
type = AccessToolsEX.TypeByNameWithDecrypt("ZX.ZXSystem_GameLevel");
originalMethod = AccessToolsEX.MethodWithDecrypt(type, "ShowGameMenu");
postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnShowInGameMenu)));
harmonyInstance.Patch(originalMethod, prefix: postfixMethod);
//GamePatch.DeleteGameSavePatch();
if (ModOptions.Instance.AutoDeleteBackups)
{
type = AccessToolsEX.TypeByNameWithDecrypt("ZX.ZXGame");
originalMethod = AccessToolsEX.MethodWithDecrypt(type, "DeleteSaveGames", new Type[] { typeof(string) });
var transpilerMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.DeleteSaveGamesTranspiler)));
postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnDeleteSaveGames)));
harmonyInstance.Patch(originalMethod, postfix: postfixMethod, transpiler: transpilerMethod);
}
}
if (ModOptions.Instance.CancelResearchAnytime)
{
//Cancel Research Anytime
type = AccessToolsEX.TypeByNameWithDecrypt("ZX.ZXCampaignState");
originalMethod = AccessToolsEX.MethodWithDecrypt(type, "get_IDResearchsRecentUnlocked");
postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnGetIDResearchsRecentUnlocked)));
harmonyInstance.Patch(originalMethod, prefix: postfixMethod);
type = AccessToolsEX.TypeByNameWithDecrypt("ZX.ZXCampaignState");
originalMethod = AccessToolsEX.MethodWithDecrypt(type, "get_HeroPerksTakenNow");
postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnGetHeroPerksTakenNow)));
harmonyInstance.Patch(originalMethod, prefix: postfixMethod);
}
if (ModOptions.Instance.OptimizeAttackPriority)
{
//Attack Priority Assistance
type = AccessToolsEX.TypeByNameWithDecrypt("ZX.Components.CEntityWatcher");
originalMethod = AccessToolsEX.MethodWithDecrypt(type, "UpdateNearestEnemy", new Type[] { typeof(bool) });
var transpilerMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnUpdateNearestEnemyTranspiler)));
harmonyInstance.Patch(originalMethod, transpiler: transpilerMethod);
}
if (ModOptions.Instance.GameSpeedChange)
{
//Game Speed Change
type = AccessToolsEX.TypeByNameWithDecrypt("DXVision.DXGame");
originalMethod = AccessTools.Method(type, "set_Paused", new Type[] { typeof(bool) });
postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnSetPaused)));
harmonyInstance.Patch(originalMethod, prefix: postfixMethod);
}
if (ModOptions.Instance.DisableAutoSave)
{
//Disable Auto-Save
type = AccessToolsEX.TypeByNameWithDecrypt("ZX.ZXSystem_GameLevel");
originalMethod = AccessToolsEX.MethodWithDecrypt(type, "SaveBackup");
postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnSaveBackup)));
harmonyInstance.Patch(originalMethod, prefix: postfixMethod);
}
if (!ModOptions.Instance.DisableAutoSave)
{
//change Auto-Save interval
type = AccessToolsEX.TypeByNameWithDecrypt("ZX.ZXSystem_GameLevel");
originalMethod = AccessToolsEX.MethodWithDecrypt(type, "CheckAutoBackup");
postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnCheckAutoBackup)));
harmonyInstance.Patch(originalMethod, transpiler: postfixMethod);
}
if (ModOptions.Instance.EnhancedSelection)
{
type = AccessToolsEX.TypeByNameWithDecrypt("ZX.ZXSystem_GameLevel");
originalMethod = AccessToolsEX.MethodWithDecrypt(type, "_OWorld_MouseDragFinish", new Type[] { typeof(DXObject), typeof(System.Drawing.Point) });
postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnCorrectSelection)));
harmonyInstance.Patch(originalMethod, prefix: postfixMethod);
}
if (ModOptions.Instance.QuickBuyResource)
{
//QuickBuyResource
//ZX.Commands.TradeCommand::OnExecute(ZX.Entities.ZXEntity,ZX.Commands.ZXCommandTarget)
List<string> TradeCommand = new List<string>() { "BuyIron", "BuyOil", "BuyStone", "BuyWood", "SellIron", "SellOil", "SellStone", "SellWood" };
var ZXEntityType = AccessToolsEX.TypeByNameWithDecrypt("ZX.Entities.ZXEntity");
var ZXCommandTargetType = AccessToolsEX.TypeByNameWithDecrypt("ZX.Commands.ZXCommandTarget");
foreach (string command in TradeCommand)
{
type = AccessToolsEX.TypeByNameWithDecrypt("ZX.Commands." + command);
originalMethod = AccessToolsEX.MethodWithDecrypt(type, "OnExecute", new Type[] { ZXEntityType, ZXCommandTargetType });
postfixMethod = new HarmonyMethod(AccessTools.Method(typeof(GamePatch), nameof(GamePatch.OnTradeCommandExecuted)));
harmonyInstance.Patch(originalMethod, postfix: postfixMethod);
}
}
}
catch (Exception e)
{
Debug.Log(e.ToString());
}
}
}
}