Skip to content

Instantly share code, notes, and snippets.

@globalpolicy
Created May 29, 2018 15:25
Show Gist options
  • Save globalpolicy/5c9f3bc071412e646524c1e552416b5d to your computer and use it in GitHub Desktop.
Save globalpolicy/5c9f3bc071412e646524c1e552416b5d to your computer and use it in GitHub Desktop.
PUBG Mouse Helper C Script
//globalpolicy
//c0dew0rth.blogspot.com
//26th May, 2018
//Hold middle mouse button to auto fire any single shot gun
//Also performs recoil compensation
#pragma once
#include <Windows.h>
#include <stdio.h>
using namespace std;
void leftClickDown()
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
}
void leftClickUp()
{
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
void mouseMove(int dx, int dy, int step = 1, int sleep = 10)
{
int stepx, stepy;
stepx = (dx < 0) ? (step*-1) : (step);
for (int cnt = 1; cnt <= abs(dx / stepx); cnt++)
{
mouse_event(MOUSEEVENTF_MOVE, stepx, 0, 0, 0);
Sleep(sleep / 2);
}
stepy = (dy < 0) ? (step*-1) : (step);
for (int cnt = 1; cnt <= abs(dy / stepy); cnt++)
{
mouse_event(MOUSEEVENTF_MOVE, 0, stepy, 0, 0);
Sleep(sleep / 2);
}
}
void typeGraveAccent()
{
keybd_event(VK_OEM_3, 0, 0, 0);
keybd_event(VK_OEM_3, 0, KEYEVENTF_KEYUP, 0);
}
void monitorLoop(int dx, int dy, int waitMs, int shootDelayMs)
{
while (true)
{
SHORT gaks = GetAsyncKeyState(VK_MBUTTON);
if (gaks & 0b1000000000000000) //if MSB is set(non-zero) i.e. being held down
{
leftClickDown();
leftClickUp();
typeGraveAccent();
leftClickDown();
#pragma region Recoil compensation/pull
/*
* first param : horizontal recoil correction per shot in pixels
* second param : vertical recoil correction per shot in pixels (greater value=stronger downward pull)
* third param : recoil correction step size in pixels (game seems to not register the pull if >=2 (?) )
* fourth param : wait period between consecutive step-pulls/step-corrections (lower value=faster fire rate) (game doesn't register the pull if <=1)
*/
mouseMove(dx, dy, 1, shootDelayMs);
/*
* Recommended parameters for :
+ 5.56 guns :
- M16A4 : 0, 29, 1, 4
- Mini 14 : 0, 35, 1, 2
- SCAR-L : 0, 35, 1, 2
+ 7.72 guns : (generally worse recoil consistency than 5.56 guns)
- SKS : 5, 40, 1, 2
- AKM : 5, 35, 1, 2 (really just use auto mode with manual correction for this; AKM is just all over the place)
- Mk14 : 0, 35, 1, 2 (better recoil consistency than AKM but still not that good)
*/
#pragma endregion
leftClickUp();
typeGraveAccent();
}
#pragma region Firing rate delay
/*
* the lower it is, the faster the firing rate
* any lower than 6 and the game will freeze
* the lower it is, the greater the recoil
*/
Sleep(shootDelayMs);
/*
* Recommended delay for :
- M16A4 : 6-8
- SKS, AKM, Mk14, Mini 14, SCAR-L : 6
*/
#pragma endregion
}
}
@marcjhon
Copy link

marcjhon commented Sep 3, 2018

how can i get the injector for no recoil?

@UlyssesUlric
Copy link

What does this number 0b1000000000000000 mean please

@globalpolicy
Copy link
Author

What does this number 0b1000000000000000 mean please

That's just a 16-bit mask. Read up on GetAsyncKeyState() for details.

@globalpolicy
Copy link
Author

how can i get the injector for no recoil?

There's no injection happening here. I do not know where you can get one. All this code does is help you control your recoil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment