package mapped;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InvalidClassException;
import java.io.ObjectInputStream;
import java.io.OptionalDataException;
import java.io.StreamCorruptedException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.Reflection;

@ObfuscatedName("py")
public class class415 extends SongTask {
   @ObfuscatedSignature(
      descriptor = "(Lql;)V"
   )
   public class415(SongTask var1) {
      super(var1);
      super.field4552 = "StartSongTask";
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(I)Z",
      garbageValue = "-799935345"
   )
   public boolean vmethod7858_base() {
      Iterator var1 = class316.musicSongs.iterator();

      while(var1.hasNext()) {
         MusicSong var2 = (MusicSong)var1.next();
         if(var2 != null && !var2.field3524 && var2.midiPcmStream != null) {
            try {
               var2.midiPcmStream.method6059_base();
               var2.midiPcmStream.setPcmStreamVolume_base(0);
               if(var2.field3534 != null) {
                  var2.midiPcmStream.method6058(var2.field3534, var2.musicTrackBoolean);
               }

               var2.field3534 = null;
               var2.field3533 = null;
               var2.musicTrackArchive = null;
               var2.field3524 = true;
            } catch (Exception var4) {
               GrandExchangeOfferWorldComparator.RunException_sendStackTrace_base((String)null, var4);
               this.method7840_base(var4.getMessage());
               return true;
            }
         }
      }

      super.field4555 = true;
      return true;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "([BB)Ljava/lang/String;",
      garbageValue = "14"
   )
   public static String method7821_base(byte[] var0) {
      int var2 = var0.length;
      StringBuilder var3 = new StringBuilder();

      for(int var4 = 0; var4 < var2 + 0; var4 += 3) {
         int var5 = var0[var4] & 255;
         var3.append(class397.field4458[var5 >>> 2]);
         if(var4 < var2 - 1) {
            int var6 = var0[var4 + 1] & 255;
            var3.append(class397.field4458[(var5 & 3) << 4 | var6 >>> 4]);
            if(var4 < var2 - 2) {
               int var7 = var0[var4 + 2] & 255;
               var3.append(class397.field4458[(var6 & 15) << 2 | var7 >>> 6]).append(class397.field4458[var7 & 63]);
            } else {
               var3.append(class397.field4458[(var6 & 15) << 2]).append("=");
            }
         } else {
            var3.append(class397.field4458[(var5 & 3) << 4]).append("==");
         }
      }

      String var1 = var3.toString();
      return var1;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(Luo;I)V",
      garbageValue = "1697357932"
   )
   public static void method7826(PacketBuffer var0) {
      ReflectionCheck var1 = (ReflectionCheck)class36.reflectionChecks.method7290();
      if(var1 != null) {
         int var2 = var0.offset;
         var0.writeInt_base(var1.id);

         for(int var3 = 0; var3 < var1.size; ++var3) {
            if(var1.creationErrors[var3] != 0) {
               var0.writeByte_base(var1.creationErrors[var3]);
            } else {
               try {
                  int var4 = var1.operations[var3];
                  Field var5;
                  int var6;
                  if(var4 == 0) {
                     var5 = var1.fields[var3];
                     var6 = Reflection.getInt(var5, (Object)null);
                     var0.writeByte_base(0);
                     var0.writeInt_base(var6);
                  } else if(var4 == 1) {
                     var5 = var1.fields[var3];
                     Reflection.setInt(var5, (Object)null, var1.intReplaceValues[var3]);
                     var0.writeByte_base(0);
                  } else if(var4 == 2) {
                     var5 = var1.fields[var3];
                     var6 = var5.getModifiers();
                     var0.writeByte_base(0);
                     var0.writeInt_base(var6);
                  }

                  Method var25;
                  if(var4 != 3) {
                     if(var4 == 4) {
                        var25 = var1.methods[var3];
                        var6 = var25.getModifiers();
                        var0.writeByte_base(0);
                        var0.writeInt_base(var6);
                     }
                  } else {
                     var25 = var1.methods[var3];
                     byte[][] var10 = var1.arguments[var3];
                     Object[] var7 = new Object[var10.length];

                     for(int var8 = 0; var8 < var10.length; ++var8) {
                        ObjectInputStream var9 = new ObjectInputStream(new ByteArrayInputStream(var10[var8]));
                        var7[var8] = var9.readObject();
                     }

                     Object var11 = Reflection.invoke(var25, (Object)null, var7);
                     if(var11 == null) {
                        var0.writeByte_base(0);
                     } else if(var11 instanceof Number) {
                        var0.writeByte_base(1);
                        var0.writeLong_base(((Number)var11).longValue());
                     } else if(var11 instanceof String) {
                        var0.writeByte_base(2);
                        var0.writeStringCp1252NullTerminated_base((String)var11);
                     } else {
                        var0.writeByte_base(4);
                     }
                  }
               } catch (ClassNotFoundException var13) {
                  var0.writeByte_base(-10);
               } catch (InvalidClassException var14) {
                  var0.writeByte_base(-11);
               } catch (StreamCorruptedException var15) {
                  var0.writeByte_base(-12);
               } catch (OptionalDataException var16) {
                  var0.writeByte_base(-13);
               } catch (IllegalAccessException var17) {
                  var0.writeByte_base(-14);
               } catch (IllegalArgumentException var18) {
                  var0.writeByte_base(-15);
               } catch (InvocationTargetException var19) {
                  var0.writeByte_base(-16);
               } catch (SecurityException var20) {
                  var0.writeByte_base(-17);
               } catch (IOException var21) {
                  var0.writeByte_base(-18);
               } catch (NullPointerException var22) {
                  var0.writeByte_base(-19);
               } catch (Exception var23) {
                  var0.writeByte_base(-20);
               } catch (Throwable var24) {
                  var0.writeByte_base(-21);
               }
            }
         }

         var0.writeCrc_base(var2);
         var1.remove_base();
      }
   }
}
