³ò
tüQc           @   s  d  Z  d d k Z d d k Z d d k l Z d d k l Z d d k Z d d k Td Z	 d Z
 e i d e
 e	 i d	 ƒ ƒ i ƒ  d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e ƒ  Z d „  Z d „  Z d „  Z d S(   sN   
$Rev: 135 $
$LastChangedDate: 2013-02-08 14:24:24 +0100 (Fr, 08. Feb 2013) $
iÿÿÿÿN(   t	   ConfigObj(   t   name(   t   *s   $Rev: 135 $s   1.5.0f rt   spe_versions   $Rev: t   InvalidFunctionNameExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyR   '   s   t   ConventionErrorc           B   s   e  Z RS(    (   R   R   (    (    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyR   +   s   t	   Signaturec           B   s#   e  Z d  Z d „  Z d d „ Z RS(   sœ  
    This is the primary class for calling Signature-based functions.
    Requirements for this class are:
        * Identifier (identifier):
            - The actual "Windows Signature" or "Linux Symbol".
            - "Windows Signatures" must be previously formatted
               with "backslash x" instead of spaces.
        * Parameter Format (param_format):
            - The type of each argument, and the return type:
                p = Pointer
                i = Integer
                f = Float
                B = Boolean
                d = Double
                L = Long
                S = String
        * Convention (convention):
            - thiscall
                Used when calling funtions from (within a C++ class)
            - cdecl
                Used when calling functions that are global
                    (not part of a C++ class)
            - fastcall
                (Reserved)
    c         C   s    t  | ƒ |  _ t d j o+ t |  i t |  i i d ƒ ƒ ƒ |  _ n t |  i ƒ |  _ t  | ƒ |  _ | d j o t	 d d | ƒ ‚ n t  | ƒ |  _
 d  S(	   Nt   ntt   string_escapet   thiscallt   cdeclt   fastcalls    "%s" is not a valid convention: s(   "thiscall", "cdecl", or "fastcall" only.(   R   R   R   (   t   strt
   identifiert   platformt   findFunctiont   lent   decodet   functiont
   findSymbolt   param_formatR   t
   convention(   t   selfR   R   R   (    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyt   __init__Q   s    	"c         C   s-   t  | ƒ t |  i ƒ t |  i |  i | ƒ S(   N(   t   tuplet   setCallingConventionR   t   callFunctionR   R   (   R   t   args(    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyt   callf   s    
(    (   R   R   t   __doc__R   R   (    (    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyR   7   s   	t   CSPEManagerc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s    
    This class is the main SPE module manager.
    Do not access any methods from this class directly.
    Instead, use the exported functions down below.
    c         C   sE   t  t i i t  t i d ƒ ƒ ƒ d ƒ |  _ h  |  _ |  i ƒ  d  S(   Nt   eventscripts_gamediri   (	   R   t   ost   patht   splitt   est	   ServerVart	   game_namet
   Signaturest   initializeSPE(   R   (    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyR   |   s    +	c         C   s]   |  i  d t t i d ƒ ƒ d ƒ |  i  d |  i ƒ |  i d ƒ |  i d |  i ƒ d S(   s”   
        Parses shared and game-specific signatures from the ini files.
        Loads up the game specific module so it can be used by SPE.
        s$   _libs/python/spe/ini/engines/shared.t
   spe_engines   .inis!   _libs/python/spe/ini/games/%s.inis   spe.games.shareds   spe.games.%sN(   t   parseINIR   R%   R&   R'   t
   loadModule(   R   (    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyR)   ‡   s
    c         C   s  t  i d ƒ } t d | | f ƒ } xÖ | D]Î } t d j o‚ d | | d j o* t i d i | | d i ƒ  ƒ ƒ } n | | d } t | | | d | | d ƒ |  i	 | | d	 <q, t | | d
 | | d | | d ƒ |  i	 | | d	 <q, Wd S(   s5   
        Parses signatures from an INI file.
        R!   s   %s/addons/eventscripts/%sR	   t    t   sigt    t   paramR   t	   shortnamet   symbolN(
   R%   R&   R    R   t   binasciit	   unhexlifyt   joinR$   R   R(   (   R   R#   t   gamedirt   INIt   sectionR.   (    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyR+   •   s     $2c         C   s2   y t  | ƒ } Wn t j
 o t Sn Xt Sd S(   sF   
        Tests to see if a particular module can be imported.
        N(   t
   __import__t   ImportErrort   Falset   True(   R   t   module_namet   mod(    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyt   moduleExists·   s
    	c         C   sü   d d k  } |  i | ƒ oÜ t | t ƒ  t ƒ  d g ƒ } x» | i D]¬ } t | i | ƒ p | i | i | ƒ o | i | t ƒ  | <qD t | i | ƒ i	 | i j oC | i | i t | i | ƒ i	 ƒ o | i | t ƒ  | <qð qD qD Wn d S(   s^  
        - Written by XE_ManUp! -

        ** THIS FUNCTION IS HIGHLY UNPYTHONIC **

        This basically takes all of the methods and class instances
        within the module of module_name and adds them to SPE.
        This way, you can call functions within that module
        directly from SPE. Example: spe.<functionInModule>(args).
        iÿÿÿÿNR/   (
   t   inspectR?   R9   t   globalst   localst   __dict__t   callablet   isclasst   typeR   (   R   R=   R@   R>   t   item(    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyR,   Â   s    
  !c         G   s8   | |  i  j o t d | ƒ ‚ n |  i  | i | ƒ S(   s2  
        Calls a function that is already in the global signature
            dictionary. These functions must be present within either
            the shared.ini or the mod specific ini file. The name
            parameter corresponds to the shortname of the function
            in the ini file.
        s$   Could not find %s in the dictionary!(   R(   R   R   (   R   R   R   (    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyR   Ú   s    
(	   R   R   R   R   R)   R+   R?   R,   R   (    (    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyR    u   s   			"		c         C   s   t  i |  ƒ d S(   sú   
    This function parses signatures from an INI file.
    Path represents the path to the INI file, with the
    base being cstrike/addons/eventscripts/. You must
    put in the .ini extension manually into the path.
    It is not done for you.
    N(   t   gSPER+   (   R#   (    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyR+   ó   s    c         G   s   t  i |  | Œ S(   sŠ   
    Calls a sigscanned function based upon its shortname
    in the INI file. args of course are the arguments to
    said function.
    (   RH   R   (   R   R   (    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyR   þ   s    c         C   s&   t  |  t |  i d ƒ ƒ ƒ } | | S(   sd  
    This function is very low level. It allows one to rip
    out C++ class instances directly from memory which are
    not normally accessible by server plugins. The signature
    parameter (which requires that the signature that is
    passed in uses hex escape characters) is the signature
    of the function that the instance is referenced in. The
    offset parameter is the number of bytes away from the
    beginning of the signature that the instance itself
    is referenced at (the beginning of the address bytes
    of the instance).

    IF YOU DO NOT KNOW WHAT YOU ARE DOING, DON'T USE THIS!
    R
   (   R   R   R   (   t	   signaturet   offsett   pFunc(    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pyt
   getPointer  s    (   R   R"   R3   t	   configobjR    R   R   R%   t   spe_Ct   __revision__t   __version__R&   t   stript
   makepublict	   ExceptionR   R   t   objectR   R    RH   R+   R   RL   (    (    (    sS   /home/saberrider/srcds/css/cstrike/addons/eventscripts/_libs/python/spe/__init__.pys   <module>   s$   
	>x				