-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOfflineMultiplayerGameHandler.cs
More file actions
312 lines (257 loc) · 10.5 KB
/
OfflineMultiplayerGameHandler.cs
File metadata and controls
312 lines (257 loc) · 10.5 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using NetworkMessages.FromServer;
using TaleWorlds.Core;
using TaleWorlds.Core.ViewModelCollection;
using TaleWorlds.Engine;
using TaleWorlds.Engine.Screens;
using TaleWorlds.InputSystem;
using TaleWorlds.Library;
using TaleWorlds.MountAndBlade;
using TaleWorlds.MountAndBlade.Diamond;
using TaleWorlds.MountAndBlade.GauntletUI;
using TaleWorlds.MountAndBlade.View.Missions;
using TaleWorlds.MountAndBlade.View.Screen;
using Debug = System.Diagnostics.Debug;
using Module = TaleWorlds.MountAndBlade.Module;
namespace CombatDevTest
{
class OfflineMultiplayerGameHandler : GameHandler
{
public override void OnBeforeSave()
{
}
public override void OnAfterSave()
{
}
protected override void OnTick()
{
base.OnTick();
if (NetworkMain.GameClient.IsInGame && (NetworkMain.GameClient.IsHostingCustomGame || Input.IsKeyDown(InputKey.F12)) &&
Mission.Current != null && Mission.Current.IsLoadingFinished &&
!Mission.Current.HasMissionBehaviour<CombatTestMissionController>())
{
Mission.Current.AddMissionBehaviour(new CombatTestMissionController());
}
}
}
internal class CombatTestMissionController : MissionView
{
private static List<string> consoleCommands;
private bool _allInvulnerable = false;
private bool enableAIChanges = false;
private bool everyonePassive = false;
private bool playerInvulnerable = false;
private AgentDrivenProperties StatsBackup = new AgentDrivenProperties();
private AgentDrivenProperties StatsToSet = new AgentDrivenProperties();
private bool wasEnableAIChanges = false;
public override void OnAfterMissionCreated()
{
base.OnAfterMissionCreated();
}
static void DisplayMessage(string msg)
{
InformationManager.DisplayMessage(
new InformationMessage(new TaleWorlds.Localization.TextObject(msg, null).ToString()));
}
public override void OnMissionTick(float dt)
{
base.OnMissionTick(dt);
RefreshGUI(dt);
}
private void RefreshGUI(float dt)
{
Imgui.BeginMainThreadScope();
Imgui.Begin("Combat Dev Feedback Reload");
if (Imgui.Button("Reload Managed Core Params"))
{
ManagedParameters.Instance.Initialize(ModuleInfo.GetXmlPath("CombatDevTest",
"managed_core_parameters"));
DisplayMessage("Reloaded managed Core Params");
}
DrawReloadXMLs();
Imgui.End();
Imgui.Begin("Combat Dev Feedback Cheats");
if (Imgui.Button(" Quit"))
{
GameStateManager gameStateManager = Game.Current.GameStateManager;
if (!(gameStateManager.ActiveState is LobbyState))
{
if (gameStateManager.ActiveState is MissionState)
{
Imgui.End();
Imgui.EndMainThreadScope();
NetworkMain.GameClient.Logout();
return;
}
gameStateManager.PopState(0);
}
}
;
DrawDevCheats();
Imgui.End();
/*Imgui.Begin(("Console"));
DrawConsole();
Imgui.End();*/
Imgui.EndMainThreadScope();
}
private void DrawDevCheats()
{
wasEnableAIChanges = enableAIChanges;
Imgui.Checkbox("Player Invulnerable", ref playerInvulnerable);
var player = Mission.Current.MainAgent;
Imgui.Checkbox($"Everyone Invulnerable?: {_allInvulnerable}", ref _allInvulnerable);
Imgui.Checkbox($"Everyone Passive?: {everyonePassive}", ref everyonePassive);
Imgui.Checkbox("Enable AI Changes", ref enableAIChanges);
foreach (var agent in Mission.Current.AllAgents)
{
if (agent == null)
{
continue;
}
agent?.SetInvulnerable(_allInvulnerable);
var component = agent?.GetComponent<AgentAIStateFlagComponent>();
if (component != null) component.IsPaused = everyonePassive;
if (agent == player)
{
continue;
}
}
if (enableAIChanges)
{
if (wasEnableAIChanges)
{
SliderUpdate();
AskForApply();
}
else
{
BackupStats();
}
}
else if (wasEnableAIChanges)
{
ResetStats();
}
if (Imgui.Button(" Gib Player 100 Money"))
{
var _gameModeServer = Mission.Current.GetMissionBehaviour<MissionMultiplayerGameModeBase>();
_gameModeServer.ChangeCurrentGoldForPeer(GameNetwork.MyPeer.GetComponent<MissionPeer>(),
_gameModeServer.GetCurrentGoldForPeer(GameNetwork.MyPeer.GetComponent<MissionPeer>()) + 100);
}
player?.SetInvulnerable(playerInvulnerable);
}
private void ResetStats()
{
var player = Mission.Current.MainAgent;
foreach (var agent in Mission.Current.AllAgents)
{
if (agent == null || agent == player)
{
continue;
}
var component = agent?.GetComponent<AgentAIStateFlagComponent>();
if (component != null) component.IsPaused = everyonePassive;
var agentDrivenProperties = (AgentDrivenProperties) agent.GetType()
.GetProperty("AgentDrivenProperties", BindingFlags.NonPublic | BindingFlags.Instance)
?.GetValue(agent);
foreach (DrivenProperty drivenProperty in (DrivenProperty[]) Enum.GetValues(typeof(DrivenProperty)))
{
if (drivenProperty >= DrivenProperty.MountManeuver ||
drivenProperty <= DrivenProperty.None) continue;
var val = StatsBackup.GetStat(drivenProperty);
agentDrivenProperties?.SetStat(drivenProperty, val);
}
agent.UpdateAgentProperties();
}
}
private void BackupStats()
{
var player = Mission.Current.MainAgent;
foreach (var agent in Mission.Current.AllAgents)
{
if (agent == null || agent == player)
{
continue;
}
var component = agent?.GetComponent<AgentAIStateFlagComponent>();
if (component != null) component.IsPaused = everyonePassive;
var agentDrivenProperties = (AgentDrivenProperties) agent.GetType()
.GetProperty("AgentDrivenProperties", BindingFlags.NonPublic | BindingFlags.Instance)
?.GetValue(agent);
if (agentDrivenProperties == null) continue;
foreach (DrivenProperty drivenProperty in (DrivenProperty[]) Enum.GetValues(
typeof(DrivenProperty)))
{
if (drivenProperty >= DrivenProperty.MountManeuver ||
drivenProperty <= DrivenProperty.None) continue;
var val = agentDrivenProperties.GetStat(drivenProperty);
StatsBackup.SetStat(drivenProperty, val);
StatsToSet.SetStat(drivenProperty, val);
}
}
}
private void AskForApply()
{
var player = Mission.Current.MainAgent;
if (Imgui.Button("UPDATE AI"))
{
foreach (var agent in Mission.Current.AllAgents)
{
if (agent == null || agent == player)
{
continue;
}
var component = agent?.GetComponent<AgentAIStateFlagComponent>();
if (component != null) component.IsPaused = everyonePassive;
var agentDrivenProperties = (AgentDrivenProperties) agent.GetType()
.GetProperty("AgentDrivenProperties", BindingFlags.NonPublic | BindingFlags.Instance)
?.GetValue(agent);
foreach (DrivenProperty drivenProperty in (DrivenProperty[]) Enum.GetValues(typeof(DrivenProperty)))
{
if (drivenProperty < DrivenProperty.MountManeuver && drivenProperty > DrivenProperty.None)
{
float val = StatsToSet.GetStat(drivenProperty);
agentDrivenProperties?.SetStat(drivenProperty, val);
}
agent.UpdateAgentProperties();
}
}
}
}
private void SliderUpdate()
{
foreach (DrivenProperty drivenProperty in (DrivenProperty[]) Enum.GetValues(typeof(DrivenProperty)))
{
if (drivenProperty < DrivenProperty.MountManeuver && drivenProperty > DrivenProperty.None)
{
float val = StatsToSet.GetStat(drivenProperty);
Imgui.SliderFloat(Enum.GetName(typeof(DrivenProperty), drivenProperty), ref val, -10, 10);
StatsToSet.SetStat(drivenProperty, val);
}
}
}
private void DrawReloadXMLs()
{
foreach (var xml in new[]
{
"BasicCultures", "MPCharacters", "MPClassDivisions", "Monsters", "SkeletonScales", "ItemModifiers",
"ItemModifierGroups", "CraftingPieces", "CraftingTemplates", "Items"
})
{
drawReloadXML(xml);
Imgui.Separator();
}
}
private void drawReloadXML(string xmlFile)
{
if (Imgui.Button($"Reload {xmlFile}"))
{
MBObjectManager.Instance.LoadXML(xmlFile, null);
}
}
}
}