TimpZ

Haxmod updated

Jun 15th, 2017
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.69 KB | None | 0 0
  1. /*
  2.     Original code by WatchingTime
  3.     https://pastebin.com/YvB9BTp9
  4.     https://twitter.com/WatchingTime_
  5.    
  6.     Modified and expanded upon by TimpZ
  7.     https://twitter.com/timpz91
  8.    
  9.     Recommended hardware guide:
  10.     https://docs.google.com/document/d/1KZrORDtJBuovVAHRZjteRitBKkwibZOc7VW0PdGedEk/edit
  11. */
  12.  
  13. // Setup and public variables
  14. #include "Nintendo.h"
  15. CGamecubeController controller(2); //sets D2 on arduino to read data from controller
  16. CGamecubeConsole console(3);       //sets D3 on arduino to write data to console
  17. Gamecube_Report_t gcc;             //structure for controller state
  18. bool shield, tilt, dolphin = 0, off = 0, switchPresetR = 0, switchPresetL = 0;
  19. byte axm, aym, cxm, cym, cycles;
  20. char ax, ay, cx, cy, buf;
  21. float swang, seang;
  22. word mode, toggle;
  23. unsigned long nx, ny, nz;
  24. int preset = 1;
  25.  
  26. // This defines the edges on the controller.
  27. //you can check these either with Serial.print or the 20XX Hack Pack
  28. #define sw_notch_x_value -.7000
  29. #define sw_notch_y_value -.7000
  30. #define se_notch_x_value  .7000
  31. #define se_notch_y_value -.7000
  32.  
  33.  
  34. /*
  35.     Available mods with description
  36. WatchingTime
  37.     perfectangles();            - reduces deadzone of cardinals and gives steepest/shallowest angles when on or near the gate
  38.     maxvectors();                   - snaps sufficiently high cardinal inputs to vectors of 1.0 magnitude of analog stick and c stick
  39.     shielddrops();                  - allows shield drops down and gives a 6 degree range of shield dropping centered on SW and SE gates
  40.     backdash();                     - fixes dashback by imposing a 1 frame buffer upon tilt turn values
  41.     dolphinfix();                   - ensures close to 0 values are reported as 0 on the sticks to fix dolphin calibration and allows user to switch to dolphin mode for backdash
  42.    
  43. TimpZ
  44.     gcc.left = 0;               - disables right lightshield
  45.     gcc.right = 0;              - disables right lightshield
  46.     remap();                    - remaps the A and B buttons. Can be modified for any digital input
  47.     zFrame();                   - disables the z button press after ~1.5 frames
  48.     xFrame();                   - disables the x button press after ~1 frames
  49.     yFrame();                   - disables the y button press after ~1 frames
  50.     lLimit();                   - disables light shield values between 1 and 70 on the L button
  51.     rLimit();                   - disables light shield values between 1 and 70 on the R button
  52. */
  53.  
  54.  
  55. //These functions define what mods the presets should use
  56. //Simply add more if you want
  57. void preset1(){
  58.   perfectangles();
  59.   maxvectors();
  60.   shielddrops();
  61.   backdash();
  62.   dolphinfix();
  63. }
  64.  
  65. void preset2(){
  66.   backdash();
  67.   shielddrops();
  68.   maxvectors();
  69.   lLimit();
  70.   gcc.right = 0;
  71.   zFrame();
  72.   yFrame();
  73.   //Serial.print(gcc.y);
  74. }
  75.  
  76. void preset3(){
  77.   remap();
  78.  
  79. }
  80.  
  81. void preset4(){
  82.   //no changes
  83. }
  84.  
  85. void lLimit(){
  86.   if(gcc.left<70) gcc.left = 0;
  87. }
  88.  
  89. void rLimit(){
  90.   if(gcc.right<70) gcc.right = 0;
  91. }
  92.  
  93. void zFrame(){
  94.   if(gcc.z){
  95.     if(nz == 0) nz = millis();
  96.     if(millis()-nz>4) gcc.z = 0;
  97.   }else nz = 0;
  98. }
  99.  
  100. void xFrame(){
  101.   if(gcc.x){
  102.     if(nx == 0) nx = millis();
  103.     if(millis()-nx>3) gcc.x = 0;
  104.   }else nx = 0;
  105. }
  106.  
  107. void yFrame(){
  108.   if(gcc.y){
  109.     if(ny == 0) ny = millis();
  110.     if(millis()-ny>3) gcc.y = 0;
  111.   }else ny = 0;
  112. }
  113.  
  114. void remap(){
  115.   bool buff;
  116.   buff = gcc.a;
  117.   gcc.a = gcc.b;
  118.   gcc.b = buff;  
  119. }
  120.  
  121. void perfectangles(){
  122.   if(axm>75){gcc.xAxis = (ax>0)?204:52; if(aym<23) gcc.yAxis = (ay>0)?151:105;}
  123.   if(aym>75){gcc.yAxis = (ay>0)?204:52; if(axm<23) gcc.xAxis = (ax>0)?151:105;}
  124. }
  125.  
  126. void maxvectors(){
  127.   if(axm>75&&aym< 9){gcc.xAxis  = (ax>0)?255:1; gcc.yAxis  = 128;}
  128.   if(aym>75&&axm< 9){gcc.yAxis  = (ay>0)?255:1; gcc.xAxis  = 128;}
  129.   if(cxm>75&&cym<23){gcc.cxAxis = (cx>0)?255:1; gcc.cyAxis = 128;}
  130.   if(cym>75&&cxm<23){gcc.cyAxis = (cy>0)?255:1; gcc.cxAxis = 128;}
  131. }
  132.  
  133. void shielddrops(){
  134.   shield = gcc.l||gcc.r||gcc.left>74||gcc.right>74||gcc.z;
  135.   if(shield){
  136.     if(ay<0&&mag(ax,ay)>75){
  137.       if(ax<0&&abs(ang(axm,aym)-swang)<4){gcc.yAxis = 73; gcc.xAxis =  73;}
  138.       if(ax>0&&abs(ang(axm,aym)-seang)<4){gcc.yAxis = 73; gcc.xAxis = 183;}
  139.     }else if(abs(ay+39)<17&&axm<23) gcc.yAxis = 73;
  140.   }
  141. }
  142.  
  143. void backdash(){
  144.   if(aym<23){
  145.     if(axm<23)buf = cycles;
  146.     if(buf>0){buf--; if(axm<64) gcc.xAxis = 128+ax*(axm<23);}
  147.   }else buf = 0;
  148. }
  149.  
  150. void dolphinfix(){
  151.   if(axm<5&&aym<5){gcc.xAxis  = 128; gcc.yAxis  = 128;}
  152.   if(cxm<5&&cym<5){gcc.cxAxis = 128; gcc.cyAxis = 128;}
  153.   if(gcc.dright&&mode<2500) dolphin = dolphin||(mode++>2000);
  154.   else mode = 0;
  155.   cycles = 3 + (6*dolphin);
  156. }
  157.  
  158. float ang(float xval, float yval){return atan(yval/xval)*57.2958;} //function to return angle in degrees when given x and y components
  159. float mag(char  xval, char  yval){return sqrt(sq(xval)+sq(yval));} //function to return vector magnitude when given x and y components
  160.  
  161. void setup(){
  162.   gcc.origin=0; gcc.errlatch=0; gcc.high1=0; gcc.errstat=0;  //init values
  163.   swang = ang(abs(sw_notch_x_value), abs(sw_notch_y_value)); //calculates angle of SW gate based on user inputted data
  164.   seang = ang(abs(se_notch_x_value), abs(se_notch_y_value)); //calculates angle of SE gate based on user inputted data
  165.  
  166.  
  167.   // Start debug serial
  168.   //Serial.begin(115200);
  169. }
  170.  
  171. void loop(){
  172.  
  173.     controller.read();
  174.     gcc = controller.getReport();
  175.  
  176.     ax = gcc.xAxis -128; ay = gcc.yAxis -128; //offsets from neutral position of analog stick
  177.     cx = gcc.cxAxis-128; cy = gcc.cyAxis-128; //offsets from neutral position of c stick
  178.     axm = abs(ax); aym = abs(ay);             //magnitude of analog stick offsets
  179.     cxm = abs(cx); cym = abs(cy);             //magnitude of c stick offsets
  180.  
  181.     //This code makes you able to switch between the presets.
  182.     //It currently works by holding down d-pad down and scrolling with L and R
  183.     if(gcc.r == 0) switchPresetR = 0;
  184.     if(gcc.ddown && gcc.r && switchPresetR == 0){
  185.         preset +=1;
  186.         switchPresetR = 1;
  187.     if(preset > 4) preset = 4; //change both these numbers to increase the number of presets available
  188.     }
  189.     if(gcc.l == 0) switchPresetL = 0;
  190.     if(gcc.ddown && gcc.l && switchPresetL == 0){
  191.         preset -=1;
  192.         switchPresetL = 1;
  193.     if(preset < 1) preset = 1;
  194.     }
  195.  
  196.     //This defines how many presets there are
  197.     //If you want more, simply make them
  198.     //Also remember to update the scrolling code above
  199.     if(preset == 1) preset1();                 //Original haxmod
  200.     if(preset == 2) preset2();                
  201.     if(preset == 3) preset3();                
  202.     if(preset == 4) preset4();                 //Unmodified
  203.  
  204.  
  205.     console.write(gcc);                       //sends controller data to the console
  206. }
Advertisement
Add Comment
Please, Sign In to add comment