import java.math.BigInteger;

public class Class338 {

   BigInteger aBigInteger4356;
   Class247 aClass247_4357;
   BigInteger aBigInteger4358;
   Class257 aClass257_4359;
   Class225_Sub14_Sub14_Sub2 aClass225_Sub14_Sub14_Sub2_4360;
   RS2Buffer aClass225_Sub23_4361;
   Class250_Sub1[] aClass250_Sub1Array4362;
   static String aString4363;
   public static Class247 aClass247_4364;


   public void method6218() {
      if(null != this.aClass250_Sub1Array4362) {
         int var1;
         for(var1 = 0; var1 < this.aClass250_Sub1Array4362.length; ++var1) {
            if(null != this.aClass250_Sub1Array4362[var1]) {
               this.aClass250_Sub1Array4362[var1].method14323(34646887);
            }
         }

         for(var1 = 0; var1 < this.aClass250_Sub1Array4362.length; ++var1) {
            if(this.aClass250_Sub1Array4362[var1] != null) {
               this.aClass250_Sub1Array4362[var1].method14324((byte)-18);
            }
         }

      }
   }

   public Class338(Class247 var1, Class257 var2, BigInteger var3, BigInteger var4) {
      this.aClass247_4357 = var1;
      this.aClass257_4359 = var2;
      this.aBigInteger4356 = var3;
      this.aBigInteger4358 = var4;
      if(!this.aClass247_4357.method4395(1453365648)) {
         this.aClass225_Sub14_Sub14_Sub2_4360 = this.aClass247_4357.method4393(255, 255, (byte)0, true, (byte)7);
      }

   }

   public boolean method6219(int var1) {
      if(this.aClass225_Sub23_4361 != null) {
         return true;
      } else {
         if(this.aClass225_Sub14_Sub14_Sub2_4360 == null) {
            if(this.aClass247_4357.method4395(1017347125)) {
               return false;
            }

            this.aClass225_Sub14_Sub14_Sub2_4360 = this.aClass247_4357.method4393(255, 255, (byte)0, true, (byte)7);
         }

         if(this.aClass225_Sub14_Sub14_Sub2_4360.aBool10562) {
            return false;
         } else {
            RS2Buffer var2 = new RS2Buffer(this.aClass225_Sub14_Sub14_Sub2_4360.method16276(509785357));
            var2.position = -1663860987;
            int var3 = var2.readUnsignedByte(-700559597);
            var2.position += var3 * 951212104;
            byte[] var4 = new byte[var2.buffer.length - var2.position * -543666943];
            var2.method13737(var4, 0, var4.length, 1385214721);
            byte[] var5;
            if(this.aBigInteger4356 != null && this.aBigInteger4358 != null) {
               BigInteger var6 = new BigInteger(var4);
               BigInteger var7 = var6.modPow(this.aBigInteger4356, this.aBigInteger4358);
               var5 = var7.toByteArray();
            } else {
               var5 = var4;
            }

            if(var5.length != 65) {
            	System.err.println("Invalid JS5 handshake footer length : " + var5.length);
               throw new RuntimeException();
            } else {
               byte[] var11 = Class222_Sub1.method14017(var2.buffer, 5, -543666943 * var2.position - var4.length - 5, 2008960221);

               int var12;
               for(var12 = 0; var12 < 64; ++var12) {
                  if(var11[var12] != var5[1 + var12]) {
                     throw new RuntimeException();
                  }
               }

               this.aClass225_Sub23_4361 = var2;
               if(this.aClass250_Sub1Array4362 == null) {
                  this.aClass250_Sub1Array4362 = new Class250_Sub1[var3];
               } else {
                  for(var12 = 0; var12 < this.aClass250_Sub1Array4362.length; ++var12) {
                     if(this.aClass250_Sub1Array4362[var12] != null) {
                        this.aClass225_Sub23_4361.position = -278646266 + var12 * 951212104;
                        int var8 = this.aClass225_Sub23_4361.readInt_(-944735383);
                        int var9 = this.aClass225_Sub23_4361.readInt_(903838533);
                        byte[] var10 = new byte[64];
                        this.aClass225_Sub23_4361.method13737(var10, 0, 64, 1385214721);
                        this.aClass250_Sub1Array4362[var12].method14328(var8, var10, var9, (byte)37);
                     }
                  }
               }

               return true;
            }
         }
      }
   }

