Faschz

DKR - Brake Exploit

Jan 10th, 2021 (edited)
1,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.25 KB | None | 0 0
  1. // Prior material on DKR Velocity: https://pastebin.com/fig64sXz
  2.  
  3. // In my initial reversing of DKR's velocity functions for the kart, I never
  4. // looked into how brake was calculated when compared to throttle. I believe the
  5. // intended behavior was to have brakes be a floating point from 0.0 to 1.0 much
  6. // like throttle, however the way they calculated it was causing the brakes to
  7. // be more powerful rising up to 1.2 and as far down as -0.05.
  8.  
  9. // Here is some rough code showing what is actually going on.
  10.  
  11. if (HOLDING_B && player->brake < 1.0f) {
  12.     player->brake += 0.2f;
  13. }
  14.  
  15. if (!HOLDING_B && player->brake >= 0.05f) {
  16.     player->brake -= 0.1f;
  17. }
  18.  
  19. // Here are some examples of situations that brake the intended algorithm
  20.  
  21. // player->brake is 0.99 when holding B
  22. // 0.99 + 0.2 = 1.19
  23.  
  24. // player->brake is 0.05 when not holding B
  25. // 0.05 - 0.1 = -0.05
  26.  
  27. // Numbers like these can happen because of the use of floating point values,
  28. // repeated braking will cause the value to slowly stray away from the 0.1
  29. // increments into these unintended ranges.
  30.  
  31. // In my previous pastebin, listed at the top of this document, I included a
  32. // line which showed the acceleration that was being calculated from the brakes
  33. // Here it is again: -0.32 * 1.7 * stats * brakes
  34. // Notice the negative sign in this case, that means the velocity will decrease
  35. // However, we can get a negative value for the brakes... the lowest of which
  36. // is -0.05. This gives us a positive acceleration and thus a speed increase.
  37.  
  38. // Now to get the top speed similar to the examples I gave last time I will
  39. // assume 0 bananas, not boosting, not drifting, normal road, and using Diddy.
  40. // (1.7 * stats * throttle + -0.32 * 1.7 * stats * brakes) / traction
  41. // (1.7 * 0.34 * 1.0 + -0.32 * 1.7 * 0.34 * -0.05) / 0.004
  42. // (0.578 + 0.009248) / 0.004
  43. // 0.587248 / 0.004
  44. // 146.812 ... and finally the square root of this is 12.117
  45. // Pulling from the last paste, the value was 12.021 without this exploit.
  46. // That is an increase of roughly 0.8% top speed. Or in terms of acceleration
  47. // it is a (0.32 * 0.05) = 0.016, 1.6% acceleration increase. Which you can see
  48. // correlates to that 0.8% top speed if you took the squareroot of 1.016. This
  49. // means the speed you gain from the exploit is the same regardless of bananas,
  50. // character, road, etc.
  51.  
  52. // Here is a sample program to kind of show how many cycles of braking would
  53. // need to occur for you to reach the theoretical 0.8% top speed gain.
  54.  
  55. int cnt = 0;
  56. float brakes = 0.0f;
  57. float previous = brakes;
  58.  
  59. while (1) {
  60.     while (brakes < 1.0f) {
  61.         brakes += 0.2f;
  62.     }
  63.    
  64.     while (brakes >= 0.05f) {
  65.         brakes -= 0.1f;
  66.     }
  67.    
  68.     cnt += 1;
  69.    
  70.     if (previous < brakes) {
  71.         break;
  72.     }
  73.    
  74.     previous = brakes;
  75. }
  76.  
  77. // After running this, the value of previous becomes -0.05f which, as expected,
  78. // is the theoretical best. And cnt is 419431, which is how many cycles of
  79. // holding the b button and letting go was required to reach that value.
  80.  
  81. // Main takeaway is.. this isn't useful at all unless perhaps for flaps if you
  82. // were crazy enough to waste that much time. Also for those wondering why the
  83. // character moves when you don't press buttons on a flat surface, this exploit
  84. // is the culprit.
Add Comment
Please, Sign In to add comment