Some help with CustomType

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Some help with CustomType

Postby Doldol » Fri May 18, 2018 11:08 pm

I have:

Syntax: Select all

if PLATFORM == 'windows':
raise NotImplementedError("UNIX Only")

class CCSGameRules(CustomType, metaclass=manager):
# 5 5 void CCSGameRules::LevelInitPostEntity(void)
LevelInitPostEntity = manager.virtual_function(
5 if PLATFORM == 'windows' else 5,
[],
DataType.VOID
)

# void CCSGameRules::RestartRound(void)
RestartRound = server['_ZN12CCSGameRules12RestartRoundEv'].make_function(
Convention.CDECL,
[DataType.POINTER],
DataType.VOID
)

_m_iMapHasVIPSafetyZone_offset = None if PLATFORM == 'windows' else 756

@property# 0 is uninit 1 is yes 2 is no
def m_iMapHasVIPSafetyZone(self):
return self.get_int(offset=self._m_iMapHasVIPSafetyZone_offset)

@m_iMapHasVIPSafetyZone.setter
def m_iMapHasVIPSafetyZone(self, value):
return self.set_int(value, offset=self._m_iMapHasVIPSafetyZone_offset)

c_gamerules = make_object(CCSGameRules, pointer)


So to call LevelInitPostEntity I would do

Syntax: Select all

c_gamerules.LevelInitPostEntity()


But to call RestartRound I would have to include the pointer manually (obviously)

Syntax: Select all

c_gamerules.RestartRound(pointer)



What's the proper way to use a symbol in a CustomType class so it automatically uses the pointer as the 1st argument?
So that I can just use

Syntax: Select all

c_gamerules.RestartRound()


Also let me know if there's a better (buildin) way to do the offset setting/getting.

Thanks

(I didn't include the imports/the code to get the pointer to keep it to the point, let me know if you need it anyway)
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Re: Some help with CustomType

Postby Doldol » Fri May 18, 2018 11:43 pm

Syntax: Select all

class CCSGameRules(CustomType, metaclass=manager):
_binary = "server"

# 5 5 CCSGameRules::LevelInitPostEntity(void)
LevelInitPostEntity = manager.virtual_function(
5 if PLATFORM == 'windows' else 5,
[],
DataType.VOID
)

# void CCSGameRules::RestartRound(void)
RestartRound = manager.function(
'_ZN12CCSGameRules12RestartRoundEv',
[],
DataType.VOID,
Convention.CDECL,
)


Is this the proper way? Should I set _binary differently?
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Some help with CustomType

Postby Ayuto » Sat May 19, 2018 4:45 am

Yes, that's the proper way. For m_iMapHasVIPSafetyZone you can also use manager.instance_attribute.

Edit: The calling convenient is wrong. It's a THISCALL. Right now it will only work on Linux, because THISCALL and CDECL are the same on Linux.
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Re: Some help with CustomType

Postby Doldol » Sat May 19, 2018 5:26 am

Ayuto wrote:Yes, that's the proper way. For m_iMapHasVIPSafetyZone you can also use manager.instance_attribute.

Edit: The calling convenient is wrong. It's a THISCALL. Right now it will only work on Linux, because THISCALL and CDECL are the same on Linux.


Okay thanks! It's only meant to work on linux anyway, thiscall is a windows only thing afaik but I guess I shouldn't have specified it.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 28 guests