Advertisement
Chronos_Ouroboros

Scroll wheel hijacking

Dec 12th, 2017
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. class ScrollWheelHijackEventHandler : EventHandler {
  2.     static const String KeyBindsCCMDs [] = { "weapnext", "weapprev" };
  3.     static const String KeyBindsNetEvents [] = { "next", "prev" };
  4.  
  5.     override bool InputProcess (InputEvent e) {
  6.         if (e.Type != InputEvent.Type_KeyDown)
  7.             return false;
  8.  
  9.         int bind1, bind2;
  10.         for (int i = 0; i < 12; i++) {
  11.             [bind1, bind2] = Bindings.GetKeysForCommand (KeyBindsCCMDs [i]);
  12.  
  13.             if (e.KeyScan == bind1 || e.KeyScan == bind2) {
  14.                 EventHandler.SendNetworkEvent (String.Format ("ScrollWheelHijack:%s", KeyBindsNetEvents [i]));
  15.                 return true;
  16.             }
  17.         }
  18.  
  19.         return false;
  20.     }
  21.  
  22.     override void NetworkProcess (ConsoleEvent e) {
  23.         if (e.Player < 0) // Don't execute this if the player isn't given/valid
  24.             return;
  25.         if (!playeringame [e.Player] || !players [e.Player].mo) // Don't execute if the player isn't ingame, the player is null or the player's PlayerPawn is null
  26.             return;
  27.  
  28.         Array<String> strings;
  29.         e.Name.Split (strings, ":");
  30.  
  31.         if (strings.Size () < 2) // Return if the array has less than two strings
  32.             return;
  33.  
  34.         if (strings [0] == "ScrollWheelHijack")
  35.             WeapBindsSystem (e);
  36.     }
  37.  
  38.     void WeapBindsSystem (ConsoleEvent e) {
  39.         PlayerInfo player = players [e.Player];
  40.  
  41.         if (!player) // Return if the player is null
  42.             return;
  43.  
  44.         Array<String> commandStrings;
  45.         e.Name.Split (commandStrings, ":");
  46.         if (commandStrings.Size () < 2) // Return if the array contains less than two strings
  47.             return;
  48.  
  49.         if (commandStrings [1] == "next") {
  50.             S7_BaseWeapon weapon = weapBinds.CycleWeapons (false, false);
  51.  
  52.             if (player.ReadyWeapon != weapon) {
  53.                 player.PendingWeapon = weapon;
  54.                 weapBinds.LastWeapon = weapon;
  55.             }
  56.         } else if (commandStrings [1] == "prev") {
  57.             S7_BaseWeapon weapon = weapBinds.CycleWeapons (true, false);
  58.  
  59.             if (player.ReadyWeapon != weapon) {
  60.                 player.PendingWeapon = weapon;
  61.                 weapBinds.LastWeapon = weapon;
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement