_PoY

Crystal-Glacierbadge bug

Nov 17th, 2020 (edited)
587
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Confirms only 206-432 & 661-999 unboosted Special Attack activate the Special Defense badge boost from Glacierbadge
  2.  
  3. #include <stdio.h>
  4. typedef unsigned char bool;
  5.  
  6. unsigned char A, B, C, D, E, F;
  7. bool CARRY, ZERO;
  8.  
  9. unsigned int MAX_STAT = (unsigned int) 999;
  10.  
  11. unsigned char LOW(unsigned int integer){ return (unsigned char) (integer % 256); }
  12. unsigned char HIGH(unsigned int integer){ return (unsigned char) (integer / 256); }
  13.  
  14.  
  15. void resetGlobals(){
  16.     A = 0;
  17.     B = 0;
  18.     C = 0;
  19.     D = 0;
  20.     E = 0;
  21.     CARRY = 0;
  22.     ZERO = 0;
  23. }
  24.  
  25. void ld(unsigned char* dest, unsigned char value){
  26.     *dest = value;
  27. }
  28.  
  29. void srl(unsigned char* reg){
  30.     CARRY = (*reg & 1);
  31.     *reg >>= 1;
  32.     ZERO = (*reg == 0);
  33. }
  34.  
  35. void rr(unsigned char* reg){
  36.     unsigned char newCarry;
  37.     newCarry = (*reg & 1);
  38.     *reg >>= 1;
  39.     *reg |= (CARRY << 7);
  40.     CARRY = newCarry;
  41.     ZERO = (*reg == 0);
  42. }
  43.  
  44. void add(unsigned char reg){
  45.     unsigned int tmpA;
  46.     tmpA = A + reg;
  47.     A += reg;
  48.     CARRY = (tmpA > 255);
  49.     ZERO = (A == 0);
  50. }
  51.  
  52. void adc(unsigned char reg){
  53.     unsigned int tmpA;
  54.     tmpA = A + reg + CARRY;
  55.     A += (reg + CARRY);
  56.     CARRY = (tmpA > 255);
  57.     ZERO = (A == 0);
  58. }
  59.  
  60. void sub(unsigned char reg){
  61.     int tmpA;
  62.     tmpA = A - reg;
  63.     A -= reg;
  64.     CARRY = (tmpA < 0);
  65.     ZERO = (A == 0);
  66. }
  67.  
  68. void sbc(unsigned char reg){
  69.     int tmpA;
  70.     tmpA = A - reg - CARRY;
  71.     A -= (reg + CARRY);
  72.     CARRY = (tmpA < 0);
  73.     ZERO = (A == 0);
  74. }
  75.  
  76. void BoostStat(unsigned char _high, unsigned char _low){
  77.     unsigned char high = _high;
  78.     unsigned char low = _low;
  79.    
  80.     ld(&A, high);
  81.     ld(&D, A);
  82.     ld(&E, low);
  83.     srl(&D);
  84.     rr(&E);
  85.     srl(&D);
  86.     rr(&E);
  87.     srl(&D);
  88.     rr(&E);
  89.     ld(&A, low);
  90.     add(E);
  91.     ld(&low, A);
  92.     ld(&A, high);
  93.     adc(D);
  94.     ld(&high, A);
  95.    
  96.     ld(&A, low);
  97.     sub(LOW(MAX_STAT));
  98.     ld(&A, high);
  99.     sbc(HIGH(MAX_STAT));
  100.    
  101.     if(CARRY){
  102.         return;
  103.     }
  104.    
  105.     ld(&A, HIGH(MAX_STAT));
  106.     ld(&high, A);
  107.     ld(&A, LOW(MAX_STAT));
  108.     ld(&low, A);
  109.    
  110.     return;
  111. }
  112.  
  113. bool testFunction(unsigned char high, unsigned char low){
  114.     BoostStat(high, low);
  115.     srl(&A);
  116.     return CARRY;
  117. }
  118.  
  119. int main()
  120. {    
  121.     unsigned char highSpcAtk;
  122.     unsigned char lowSpcAtk;
  123.    
  124.     unsigned int MIN_INPUT = 0;
  125.     unsigned int MAX_INPUT = 999;
  126.    
  127.     bool out;
  128.    
  129.     for(unsigned int i = MIN_INPUT; i <= MAX_INPUT; i++){
  130.         resetGlobals();
  131.         highSpcAtk = HIGH(i);
  132.         lowSpcAtk = LOW(i);
  133.         out = testFunction(highSpcAtk, lowSpcAtk);
  134.         printf("%4d %s\n", (highSpcAtk<<8)|lowSpcAtk, out ? "BOOST":"");
  135.     }
  136. }
  137.  
RAW Paste Data