Effectively using INI-files with signatures

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Effectively using INI-files with signatures

Postby iPlayer » Thu Sep 22, 2016 5:05 am

Hey there,

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?
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Effectively using INI-files with signatures

Postby L'In20Cible » Thu Sep 22, 2016 5:14 am

You want the function for hooking purpose I assume?
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Effectively using INI-files with signatures

Postby iPlayer » Thu Sep 22, 2016 5:17 am

Yep. Well, this situation occurs pretty often lately. When I have a valid signature but not an object pointer.

P.S. You just reminded me of my mobile operator. I wanted to buy an LTE-modem and as soon as the consultant saw me, he asked "You are not going to unlock this modem, are you?"
Last edited by iPlayer on Thu Sep 22, 2016 5:19 am, edited 1 time in total.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Effectively using INI-files with signatures

Postby L'In20Cible » Thu Sep 22, 2016 5:19 am

You don't need an object, as long as you have the class. Check out BaseEntityOutput: https://github.com/Source-Python-Dev-Te ... py#L31-L45
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Effectively using INI-files with signatures

Postby iPlayer » Thu Sep 22, 2016 5:26 am

I tried to go without an object, but it said
ValueError: _binary was not specified.


So I went with creating a subclass of CustomType (with a meta of my manager). So that class that I made will be capable of providing me with methods? Nice. Sorry for dumb question then.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Effectively using INI-files with signatures

Postby L'In20Cible » Thu Sep 22, 2016 5:27 am

User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Effectively using INI-files with signatures

Postby iPlayer » Thu Sep 22, 2016 8:41 am

Exactly what I needed. Thanks in advance!
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 20 guests