1
+ import win32process
2
+ import win32con
3
+ import win32api
4
+ import ctypes
5
+ import win32gui
6
+ import time
7
+
8
+
9
+
10
+ hook_enable = False
11
+ hover_height = 0
12
+ print ('悬停钩子辅助(测试)已启用,游戏中按E开启/关闭,按F提高悬停高度,按G降低高度' )
13
+ def on_press (key ):
14
+ global hook_enable ,hover_height
15
+ try :
16
+ if (key .char == 'e' ):
17
+ hook_enable = not hook_enable
18
+ if (key .char == 'f' ):
19
+ hover_height = hover_height - 16
20
+ if (key .char == 'g' ):
21
+ hover_height = hover_height + 16
22
+ except :
23
+ pass
24
+ def hover_hook ():
25
+ from pynput .keyboard import Key , Controller as c_keyboard
26
+ from pynput .mouse import Button , Controller as c_mouse
27
+ from pynput import keyboard
28
+ global hook_enable ,hover_height
29
+ listener = keyboard .Listener (on_press = on_press )
30
+ listener .start ()
31
+ keyboard = c_keyboard ()
32
+ mouse = c_mouse ()
33
+
34
+ PROCESS_ALL_ACCESS = (0x000F0000 | 0x00100000 | 0xFFF )
35
+ window = win32gui .FindWindow (None ,"DDNet Client" )
36
+ if window == 0 :
37
+ print ("游戏没有运行,请打开游戏" )
38
+ print ("game not running" )
39
+ while window == 0 :
40
+ window = win32gui .FindWindow (None ,"DDNet Client" )
41
+ time .sleep (1 )
42
+ hid ,pid = win32process .GetWindowThreadProcessId (window )
43
+ phand = win32api .OpenProcess (PROCESS_ALL_ACCESS ,False ,pid )
44
+ mydll = ctypes .windll .LoadLibrary ("C:\\ Windows\\ System32\\ kernel32.dll" )
45
+ module_handles = win32process .EnumProcessModules (phand )
46
+ module_handle = module_handles [0 ]
47
+
48
+ data = ctypes .c_long (0 )
49
+ #x_addr = module_handle + 0x3D3770
50
+ y_addr = module_handle + 0x3D376C
51
+ #hook_ptr = module_handle + 0x405100
52
+ #mydll.ReadProcessMemory(int(phand),ctypes.c_void_p(hook_ptr),ctypes.byref(data),3,None)
53
+ #hook_addr = data.value
54
+ #mydll.ReadProcessMemory(int(phand),ctypes.c_void_p(hook_ptr+3),ctypes.byref(data),3,None)
55
+ #hook_addr = (data.value << 24) + hook_addr + 0x35C
56
+
57
+ hook_start_once = True
58
+ ysumerr = 0
59
+ press_time = 0
60
+ press_time_clean = False
61
+ while (1 ):
62
+ if (hook_enable ):
63
+ if (hook_start_once ):
64
+ mydll .ReadProcessMemory (int (phand ),ctypes .c_void_p (y_addr ),ctypes .byref (data ),4 ,None )
65
+ lasty = data .value
66
+ hover_height = data .value
67
+ ysumerr = 0
68
+ hook_start_once = False
69
+ yerr = data .value - hover_height
70
+ ysumerr = ysumerr + yerr
71
+ if (ysumerr > 500 ):
72
+ ysumerr = 500
73
+ if (ysumerr < - 500 ):
74
+ ysumerr = - 500
75
+ yd = data .value - lasty
76
+ ys = ysumerr * 0.004
77
+ ct = yerr * 0.25 + yd * 4 + ys
78
+ if (ct > 0 ):
79
+ mouse .press (Button .right )
80
+ if (press_time_clean == False ):
81
+ press_time_clean = True
82
+ press_time = 0
83
+ else :
84
+ mouse .release (Button .right )
85
+ press_time = 0
86
+ press_time_clean = False
87
+ if (press_time > 10 ):
88
+ mouse .release (Button .right )
89
+ press_time = 0 ;
90
+ press_time = press_time + 1
91
+ time .sleep (0.001 )
92
+ lasty = data .value
93
+ mydll .ReadProcessMemory (int (phand ),ctypes .c_void_p (y_addr ),ctypes .byref (data ),4 ,None )
94
+ else :
95
+ if (hook_start_once == False ):
96
+ hook_start_once = True
97
+ mouse .release (Button .right )
98
+ time .sleep (0.000001 )
99
+ hover_hook ()
0 commit comments