package mapped;

import java.applet.Applet;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.ImageObserver;
import java.net.URL;
import net.runelite.api.events.FocusChanged;
import net.runelite.api.hooks.DrawCallbacks;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSGameEngine;

@ObfuscatedName("bm")
public abstract class GameEngine extends Applet implements Runnable, FocusListener, WindowListener, RSGameEngine {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lih;"
   )
   protected static TaskHandler taskHandler;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Lbm;"
   )
   static GameEngine gameEngine;
   @ObfuscatedName("ar")
   @ObfuscatedGetter(
      intValue = -827441371
   )
   static int GameEngine_redundantStartThreadCount;
   @ObfuscatedName("ao")
   @ObfuscatedGetter(
      longValue = 5534814896619431251L
   )
   static long stopTimeMs;
   @ObfuscatedName("ab")
   static boolean isKilled;
   @ObfuscatedName("aa")
   @ObfuscatedGetter(
      intValue = 624668735
   )
   static int gameCyclesToDo;
   @ObfuscatedName("ac")
   @ObfuscatedGetter(
      intValue = -964178105
   )
   static int cycleDurationMillis;
   @ObfuscatedName("al")
   @ObfuscatedGetter(
      intValue = -1128762955
   )
   static int fiveOrOne;
   @ObfuscatedName("az")
   @ObfuscatedGetter(
      intValue = 404525363
   )
   protected static int fps;
   @ObfuscatedName("ax")
   static long[] graphicsTickTimes;
   @ObfuscatedName("as")
   @ObfuscatedGetter(
      intValue = 747470065
   )
   static int field181;
   @ObfuscatedName("ay")
   static long[] clientTickTimes;
   @ObfuscatedName("ba")
   @ObfuscatedGetter(
      intValue = 1156670789
   )
   static int field186;
   @ObfuscatedName("by")
   static volatile boolean volatileFocus;
   @ObfuscatedName("bz")
   @ObfuscatedSignature(
      descriptor = "Laf;"
   )
   static KeyHandler keyHandler;
   @ObfuscatedName("bs")
   @ObfuscatedGetter(
      longValue = -2230762345531244515L
   )
   static long garbageCollectorLastCollectionTime;
   @ObfuscatedName("bx")
   @ObfuscatedGetter(
      longValue = -7548871332020518939L
   )
   static long garbageCollectorLastCheckTimeMs;
   @ObfuscatedName("au")
   boolean hasErrored;
   @ObfuscatedName("aj")
   @ObfuscatedGetter(
      intValue = 884082393
   )
   protected int contentWidth;
   @ObfuscatedName("am")
   @ObfuscatedGetter(
      intValue = 1979611029
   )
   protected int contentHeight;
   @ObfuscatedName("aq")
   @ObfuscatedGetter(
      intValue = -1557715643
   )
   int canvasX;
   @ObfuscatedName("ai")
   @ObfuscatedGetter(
      intValue = -2094233233
   )
   int canvasY;
   @ObfuscatedName("an")
   @ObfuscatedGetter(
      intValue = 862149103
   )
   int field187;
   @ObfuscatedName("ag")
   @ObfuscatedGetter(
      intValue = -1983051697
   )
   int field195;
   @ObfuscatedName("ad")
   @ObfuscatedGetter(
      intValue = 1783195025
   )
   int maxCanvasWidth;
   @ObfuscatedName("af")
   @ObfuscatedGetter(
      intValue = 1667963299
   )
   int maxCanvasHeight;
   @ObfuscatedName("be")
   protected boolean field170;
   @ObfuscatedName("bi")
   Frame frame;
   @ObfuscatedName("bv")
   java.awt.Canvas canvas;
   @ObfuscatedName("bf")
   volatile boolean fullRedraw;
   @ObfuscatedName("bm")
   boolean resizeCanvasNextFrame;
   @ObfuscatedName("bp")
   volatile boolean isCanvasInvalid;
   @ObfuscatedName("bw")
   @ObfuscatedGetter(
      longValue = -1360498837248928365L
   )
   volatile long field198;
   @ObfuscatedName("bo")
   @ObfuscatedSignature(
      descriptor = "Lae;"
   )
   MouseWheelHandler mouseWheelHandler;
   @ObfuscatedName("bt")
   Clipboard clipboard;
   @ObfuscatedName("bu")
   final EventQueue eventQueue;
   public Thread thread;

   static {
      gameEngine = null;
      GameEngine_redundantStartThreadCount = 0;
      stopTimeMs = 0L;
      isKilled = false;
      cycleDurationMillis = 20;
      fiveOrOne = 1;
      fps = 0;
      graphicsTickTimes = new long[32];
      clientTickTimes = new long[32];
      field186 = 500;
      volatileFocus = true;
      keyHandler = new KeyHandler();
      garbageCollectorLastCollectionTime = -1L;
      garbageCollectorLastCheckTimeMs = -1L;
   }

   protected GameEngine() {
      this.hasErrored = false;
      this.canvasX = 0;
      this.canvasY = 0;
      this.field170 = false;
      this.fullRedraw = true;
      this.resizeCanvasNextFrame = false;
      this.isCanvasInvalid = false;
      this.onReplaceCanvasNextFrameChanged(-1);
      this.field198 = 0L;
      EventQueue var1 = null;

      try {
         var1 = Toolkit.getDefaultToolkit().getSystemEventQueue();
      } catch (Throwable var3) {
         ;
      }

      this.eventQueue = var1;
      DevicePcmPlayerProvider var2 = new DevicePcmPlayerProvider();
      PcmPlayer.pcmPlayerProvider = var2;
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(IIB)V",
      garbageValue = "-49"
   )
   protected final void setMaxCanvasSize_base(int var1, int var2) {
      if(!SpriteMask.client.isStretchedEnabled() || !SpriteMask.client.isResized()) {
         this.copy$setMaxCanvasSize(var1, var2, (byte)-49);
      }
   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(Ljava/lang/Object;I)V",
      garbageValue = "-1974837267"
   )
   final void post_base(Object var1) {
      if(!SpriteMask.client.isGpu()) {
         this.copy$post(var1, -1974837267);
      }

      DrawCallbacks var2 = SpriteMask.client.getDrawCallbacks();
      if(var2 != null) {
         var2.draw(Client.viewportColor);
      }

   }

   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "(I)Lis;",
      garbageValue = "313158588"
   )
   protected class212 mouseWheel_base() {
      if(this.mouseWheelHandler == null) {
         this.mouseWheelHandler = new MouseWheelHandler();
         this.mouseWheelHandler.addTo_base(this.canvas);
      }

      return this.mouseWheelHandler;
   }

   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-2071259913"
   )
   protected void setUpClipboard_base() {
      this.clipboard = this.getToolkit().getSystemClipboard();
   }

   @ObfuscatedName("ac")
   @ObfuscatedSignature(
      descriptor = "(Ljava/lang/String;B)V",
      garbageValue = "-117"
   )
   protected void method501_base(String var1) {
      this.clipboard.setContents(new StringSelection(var1), (ClipboardOwner)null);
   }

   @ObfuscatedName("al")
   @ObfuscatedSignature(
      descriptor = "(B)Ljava/awt/datatransfer/Clipboard;",
      garbageValue = "88"
   )
   public Clipboard method498_base() {
      return this.clipboard;
   }

   @ObfuscatedName("az")
   @ObfuscatedSignature(
      descriptor = "(B)V",
      garbageValue = "57"
   )
   protected final void setUpKeyboard_base() {
      if(TaskHandler.javaVendor.toLowerCase().indexOf("microsoft") != -1) {
         class28.KeyHandler_keyCodes[186] = 57;
         class28.KeyHandler_keyCodes[187] = 27;
         class28.KeyHandler_keyCodes[188] = 71;
         class28.KeyHandler_keyCodes[189] = 26;
         class28.KeyHandler_keyCodes[190] = 72;
         class28.KeyHandler_keyCodes[191] = 73;
         class28.KeyHandler_keyCodes[192] = 58;
         class28.KeyHandler_keyCodes[219] = 42;
         class28.KeyHandler_keyCodes[220] = 74;
         class28.KeyHandler_keyCodes[221] = 43;
         class28.KeyHandler_keyCodes[222] = 59;
         class28.KeyHandler_keyCodes[223] = 28;
      } else {
         class28.KeyHandler_keyCodes[44] = 71;
         class28.KeyHandler_keyCodes[45] = 26;
         class28.KeyHandler_keyCodes[46] = 72;
         class28.KeyHandler_keyCodes[47] = 73;
         class28.KeyHandler_keyCodes[59] = 57;
         class28.KeyHandler_keyCodes[61] = 27;
         class28.KeyHandler_keyCodes[91] = 42;
         class28.KeyHandler_keyCodes[92] = 74;
         class28.KeyHandler_keyCodes[93] = 43;
         class28.KeyHandler_keyCodes[192] = 28;
         class28.KeyHandler_keyCodes[222] = 58;
         class28.KeyHandler_keyCodes[520] = 59;
      }

      keyHandler.method361_base(this.canvas);
   }

   @ObfuscatedName("av")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-379793759"
   )
   protected final void method567_base() {
      keyHandler.method358_base();
   }

   @ObfuscatedName("ax")
   @ObfuscatedSignature(
      descriptor = "(Lbi;II)V",
      garbageValue = "1492984668"
   )
   protected void method505_base(class29 var1, int var2) {
      keyHandler.method379_base(var1, var2);
   }

   @ObfuscatedName("as")
   @ObfuscatedSignature(
      descriptor = "(B)V",
      garbageValue = "-1"
   )
   protected final void method506_base() {
      java.awt.Canvas var1 = this.canvas;
      var1.addMouseListener(MouseHandler.MouseHandler_instance);
      var1.addMouseMotionListener(MouseHandler.MouseHandler_instance);
      var1.addFocusListener(MouseHandler.MouseHandler_instance);
   }

   @ObfuscatedName("ay")
   @ObfuscatedSignature(
      descriptor = "(S)V",
      garbageValue = "27503"
   )
   final void resizeCanvas_base() {
      if(SpriteMask.client.isStretchedEnabled()) {
         SpriteMask.client.invalidateStretching(false);
         if(SpriteMask.client.isResized()) {
            Dimension var1 = SpriteMask.client.getRealDimensions();
            this.setMaxCanvasWidth(var1.width);
            this.setMaxCanvasHeight(var1.height);
         }
      }

      this.copy$resizeCanvas((short)27503);
   }

   @ObfuscatedName("ak")
   @ObfuscatedSignature(
      descriptor = "(B)V",
      garbageValue = "101"
   )
   protected abstract void resizeGame_base();

   @ObfuscatedName("aj")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "103216408"
   )
   void clearBackground_base() {
      int var1 = this.canvasX;
      int var2 = this.canvasY;
      int var3 = this.contentWidth - Language.canvasWidth - var1;
      int var4 = this.contentHeight - class47.canvasHeight - var2;
      if(var1 > 0 || var3 > 0 || var2 > 0 || var4 > 0) {
         try {
            Container var5 = this.container_base();
            int var6 = 0;
            int var7 = 0;
            if(var5 == this.frame) {
               Insets var8 = this.frame.getInsets();
               var6 = var8.left;
               var7 = var8.top;
            }

            Graphics var10 = var5.getGraphics();
            var10.setColor(Color.black);
            if(var1 > 0) {
               var10.fillRect(var6, var7, var1, this.contentHeight);
            }

            if(var2 > 0) {
               var10.fillRect(var6, var7, this.contentWidth, var2);
            }

            if(var3 > 0) {
               var10.fillRect(var6 + this.contentWidth - var3, var7, var3, this.contentHeight);
            }

            if(var4 > 0) {
               var10.fillRect(var6, var7 + this.contentHeight - var4, this.contentWidth, var4);
            }
         } catch (Exception var9) {
            ;
         }
      }

   }

   @ObfuscatedName("am")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "1609680743"
   )
   final void replaceCanvas_base() {
      if(SpriteMask.client != null && SpriteMask.client.isGpu()) {
         this.setFullRedraw(false);
      } else {
         this.copy$replaceCanvas(1609680743);
      }
   }

   @ObfuscatedName("aq")
   @ObfuscatedSignature(
      descriptor = "(IIIII)V",
      garbageValue = "958927213"
   )
   protected final void startThread_base(int var1, int var2, int var3, int var4) {
      try {
         if(gameEngine != null) {
            ++GameEngine_redundantStartThreadCount;
            if(GameEngine_redundantStartThreadCount >= 3) {
               this.error_base("alreadyloaded");
               return;
            }

            this.getAppletContext().showDocument(this.getDocumentBase(), "_self");
            return;
         }

         gameEngine = this;
         Language.canvasWidth = var1;
         Client.canvasWidthChanged(-1);
         class47.canvasHeight = var2;
         Client.canvasHeightChanged(-1);
         class145.RunException_revision = var3;
         RunException.field5301 = var4;
         RunException.RunException_applet = this;
         if(taskHandler == null) {
            taskHandler = new TaskHandler();
         }

         taskHandler.method4190(this, 1);
      } catch (Exception var6) {
         GrandExchangeOfferWorldComparator.RunException_sendStackTrace_base((String)null, var6);
         this.error_base("crash");
      }

   }

   @ObfuscatedName("ai")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-1184721348"
   )
   final synchronized void addCanvas_base() {
      Container var1 = this.container_base();
      if(this.canvas != null) {
         this.canvas.removeFocusListener(this);
         var1.remove(this.canvas);
      }

      Language.canvasWidth = Math.max(var1.getWidth(), this.field187);
      Client.canvasWidthChanged(-1);
      class47.canvasHeight = Math.max(var1.getHeight(), this.field195);
      Client.canvasHeightChanged(-1);
      Insets var2;
      if(this.frame != null) {
         var2 = this.frame.getInsets();
         Language.canvasWidth -= var2.left + var2.right;
         Client.canvasWidthChanged(-1);
         class47.canvasHeight -= var2.top + var2.bottom;
         Client.canvasHeightChanged(-1);
      }

      this.canvas = new Canvas(this);
      var1.setBackground(Color.BLACK);
      var1.setLayout((LayoutManager)null);
      var1.add(this.canvas);
      this.canvas.setSize(Language.canvasWidth, class47.canvasHeight);
      this.canvas.setVisible(true);
      this.canvas.setBackground(Color.BLACK);
      if(var1 == this.frame) {
         var2 = this.frame.getInsets();
         this.canvas.setLocation(this.canvasX + var2.left, var2.top + this.canvasY);
      } else {
         this.canvas.setLocation(this.canvasX, this.canvasY);
      }

      this.canvas.addFocusListener(this);
      this.canvas.requestFocus();
      this.fullRedraw = true;
      if(class338.rasterProvider != null && Language.canvasWidth == class338.rasterProvider.width && class47.canvasHeight == class338.rasterProvider.height) {
         ((RasterProvider)class338.rasterProvider).setComponent_base(this.canvas);
         class338.rasterProvider.drawFull_base(0, 0);
      } else {
         class338.rasterProvider = new RasterProvider(Language.canvasWidth, class47.canvasHeight, this.canvas, this.field170);
      }

      this.isCanvasInvalid = false;
      this.onReplaceCanvasNextFrameChanged(-1);
      this.field198 = SpotAnimationDefinition.method3775_base();
   }

   @ObfuscatedName("aw")
   @ObfuscatedSignature(
      descriptor = "(ZI)V",
      garbageValue = "1876817454"
   )
   protected void method513_base(boolean var1) {
      if(this.field170 != var1) {
         this.field170 = var1;
         class338.rasterProvider.method9701_base(var1);
         class338.rasterProvider.apply_base();
      }

   }

   @ObfuscatedName("ae")
   @ObfuscatedSignature(
      descriptor = "(I)Z",
      garbageValue = "1264805931"
   )
   protected final boolean checkHost_base() {
      return true;
   }

   @ObfuscatedName("an")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-1012835334"
   )
   void clientTick_base() {
      long var1 = SpotAnimationDefinition.method3775_base();
      long var3 = clientTickTimes[class18.field88];
      clientTickTimes[class18.field88] = var1;
      class18.field88 = class18.field88 + 1 & 31;
      if(var3 != 0L && var1 > var3) {
         ;
      }

      synchronized(this) {
         class357.hasFocus = volatileFocus;
      }

      this.doCycle_base();
   }

   @ObfuscatedName("ag")
   @ObfuscatedSignature(
      descriptor = "(B)V",
      garbageValue = "1"
   )
   protected final void method517_base() {
      this.fullRedraw = true;
   }

   @ObfuscatedName("ad")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "1866404073"
   )
   void graphicsTick_base() {
      Container var1 = this.container_base();
      long var2 = SpotAnimationDefinition.method3775_base();
      long var4 = graphicsTickTimes[field181];
      graphicsTickTimes[field181] = var2;
      field181 = field181 + 1 & 31;
      if(var4 != 0L && var2 > var4) {
         int var6 = (int)(var2 - var4);
         fps = ((var6 >> 1) + 32000) / var6;
      }

      if(++field186 - 1 > 50) {
         field186 -= 50;
         this.fullRedraw = true;
         this.canvas.setSize(Language.canvasWidth, class47.canvasHeight);
         this.canvas.setVisible(true);
         if(var1 == this.frame) {
            Insets var7 = this.frame.getInsets();
            this.canvas.setLocation(var7.left + this.canvasX, this.canvasY + var7.top);
         } else {
            this.canvas.setLocation(this.canvasX, this.canvasY);
         }
      }

      if(this.isCanvasInvalid) {
         this.replaceCanvas_base();
      }

      this.method590_base();
      this.draw_base(this.fullRedraw);
      if(this.fullRedraw) {
         this.clearBackground_base();
      }

      this.fullRedraw = false;
   }

   @ObfuscatedName("af")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-992112857"
   )
   final void method590_base() {
      Bounds var1 = this.method555();
      if(this.contentWidth != var1.highX || this.contentHeight != var1.highY || this.resizeCanvasNextFrame) {
         this.resizeCanvas_base();
         this.resizeCanvasNextFrame = false;
      }

   }

   @ObfuscatedName("be")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-327763413"
   )
   final void method520_base() {
      this.resizeCanvasNextFrame = true;
   }

   @ObfuscatedName("bd")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-2127713911"
   )
   final synchronized void kill_base() {
      if(!isKilled) {
         isKilled = true;

         try {
            this.canvas.removeFocusListener(this);
         } catch (Exception var5) {
            ;
         }

         try {
            this.kill0_base();
         } catch (Exception var4) {
            ;
         }

         if(this.frame != null) {
            try {
               System.exit(0);
            } catch (Throwable var3) {
               ;
            }
         }

         if(taskHandler != null) {
            try {
               taskHandler.close_base();
            } catch (Exception var2) {
               ;
            }
         }

         this.vmethod1353_base();
      }
   }

   @ObfuscatedName("bm")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-550390769"
   )
   protected abstract void setUp_base();

   @ObfuscatedName("bp")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "564244601"
   )
   protected abstract void doCycle_base();

   @ObfuscatedName("bw")
   @ObfuscatedSignature(
      descriptor = "(ZI)V",
      garbageValue = "-851092167"
   )
   protected abstract void draw_base(boolean var1);

   @ObfuscatedName("bj")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "1863199463"
   )
   protected abstract void kill0_base();

   @ObfuscatedName("bn")
   @ObfuscatedSignature(
      descriptor = "(ILjava/lang/String;ZI)V",
      garbageValue = "1838069290"
   )
   protected final void drawInitial_base(int var1, String var2, boolean var3) {
      try {
         Graphics var4 = this.canvas.getGraphics();
         if(class28.fontHelvetica13 == null) {
            class28.fontHelvetica13 = new java.awt.Font("Helvetica", 1, 13);
            class6.loginScreenFontMetrics = this.canvas.getFontMetrics(class28.fontHelvetica13);
         }

         if(var3) {
            var4.setColor(Color.black);
            var4.fillRect(0, 0, Language.canvasWidth, class47.canvasHeight);
         }

         Color var5 = new Color(140, 17, 17);

         try {
            if(class151.field1682 == null) {
               class151.field1682 = this.canvas.createImage(304, 34);
            }

            Graphics var6 = class151.field1682.getGraphics();
            var6.setColor(var5);
            var6.drawRect(0, 0, 303, 33);
            var6.fillRect(2, 2, var1 * 3, 30);
            var6.setColor(Color.black);
            var6.drawRect(1, 1, 301, 31);
            var6.fillRect(var1 * 3 + 2, 2, 300 - var1 * 3, 30);
            var6.setFont(class28.fontHelvetica13);
            var6.setColor(Color.white);
            var6.drawString(var2, (304 - class6.loginScreenFontMetrics.stringWidth(var2)) / 2, 22);
            var4.drawImage(class151.field1682, Language.canvasWidth / 2 - 152, class47.canvasHeight / 2 - 18, (ImageObserver)null);
         } catch (Exception var9) {
            int var7 = Language.canvasWidth / 2 - 152;
            int var8 = class47.canvasHeight / 2 - 18;
            var4.setColor(var5);
            var4.drawRect(var7, var8, 303, 33);
            var4.fillRect(var7 + 2, var8 + 2, var1 * 3, 30);
            var4.setColor(Color.black);
            var4.drawRect(var7 + 1, var8 + 1, 301, 31);
            var4.fillRect(var7 + var1 * 3 + 2, var8 + 2, 300 - var1 * 3, 30);
            var4.setFont(class28.fontHelvetica13);
            var4.setColor(Color.white);
            var4.drawString(var2, var7 + (304 - class6.loginScreenFontMetrics.stringWidth(var2)) / 2, var8 + 22);
         }
      } catch (Exception var10) {
         this.canvas.repaint();
      }

   }

   @ObfuscatedName("bo")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "180057214"
   )
   protected final void method515_base() {
      class151.field1682 = null;
      class28.fontHelvetica13 = null;
      class6.loginScreenFontMetrics = null;
   }

   @ObfuscatedName("bt")
   @ObfuscatedSignature(
      descriptor = "(Ljava/lang/String;B)V",
      garbageValue = "5"
   )
   protected void error_base(String var1) {
      if(!this.hasErrored) {
         this.hasErrored = true;
         System.out.println("error_game_" + var1);

         try {
            this.getAppletContext().showDocument(new URL(this.getCodeBase(), "error_game_" + var1 + ".ws"), "_self");
         } catch (Exception var3) {
            ;
         }

      }
   }

   @ObfuscatedName("bu")
   @ObfuscatedSignature(
      descriptor = "(S)Ljava/awt/Container;",
      garbageValue = "-19045"
   )
   Container container_base() {
      return (Container)(this.frame != null?this.frame:this);
   }

   @ObfuscatedName("by")
   @ObfuscatedSignature(
      descriptor = "(B)Lrv;",
      garbageValue = "110"
   )
   Bounds method555() {
      Container var1 = this.container_base();
      int var2 = Math.max(var1.getWidth(), this.field187);
      int var3 = Math.max(var1.getHeight(), this.field195);
      if(this.frame != null) {
         Insets var4 = this.frame.getInsets();
         var2 -= var4.left + var4.right;
         var3 -= var4.bottom + var4.top;
      }

      return new Bounds(var2, var3);
   }

   @ObfuscatedName("bh")
   @ObfuscatedSignature(
      descriptor = "(B)Z",
      garbageValue = "50"
   )
   protected final boolean hasFrame_base() {
      return this.frame != null;
   }

   @ObfuscatedName("bc")
   @ObfuscatedSignature(
      descriptor = "(B)V",
      garbageValue = "-94"
   )
   protected abstract void vmethod1353_base();

   public final void destroy() {
      if(this == gameEngine && !isKilled) {
         stopTimeMs = SpotAnimationDefinition.method3775_base();
         class219.method4260_base(5000L);
         this.kill_base();
      }
   }

   public final synchronized void paint(Graphics var1) {
      if(this == gameEngine && !isKilled) {
         this.fullRedraw = true;
         if(SpotAnimationDefinition.method3775_base() - this.field198 > 1000L) {
            Rectangle var2 = var1.getClipBounds();
            if(var2 == null || var2.width >= Language.canvasWidth && var2.height >= class47.canvasHeight) {
               this.isCanvasInvalid = true;
               this.onReplaceCanvasNextFrameChanged(-1);
            }
         }

      }
   }

   public void onRun() {
      this.thread = Thread.currentThread();
      this.thread.setName("Client");
   }

   public void onFocusGained(FocusEvent var1) {
      FocusChanged var2 = new FocusChanged();
      var2.setFocused(true);
      SpriteMask.client.getCallbacks().post(var2);
   }

   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "1609680743"
   )
   public final void copy$replaceCanvas(int var1) {
      keyHandler.method362_base(this.canvas);
      class339.method6309_base(this.canvas);
      if(this.mouseWheelHandler != null) {
         this.mouseWheelHandler.method306_base(this.canvas);
      }

      this.addCanvas_base();
      keyHandler.method361_base(this.canvas);
      java.awt.Canvas var2 = this.canvas;
      var2.addMouseListener(MouseHandler.MouseHandler_instance);
      var2.addMouseMotionListener(MouseHandler.MouseHandler_instance);
      var2.addFocusListener(MouseHandler.MouseHandler_instance);
      if(this.mouseWheelHandler != null) {
         this.mouseWheelHandler.addTo_base(this.canvas);
      }

      this.method520_base();
   }

   public java.awt.Canvas getCanvas() {
      return this.canvas;
   }

   public boolean isClientThread() {
      return this.thread == Thread.currentThread();
   }

   @ObfuscatedSignature(
      descriptor = "(Ljava/lang/Object;I)V",
      garbageValue = "-1974837267"
   )
   public final void copy$post(Object var1, int var2) {
      if(this.eventQueue != null) {
         for(int var3 = 0; var3 < 50 && this.eventQueue.peekEvent() != null; ++var3) {
            class219.method4260_base(1L);
         }

         if(var1 != null) {
            this.eventQueue.postEvent(new ActionEvent(var1, 1001, "dummy"));
         }

      }
   }

   @ObfuscatedSignature(
      descriptor = "(IIB)V",
      garbageValue = "-49"
   )
   public final void copy$setMaxCanvasSize(int var1, int var2, byte var3) {
      if(this.maxCanvasWidth != var1 || var2 != this.maxCanvasHeight) {
         this.method520_base();
      }

      this.maxCanvasWidth = var1;
      this.maxCanvasHeight = var2;
   }

   @ObfuscatedSignature(
      descriptor = "(S)V",
      garbageValue = "27503"
   )
   public final void copy$resizeCanvas(short var1) {
      Container var2 = this.container_base();
      if(var2 != null) {
         Bounds var3 = this.method555();
         this.contentWidth = Math.max(var3.highX, this.field187);
         this.contentHeight = Math.max(var3.highY, this.field195);
         if(this.contentWidth <= 0) {
            this.contentWidth = 1;
         }

         if(this.contentHeight <= 0) {
            this.contentHeight = 1;
         }

         Language.canvasWidth = Math.min(this.contentWidth, this.maxCanvasWidth);
         Client.canvasWidthChanged(-1);
         class47.canvasHeight = Math.min(this.contentHeight, this.maxCanvasHeight);
         Client.canvasHeightChanged(-1);
         this.canvasX = (this.contentWidth - Language.canvasWidth) / 2;
         this.canvasY = 0;
         this.canvas.setSize(Language.canvasWidth, class47.canvasHeight);
         class338.rasterProvider = new RasterProvider(Language.canvasWidth, class47.canvasHeight, this.canvas, this.field170);
         if(var2 == this.frame) {
            Insets var4 = this.frame.getInsets();
            this.canvas.setLocation(var4.left + this.canvasX, this.canvasY + var4.top);
         } else {
            this.canvas.setLocation(this.canvasX, this.canvasY);
         }

         this.fullRedraw = true;
         this.resizeGame_base();
      }
   }

   public void setFullRedraw(boolean var1) {
      this.fullRedraw = var1;
   }

   public boolean isReplaceCanvasNextFrame() {
      return this.isCanvasInvalid;
   }

   public void setReplaceCanvasNextFrame(boolean var1) {
      this.isCanvasInvalid = var1;
   }

   public void setResizeCanvasNextFrame(boolean var1) {
      this.resizeCanvasNextFrame = var1;
   }

   public void setMaxCanvasWidth(int var1) {
      this.maxCanvasWidth = var1;
   }

   public void setMaxCanvasHeight(int var1) {
      this.maxCanvasHeight = var1;
   }

   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-1"
   )
   public void onReplaceCanvasNextFrameChanged(int var1) {
      if(SpriteMask.client != null && SpriteMask.client.isGpu() && this.isReplaceCanvasNextFrame()) {
         this.setReplaceCanvasNextFrame(false);
         this.setResizeCanvasNextFrame(true);
      }

   }

   public final void start() {
      if(this == gameEngine && !isKilled) {
         stopTimeMs = 0L;
      }
   }

   public final void stop() {
      if(this == gameEngine && !isKilled) {
         stopTimeMs = SpotAnimationDefinition.method3775_base() + 4000L;
      }
   }

   public final void focusGained(FocusEvent var1) {
      this.onFocusGained(var1);
      volatileFocus = true;
      this.fullRedraw = true;
   }

   public final void focusLost(FocusEvent var1) {
      volatileFocus = false;
   }

   public final void windowClosing(WindowEvent var1) {
      this.destroy();
   }

   public final void windowDeactivated(WindowEvent var1) {
   }

   public final void windowIconified(WindowEvent var1) {
   }

   public final void windowOpened(WindowEvent var1) {
   }

   public abstract void init();

   public final void windowActivated(WindowEvent var1) {
   }

   public final void windowDeiconified(WindowEvent var1) {
   }

   public final void windowClosed(WindowEvent var1) {
   }

   public void run() {
      this.onRun();

      try {
         if(TaskHandler.javaVendor != null) {
            String var1 = TaskHandler.javaVendor.toLowerCase();
            if(var1.indexOf("sun") != -1 || var1.indexOf("apple") != -1) {
               String var2 = TaskHandler.javaVersion;
               if(var2.equals("1.1") || var2.startsWith("1.1.") || var2.equals("1.2") || var2.startsWith("1.2.") || var2.equals("1.3") || var2.startsWith("1.3.") || var2.equals("1.4") || var2.startsWith("1.4.") || var2.equals("1.5") || var2.startsWith("1.5.") || var2.equals("1.6.0")) {
                  this.error_base("wrongjava");
                  return;
               }

               if(var2.startsWith("1.6.0_")) {
                  int var3;
                  for(var3 = 6; var3 < var2.length() && Player.isDigit_base(var2.charAt(var3)); ++var3) {
                     ;
                  }

                  String var4 = var2.substring(6, var3);
                  if(ClientPacket.isNumber_base(var4) && Huffman.method6840_base(var4) < 10) {
                     this.error_base("wrongjava");
                     return;
                  }
               }

               fiveOrOne = 5;
            }
         }

         this.setFocusCycleRoot(true);
         this.addCanvas_base();
         this.setUp_base();
         ArchiveDiskAction.clock = SoundSystem.method863();

         while(stopTimeMs == 0L || SpotAnimationDefinition.method3775_base() < stopTimeMs) {
            gameCyclesToDo = ArchiveDiskAction.clock.wait_base(cycleDurationMillis, fiveOrOne);

            for(int var5 = 0; var5 < gameCyclesToDo; ++var5) {
               this.clientTick_base();
            }

            this.graphicsTick_base();
            this.post_base(this.canvas);
         }
      } catch (Exception var6) {
         GrandExchangeOfferWorldComparator.RunException_sendStackTrace_base((String)null, var6);
         this.error_base("crash");
      }

      this.kill_base();
   }

   public final void update(Graphics var1) {
      this.paint(var1);
   }

   public Thread getClientThread() {
      return this.thread;
   }

   public boolean isResizeCanvasNextFrame() {
      return this.resizeCanvasNextFrame;
   }

   public void post(Object var1) {
      this.post_base(var1);
   }

   public void resizeCanvas() {
      this.resizeCanvas_base();
   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "([BIIIIIIIII[Liw;B)V",
      garbageValue = "48"
   )
   static final void method544(byte[] var0, int var1, int var2, int var3, int var4, int var5, int var6, int var7, int var8, int var9, CollisionMap[] var10) {
      int var12;
      for(int var11 = 0; var11 < 8; ++var11) {
         for(var12 = 0; var12 < 8; ++var12) {
            if(var11 + var2 > 0 && var11 + var2 < 103 && var3 + var12 > 0 && var3 + var12 < 103) {
               var10[var1].flags[var11 + var2][var12 + var3] &= -16777217;
            }
         }
      }

      Buffer var24 = new Buffer(var0);

      for(var12 = 0; var12 < 4; ++var12) {
         for(int var13 = 0; var13 < 64; ++var13) {
            for(int var14 = 0; var14 < 64; ++var14) {
               if(var12 == var4 && var13 >= var5 && var13 < var5 + 8 && var14 >= var6 && var14 < var6 + 8) {
                  int var15 = var2 + class31.method469_base(var13 & 7, var14 & 7, var7);
                  int var18 = var13 & 7;
                  int var19 = var14 & 7;
                  int var20 = var7 & 3;
                  int var17;
                  if(var20 == 0) {
                     var17 = var19;
                  } else if(var20 == 1) {
                     var17 = 7 - var18;
                  } else if(var20 == 2) {
                     var17 = 7 - var19;
                  } else {
                     var17 = var18;
                  }

                  int var21 = var17 + var3;
                  int var22 = (var13 & 7) + var8 + var2;
                  int var23 = var3 + (var14 & 7) + var9;
                  class14.method190(var24, var1, var15, var21, var22, var23, var7);
               } else {
                  class14.method190(var24, 0, -1, -1, 0, 0, 0);
               }
            }
         }
      }

   }
}
