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

Blogs

Check out the latest blogs from LambdaTest on this topic:

Migrating Test Automation Suite To Cypress 10

There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.

How To Handle Multiple Windows In Selenium Python

Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.

Testing Modern Applications With Playwright ????

Web applications continue to evolve at an unbelievable pace, and the architecture surrounding web apps get more complicated all of the time. With the growth in complexity of the web application and the development process, web application testing also needs to keep pace with the ever-changing demands.

Test Optimization for Continuous Integration

โ€œTest frequently and early.โ€ If youโ€™ve been following my testing agenda, youโ€™re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. Iโ€™ve encountered several teams who have a lot of automated tests but donโ€™t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.

Unveiling Samsung Galaxy Z Fold4 For Mobile App Testing

Hey LambdaTesters! Weโ€™ve got something special for you this week. ????

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