How can I reset the proxy after connecting to the gateway server. There is not much information about proxy(SOCKS) in the GUI plugin.
Use the Windows API to click phBot buttons directly.
I just find out people asking me the same, and some similar questions on discord recently so Iām leaving here what I did long ago.
This is a wrapper I made long long long ago.
WinAPI.py
# Lib version v1.0.1 - JellyBitz
import platform
import ctypes
user32 = ctypes.WinDLL('user32',use_last_error=True)
EnumWindows = user32.EnumWindows
EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
MOUSEEVENTF_MOVE = 0x0001
MOUSEEVENTF_LEFTDOWN = 0x0002
MOUSEEVENTF_LEFTUP = 0x0004
MOUSEEVENTF_RIGHTDOWN = 0x0008
MOUSEEVENTF_RIGHTUP = 0x0010
WM_LBUTTONDOWN = 0x0201;
WM_LBUTTONUP = 0x0202;
WM_RBUTTONDOWN = 0x0204;
WM_RBUTTONUP = 0x0205;
SW_HIDE = 0
SW_SHOW = 5
SW_MINIMIZE = 6
SW_RESTORE = 9
# __________ Windows stuffs ________
import re
# Get window handlers by process id
def GetWindowHandlersByID(process_id):
handlers = []
# Windows OS only
if platform.system() == 'Windows':
# Window callback function
def foreach_window(hwnd,lParam):
# Check handlers with visible window
if user32.IsWindowVisible(hwnd):
pid = GetProcessIdFromHandler(hwnd)
# Filter handler by id
if pid == process_id:
handlers.append(hwnd)
# Continue to the next window
return True
# Enumerate all windows running
EnumWindows(EnumWindowsProc(foreach_window),0)
return handlers
# Get window handlers by title
def GetWindowHandlersByTitle(window_title,isRegexPattern=False):
handlers = []
# Windows OS only
if platform.system() == 'Windows':
# Window callback function
def foreach_window(hwnd,lParam):
# Check handlers with visible window
if user32.IsWindowVisible(hwnd):
title = GetWindowTitle(hwnd)
if isRegexPattern:
if re.search(window_title,title):
handlers.append(hwnd)
else:
# Filter handler by name
if title == window_title:
handlers.append(hwnd)
# Continue to the next window
return True
# Enumerate all windows running
EnumWindows(EnumWindowsProc(foreach_window),0)
return handlers
# Get window process by window title
def GetProcessIdByTitle(window_title,isRegexPattern=False):
process_id = []
# Windows OS only
if platform.system() == 'Windows':
# Window callback function
def foreach_window(hwnd,lParam):
# Check handlers with visible window
if user32.IsWindowVisible(hwnd):
title = GetWindowTitle(hwnd)
if isRegexPattern:
if re.search(window_title,title):
handlers.append(GetProcessIdFromHandler(hwnd))
else:
# Filter handler by name
if title == window_title:
handlers.append(GetProcessIdFromHandler(hwnd))
# Continue to the next window
return True
# Enumerate all windows running
EnumWindows(EnumWindowsProc(foreach_window),0)
return process_id
# Return the process ID from window handler
def GetProcessIdFromHandler(hwnd):
lpdw_process_id = ctypes.c_ulong()
user32.GetWindowThreadProcessId(hwnd,ctypes.byref(lpdw_process_id))
return lpdw_process_id.value
# Get the window text using his handler
def GetWindowTitle(hwnd):
length = user32.GetWindowTextLengthW(hwnd)
buff = ctypes.create_unicode_buffer(length+1)
user32.GetWindowTextW(hwnd,buff,length+1)
return buff.value
# Bring to the front the window specified
def BringToFront(hwnd):
# Check if is minimized
if user32.IsIconic(hwnd):
user32.ShowWindow(hwnd,SW_RESTORE)
# Just set to the top
user32.SetForegroundWindow(hwnd)
# Hide the window handler specified
def HideWindow(hwnd):
user32.ShowWindow(hwnd,SW_HIDE)
# Show the window handler specified
def ShowWindow(hwnd):
user32.ShowWindow(hwnd,SW_SHOW)
# Minimize the window handler
def MinimizeWindow(hwnd):
user32.ShowWindow(hwnd,SW_MINIMIZE)
# Moves the window into the screen
def MoveWindow(hwnd,x,y):
user32.MoveWindow(hwnd,x,y,1,1,False)
# Check if the window is visible
def IsWindowVisible(hwnd):
return user32.IsWindowVisible(hwnd)
# Send a click to screen position
def Click(screenPosX,screenPosY,option='left'):
# Check which click is going to happen
if option == 'left':
event_up = MOUSEEVENTF_LEFTUP
event_down = MOUSEEVENTF_LEFTDOWN
elif option == 'right':
event_up = MOUSEEVENTF_RIGHTUP
event_down = MOUSEEVENTF_RIGHTDOWN
else:
# abort
return
# Try to fix if mouse is being used
user32.mouse_event(event_up,0,0,0,0)
# Positionates the mouse
user32.SetCursorPos(screenPosX-1, screenPosY-1)
# Generates an absolute movement event
user32.mouse_event(MOUSEEVENTF_MOVE,1,1,0,0)
# Click process
user32.mouse_event(event_down,0,0,0,0)
user32.mouse_event(event_up,0,0,0,0)
# Send a click into the position of the window handler
def WindowClick(hwnd,windowPosX,windowPosY,option='left'):
if option == 'left':
event_up = WM_LBUTTONUP
event_down = WM_LBUTTONDOWN
elif option == 'right':
event_up = WM_RBUTTONUP
event_down = WM_RBUTTONDOWN
else:
# abort
return
# Converting point to int
pos = int((windowPosY << 16) | (windowPosX & 0xFFFF))
user32.PostMessageA(hwnd,event_down,1,pos)
user32.PostMessageA(hwnd,event_up,0,pos)
How to use it?
AgentProxyReset.py
from phBot import *
import WinAPI
import os
from threading import Timer
pName = 'AgentProxyReset'
pVersion = '1.1.0'
#pUrl = 'https://raw.githubusercontent.com/JellyBitz/phBot-xPlugins/master/AgentProxyReset.py'
# ______________________________ Methods ______________________________ #
# Resets the config proxy from file
def ResetProxyConfig():
log("Plugin: Resetting proxy...")
# Get phBot window handler
handlers = WinAPI.GetWindowHandlersByID(os.getpid())
# Confirm that handler has been found
if len(handlers) == 0:
log("Plugin: Error, phBot window cannot be found!")
return
hwnd = handlers[0]
# Click tab option & button
Click_SilkroadLogin(hwnd)
Click_SilkroadLogin_btnReset(hwnd)
log("Plugin: Proxy config has been reseted!")
log("Plugin: Minimize and Hide window now...")
Timer(1.0,WinAPI.MinimizeWindow,[hwnd]).start()
Timer(2.0,WinAPI.HideWindow,[hwnd]).start()
# Execute it 60s later just in case
Timer(61.0,WinAPI.MinimizeWindow,[hwnd]).start()
Timer(62.0,WinAPI.HideWindow,[hwnd]).start()
# Vertical tab click
def Click_SilkroadLogin(hwnd):
WinAPI.WindowClick(hwnd,100,60)
# Button click
def Click_SilkroadLogin_btnReset(hwnd):
WinAPI.WindowClick(hwnd,435,235)
# ______________________________ Events ______________________________ #
# Called when the bot successfully connects to the game server
def connected():
ResetProxyConfig()
# Plugin load success
log('Plugin: '+pName+' v'+pVersion+' successfully loaded')
1 Like
And there is also an example to insert keys to try to change the proxy IP/PORT.
WM_KEYDOWN = 0x0100
WM_KEYUP = 0x0101
WM_CHAR = 0x0102
VK_RETURN = 0x0D
# Insert a window key in the focused control
def WindowKey(hwnd, Letter = 'A'):
# Emulate an ENTER pressed
if Letter == "\n":
user32.SendMessage(hwnd, WM_KEYDOWN, VK_RETURN, 0)
user32.SendMessage(hwnd, WM_KEYUP, VK_RETURN, 0)
return
# Emulate a regular key pressed
vkCode = ord(Letter) # Gets the virtual key code for the letter
user32.PostMessageA(hwnd, WM_KEYDOWN, vkCode, 0)
user32.PostMessageA(hwnd, WM_CHAR, vkCode, 0)
user32.PostMessageA(hwnd, WM_KEYUP, vkCode, 0)
Take it as an example since I never tested actually, but it should work if you start looking for c++ references like this : How do I send Enter key with PostMessage in C#?
1 Like