DeathChaos25

DHook test

Sep 4th, 2015
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.81 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <dhooks>
  3. #include <sdktools>
  4.  
  5. new Handle:hSequenceSet;
  6. new Handle:sdkDoAnim;
  7. static clienthook[MAXPLAYERS + 1] = -1;
  8. static clone[MAXPLAYERS + 1] = -1;
  9.  
  10. #define ANIM_NICK       631
  11. #define ANIM_ELLIS      636
  12. #define ANIM_ROCH       639
  13. #define ANIM_ZOEY       529
  14. #define ANIM_LOUIS      539
  15. #define ANIM_FRANCIS    542
  16. #define ANIM_BILL       539
  17.  
  18. static const String:MODEL_NICK[] = "models/survivors/survivor_gambler.mdl";
  19. static const String:MODEL_ROCHELLE[] = "models/survivors/survivor_producer.mdl";
  20. static const String:MODEL_COACH[] = "models/survivors/survivor_coach.mdl";
  21. static const String:MODEL_ELLIS[] = "models/survivors/survivor_mechanic.mdl";
  22. static const String:MODEL_BILL[] = "models/survivors/survivor_namvet.mdl";
  23. static const String:MODEL_ZOEY[] = "models/survivors/survivor_teenangst.mdl";
  24. static const String:MODEL_FRANCIS[] = "models/survivors/survivor_biker.mdl";
  25. static const String:MODEL_LOUIS[] = "models/survivors/survivor_manager.mdl";
  26.  
  27. public Plugin:myinfo =
  28. {
  29.     name = "L4D2 DHook Test",
  30.     author = "DeathChaos25",
  31.     description = "",
  32.     version = "",
  33.     url = ""
  34. }
  35.  
  36. public OnPluginStart()
  37. {
  38.     SetConVarInt(FindConVar("survivor_allow_crawling"), 1);
  39.     SetConVarInt(FindConVar("survivor_crawl_speed"), 35);
  40.     LoadOffset();
  41.     PrepSDKCall();
  42.     RegConsoleCmd("sm_hook", HOOKME);
  43. }
  44.  
  45. public OnGameFrame()
  46. {
  47.     for (new client = 1; client <= MaxClients; client++)
  48.     {
  49.         if (!IsClientInGame(client))return;
  50.         new buttons = GetClientButtons(client);
  51.         if (IsSurvivor(client) && IsPlayerAlive(client) && !IsPlayerHeld(client)
  52.              && GetEntProp(client, Prop_Send, "m_isHangingFromLedge") != 1
  53.              && GetEntProp(client, Prop_Send, "m_reviveOwner") == -1 && IsIncapacitated(client) && buttons & IN_FORWARD)
  54.         {
  55.             new String:model[128];
  56.             GetClientModel(client, model, sizeof(model));
  57.             if (StrEqual(model, MODEL_COACH))return;
  58.             if (clienthook[client] != 1)
  59.             {
  60.                 GotoThirdPerson(client);
  61.                 clienthook[client] = DHookEntity(hSequenceSet, false, client);
  62.                 SDKCall(sdkDoAnim, client, 71, 0);
  63.                 if(StrEqual(model, MODEL_ZOEY))
  64.                 {
  65.                     SetEntProp(client, Prop_Send, "m_nSequence", ANIM_ZOEY);
  66.                 }
  67.                 else if(StrEqual(model, MODEL_NICK))
  68.                 {
  69.                     SetEntProp(client, Prop_Send, "m_nSequence", ANIM_NICK);
  70.                 }
  71.                 else if(StrEqual(model, MODEL_ELLIS))
  72.                 {
  73.                     SetEntProp(client, Prop_Send, "m_nSequence", ANIM_ELLIS);
  74.                 }
  75.                 else if(StrEqual(model, MODEL_ROCHELLE))
  76.                 {
  77.                     SetEntProp(client, Prop_Send, "m_nSequence", ANIM_ROCH);
  78.                 }
  79.                 else if(StrEqual(model, MODEL_BILL))
  80.                 {
  81.                     SetEntProp(client, Prop_Send, "m_nSequence", ANIM_BILL);
  82.                 }
  83.                 else if(StrEqual(model, MODEL_FRANCIS))
  84.                 {
  85.                     SetEntProp(client, Prop_Send, "m_nSequence", ANIM_FRANCIS);
  86.                 }
  87.                 else if(StrEqual(model, MODEL_LOUIS))
  88.                 {
  89.                     SetEntProp(client, Prop_Send, "m_nSequence", ANIM_LOUIS);
  90.                 }
  91.             }
  92.         }
  93.         else if (IsSurvivor(client) && IsPlayerAlive(client) && GetEntProp(client, Prop_Send, "m_isHangingFromLedge") != 1 && IsIncapacitated(client))
  94.         {
  95.             SDKCall(sdkDoAnim, client, 20, 0);
  96.             if (clienthook[client] > 0)
  97.             {
  98.                 DHookRemoveHookID(clienthook[client]);
  99.                 GotoFirstPerson(client);
  100.                 clienthook[client] = -1;
  101.             }
  102.         }
  103.     }
  104. }
  105.  
  106. public Action:HOOKME(client, args)
  107. {
  108.     if (IsSurvivor(client))
  109.     {
  110.         if (clienthook[client] > 0)
  111.         {
  112.             DHookRemoveHookID(clienthook[client]);
  113.             clienthook[client] = -1;
  114.         }
  115.         else clienthook[client] = DHookEntity(hSequenceSet, true, client);
  116.     }
  117.     else ReplyToCommand(client, "Must be an ingame survivor to use this command!");
  118. }
  119. public MRESReturn:OnSequenceSet(client, Handle:hParams)
  120. {
  121.     return MRES_Ignored;
  122. }
  123.  
  124. bool:IsSurvivor(client)
  125. {
  126.     return (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2);
  127. }
  128.  
  129. LoadOffset()
  130. {
  131.     new Handle:temp = LoadGameConfigFile("l4d2_sequence");
  132.    
  133.     if (temp == INVALID_HANDLE)
  134.     {
  135.         SetFailState("Error: Gamedata not found");
  136.     }
  137.    
  138.     new offset;
  139.     offset = GameConfGetOffset(temp, "CTerrorPlayer::SelectWeightedSequence");
  140.     if (offset == -1)
  141.     {
  142.         CloseHandle(temp);
  143.         LogError("Unable to get offset for CTerrorPlayer::SelectWeightedSequence");
  144.         return;
  145.     }
  146.     hSequenceSet = DHookCreate(offset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity, OnSequenceSet);
  147.     DHookAddParam(hSequenceSet, HookParamType_Int);
  148. }
  149.  
  150. stock bool:IsPlayerHeld(client)
  151. {
  152.     new jockey = GetEntPropEnt(client, Prop_Send, "m_jockeyAttacker");
  153.     new charger = GetEntPropEnt(client, Prop_Send, "m_pummelAttacker");
  154.     new hunter = GetEntPropEnt(client, Prop_Send, "m_pounceAttacker");
  155.     new smoker = GetEntPropEnt(client, Prop_Send, "m_tongueOwner");
  156.     if (jockey > 0 || charger > 0 || hunter > 0 || smoker > 0)
  157.     {
  158.         return true;
  159.     }
  160.     return false;
  161. }
  162. stock bool:IsIncapacitated(client)
  163. {
  164.     if (GetEntProp(client, Prop_Send, "m_isIncapacitated", 1) > 0)
  165.         return true;
  166.     return false;
  167. }
  168.  
  169. static PrepSDKCall()
  170. {
  171.     new Handle:config = LoadGameConfigFile("l4d2_sequence");
  172.    
  173.     if (config == INVALID_HANDLE)
  174.     {
  175.         SetFailState("Error: unable to load l4d2_sequence gamedata file");
  176.     }
  177.    
  178.     StartPrepSDKCall(SDKCall_Player);
  179.    
  180.     if (!PrepSDKCall_SetFromConf(config, SDKConf_Virtual, "CTerrorPlayer::DoAnimationEvent"))
  181.     {
  182.         CloseHandle(config);
  183.         SetFailState("Cant find CTerrorPlayer::DoAnimationEvent Signature in gamedata file");
  184.     }
  185.     PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
  186.     PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
  187.     CloseHandle(config);
  188.     sdkDoAnim = EndPrepSDKCall();
  189.     if (sdkDoAnim == INVALID_HANDLE)
  190.     {
  191.         SetFailState("Cant initialize CTerrorPlayer::DoAnimationEvent SDKCall, Signature broken");
  192.     }
  193. }
  194.  
  195. GotoThirdPerson(client)
  196. {
  197.     SetEntPropFloat(client, Prop_Send, "m_TimeForceExternalView", 99999.3);
  198. }
  199.  
  200. GotoFirstPerson(client)
  201. {
  202.     SetEntPropFloat(client, Prop_Send, "m_TimeForceExternalView", 0.0);
  203. }
Advertisement
Add Comment
Please, Sign In to add comment