Entity has a mechanism to speed up the retrieval of dynamic_attributes/server_classes, but TypeManager itself does not. With this improvement, instances created by TypeManager can speed up the retrieval of function/virtual_function.
In virtual_function, I tried to improve the performance by using type_info and caching, but it did not improve the performance.
Test Code (CS:GO/Linux):
import time
from memory import find_binary
from memory import make_object
from memory.manager import CustomType
from memory.manager import TypeManager
""" TypeManager.function Test"""
# _ZN9CCSPlayer12RoundRespawnEv
signature = b"\x55\x89\xE5\x56\x53\x83\xEC\x1C\x8B\x5D\x08\xFF\x35\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x83\xC4\x10\x84\xC0\x0F\x85\x2A\x2A\x2A\x2A\x8B\x13"
# Cache signature
find_binary("server", srv_check=False)[signature]
manager = TypeManager()
class Test(CustomType, metaclass=manager):
_binary = "server"
_srv_check = False
_size = 0
_spawn = manager.function(signature)
# Cache function
Test._spawn
s = time.perf_counter()
for i in range(100000):
Test._spawn
e = time.perf_counter()
print(e-s, "Test._spawn")
# Cache function
test = Test()
test._spawn
s = time.perf_counter()
for i in range(100000):
test._spawn
e = time.perf_counter()
print(e-s, "test._spawn")
l = [Test() for i in range(100000)]
s = time.perf_counter()
for i in range(100000):
l[i]._spawn
e = time.perf_counter()
print(e-s, "Test()._spawn")
""" TypeManager.virtual_function Test"""
manager = TypeManager()
class Test(CustomType, metaclass=manager):
blind = manager.virtual_function(551, (DataType.FLOAT, DataType.FLOAT, DataType.FLOAT))
pointer = Entity.find("player").pointer
test = make_object(Test, pointer)
test.blind
s = time.perf_counter()
for i in range(100000):
test.blind
e = time.perf_counter()
print(e-s, "test.blind")
l = [make_object(Test, pointer) for i in range(100000)]
s = time.perf_counter()
for i in range(100000):
l[i].blind
e = time.perf_counter()
print(e-s, "make_object(Test, pointer).blind")
Since the implementation has changed, the test results have also changed.
Output :
Entity has a mechanism to speed up the retrieval of dynamic_attributes/server_classes, but TypeManager itself does not. With this improvement, instances created by TypeManager can speed up the retrieval of function/virtual_function.
In virtual_function, I tried to improve the performance by using type_info and caching, but it did not improve the performance.
Test Code (CS:GO/Linux):
Since the implementation has changed, the test results have also changed. Output :