package mapped;

import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSBuffer;
import net.runelite.rs.api.RSEvictingDualNodeHashTable;
import net.runelite.rs.api.RSVarbitComposition;

@ObfuscatedName("ht")
public class VarbitComposition extends DualNode implements RSVarbitComposition {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lol;"
   )
   public static AbstractArchive VarbitDefinition_archive;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Llk;"
   )
   static EvictingDualNodeHashTable VarbitDefinition_cached;
   @ObfuscatedName("au")
   static final int[] field2028;
   @ObfuscatedName("fy")
   @ObfuscatedSignature(
      descriptor = "Loh;"
   )
   static Archive archive13;
   @ObfuscatedName("ar")
   @ObfuscatedGetter(
      intValue = 1065217469
   )
   public int baseVar;
   @ObfuscatedName("ao")
   @ObfuscatedGetter(
      intValue = -578060217
   )
   public int startBit;
   @ObfuscatedName("ab")
   @ObfuscatedGetter(
      intValue = 645306173
   )
   public int endBit;

   static {
      VarbitDefinition_cached = new EvictingDualNodeHashTable(64);
      field2028 = new int[32];
      int var0 = 2;

      for(int var1 = 0; var1 < 32; ++var1) {
         field2028[var1] = var0 - 1;
         var0 += var0;
      }

   }

   VarbitComposition() {
      this.rl$init();
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(Luj;B)V",
      garbageValue = "-93"
   )
   void method3808(Buffer var1) {
      while(true) {
         int var2 = var1.readUnsignedByte_base();
         if(var2 == 0) {
            return;
         }

         this.method3803(var1, var2);
      }
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(Luj;II)V",
      garbageValue = "-30709508"
   )
   void method3803(Buffer var1, int var2) {
      if(var2 == 1) {
         this.baseVar = var1.readUnsignedShort_base();
         this.startBit = var1.readUnsignedByte_base();
         this.endBit = var1.readUnsignedByte_base();
      }

   }

   public final void rl$init() {
      RSEvictingDualNodeHashTable var1 = SpriteMask.client.getVarbitCache();
      var1.resize(256);
   }

   public int getIndex() {
      return this.baseVar;
   }

   public int getLeastSignificantBit() {
      return this.startBit;
   }

   public int getMostSignificantBit() {
      return this.endBit;
   }

   public void decode(RSBuffer var1) {
      this.method3808((Buffer)var1);
   }
}
