[DEV/(Win32)] Alternative OnTick, Delay, Repeat for client side.

Post Python examples to help other users.
User avatar
Sam
Senior Member
Posts: 131
Joined: Tue Jul 03, 2018 3:00 pm
Location: Russian Federation
Contact:

[DEV/(Win32)] Alternative OnTick, Delay, Repeat for client side.

Postby Sam » Sat May 16, 2020 10:35 pm

Syntax: Select all

from core import get_interface
from memory.manager import manager, CustomType
from memory import Convention, DataType
from listeners import ListenerManager, ListenerManagerDecorator
from hooks.exceptions import except_hooks

import time
import bisect

p_gEngineClient = get_interface('engine', 'VEngineClient014')

class VEngineClient(CustomType, metaclass=manager):
EngineStats_BeginFrame = manager.virtual_function(54, [], DataType.VOID, Convention.THISCALL)
EngineStats_EndFrame = manager.virtual_function(55, [], DataType.VOID, Convention.THISCALL)

EngineClient = make_object(VEngineClient, p_gEngineClient)

class PreTick(ListenerManagerDecorator):
manager = ListenerManager()

class PostTick(ListenerManagerDecorator):
manager = ListenerManager()

@PreHook(EngineClient.EngineStats_BeginFrame)
def PreTick_Notify(args):
PreTick.manager.notify()

@PostHook(EngineClient.EngineStats_EndFrame)
def PostTick_Notify(args, ret):
PostTick.manager.notify()

class _DelayManager(list):
"""A class that is responsible for executing delays."""
use_post_tick:bool = False
def __init__(self):
super().__init__()
if self.use_post_tick:
PostTick.manager.register_listener(self._tick)
else:
PreTick.manager.register_listener(self._tick)
def _tick(self):
"""Internal tick listener."""
current_time = time.time()
while self and self[0].exec_time <= current_time:
try:
self.pop(0).execute()
except:
except_hooks.print_exception()
def add(self, delay):
"""Add a delay to the list.
:param Delay delay:
The delay to add.
"""
bisect.insort_right(self, delay)

import listeners
listeners.tick._delay_manager = _DelayManager()

from listeners.tick import Repeat
from colors import Color

ConColorMsg = find_binary('tier0')['?ConColorMsg@@YAXABVColor@@PBDZZ'].make_function(Convention.CDECL, [DataType.POINTER, DataType.STRING], DataType.VOID)

def ex1(null):
ConColorMsg(Color(255, 0, 255), '[Pre] Hello, World!\n')

def ex2(null):
ConColorMsg(Color(255, 0, 255), '[Post] Hello, World!\n')


pr = Repeat(ex1, (0,))
pr.start(1)

listeners.tick._delay_manager.use_post_tick = True

ps = Repeat(ex2, (0,))
ps.start(1)


[Pre] Hello, World!
[Post] Hello, World!
[Pre] Hello, World!
[Post] Hello, World!
It's a trap!

Return to “Code examples / Cookbook”

Who is online

Users browsing this forum: No registered users and 4 guests