package mapped;

import java.util.HashSet;
import java.util.Set;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSModeWhere;

@ObfuscatedName("ok")
public class ModeWhere implements MouseWheel, RSModeWhere {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4417;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4414;
   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4415;
   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4416;
   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4419;
   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4424;
   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4431;
   @ObfuscatedName("ac")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4420;
   @ObfuscatedName("al")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4421;
   @ObfuscatedName("az")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4422;
   @ObfuscatedName("ap")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4423;
   @ObfuscatedName("av")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4428;
   @ObfuscatedName("ax")
   @ObfuscatedSignature(
      descriptor = "Lok;"
   )
   static final ModeWhere field4413;
   @ObfuscatedName("bk")
   static String field4426;
   @ObfuscatedName("as")
   @ObfuscatedGetter(
      intValue = -55608669
   )
   final int id;
   @ObfuscatedName("ay")
   final Set field4427;

   static {
      field4417 = new ModeWhere("", 0, new class382[]{class382.field4393, class382.field4392});
      field4414 = new ModeWhere("", 1, new class382[]{class382.field4390, class382.field4393, class382.field4392});
      field4415 = new ModeWhere("", 2, new class382[]{class382.field4390, class382.field4391, class382.field4393});
      field4416 = new ModeWhere("", 3, new class382[]{class382.field4390});
      field4419 = new ModeWhere("", 4);
      field4424 = new ModeWhere("", 5, new class382[]{class382.field4390, class382.field4393});
      field4431 = new ModeWhere("", 6, new class382[]{class382.field4393});
      field4420 = new ModeWhere("", 8, new class382[]{class382.field4390, class382.field4393});
      field4421 = new ModeWhere("", 9, new class382[]{class382.field4390, class382.field4391});
      field4422 = new ModeWhere("", 10, new class382[]{class382.field4390});
      field4423 = new ModeWhere("", 11, new class382[]{class382.field4390});
      field4428 = new ModeWhere("", 12, new class382[]{class382.field4390, class382.field4393});
      field4413 = new ModeWhere("", 13, new class382[]{class382.field4390});
      method7211();
   }

   @ObfuscatedSignature(
      descriptor = "(Ljava/lang/String;I[Lot;)V"
   )
   ModeWhere(String var1, int var2, class382[] var3) {
      this.field4427 = new HashSet();
      this.id = var2;
      class382[] var4 = var3;

      for(int var5 = 0; var5 < var4.length; ++var5) {
         class382 var6 = var4[var5];
         this.field4427.add(var6);
      }

   }

   ModeWhere(String var1, int var2) {
      this.field4427 = new HashSet();
      this.id = var2;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(B)I",
      garbageValue = "-11"
   )
   public int rsOrdinal_base() {
      return this.id;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(I)[Lok;",
      garbageValue = "435699803"
   )
   static ModeWhere[] method7211() {
      return new ModeWhere[]{field4421, field4413, field4428, field4420, field4419, field4415, field4417, field4423, field4424, field4414, field4431, field4422, field4416};
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(IIII)Ldt;",
      garbageValue = "-1608087816"
   )
   static Script method7204(int var0, int var1, int var2) {
      int var3 = class10.method109_base(var1, var0);
      Script var4 = WorldMapData_1.method4789(var3, var0);
      if(var4 != null) {
         return var4;
      } else {
         int var5 = (-3 - var2 << 8) + var0;
         var4 = WorldMapData_1.method4789(var5, var0);
         if(var4 != null) {
            return var4;
         } else {
            int var6 = var0 + -512;
            var4 = WorldMapData_1.method4789(var6, var0);
            return var4 != null?var4:null;
         }
      }
   }

   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "277734474"
   )
   public static void method7211_base() {
      ParamComposition.ParamDefinition_cached.clear_base();
   }

