-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvrising_camera.ahk
1279 lines (1152 loc) · 48.6 KB
/
vrising_camera.ahk
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
; VRising mouse lock script (improves aim and reaction times for some people)
; github.com/tekert
; v0.9
; CHANGELOG
; ver 0.9.5
; Found how to change the pitch from memory (press F2 and wait 20s), sadly using AOBs,
; maybe in the future I will find where cameraState object is populated.
; ver 0.9
; Almost a complete rewrite using classes, many refactors for scans.
; Added memory scan and pixelget options
; Overall better hadling of inputs and window change using windows events hooks instead of autohotkey timers
;
; ver 0.8.
; Better handling of key inputs and camera logic. Tested many hours ingame.
;
; ver 0.7:
; I prefer to use screenshots for menu detection, it's a bit cumbersome but works once set
; Since ahk is slow for screenshots and getting pixel data, I use an external lib for that thas is 50% or more faster.
; depends on how many pixelGets are done on base ahk, 1 ImageSearch = 2 PixelGetColor (yeah.. that bad)
; the ImagePut lib 1 to X PixelGet = 1 PixelGetColor because is uses a buffer, this should be in the standard lib of ahk really.
; if I use memory scans it will work on all resolutions but may break on an update. (I made it, works better,
; but if game updates it may break or change behaviour, discarded the code :( stick with pixels..
; Now using ImagePut library, to uses buffers when scanning for pixels, it uses basic C, so it's fast.
; -------------
; User Options
; -------------
useMemScan := True
; Uses memory scans to check for open menus to unlock and lock the mouse, works on all resolutions but may break on a future update.
; It's faster and can use lower scanMemoryInterval
; False uses ImagePut library to buffer screenshots to analize the image for pixels belonging to menus,
; it may not be that reliable on some menus when overlay effect like tooltips or text cover the screen UI, but works petty good overall.
; False may need a larger scanMemoryInterval (150ms is fine when ussing ImagePut library, the default PixelGet of autohotkey take a screenshot per each Get)
; There are many ways to scan for somethig, like FindText library, ImageSearch (need external images) or simply scaning specific pixels on resolutions.
; Default is true but it needs pointer values, using CheatEngine and comparing pointer maps can get you some results,
; UnityPlyaer.dll changes less often it contains the core unity 3d engine.
; <more notes on pointers below>.
scanMemoryInterval := 150 ; miliseconds (don't go lower than 100ms for now if usesMemScan = False)
lockMouseOnYaxis := 0.27
; Use 0.45 to 0.0 (Y axys % on where the mouse will center, 0 is top of the screen)
; Dont use more than ~30% for the Y axis or you can't use the maximum distance on ground abilities.
; For throwing area abilities closer to you there are two ingame methods, one is tilting the camera to the ground, it helps but not enough
; The other is zooming the camera with the mousewheel before launching the ability and tilting the camera.. a bit cumbersome but doable with practice. (not too bad)
; The last is, pressing <script_key=shift> before throwing the ability so you can move the cursor, if the ability is on Q and the script key is shift, this is not ideal.
; TODO: make it so we can move the mouse on the Y axis from 0.45 to 0.25 (uhm, is possible but don't know if it's ideal, check other options)
restoreMousePosition := False
; True = Restores the original mouse position from before after unlocking the mouse.
; False = Don't
pitchValue := 0.4
; Most npcs disapear at ~50 meters or so
; so Ranges from 0.0 to 0.3 are a bit dissy for pvp
; Default is 0.6632251143
; ---------------------------------
; Please don't edit below this line unless you know what you are doing (except maybe the hotkeys section)
; ---------------------------------
;;; Address for memory scans ;;;;
; Array of pointer offsets taken from pointers maps where the menu state byte is stored:
; Tested Working from [1.0.0] to [v1.0.6]
menuModuleName := "UnityPlayer.dll"
menuModuleOffset := 0x01CEE8E8
menuModulePointerOffsets := [0xB8, 0x00, 0xB0, 0xF0, 0x40, 0x20, 0x18]
; NOTE:
; To find the menuAddress manually, go to main menu (not ESC menu but main menu), Using CheatEngine search for a byte value of 0x05 (mark Hex and put 05),
; then go to options menu ingame, search for 0x04, finally go to the cinematic menu, play a cinematic and while it's playing search for 0x03
; There is your menuAddress, now repeat this a bunch of times after closing/start the game, taking pointer scans after you find the menuAddress each time,
; after 2 or 3 times, compare the pointer scans against the current most recent scan and pick some pointers from UnityPlayer.dll.
; Pitch cameraState structure
; This value gets created dynamically each time a world is loaded, the final value of the pitch is always a float = 0,6632251143 or AOB = 1F C9 29 3F little endian
; AOB of structure: 1F C9 29 3F 00 00 60 41 00 00 A0 40 00 00 78 41 36 8D A7 3F DB 0F 49 3F 01 00 00 00 00 00 78 41 00 00 00 00
; "??" may be used for wildcards, like "01 02 ?? 04 05"
; Tested Working in [v1.0.6]
pitchAOB := "1F C9 29 3F 00 00 60 41 00 00 A0 40 00 00 78 41 36 8D A7 3F DB 0F 49 3F 01 00 00 00 00 00 78 41 00 00 00 00"
pitchOffset := 0x0 ; 1F C9 29 3F is our pitch se offet is 0
/*
NOTE:
To find this struct on Cheat Engine, activate mono features and set a breakpoint on ProjectM.Camera.dll -> ProjectM.TopdownCameraSystem -> UpdateCameraInputs method.
Load a game.
Look for the TopDownCameraState parameter, on v1.0.6 is the 3rd one, for example the rdx register, thats the address of this struct.
cameraState structure
dynamically allocated
some values like pitch derived from other values.
This gets created somewhere by the unity engine on game world load
TODO: check what the other values do.
52 B8 9E 3F 6F 12 03 3B
6F 12 03 3C 6F 12 03 3B
6F 12 03 3C 00 00 C8 42
00 00 E1 43 00 00 48 42
00 00 16 43 00 00 00 00
?? ?? ?? ?? ?? ?? ?? ?? Pointer
9A 99 19 3F 00 00 00 00
?? ?? ?? ?? ?? ?? ?? ?? Pointer
9A 99 99 3E 00 00 F0 40
?? ?? ?? ?? ?? ?? ?? ?? Pointer
00 00 00 41 66 66 66 3F
00 00 40 41 00 00 40 41
00 00 40 40 00 00 60 41
C0 92 81 3F
1F C9 29 3F <- Here is our pitch float
00 00 60 41 00 00 A0 40
00 00 78 41 36 8D A7 3F
DB 0F 49 3F 01 00 00 00
00 00 78 41 00 00 00 00
*/
#Requires AutoHotkey >=2.0
; https://github.com/Kalamity/classMemory (converted to v2 by github.com/tekert)
#Include %A_ScriptDir%\classMemory\classMemoryv2.ahk
if (_ClassMemory.Prototype.__Class != "_ClassMemory")
{
MsgBox("class memory not correctly installed. Or the (global class) variable `"_ClassMemory`" has been overwritten")
ExitApp()
}
; https://github.com/iseahound/ImagePut (only needed if we want to use pixels instead of memory for detection)
#Include *i %A_ScriptDir%\ImagePut\ImagePut.ahk
Thread "Interrupt", 0 ; Make all threads always-interruptible. instead of minimum runtime (slice) of 15ms, usefull for heavy timers.
SetWorkingDir(A_ScriptDir)
#SingleInstance Force
SendMode("Input")
Persistent
#MaxThreadsPerHotkey 1 ; Important, default.
#HotIf WinActive("ahk_exe VRising.exe") ; By default ont enable hotkeys when game window is active. may cause weird problems when window is out of focus and hooks are disabled. TEST
CoordMode("Mouse", "Window") ; To support the game if its in window mode
;WinWait("ahk_exe VRising.exe")
; Make all newly launched threads (hotkeys) higher priority, (not interruptable by timers)
; https://www.autohotkey.com/docs/v2/lib/Thread.htm#NoTimers
Thread "NoTimers", True
; Create the main object, this will handle everything
vrObj := VRising("VRising.exe", useMemScan)
vrObj.setMenuAddresses(menuModuleName, menuModuleOffset, menuModulePointerOffsets)
vrObj.restoreMousePosition := restoreMousePosition
vrObj.setPitchAOB(pitchAOB, pitchOffset)
vrObj.lockAxysLevel := lockMouseOnYaxis
;---------------
;--- HOTKEYS ---
;---------------
;
; All these hotkeys only work when the game window is active so no need to check on every key press.
;
; F1 or End key: Enables or disables the script, disabling timers and hotkeys except for F1 and End keys
; https://www.autohotkey.com/docs/v2/lib/Suspend.htm
#SuspendExempt
~End::
~F1::
{
if (A_IsSuspended)
vrObj.SuspendScript(False, True)
else
vrObj.SuspendScript(True, True)
}
#SuspendExempt False
; This may take 20s to have effect, dont spam it :)
~F2::
{
static canSpam := 1
if (canSpam)
{
canSpam := 0
vrObj.setPitch(pitchValue)
canSpam := 1
}
}
; Temporarily disables auto mouse lock when shift is pressed.
$LShift::
{
vrObj.DisableScanTimer()
SendEvent("{Lshift down}")
}
$LShift Up::
{
SendEvent("{Lshift up}")
vrObj.EnableScanTimer()
}
; Play nicely with real right mouse clicks when this script is enabled.
RButton::
{
; Disable reading right clicks when the camera is locked (so we don't unlock it involuntarily)
If (vrObj.isCameraLocked())
{
; *You can send another key here to trigger an ability with the right mouse when in the field.
return
}
Send("{RButton down}")
}
RButton Up::
{
; Disable reading right clicks when the camera is locked (so we don't unlock it involuntarily)
If (vrObj.isCameraLocked())
{
; *You can release the above key here to trigger an ability with the right mouse when in the field.
return
}
Send("{RButton up}")
}
; Action wheel
$Ctrl::
{
vrObj.DisableScanTimer() ; key spam is controlled inside this function.
SendEvent("{Ctrl down}")
}
$Ctrl Up::
{
SendEvent("{Ctrl up}")
vrObj.EnableScanTimer()
}
; Emote Wheel
$LAlt::
{
vrObj.DisableScanTimer() ; key spam is controlled inside this function.
SendEvent("{LAlt down}")
}
$LAlt Up::
{
SendEvent("{LAlt up}")
vrObj.EnableScanTimer()
}
; Keyboard for console
;SC029:: ; This is the key above "TAB" left of "1"
F4:: ; <- put here your favorite key to open the console, we use de default SC029
{
Send '{U+0060}' ;"`" <- back accent: https://kbdlayout.info/how/%60
}
; ------------
; HOTKEYS END
; ------------
class VRising
{
processName := "VRising.exe"
restoreMousePosition := True
; Lock the mouse at this height on the Y axys on the middle of the game window
; Percent from 0.0 to 1.0 of the Y axys, 0.0 (0%) being the top and 1.0 (100%) the bottom.
; Here we lock it just below 1/4 by default counting from the top of the game window
lockAxysLevel
{
get => this._lockAxysLevel
set
{
if (value > 1.0)
this._lockAxysLevel := 1.0
else if (value < 0)
this._lockAxysLevel := 0
else
this._lockAxysLevel := value
}
}
; Private members start with _
_hProcess := "" ; HANDLE of the vrising.exe process (not used if using pixel scans)
_vrisingMem := "" ; _ClassMemory Object (not used if using pixel scans)
_menuAddress := 0 ; Memory pitchAddress to check for overlay menus (not used if using pixel scans)
_pitchAOB := ""
_pitchAOBOffset := 0x0 ; Offset for the AOB pattern
_winHooksArray := []
_timerDisabled := True ; Enable or disable auto lock with F1 key (also used internally to disable the script when shift or etc)
_cameraLocked := False ; True when the camera is currently locked by the script (used to play nicely with real right mouse clicks on menus)
_isInFocus := ""
_menuModuleName := "" ; Module name of there the menu state pointer is stored.
_menuModuleOffset := 0 ; Module offset where the menu state pointer is inside the module
_menuModulePointerOffsets := [] ; Array of offsets in order from pointer scans.
_useMemScan := True
_lockAxysLevel := 0.27
_scanMenusFunc := "" ; !Important, for SetTimer Off we have to use the same ObjBindMethod that was used to create the timer,
; since its not static, it creates a new object on each call.
_savedXpos := "" ; Save mouse X position before locking it with right click
_savedYpos := "" ; Save mouse Y position before locking it with right click
; Parameters:
; useMemScan - If false, uses PixelGet, this will have to be manually verified depending on resolution but works on all versions (if the pixels don't change)
; If True, uses the values supplied in setMenuAddresses method to scan for menu activity, works on all resolutions but maybe not all versions
__new(processName := "VRising.exe", useMemScan := True)
{
this._useMemScan := useMemScan
if this._useMemScan
{
if (Type(processName) = 'String')
this.processName := processName
else
throw TypeError("Need a String type for processName")
}
else
{
; https://github.com/iseahound/ImagePut/wiki/PixelSearch-and-ImageSearch#pixelsearch
if (ImagePut.Prototype.__Class != "ImagePut")
{
MsgBox("class ImagePutBuffer library not correctly installed.")
ExitApp
}
}
; Dont do SetTimer(ObjBindMethod(this, "_ScanMenusTimer"), 0), since it creates a new object and the timer wont be cancelled, thats why we set a Func
; This is used to suspend or resume de timers that scan for menus ingame.
this._scanMenusFunc := ObjBindMethod(this, "_ScanMenusTimer")
this._isInFocus := WinActive("ahk_exe " this.processName)
this.SuspendScript(True) ; Start suspended by default TODO: check WinActive and set this.
; This class will be controlled by external windows events that use WinEventProc calls
; We need to enable it when the script starts to detect when the process is closed and when the process is active or restarted
; When Foreground event occurs call func ForeGroundChange for any process (basically when any window comes to the foreground the func is called)
this._winHooksArray.Push(WinHook.Event.Add(3, 3, ObjBindMethod(this, "_WindowChange"), ,)) ; 3 = EVENT_SYSTEM_FOREGROUND
; Foreground wont catch some events when the game is in window mode and there are two foreground windows and one them is from the system.
; adding focus events complements all cases when the user or the system switch focus from the game window.
this._winHooksArray.Push(WinHook.Event.Add(0x8005, 0x8005, ObjBindMethod(this, "_WindowChange"), ,)) ; 0x8005 = EVENT_SYSTEM_FOCUS
}
; Disable Timers and events hooks and delete itself.
__Delete()
{
for hWinEventHook in this._winHooksArray
WinHook.Event.UnHook(hWinEventHook)
this._winHooksArray := ""
this._closeMemory()
}
; This Method controls the internal state of this class, script suspension, stoping/resuming timer, and memory reinit if handles are no longer valid.
; https://learn.microsoft.com/en-us/windows/win32/api/winuser/nc-winuser-wineventproc
_WindowChange(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime)
{
processName := ""
try
{
processName := WinGetProcessName("ahk_id " hwnd)
}
catch Error as e
{
; Target could not be found, continue as false , strange, TODO: test this
}
If (processName = this.processName)
{
if !this._isInFocus
this._isInFocus := True
else
return ; If already in focus return.
if (this._useMemScan)
{
; If we already has a valid handle (process had not restarted) use the current loaded handle
if (!this.isMemValid())
{
; Close old memory and reinit.
this._closeMemory()
this._initMemory()
}
}
; Unsuspend hotkeys and resume scan timers
this.SuspendScript(False)
}
else
{
if !this._isInFocus
return ; If already NOT in focus return.
this._isInFocus := False
; Window Loses Focus, suspend hotkeys and pause scan timers
this.SuspendScript(True)
}
}
; Check if the process handle we have had not been closed or restarted
isMemValid()
{
if (isObject(this._vrisingMem))
{
if (!this._vrisingMem.isHandleValid())
return False
}
else
return False
return True
}
; Does a bunch of unit work instead of calling each function directly on event change.
; This only gets called from windows events (when the game is on the foreground and focused)
_initMemory()
{
static errors := 0
if (!ProcessExist(this.processName))
throw Error("Init Memory failed, process " this.processName " doesn't exists!")
retry:
this._openMemory()
menuAddress := this._getMenuAddress()
if ((menuAddress = "") or (menuAddress <= 0))
{
; An Error, wait more before trying again.
errors += 1
if (errors > 10)
{
MsgBox "Could not get menu pointer address, maybe UnityPlayer.dll changed, report it con github, menuAddress: " menuAddress
ExitApp
}
this._closeMemory()
Sleep(1000)
GoTo retry
}
errors := 0
this._menuAddress := menuAddress
; TODO: Sadly pitch memory pitchAddress is dynamically created and its value too, so we have to scan for it every time we want the pitch changed
; no use getting the camera pitch address now, wait until the user ask for it.
}
; Disable Timers and close Memory instance
_closeMemory()
{
this.DisableScanTimer()
this._vrisingMem := ""
this._hProcess := "" ; Is closed automatically when the _classMemory object is destroyed so it's ivalid now, we delete it.
this._menuAddress := 0
this._savedXpos := ""
this._savedYpos := ""
}
; Opens _ClassMemory object for vrising.exe, if a handle is already opened and valid it does nothing
_openMemory()
{
if (this.isMemValid())
return
; We need write access for chaning camera pitch values inside the game.
dwDesiredAccess := _ClassMemory.aRights.PROCESS_QUERY_INFORMATION | _ClassMemory.aRights.PROCESS_VM_READ | _ClassMemory.aRights.PROCESS_VM_WRITE
hProcessCopy := 0
vrisingMem := _ClassMemory("ahk_exe " this.processName, dwDesiredAccess, &hProcessCopy)
if !isObject(vrisingMem)
{
msgbox "Failed to open Vrising.exe handle"
return
}
if (hProcessCopy = 0)
msgbox "The game isn't running (not found) or you passed an incorrect program identifier parameter. In some cases _ClassMemory.setSeDebugPrivilege() may be required."
else if (hProcessCopy = "")
msgbox "OpenProcess failed. If the target process has admin rights, then the script also needs to be ran as admin. _ClassMemory.setSeDebugPrivilege() may also be required. Consult <TODO github> for more information."
if ((hProcessCopy = 0) or (hProcessCopy = ""))
return
this._vrisingMem := vrisingMem
this._hProcess := hProcessCopy
}
setMenuAddresses(menuModuleName := "", menuModuleOffset := 0, menuModulePointerOffsets := [])
{
if (menuModuleName = "")
throw ValueError("Please provide a valid menuModuleName to search for")
this._menuModuleName := menuModuleName
this._menuModuleOffset := menuModuleOffset
this._menuModulePointerOffsets := menuModulePointerOffsets
}
setPitchAOB(pitchAOB, pitchAOBOffset := 0x0)
{
this._pitchAOB := pitchAOB
this._pitchAOBOffset := pitchAOBOffset
}
; We have to scan every time this is called, the AOB pattern is dynamically allocated, it changes everytime a world is loaded, and the value is computen dynamically.
; TODO: check where this value gets computed.
;
; Parameters:
; pitch 4 byte Float values from 0.0 (full pitch range) to 1.0 (camera pitch locked)
;
; Return values:
; True - Success. The memory pitchAddress of the pitch pitchAddress was written, camera pitch should change
; False - Error. Something happended and pitch was not changed.
setPitch(pitch)
{
if (!IsFloat(pitch))
{
MsgBox "pitch has to be a float value! instead we got " type(pitch)
return False
}
ret := 0
scanFromAddress := 0
; Change all ocurrences, this object is created at least 2 times in memory, the first one fades at garbage collection.
Loop
{
foundAddress := this._scanCameraPitchAddress(scanFromAddress)
if ((foundAddress = "") or (foundAddress < 0))
{
MsgBox "Could not get pitch address, setPitch error, foundAddress returned: " foundAddress
return False
}
if (foundAddress = 0)
{
return ret ? True : False
}
scanFromAddress := foundAddress + 4
try
{
ret := this._vrisingMem.write(foundAddress, pitch, "Float")
; Non Zero - Indicates success.
; Zero - Indicates failure. Check errorLevel and A_LastError for more information
; Null - An invalid type was passed. this.Errorlevel is set to -2 TODO: throws on v2
if ((ret = "") or (ret = 0))
return False
}
catch Error as err
{
throw err
;return False
}
}
return False
}
; NOTE: We have to compute this every time a world is loaded,
; the only way for now is to create a hotkey to change the pitch wich first scans the AOB using this pitchAddress.
; startAddress - The memory address from which to begin the search.
; endAddress - The memory address at which the search ends.
; Defaults to 0x7FFFFFFF for 32 bit target processes.
; Defaults to 0xFFFFFFFF for 64 bit target processes when the AHK script is 32 bit.
; Defaults to 0x7FFFFFFFFFF for 64 bit target processes when the AHK script is 64 bit.
; 0x7FFFFFFF and 0x7FFFFFFFFFF are the maximum process usable virtual address spaces for 32 and 64 bit applications.
; Anything higher is used by the system (unless /LARGEADDRESSAWARE and 4GT have been modified).
; Note: The entire pattern must be occur inside this range for a match to be found. The range is inclusive.
; Return values:
; Positive integer - Success. The memory pitchAddress of the found pattern.
; 0 The pattern was not found.
; -1 VirtualQueryEx() failed.
; -2 Failed to read a memory region.
; -10 The aAOBPattern* is invalid. (No bytes were passed)
; -99 Invalid handle or _ClassMemory Object, reopen handle and try again
_scanCameraPitchAddress(startAddress := 0, endAddress := "")
{
if (!this.isMemValid())
return -99
;if ((this._cameraStateAddress != "") and (this._cameraStateAddress > 0))
; return this._cameraStateAddress
pitchAddress := ""
try
{
pattern := this._vrisingMem.hexStringToPattern(this._pitchAOB)
pitchAddress := this._vrisingMem.processPatternScan(,, pattern*) ; Note the '*'
; Memory Address are returned as an int decimal
if (pitchAddress < 0)
{
switch pitchAddress
{
case -1: MsgBox "VirtualQueryEx() failed."
case -2: MsgBox "Failed to read a memory region"
case -10: MsgBox "The aAOBPattern* is invalid. (No bytes were passed)"
}
}
else
pitchAddress += + this._pitchAOBOffset
}
catch Error as err
{
Sleep(1000)
;throw err
}
return pitchAddress
}
; Method: _getMenuAddress()
; Get the base addres of the open/close state of game menues
; Memory Address are returned as an int decimal
; Return values:
; Positive integer - The module's base/load pitchAddress (success).
; -1 - Module not found
; -3 - EnumProcessModulesEx failed
; -4 - The AHK script is 32 bit and you are trying to access the modules of a 64 bit target process. Or the target process has been closed.
; -99 - Invalid handle or _ClassMemory Object, reopen handle and try again
;
/* --------
POINTERS (UnityEngine.dll: this contains the game 3d engine so it shouldn't change often, GameAssembly.dll contains the actual game code and it changes every update)
There are like ~300 candidates inside this UnityEngine.dll, I chose the shortest path with the lower base pitchAddress
["UnityPlayer.dll"+01CEE8E8]+B8]+0]+B0]+F0]+40]+20]+18 = value that hold a byte with depending on wich menu is open
Byte values in game:
0x17 = action camera with no menus (no inv, loot, build, plant) open
0x19 = TAB menu, K, J open
0x18 = ESC menu open
0x1A = M menu open
Byte values in Main Menu:
0x05 = Main Menu
0x03 = Cinamatic
0x04 = Options - Play menu - Load game
*/
_getMenuAddress()
{
if (!this.isMemValid())
return -99
if ((this._menuAddress != "") and (this._menuAddress > 0))
return this._menuAddress
; Positive integer - The module's base/load pitchAddress (success).
; -1 - Module not found
; -3 - EnumProcessModulesEx failed
; -4 - The AHK script is 32 bit and you are trying to access the modules of a 64 bit target process. Or the target process has been closed.
moduleBaseAddress := this._vrisingMem.getModuleBaseAddress(this._menuModuleName)
if (moduleBaseAddress < 0)
{
switch moduleBaseAddress
{
case -1: MsgBox "Module " this._menuModuleName " not found"
case -3: MsgBox "EnumProcessModulesEx failed"
case -4: MsgBox "The AHK script is 32 bit and you are trying to access the modules of a 64 bit target process. Or the target process has been closed."
}
return moduleBaseAddress
}
ret := ""
try
{
ret := this._vrisingMem.getAddressFromOffsets(moduleBaseAddress + this._menuModuleOffset, this._menuModulePointerOffsets*)
if (ret = "" or ret <= 0)
{
; TODO: url for issues.
MsgBox "Could not get menu pointer address, maybe UnityPlayer.dll changed, report it con github, ret: " ret
}
}
catch Error as err
{
; Maybe the process is being loaded, wait and try again.
Sleep(1000)
}
return ret
}
; Returns true if any type of VRising menu is currently opened. false the camera has any type on menu that requires the mouse is open.
; Return values:
; false/true - Any kind of Menu is open, be main menu, overlay or whatever thar requiered mouse to navigate. Or if an error ocurred returns True
; -99 - Invalid handle or _ClassMemory Object, reopen handle and try again
isMenuOpen()
{
if (this._useMemScan)
{
if (!this.isMemValid())
throw Error("Handle is no longer valid, can't check if menu is open")
byte := 0
if (this._menuAddress != "" and this._menuAddress > 0)
{
try
{
byte := this._vrisingMem.read(this._menuAddress, "UChar") ; We can read from offsets here but better to use the cached this._menuAddress.
; TODO: error message log (but we don't want to disturb the player screen at this stage)
if (byte = "")
return True ; TODO: for now unlock the mouse if an error ocurred reading.
if (byte != 0x17) ; 0x17 = 23 means we are fully in action camera.
return True
}
catch Error as Err
{
return True ;TODO: for now unlock the mouse if an trown error ocurred reading.
}
}
}
else
{
; TODO more resolutions
; https://github.com/iseahound/ImagePut/wiki/PixelSearch-and-ImageSearch
; https://github.com/iseahound/ImagePut/wiki/Input-Types-&-Output-Functions#input-types
; add 0xFF to all colors as explained in the doc. https://github.com/iseahound/ImagePut/wiki/PixelSearch-and-ImageSearch#pixelgetcolor--pixelsetcolor
pic := ImagePutBuffer({ screenshot: "A" }) ; Take screenshot of active window.
if (pic.width = 1920) and (pic.height = 1080)
{
; Player menu open on 1920x1080
; Top left border of equipment tab (has to be left, the entire middle and right sections a overlaped by tooltips sometimes)
if ((pic[135, 93] = 0xFF414950)
and (pic[136, 93] = 0xFF414950)
and (pic[137, 93] = 0xFF3A4047)
and (pic[138, 93] = 0xFF2F353A))
return true
; Action bar on 1920x1080 (if action bar is not visible then we are in a fullscren menu)
; (left wings on the health globe)
if ((pic[888, 961] != 0xFF9EA6AD)
and (pic[889, 962] != 0xFF98ABB5)
and (pic[890, 963] != 0xFF92A8BB)
and (pic[891, 964] != 0xFF91A8B3))
return true
}
else
{
MsgBox "Resolution Not supported (try full screen), Script will pause."
this.SuspendScript()
Pause 1
}
}
return False
}
; Suspends the script so that hotkeys are disabled temporarily, and pauses the scan timers too.
; Paremeters:
; s - Suspends the script so that hotkeys will not have any effect. False unsuspends the script
; userForced - Forces the script to stay suspended (e.g will only unsuspend s=False if userForced is True)
;
; If already suspended or unsuspended does nothing (User manual suspensions take priority)
; self note: It's a bit dificult to read, it was merged from two methods, maybe it was not a good idea.
SuspendScript(s := True, userForced := False)
{
static staySuspended := False ; Force script to stay is suspended state
; No suspended/unsuspend if the script is currently force suspended and userForced flag = false
if ((userForced = false) and staySuspended)
return
if (s)
{
if (!A_IsSuspended)
{
if (userForced)
staySuspended := True
Suspend(1)
}
this.DisableScanTimer()
}
else
{
if (A_IsSuspended)
{
; Clear the force flag if we want to unsuspend a forced suspend with userForced = True
if ((userForced) and staySuspended)
staySuspended := False
Suspend(0)
}
this.EnableScanTimer() ; enable scan timer even if the script is not suspended, cold start.
}
}
; Disable the menu scan timer and unlocks the camera (called internally when suspending the script)
DisableScanTimer()
{
if (!this._timerDisabled)
{
SetTimer(this._scanMenusFunc, 0) ; Delete timer
this._timerDisabled := true
this.UnlockCamera()
}
}
; Called internally when resuming the script from suspension
EnableScanTimer()
{
if (this._timerDisabled)
{
this._timerDisabled := false
;this.LockCamera() ; Timer will lock or unlock the camera, don't force it. maybe the player is already on a menu.
Thread "NoTimers", False
SetTimer(this._scanMenusFunc, scanMemoryInterval, 0)
Thread "NoTimers", True
}
}
; Timer runs this every <scan_screen_interval>
; This thread may be interrumped at any time.
_ScanMenusTimer()
{
; In case this thread is resumed late.
If (this._timerDisabled)
return
try
{
menuOpen := this.isMenuOpen()
; In case this thread is resumed late.
If (this._timerDisabled)
return
if (menuOpen)
{
if (this._cameraLocked)
this.UnlockCamera() ; execute this line only the first time
; (we want to use real right clicks on build menu and this executes every <scanMemoryInterval>)
}
else
{
if (!this._cameraLocked)
this.LockCamera()
}
}
catch Error
{
this.UnlockCamera()
return ; maybe the memory handle is not valid or some other problem, don't disturb the player, return silently.
; TODO: maybe send a notification to the logs.
}
}
; SendEvents are more realiable, no need to Sleep everywhere.
UnlockCamera()
{
If (GetKeyState("RButton"))
{
SendEvent("{RButton up}")
this._cameraLocked := false
if (this._savedXpos = "" or this._savedYpos = "") or !restoreMousePosition
return
else
MouseMove(this._savedXpos, this._savedYpos, 0)
}
}
LockCamera()
{
if (this._timerDisabled) ; Don't lock if we disabled camera lock (thread may be resumed late)
return
if (A_IsSuspended) ; Don't lock the camera id the script is suspended
return
if !WinActive("ahk_exe " this.processName) ; Also don't lock it if its not active.
return
If (!GetKeyState("RButton")) ; Don't lock if the user is using the right click, wait until release
{
WinGetPos &Window_X, &Window_Y, &Window_Width, &Window_Height, "A"
MouseGetPos &_savedXpos, &_savedYpos ; Save current mouse postion before moving it, so we can restore it later.
this._savedXpos := _savedXpos, this._savedYpos := _savedYpos
BlockInput "MouseMove"
MouseMove(Window_Width * 0.5, Window_Height * this._lockAxysLevel, 0) ; Move the mouse it a the top middle
Sleep(30) ; Needed for some edge cases when releasing some keys rapidly causes mouse to drag the screen.
this._cameraLocked := true
SendEvent("{RButton down}") ; SendInput sometimes shifts the mouse before sending rbutton down with the game
; if the user moves the mouse too quickly when relocking the camera.
BlockInput "MouseMoveOff"
}
}
isCameraLocked()
{
return this._cameraLocked
}
}
; Converted to ahk v2 by
; github.com/tekert
;
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=59149
; Below is the original comment:
;
; [Class] WinHook
; Fanatic Guru
; 2019 02 18 v2
;
; Class to set hooks of windows or processes
;
;{============================
;
; Class (Nested): WinHook.Shell
;
; Method:
; Add(Func, wTitle:="", wClass:="", wExe:="", Event:=0)
;
; Desc: Add Shell Hook
;
; Parameters:
; 1) {Func} Function name or Function object to call on event
; 2) {wTitle} window Title to watch for event (default = "", all windows)
; 3) {wClass} window Class to watch for event (default = "", all windows)
; 4) {wExe} window Exe to watch for event (default = "", all windows)
; 5) {Event} Event (default = 0, all events)
;
; Returns: {Index} index to hook that can be used to Remove hook
;
; Shell Hook Events:
; 1 = HSHELL_WINDOWCREATED
; 2 = HSHELL_WINDOWDESTROYED
; 3 = HSHELL_ACTIVATESHELLWINDOW
; 4 = HSHELL_WINDOWACTIVATED
; 5 = HSHELL_GETMINRECT
; 6 = HSHELL_REDRAW
; 7 = HSHELL_TASKMAN
; 8 = HSHELL_LANGUAGE
; 9 = HSHELL_SYSMENU
; 10 = HSHELL_ENDTASK
; 11 = HSHELL_ACCESSIBILITYSTATE
; 12 = HSHELL_APPCOMMAND
; 13 = HSHELL_WINDOWREPLACED
; 14 = HSHELL_WINDOWREPLACING
; 32768 = 0x8000 = HSHELL_HIGHBIT
; 32772 = 0x8000 + 4 = 0x8004 = HSHELL_RUDEAPPACTIVATED (HSHELL_HIGHBIT + HSHELL_WINDOWACTIVATED)
; 32774 = 0x8000 + 6 = 0x8006 = HSHELL_FLASH (HSHELL_HIGHBIT + HSHELL_REDRAW)
;
; Note: ObjBindMethod(obj, Method) can be used to create a function object to a class method
; WinHook.Shell.Add(ObjBindMethod(TestClass.TestNestedClass, "MethodName"), wTitle, wClass, wExe, Event)
;
; ----------
;
; Desc: Function Called on Event
; FuncOrMethod(Win_Hwnd, Win_Title, Win_Class, Win_Exe, Win_Event)
;
; Parameters:
; 1) {Win_Hwnd} window handle ID of window with event
; 2) {Win_Title} window Title of window with event
; 3) {Win_Class} window Class of window with event
; 4) {Win_Exe} window Exe of window with event
; 5) {Win_Event} window Event
;
; Note: FuncOrMethod will be called with DetectHiddenWindows On.
;
; --------------------
;
; Method: Report(ByRef Object)
;
; Desc: Report Shell Hooks
;
; Returns: string report
; ByRef Object[Index].{Func, Title:, Class, Exe, Event}
;
; --------------------
;
; Method: Remove(Index)
; Method: Deregister()
;
;{============================
;
; Class (Nested): WinHook.Event
;
; Method:
; Add(eventMin, eventMax, eventProc, idProcess, WinTitle := "")
;
; Desc: Add Event Hook
;
; Parameters:
; 1) {eventMin} lowest Event value handled by the hook function
; 2) {eventMax} highest event value handled by the hook function
; 3) {eventProc} event hook function, call be function name or function object
; 4) {idProcess} ID of the process from which the hook function receives events (default = 0, all processes)
; 5) {WinTitle} WinTitle to identify which windows to operate on, (default = "", all windows)
;
; Returns: {hWinEventHook} handle to hook that can be used to unhook
;
; Event Hook Events:
; 0x8012 = EVENT_OBJECT_ACCELERATORCHANGE
; 0x8017 = EVENT_OBJECT_CLOAKED
; 0x8015 = EVENT_OBJECT_CONTENTSCROLLED
; 0x8000 = EVENT_OBJECT_CREATE
; 0x8011 = EVENT_OBJECT_DEFACTIONCHANGE
; 0x800D = EVENT_OBJECT_DESCRIPTIONCHANGE
; 0x8001 = EVENT_OBJECT_DESTROY
; 0x8021 = EVENT_OBJECT_DRAGSTART
; 0x8022 = EVENT_OBJECT_DRAGCANCEL
; 0x8023 = EVENT_OBJECT_DRAGCOMPLETE
; 0x8024 = EVENT_OBJECT_DRAGENTER
; 0x8025 = EVENT_OBJECT_DRAGLEAVE