Ayuto

ICvar callback example

Dec 30th, 2013
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. import binutils
  2.  
  3. from binutils     import Convention
  4. from custom_types import ICvar
  5.  
  6. # Get the server binary
  7. server = binutils.find_binary('cstrike/bin/server')
  8.  
  9. # Get the ICvar interface
  10. cvar = ICvar(server['cvar'].get_ptr())
  11.  
  12. # Create a global change callback
  13. # typedef void ( *FnChangeCallback_t )( IConVar *var, const char *pOldValue, float flOldValue );
  14. @binutils.callback(Convention.CDECL, 'pZf)v')
  15. def cpp_change_callback(var, str_old_value, float_old_value, ebp):
  16.     print (var, str_old_value, float_old_value)
  17.  
  18. # Install the callback
  19. cvar.InstallGlobalChangeCallback(cpp_change_callback)
  20.  
  21. def unload():
  22.     # Remove the callback
  23.     cvar.RemoveGlobalChangeCallback(cpp_change_callback)
  24.  
  25.     # Free the memory
  26.     cpp_change_callback.free()
Advertisement
Add Comment
Please, Sign In to add comment