Effectively using INI-files with signatures
Posted: Thu Sep 22, 2016 5:05 am
Hey there,
I kinda hate defining functions inside of the plugin code:
Especially when there's memory.manager which is capable of building functions nicely from an INI-file:
For many reasons:
1. You don't need to maintain the code, only the data files
2. Code is cleaner
3. You don't care about 79-characters rule in a data file
4. You don't need to do platform checks by yourself
5. Sweets like: no "\x" makes it easier to see the signature; no need to define a POINTER in the arguments if the convention is THISCALL; etc
So in the past I sometimes used memory.manager module to handle my functions. But there's a little downside to it (in my case). It's designed such way that you will always make a type that will have those functions as methods. And to use those functions, you will have to make an object of that type by... using a proper pointer!
Well, it's not a downside if you're building virtual functions since you'll have to have the pointer anyways. But let's say I have a function described above:
CCSGameRules::TeamExterminationCheck(CCSGameRules *this, int, int, int, int, bool)
With a python code it's as easy as pie: you don't need a pointer to a CCSGameRules object, only a binary (server = find_binary('server')) and a proper signature.
Using TypeManager I'd need to find a pointer... What if I only need to define a single regular function, not a virtual one?
So I decided to dig inside of how it works and it seems that re-creating TypeManager's work manually is not that much of fun: https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/memory/manager.py#L307
I'd like to make the best use of what is available to me. Any advice?
I kinda hate defining functions inside of the plugin code:
Syntax: Select all
if PLATFORM == "windows":
TEAM_EXTERMINATION_CHECK = b"\x55\x8B\xEC\x51\x56\x8B\xF1\x57\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x0F\x8E\x0A\x01\x00\x00\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x0F\x8E\xFD\x00\x00\x00"
else:
TEAM_EXTERMINATION_CHECK = "_ZN12CCSGameRules22TeamExterminationCheckEiiiib"
team_extermination_check = server[TEAM_EXTERMINATION_CHECK].make_function(
Convention.THISCALL,
[DataType.POINTER, DataType.INT, DataType.INT, DataType.INT, DataType.INT, DataType.BOOL]
DataType.VOID
)
Especially when there's memory.manager which is capable of building functions nicely from an INI-file:
Syntax: Select all
[function]
[[team_extermination_check]]
identifier_windows = 55 8B EC 51 56 8B F1 57 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 0F 8E 0A 01 00 00 2A 2A 2A 2A 2A 2A 2A 0F 8E FD 00 00 00
identifier_linux = _ZN12CCSGameRules22TeamExterminationCheckEiiiib
arguments = INT, INT, INT, INT, BOOL
For many reasons:
1. You don't need to maintain the code, only the data files
2. Code is cleaner
3. You don't care about 79-characters rule in a data file
4. You don't need to do platform checks by yourself
5. Sweets like: no "\x" makes it easier to see the signature; no need to define a POINTER in the arguments if the convention is THISCALL; etc
So in the past I sometimes used memory.manager module to handle my functions. But there's a little downside to it (in my case). It's designed such way that you will always make a type that will have those functions as methods. And to use those functions, you will have to make an object of that type by... using a proper pointer!
Well, it's not a downside if you're building virtual functions since you'll have to have the pointer anyways. But let's say I have a function described above:
CCSGameRules::TeamExterminationCheck(CCSGameRules *this, int, int, int, int, bool)
With a python code it's as easy as pie: you don't need a pointer to a CCSGameRules object, only a binary (server = find_binary('server')) and a proper signature.
Using TypeManager I'd need to find a pointer... What if I only need to define a single regular function, not a virtual one?
So I decided to dig inside of how it works and it seems that re-creating TypeManager's work manually is not that much of fun: https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/memory/manager.py#L307
I'd like to make the best use of what is available to me. Any advice?