DeathChaos25

dhooks.inc

Sep 2nd, 2015
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.07 KB | None | 0 0
  1. #if defined _dhooks_included
  2. #endinput
  3. #endif
  4. #define _dhooks_included
  5.  
  6. enum ObjectValueType
  7. {
  8.     ObjectValueType_Int = 0,
  9.     ObjectValueType_Bool,
  10.     ObjectValueType_Ehandle,
  11.     ObjectValueType_Float,
  12.     ObjectValueType_CBaseEntityPtr,
  13.     ObjectValueType_IntPtr,
  14.     ObjectValueType_BoolPtr,
  15.     ObjectValueType_EhandlePtr,
  16.     ObjectValueType_FloatPtr,
  17.     ObjectValueType_Vector,
  18.     ObjectValueType_VectorPtr,
  19.     ObjectValueType_CharPtr,
  20.     ObjectValueType_String
  21. };
  22.  
  23. enum ListenType
  24. {
  25.     ListenType_Created,
  26.     ListenType_Deleted
  27. };
  28.  
  29. enum ReturnType
  30. {
  31.     ReturnType_Unknown,
  32.     ReturnType_Void,
  33.     ReturnType_Int,
  34.     ReturnType_Bool,
  35.     ReturnType_Float,
  36.     ReturnType_String, //Note this is a string_t
  37.     ReturnType_StringPtr, //Note this is a string_t *
  38.     ReturnType_CharPtr,
  39.     ReturnType_Vector,
  40.     ReturnType_VectorPtr,
  41.     ReturnType_CBaseEntity,
  42.     ReturnType_Edict
  43. };
  44.  
  45. enum HookParamType
  46. {
  47.     HookParamType_Unknown,
  48.     HookParamType_Int,
  49.     HookParamType_Bool,
  50.     HookParamType_Float,
  51.     HookParamType_String, //Note this is a string_t
  52.     HookParamType_StringPtr, //Note this is a string_t *
  53.     HookParamType_CharPtr,
  54.     HookParamType_VectorPtr,
  55.     HookParamType_CBaseEntity,
  56.     HookParamType_ObjectPtr,
  57.     HookParamType_Edict,
  58.     HookParamType_Object
  59. };
  60.  
  61. enum ThisPointerType
  62. {
  63.     ThisPointer_Ignore,
  64.     ThisPointer_CBaseEntity,
  65.     ThisPointer_Address
  66. };
  67.  
  68. enum HookType
  69. {
  70.     HookType_Entity,
  71.     HookType_GameRules,
  72.     HookType_Raw
  73. };
  74.  
  75. enum MRESReturn
  76. {
  77.     MRES_ChangedHandled = -2,   // Use changed values and return MRES_Handled
  78.     MRES_ChangedOverride,       // Use changed values and return MRES_Override
  79.     MRES_Ignored,               // plugin didn't take any action
  80.     MRES_Handled,               // plugin did something, but real function should still be called
  81.     MRES_Override,              // call real function, but use my return value
  82.     MRES_Supercede              // skip real function; use my return value
  83. };
  84.  
  85. enum DHookPassFlag
  86. {
  87.     DHookPass_ByVal = (1<<0),
  88.     DHookPass_ByRef = (1<<1)
  89. };
  90.  
  91. typeset ListenCB
  92. {
  93.     //Deleted
  94.     function void (int entity);
  95.    
  96.     //Created
  97.     function void (int entity, const char[] classname);
  98. };
  99.  
  100. typeset DHookRemovalCB
  101. {
  102.     function void (int hookid);
  103. };
  104. typeset DHookCallback
  105. {
  106.     //Function Example: void Ham::Test() with this pointer ignore
  107.     function MRESReturn ();
  108.    
  109.     //Function Example: void Ham::Test() with this pointer passed
  110.     function MRESReturn (int pThis);
  111.    
  112.     //Function Example: void Ham::Test(int cake) with this pointer ignore
  113.     function MRESReturn (Handle hParams);
  114.    
  115.     //Function Example: void Ham::Test(int cake) with this pointer passed
  116.     function MRESReturn (int pThis, Handle hParams);
  117.    
  118.     //Function Example: int Ham::Test() with this pointer ignore
  119.     function MRESReturn (Handle hReturn);
  120.    
  121.     //Function Example: int Ham::Test() with this pointer passed
  122.     function MRESReturn (int pThis, Handle hReturn);
  123.    
  124.     //Function Example: int Ham::Test(int cake) with this pointer ignore
  125.     function MRESReturn (Handle hReturn, Handle hParams);
  126.    
  127.     //Function Example: int Ham::Test(int cake) with this pointer passed
  128.     function MRESReturn (int pThis, Handle hReturn, Handle hParams);
  129.    
  130.     //Address NOW
  131.    
  132.     //Function Example: void Ham::Test() with this pointer passed
  133.     function MRESReturn (Address pThis);
  134.    
  135.     //Function Example: void Ham::Test(int cake) with this pointer passed
  136.     function MRESReturn (Address pThis, Handle hParams);
  137.    
  138.     //Function Example: int Ham::Test() with this pointer passed
  139.     function MRESReturn (Address pThis, Handle hReturn);
  140.    
  141.     //Function Example: int Ham::Test(int cake) with this pointer passed
  142.     function MRESReturn (Address pThis, Handle hReturn, Handle hParams);
  143.    
  144. };
  145.  
  146. /* Adds an entity listener hook
  147.  *
  148.  * @param type          Type of listener to add
  149.  * @param callback      Callback to use
  150.  *
  151.  * @noreturn
  152. */
  153. native void DHookAddEntityListener(ListenType type, ListenCB callback);
  154.  
  155. /* Removes an entity listener hook
  156.  *
  157.  * @param type          Type of listener to remove
  158.  * @param callback      Callback this listener was using
  159.  *
  160.  * @return True if one was removed false otherwise.
  161. */
  162. native bool DHookRemoveEntityListener(ListenType type, ListenCB callback);
  163.  
  164. /* Creates a hook
  165.  *
  166.  * @param offset        vtable offset for function to hook
  167.  * @param hooktype      Type of hook
  168.  * @param returntype    Type type of return
  169.  * @param thistype      Type of this pointer or ignore (ignore can be used if not needed)
  170.  * @param callback      Callback function
  171.  *
  172.  * @return Returns setup handle for the hook or INVALID_HANDLE.
  173. */
  174. native Handle DHookCreate(int offset, HookType hooktype, ReturnType returntype, ThisPointerType thistype, DHookCallback callback);
  175.  
  176. /* Adds param to a hook setup
  177.  *
  178.  * @param setup         Setup handle to add the param to.
  179.  * @param type          Param type
  180.  * @param size          Used for Objects (not Object ptr) to define the size of the object.
  181.  * @param flag          Used to change the pass type.
  182.  *
  183.  * @error   Invalid setup handle or too many params added (request upping the max in thread)
  184.  * @noreturn
  185. */
  186. native void DHookAddParam(Handle setup, HookParamType type, int size=-1, DHookPassFlag flag=DHookPass_ByVal);
  187. //native DHookAddParam(Handle:setup, HookParamType:type);
  188.  
  189. /* Hook entity
  190.  *
  191.  * @param setup         Setup handle to use to add the hook.
  192.  * @param post          True to make the hook a post hook. (If you need to change the retunr value or need the return value use a post hook! If you need to change params and return use a pre and post hook!)
  193.  * @param entity        Entity index to hook on.
  194.  * @param removalcb     Callback for when the hook is removed (Entity hooks are auto-removed on entity destroyed and will call this callback)
  195.  *
  196.  * @error Invalid setup handle, invalid entity or invalid hook type.
  197.  * @return -1 on fail a hookid on success
  198. */
  199. native int DHookEntity(Handle setup, bool post, int entity, DHookRemovalCB removalcb=INVALID_FUNCTION);
  200.  
  201. /* Hook gamerules
  202.  *
  203.  * @param setup         Setup handle to use to add the hook.
  204.  * @param post          True to make the hook a post hook. (If you need to change the retunr value or need the return value use a post hook! If you need to change params and return use a pre and post hook!)
  205.  * @param removalcb     Callback for when the hook is removed (Game rules hooks are auto-removed on map end and will call this callback)
  206.  *
  207.  * @error Invalid setup handle, failing to get gamerules pointer or invalid hook type.
  208.  * @return -1 on fail a hookid on success
  209. */
  210. native int DHookGamerules(Handle setup, bool post, DHookRemovalCB removalcb=INVALID_FUNCTION);
  211.  
  212. /* Hook a raw pointer
  213.  *
  214.  * @param setup         Setup handle to use to add the hook.
  215.  * @param post          True to make the hook a post hook. (If you need to change the retunr value or need the return value use a post hook! If you need to change params and return use a pre and post hook!)
  216.  * @param addr          This pointer address.
  217.  * @param removalcb     Callback for when the hook is removed (Entity hooks are auto-removed on entity destroyed and will call this callback)
  218.  *
  219.  * @error Invalid setup handle, invalid address or invalid hook type.
  220.  * @return -1 on fail a hookid on success
  221. */
  222. native int DHookRaw(Handle setup, bool post, Address addr, DHookRemovalCB removalcb=INVALID_FUNCTION);
  223.  
  224. /* Remove hook by hook id
  225.  *
  226.  * @param hookid        Hook id to remove
  227.  *
  228.  * @return true on success false otherwise
  229.  * @note This will not fire the removal callback!
  230. */
  231. native bool DHookRemoveHookID(int hookid);
  232.  
  233. /* Get param value (Only use for: int, entity, bool or float param types)
  234.  *
  235.  * @param hParams       Handle to params structure
  236.  * @param num           Param number to get. (Example if the function has 2 params and you need the value of the first param num would be 1. 0 Will return the number of params stored)
  237.  *
  238.  * @error Invalid handle. Invalid param number. Invalid param type.
  239.  * @return value if num greater than 0. If 0 returns paramcount.
  240. */
  241. native any DHookGetParam(Handle hParams, int num);
  242.  
  243. /* Get vector param value
  244.  *
  245.  * @param hParams       Handle to params structure
  246.  * @param num           Param number to get. (Example if the function has 2 params and you need the value of the first param num would be 1.)
  247.  * @param vec           Vector buffer to store result.
  248.  *
  249.  * @error Invalid handle. Invalid param number. Invalid param type.
  250.  * @noreturn
  251. */
  252. native void DHookGetParamVector(Handle hParams, int num, float vec[3]);
  253.  
  254. /* Get string param value
  255.  *
  256.  * @param hParams       Handle to params structure
  257.  * @param num           Param number to get. (Example if the function has 2 params and you need the value of the first param num would be 1.)
  258.  * @param buffer        String buffer to store result
  259.  * @param size          Buffer size
  260.  *
  261.  * @error Invalid handle. Invalid param number. Invalid param type.
  262.  * @noreturn
  263. */
  264. native void DHookGetParamString(Handle hParams, int num, char[] buffer, int size);
  265.  
  266. /* Set param value (Only use for: int, entity, bool or float param types)
  267.  *
  268.  * @param hParams       Handle to params structure
  269.  * @params num          Param number to set (Example if the function has 2 params and you need to set the value of the first param num would be 1.)
  270.  * @param value         Value to set it as (only pass int, bool, float or entity index)
  271.  *
  272.  * @error Invalid handle. Invalid param number. Invalid param type.
  273.  * @noreturn
  274. */
  275. native void DHookSetParam(Handle hParams, int num, any value);
  276.  
  277. /* Set vector param value
  278.  *
  279.  * @param hParams       Handle to params structure
  280.  * @params num          Param number to set (Example if the function has 2 params and you need to set the value of the first param num would be 1.)
  281.  * @param vec           Value to set vector as.
  282.  *
  283.  * @error Invalid handle. Invalid param number. Invalid param type.
  284.  * @noreturn
  285. */
  286. native void DHookSetParamVector(Handle hParams, int num, float vec[3]);
  287.  
  288. /* Set string param value
  289.  *
  290.  * @param hParams       Handle to params structure
  291.  * @params num          Param number to set (Example if the function has 2 params and you need to set the value of the first param num would be 1.)
  292.  * @param value         Value to set string as.
  293.  *
  294.  * @error Invalid handle. Invalid param number. Invalid param type.
  295.  * @noreturn
  296. */
  297. native void DHookSetParamString(Handle hParams, int num, char[] value);
  298.  
  299. /* Get return value (Only use for: int, entity, bool or float return types)
  300.  *
  301.  * @param hReturn       Handle to return structure
  302.  *
  303.  * @error Invalid Handle, invalid type.
  304.  * @return Returns default value if prehook returns actual value if post hook.
  305. */
  306. native any DHookGetReturn(Handle hReturn);
  307.  
  308. /* Get return vector value
  309.  *
  310.  * @param hReturn       Handle to return structure
  311.  * @param vec           Vector buffer to store result in. (In pre hooks will be default value (0.0,0.0,0.0))
  312.  *
  313.  * @error Invalid Handle, invalid type.
  314.  * @noreturn
  315. */
  316. native void DHookGetReturnVector(Handle hReturn, float vec[3]);
  317.  
  318. /* Get return string value
  319.  *
  320.  * @param hReturn       Handle to return structure
  321.  * @param buffer        String buffer to store result in. (In pre hooks will be default value "")
  322.  * @param size          String buffer size
  323.  *
  324.  * @error Invalid Handle, invalid type.
  325.  * @noreturn
  326. */
  327. native void DHookGetReturnString(Handle hReturn, char[] buffer, int size);
  328.  
  329. /* Set return value (Only use for: int, entity, bool or float return types)
  330.  *
  331.  * @param hReturn       Handle to return structure
  332.  * @param value         Value to set return as
  333.  *
  334.  * @error Invalid Handle, invalid type.
  335.  * @noreturn
  336. */
  337. native void DHookSetReturn(Handle hReturn, any value);
  338.  
  339. /* Set return vector value
  340.  *
  341.  * @param hReturn       Handle to return structure
  342.  * @param vec           Value to set return vector as
  343.  *
  344.  * @error Invalid Handle, invalid type.
  345.  * @noreturn
  346. */
  347. native void DHookSetReturnVector(Handle hReturn, float vec[3]);
  348.  
  349. /* Set return string value
  350.  *
  351.  * @param hReturn       Handle to return structure
  352.  * @param value         Value to set return string as
  353.  *
  354.  * @error Invalid Handle, invalid type.
  355.  * @noreturn
  356. */
  357. native void DHookSetReturnString(Handle hReturn, char[] value);
  358.  
  359. //WE SHOULD WRAP THESE AROUND STOCKS FOR NON PTR AS WE SUPPORT BOTH WITH THESE NATIVE'S
  360.  
  361. /* Gets an objects variable value
  362.  *
  363.  * @param hParams       Handle to params structure
  364.  * @param num           Param number to get.
  365.  * @param offset        Offset within the object to the var to get.
  366.  * @param type          Type of var it is
  367.  *
  368.  * @error Invalid handle. Invalid param number. Invalid param type. Invalid Object type.
  369.  * @return Value of the objects var. If EHANDLE type or entity returns entity index.
  370. */
  371. native any DHookGetParamObjectPtrVar(Handle hParams, int num, int offset, ObjectValueType type);
  372.  
  373. /* Sets an objects variable value
  374.  *
  375.  * @param hParams       Handle to params structure
  376.  * @param num           Param number to set.
  377.  * @param offset        Offset within the object to the var to set.
  378.  * @param type          Type of var it is
  379.  * @param value         The value to set the var to.
  380.  *
  381.  * @error Invalid handle. Invalid param number. Invalid param type. Invalid Object type.
  382.  * @noreturn
  383. */
  384. native void DHookSetParamObjectPtrVar(Handle hParams, int num, int offset, ObjectValueType type, any value);
  385.  
  386. /* Gets an objects vector variable value
  387.  *
  388.  * @param hParams       Handle to params structure
  389.  * @param num           Param number to get.
  390.  * @param offset        Offset within the object to the var to get.
  391.  * @param type          Type of var it is
  392.  * @param buffer        Buffer to store the result vector
  393.  *
  394.  * @error Invalid handle. Invalid param number. Invalid param type. Invalid Object type.
  395.  * @noreturn
  396. */
  397. native void DHookGetParamObjectPtrVarVector(Handle hParams, int num, int offset, ObjectValueType type, float buffer[3]);
  398.  
  399. /* Sets an objects vector variable value
  400.  *
  401.  * @param hParams       Handle to params structure
  402.  * @param num           Param number to set.
  403.  * @param offset        Offset within the object to the var to set.
  404.  * @param type          Type of var it is
  405.  * @param value         The value to set the vector var to.
  406.  *
  407.  * @error Invalid handle. Invalid param number. Invalid param type. Invalid Object type.
  408.  * @noreturn
  409. */
  410. native void DHookSetParamObjectPtrVarVector(Handle hParams, int num, int offset, ObjectValueType type, float value[3]);
  411.  
  412. /* Gets an objects string variable value
  413.  *
  414.  * @param hParams       Handle to params structure
  415.  * @param num           Param number to get.
  416.  * @param offset        Offset within the object to the var to get.
  417.  * @param type          Type of var it is
  418.  * @param buffer        Buffer to store the result vector
  419.  * @param size          Size of the buffer
  420.  *
  421.  * @error Invalid handle. Invalid param number. Invalid param type. Invalid Object type.
  422.  * @noreturn
  423. */
  424. native void DHookGetParamObjectPtrString(Handle hParams, int num, int offset, ObjectValueType type, char[] buffer, int size);
  425.  
  426. /* Checks if a pointer param is null
  427.  *
  428.  * @param hParams       Handle to params structure
  429.  * @param num           Param number to check.
  430.  *
  431.  * @error Non pointer param
  432.  * @return True if null false otherwise.
  433. */
  434. native bool DHookIsNullParam(Handle hParams, int num);
  435.  
  436. public Extension __ext_dhooks =
  437. {
  438.     name = "dhooks",
  439.     file = "dhooks.ext",
  440. #if defined AUTOLOAD_EXTENSIONS
  441.     autoload = 1,
  442. #else
  443.     autoload = 0,
  444. #endif
  445. #if defined REQUIRE_EXTENSIONS
  446.     required = 1,
  447. #else
  448.     required = 0,
  449. #endif
  450. };
  451.  
  452. #if !defined REQUIRE_EXTENSIONS
  453. public __ext_dhooks_SetNTVOptional()
  454. {
  455.     MarkNativeAsOptional("DHookAddEntityListener");
  456.     MarkNativeAsOptional("DHookRemoveEntityListener");
  457.     MarkNativeAsOptional("DHookCreate");
  458.     MarkNativeAsOptional("DHookAddParam");
  459.     MarkNativeAsOptional("DHookEntity");
  460.     MarkNativeAsOptional("DHookGamerules");
  461.     MarkNativeAsOptional("DHookRaw");
  462.     MarkNativeAsOptional("DHookRemoveHookID");
  463.     MarkNativeAsOptional("DHookGetParam");
  464.     MarkNativeAsOptional("DHookGetParamVector");
  465.     MarkNativeAsOptional("DHookGetParamString");
  466.     MarkNativeAsOptional("DHookSetParam");
  467.     MarkNativeAsOptional("DHookSetParamVector");
  468.     MarkNativeAsOptional("DHookSetParamString");
  469.     MarkNativeAsOptional("DHookGetReturn");
  470.     MarkNativeAsOptional("DHookGetReturnVector");
  471.     MarkNativeAsOptional("DHookGetReturnString");
  472.     MarkNativeAsOptional("DHookSetReturn");
  473.     MarkNativeAsOptional("DHookSetReturnVector");
  474.     MarkNativeAsOptional("DHookSetReturnString");
  475.     MarkNativeAsOptional("DHookGetParamObjectPtrVar");
  476.     MarkNativeAsOptional("DHookSetParamObjectPtrVar");
  477.     MarkNativeAsOptional("DHookGetParamObjectPtrVarVector");
  478.     MarkNativeAsOptional("DHookSetParamObjectPtrVarVector");
  479.     MarkNativeAsOptional("DHookIsNullParam");
  480.     MarkNativeAsOptional("DHookGetParamObjectPtrString");
  481. }
  482. #endif
Advertisement
Add Comment
Please, Sign In to add comment