forked from Fryheit/Kombatant
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathKombatant.cs
407 lines (354 loc) · 9.8 KB
/
Kombatant.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
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
//!CompilerOption:Optimize:On
//#define DBG
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;
using Buddy.Overlay.Controls;
using ff14bot;
using ff14bot.AClasses;
using ff14bot.Behavior;
using ff14bot.Helpers;
using ff14bot.Managers;
using ff14bot.Navigation;
using ff14bot.Pathing.Service_Navigation;
using GreyMagic;
using Kombatant.Forms;
using Kombatant.Forms.Models;
using Kombatant.Logic;
using Kombatant.Helpers;
using Kombatant.Localization;
using Kombatant.Memory;
using TreeSharp;
using BotBase = Kombatant.Settings.BotBase;
using UserControl = System.Windows.Controls.UserControl;
namespace Kombatant
{
/// <summary>
/// <para>Kombatant - An Advanced Open-Source Combat Assist Botbase</para>
/// <para>For credits and stuff, see README.md</para>
/// </summary>
// ReSharper disable once UnusedMember.Global
public class Kombatant : AsyncBotBase
{
//private static Kombatant kombatant;
//internal static Kombatant Instance => kombatant ?? (kombatant = new Kombatant());
#region Botbase Metadata
public override string Name => Localization.Localization.Name_Kombatant;
public override bool IsAutonomous => Settings.BotBase.Instance.IsAutonomous;
public override bool RequiresProfile => false;
public override bool WantButton => true;
public override PulseFlags PulseFlags => Settings.Fleeting.Instance.BotBasePulseFlags;
public static float CombatReachAdj { get; internal set; }
/// <summary>
/// Required dummy composite. Why, though?
/// </summary>
public override Composite Root => new ActionAlwaysFail();
#endregion
#region Xaml Dummies
private Window _window;
private static readonly object ContentLock = new object();
private UserControl _windowContent;
#endregion
#region Windows Forms Dummies
private ClassicSettingsForm _classicSettings;
#endregion
/// <summary>
/// Called when someone presses "Botbase Settings" in the main window.
/// </summary>
public override void OnButtonPress()
{
if (Settings.BotBase.Instance.UseWinFormsSettings)
{
if (_classicSettings == null || _classicSettings.IsDisposed)
_classicSettings = new ClassicSettingsForm();
_classicSettings.Show();
}
else
{
if (_window == null)
{
_window = new SettingsForm
{
DataContext = SettingsFormModel.Instance,
Content = LoadWindowContent(),
//Width = LoadWindowContent().Width+5,
//Height = LoadWindowContent().Height+30,
Title = $"Kombatant {Core.Me?.Name}",
WindowStartupLocation = WindowStartupLocation.CenterScreen,
};
_window.Loaded += (e, a) =>
{
};
_window.Closed += (e, a) =>
{
_window = null;
_windowContent = null;
Settings.BotBase.Reload();
Settings.Hotkeys.Reload();
Logging.Write(Localization.Localization.Msg_ReloadedSettings);
};
try
{
_window.Show();
_window.Focus();
}
catch (Exception)
{
// ignored
}
}
else
{
try
{
if (_window.WindowState == WindowState.Minimized)
{
_window.WindowState = WindowState.Normal;
}
//else
//{
// _window.WindowState = WindowState.Minimized;
//}
_window.Focus();
}
catch (Exception)
{
// ignored
}
}
}
//if (RoutineManager.Current.Name == "ShinraPVP")
//{
// RoutineManager.Current.OnButtonPress();
//}
}
/// <summary>
/// Load up the xaml window.
/// </summary>
/// <returns></returns>
private UserControl LoadWindowContent()
{
try
{
lock (ContentLock)
{
_windowContent = WpfHelper.Instance.LoadWindowContent(Resources.Controls.SettingsControl);
return _windowContent;
}
}
catch (Exception ex)
{
LogHelper.Instance.Log(@"Exception loading window content! {0}", ex);
}
return null;
}
private static bool sidestepStatus;
private static bool _init;
public Kombatant()
{
if (!_init)
{
Task.Factory.StartNew(() =>
{
init();
_init = true;
LogHelper.Instance.Log("Kombatant Initialized.");
});
}
}
internal static bool _memoFaliure;
private void init()
{
try
{
_ = Offsets.Instance;
}
catch (Exception e)
{
_memoFaliure = true;
}
LocalizationInitializer.Initalize();
//Settings.BotBase.Instance.AutoRegisterDuties = false;
}
public override void Pulse()
{
}
//static Thread t1 => new Thread(() =>
// {
// LogHelper.Instance.Log("<AnimationHack> Thread Started.");
// while (running)
// {
// if (BotBase.Instance.EnableAnimationLockHack)
// {
// Core.Memory.Write(AnimationLockTimer, BotBase.Instance.AnimationLockMaxDelay);
// }
// if (BotBase.Instance.EnableAnimationSpeedHack)
// {
// Core.Memory.Write(Core.Me.Pointer + 0xCD4, BotBase.Instance.AnimationSpeed);
// Core.Memory.Write(Core.Me.Pointer + 0xCD8, BotBase.Instance.AnimationSpeed);
// }
// Thread.SpinWait(10);
// }
// LogHelper.Instance.Log("<AnimationHack> Thread Aborted.");
// });
/// <summary>
/// Called when the botbase gets started.
/// </summary>
public override void Start()
{
try { sidestepStatus = PluginManager.Plugins.First(i => i.Plugin.Name == "SideStep").Enabled; }
catch { }
// Always start paused
Settings.BotBase.Instance.IsPaused = false;
// Set up navigation
Navigator.PlayerMover = new SlideMover();
Navigator.NavigationProvider = new ServiceNavigationProvider();
// Register the hotkeys
HotkeyHelper.Instance.ReloadHotkeys();
//// Less than 30 TPS are a no-no due to the design of this botbase. At least warn the user of this!
//if (TreeRoot.TicksPerSecond < 30)
//{
// LogHelper.Instance.Log(Localization.Localization.Msg_Not30Tps_Log);
// OverlayHelper.Instance.AddToast(Localization.Localization.Msg_Not30Tps, Colors.Red, Colors.DarkRed, TimeSpan.FromSeconds(10));
//}
if (Settings.BotBase.Instance.UseStatusOverlay) OverlayManager.StartStatusOverlay();
if (Settings.BotBase.Instance.UseFocusOverlay) OverlayManager.StartFocusOverlay();
}
/// <summary>
/// Called when the botbase gets stopped.
/// </summary>
public override void Stop()
{
// Destroy the navigator
Navigator.PlayerMover = new NullMover();
Navigator.NavigationProvider = new NullProvider();
// Unregister the hotkeys
HotkeyHelper.Instance.UnregisterHotkeys();
try
{
Core.Memory.Patches["GroundSpeedHook"].Remove();
Core.Memory.Patches["CombatReachHook"].Remove();
Core.Memory.Patches["NoKnockbackPatch"].Remove();
}
catch (Exception e)
{
}
// Stop Overlays
OverlayManager.StopFocusOverlay();
OverlayManager.StopStatusOverlay();
//OverlayManager.StatusOverlay.Update(StatusOverlayUiComponent.RunningStatus.Stopped);
try { PluginManager.Plugins.First(i => i.Plugin.Name == "SideStep").Enabled = sidestepStatus; }
catch { }
}
/// <summary>
/// Task wrapper for the main botbase logic.
/// </summary>
/// <returns></returns>
public override Task AsyncRoot()
{
return KombatantLogic();
}
/// <summary>
/// Main botbase logic task.
/// </summary>
/// <returns></returns>
private async Task<bool> KombatantLogic()
{
#if DBG
using (new PerformanceLogger("TotalExecutionTime"))
#endif
{
#if DBG
using (new PerformanceLogger("RefreshOverlay"))
#endif
{
//invoking UI thread to refresh overlay
if (BotBase.Instance.UseFocusOverlay)
OverlayManager.FocusOverlay.Update();
if (BotBase.Instance.UseStatusOverlay)
OverlayManager.StatusOverlay.Update();
}
// Execute Loot logic
if (await Loot.Instance.ExecuteLogic())
return await Task.FromResult(true);
#if DBG
using (new PerformanceLogger("SetTickRate"))
#endif
{
//TreeRoot.TicksPerSecond = BotBase.Instance.IsPaused ? (byte)BotBase.Instance.PausingTickRate : (byte)BotBase.Instance.RunningTickRate;
}
#if DBG
using (new PerformanceLogger("CommenceDuty"))
#endif
{
// Execute duty commence logic
if (await CommenceDuty.Instance.ExecuteLogic())
return await Task.FromResult(true);
}
#if DBG
using (new PerformanceLogger("Mechanics"))
#endif
{
// Execute mechanics logic (gaze attacks et al)
if (await Mechanics.Instance.ExecuteLogic())
return await Task.FromResult(true);
}
#if DBG
using (new PerformanceLogger("Convenience"))
#endif
{
// Execute convenience logic (auto sprint etc.)
if (await Convenience.Instance.ExecuteLogic())
return await Task.FromResult(true);
}
#if DBG
using (new PerformanceLogger("Target"))
#endif
{
// Execute target logic
if (await Target.Instance.ExecuteLogic())
return await Task.FromResult(true);
}
#if DBG
using (new PerformanceLogger("Avoidance"))
#endif
{
// Execute avoidance logic
if (await Avoidance.Instance.ExecuteLogic())
return await Task.FromResult(true);
}
#if DBG
using (new PerformanceLogger("Movement"))
#endif
{
// Execute auto movement
if (await Movement.Instance.ExecuteLogic())
return await Task.FromResult(true);
}
#if DBG
using (new PerformanceLogger("CombatLogic"))
#endif
{
//// Execute combat logic
if (await CombatLogic.Instance.ExecuteLogic())
return await Task.FromResult(true);
}
//// Execute tank specific logic
//if (await Tank.Instance.ExecuteLogic())
// return await Task.FromResult(true);
//// Execute healer specific logic
//if (await Healer.Instance.ExecuteLogic())
// return await Task.FromResult(true);
//// Execute DPS specific logic
//if (await DPS.Instance.ExecuteLogic())
// return await Task.FromResult(true);
return await Task.FromResult(false);
}
}
}
}