   @ObfuscatedName("jc")
   @ObfuscatedSignature(
      descriptor = "(B)V",
      garbageValue = "-46"
   )
   static final void method7205_base() {
      LoginScreenAnimation.method2513_base(false);
      Client.field555 = 0;
      boolean var0 = true;

      int var1;
      for(var1 = 0; var1 < WorldMapData_1.regionLandArchives.length; ++var1) {
         if(UserComparator7.regionMapArchiveIds[var1] != -1 && WorldMapData_1.regionLandArchives[var1] == null) {
            WorldMapData_1.regionLandArchives[var1] = WorldMapSection0.archive9.takeFile_base(UserComparator7.regionMapArchiveIds[var1], 0);
            if(WorldMapData_1.regionLandArchives[var1] == null) {
               var0 = false;
               ++Client.field555;
            }
         }

         if(UserComparator3.regionLandArchiveIds[var1] != -1 && GrandExchangeEvent.regionMapArchives[var1] == null) {
            GrandExchangeEvent.regionMapArchives[var1] = WorldMapSection0.archive9.takeFileEncrypted_base(UserComparator3.regionLandArchiveIds[var1], 0, Varcs.xteaKeys[var1]);
            if(GrandExchangeEvent.regionMapArchives[var1] == null) {
               var0 = false;
               ++Client.field555;
            }
         }
      }

      if(!var0) {
         Client.field559 = 1;
      } else {
         Client.field521 = 0;
         var0 = true;

         int var3;
         int var4;
         for(var1 = 0; var1 < WorldMapData_1.regionLandArchives.length; ++var1) {
            byte[] var2 = GrandExchangeEvent.regionMapArchives[var1];
            if(var2 != null) {
               var3 = (KitDefinition.regions[var1] >> 8) * 64 - NpcOverrides.baseX;
               var4 = (KitDefinition.regions[var1] & 255) * 64 - class101.baseY;
               if(Client.isInInstance) {
                  var3 = 10;
                  var4 = 10;
               }

               var0 &= class150.method3283_base(var2, var3, var4);
            }
         }

         if(!var0) {
            Client.field559 = 2;
         } else {
            if(Client.field559 != 0) {
               LoginPacket.drawLoadingMessage_base("Loading - please wait." + "<br>" + " (" + 100 + "%" + ")", true);
            }

            class102.method2728_base();
            class36.scene.clear_base();

            for(var1 = 0; var1 < 4; ++var1) {
               Client.collisionMaps[var1].clear_base();
            }

            int var15;
            for(var1 = 0; var1 < 4; ++var1) {
               for(var15 = 0; var15 < 104; ++var15) {
                  for(var3 = 0; var3 < 104; ++var3) {
                     Tiles.Tiles_renderFlags[var1][var15][var3] = 0;
                  }
               }
            }

            class102.method2728_base();
            MidiPcmStream.method6133_base();
            var1 = WorldMapData_1.regionLandArchives.length;
            WorldMapSectionType.method4888_base();
            LoginScreenAnimation.method2513_base(true);
            int var16;
            if(!Client.isInInstance) {
               byte[] var5;
               for(var15 = 0; var15 < var1; ++var15) {
                  var3 = (KitDefinition.regions[var15] >> 8) * 64 - NpcOverrides.baseX;
                  var4 = (KitDefinition.regions[var15] & 255) * 64 - class101.baseY;
                  var5 = WorldMapData_1.regionLandArchives[var15];
                  if(var5 != null) {
                     class102.method2728_base();
                     class427.method7949(var5, var3, var4, DefaultsGroup.field4740 * 8 - 48, class223.field2367 * 8 - 48, Client.collisionMaps);
                  }
               }

               for(var15 = 0; var15 < var1; ++var15) {
                  var3 = (KitDefinition.regions[var15] >> 8) * 64 - NpcOverrides.baseX;
                  var4 = (KitDefinition.regions[var15] & 255) * 64 - class101.baseY;
                  var5 = WorldMapData_1.regionLandArchives[var15];
                  if(var5 == null && class223.field2367 < 800) {
                     class102.method2728_base();
                     MouseHandler.method670_base(var3, var4, 64, 64);
                  }
               }

               LoginScreenAnimation.method2513_base(true);

               for(var15 = 0; var15 < var1; ++var15) {
                  byte[] var17 = GrandExchangeEvent.regionMapArchives[var15];
                  if(var17 != null) {
                     var4 = (KitDefinition.regions[var15] >> 8) * 64 - NpcOverrides.baseX;
                     var16 = (KitDefinition.regions[var15] & 255) * 64 - class101.baseY;
                     class102.method2728_base();
                     class250.method4934(var17, var4, var16, class36.scene, Client.collisionMaps);
                  }
               }
            }

            int var6;
            int var7;
            int var8;
            if(Client.isInInstance) {
               int var9;
               int var10;
               int var11;
               for(var15 = 0; var15 < 4; ++var15) {
                  class102.method2728_base();

                  for(var3 = 0; var3 < 13; ++var3) {
                     for(var4 = 0; var4 < 13; ++var4) {
                        boolean var18 = false;
                        var6 = Client.instanceChunkTemplates[var15][var3][var4];
                        if(var6 != -1) {
                           var7 = var6 >> 24 & 3;
                           var8 = var6 >> 1 & 3;
                           var9 = var6 >> 14 & 1023;
                           var10 = var6 >> 3 & 2047;
                           var11 = (var9 / 8 << 8) + var10 / 8;

                           for(int var12 = 0; var12 < KitDefinition.regions.length; ++var12) {
                              if(KitDefinition.regions[var12] == var11 && WorldMapData_1.regionLandArchives[var12] != null) {
                                 int var13 = (var9 - var3) * 8;
                                 int var14 = (var10 - var4) * 8;
                                 GameEngine.method544(WorldMapData_1.regionLandArchives[var12], var15, var3 * 8, var4 * 8, var7, (var9 & 7) * 8, (var10 & 7) * 8, var8, var13, var14, Client.collisionMaps);
                                 var18 = true;
                                 break;
                              }
                           }
                        }

                        if(!var18) {
                           class230.method4458_base(var15, var3 * 8, var4 * 8);
                        }
                     }
                  }
               }

               for(var15 = 0; var15 < 13; ++var15) {
                  for(var3 = 0; var3 < 13; ++var3) {
                     var4 = Client.instanceChunkTemplates[0][var15][var3];
                     if(var4 == -1) {
                        MouseHandler.method670_base(var15 * 8, var3 * 8, 8, 8);
                     }
                  }
               }

               LoginScreenAnimation.method2513_base(true);

               for(var15 = 0; var15 < 4; ++var15) {
                  class102.method2728_base();

                  for(var3 = 0; var3 < 13; ++var3) {
                     for(var4 = 0; var4 < 13; ++var4) {
                        var16 = Client.instanceChunkTemplates[var15][var3][var4];
                        if(var16 != -1) {
                           var6 = var16 >> 24 & 3;
                           var7 = var16 >> 1 & 3;
                           var8 = var16 >> 14 & 1023;
                           var9 = var16 >> 3 & 2047;
                           var10 = (var8 / 8 << 8) + var9 / 8;

                           for(var11 = 0; var11 < KitDefinition.regions.length; ++var11) {
                              if(KitDefinition.regions[var11] == var10 && GrandExchangeEvent.regionMapArchives[var11] != null) {
                                 Tiles.method2294(GrandExchangeEvent.regionMapArchives[var11], var15, var3 * 8, var4 * 8, var6, (var8 & 7) * 8, (var9 & 7) * 8, var7, class36.scene, Client.collisionMaps);
                                 break;
                              }
                           }
                        }
                     }
                  }
               }
            }

            LoginScreenAnimation.method2513_base(true);
            class102.method2728_base();
            class156.method3394(class36.scene, Client.collisionMaps);
            LoginScreenAnimation.method2513_base(true);
            var15 = Tiles.Tiles_minPlane;
            if(var15 > ItemLayer.Client_plane) {
               var15 = ItemLayer.Client_plane;
            }

            if(var15 < ItemLayer.Client_plane - 1) {
               var15 = ItemLayer.Client_plane - 1;
            }

            if(Client.isLowDetail) {
               class36.scene.init_base(Tiles.Tiles_minPlane);
            } else {
               class36.scene.init_base(0);
            }

            for(var3 = 0; var3 < 104; ++var3) {
               for(var4 = 0; var4 < 104; ++var4) {
                  ClanSettings.updateItemPile_base(var3, var4);
               }
            }

            class102.method2728_base();
            class90.method2384_base();
            ObjectComposition.ObjectDefinition_cachedModelData.clear_base();
            PacketBufferNode var19;
            if(SpriteMask.client.hasFrame_base()) {
               var19 = class113.method2919(ClientPacket.DETECT_MODIFIED_CLIENT, Client.packetWriter.isaacCipher);
               var19.packetBuffer.writeInt_base(1057001181);
               Client.packetWriter.method2867(var19);
            }

            if(!Client.isInInstance) {
               var3 = (DefaultsGroup.field4740 - 6) / 8;
               var4 = (DefaultsGroup.field4740 + 6) / 8;
               var16 = (class223.field2367 - 6) / 8;
               var6 = (class223.field2367 + 6) / 8;

               for(var7 = var3 - 1; var7 <= var4 + 1; ++var7) {
                  for(var8 = var16 - 1; var8 <= var6 + 1; ++var8) {
                     if(var7 < var3 || var7 > var4 || var8 < var16 || var8 > var6) {
                        WorldMapSection0.archive9.loadRegionFromName_base("m" + var7 + "_" + var8);
                        WorldMapSection0.archive9.loadRegionFromName_base("l" + var7 + "_" + var8);
                     }
                  }
               }
            }

            WorldMapSection2.updateGameState_base(30);
            class102.method2728_base();
            class320.method6187_base();
            var19 = class113.method2919(ClientPacket.MAP_BUILD_COMPLETE, Client.packetWriter.isaacCipher);
            Client.packetWriter.method2867(var19);
            WorldMapRenderer.method4746_base();
         }
      }
   }
}
