How to use hook_wait method in Selene

Best Python code snippet using selene_python

hooks.py

Source:hooks.py Github

copy

Full Screen

...86 self.game.frame_count_patch.patch(self.tas_dll.FrameCount.offset)87 )88 self.game.PresInt.value = 589 # Hook wait function90 self.hook_wait(True)91 # Hook QueryPerformanceCounter92 '''self.write_memory(93 self.game.qpc_patch_1.address,94 self.game.qpc_patch_1.patch(self.tas_dll.qpc_hook.address)95 )'''96 '''self.write_memory(97 self.game.qpc_patch_2.address,98 self.game.qpc_patch_2.patch(self.tas_dll.qpc_hook.address)99 )'''100 def release(self):101 """102 Release the hooks103 """104 if not (self.handle or self.w_handle):105 return106 handles = [self.handle, self.w_handle]107 for handle in handles:108 try:109 # If the application is closed this will fail110 CloseHandle(handle)111 except OSError:112 pass113 def rehook(self):114 self.release()115 try:116 self.acquire()117 except OSError:118 raise GameNotRunningError(119 f"Could not acquire the TAS Hook to {self.WINDOW_NAME}. "120 "Make sure the game is running."121 )122 def check_and_rehook(self):123 """124 Check if the game is running, if not try to rehook.125 :return:126 """127 try:128 self.igt() # TODO: Use something else than igt129 except GameNotRunningError:130 self.rehook()131 def read_memory(self, address, length):132 out = (BYTE*length)()133 ReadProcessMemory(self.handle, LPVOID(address), pointer(out),134 SIZE(length), pointer(SIZE(0)))135 return bytes(out)136 def write_memory(self, address, data):137 ptr = pointer((BYTE*len(data))(*data))138 WriteProcessMemory(self.handle, LPVOID(address), ptr,139 SIZE(len(data)), pointer(SIZE(0)))140 def force_quit(self):141 result = TerminateProcess(self.handle)142 if result == 0:143 print('Quit Failed')144 else:145 print('Quit Successful.')146 self.release()147 def get_module_info(self, module_name):148 lpszModuleName = module_name.encode("ascii")149 # TH32CS_SNAPMODULE and TH32CS_SNAPMODULE32150 hSnapshot = CreateToolhelp32Snapshot(0x8 | 0x10, self.process_id)151 ModuleEntry32 = MODULEENTRY32()152 ModuleEntry32.dwSize = sizeof(MODULEENTRY32)153 if Module32First(hSnapshot, pointer(ModuleEntry32)):154 while True:155 if ModuleEntry32.szModule == lpszModuleName:156 out = ModuleEntry32157 CloseHandle(hSnapshot)158 return out159 if Module32Next(hSnapshot, pointer(ModuleEntry32)):160 continue161 else:162 CloseHandle(hSnapshot)163 raise RuntimeError(f"Module {module_name} cannot be found")164 def get_module_base_address(self, module_name):165 try:166 info = self.get_module_info(module_name)167 except RuntimeError:168 return None169 return cast(info.modBaseAddr, LPVOID).value170 def inject_dll(self, dll_name):171 dll_name = dll_name.encode('ascii')172 remote_str = VirtualAllocEx(173 self.handle,174 LPVOID(0),175 SIZE(len(dll_name)),176 DWORD(0x00002000 | 0x00001000),177 DWORD(0x04)178 )179 self.write_memory(remote_str, dll_name)180 self.LoadLib = self.game.LoadLibraryA_ptr.value181 CreateRemoteThread(182 self.handle,183 LPVOID(0),184 SIZE(0),185 self.LoadLib,186 LPVOID(remote_str),187 DWORD(0),188 DWORD(0)189 )190 def write_input(self, input_state, force=False):191 """Sends input state to the game"""192 assert self.mode == "tas_input"193 if not force:194 while not self.tas_dll.Sync.value:195 pass196 self.tas_dll.input_state.value = input_state197 self.tas_dll.Sync.value = False198 def next(self):199 assert self.mode == "custom"200 while self.tas_dll.WaitFlag.value != 2:201 pass202 self.tas_dll.WaitFlag.value = 1203 def hook_wait(self, state):204 if state:205 self.write_memory(206 self.game.wait_hook.address,207 self.game.wait_hook.patch(self.tas_dll.wait_hook.value)208 )209 self.write_memory(self.game.no_skip.address, self.game.no_skip.patch)210 else:211 self.write_memory(self.game.wait_hook, self.game.wait_hook.orig)212 if self.tas_dll.wait_flag.value == 2:213 self.tas_dll.wait_flag.value = 1214 def set_mode(self, mode):215 """ mode:216 default217 tas_input...

Full Screen

Full Screen

configuration.py

Source:configuration.py Github

copy

Full Screen

...105 @property106 def hook_wait_failure(self) -> Callable[[TimeoutException], Exception]:107 return self._hook_wait_failure108 # def hook_wait_success(self)109 # def hook_wait(self)110 def wait(self, entity):111 return Wait(112 entity, at_most=self.timeout, or_fail_with=self.hook_wait_failure113 )114 @property115 def base_url(self) -> str:116 return self._base_url117 @property118 def set_value_by_js(self) -> bool:119 return self._set_value_by_js120 @property121 def type_by_js(self) -> bool:122 return self._type_by_js123 @property...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful