Advertisement
Guest User

SDK Hooks b2.2.0 GroundEntChangedPost crash

a guest
Jul 5th, 2012
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.43 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////
  2. //
  3. //          Physics Control
  4. //              (for TF2)
  5. //          by thaCURSEDpie
  6. //
  7. //          2012-07-04
  8. //
  9. //          pre-alpha
  10. //
  11. //
  12. //          This plugin aims to give server-admins
  13. //          greater control over the game's physics.
  14. //
  15. ////////////////////////////////////////////////////////////
  16.  
  17. ////////////////////////////////////////////////////////////
  18. //
  19. //          Includes et cetera
  20. //
  21. ////////////////////////////////////////////////////////////
  22.  
  23. #pragma semicolon 1
  24.  
  25. #define PLUGIN_VERSION      "0.0.0"
  26. #define SHORT_DESCRIPTION   "Physics Control by thaCURSEDpie"
  27. #define MAX_PLAYERS         33
  28.  
  29. #include <sourcemod>
  30. #include <sdktools>
  31. #include <sdkhooks>
  32. #include <tf2>
  33.  
  34. ////////////////////////////////////////////////////////////
  35. //
  36. //          Global vars
  37. //
  38. ////////////////////////////////////////////////////////////
  39.  
  40. //-- Handles
  41. new Handle:hEnabled                 = INVALID_HANDLE;
  42. new Handle:hAirstrafeMult       = INVALID_HANDLE;
  43. new Handle:hBhopMult                = INVALID_HANDLE;
  44. new Handle:hBhopMaxDelay            = INVALID_HANDLE;
  45. new Handle:hBhopZMult               = INVALID_HANDLE;
  46.  
  47. //-- Values
  48. new Float:fAirstrafeMult = 1.0;
  49. new Float:fBhopMult = 1.0;
  50. new Float:fBhopMaxDelay = 1.0;
  51. new Float:fBhopZMult = 1.0;
  52. new bool:bModEnabled = true;
  53.  
  54. //-- Player properties
  55. new Float:fAirstrafeMults[MAX_PLAYERS];
  56. new Float:fBhopMults[MAX_PLAYERS];
  57. new Float:fBhopZMults[MAX_PLAYERS];
  58. new Float:fOldVels[MAX_PLAYERS][3];
  59. new bool:bIsInAir[MAX_PLAYERS];
  60. new bool:bJumpPressed[MAX_PLAYERS];
  61. new Float:fMomentTouchedGround[MAX_PLAYERS];
  62. new Float:fBhopMaxDelays[MAX_PLAYERS];
  63. new iGroundEntities[MAX_PLAYERS];
  64.  
  65. ////////////////////////////////////////////////////////////
  66. //
  67. //          Mod description
  68. //
  69. ////////////////////////////////////////////////////////////
  70.  
  71. public Plugin:myinfo =
  72. {
  73.     name            = "Physics Control",
  74.     author      = "thaCURSEDpie",
  75.     description     = "This plugin aims to give server admins more control over the game physics.",
  76.     version         = PLUGIN_VERSION,
  77.     url             = "http://www.sourcemod.net"
  78. };
  79.    
  80. ////////////////////////////////////////////////////////////
  81. //
  82. //          OnPluginStart
  83. //
  84. ////////////////////////////////////////////////////////////
  85.  
  86. public OnPluginStart()
  87. {
  88.     //-- Cmds
  89.     RegAdminCmd("sm_phctrlreload", CmdReload, ADMFLAG_SLAY);
  90.    
  91.     //-- Convars
  92.     CreateConVar("phctrl_version", PLUGIN_VERSION, SHORT_DESCRIPTION, FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY);
  93.    
  94.     hEnabled = CreateConVar("phctrl_enabled", "1", "Enable Physics Control", FCVAR_PLUGIN);
  95.     hAirstrafeMult = CreateConVar("phctrl_airstrafemult", "1.0", "The multiplier to apply to airstrafing", FCVAR_PLUGIN);
  96.     hBhopMult = CreateConVar("phctrl_bhopmult", "1.0", "Boost to apply to bunnyhopping", FCVAR_PLUGIN);
  97.     hBhopMaxDelay = CreateConVar("phctrl_bhopmaxdelay", "1.0", "Maximum time after the player has touched the ground, that he still can get the bhop boost, in seconds", FCVAR_PLUGIN);
  98.     hBhopZMult = CreateConVar("phctrl_bhopzmult", "1.0", "Boost to apply to Upward velocity when bunnyhopping", FCVAR_PLUGIN);
  99.    
  100.     HookConVarChange(hAirstrafeMult, OnAirstrafeMultChanged);
  101.     HookConVarChange(hEnabled, OnEnabledChanged);
  102.     HookConVarChange(hBhopMult, OnBhopMultChanged);
  103.     HookConVarChange(hBhopMaxDelay, OnBhopMaxDelayChanged);
  104.     HookConVarChange(hBhopZMult, OnBhopZMultChanged);
  105.    
  106.     Init();
  107. }
  108.  
  109. public Init()
  110. {
  111.     //-- Init some arrays and values
  112.     for (new i = 1; i < MAX_PLAYERS; i++)
  113.     {
  114.         fAirstrafeMults[i] = fAirstrafeMult;
  115.         fBhopMults[i] = fBhopMult;
  116.         fBhopMaxDelays[i] = fBhopMaxDelay;
  117.         fBhopZMults[i] = fBhopZMult;
  118.        
  119.         if (IsValidEntity(i) && IsClientConnected(i))
  120.         {
  121.             SDKHook(i, SDKHook_PostThink, OnPostThink);
  122.             // SDKHook(i, SDKHook_GroundEntChangedPost, OnGroundEntChanged); // Causes crash!
  123.         }
  124.     }
  125. }
  126.  
  127. public Action:CmdReload(client, args)
  128. {
  129.     Init();
  130.     PrintToChat(client, "Physics Control reloaded!");
  131.    
  132.     return Plugin_Handled;
  133. }
  134.  
  135. ////////////////////////////////////////////////////////////
  136. //
  137. //          OnClientPutInServer
  138. //
  139. ////////////////////////////////////////////////////////////
  140.  
  141. public OnClientPutInServer(client)
  142. {
  143.     SDKHook(client, SDKHook_PostThink, OnPostThink);
  144.     // SDKHook(client, SDKHook_GroundEntChangedPost, OnGroundEntChanged); // Causes crash!
  145. }
  146.  
  147. ////////////////////////////////////////////////////////////
  148. //
  149. //          Convars Changed Hooks
  150. //
  151. ////////////////////////////////////////////////////////////
  152.  
  153. public OnEnabledChanged(Handle:convar, const String:oldValue[], const String:newValue[])
  154. {
  155.     bModEnabled = GetConVarBool(convar);
  156. }
  157.  
  158. public OnAirstrafeMultChanged(Handle:convar, const String:oldValue[], const String:newValue[])
  159. {
  160.     fAirstrafeMult = GetConVarFloat(convar);
  161.    
  162.     for (new i = 0; i < MAX_PLAYERS; i++)
  163.     {
  164.         fAirstrafeMults[i] = fAirstrafeMult;
  165.     }
  166. }
  167.  
  168. public OnBhopMultChanged(Handle:convar, const String:oldValue[], const String:newValue[])
  169. {  
  170.     fBhopMult = GetConVarFloat(convar);
  171.    
  172.     for (new i = 0; i < MAX_PLAYERS; i++)
  173.     {
  174.         fBhopMults[i] = fBhopMult;
  175.     }
  176. }
  177.  
  178. public OnBhopZMultChanged(Handle:convar, const String:oldValue[], const String:newValue[])
  179. {  
  180.     fBhopZMult = GetConVarFloat(convar);
  181.    
  182.     for (new i = 0; i < MAX_PLAYERS; i++)
  183.     {
  184.         fBhopZMults[i] = fBhopZMult;
  185.     }
  186. }
  187.  
  188. public OnBhopMaxDelayChanged(Handle:convar, const String:oldValue[], const String:newValue[])
  189. {
  190.     new Float:oldMult = fBhopMaxDelay;
  191.    
  192.     fBhopMaxDelay = GetConVarFloat(convar);
  193.    
  194.     for (new i = 0; i < MAX_PLAYERS; i++)
  195.     {
  196.         if (fBhopMaxDelays[i] == oldMult)
  197.         {
  198.             fBhopMaxDelays[i] = fBhopMaxDelay;
  199.         }
  200.     }
  201. }
  202.  
  203. ////////////////////////////////////////////////////////////
  204. //
  205. //          OnPlayerRunCmd
  206. //
  207. ////////////////////////////////////////////////////////////
  208.  
  209. public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
  210. {
  211.     if (!bModEnabled)
  212.     {
  213.         return Plugin_Continue;
  214.     }
  215.    
  216.     if (bIsInAir[client])
  217.     {      
  218.         vel[0] *= fAirstrafeMults[client];
  219.         vel[1] *= fAirstrafeMults[client];
  220.         // PrintToConsole(client, "mult: %f", fAirstrafeMults[client]);
  221.         // PrintToConsole(client, "new vel: x: %f y: %f", vel[0], vel[1]);
  222.     }
  223.     else
  224.     {
  225.         if (buttons & IN_JUMP)
  226.         {
  227.             bJumpPressed[client] = true;
  228.         }
  229.     }
  230.    
  231.     return Plugin_Continue;
  232. }
  233.  
  234. ////////////////////////////////////////////////////////////
  235. //
  236. //          OnPostThink
  237. //
  238. ////////////////////////////////////////////////////////////
  239.  
  240. public OnPostThink(client)
  241. {
  242.     if (!bModEnabled || !IsValidEntity(client) || !IsClientInGame(client) || !IsPlayerAlive(client))
  243.     {
  244.         return;
  245.     }  
  246.    
  247.     /*
  248.     new iGroundEntity = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity");
  249.    
  250.     if (iGroundEntity == -1)
  251.     {          
  252.         // PrintToConsole(client, "Ha! We are in the air!");
  253.        
  254.         // Air 
  255.         GetEntPropVector(client, Prop_Data, "m_vecVelocity", fOldVels[client]);
  256.         bIsInAir[client] = true;
  257.     }
  258.     else
  259.     {
  260.         // Ground or entity
  261.         if (bIsInAir[client])
  262.         {
  263.             fMomentTouchedGround[client] = GetTickedTime();
  264.             bIsInAir[client] = false;
  265.         }
  266.     }
  267.     */
  268.    
  269.     if (bJumpPressed[client])
  270.     {          
  271.         bJumpPressed[client] = false;
  272.        
  273.         if (fBhopMults[client] != -1 && GetTickedTime() - fMomentTouchedGround[client] <= fBhopMaxDelays[client])
  274.         {
  275.             new Float:fNewVel[3];
  276.            
  277.             GetEntPropVector(client, Prop_Data, "m_vecVelocity", fNewVel);
  278.            
  279.             fNewVel[0] = fOldVels[client][0] * fBhopMults[client];
  280.             fNewVel[1] = fOldVels[client][1] * fBhopMults[client];         
  281.             fNewVel[2] *= fBhopZMults[client];
  282.            
  283.             PrintToConsole(client, "bHop boost: mult: %f, zmult: %f, old: %f %f, new: %f %f", fBhopMults[client], fBhopZMults[client], fOldVels[client][0], fOldVels[client][1], fNewVel[0], fNewVel[1]);
  284.            
  285.             TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, fNewVel);
  286.         }
  287.         else
  288.         {
  289.             PrintToConsole(client, "Not allowed to bHop! Current time: %f, last: %f, diff: %f", GetTickedTime(), fMomentTouchedGround[client], GetTickedTime() - fMomentTouchedGround[client]);
  290.         }
  291.     }
  292. }
  293.  
  294. ////////////////////////////////////////////////////////////
  295. //
  296. //          OnGroundEntChanged
  297. //
  298. ////////////////////////////////////////////////////////////
  299.  
  300. public OnGroundEntChanged(client)
  301. {
  302.     iGroundEntities[client] = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity");
  303.    
  304.     if (iGroundEntities[client] == -1)
  305.     {          
  306.         // PrintToConsole(client, "Ha! We are in the air!");
  307.        
  308.         // Air 
  309.         GetEntPropVector(client, Prop_Data, "m_vecVelocity", fOldVels[client]);
  310.         bIsInAir[client] = true;
  311.     }
  312.     else
  313.     {
  314.         // Ground or entity
  315.         if (bIsInAir[client])
  316.         {
  317.             fMomentTouchedGround[client] = GetTickedTime();
  318.             bIsInAir[client] = false;
  319.         }
  320.     }
  321. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement