-
Notifications
You must be signed in to change notification settings - Fork 0
/
IngressPoint.cs
279 lines (244 loc) · 14.9 KB
/
IngressPoint.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using HarmonyLib;
using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
namespace IncreasedRange
{
public static class IngressPoint
{
private static FieldInfo behaviorTreeMap = typeof(BehaviorManager).GetField("behaviorTreeMap", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
private static bool ranOnce = false;
/* [HarmonyPatch(typeof(Weapons))]
[HarmonyPatch("AimAtTarget")]
public static class PatchAlwaysFire
{
public static void Postfix(ref Weapons __instance, ref Tank tank)
{
__instance.FireWeapons(tank);
}
} */
/* [HarmonyPatch(typeof(ModuleWeapon))]
[HarmonyPatch("UpdateAutoAimBehaviour")]
public static class PatchAlwaysFire
{
private static FieldInfo m_HasTargetInFiringCone = typeof(ModuleWeapon).GetField("m_HasTargetInFiringCone", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
private static FieldInfo m_CurrentAITreeType = typeof(TechAI).GetField("m_CurrentAITreeType", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
public static void Postfix(ref ModuleWeapon __instance)
{
if ((bool) m_HasTargetInFiringCone.GetValue(__instance) && __instance.block.tank.IsAIControlled())
{
AITreeType currentTreeType = (AITreeType)m_CurrentAITreeType.GetValue(__instance.block.tank.AI);
if (currentTreeType != null && currentTreeType.IsType(AITreeType.AITypes.Guard))
{
__instance.FireControl = true;
}
}
}
} */
public static class PatchLog
{
/*
[HarmonyPatch(typeof(BehaviorManager.BehaviorTree))]
[HarmonyPatch("Initialize")]
public static class PatchInitialize
{
public static void Postfix(ref BehaviorManager.BehaviorTree __instance)
{
Console.WriteLine($"Initializing Behavior Tree {__instance.behavior}");
__instance.behavior.LogTaskChanges = true;
}
}
*/
/* [HarmonyPatch(typeof(BehaviorManager))]
[HarmonyPatch("EnableBehavior")]
public static class PatchEnableBehavior
{
private static FieldInfo behaviorTreeMap = typeof(BehaviorManager).GetField("behaviorTreeMap", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
private static FieldInfo pausedBehaviorTrees = typeof(BehaviorManager).GetField("pausedBehaviorTrees", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
public static bool Prefix(ref BehaviorManager __instance, ref Behavior behavior)
{
Dictionary<Behavior, BehaviorManager.BehaviorTree> behaviorTreeMap = (Dictionary<Behavior, BehaviorManager.BehaviorTree>)PatchEnableBehavior.behaviorTreeMap.GetValue(__instance);
if (__instance.IsBehaviorEnabled(behavior) && behaviorTreeMap.TryGetValue(behavior, out BehaviorManager.BehaviorTree tree))
{
Console.WriteLine($"Attempt to enable already enabled Behavior Tree {tree.behavior.BehaviorName} : {tree.behavior.BehaviorDescription}");
return false;
}
Dictionary<Behavior, BehaviorManager.BehaviorTree> pausedBehaviorTrees = (Dictionary<Behavior, BehaviorManager.BehaviorTree>)PatchEnableBehavior.pausedBehaviorTrees.GetValue(__instance);
if (behavior != null && BehaviorManager.instance != null && pausedBehaviorTrees.TryGetValue(behavior, out tree))
{
Console.WriteLine($"Enabling Paused Behavior Tree {tree.behavior.BehaviorName} : {tree.behavior.BehaviorDescription}");
tree.behavior.LogTaskChanges = true;
}
else
{
Console.WriteLine("Enabling Uninitialized Behavior Tree");
}
return true;
}
private static string NodeString(BehaviorDesigner.Runtime.Tasks.Task task)
{
return $"({task.FriendlyName}:{task.GetHashCode()})";
}
public static void Postfix(ref BehaviorManager __instance, ref Behavior behavior)
{
Dictionary<Behavior, BehaviorManager.BehaviorTree> behaviorTreeMap = (Dictionary<Behavior, BehaviorManager.BehaviorTree>)PatchEnableBehavior.behaviorTreeMap.GetValue(__instance);
if (behavior != null && BehaviorManager.instance != null)
{
BehaviorManager.BehaviorTree tree = behaviorTreeMap[behavior];
Console.WriteLine("MY DEBUG:");
Console.WriteLine($"Task List: [{(tree.taskList == null ? "" : string.Join(", ", tree.taskList.Select(task => NodeString(task))))}]");
Console.WriteLine($"Parent Index: [{(tree.parentIndex == null ? "" : string.Join(", ", tree.parentIndex.Select(ind => ind < 0 ? "ROOT" : NodeString(tree.taskList[ind]))))}]");
Console.WriteLine($"Children Index: [\n{(tree.childrenIndex == null ? "" : string.Join(",\n", tree.childrenIndex.Select(list => list == null ? "\t[]" : "\t[" + string.Join(", ", list.Select(ind => ind < 0 ? "ROOT" : NodeString(tree.taskList[ind]))) + "]")))}]");
Console.WriteLine($"Relative Child Index: [{(tree.relativeChildIndex == null ? "" : string.Join(", ", tree.relativeChildIndex.Select(ind => ind < 0 ? "ROOT" : NodeString(tree.taskList[ind]))))}]");
Console.WriteLine($"Parent Composite Index: [{(tree.parentCompositeIndex == null ? "" : string.Join(", ", tree.parentCompositeIndex.Select(ind => ind < 0 ? "ROOT" : NodeString(tree.taskList[ind]))))}]");
Console.WriteLine($"Children Conditional Index: [\n{(tree.childConditionalIndex == null ? "" : string.Join(",\n", tree.childConditionalIndex.Select(list => list == null ? "\t[]" : "\t[" + string.Join(", ", list.Select(ind => ind < 0 ? "ROOT" : NodeString(tree.taskList[ind]))) + "]")))}]");
}
}
} */
}
[HarmonyPatch(typeof(TechWeapon))]
[HarmonyPatch("OnSpawn")]
public static class PatchManualRange
{
public static void Postfix(ref TechWeapon __instance)
{
__instance.m_ManualTargetingSettingsGamepad.m_ManualTargetingRadiusSP = 900.0f;
__instance.m_ManualTargetingSettingsMAndKB.m_ManualTargetingRadiusSP = 900.0f;
}
}
/* [HarmonyPatch(typeof(EnemyInRange))]
[HarmonyPatch("OnUpdate")]
public static class PatchNeverRange
{
public static void Postfix(ref TaskStatus __result)
{
__result = TaskStatus.Failure;
}
} */
// For standard AI enemies
[HarmonyPatch(typeof(ChargeAtVisible))]
[HarmonyPatch("OnAwake")]
public static class PatchAttackRange
{
public static void Postfix(ref ChargeAtVisible __instance)
{
__instance.m_AttackRange = 900.0f;
}
}
[HarmonyPatch(typeof(GetNearestPlayerOnTeam))]
[HarmonyPatch("OnAwake")]
public static class PatchGetNearestPlayerOnTeam
{
public static void Postfix(ref GetNearestPlayerOnTeam __instance)
{
__instance.m_MaxRange.SetValue(1800.0f);
}
}
/* [HarmonyPatch(typeof(VisibleInRange))]
[HarmonyPatch("OnAwake")]
public static class PatchVisibleInRange
{
public static void Postfix(ref VisibleInRange __instance)
{
__instance.m_Range.SetValue(900.0f);
}
}
[HarmonyPatch(typeof(TechVision))]
[HarmonyPatch("OnSpawn")]
public static class PatchTechVision
{
private static FieldInfo m_SearchRadius = typeof(TechVision).GetField("m_SearchRadius", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
public static void Postfix(ref TechVision __instance)
{
m_SearchRadius.SetValue(__instance, Mathf.Max(900.0f, (float)m_SearchRadius.GetValue(__instance)));
}
} */
[HarmonyPatch(typeof(ModuleRadar))]
[HarmonyPatch("OnPool")]
public static class PatchModuleRadar
{
public static void Postfix(ref ModuleRadar __instance)
{
FieldInfo m_Range = typeof(ModuleRadar).GetField("m_Range", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
m_Range.SetValue(__instance, Mathf.Max(900.0f, (float)m_Range.GetValue(__instance)));
}
}
[HarmonyPatch(typeof(ModuleVision))]
[HarmonyPatch("OnPool")]
public static class PatchModuleVision
{
private static FieldInfo m_Range = typeof(ModuleVision).GetField("m_Range", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
public static void Postfix(ref ModuleVision __instance)
{
__instance.visionRange = Mathf.Max(__instance.visionRange, 900.0f);
__instance.visionConeAngle = 360.0f;
m_Range.SetValue(__instance, Mathf.Max(900.0f, (float)m_Range.GetValue(__instance)));
}
}
/* [HarmonyPatch(typeof(TechAI))]
[HarmonyPatch("OnSpawn")]
public static class PatchLogIn
{
private static MethodInfo EnableCurrentTree = typeof(TechAI).GetMethod("EnableCurrentTree", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
private static MethodInfo DisableCurrentTree = typeof(TechAI).GetMethod("DisableCurrentTree", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
private static FieldInfo m_BehaviorTree = typeof(TechAI).GetField("m_BehaviorTree", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
private static FieldInfo m_CurrentAITreeType = typeof(TechAI).GetField("m_CurrentAITreeType", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
private static string NodeString(BehaviorDesigner.Runtime.Tasks.Task task)
{
return $"({task.FriendlyName}:{task.GetHashCode()})";
}
public static void Postfix(ref TechAI __instance)
{
BehaviorTree behavior = (BehaviorTree)m_BehaviorTree.GetValue(__instance);
if (!IngressPoint.ranOnce && behavior != null)
{
IngressPoint.ranOnce = true;
// AITreeType.AITypes originalTreeType = ((AITreeType)m_CurrentAITreeType.GetValue(__instance)).GetAIType();
// For every AI Type, force enable
List<AITreeType.AITypes> treeTypes = Enum.GetValues(typeof(AITreeType.AITypes)).Cast<AITreeType.AITypes>().ToList();
Behavior.CreateBehaviorManager();
Dictionary<Behavior, BehaviorManager.BehaviorTree> behaviorTreeMap = (Dictionary<Behavior, BehaviorManager.BehaviorTree>)IngressPoint.behaviorTreeMap.GetValue(BehaviorManager.instance);
// FollowPassive is null
// Specific is null
List<AITreeType.AITypes> exclusionList = new List<AITreeType.AITypes>() {
AITreeType.AITypes.Escort,
AITreeType.AITypes.Idle,
AITreeType.AITypes.Guard,
AITreeType.AITypes.Harvest,
AITreeType.AITypes.FollowPassive
};
foreach (AITreeType.AITypes aiType in treeTypes.Where(item => !exclusionList.Contains(item)))
{
Console.WriteLine($"AI TYPE: {aiType}");
__instance.SetBehaviorType(new AITreeType(aiType), true);
EnableCurrentTree.Invoke(__instance, null);
d.Assert(behavior != null);
BehaviorManager.BehaviorTree tree = behaviorTreeMap[behavior];
Console.WriteLine("MY DEBUG:");
Console.WriteLine($"Task List: [{(tree.taskList == null ? "" : string.Join(", ", tree.taskList.Select(task => NodeString(task))))}]");
Console.WriteLine($"Parent Index: [{(tree.parentIndex == null ? "" : string.Join(", ", tree.parentIndex.Select(ind => ind < 0 ? "ROOT" : NodeString(tree.taskList[ind]))))}]");
Console.WriteLine($"Children Index: [\n{(tree.childrenIndex == null ? "" : string.Join(",\n", tree.childrenIndex.Select(list => list == null ? "\t[]" : "\t[" + string.Join(", ", list.Select(ind => ind < 0 ? "ROOT" : NodeString(tree.taskList[ind]))) + "]")))}]");
Console.WriteLine($"Relative Child Index: [{(tree.relativeChildIndex == null ? "" : string.Join(", ", tree.relativeChildIndex.Select(ind => ind < 0 ? "ROOT" : NodeString(tree.taskList[ind]))))}]");
Console.WriteLine($"Parent Composite Index: [{(tree.parentCompositeIndex == null ? "" : string.Join(", ", tree.parentCompositeIndex.Select(ind => ind < 0 ? "ROOT" : NodeString(tree.taskList[ind]))))}]");
Console.WriteLine($"Children Conditional Index: [\n{(tree.childConditionalIndex == null ? "" : string.Join(",\n", tree.childConditionalIndex.Select(list => list == null ? "\t[]" : "\t[" + string.Join(", ", list.Select(ind => ind < 0 ? "ROOT" : NodeString(tree.taskList[ind]))) + "]")))}]");
DisableCurrentTree.Invoke(__instance, null);
}
// __instance.SetBehaviorType(new AITreeType(originalTreeType), true);
EnableCurrentTree.Invoke(__instance, null);
}
}
} */
public static void Main()
{
FieldInfo m_SleepRangeFromCamera = typeof(ManTechs).GetField("m_SleepRangeFromCamera", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
m_SleepRangeFromCamera.SetValue(Singleton.Manager<ManTechs>.inst, 2700.0f);
Console.WriteLine($"Current sleep range: {m_SleepRangeFromCamera.GetValue(Singleton.Manager<ManTechs>.inst)}");
new Harmony("flsoz.ttmm.increasedrange.mod").PatchAll(Assembly.GetExecutingAssembly());
}
}
}