   public Class250_Sub1 method6220(int var1, Class218 var2, Class218 var3, int var4) {
      return this.method6222(var1, var2, var3, true, 2146449705);
   }

   public void method6221(int var1) {
      if(null != this.aClass250_Sub1Array4362) {
         int var2;
         for(var2 = 0; var2 < this.aClass250_Sub1Array4362.length; ++var2) {
            if(null != this.aClass250_Sub1Array4362[var2]) {
               this.aClass250_Sub1Array4362[var2].method14323(34646887);
            }
         }

         for(var2 = 0; var2 < this.aClass250_Sub1Array4362.length; ++var2) {
            if(this.aClass250_Sub1Array4362[var2] != null) {
               this.aClass250_Sub1Array4362[var2].method14324((byte)-79);
            }
         }

      }
   }

   Class250_Sub1 method6222(int var1, Class218 var2, Class218 var3, boolean var4, int var5) {
      if(null == this.aClass225_Sub23_4361) {
         throw new RuntimeException();
      } else if(var1 >= 0 && var1 < this.aClass250_Sub1Array4362.length) {
         if(this.aClass250_Sub1Array4362[var1] != null) {
            return this.aClass250_Sub1Array4362[var1];
         } else {
            this.aClass225_Sub23_4361.position = -278646266 + 951212104 * var1;
            int var6 = this.aClass225_Sub23_4361.readInt_(-1373109515);
            int var7 = this.aClass225_Sub23_4361.readInt_(1559866781);
            byte[] var8 = new byte[64];
            this.aClass225_Sub23_4361.method13737(var8, 0, 64, 1385214721);
            Class250_Sub1 var9 = new Class250_Sub1(var1, var2, var3, this.aClass247_4357, this.aClass257_4359, var6, var8, var7, var4);
            this.aClass250_Sub1Array4362[var1] = var9;
            return var9;
         }
      } else {
         throw new RuntimeException();
      }
   }

   public Class250_Sub1 method6223(int var1, Class218 var2, Class218 var3) {
      return this.method6222(var1, var2, var3, true, 2146687870);
   }

   public Class250_Sub1 method6224(int var1, Class218 var2, Class218 var3) {
      return this.method6222(var1, var2, var3, true, 2147455083);
   }

   Class250_Sub1 method6225(int var1, Class218 var2, Class218 var3, boolean var4) {
      if(null == this.aClass225_Sub23_4361) {
         throw new RuntimeException();
      } else if(var1 >= 0 && var1 < this.aClass250_Sub1Array4362.length) {
         if(this.aClass250_Sub1Array4362[var1] != null) {
            return this.aClass250_Sub1Array4362[var1];
         } else {
            this.aClass225_Sub23_4361.position = -278646266 + 951212104 * var1;
            int var5 = this.aClass225_Sub23_4361.readInt_(672984945);
            int var6 = this.aClass225_Sub23_4361.readInt_(-45899180);
            byte[] var7 = new byte[64];
            this.aClass225_Sub23_4361.method13737(var7, 0, 64, 1385214721);
            Class250_Sub1 var8 = new Class250_Sub1(var1, var2, var3, this.aClass247_4357, this.aClass257_4359, var5, var7, var6, var4);
            this.aClass250_Sub1Array4362[var1] = var8;
            return var8;
         }
      } else {
         throw new RuntimeException();
      }
   }

   public void method6226() {
      if(null != this.aClass250_Sub1Array4362) {
         int var1;
         for(var1 = 0; var1 < this.aClass250_Sub1Array4362.length; ++var1) {
            if(null != this.aClass250_Sub1Array4362[var1]) {
               this.aClass250_Sub1Array4362[var1].method14323(34646887);
            }
         }

         for(var1 = 0; var1 < this.aClass250_Sub1Array4362.length; ++var1) {
            if(this.aClass250_Sub1Array4362[var1] != null) {
               this.aClass250_Sub1Array4362[var1].method14324((byte)3);
            }
         }

      }
   }

   public Class250_Sub1 method6227(int var1, Class218 var2, Class218 var3) {
      return this.method6222(var1, var2, var3, true, 2147278850);
   }

