Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpalpha/fc37b9fb30449df7ab8fbb2c1d14176d to your computer and use it in GitHub Desktop.
Save mpalpha/fc37b9fb30449df7ab8fbb2c1d14176d to your computer and use it in GitHub Desktop.
Titan2, GTuner IV, ANTIRECOIL (V+H), adjust on the fly, interactive config, autosave script.
#pragma METAINFO("ANTIRECOIL, horizontal, vertical, adjust in-game, interactive config, autosave", 1, 02, "ETB")
// Frist of all, thanks to RedbeardCrunch, J2Kbr, Layman, Scachi, and Antithesis
// Anti Recoil
// Hold Both Triggers & Press DPAD UP, DOWN, LEFT, RIGHT to adjust.
fix32 RECOIL_V = 30.0; // Vertical Recoil range -100.0 to 100.0
fix32 RECOIL_H = 0.0; // Horizontal Recoil range -100.0 to 100.0
fix32 ADJUSTMENT_STEP = 1.0; // increment to adjust recoil per interation range 1.0 to 10.0
fix32 RY; // reserved
fix32 RX; // reserved
// ADS Toggle
// Hold Both Triggers & Press Right Stick (button)
uint8 TOGGLE_ADS = TRUE; // Toggle ADS Default
fix32 STICK_NOISE = 4.32; // Change this value to adjust the size of the Deadzone to ignore when using a Xim Apex.
// in Gtuner IV > Device Monitor, flick the right stick and take note of the largest value.
bool PMUpdate = FALSE; // To save/write down the value to pmem set this flag to TRUE in the main loop.
// assign pmem locations (remember to match interactive config byteoffsets)
uint8 STICK_NOISE_PMEM = 0; // pmem slot
uint8 RECOIL_V_PMEM = 4; // pmem slot
uint8 RECOIL_H_PMEM = 8; // pmem slot
uint8 TOGGLE_ADS_PMEM = 12; // pmem slot
init {
pmem_load(); // load the ui pmem
pmem_read(STICK_NOISE_PMEM, &STICK_NOISE); // read the value to change from the ui
pmem_read(RECOIL_V_PMEM, &RECOIL_V); // read the value to change from the ui
pmem_read(RECOIL_H_PMEM, &RECOIL_H); // read the value to change from the ui
pmem_read(TOGGLE_ADS_PMEM, &TOGGLE_ADS); // read the value to change from the ui
STICK_NOISE = clamp(STICK_NOISE,0.0,255.0); // just to make sure the value is in the correct value range
RECOIL_V = clamp(RECOIL_V,-100.0,100.0); // just to make sure the value is in the correct value range
RECOIL_H = clamp(RECOIL_H,-100.0,100.0); // just to make sure the value is in the correct value range
ADJUSTMENT_STEP = clamp(ADJUSTMENT_STEP,1.0,10.0); // just to make sure the value is in the correct value range
printf("STICK_NOISE: %.04f", STICK_NOISE);
printf("RECOIL_V: %.04f", RECOIL_V);
printf("RECOIL_H: %.04f", RECOIL_H);
printf("ADJUSTMENT_STEP: %.04f", ADJUSTMENT_STEP);
printf("TOGGLE_ADS: %d", TOGGLE_ADS);
// Light Blue led = ADS enabled, White led = ADS disabled
set_light(TOGGLE_ADS? 'W': 'S');
}
main {
// adjust anti-recoil
if (is_active(BUTTON_5) && is_active(BUTTON_8)) { // Hold Both Triggers
if ( event_active(BUTTON_10) ) { // ...and Press DPAD_UP
if ( RECOIL_V > -100.0) {
RECOIL_V = (RECOIL_V - ADJUSTMENT_STEP);
pmem_write(RECOIL_V_PMEM,(fix32) RECOIL_V); // update the pmem value
PMUpdate=TRUE; // pmem and gui value throttle
}
}
if ( event_active(BUTTON_11) ) { // ...and Press DPAD_DOWN
if ( RECOIL_V < 100.0) {
RECOIL_V = (RECOIL_V + ADJUSTMENT_STEP);
pmem_write(RECOIL_V_PMEM,(fix32) RECOIL_V); // update the pmem value
PMUpdate=TRUE; // pmem and gui value throttle
}
}
if ( event_active(BUTTON_12) ) { // ...Press DPAD_LEFT
if ( RECOIL_H > -100.0) {
RECOIL_H = (RECOIL_H - ADJUSTMENT_STEP);
pmem_write(RECOIL_H_PMEM,(fix32) RECOIL_H); // update the pmem value
PMUpdate=TRUE; // pmem and gui value throttle
}
}
if ( event_active(BUTTON_13) ) { // ...and Press DPAD_RIGHT
if ( RECOIL_H < 100.0) {
RECOIL_H = (RECOIL_H + ADJUSTMENT_STEP);
pmem_write(RECOIL_H_PMEM,(fix32) RECOIL_H); // update the pmem value
PMUpdate=TRUE; // pmem and gui value throttle
}
}
if ( event_active(BUTTON_6) ) { // ...and Press Right Stick
TOGGLE_ADS = (!TOGGLE_ADS);
pmem_write(TOGGLE_ADS_PMEM, TOGGLE_ADS); // toggle and update the pmem value
PMUpdate=TRUE; // pmem and gui value throttle
}
}
// save values when changed
if (PMUpdate) {
PMSave(); // This function should be called on every iteration if changes are detected.
}
// DEADZONE REMOVER
if(abs(get_actual(STICK_1_X)) < STICK_NOISE) { set_val(STICK_1_X, 0.0); }
if(abs(get_actual(STICK_1_Y)) < STICK_NOISE) { set_val(STICK_1_Y, 0.0); }
if(abs(get_actual(STICK_2_X)) < STICK_NOISE) { set_val(STICK_2_X, 0.0); }
if(abs(get_actual(STICK_2_Y)) < STICK_NOISE) { set_val(STICK_2_Y, 0.0); }
// ANTI-RECOIL
if(get_val(BUTTON_5) && (!TOGGLE_ADS || get_val(BUTTON_8)))
{
AntiRecoil(STICK_1_Y,RECOIL_V);
AntiRecoil(STICK_1_X,RECOIL_H);
}
}
// Update the persistent memory, but not faster than 1000ms (1 second)
void PMSave() {
static uint32 PMSLast = 0;
if (PMUpdate && PMSLast < system_time())
{
printf("STICK_NOISE: %.04f", STICK_NOISE);
printf("RECOIL_V: %.04f", RECOIL_V);
printf("RECOIL_H: %.04f", RECOIL_H);
printf("ADJUSTMENT_STEP: %.04f", ADJUSTMENT_STEP);
printf("TOGGLE_ADS: %d", TOGGLE_ADS);
PMUpdate = FALSE;
printf("ic update");
printf("GCMD:InteractiveConfiguration.Refresh");
PMSLast = system_time() + 1000;
pmem_save();
// Light Blue led = ADS enabled, White led = ADS disabled
set_light(TOGGLE_ADS? 'W': 'S');
}
}
void AntiRecoil (uint8 axis, fix32 recoil)
{
RY = get_actual(STICK_1_Y);
RX = get_actual(STICK_1_X);
if (get_val(BUTTON_5) && (sqrt(RX*RX + RY*RY)) <= abs(recoil))
{
if(abs(RY) <= abs(recoil))
{
set_val(axis,(recoil * (100.0 - abs(get_val(axis)))) / 100.0 + get_val(axis));
}
}
}
void set_light(unsigned char new_light) {
static unsigned char old_light;
static uint32 timestamp;
if(new_light != old_light && (system_time() - timestamp > 50)) {
switch(new_light) {
timestamp = system_time(), old_light = new_light;
// PINK LED
case 'P' :led_set(LED_1, 0.0, 0), led_set(LED_2, 0.0, 0), led_set(LED_3, 0.0, 0),led_set(LED_4, 5.0, 0); return;
// BLUE LED
case 'B': led_set(LED_1, 25.0, 0),led_set(LED_2, 0.0, 0), led_set(LED_3, 0.0, 0),led_set(LED_4, 0.0, 0); return;
// SKY BLUE LED
case 'S': led_set(LED_1, 50.0, 0),led_set(LED_2, 0.0, 0), led_set(LED_3, 50.0, 0),led_set(LED_4, 0.0, 0); return;
// RED LED
case 'R': led_set(LED_1, 0.0, 0),led_set(LED_2, 25.0, 0), led_set(LED_3, 0.0, 0),led_set(LED_4, 0.0, 0); return;
// WHITE LED
case 'W': led_set(LED_1, 25.0, 0), led_set(LED_2, 25.0, 0), led_set(LED_3, 25.0, 0), led_set(LED_4, 25.0, 0); return;
// YELLOW LED
case 'Y': led_set(LED_1, 0.0, 0),led_set(LED_2, 30.0, 0), led_set(LED_3, 10.0, 0), led_set(LED_4, 0.0, 0); return;
// GREEN LED
case 'G': led_set(LED_1, 0.0, 0), led_set(LED_2, 0.0, 0), led_set(LED_3, 25.0, 0), led_set(LED_4, 0.0, 0); return;
// NO LED
case 'N':led_set(LED_1, 0.0, 0),led_set(LED_2, 0.0, 0), led_set(LED_3, 0.0, 0), led_set(LED_4, 0.0, 0);
}
}
return;
}
/***************
<cfgdesc>
[Universal Anti-Recoil]
shortdesc = <<<MULTILINE
Horizontal: Hold both triggers + press left or right dpad
Vertical: Hold both triggers + press up or down dpad
Toggle ADS: Hold both triggers + press right stick button
Adjust in-game.
Interactive configuration.
Autosave.
MULTILINE
control = info
[Sticknoise]
shortdesc = <<<MULTILINE
The default value 4.32 should be a good start.
If you want to tweak this, set it to the max value of your sticks resting position values.
Use the "Device Monitor" to examine them.
MULTILINE
byteoffset = 0
bitsize = 32
control = spinboxf
default = 432
minimum = 0
maximum = 2000
step = 1
decimals = 2
[Anti Recoil Vertical]
shortdesc = Vertical recoil compensation
byteoffset = 4
bitsize = 32
control = spinboxf
default = 300
minimum = -1000
maximum = 1000
step = 1
decimals = 1
[Anti Recoil Horizontal]
shortdesc = Horizontal recoil compensation
byteoffset = 8
bitsize = 32
control = spinboxf
default = 0
minimum = -1000
maximum = 1000
step = 1
decimals = 1
[Toggle ADS]
shortdesc = Enable this if you would like Anti Recoil enabled while aiming down sight or during hip fire.
byteoffset = 12
bitsize = 8
control = checkbox
default = 1
item = Enable
</cfgdesc>
***************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment