package com.nelsonjrodrigues.pchud.net;

public class Extractor {

    private byte[] buffer;
    private int offset;
    private int length;

    public Extractor(byte[] buffer, int offset, int length) {
        this.buffer = buffer;
        this.offset = offset;
        this.length = length;
    }

    public int s8() {
        if (offset > length) {
            throw new ArrayIndexOutOfBoundsException();
        }
        return buffer[offset++];
    }

    public int u8() {
        if (offset > length) {
            throw new ArrayIndexOutOfBoundsException();
        }
        return Byte.toUnsignedInt(buffer[offset++]);
    }

    public int[] u8(int length) {
        int[] u8 = new int[length];
        for (int i = 0; i < length; i++) {
            u8[i] = u8();
        }
        return u8;
    }

    public int s16() {
        return u8() ^
               s8() << 8;
    }

    public int[] s16(int length) {
        int[] s16 = new int[length];
        for (int i = 0; i < length; i++) {
            s16[i] = s16();
        }
        return s16;
    }

    public int u16() {
        return u8() ^
               u8() << 8;
    }

    public int[] u16(int length) {
        int[] u16 = new int[length];
        for (int i = 0; i < length; i++) {
            u16[i] = u16();
        }
        return u16;
    }

    public float f32() {
        return Float.intBitsToFloat(u8() ^
                                    u8() << 8 ^
                                    u8() << 16 ^
                                    u8() << 24);
    }

    public float[] f32(int length) {
        float[] f32 = new float[length];
        for (int i = 0; i < length; i++) {
            f32[i] = f32();
        }
        return f32;
    }

    public String[] str64(int length) {
        String[] strings = new String[length];
        for(int i=0; i<length; i ++) {
            strings[i] = str64();
        }
        return strings;
    }
    public String str64() {
        return str(64);
    }
    public String str(int length) {
        char[] charArr = new char[length];
        for (int i = 0; i < length; i++) {
            charArr[i] = (char) u8();
        }
        return new String(charArr);
    }
}

@@ -34,16 +34,44 @@
 d.net;%0A%0A
+import java.util.Arrays;%0A%0A%0A%0A
 public c
@@ -1861,20 +1861,25 @@
  for
+ 
 (int i
-=
+ = 
 0; i
-%3C
+ %3C 
 leng
@@ -1883,17 +1883,16 @@
 ength; i
- 
 ++) %7B%0A  
@@ -1955,32 +1955,33 @@
  strings;%0A    %7D%0A
+%0A
     public Strin
@@ -2018,24 +2018,25 @@
 (64);%0A    %7D%0A
+%0A
     public S
@@ -2094,32 +2094,62 @@
 w char%5Blength%5D;%0A
+        int arrSize = length;%0A
         for (int
@@ -2213,33 +2213,138 @@
 ) u8();%0A        
-%7D
+    if (charArr%5Bi%5D == '%5C0') %7B%0A                arrSize = i;%0A                break;%0A            %7D%0A        %7D%0A
 %0A        return 
@@ -2361,16 +2361,28 @@
 (charArr
+, 0, arrSize
 );%0A    %7D
@@ -2382,10 +2382,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Fix strings in extractor