Custom convention support in TypeManager.create_type_from_dict

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:

Custom convention support in TypeManager.create_type_from_dict

Postby iPlayer » Mon Apr 24, 2017 10:54 am

Hey there,

Is there any built-in mechanism to specify custom conventions that will be used when parsing data in TypeManager.create_type_from_dict/create_type_from_file?

Say, I've got the following file

Syntax: Select all

[function]

# CTFGameRules::GetPayloadToBlock
[[get_payload_to_block]]
identifier_windows =
identifier_linux = _ZNK12CTFGameRules17GetPayloadToBlockEi
convention = MY_CALLING_CONVENTION
arguments_windows = POINTER, INT
arguments_linux = POINTER, POINTER, INT

I'd like to pass somewhere a dict like

Syntax: Select all

{'MY_CALLING_CONVENTION': MyCallingConvention}

to get the function built with that convention.

So far the only possibility I've found is to:
1. Subclass memory.helpers.Key and override its as_convention method;
2. Subclass memory.manager.TypeManager and override its create_type_from_dict method so that it will use my own Key class instead of the stock one.

But create_type_from_dict is way too big. Copy-pasting it only to replace all Key occurrences seems dumb to me.
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
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Custom convention support in TypeManager.create_type_from_dict

Postby iPlayer » Mon Apr 24, 2017 11:26 am

For now I will override TypeManager.function to replace convention in case it is Convention.CUSTOM and will define conventions I need as CUSTOM in the ini-file. This limits me to one custom convention per one TypeManager. Luckily I only need one.

Syntax: Select all

class PLRTypeManager(TypeManager):
def function(
self, identifier, args=(), return_type=DataType.VOID,
convention=Convention.THISCALL, doc=None):

if convention == Convention.CUSTOM:
convention = _GetPayloadConvention

return super().function(identifier, args, return_type, convention, doc)
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
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Custom convention support in TypeManager.create_type_from_dict

Postby Ayuto » Mon Apr 24, 2017 7:11 pm


Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 38 guests