-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainWindow.xaml.cs
1727 lines (1522 loc) · 69.1 KB
/
MainWindow.xaml.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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Diagnostics;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Threading;
using System.Reflection;
using MiscUtils;
namespace EldenRingTool
{
public partial class MainWindow : Window, IDisposable
{
//TODO: reorganise a bit.
[DllImport("User32.dll")]
private static extern bool RegisterHotKey(
[In] IntPtr hWnd,
[In] int id,
[In] uint fsModifiers,
[In] uint vk);
[DllImport("User32.dll")]
private static extern bool UnregisterHotKey(
[In] IntPtr hWnd,
[In] int id);
const int WM_HOTKEY = 0x0312;
[Flags]
public enum Modifiers
{
NO_MOD = 0x0000,
ALT = 0x0001,
CTRL = 0x0002,
SHIFT = 0x0004,
WIN = 0x0008
}
public enum HOTKEY_ACTIONS
{
QUITOUT = 1,
TELEPORT_SAVE,
TELEPORT_LOAD,
YEET_FORWARD, YEET_UP, YEET_DOWN, YEET_PLUS_X, YEET_MINUS_X, YEET_PLUS_Z, YEET_MINUS_Z,
KILL_TARGET, FREEZE_TARGET_HP,
COL_MESH_A, COL_MESH_B, COL_MESH_CYCLE,
CHAR_MESH, HIDE_MODELS,
HITBOX_A, HITBOX_B,
NO_DEATH, ALL_NO_DEATH,
ONE_HP, MAX_HP, DIE, RUNE_ARC, SET_HP_LAST,
DISABLE_AI, REPEAT_ENEMY_ACTIONS,
INF_STAM, INF_FP, INF_CONSUM, ONE_SHOT,
NO_GRAVITY, NO_MAP_COL,
TORRENT_NO_DEATH, TORRENT_NO_GRAV, TORRENT_NO_MAP_COL,
POISE_VIEW,
SOUND_VIEW, TARGETING_VIEW,
EVENT_VIEW, EVENT_STOP,
FREE_CAMERA, FREE_CAMERA_CONTROL, NO_CLIP, ALLOW_MAP_COMBAT, TORRENT_ANYWHERE,
DISABLE_STEAM_INPUT_ENUM, DISABLE_STEAM_ACHIEVEMENTS, MUTE_MUSIC,
ADD_SOULS,
GAME_SPEED_25PC, GAME_SPEED_50PC, GAME_SPEED_75PC, GAME_SPEED_100PC, GAME_SPEED_150PC, GAME_SPEED_200PC, GAME_SPEED_300PC, GAME_SPEED_500PC, GAME_SPEED_1000PC,
FPS_30, FPS_60, FPS_120, FPS_144, FPS_240, FPS_1000,
FPS, //arbitrary fps
TOGGLE_STATS_FULL, TOGGLE_RESISTS, TOGGLE_COORDS,
ENABLE_TARGET_HOOK, STAY_ON_TOP,
GREAT_RUNE, PHYSICK, ASHES, SPELLS,
}
public class HotkeyAction
{
public HOTKEY_ACTIONS actID { get; set; } = 0;
public bool needsParam()
{
return actID == HOTKEY_ACTIONS.FPS;
}
public string someParam { get; set; } = null;
public override string ToString()
{
var ret = actID.ToString();
if (someParam != null) { ret += " " + someParam.ToString(); }
return ret;
}
}
ERProcess _process = null;
private bool disposedValue;
System.Windows.Threading.DispatcherTimer _timer = new System.Windows.Threading.DispatcherTimer();
string _normalTitle = "";
bool _hooked = false;
const string hotkeyFileName = "ertool_hotkeys.txt";
Dictionary<string, Modifiers> modMap = new Dictionary<string, Modifiers>();
Dictionary<string, HOTKEY_ACTIONS> actionMap = new Dictionary<string, HOTKEY_ACTIONS>();
Dictionary<string, Key> keyMap = new Dictionary<string, Key>();
Dictionary<int, List<HotkeyAction>> registeredHotkeys = new Dictionary<int, List<HotkeyAction>>();
(float, float, float) lastPos = (0, 0, 0);
(float, float, float) diffNormalisedLpf = (0, 0, 0);
#if DEBUG
(float, float, float, float, uint)? lastMapPos = null;
#endif
const float YEET_AMOUNT = 1;
int recentlyYeetedCounter = 0;
(float, float, float, float, uint)? savedMapPos = null;
const string websiteUrl = @"https://ds3tool.s3.ap-southeast-2.amazonaws.com/tools.html";
const string updateCheckUrl = @"https://ds3tool.s3.ap-southeast-2.amazonaws.com/ERToolUpdates.txt";
bool updateCheckStartupCheckDone = false;
bool _freeCamFirstActivation = true;
bool isCompact = false;
bool _playerNoDeathStateWas = false;
bool _torNoDeathStateWas = false;
bool _noClipActive = false;
static string windowStateFile()
{
return Utils.getFnameInAppdata("windowstate.txt", "ERTool");
}
static string getHotkeyFileAppData()
{
return Utils.getFnameInAppdata(hotkeyFileName, "ERTool");
}
static string hotkeyFile()
{//local file can override (an older tool version used a local file)
if (File.Exists(hotkeyFileName)) { return hotkeyFileName; }
return getHotkeyFileAppData();
}
static string getUpdCheckFile()
{
return Utils.getFnameInAppdata("DisableUpdateCheck", "ERTool");
}
static string posDbFile()
{
return Utils.getFnameInAppdata("saved_positions.txt", "ERTool");
}
static string extraFlagsFile()
{
return Utils.getFnameInAppdata("extra_flags.txt", "ERTool");
}
public MainWindow()
{
InitializeComponent();
var assInfo = Assembly.GetEntryAssembly().GetName();
Title = "ERTool v" + assInfo.Version;
_normalTitle = Title;
Closing += MainWindow_Closing;
Closed += MainWindow_Closed;
Loaded += MainWindow_Loaded;
retry:
try
{
_process = new ERProcess();
}
catch { _process = null; }
if (null == _process)
{
var res = MessageBox.Show("Could not attach to the game. This could be because it's not running, or because it was blocked by Easy Anti Cheat or by anti virus.\r\n\r\nClick Yes to try launching the game with EAC disabled, or No to just try attaching again.", "hobbWeird", MessageBoxButton.YesNoCancel);
if (res == MessageBoxResult.Yes)
{
if (!LaunchUtils.launchGame())
{
MessageBox.Show("Could not launch game.", "Sadge", MessageBoxButton.OK, MessageBoxImage.Warning);
}
else
{//success but wait a bit for it to start.
for (int i = 0; i < 30; i++)
{
System.Threading.Thread.Sleep(1000);
if (ERProcess.checkGameRunning())
{
System.Threading.Thread.Sleep(1000); //arbitrary wait to let the game start up more before applying patches. likely not required.
break;
}
}
}
goto retry;
}
else if (res == MessageBoxResult.No)
{
goto retry;
}
Close();
}
else
{//we good
_process.patchLogos();
_timer.Tick += _timer_Tick;
_timer.Interval = TimeSpan.FromSeconds(0.1); //~10hz UI update rate
_timer.Start();
}
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
var windowInfo = $"{Left} {Top} {isCompact} {resistsPanel.Visibility} {chkSteamInputEnum.IsChecked} {chkSteamAchieve.IsChecked} {chkMuteMusic.IsChecked}";
File.WriteAllText(windowStateFile(), windowInfo);
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
}
void loadWindowState()
{
try
{
var windowInfo = File.ReadAllText(windowStateFile());
if (string.IsNullOrEmpty(windowInfo)) { return; }
var spl = windowInfo.Split(' ');
var left = double.Parse(spl[0]);
var top = double.Parse(spl[1]);
bool compact = bool.Parse(spl[2]);
string vis = spl[3];
if ((left + Width) > System.Windows.SystemParameters.VirtualScreenWidth || (top + Height) > System.Windows.SystemParameters.VirtualScreenHeight)
{
Console.WriteLine("Not restoring position, would go off-screen");
}
else
{
Left = left;
Top = top;
}
if (compact) { setCompact(); } //default full
if (vis == Visibility.Visible.ToString()) { toggleResists(null, null); } //default hidden
if (spl.Length >= 7)
{
chkSteamInputEnum.IsChecked = bool.Parse(spl[4]);
chkSteamAchieve.IsChecked = bool.Parse(spl[5]);
chkMuteMusic.IsChecked = bool.Parse(spl[6]);
}
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
}
//TODO: move hotkey stuff to utils?
void setUpMapsForHotkeys()
{
foreach (var mod in Enum.GetValues(typeof(Modifiers)))
{
modMap[mod.ToString()] = (Modifiers)mod;
}
foreach (var act in Enum.GetValues(typeof(HOTKEY_ACTIONS)))
{
actionMap[act.ToString()] = (HOTKEY_ACTIONS)act;
}
foreach (var k in Enum.GetValues(typeof(Key)))
{
keyMap[k.ToString()] = (Key)k;
}
}
bool parseHotkeys(string linesStr = null)
{
try
{
string[] lines;
if (!string.IsNullOrEmpty(linesStr))
{
lines = linesStr.Split('\r', '\n');
}
else
{
lines = File.ReadAllLines(hotkeyFile());
}
var hotkeyMap = new Dictionary<(Key, Modifiers), List<HotkeyAction>>();
foreach (var line in lines)
{
if (line.StartsWith(";") || line.StartsWith("#") || line.StartsWith("//")) { continue; }
var modifiers = Modifiers.NO_MOD;
HotkeyAction action = null;
Key? hotkey = null;
var spl = line.Split(' ');
for (int j = 0; j < spl.Length; j++)
{
var s = spl[j];
if (modMap.ContainsKey(s)) { modifiers |= modMap[s]; }
if (keyMap.ContainsKey(s)) { hotkey = keyMap[s]; }
if (actionMap.ContainsKey(s))
{
action = new HotkeyAction() { actID = actionMap[s] };
if (action.needsParam())
{//param is meant to be right after
var paramInd = j + 1;
if (spl.Length > paramInd)
{
var paramStr = spl[paramInd];
action.someParam = paramStr;
continue; //no further processing
}
}
}
}
if (action != null && hotkey.HasValue)
{
var key = (hotkey.Value, modifiers);
if (!hotkeyMap.ContainsKey(key))
{
hotkeyMap.Add(key, new List<HotkeyAction>());
}
hotkeyMap[key].Add(action);
}
}
int i = 0;
foreach (var kvp in hotkeyMap)
{
registeredHotkeys.Add(i, kvp.Value);
RegisterHotKey(new WindowInteropHelper(this).Handle, i, (uint)kvp.Key.Item2, (uint)KeyInterop.VirtualKeyFromKey(kvp.Key.Item1));
var debugStr = $"Hotkey {i} set: {kvp.Key} ->";
foreach (var act in kvp.Value)
{
debugStr += " " + act.ToString();
}
Utils.debugWrite(debugStr);
i++;
}
btnHotkeys.Foreground = registeredHotkeys.Count > 0 ? Brushes.Blue : Brushes.Black;
return true;
}
catch { }
return false;
}
void clearRegisteredHotkeys()
{
foreach (var h in registeredHotkeys)
{
UnregisterHotKey(new WindowInteropHelper(this).Handle, h.Key);
}
registeredHotkeys.Clear();
}
string generateDefaultHotkeyFile(bool writeOut = true)
{
var sb = new StringBuilder();
sb.AppendLine(";Set hotkeys below. Some example hotkeys are provided.");
sb.AppendLine(";If you don't want to use hotkeys, just remove all the hotkeys listed.");
sb.AppendLine(";Restart ERTool after updating the hotkeys, or ctrl+click the hotkeys button.");
sb.AppendLine(";Lines starting with ; are ignored.");
sb.AppendLine(";All text is case-sensitive.");
sb.AppendLine(";Note that these are global hotkeys and may conflict with other applications. If a given key doesn't work, try using a modifier. (Eg. F12 may not work but CTRL F12 should.) Some of the more obscure keys may also not work.");
sb.AppendLine(";To generate a fresh hotkey file, alt+click the hotkey setup button.");
sb.Append(";Valid actions:");
foreach (var kvp in actionMap) { sb.Append(" " + kvp.Key); }
sb.AppendLine();
sb.Append(";Valid modifier keys:");
foreach (var kvp in modMap) { sb.Append(" " + kvp.Key); }
sb.AppendLine();
sb.Append(";Valid keys:");
foreach (var kvp in keyMap) { sb.Append(" " + kvp.Key); }
sb.AppendLine();
sb.AppendLine($"{Modifiers.CTRL} {Modifiers.SHIFT} {Key.Z} {HOTKEY_ACTIONS.QUITOUT}");
sb.AppendLine($"{Modifiers.CTRL} {Modifiers.SHIFT} {Key.C} {HOTKEY_ACTIONS.TELEPORT_SAVE}");
sb.AppendLine($"{Modifiers.CTRL} {Modifiers.SHIFT} {Key.V} {HOTKEY_ACTIONS.TELEPORT_LOAD}");
sb.AppendLine($"{Modifiers.CTRL} {Modifiers.SHIFT} {Key.K} {HOTKEY_ACTIONS.KILL_TARGET}");
if (writeOut) { File.WriteAllText(hotkeyFile(), sb.ToString()); }
return sb.ToString();
}
void backupHotkeyFile()
{
try
{
File.Copy(hotkeyFile(), hotkeyFile() + ".bak", true);
}
catch { }
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
try
{
//register for message passing
var source = PresentationSource.FromVisual(this as Visual) as HwndSource;
if (null == source) { Utils.debugWrite("Could not make hwnd source"); }
source.AddHook(WndProc);
//hotkeys
setUpMapsForHotkeys();
if (File.Exists(hotkeyFileName) && !File.Exists(getHotkeyFileAppData()))
{
MessageBox.Show("Hotkey mapping will be moved to AppData. Shift-click Hotkey Setup if you need to access this folder.");
File.Move(hotkeyFileName, getHotkeyFileAppData());
}
if (File.Exists(hotkeyFile()))
{
if (!parseHotkeys())
{
MessageBox.Show("Failed to parse hotkey file.");
}
}
else
{//none by default
}
}
catch(Exception ex) { Utils.debugWrite(ex.ToString()); }
loadWindowState(); //restore last state if saved
maybeDoUpdateCheck();
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_HOTKEY)
{
int id = wParam.ToInt32();
Utils.debugWrite($"Got hotkey id {id}");
if (!registeredHotkeys.ContainsKey(id))
{
Utils.debugWrite($"Invalid hotkey {id}");
}
else
{
var actList = registeredHotkeys[id];
foreach (var act in actList)
{
Utils.debugWrite($"Doing action {act}");
doAct(act);
}
}
}
return IntPtr.Zero;
}
void doAct(HotkeyAction action)
{
var act = action.actID;
switch (act)
{
case HOTKEY_ACTIONS.QUITOUT: doQuitout(null, null); break;
case HOTKEY_ACTIONS.TELEPORT_SAVE: savePos(null, null); break;
case HOTKEY_ACTIONS.TELEPORT_LOAD: restorePos(null, null); break;
case HOTKEY_ACTIONS.YEET_FORWARD: doYeet("Forward", null); break;
case HOTKEY_ACTIONS.YEET_UP: doYeet("+Y", null); break;
case HOTKEY_ACTIONS.YEET_DOWN: doYeet("-Y", null); break;
case HOTKEY_ACTIONS.YEET_PLUS_X: doYeet("+X", null); break;
case HOTKEY_ACTIONS.YEET_MINUS_X: doYeet("-X", null); break;
case HOTKEY_ACTIONS.YEET_PLUS_Z: doYeet("+Z", null); break;
case HOTKEY_ACTIONS.YEET_MINUS_Z: doYeet("-Z", null); break;
case HOTKEY_ACTIONS.KILL_TARGET: killTarget(null, null); break;
case HOTKEY_ACTIONS.FREEZE_TARGET_HP: chkFreezeHP.IsChecked ^= true; break;
case HOTKEY_ACTIONS.COL_MESH_A: chkColMeshA.IsChecked ^= true; break;
case HOTKEY_ACTIONS.COL_MESH_B: chkColMeshB.IsChecked ^= true; break;
case HOTKEY_ACTIONS.COL_MESH_CYCLE: changeMeshColours(null, null); break;
case HOTKEY_ACTIONS.CHAR_MESH: chkCharMesh.IsChecked ^= true; break;
case HOTKEY_ACTIONS.HIDE_MODELS: chkHideModels.IsChecked ^= true; break;
case HOTKEY_ACTIONS.HITBOX_A: chkHitboxA.IsChecked ^= true; break;
case HOTKEY_ACTIONS.HITBOX_B: chkHitboxB.IsChecked ^= true; break;
case HOTKEY_ACTIONS.NO_DEATH: chkPlayerNoDeath.IsChecked ^= true; break;
case HOTKEY_ACTIONS.ALL_NO_DEATH: chkAllNoDeath.IsChecked ^= true; break;
case HOTKEY_ACTIONS.ONE_HP: chkOneHP.IsChecked ^= true; break;
case HOTKEY_ACTIONS.MAX_HP: chkMaxHP.IsChecked ^= true; break;
case HOTKEY_ACTIONS.SET_HP_LAST: if (lastSetHP.HasValue) { _process.getSetPlayerHP(lastSetHP.Value); } break;
case HOTKEY_ACTIONS.DIE: instantDeath(null, null); break;
case HOTKEY_ACTIONS.RUNE_ARC: chkRuneArc.IsChecked ^= true; break;
case HOTKEY_ACTIONS.DISABLE_AI: chkDisableAI.IsChecked ^= true; break;
case HOTKEY_ACTIONS.REPEAT_ENEMY_ACTIONS: chkRepeatAction.IsChecked ^= true; break;
case HOTKEY_ACTIONS.INF_STAM: chkInfStam.IsChecked ^= true; break;
case HOTKEY_ACTIONS.INF_FP: chkInfFP.IsChecked ^= true; break;
case HOTKEY_ACTIONS.INF_CONSUM: chkInfConsum.IsChecked ^= true; break;
case HOTKEY_ACTIONS.ONE_SHOT: chkOneShot.IsChecked ^= true; break;
case HOTKEY_ACTIONS.NO_GRAVITY: chkPlayerNoGrav.IsChecked ^= true; break;
case HOTKEY_ACTIONS.NO_MAP_COL: chkPlayerNoMapCol.IsChecked ^= true; break;
case HOTKEY_ACTIONS.TORRENT_NO_DEATH: chkTorNoDeath.IsChecked ^= true; break;
case HOTKEY_ACTIONS.TORRENT_NO_GRAV: chkTorNoGrav.IsChecked ^= true; break;
case HOTKEY_ACTIONS.TORRENT_NO_MAP_COL: chkTorNoMapCol.IsChecked ^= true; break;
case HOTKEY_ACTIONS.POISE_VIEW: chkPoiseView.IsChecked ^= true; break;
case HOTKEY_ACTIONS.SOUND_VIEW: chkSoundView.IsChecked ^= true; break;
case HOTKEY_ACTIONS.TARGETING_VIEW: chkTargetingView.IsChecked ^= true; break;
case HOTKEY_ACTIONS.EVENT_VIEW: chkEventView.IsChecked ^= true; break;
case HOTKEY_ACTIONS.EVENT_STOP: chkEventStop.IsChecked ^= true; break;
case HOTKEY_ACTIONS.FREE_CAMERA: chkFreeCam.IsChecked ^= true; break;
case HOTKEY_ACTIONS.FREE_CAMERA_CONTROL: chkFreeCamControl.IsChecked ^= true; break;
case HOTKEY_ACTIONS.NO_CLIP: chkNoClip.IsChecked ^= true; break;
case HOTKEY_ACTIONS.ALLOW_MAP_COMBAT: chkCombatMap.IsChecked ^= true; break;
case HOTKEY_ACTIONS.TORRENT_ANYWHERE: chkTorrentAnywhere.IsChecked ^= true; break;
case HOTKEY_ACTIONS.DISABLE_STEAM_INPUT_ENUM: chkSteamInputEnum.IsChecked ^= true; break;
case HOTKEY_ACTIONS.DISABLE_STEAM_ACHIEVEMENTS: chkSteamAchieve.IsChecked ^= true; break;
case HOTKEY_ACTIONS.MUTE_MUSIC: chkMuteMusic.IsChecked ^= true; break;
case HOTKEY_ACTIONS.ADD_SOULS: addSouls(null, null); break;
case HOTKEY_ACTIONS.GAME_SPEED_25PC: _process.getSetGameSpeed(0.25f); break;
case HOTKEY_ACTIONS.GAME_SPEED_50PC: _process.getSetGameSpeed(0.5f); break;
case HOTKEY_ACTIONS.GAME_SPEED_75PC: _process.getSetGameSpeed(0.75f); break;
case HOTKEY_ACTIONS.GAME_SPEED_100PC: _process.getSetGameSpeed(1.0f); break;
case HOTKEY_ACTIONS.GAME_SPEED_150PC: _process.getSetGameSpeed(1.5f); break;
case HOTKEY_ACTIONS.GAME_SPEED_200PC: _process.getSetGameSpeed(2.0f); break;
case HOTKEY_ACTIONS.GAME_SPEED_300PC: _process.getSetGameSpeed(3.0f); break;
case HOTKEY_ACTIONS.GAME_SPEED_500PC: _process.getSetGameSpeed(5.0f); break;
case HOTKEY_ACTIONS.GAME_SPEED_1000PC: _process.getSetGameSpeed(10.0f); break;
case HOTKEY_ACTIONS.FPS_30: _process.getSetFrameTimeTarget(1 / 30.0f); break;
case HOTKEY_ACTIONS.FPS_60: _process.getSetFrameTimeTarget(1 / 60.0f); break;
case HOTKEY_ACTIONS.FPS_120: _process.getSetFrameTimeTarget(1 / 120.0f); break;
case HOTKEY_ACTIONS.FPS_144: _process.getSetFrameTimeTarget(1 / 144.0f); break;
case HOTKEY_ACTIONS.FPS_240: _process.getSetFrameTimeTarget(1 / 240.0f); break;
case HOTKEY_ACTIONS.FPS_1000: _process.getSetFrameTimeTarget(1 / 1000.0f); break;
case HOTKEY_ACTIONS.FPS:
{
var targetFps = 60.0f;
if (!string.IsNullOrEmpty(action.someParam) && float.TryParse(action.someParam, out var targetFpsOut))
{
targetFps = targetFpsOut;
}
else
{
Utils.debugWrite("Error parsing fps");
}
var frameTime = 1 / targetFps;
_process.getSetFrameTimeTarget(frameTime);
}
break;
case HOTKEY_ACTIONS.TOGGLE_STATS_FULL: toggleStatsFull(null, null); break;
case HOTKEY_ACTIONS.TOGGLE_RESISTS: toggleResists(null, null); break;
case HOTKEY_ACTIONS.TOGGLE_COORDS: toggleCoords(null, null); break;
case HOTKEY_ACTIONS.ENABLE_TARGET_HOOK: installTargetHook(targetHookButton, null); break;
case HOTKEY_ACTIONS.STAY_ON_TOP: chkStayOnTop.IsChecked ^= true; break;
case HOTKEY_ACTIONS.GREAT_RUNE: _process.openMenuByName(_process.MENUS[1]); break;
case HOTKEY_ACTIONS.PHYSICK: _process.openMenuByName(_process.MENUS[2]); break;
case HOTKEY_ACTIONS.ASHES: _process.openMenuByName(_process.MENUS[3]); break;
case HOTKEY_ACTIONS.SPELLS: _process.openMenuByName(_process.MENUS[5]); break;
default: Utils.debugWrite("Action not handled: " + act.ToString()); break;
}
}
void updateTargetInfo()
{
var hp = _process.getSetTargetInfo(ERProcess.TargetInfo.HP);
var hpmax = _process.getSetTargetInfo(ERProcess.TargetInfo.MAX_HP);
var poise = _process.getSetTargetInfo(ERProcess.TargetInfo.POISE);
var poisemax = _process.getSetTargetInfo(ERProcess.TargetInfo.MAX_POISE);
var poisetimer = _process.getSetTargetInfo(ERProcess.TargetInfo.POISE_TIMER);
//Console.WriteLine($"{hp} {hpmax} {poise} {poisemax} {poisetimer}");
if (double.IsNaN(hp)) { return; }
if (hpBar.Value > hpmax) { hpBar.Value = 0; }
hpBar.Maximum = hpmax;
hpBar.Value = hp > 0 ? hp : 0;
hpText.Text = $"HP: {(int)hp} / {(int)hpmax}";
if (poiseBar.Value > poisemax) { poiseBar.Value = 0; }
poiseBar.Maximum = double.IsNaN(poisemax) ? 1 : poisemax;
poiseBar.Value = double.IsNaN(poise) ? 0 : poise > 0 ? poise : 0;
poiseText.Text = $"Poise: {poise:F1} / {poisemax:F1}";
//timer max is a bit annoying. you can try and 'find' it by observing the max and resetting on target switch.
if (poisetimer < 0) { poiseTimerBar.Value = 0; poiseTimerBar.Maximum = 1; } //make sure not to lower maximum below old value
if (poisetimer > poiseTimerBar.Maximum) { poiseTimerBar.Maximum = poisetimer; }
var timeValToSet = poisetimer < 0 ? 0 : poisetimer > poiseTimerBar.Maximum ? poiseTimerBar.Maximum : poisetimer;
poiseTimerBar.Value = timeValToSet;
poiseTimerText.Text = $"Poise reset time: {poisetimer:F1}";
if (resistsPanel.Visibility == Visibility.Visible)
{
var resistNames = new List<string>() { "Poison", "Rot", "Bleed", "Blight", "Frost", "Sleep", "Madness" };
var resistBars = new List<ProgressBar>() { poisonBar, rotBar, bleedBar, blightBar, frostBar, sleepBar, madBar };
var resistText = new List<TextBlock>() { poisonText, rotText, bleedText, blightText, frostText, sleepText, madText };
for (int i = 0; i < resistNames.Count; i++)
{
var statInd = ERProcess.TargetInfo.POISON + i * 2;
var statIndMax = statInd + 1;
var statAmount = _process.getSetTargetInfo(statInd);
var statMax = _process.getSetTargetInfo(statIndMax);
var statBar = resistBars[i];
var statText = resistText[i];
var statName = resistNames[i];
if (statBar.Value > statMax) { statBar.Value = 0; }
statBar.Maximum = statMax;
statBar.Value = statAmount > 0 ? statAmount : 0;
statText.Text = $"{statName}: {(int)statAmount} / {(int)statMax}";
}
}
}
void updateMovement()
{
#if DEBUG
if (!_process.isGameLoaded()) { Console.WriteLine("Game not loaded"); }
//Utils.debugWrite(_process.getSetFreeCamCoords().ToString());
{
var mapCoords = _process.getMapCoords();
if (!mapCoords.Equals(lastMapPos))
{
lastMapPos = mapCoords;
Utils.debugWrite("Local: " + _process.getSetLocalCoords().ToString() + " Map: " + mapCoords.ToString() + " " + TeleportHelper.mapIDString(mapCoords.Item5) + " World: " + TeleportHelper.getWorldMapCoords(mapCoords));
}
}
/*if (_process.isRiding())
{
var torCoords = _process.getSetTorrentLocalCoords();
Utils.debugWrite(torCoords.ToString());
}*/
#endif
if (_noClipActive)
{
var noClipPos = _process.getSetFreeCamCoords();
noClipPos.Item2 += 0.5f; //player slightly above camera
_process.getSetLocalCoords(noClipPos);
}
var pos = _process.getSetLocalCoords();
if (positionPanel.Visibility == Visibility.Visible)
{
var isRiding = _process.isRiding() ? "R" : "";
var posPlayer = _process.getSetPlayerLocalCoords();
var posTorrent = _process.getSetTorrentLocalCoords();
var mapCoords = _process.getMapCoords();
//localPos.Text = $"Local: [{pos.Item1:F2} {pos.Item2:F2} {pos.Item3:F2}]"; //switches between player and torrent
localPos.Text = $"P: [{posPlayer.Item1:F2} {posPlayer.Item2:F2} {posPlayer.Item3:F2}] T: [{posTorrent.Item1:F2} {posTorrent.Item2:F2} {posTorrent.Item3:F2}] {isRiding}";
var mapRotDeg = mapCoords.Item4 * 180 / Math.PI;
var mapIDstr = TeleportHelper.mapIDString(mapCoords.Item5);
mapPos.Text = $"Map: [{mapCoords.Item1:F2} {mapCoords.Item2:F2} {mapCoords.Item3:F2}] rotation: [{mapRotDeg:F1}°]";
mapID.Text = $"Map ID: [{mapIDstr}]";
var globalCoords = TeleportHelper.getWorldMapCoords(mapCoords);
string dimension = "?";
if (TeleportHelper.mapAreaIsMainWorld(globalCoords.Item4 << 24)) { dimension = "MAIN"; }
else if (TeleportHelper.mapAreaIsDLC(globalCoords.Item4 << 24)) { dimension = "DLC"; }
globalPos.Text = $"Global: [{dimension} {globalCoords.Item1:F2} {globalCoords.Item2:F2} {globalCoords.Item3:F2}]";
}
//track moving direction for the purpose of 'yeeting' 'forward'
if (recentlyYeetedCounter > 0) { recentlyYeetedCounter--; return; }//only track regular movement
var diff = (pos.Item1 - lastPos.Item1, pos.Item2 - lastPos.Item2, pos.Item3 - lastPos.Item3);
lastPos = pos;
var diffMag = (float)Math.Sqrt(diff.Item1 * diff.Item1 + diff.Item2 * diff.Item2 + diff.Item3 * diff.Item3);
if (diffMag < 0.1 || diffMag > 5) { return; } //ignore tiny or huge changes
var scale = YEET_AMOUNT / diffMag; //normalise
var diffNormalised = (diff.Item1 * scale, diff.Item2 * scale, diff.Item3 * scale);
var lpfA = 0.5f;
diffNormalisedLpf = (diffNormalised.Item1 * lpfA + diffNormalisedLpf.Item1 * (1 - lpfA),
diffNormalised.Item2 * lpfA + diffNormalisedLpf.Item2 * (1 - lpfA),
diffNormalised.Item3 * lpfA + diffNormalisedLpf.Item3 * (1 - lpfA));
//Console.WriteLine($"{diff} {diffMag} {diffNormalised} {diffNormalisedLpf}");
}
private void _timer_Tick(object sender, EventArgs e)
{
var good = _process?.weGood ?? false;
dockPanel.IsEnabled = good;
Title = good ? _normalTitle : "F?";
if (!good) { return; }
if (_hooked)
{
try
{
updateTargetInfo();
}
catch { }
}
updateMovement();
}
private void MainWindow_Closed(object sender, EventArgs e)
{
Dispose(true);
}
private void colMeshAOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.COL_MESH_A);
_process.freezeOn(ERProcess.DebugOpts.DISABLE_MAP);
_process.freezeOn(ERProcess.DebugOpts.DISABLE_TREES);
_process.freezeOn(ERProcess.DebugOpts.DISABLE_ROCKS);
_process.freezeOn(ERProcess.DebugOpts.DISABLE_GRASS);
_process.freezeOn(ERProcess.DebugOpts.DISABLE_DISTANT_MAP);
}
private void colMeshAOff(object sender, RoutedEventArgs e)
{
_process.offAndUnFreeze(ERProcess.DebugOpts.COL_MESH_A);
_process.offAndUnFreeze(ERProcess.DebugOpts.DISABLE_MAP);
_process.offAndUnFreeze(ERProcess.DebugOpts.DISABLE_TREES);
_process.offAndUnFreeze(ERProcess.DebugOpts.DISABLE_ROCKS);
_process.offAndUnFreeze(ERProcess.DebugOpts.DISABLE_GRASS);
_process.offAndUnFreeze(ERProcess.DebugOpts.DISABLE_DISTANT_MAP);
}
//code is gonna get repetitive. i'm sorry. i never planned this many features.
//TODO: simplify code somehow
private void charMeshOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.CHARACTER_MESH);
}
private void charMeshOff(object sender, RoutedEventArgs e)
{
_process.offAndUnFreeze(ERProcess.DebugOpts.CHARACTER_MESH);
}
private void charModelHideOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.DISABLE_CHARACTER);
}
private void charModelHideOff(object sender, RoutedEventArgs e)
{
_process.offAndUnFreeze(ERProcess.DebugOpts.DISABLE_CHARACTER);
}
private void hitboxOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.HITBOX_VIEW_A);
}
private void hitboxOff(object sender, RoutedEventArgs e)
{
_process.offAndUnFreeze(ERProcess.DebugOpts.HITBOX_VIEW_A);
}
private void hitboxBOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.HITBOX_VIEW_B);
}
private void hitboxBOff(object sender, RoutedEventArgs e)
{
_process.offAndUnFreeze(ERProcess.DebugOpts.HITBOX_VIEW_B);
}
private void noDeathOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.NO_DEATH);
}
private void noDeathOff(object sender, RoutedEventArgs e)
{
_process.offAndUnFreeze(ERProcess.DebugOpts.NO_DEATH);
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
if (_process != null)
{
_process.Dispose();
_process = null;
}
if (_timer != null)
{
_timer.Stop();
_timer = null;
}
}
disposedValue = true;
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
private void doQuitout(object sender, RoutedEventArgs e)
{
_process.enableOpt(ERProcess.DebugOpts.INSTANT_QUITOUT);
}
private void oneHPOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.ONE_HP);
}
private void oneHPOff(object sender, RoutedEventArgs e)
{
_process.offAndUnFreeze(ERProcess.DebugOpts.ONE_HP);
}
private void maxHPOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.MAX_HP);
}
private void maxHPOff(object sender, RoutedEventArgs e)
{
_process.offAndUnFreeze(ERProcess.DebugOpts.MAX_HP);
}
private void colMeshBOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.COL_MESH_B);
_process.freezeOn(ERProcess.DebugOpts.DISABLE_MAP);
_process.freezeOn(ERProcess.DebugOpts.DISABLE_TREES);
_process.freezeOn(ERProcess.DebugOpts.DISABLE_ROCKS);
_process.freezeOn(ERProcess.DebugOpts.DISABLE_GRASS);
_process.freezeOn(ERProcess.DebugOpts.DISABLE_DISTANT_MAP);
}
private void colMeshBOff(object sender, RoutedEventArgs e)
{
_process.offAndUnFreeze(ERProcess.DebugOpts.COL_MESH_B);
_process.offAndUnFreeze(ERProcess.DebugOpts.DISABLE_MAP);
_process.offAndUnFreeze(ERProcess.DebugOpts.DISABLE_TREES);
_process.offAndUnFreeze(ERProcess.DebugOpts.DISABLE_ROCKS);
_process.offAndUnFreeze(ERProcess.DebugOpts.DISABLE_GRASS);
_process.offAndUnFreeze(ERProcess.DebugOpts.DISABLE_DISTANT_MAP);
}
private void installTargetHook(object sender, RoutedEventArgs e)
{
(sender as Button).IsEnabled = false;
if (!_process.installTargetHook())
{
MessageBox.Show("Could not install hook. This could be because a Cheat Engine table has already installed its own hook. Restart the game and try again.", "Sadge", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
_hooked = true;
targetPanel.Opacity = 1;
targetPanel.IsEnabled = true;
}
private void targetHpFreezeOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.TARGET_HP);
}
private void targetHpFreezeOff(object sender, RoutedEventArgs e)
{
_process.offAndUnFreeze(ERProcess.DebugOpts.TARGET_HP);
}
private void killTarget(object sender, RoutedEventArgs e)
{
_process.getSetTargetInfo(ERProcess.TargetInfo.HP, 0);
}
private void doYeet(object sender, RoutedEventArgs e)
{
var amt = YEET_AMOUNT;
if (Keyboard.IsKeyDown(Key.LeftCtrl)) { amt *= 10; }
if (Keyboard.IsKeyDown(Key.LeftShift)) { amt *= 10; }
if (Keyboard.IsKeyDown(Key.LeftAlt)) { amt *= 100; }
var pos = _process.getSetLocalCoords();
var str = "";
if (sender is string) { str = (string)sender; }
if (sender is Button) { str = (string)((Button)sender).Content; }
switch (str)
{
case "Forward":
{
pos.Item1 += amt * diffNormalisedLpf.Item1;
pos.Item2 += amt * diffNormalisedLpf.Item2;// + 0.2f; //consider, to go a bit up
pos.Item3 += amt * diffNormalisedLpf.Item3;
break;
}
case "+X":
pos.Item1 += amt;
break;
case "-X":
pos.Item1 -= amt;
break;
case "+Y":
pos.Item2 += amt;
break;
case "-Y":
pos.Item2 -= amt;
break;
case "+Z":
pos.Item3 += amt;
break;
case "-Z":
pos.Item3 -= amt;
break;
}
_process.getSetLocalCoords(pos);
recentlyYeetedCounter = 5;
}
private void savePos(object sender, RoutedEventArgs e)
{
savedMapPos = _process.getMapCoords();
restorePosButton.IsEnabled = true;
}
bool inWarp = false;
void doGlobalTP((float, float, float, float, uint) pos)
{//TODO: move this into erprocess
if (inWarp) { return; } //block trying to warp multiple times at once as this can break the game
inWarp = true;
var mapCoordsNow = _process.getMapCoords();
if (pos.Item5 == mapCoordsNow.Item5)
{//same map region. don't attempt warp.
_process.teleportToGlobal(pos);
inWarp = false;
return;
}
//you can die from long range TP
var noDeathState = chkPlayerNoDeath.IsChecked;
chkPlayerNoDeath.IsChecked = true;
var noGravState = chkPlayerNoGrav.IsChecked;
chkPlayerNoGrav.IsChecked = true;
var t = new Thread(() =>
{
Thread.Sleep(250); //wait for freeze to enable
var ret = _process.teleportToGlobal(pos, 0.5f, warpIfNeeded: true);
if (ret == 0)
{//just ported
Thread.Sleep(5000);
_process.teleportToGlobal(pos, 0.5f);
}
else if (ret == 1)
{//warped. TODO: identify if we've fully loaded in, or at least mostly.
Thread.Sleep(5000);
}
Dispatcher.Invoke(() =>
{
chkPlayerNoGrav.IsChecked = noGravState;
chkPlayerNoDeath.IsChecked = noDeathState;
inWarp = false;
});
});
t.Start();
}
private void restorePos(object sender, RoutedEventArgs e)
{
if (savedMapPos.HasValue)
{
doGlobalTP(savedMapPos.Value);
}
}
private void noAIOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.DISABLE_AI);
}
private void noAIOff(object sender, RoutedEventArgs e)
{
_process.offAndUnFreeze(ERProcess.DebugOpts.DISABLE_AI);
}
private void noStamOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.NO_STAM);
}
private void noStamOff(object sender, RoutedEventArgs e)
{
_process.offAndUnFreeze(ERProcess.DebugOpts.NO_STAM);
}
private void noFPOn(object sender, RoutedEventArgs e)
{
_process.freezeOn(ERProcess.DebugOpts.NO_FP);
}