   public void method6228() {
      if(null != this.aClass250_Sub1Array4362) {
         int var1;
         for(var1 = 0; var1 < this.aClass250_Sub1Array4362.length; ++var1) {
            if(null != this.aClass250_Sub1Array4362[var1]) {
               this.aClass250_Sub1Array4362[var1].method14323(34646887);
            }
         }

         for(var1 = 0; var1 < this.aClass250_Sub1Array4362.length; ++var1) {
            if(this.aClass250_Sub1Array4362[var1] != null) {
               this.aClass250_Sub1Array4362[var1].method14324((byte)-125);
            }
         }

      }
   }

   public void method6229() {
      if(null != this.aClass250_Sub1Array4362) {
         int var1;
         for(var1 = 0; var1 < this.aClass250_Sub1Array4362.length; ++var1) {
            if(null != this.aClass250_Sub1Array4362[var1]) {
               this.aClass250_Sub1Array4362[var1].method14323(34646887);
            }
         }

         for(var1 = 0; var1 < this.aClass250_Sub1Array4362.length; ++var1) {
            if(this.aClass250_Sub1Array4362[var1] != null) {
               this.aClass250_Sub1Array4362[var1].method14324((byte)-101);
            }
         }

      }
   }

   public static Class48 method6230(int var0, byte var1) {
      return 835545533 * Class48.aClass48_495.anInt494 == var0?Class48.aClass48_495:(Class48.aClass48_493.anInt494 * 835545533 == var0?Class48.aClass48_493:null);
   }

   static final void method6231(Class508 var0, int var1) {
      int var2 = var0.anIntArray6027[(var0.anInt6003 -= 98312473) * -937710807];
      Class124 var3 = Class97.method1903(var2, 163066169);
      Class121 var4 = Class18.aClass121Array188[var2 >> 16];
      Class79.method1632(var3, var4, var0, 1024720872);
   }

   static final void method6232(Class508 var0, int var1) {
      var0.anIntArray6027[(var0.anInt6003 += 98312473) * -937710807 - 1] = Class500.aClass225_Sub6_5953.aClass463_Sub22_8461.method12986((byte)113);
   }

   static final void method6233(int var0, int var1, int var2, int var3, int var4, int var5, int var6, byte var7) {
      int var8 = var6 - 334;
      if(var8 < 0) {
         var8 = 0;
      } else if(var8 > 100) {
         var8 = 100;
      }

      int var9 = client.aShort7954 + (client.aShort7793 - client.aShort7954) * var8 / 100;
      var5 = var9 * var5 >> 8;
      int var10 = 16384 - var3 & 16383;
      int var11 = 16384 - var4 & 16383;
      int var12 = 0;
      int var13 = 0;
      int var14 = var5;
      if(var10 != 0) {
         var13 = -var5 * Class312.anIntArray3943[var10] >> 14;
         var14 = Class312.anIntArray3956[var10] * var5 >> 14;
      }

      if(0 != var11) {
         var12 = var14 * Class312.anIntArray3943[var11] >> 14;
         var14 = Class312.anIntArray3956[var11] * var14 >> 14;
      }

      Class90.anInt895 = (var0 - var12) * -1415269723;
      Class416.anInt5137 = (var1 - var13) * -1544030555;
      Class4.anInt112 = -2025085711 * (var2 - var14);
      Class365.anInt4603 = var3 * 5027157;
      Class85.anInt867 = 1910759249 * var4;
      Class173.anInt2083 = 0;
   }

   static final void method6234(Class508 var0, byte var1) {
      Class505 var2 = var0.aBool6014?var0.aClass505_6011:var0.aClass505_6010;
      Class124 var3 = var2.aClass124_5977;
      Class121 var4 = var2.aClass121_5978;
      Class18.method789(var3, var4, var0, -1777845466);
   }

   static final void method6235(Class508 var0, int var1) {
      int var2 = var0.anIntArray6027[(var0.anInt6003 -= 98312473) * -937710807];
      Class124 var3 = Class97.method1903(var2, 603806122);
      Class121 var4 = Class18.aClass121Array188[var2 >> 16];
      Class463.method7816(var3, var4, var0, -774587639);
   }

   static final void method6236(Class508 var0, byte var1) {
      var0.anInt6003 -= 196624946;
      client.aShort7954 = (short)var0.anIntArray6027[-937710807 * var0.anInt6003];
      if(client.aShort7954 <= 0) {
         client.aShort7954 = 256;
      }

      client.aShort7793 = (short)var0.anIntArray6027[1 + -937710807 * var0.anInt6003];
      if(client.aShort7793 <= 0) {
         client.aShort7793 = 320;
      }

   }
}
