commit 110a5872c52bcbbd49356908d452be23286ac9b4 Author: woahscam Date: Tue Nov 8 12:59:53 2022 -0500 Initial Push diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..95e52b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.idea +/bin +.class \ No newline at end of file diff --git a/Frosty.iml b/Frosty.iml new file mode 100644 index 0000000..983e531 --- /dev/null +++ b/Frosty.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/alex/io/InputStream.java b/src/com/alex/io/InputStream.java new file mode 100644 index 0000000..3c9090f --- /dev/null +++ b/src/com/alex/io/InputStream.java @@ -0,0 +1,255 @@ +package com.alex.io; + +import com.alex.io.Stream; + +public final class InputStream extends Stream { + private static final int[] BIT_MASK = new int[]{0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, '\uffff', 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, Integer.MAX_VALUE, -1}; + + public void initBitAccess() { + this.bitPosition = this.offset * 8; + } + + public void finishBitAccess() { + this.offset = (7 + this.bitPosition) / 8; + } + + public int readBits(int bitOffset) { + int bytePos = this.bitPosition >> 1779819011; + int i_8_ = -(7 & this.bitPosition) + 8; + this.bitPosition += bitOffset; + + int value; + for(value = 0; ~bitOffset < ~i_8_; i_8_ = 8) { + value += (BIT_MASK[i_8_] & this.buffer[bytePos++]) << -i_8_ + bitOffset; + bitOffset -= i_8_; + } + + if(~i_8_ == ~bitOffset) { + value += this.buffer[bytePos] & BIT_MASK[i_8_]; + } else { + value += this.buffer[bytePos] >> -bitOffset + i_8_ & BIT_MASK[bitOffset]; + } + + return value; + } + + public InputStream(int capacity) { + this.buffer = new byte[capacity]; + } + + public InputStream(byte[] buffer) { + this.buffer = buffer; + this.length = buffer.length; + } + + public void checkCapacity(int length) { + if(this.offset + length >= this.buffer.length) { + byte[] newBuffer = new byte[(this.offset + length) * 2]; + System.arraycopy(this.buffer, 0, newBuffer, 0, this.buffer.length); + this.buffer = newBuffer; + } + + } + + public void skip(int length) { + this.offset += length; + } + + public void setLength(int length) { + this.length = length; + } + + public void setOffset(int offset) { + this.offset = offset; + } + + public int getRemaining() { + return this.offset < this.length?this.length - this.offset:0; + } + + public void addBytes(byte[] b, int offset, int length) { + this.checkCapacity(length - offset); + System.arraycopy(b, offset, this.buffer, this.offset, length); + this.length += length - offset; + } + + public int readPacket() { + return this.readUnsignedByte(); + } + + public int readByte() { + return this.getRemaining() > 0?this.buffer[this.offset++]:0; + } + + public void readBytes(byte[] buffer, int off, int len) { + for(int k = off; k < len + off; ++k) { + buffer[k] = (byte)this.readByte(); + } + + } + + public void readBytes(byte[] buffer) { + this.readBytes(buffer, 0, buffer.length); + } + + public int readSmart2() { + int i = 0; + + int i_33_; + for(i_33_ = this.readUnsignedSmart(); ~i_33_ == -32768; i += 32767) { + i_33_ = this.readUnsignedSmart(); + } + + i += i_33_; + return i; + } + + public int readUnsignedByte() { + return this.readByte() & 255; + } + + public int readByte128() { + return (byte)(this.readByte() - 128); + } + + public int readByteC() { + return (byte)(-this.readByte()); + } + + public int read128Byte() { + return (byte)(128 - this.readByte()); + } + + public int readUnsignedByte128() { + return this.readUnsignedByte() - 128 & 255; + } + + public int readUnsignedByteC() { + return -this.readUnsignedByte() & 255; + } + + public int readUnsigned128Byte() { + return 128 - this.readUnsignedByte() & 255; + } + + public int readShortLE() { + int i = this.readUnsignedByte() + (this.readUnsignedByte() << 8); + if(i > 32767) { + i -= 65536; + } + + return i; + } + + public int readShort128() { + int i = (this.readUnsignedByte() << 8) + (this.readByte() - 128 & 255); + if(i > 32767) { + i -= 65536; + } + + return i; + } + + public int readShortLE128() { + int i = (this.readByte() - 128 & 255) + (this.readUnsignedByte() << 8); + if(i > 32767) { + i -= 65536; + } + + return i; + } + + public int read128ShortLE() { + int i = (128 - this.readByte() & 255) + (this.readUnsignedByte() << 8); + if(i > 32767) { + i -= 65536; + } + + return i; + } + + public int readShort() { + int i = (this.readUnsignedByte() << 8) + this.readUnsignedByte(); + if(i > 32767) { + i -= 65536; + } + + return i; + } + + public int readUnsignedShortLE() { + return this.readUnsignedByte() + (this.readUnsignedByte() << 8); + } + + public int readUnsignedShort() { + return (this.readUnsignedByte() << 8) + this.readUnsignedByte(); + } + + public int readUnsignedShort128() { + return (this.readUnsignedByte() << 8) + (this.readByte() - 128 & 255); + } + + public int readUnsignedShortLE128() { + return (this.readByte() - 128 & 255) + (this.readUnsignedByte() << 8); + } + + public int readInt() { + return (this.readUnsignedByte() << 24) + (this.readUnsignedByte() << 16) + (this.readUnsignedByte() << 8) + this.readUnsignedByte(); + } + + public int read24BitInt() { + return (this.readUnsignedByte() << 16) + (this.readUnsignedByte() << 8) + this.readUnsignedByte(); + } + + public int readIntV1() { + return (this.readUnsignedByte() << 8) + this.readUnsignedByte() + (this.readUnsignedByte() << 24) + (this.readUnsignedByte() << 16); + } + + public int readIntV2() { + return (this.readUnsignedByte() << 16) + (this.readUnsignedByte() << 24) + this.readUnsignedByte() + (this.readUnsignedByte() << 8); + } + + public int readIntLE() { + return this.readUnsignedByte() + (this.readUnsignedByte() << 8) + (this.readUnsignedByte() << 16) + (this.readUnsignedByte() << 24); + } + + public long readLong() { + long l = (long)this.readInt() & 4294967295L; + long l1 = (long)this.readInt() & 4294967295L; + return (l << 32) + l1; + } + + public String readString() { + String s; + int b; + for(s = ""; (b = this.readByte()) != 0; s = s + (char)b) { + } + + return s; + } + + public String readJagString() { + this.readByte(); + + String s; + int b; + for(s = ""; (b = this.readByte()) != 0; s = s + (char)b) { + } + + return s; + } + + public int readBigSmart() { + if(~this.buffer[this.offset] <= -1) { + int value = this.readUnsignedShort(); + return value == 32767?-1:value; + } else { + return this.readInt() & Integer.MAX_VALUE; + } + } + + public int readUnsignedSmart() { + int i = 255 & this.buffer[this.offset]; + return i >= 128?-32768 + this.readUnsignedShort():this.readUnsignedByte(); + } +} diff --git a/src/com/alex/io/OutputStream.java b/src/com/alex/io/OutputStream.java new file mode 100644 index 0000000..aa04c8c --- /dev/null +++ b/src/com/alex/io/OutputStream.java @@ -0,0 +1,331 @@ +package com.alex.io; + +import com.alex.io.Stream; + +import java.math.BigInteger; + +public final class OutputStream extends Stream { + private static final int[] BIT_MASK = new int[32]; + private int opcodeStart = 0; + + static { + for(int i = 0; i < 32; ++i) { + BIT_MASK[i] = (1 << i) - 1; + } + + } + + public OutputStream(int capacity) { + this.setBuffer(new byte[capacity]); + } + + public OutputStream() { + this.setBuffer(new byte[16]); + } + + public OutputStream(byte[] buffer) { + this.setBuffer(buffer); + this.offset = buffer.length; + this.length = buffer.length; + } + + public OutputStream(int[] buffer) { + this.setBuffer(new byte[buffer.length]); + int[] arr$ = buffer; + int len$ = buffer.length; + + for(int i$ = 0; i$ < len$; ++i$) { + int value = arr$[i$]; + this.writeByte(value); + } + + } + + public void checkCapacityPosition(int position) { + if(position >= this.getBuffer().length) { + byte[] newBuffer = new byte[position + 16]; + System.arraycopy(this.getBuffer(), 0, newBuffer, 0, this.getBuffer().length); + this.setBuffer(newBuffer); + } + + } + + public void skip(int length) { + this.setOffset(this.getOffset() + length); + } + + public void setOffset(int offset) { + this.offset = offset; + } + + public void writeBytes(byte[] b, int offset, int length) { + this.checkCapacityPosition(this.getOffset() + length - offset); + System.arraycopy(b, offset, this.getBuffer(), this.getOffset(), length); + this.setOffset(this.getOffset() + (length - offset)); + } + + public void writeBytes(byte[] b) { + byte offset = 0; + int length = b.length; + this.checkCapacityPosition(this.getOffset() + length - offset); + System.arraycopy(b, offset, this.getBuffer(), this.getOffset(), length); + this.setOffset(this.getOffset() + (length - offset)); + } + + public void addBytes128(byte[] data, int offset, int len) { + for(int k = offset; k < len; ++k) { + this.writeByte((byte)(data[k] + 128)); + } + + } + + public void addBytesS(byte[] data, int offset, int len) { + for(int k = offset; k < len; ++k) { + this.writeByte((byte)(-128 + data[k])); + } + + } + + public void addBytes_Reverse(byte[] data, int offset, int len) { + for(int i = len - 1; i >= 0; --i) { + this.writeByte(data[i]); + } + + } + + public void addBytes_Reverse128(byte[] data, int offset, int len) { + for(int i = len - 1; i >= 0; --i) { + this.writeByte((byte)(data[i] + 128)); + } + + } + + public void writeByte(int i) { + this.writeByte(i, this.offset++); + } + + public void writeNegativeByte(int i) { + this.writeByte(-i, this.offset++); + } + + public void writeByte(int i, int position) { + this.checkCapacityPosition(position); + this.getBuffer()[position] = (byte)i; + } + + public void writeByte128(int i) { + this.writeByte(i + 128); + } + + public void writeByteC(int i) { + this.writeByte(-i); + } + + public void write3Byte(int i) { + this.writeByte(i >> 16); + this.writeByte(i >> 8); + this.writeByte(i); + } + + public void write128Byte(int i) { + this.writeByte(128 - i); + } + + public void writeShortLE128(int i) { + this.writeByte(i + 128); + this.writeByte(i >> 8); + } + + public void writeShort128(int i) { + this.writeByte(i >> 8); + this.writeByte(i + 128); + } + + public void writeBigSmart(int i) { + //if(i >= 32767 && i >= 0) { + if(i >= 52767 && i >= 0) { + this.writeInt(i - Integer.MAX_VALUE - 1); + } else { + this.writeShort(i >= 0?i:52767); + //this.writeShort(i >= 0?i:32767); + } + + } + + public void writeSmart(int i) { + if(i >= 128) { + this.writeShort(i); + } else { + this.writeByte(i); + } + + } + + public void writeShort(int i) { + this.writeByte(i >> 8); + this.writeByte(i); + } + + public void writeShortLE(int i) { + this.writeByte(i); + this.writeByte(i >> 8); + } + + public void write24BitInt(int i) { + this.writeByte(i >> 16); + this.writeByte(i >> 8); + this.writeByte(i); + } + + public void writeInt(int i) { + this.writeByte(i >> 24); + this.writeByte(i >> 16); + this.writeByte(i >> 8); + this.writeByte(i); + } + + public void writeIntV1(int i) { + this.writeByte(i >> 8); + this.writeByte(i); + this.writeByte(i >> 24); + this.writeByte(i >> 16); + } + + public void writeIntV2(int i) { + this.writeByte(i >> 16); + this.writeByte(i >> 24); + this.writeByte(i); + this.writeByte(i >> 8); + } + + public void writeIntLE(int i) { + this.writeByte(i); + this.writeByte(i >> 8); + this.writeByte(i >> 16); + this.writeByte(i >> 24); + } + + public void writeLong(long l) { + this.writeByte((int)(l >> 56)); + this.writeByte((int)(l >> 48)); + this.writeByte((int)(l >> 40)); + this.writeByte((int)(l >> 32)); + this.writeByte((int)(l >> 24)); + this.writeByte((int)(l >> 16)); + this.writeByte((int)(l >> 8)); + this.writeByte((int)l); + } + + public void writePSmarts(int i) { + if(i < 128) { + this.writeByte(i); + } else if (i < 32768) { + this.writeShort(32768 + i); + }else { + System.out.println("Error psmarts out of range:"); + } + + } + + public void writeString(String s) { + this.checkCapacityPosition(this.getOffset() + s.length() + 1); + System.arraycopy(s.getBytes(), 0, this.getBuffer(), this.getOffset(), s.length()); + this.setOffset(this.getOffset() + s.length()); + this.writeByte(0); + } + + public void writeGJString(String s) { + this.writeByte(0); + this.writeString(s); + } + + public void putGJString3(String s) { + this.writeByte(0); + this.writeString(s); + this.writeByte(0); + } + + public void writePacket(int id) { + this.writeByte(id); + } + + public void writePacketVarByte(int id) { + this.writePacket(id); + this.writeByte(0); + this.opcodeStart = this.getOffset() - 1; + } + + public void writePacketVarShort(int id) { + this.writePacket(id); + this.writeShort(0); + this.opcodeStart = this.getOffset() - 2; + } + + public void endPacketVarByte() { + this.writeByte(this.getOffset() - (this.opcodeStart + 2) + 1, this.opcodeStart); + } + + public void endPacketVarShort() { + int size = this.getOffset() - (this.opcodeStart + 2); + this.writeByte(size >> 8, this.opcodeStart++); + this.writeByte(size, this.opcodeStart); + } + + public void initBitAccess() { + this.bitPosition = this.getOffset() * 8; + } + + public void finishBitAccess() { + this.setOffset((this.bitPosition + 7) / 8); + } + + public int getBitPos(int i) { + return 8 * i - this.bitPosition; + } + + public void writeBits(int numBits, int value) { + int bytePos = this.bitPosition >> 3; + int bitOffset = 8 - (this.bitPosition & 7); + + byte[] var10000; + for(this.bitPosition += numBits; numBits > bitOffset; bitOffset = 8) { + this.checkCapacityPosition(bytePos); + var10000 = this.getBuffer(); + var10000[bytePos] = (byte)(var10000[bytePos] & ~BIT_MASK[bitOffset]); + var10000 = this.getBuffer(); + int var10001 = bytePos++; + var10000[var10001] = (byte)(var10000[var10001] | value >> numBits - bitOffset & BIT_MASK[bitOffset]); + numBits -= bitOffset; + } + + this.checkCapacityPosition(bytePos); + if(numBits == bitOffset) { + var10000 = this.getBuffer(); + var10000[bytePos] = (byte)(var10000[bytePos] & ~BIT_MASK[bitOffset]); + var10000 = this.getBuffer(); + var10000[bytePos] = (byte)(var10000[bytePos] | value & BIT_MASK[bitOffset]); + } else { + var10000 = this.getBuffer(); + var10000[bytePos] = (byte)(var10000[bytePos] & ~(BIT_MASK[numBits] << bitOffset - numBits)); + var10000 = this.getBuffer(); + var10000[bytePos] = (byte)(var10000[bytePos] | (value & BIT_MASK[numBits]) << bitOffset - numBits); + } + + } + + public void setBuffer(byte[] buffer) { + this.buffer = buffer; + } + + public void rsaEncode(BigInteger key, BigInteger modulus) { + int length = this.offset; + this.offset = 0; + byte[] data = new byte[length]; + this.getBytes(data, 0, length); + BigInteger biginteger2 = new BigInteger(data); + BigInteger biginteger3 = biginteger2.modPow(key, modulus); + byte[] out = biginteger3.toByteArray(); + this.offset = 0; + this.writeBytes(out, 0, out.length); + } +} diff --git a/src/com/alex/io/Stream.java b/src/com/alex/io/Stream.java new file mode 100644 index 0000000..4f5367f --- /dev/null +++ b/src/com/alex/io/Stream.java @@ -0,0 +1,91 @@ +package com.alex.io; + +public abstract class Stream { + protected int offset; + protected int length; + protected byte[] buffer; + protected int bitPosition; + + public int getLength() { + return this.length; + } + + public byte[] getBuffer() { + return this.buffer; + } + + public int getOffset() { + return this.offset; + } + + public void decodeXTEA(int[] keys) { + this.decodeXTEA(keys, 5, this.length); + } + + public void decodeXTEA(int[] keys, int start, int end) { + int l = this.offset; + this.offset = start; + int i1 = (end - start) / 8; + + for(int j1 = 0; j1 < i1; ++j1) { + int k1 = this.readInt(); + int l1 = this.readInt(); + int sum = -957401312; + int delta = -1640531527; + + for(int k2 = 32; k2-- > 0; k1 -= (l1 >>> 5 ^ l1 << 4) + l1 ^ keys[sum & 3] + sum) { + l1 -= keys[(sum & 7300) >>> 11] + sum ^ (k1 >>> 5 ^ k1 << 4) + k1; + sum -= delta; + } + + this.offset -= 8; + this.writeInt(k1); + this.writeInt(l1); + } + + this.offset = l; + } + + public final void encodeXTEA(int[] keys, int start, int end) { + int o = this.offset; + int j = (end - start) / 8; + this.offset = start; + + for(int k = 0; k < j; ++k) { + int l = this.readInt(); + int i1 = this.readInt(); + int sum = 0; + int delta = -1640531527; + + for(int l1 = 32; l1-- > 0; i1 += l + (l >>> 5 ^ l << 4) ^ keys[(7916 & sum) >>> 11] + sum) { + l += sum + keys[3 & sum] ^ i1 + (i1 >>> 5 ^ i1 << 4); + sum += delta; + } + + this.offset -= 8; + this.writeInt(l); + this.writeInt(i1); + } + + this.offset = o; + } + + private final int readInt() { + this.offset += 4; + return ((255 & this.buffer[-3 + this.offset]) << 16) + ((255 & this.buffer[-4 + this.offset]) << 24) + ((this.buffer[-2 + this.offset] & 255) << 8) + (this.buffer[-1 + this.offset] & 255); + } + + public void writeInt(int value) { + this.buffer[this.offset++] = (byte)(value >> 24); + this.buffer[this.offset++] = (byte)(value >> 16); + this.buffer[this.offset++] = (byte)(value >> 8); + this.buffer[this.offset++] = (byte)value; + } + + public final void getBytes(byte[] data, int off, int len) { + for(int k = off; k < len + off; ++k) { + data[k] = this.buffer[this.offset++]; + } + + } +} diff --git a/src/com/alex/loaders/animations/AnimationDefinitions.java b/src/com/alex/loaders/animations/AnimationDefinitions.java new file mode 100644 index 0000000..4b8ed90 --- /dev/null +++ b/src/com/alex/loaders/animations/AnimationDefinitions.java @@ -0,0 +1,281 @@ +package com.alex.loaders.animations; + +import com.alex.io.InputStream; +import com.alex.store.Store; + +import java.io.IOException; +import java.io.PrintStream; +import java.util.concurrent.ConcurrentHashMap; + +public class AnimationDefinitions { + public static Store cache; + public static int id; + public int loopCycles = 99; + public int anInt2137; + public static int[] frames; + public int anInt2140 = -1; + public boolean aBoolean2141 = false; + public int priority = 5; + public int leftHandEquip = -1; + public int rightHandEquip = -1; + public int anInt2145; + public int[][] handledSounds; + public boolean[] aBooleanArray2149; + public int[] anIntArray2151; + public boolean aBoolean2152 = false; + public static int[] delays; + public int anInt2155 = 2; + public boolean aBoolean2158 = false; + public boolean aBoolean2159 = false; + public int anInt2162 = -1; + public int loopDelay = -1; + public int[] soundMinDelay; + public int[] soundMaxDelay; + public int[] anIntArray1362; + public boolean effect2Sound; + private static final ConcurrentHashMap animDefs = new ConcurrentHashMap(); + + public static void main(String[] args) throws IOException { + cache = new Store("C:/Users/yvonne � christer/Dropbox/Source/data/562cache/"); + + label55: + for(int i = 0; i < 1; ++i) { + System.out.println("Emote ID: " + i); + int k = 0; + + while(true) { + getAnimationDefinitions(i); + PrintStream var10000; + StringBuilder var10001; + if(k >= delays.length) { + k = 0; + + while(true) { + getAnimationDefinitions(i); + if(k >= frames.length) { + System.out.println("loopDelay = " + getAnimationDefinitions(i).loopDelay); + System.out.println("leftHandEquip = " + getAnimationDefinitions(i).leftHandEquip); + System.out.println("priority = " + getAnimationDefinitions(i).priority); + System.out.println("rightHandEquip = " + getAnimationDefinitions(i).rightHandEquip); + System.out.println("loopCycles = " + getAnimationDefinitions(i).loopCycles); + System.out.println("anInt2140 = " + getAnimationDefinitions(i).anInt2140); + System.out.println("anInt2162 = " + getAnimationDefinitions(i).anInt2162); + System.out.println("anInt2155 = " + getAnimationDefinitions(i).anInt2155); + System.out.println("anInt2145 = " + getAnimationDefinitions(i).anInt2145); + + for(k = 0; k < getAnimationDefinitions(i).anIntArray2151.length; ++k) { + System.out.println("anIntArray2151[" + k + "] = " + getAnimationDefinitions(i).anIntArray2151[k]); + } + + for(k = 0; k < getAnimationDefinitions(i).aBooleanArray2149.length; ++k) { + System.out.println("aBooleanArray2149[" + k + "] = " + getAnimationDefinitions(i).aBooleanArray2149[k]); + } + + System.out.println("aBoolean2152 = " + getAnimationDefinitions(i).aBoolean2152); + + for(k = 0; k < getAnimationDefinitions(i).anIntArray1362.length; ++k) { + System.out.println("anIntArray1362[" + k + "] = " + getAnimationDefinitions(i).anIntArray1362[k]); + } + continue label55; + } + + var10000 = System.out; + var10001 = (new StringBuilder()).append("frames[").append(k).append("] = "); + getAnimationDefinitions(i); + var10000.println(var10001.append(frames[k])); + ++k; + } + } + + var10000 = System.out; + var10001 = (new StringBuilder()).append("delays[").append(k).append("] = "); + getAnimationDefinitions(i); + var10000.println(var10001.append(delays[k])); + ++k; + } + } + + } + + public static final AnimationDefinitions getAnimationDefinitions(int emoteId) { + try { + AnimationDefinitions var3 = (AnimationDefinitions)animDefs.get(Integer.valueOf(emoteId)); + if(var3 != null) { + return var3; + } else { + byte[] data = cache.getIndexes()[20].getFile(emoteId >>> 7, emoteId & 127); + var3 = new AnimationDefinitions(); + if(data != null) { + var3.readValueLoop(new InputStream(data)); + } + + var3.method2394(); + animDefs.put(Integer.valueOf(emoteId), var3); + id = emoteId; + return var3; + } + } catch (Throwable var31) { + return null; + } + } + + private void readValueLoop(InputStream stream) { + while(true) { + int opcode = stream.readUnsignedByte(); + if(opcode == 0) { + return; + } + + this.readValues(stream, opcode); + } + } + + public int getEmoteTime() { + if(delays == null) { + return 0; + } else { + int ms = 0; + int[] arr$ = delays; + int len$ = arr$.length; + + for(int i$ = 0; i$ < len$; ++i$) { + int i = arr$[i$]; + ms += i; + } + + return ms * 30; + } + } + + public int getEmoteGameTickets() { + return this.getEmoteTime() / 1000; + } + + private void readValues(InputStream stream, int opcode) { + int index; + int i_21_; + if(opcode == 1) { + index = stream.readUnsignedShort(); + delays = new int[index]; + + for(i_21_ = 0; ~index < ~i_21_; ++i_21_) { + delays[i_21_] = stream.readUnsignedShort(); + } + + frames = new int[index]; + + for(i_21_ = 0; ~i_21_ > ~index; ++i_21_) { + frames[i_21_] = stream.readUnsignedShort(); + } + + for(i_21_ = 0; i_21_ < index; ++i_21_) { + frames[i_21_] += stream.readUnsignedShort() << 16; + } + } else if(opcode == 2) { + this.loopDelay = stream.readUnsignedShort(); + } else if(opcode == 3) { + this.aBooleanArray2149 = new boolean[256]; + index = stream.readUnsignedByte(); + + for(i_21_ = 0; i_21_ < index; ++i_21_) { + this.aBooleanArray2149[stream.readUnsignedByte()] = true; + } + } else if(opcode == 4) { + this.aBoolean2152 = true; + } else if(opcode == 5) { + this.priority = stream.readUnsignedByte(); + } else if(opcode == 6) { + this.rightHandEquip = stream.readUnsignedShort(); + } else if(opcode == 7) { + this.leftHandEquip = stream.readUnsignedShort(); + } else if(opcode == 8) { + this.loopCycles = stream.readUnsignedByte(); + } else if(opcode == 9) { + this.anInt2140 = stream.readUnsignedByte(); + } else if(opcode == 10) { + this.anInt2162 = stream.readUnsignedByte(); + } else if(opcode == 11) { + this.anInt2155 = stream.readUnsignedByte(); + } else if(opcode == 12) { + index = stream.readUnsignedByte(); + this.anIntArray2151 = new int[index]; + + for(i_21_ = 0; ~i_21_ > ~index; ++i_21_) { + this.anIntArray2151[i_21_] = stream.readUnsignedShort(); + } + + for(i_21_ = 0; index > i_21_; ++i_21_) { + this.anIntArray2151[i_21_] += stream.readUnsignedShort() << 16; + } + } else if(opcode == 13) { + index = stream.readUnsignedShort(); + this.handledSounds = new int[index][]; + + for(i_21_ = 0; i_21_ < index; ++i_21_) { + int i_22_ = stream.readUnsignedByte(); + if(~i_22_ < -1) { + this.handledSounds[i_21_] = new int[i_22_]; + this.handledSounds[i_21_][0] = stream.read24BitInt(); + + for(int i_23_ = 1; ~i_22_ < ~i_23_; ++i_23_) { + this.handledSounds[i_21_][i_23_] = stream.readUnsignedShort(); + } + } + } + } else if(opcode == 14) { + this.aBoolean2141 = true; + } else if(opcode == 15) { + this.aBoolean2159 = true; + } else if(opcode == 16) { + this.aBoolean2158 = true; + } else if(opcode == 17) { + this.anInt2145 = stream.readUnsignedByte(); + } else if(opcode == 18) { + this.effect2Sound = true; + } else if(opcode == 19) { + if(this.anIntArray1362 == null) { + this.anIntArray1362 = new int[this.handledSounds.length]; + + for(index = 0; index < this.handledSounds.length; ++index) { + this.anIntArray1362[index] = 255; + } + } + + this.anIntArray1362[stream.readUnsignedByte()] = stream.readUnsignedByte(); + } else if(opcode == 20) { + if(this.soundMaxDelay == null || this.soundMinDelay == null) { + this.soundMaxDelay = new int[this.handledSounds.length]; + this.soundMinDelay = new int[this.handledSounds.length]; + + for(index = 0; index < this.handledSounds.length; ++index) { + this.soundMaxDelay[index] = 256; + this.soundMinDelay[index] = 256; + } + } + + index = stream.readUnsignedByte(); + this.soundMaxDelay[index] = stream.readUnsignedShort(); + this.soundMinDelay[index] = stream.readUnsignedShort(); + } + + } + + public void method2394() { + if(this.anInt2140 == -1) { + if(this.aBooleanArray2149 == null) { + this.anInt2140 = 0; + } else { + this.anInt2140 = 2; + } + } + + if(this.anInt2162 == -1) { + if(this.aBooleanArray2149 == null) { + this.anInt2162 = 0; + } else { + this.anInt2162 = 2; + } + } + + } +} diff --git a/src/com/alex/loaders/clientscripts/ClientScript.java b/src/com/alex/loaders/clientscripts/ClientScript.java new file mode 100644 index 0000000..60aae5b --- /dev/null +++ b/src/com/alex/loaders/clientscripts/ClientScript.java @@ -0,0 +1,4 @@ +package com.alex.loaders.clientscripts; + +public class ClientScript { +} diff --git a/src/com/alex/loaders/images/IndexedColorImageFile.java b/src/com/alex/loaders/images/IndexedColorImageFile.java new file mode 100644 index 0000000..9b73f42 --- /dev/null +++ b/src/com/alex/loaders/images/IndexedColorImageFile.java @@ -0,0 +1,341 @@ +package com.alex.loaders.images; + +import com.alex.io.InputStream; +import com.alex.io.OutputStream; +import com.alex.store.Store; + +import java.awt.image.BufferedImage; +import java.util.Arrays; + +public final class IndexedColorImageFile { + private BufferedImage[] images; + private int[] pallete; + private int[][] pixelsIndexes; + private byte[][] alpha; + private boolean[] usesAlpha; + private int biggestWidth; + private int biggestHeight; + + public IndexedColorImageFile(BufferedImage... images) { + this.images = images; + } + + public IndexedColorImageFile(Store cache, int archiveId, int fileId) { + this(cache, 8, archiveId, fileId); + } + + public IndexedColorImageFile(Store cache, int idx, int archiveId, int fileId) { + this.decodeArchive(cache, idx, archiveId, fileId); + } + + public void decodeArchive(Store cache, int idx, int archiveId, int fileId) { + byte[] data = cache.getIndexes()[idx].getFile(archiveId, fileId); + if(data != null) { + InputStream stream = new InputStream(data); + stream.setOffset(data.length - 2); + int count = stream.readUnsignedShort(); + this.images = new BufferedImage[count]; + this.pixelsIndexes = new int[this.images.length][]; + this.alpha = new byte[this.images.length][]; + this.usesAlpha = new boolean[this.images.length]; + int[] imagesMinX = new int[this.images.length]; + int[] imagesMinY = new int[this.images.length]; + int[] imagesWidth = new int[this.images.length]; + int[] imagesHeight = new int[this.images.length]; + stream.setOffset(data.length - 7 - this.images.length * 8); + this.setBiggestWidth(stream.readShort()); + this.setBiggestHeight(stream.readShort()); + int palleteLength = (stream.readUnsignedByte() & 255) + 1; + + int i_20_; + for(i_20_ = 0; i_20_ < this.images.length; ++i_20_) { + imagesMinX[i_20_] = stream.readUnsignedShort(); + } + + for(i_20_ = 0; i_20_ < this.images.length; ++i_20_) { + imagesMinY[i_20_] = stream.readUnsignedShort(); + } + + for(i_20_ = 0; i_20_ < this.images.length; ++i_20_) { + imagesWidth[i_20_] = stream.readUnsignedShort(); + } + + for(i_20_ = 0; i_20_ < this.images.length; ++i_20_) { + imagesHeight[i_20_] = stream.readUnsignedShort(); + } + + stream.setOffset(data.length - 7 - this.images.length * 8 - (palleteLength - 1) * 3); + this.pallete = new int[palleteLength]; + + for(i_20_ = 1; i_20_ < palleteLength; ++i_20_) { + this.pallete[i_20_] = stream.read24BitInt(); + if(this.pallete[i_20_] == 0) { + this.pallete[i_20_] = 1; + } + } + + stream.setOffset(0); + + for(i_20_ = 0; i_20_ < this.images.length; ++i_20_) { + int pixelsIndexesLength = imagesWidth[i_20_] * imagesHeight[i_20_]; + this.pixelsIndexes[i_20_] = new int[pixelsIndexesLength]; + this.alpha[i_20_] = new byte[pixelsIndexesLength]; + int maskData = stream.readUnsignedByte(); + int i_31_; + if((maskData & 2) == 0) { + int var201; + if((maskData & 1) == 0) { + for(var201 = 0; var201 < pixelsIndexesLength; ++var201) { + this.pixelsIndexes[i_20_][var201] = (byte)stream.readByte(); + } + } else { + for(var201 = 0; var201 < imagesWidth[i_20_]; ++var201) { + for(i_31_ = 0; i_31_ < imagesHeight[i_20_]; ++i_31_) { + this.pixelsIndexes[i_20_][var201 + i_31_ * imagesWidth[i_20_]] = (byte)stream.readByte(); + } + } + } + } else { + this.usesAlpha[i_20_] = true; + boolean var20 = false; + if((maskData & 1) == 0) { + for(i_31_ = 0; i_31_ < pixelsIndexesLength; ++i_31_) { + this.pixelsIndexes[i_20_][i_31_] = (byte)stream.readByte(); + } + + for(i_31_ = 0; i_31_ < pixelsIndexesLength; ++i_31_) { + byte var21 = this.alpha[i_20_][i_31_] = (byte)stream.readByte(); + var20 |= var21 != -1; + } + } else { + int var211; + for(i_31_ = 0; i_31_ < imagesWidth[i_20_]; ++i_31_) { + for(var211 = 0; var211 < imagesHeight[i_20_]; ++var211) { + this.pixelsIndexes[i_20_][i_31_ + var211 * imagesWidth[i_20_]] = stream.readByte(); + } + } + + for(i_31_ = 0; i_31_ < imagesWidth[i_20_]; ++i_31_) { + for(var211 = 0; var211 < imagesHeight[i_20_]; ++var211) { + byte i_33_ = this.alpha[i_20_][i_31_ + var211 * imagesWidth[i_20_]] = (byte)stream.readByte(); + var20 |= i_33_ != -1; + } + } + } + + if(!var20) { + this.alpha[i_20_] = null; + } + } + + this.images[i_20_] = this.getBufferedImage(imagesWidth[i_20_], imagesHeight[i_20_], this.pixelsIndexes[i_20_], this.alpha[i_20_], this.usesAlpha[i_20_]); + } + } + + } + + public BufferedImage getBufferedImage(int width, int height, int[] pixelsIndexes, byte[] extraPixels, boolean useExtraPixels) { + if(width > 0 && height > 0) { + BufferedImage image = new BufferedImage(width, height, 6); + int[] rgbArray = new int[width * height]; + int i = 0; + int i_43_ = 0; + int i_46_; + int i_47_; + if(useExtraPixels && extraPixels != null) { + for(i_46_ = 0; i_46_ < height; ++i_46_) { + for(i_47_ = 0; i_47_ < width; ++i_47_) { + rgbArray[i_43_++] = extraPixels[i] << 24 | this.pallete[pixelsIndexes[i] & 255]; + ++i; + } + } + } else { + for(i_46_ = 0; i_46_ < height; ++i_46_) { + for(i_47_ = 0; i_47_ < width; ++i_47_) { + int i_48_ = this.pallete[pixelsIndexes[i++] & 255]; + rgbArray[i_43_++] = i_48_ != 0?-16777216 | i_48_:0; + } + } + } + + image.setRGB(0, 0, width, height, rgbArray, 0, width); + image.flush(); + return image; + } else { + return null; + } + } + + public byte[] encodeFile() { + if(this.pallete == null) { + this.generatePallete(); + } + + OutputStream stream = new OutputStream(); + + int container; + int len$; + int i$; + for(container = 0; container < this.images.length; ++container) { + len$ = 0; + if(this.usesAlpha[container]) { + len$ |= 2; + } + + stream.writeByte(len$); + + for(i$ = 0; i$ < this.pixelsIndexes[container].length; ++i$) { + stream.writeByte(this.pixelsIndexes[container][i$]); + } + + if(this.usesAlpha[container]) { + for(i$ = 0; i$ < this.alpha[container].length; ++i$) { + stream.writeByte(this.alpha[container][i$]); + } + } + } + + for(container = 0; container < this.pallete.length; ++container) { + stream.write24BitInt(this.pallete[container]); + } + + if(this.biggestWidth == 0 && this.biggestHeight == 0) { + BufferedImage[] var7 = this.images; + len$ = var7.length; + + for(i$ = 0; i$ < len$; ++i$) { + BufferedImage image = var7[i$]; + if(image.getWidth() > this.biggestWidth) { + this.biggestWidth = image.getWidth(); + } + + if(image.getHeight() > this.biggestHeight) { + this.biggestHeight = image.getHeight(); + } + } + } + + stream.writeShort(this.biggestWidth); + stream.writeShort(this.biggestHeight); + stream.writeByte(this.pallete.length - 1); + + for(container = 0; container < this.images.length; ++container) { + stream.writeShort(this.images[container].getMinX()); + } + + for(container = 0; container < this.images.length; ++container) { + stream.writeShort(this.images[container].getMinY()); + } + + for(container = 0; container < this.images.length; ++container) { + stream.writeShort(this.images[container].getWidth()); + } + + for(container = 0; container < this.images.length; ++container) { + stream.writeShort(this.images[container].getHeight()); + } + + stream.writeShort(this.images.length); + byte[] var71 = new byte[stream.getOffset()]; + stream.setOffset(0); + stream.getBytes(var71, 0, var71.length); + return var71; + } + + public int getPalleteIndex(int rgb) { + if(this.pallete == null) { + this.pallete = new int[1]; + } + + for(int var3 = 0; var3 < this.pallete.length; ++var3) { + if(this.pallete[var3] == rgb) { + return var3; + } + } + + if(this.pallete.length == 256) { + System.out.println("Pallete to big, please reduce images quality."); + return 0; + } else { + int[] var31 = new int[this.pallete.length + 1]; + System.arraycopy(this.pallete, 0, var31, 0, this.pallete.length); + var31[this.pallete.length] = rgb; + this.pallete = var31; + return this.pallete.length - 1; + } + } + + public int addImage(BufferedImage image) { + BufferedImage[] newImages = Arrays.copyOf(this.images, this.images.length + 1); + newImages[this.images.length] = image; + this.images = newImages; + this.pallete = null; + this.pixelsIndexes = null; + this.alpha = null; + this.usesAlpha = null; + return this.images.length - 1; + } + + public void replaceImage(BufferedImage image, int index) { + this.images[index] = image; + this.pallete = null; + this.pixelsIndexes = null; + this.alpha = null; + this.usesAlpha = null; + } + + public void generatePallete() { + this.pixelsIndexes = new int[this.images.length][]; + this.alpha = new byte[this.images.length][]; + this.usesAlpha = new boolean[this.images.length]; + + for(int index = 0; index < this.images.length; ++index) { + BufferedImage image = this.images[index]; + int[] rgbArray = new int[image.getWidth() * image.getHeight()]; + image.getRGB(0, 0, image.getWidth(), image.getHeight(), rgbArray, 0, image.getWidth()); + this.pixelsIndexes[index] = new int[image.getWidth() * image.getHeight()]; + this.alpha[index] = new byte[image.getWidth() * image.getHeight()]; + + for(int pixel = 0; pixel < this.pixelsIndexes[index].length; ++pixel) { + int rgb = rgbArray[pixel]; + int medintrgb = this.convertToMediumInt(rgb); + int i = this.getPalleteIndex(medintrgb); + this.pixelsIndexes[index][pixel] = i; + if(rgb >> 24 != 0) { + this.alpha[index][pixel] = (byte)(rgb >> 24); + this.usesAlpha[index] = true; + } + } + } + + } + + public int convertToMediumInt(int rgb) { + OutputStream out = new OutputStream(4); + out.writeInt(rgb); + InputStream stream = new InputStream(out.getBuffer()); + stream.setOffset(1); + rgb = stream.read24BitInt(); + return rgb; + } + + public BufferedImage[] getImages() { + return this.images; + } + + public int getBiggestWidth() { + return this.biggestWidth; + } + + public void setBiggestWidth(int biggestWidth) { + this.biggestWidth = biggestWidth; + } + + public int getBiggestHeight() { + return this.biggestHeight; + } + + public void setBiggestHeight(int biggestHeight) { + this.biggestHeight = biggestHeight; + } +} diff --git a/src/com/alex/loaders/images/LoaderImageArchive.java b/src/com/alex/loaders/images/LoaderImageArchive.java new file mode 100644 index 0000000..936202e --- /dev/null +++ b/src/com/alex/loaders/images/LoaderImageArchive.java @@ -0,0 +1,37 @@ +package com.alex.loaders.images; + +import com.alex.store.Store; + +import java.awt.*; + +public class LoaderImageArchive { + private byte[] data; + + public LoaderImageArchive(byte[] data) { + this.data = data; + } + + public LoaderImageArchive(Store cache, int archiveId) { + this(cache, 32, archiveId, 0); + } + + private LoaderImageArchive(Store cache, int idx, int archiveId, int fileId) { + this.decodeArchive(cache, idx, archiveId, fileId); + } + + private void decodeArchive(Store cache, int idx, int archiveId, int fileId) { + byte[] data = cache.getIndexes()[idx].getFile(archiveId, fileId); + if(data != null) { + this.data = data; + } + + } + + public Image getImage() { + return Toolkit.getDefaultToolkit().createImage(this.data); + } + + public byte[] getImageData() { + return this.data; + } +} diff --git a/src/com/alex/loaders/interfaces/IComponent.java b/src/com/alex/loaders/interfaces/IComponent.java new file mode 100644 index 0000000..8c2fe41 --- /dev/null +++ b/src/com/alex/loaders/interfaces/IComponent.java @@ -0,0 +1,842 @@ +package com.alex.loaders.interfaces; + +import com.alex.io.InputStream; +import com.alex.loaders.interfaces.IComponentSettings; + +public class IComponent { + public Object[] anObjectArray2296; + public int anInt2297 = 0; + public int anInt2298 = -1; + public int[] anIntArray2299; + public int anInt2300; + public int anInt2301 = 1; + public Object[] anObjectArray2302; + public int anInt2303 = -1; + public int anInt2305 = 0; + public boolean aBoolean2306 = false; + public int anInt2308 = 0; + public int[] anIntArray2310; + public byte aByte2311 = 0; + public int anInt2312 = 0; + public Object[] anObjectArray2313; + public int anInt2314; + public int[] anIntArray2315; + public Object[] anObjectArray2316; + public byte[] aByteArray2317; + public Object[] anObjectArray2318; + public int anInt2319 = 0; + public int anInt2321 = -1; + public int height = 0; + public int[] anIntArray2323; + public int anInt2324 = 0; + public int anInt2325 = 0; + public IComponent[] aClass173Array2326; + public int[][] anIntArrayArray2327; + public Object[] anObjectArray2328; + public String aString2329 = "Ok"; + public String aString2330; + public Object[] anObjectArray2331; + public int anInt2332 = 0; + public int anInt2333 = 0; + public String aString2334 = ""; + public int anInt2335 = 0; + public Object[] anObjectArray2336; + public int[] anIntArray2337; + public int anInt2338 = 0; + public int anInt2340; + public byte aByte2341 = 0; + public boolean aBoolean2342; + public int anInt2343 = 0; + public Object[] anObjectArray2344; + public IComponent aClass173_2345 = null; + public static int anInt2346; + public int anInt2347 = 0; + public Object[] anObjectArray2348; + public int anInt2349 = -1; + public int anInt2350 = -1; + public Object[] anObjectArray2351; + public Object[] anObjectArray2352; + public boolean aBoolean2353 = false; + public boolean useScripts = false; + public byte aByte2356 = 0; + public String aString2357 = ""; + public int modelId; + public int[] anIntArray2360; + public int anInt2361 = -1; + public Object[] anObjectArray2362; + public String[] aStringArray2363; + public int anInt2364 = 0; + public int anInt2365 = -1; + public boolean aBoolean2366 = false; + public boolean aBoolean2367 = false; + public boolean aBoolean2368 = false; + public int anInt2369 = 0; + public Object[] anObjectArray2371; + public String aString2373 = ""; + public int anInt2374 = -1; + public int anInt2375 = -1; + public int imageId = -1; + public int[] anIntArray2379; + public boolean aBoolean2380 = false; + public int anInt2381 = 0; + public int anInt2382; + public short aShort2383 = 0; + public int[] anIntArray2384; + public String[] aStringArray2385; + public int anInt2386 = -1; + public int[] anIntArray2388; + public int anInt2389 = 0; + public int anInt2390 = 0; + public String aString2391 = ""; + public boolean aBoolean2393 = false; + public int anInt2394 = 1; + public Object[] anObjectArray2395; + public int anInt2396 = 0; + public int anInt2397 = 0; + public IComponentSettings settings; + public Object[] anObjectArray2399; + public int[] anIntArray2400; + public boolean aBoolean2401 = false; + public Object[] anObjectArray2402; + public int anInt2403 = 100; + public boolean hidden = false; + public Object[] anObjectArray2405; + public int[] anIntArray2407; + public Object[] anObjectArray2408; + public int anInt2409; + public Object[] anObjectArray2410; + public int anInt2411 = 0; + public int anInt2412 = 0; + public boolean aBoolean2413 = false; + public int anInt2414 = 0; + public int anInt2415 = 0; + public int modelType = 1; + public byte[] aByteArray2417; + public int[] anIntArray2418; + public boolean aBoolean2419; + public short aShort2420 = 3000; + public int anInt2421 = -1; + public boolean aBoolean2422 = false; + public int anInt2423 = 0; + public int anInt2424 = 0; + public Object[] defaultScript; + public int anInt2427 = 0; + public boolean aBoolean2429 = false; + public int[] anIntArray2431; + public int y = 0; + public int borderThickness = 0; + public boolean aBoolean2434 = false; + public int anInt2435 = 0; + public boolean aBoolean2436 = false; + public int anInt2437 = 0; + public int anInt2438 = 1; + public Object[] anObjectArray2439; + public int width = 0; + public int anInt2441 = 0; + public int anInt2442 = 0; + public int anInt2443 = -1; + public int anInt2444 = 0; + public int x = 0; + public Object[] anObjectArray2446; + public Object[] anObjectArray2447; + public int anInt2448 = -1; + public int[] anIntArray2449; + public int anInt2450 = 0; + public int anInt2451 = 0; + public int[] anIntArray2452; + public int anInt2453 = -1; + public Object[] anObjectArray2454; + public int hash = -1; + public int parentId = -1; + public int anInt2457 = -1; + public int anInt2458; + public int anInt2459 = 0; + public int anInt2461 = 0; + public Object[] anObjectArray2462; + public String aString2463 = ""; + public Object[] anObjectArray2464; + public Object[] anObjectArray2465; + public int anInt2467 = 0; + public byte aByte2469 = 0; + public int type; + public int anInt2471 = 1; + public int[] anIntArray2472; + public String aString2473; + public int anInt2474 = 2; + public Object[] anObjectArray2475; + public boolean aBoolean2476 = false; + public int anInt2477 = 0; + public int[] anIntArray2478; + public int anInt2479 = 0; + public int anInt2480 = 0; + public int anInt2481 = 1; + public int anInt2482 = 0; + public Object[] anObjectArray2483; + public int anInt2484 = 0; + public boolean aBoolean4782; + + public void decodeScriptsFormat(InputStream stream) { + this.useScripts = true; + int newInt = stream.readUnsignedByte(); + if(newInt == 255) { + newInt = -1; + } + + this.type = stream.readUnsignedByte(); + if(~(this.type & 128) != -1) { + this.type &= 127; + this.aString2473 = stream.readString(); + } + + this.anInt2441 = stream.readUnsignedShort(); + this.x = stream.readShort(); + this.y = stream.readShort(); + this.width = stream.readUnsignedShort(); + this.height = stream.readUnsignedShort(); + this.aByte2356 = (byte)stream.readByte(); + this.aByte2341 = (byte)stream.readByte(); + this.aByte2469 = (byte)stream.readByte(); + this.aByte2311 = (byte)stream.readByte(); + this.parentId = stream.readUnsignedShort(); + if(~this.parentId != -65536) { + this.parentId += this.hash & -65536; + } else { + this.parentId = -1; + } + + int i_17_ = stream.readUnsignedByte(); + this.hidden = ~(1 & i_17_) != -1; + if(newInt >= 0) { + this.aBoolean2429 = ~(i_17_ & 2) != -1; + } + + if(~this.type == -1) { + this.anInt2444 = stream.readUnsignedShort(); + this.anInt2479 = stream.readUnsignedShort(); + if(~newInt > -1) { + this.aBoolean2429 = stream.readUnsignedByte() == 1; + } + } + + int settingsHash; + if(~this.type == -6) { + this.imageId = stream.readInt(); + this.anInt2381 = stream.readUnsignedShort(); + settingsHash = stream.readUnsignedByte(); + this.aBoolean2422 = ~(2 & settingsHash) != -1; + this.aBoolean2434 = ~(settingsHash & 1) != -1; + this.anInt2369 = stream.readUnsignedByte(); + this.borderThickness = stream.readUnsignedByte(); + this.anInt2325 = stream.readInt(); + this.aBoolean2419 = ~stream.readUnsignedByte() == -2; + this.aBoolean2342 = ~stream.readUnsignedByte() == -2; + this.anInt2467 = stream.readInt(); + if(~newInt <= -4) { + this.aBoolean4782 = ~stream.readUnsignedByte() == -2; + } + } + + if(~this.type == -7) { + this.modelType = 1; + this.modelId = stream.readBigSmart(); + this.anInt2480 = stream.readShort(); + this.anInt2459 = stream.readShort(); + this.anInt2461 = stream.readUnsignedShort(); + this.anInt2482 = stream.readUnsignedShort(); + this.anInt2308 = stream.readUnsignedShort(); + this.anInt2403 = stream.readUnsignedShort(); + this.anInt2443 = stream.readUnsignedShort(); + if(this.anInt2443 == '\uffff') { + this.anInt2443 = -1; + } + + this.aBoolean2476 = stream.readUnsignedByte() == 1; + this.aShort2383 = (short)stream.readUnsignedShort(); + this.aShort2420 = (short)stream.readUnsignedShort(); + this.aBoolean2368 = stream.readUnsignedByte() == 1; + if(~this.aByte2356 != -1) { + this.anInt2423 = stream.readUnsignedShort(); + } + + if(this.aByte2341 != 0) { + this.anInt2397 = stream.readUnsignedShort(); + } + } + + if(this.type == 4) { + this.anInt2375 = stream.readBigSmart(); + if(~this.anInt2375 == -65536) { + this.anInt2375 = -1; + } + + this.aString2357 = stream.readString(); + if(this.aString2357.toLowerCase().contains("ship")) { + System.out.println(this.hash >> 16); + } + + this.anInt2364 = stream.readUnsignedByte(); + this.anInt2312 = stream.readUnsignedByte(); + this.anInt2297 = stream.readUnsignedByte(); + this.aBoolean2366 = ~stream.readUnsignedByte() == -2; + this.anInt2467 = stream.readInt(); + } + + if(this.type == 3) { + this.anInt2467 = stream.readInt(); + this.aBoolean2367 = ~stream.readUnsignedByte() == -2; + this.anInt2369 = stream.readUnsignedByte(); + } + + if(~this.type == -10) { + this.anInt2471 = stream.readUnsignedByte(); + this.anInt2467 = stream.readInt(); + this.aBoolean2306 = ~stream.readUnsignedByte() == -2; + } + + settingsHash = stream.read24BitInt(); + int i_28_ = stream.readUnsignedByte(); + int i_30_; + if(i_28_ != 0) { + this.anIntArray2449 = new int[11]; + this.aByteArray2417 = new byte[11]; + + for(this.aByteArray2317 = new byte[11]; ~i_28_ != -1; i_28_ = stream.readUnsignedByte()) { + i_30_ = -1 + (i_28_ >> 360744868); + i_28_ = i_28_ << -456693784 | stream.readUnsignedByte(); + i_28_ &= 4095; + if(~i_28_ != -4096) { + this.anIntArray2449[i_30_] = i_28_; + } else { + this.anIntArray2449[i_30_] = -1; + } + + this.aByteArray2317[i_30_] = (byte)stream.readByte(); + if(~this.aByteArray2317[i_30_] != -1) { + this.aBoolean2401 = true; + } + + this.aByteArray2417[i_30_] = (byte)stream.readByte(); + } + } + + this.aString2391 = stream.readString(); + i_30_ = stream.readUnsignedByte(); + int i_31_ = i_30_ & 15; + int i_33_; + if(~i_31_ < -1) { + this.aStringArray2385 = new String[i_31_]; + + for(i_33_ = 0; i_31_ > i_33_; ++i_33_) { + this.aStringArray2385[i_33_] = stream.readString(); + } + } + + i_33_ = i_30_ >> -686838332; + int defaultHash; + int i; + if(~i_33_ < -1) { + defaultHash = stream.readUnsignedByte(); + this.anIntArray2315 = new int[1 + defaultHash]; + + for(i = 0; i < this.anIntArray2315.length; ++i) { + this.anIntArray2315[i] = -1; + } + + this.anIntArray2315[defaultHash] = stream.readUnsignedShort(); + } + + if(~i_33_ < -2) { + defaultHash = stream.readUnsignedByte(); + this.anIntArray2315[defaultHash] = stream.readUnsignedShort(); + } + + this.aString2330 = stream.readString(); + if(this.aString2330.equals("")) { + this.aString2330 = null; + } + + this.anInt2335 = stream.readUnsignedByte(); + this.anInt2319 = stream.readUnsignedByte(); + this.aBoolean2436 = ~stream.readUnsignedByte() == -2; + this.aString2463 = stream.readString(); + defaultHash = -1; + if(~method2412(settingsHash) != -1) { + defaultHash = stream.readUnsignedShort(); + if(~defaultHash == -65536) { + defaultHash = -1; + } + + this.anInt2303 = stream.readUnsignedShort(); + if(this.anInt2303 == '\uffff') { + this.anInt2303 = -1; + } + + this.anInt2374 = stream.readUnsignedShort(); + if(this.anInt2374 == '\uffff') { + this.anInt2374 = -1; + } + } + + this.settings = new IComponentSettings(settingsHash, defaultHash); + this.defaultScript = this.decodeScript(stream); + this.anObjectArray2462 = this.decodeScript(stream); + this.anObjectArray2402 = this.decodeScript(stream); + this.anObjectArray2371 = this.decodeScript(stream); + this.anObjectArray2408 = this.decodeScript(stream); + this.anObjectArray2439 = this.decodeScript(stream); + this.anObjectArray2454 = this.decodeScript(stream); + this.anObjectArray2410 = this.decodeScript(stream); + this.anObjectArray2316 = this.decodeScript(stream); + this.anObjectArray2465 = this.decodeScript(stream); + this.anObjectArray2446 = this.decodeScript(stream); + this.anObjectArray2313 = this.decodeScript(stream); + this.anObjectArray2318 = this.decodeScript(stream); + this.anObjectArray2328 = this.decodeScript(stream); + this.anObjectArray2395 = this.decodeScript(stream); + this.anObjectArray2331 = this.decodeScript(stream); + this.anObjectArray2405 = this.decodeScript(stream); + this.anObjectArray2351 = this.decodeScript(stream); + this.anObjectArray2302 = this.decodeScript(stream); + this.anObjectArray2296 = this.decodeScript(stream); + this.anIntArray2452 = this.method2465(stream); + this.anIntArray2472 = this.method2465(stream); + this.anIntArray2360 = this.method2465(stream); + this.anIntArray2388 = this.method2465(stream); + this.anIntArray2299 = this.method2465(stream); + System.out.println("useScripts = " + this.useScripts); + System.out.println("x = " + this.x); + System.out.println("y = " + this.y); + System.out.println("width = " + this.width); + System.out.println("height = " + this.height); + System.out.println("parentId = " + this.parentId); + System.out.println("imageId = " + this.imageId); + System.out.println("modelId = " + this.modelId); + System.out.println("aString2357 = " + this.aString2357); + System.out.println("aString2391 = " + this.aString2391); + + for(i = 0; i < this.aStringArray2385.length; ++i) { + System.out.println("aStringArray2385[" + i + "] = " + this.aStringArray2385[i]); + } + + for(i = 0; i < this.anIntArray2315.length; ++i) { + System.out.println("anIntArray2315[" + i + "] = " + this.anIntArray2315[i]); + } + + System.out.println("aString2330 = " + this.aString2330); + System.out.println("aBoolean2436 = " + this.aBoolean2436); + System.out.println("aString2463 = " + this.aString2463); + System.out.println("anInt2303 = " + this.anInt2303); + System.out.println("anInt2364 = " + this.anInt2364); + + for(i = 0; i < this.anObjectArray2462.length; ++i) { + System.out.println("anObjectArray2462[" + i + "] = " + this.anObjectArray2462[i]); + } + + for(i = 0; i < this.anObjectArray2402.length; ++i) { + System.out.println("anObjectArray2402[" + i + "] = " + this.anObjectArray2402[i]); + } + + for(i = 0; i < this.anObjectArray2371.length; ++i) { + System.out.println("anObjectArray2371[" + i + "] = " + this.anObjectArray2371[i]); + } + + for(i = 0; i < this.anObjectArray2408.length; ++i) { + System.out.println("anObjectArray2408[" + i + "] = " + this.anObjectArray2408[i]); + } + + for(i = 0; i < this.anObjectArray2439.length; ++i) { + System.out.println("anObjectArray2439[" + i + "] = " + this.anObjectArray2439[i]); + } + + for(i = 0; i < this.anObjectArray2454.length; ++i) { + System.out.println("anObjectArray2454[" + i + "] = " + this.anObjectArray2454[i]); + } + + for(i = 0; i < this.anObjectArray2410.length; ++i) { + System.out.println("anObjectArray2410[" + i + "] = " + this.anObjectArray2410[i]); + } + + for(i = 0; i < this.anObjectArray2316.length; ++i) { + System.out.println("anObjectArray2316[" + i + "] = " + this.anObjectArray2316[i]); + } + + for(i = 0; i < this.anObjectArray2465.length; ++i) { + System.out.println("anObjectArray2465[" + i + "] = " + this.anObjectArray2465[i]); + } + + for(i = 0; i < this.anObjectArray2446.length; ++i) { + System.out.println("anObjectArray2446[" + i + "] = " + this.anObjectArray2446[i]); + } + + for(i = 0; i < this.anObjectArray2313.length; ++i) { + System.out.println("anObjectArray2313[" + i + "] = " + this.anObjectArray2313[i]); + } + + for(i = 0; i < this.anObjectArray2318.length; ++i) { + System.out.println("anObjectArray2318[" + i + "] = " + this.anObjectArray2318[i]); + } + + for(i = 0; i < this.anObjectArray2328.length; ++i) { + System.out.println("anObjectArray2328[" + i + "] = " + this.anObjectArray2328[i]); + } + + for(i = 0; i < this.anObjectArray2395.length; ++i) { + System.out.println("anObjectArray2395[" + i + "] = " + this.anObjectArray2395[i]); + } + + for(i = 0; i < this.anObjectArray2331.length; ++i) { + System.out.println("anObjectArray2331[" + i + "] = " + this.anObjectArray2331[i]); + } + + for(i = 0; i < this.anObjectArray2405.length; ++i) { + System.out.println("anObjectArray2405[" + i + "] = " + this.anObjectArray2405[i]); + } + + for(i = 0; i < this.anObjectArray2351.length; ++i) { + System.out.println("anObjectArray2351[" + i + "] = " + this.anObjectArray2351[i]); + } + + for(i = 0; i < this.anObjectArray2302.length; ++i) { + System.out.println("anObjectArray2302[" + i + "] = " + this.anObjectArray2302[i]); + } + + for(i = 0; i < this.anObjectArray2296.length; ++i) { + System.out.println("anObjectArray2296[" + i + "] = " + this.anObjectArray2296[i]); + } + + for(i = 0; i < this.anIntArray2452.length; ++i) { + System.out.println("anIntArray2452[" + i + "] = " + this.anIntArray2452[i]); + } + + for(i = 0; i < this.anIntArray2472.length; ++i) { + System.out.println("anIntArray2472[" + i + "] = " + this.anIntArray2472[i]); + } + + for(i = 0; i < this.anIntArray2360.length; ++i) { + System.out.println("anIntArray2360[" + i + "] = " + this.anIntArray2360[i]); + } + + for(i = 0; i < this.anIntArray2388.length; ++i) { + System.out.println("anIntArray2388[" + i + "] = " + this.anIntArray2388[i]); + } + + for(i = 0; i < this.anIntArray2299.length; ++i) { + System.out.println("anIntArray2299[" + i + "] = " + this.anIntArray2299[i]); + } + + } + + public Object[] decodeScript(InputStream stream) { + int size = stream.readUnsignedByte(); + Object[] objects = new Object[size]; + + for(int index = 0; ~size < ~index; ++index) { + int i_41_ = stream.readUnsignedByte(); + if(~i_41_ == -1) { + objects[index] = new Integer(stream.readInt()); + } else if(i_41_ == 1) { + objects[index] = stream.readString(); + } + } + + this.aBoolean2353 = true; + return objects; + } + + public int[] method2465(InputStream stream) { + int size = stream.readUnsignedByte(); + if(size == 0) { + return null; + } else { + int[] array = new int[size]; + + for(int index = 0; size > index; ++index) { + array[index] = stream.readInt(); + } + + return array; + } + } + + public void decodeNoscriptsFormat(InputStream stream) { + this.useScripts = false; + this.type = stream.readUnsignedByte(); + this.anInt2324 = stream.readUnsignedByte(); + this.anInt2441 = stream.readUnsignedShort(); + this.x = stream.readShort(); + this.y = stream.readShort(); + this.width = stream.readUnsignedShort(); + this.height = stream.readUnsignedShort(); + this.aByte2341 = 0; + this.aByte2356 = 0; + this.aByte2311 = 0; + this.aByte2469 = 0; + this.anInt2369 = stream.readUnsignedByte(); + this.parentId = stream.readUnsignedShort(); + if(~this.parentId == -65536) { + this.parentId = -1; + } else { + this.parentId += this.hash & -65536; + } + + this.anInt2448 = stream.readUnsignedShort(); + if(~this.anInt2448 == -65536) { + this.anInt2448 = -1; + } + + int i = stream.readUnsignedByte(); + int i_1_; + if(~i < -1) { + this.anIntArray2407 = new int[i]; + this.anIntArray2384 = new int[i]; + + for(i_1_ = 0; i > i_1_; ++i_1_) { + this.anIntArray2384[i_1_] = stream.readUnsignedByte(); + this.anIntArray2407[i_1_] = stream.readUnsignedShort(); + } + } + + i_1_ = stream.readUnsignedByte(); + int i_5_; + int is; + int i_13_; + if(~i_1_ < -1) { + this.anIntArrayArray2327 = new int[i_1_][]; + + for(i_5_ = 0; ~i_1_ < ~i_5_; ++i_5_) { + is = stream.readUnsignedShort(); + this.anIntArrayArray2327[i_5_] = new int[is]; + + for(i_13_ = 0; ~is < ~i_13_; ++i_13_) { + this.anIntArrayArray2327[i_5_][i_13_] = stream.readUnsignedShort(); + if(~this.anIntArrayArray2327[i_5_][i_13_] == -65536) { + this.anIntArrayArray2327[i_5_][i_13_] = -1; + } + } + } + } + + if(~this.type == -1) { + this.anInt2479 = stream.readUnsignedShort(); + this.hidden = stream.readUnsignedByte() == 1; + } + + if(this.type == 1) { + stream.readUnsignedShort(); + stream.readUnsignedByte(); + } + + i_5_ = 0; + if(~this.type == -3) { + this.anIntArray2400 = new int[this.height * this.width]; + this.aByte2341 = 3; + this.anIntArray2418 = new int[this.height * this.width]; + this.aByte2356 = 3; + is = stream.readUnsignedByte(); + if(is == 1) { + i_5_ |= 268435456; + } + + i_13_ = stream.readUnsignedByte(); + if(i_13_ == 1) { + i_5_ |= 1073741824; + } + + int var10 = stream.readUnsignedByte(); + stream.readUnsignedByte(); + if(~var10 == -2) { + i_5_ |= Integer.MIN_VALUE; + } + + this.anInt2332 = stream.readUnsignedByte(); + this.anInt2414 = stream.readUnsignedByte(); + this.anIntArray2337 = new int[20]; + this.anIntArray2323 = new int[20]; + this.anIntArray2431 = new int[20]; + + int i_11_; + for(i_11_ = 0; i_11_ < 20; ++i_11_) { + int var12 = stream.readUnsignedByte(); + if(~var12 != -2) { + this.anIntArray2431[i_11_] = -1; + } else { + this.anIntArray2323[i_11_] = stream.readShort(); + this.anIntArray2337[i_11_] = stream.readShort(); + this.anIntArray2431[i_11_] = stream.readInt(); + } + } + + this.aStringArray2363 = new String[5]; + + for(i_11_ = 0; i_11_ < 5; ++i_11_) { + String var121 = stream.readString(); + if(~var121.length() < -1) { + this.aStringArray2363[i_11_] = var121; + i_5_ |= 1 << 23 + i_11_; + } + } + } + + if(~this.type == -4) { + this.aBoolean2367 = ~stream.readUnsignedByte() == -2; + } + + if(~this.type == -5 || this.type == 1) { + this.anInt2312 = stream.readUnsignedByte(); + this.anInt2297 = stream.readUnsignedByte(); + this.anInt2364 = stream.readUnsignedByte(); + this.anInt2375 = stream.readUnsignedShort(); + if(~this.anInt2375 == -65536) { + this.anInt2375 = -1; + } + + this.aBoolean2366 = stream.readUnsignedByte() == 1; + } + + if(~this.type == -5) { + this.aString2357 = stream.readString(); + this.aString2334 = stream.readString(); + } + + if(this.type == 1 || ~this.type == -4 || this.type == 4) { + this.anInt2467 = stream.readInt(); + } + + if(this.type == 3 || this.type == 4) { + this.anInt2424 = stream.readInt(); + this.anInt2451 = stream.readInt(); + this.anInt2477 = stream.readInt(); + } + + if(~this.type == -6) { + this.imageId = stream.readInt(); + this.anInt2349 = stream.readInt(); + } + + if(~this.type == -7) { + this.modelType = 1; + this.modelId = stream.readUnsignedShort(); + this.anInt2301 = 1; + if(this.modelId == '\uffff') { + this.modelId = -1; + } + + this.anInt2386 = stream.readUnsignedShort(); + if(~this.anInt2386 == -65536) { + this.anInt2386 = -1; + } + + this.anInt2443 = stream.readUnsignedShort(); + if(this.anInt2443 == '\uffff') { + this.anInt2443 = -1; + } + + this.anInt2298 = stream.readUnsignedShort(); + if(this.anInt2298 == '\uffff') { + this.anInt2298 = -1; + } + + this.anInt2403 = stream.readUnsignedShort(); + this.anInt2461 = stream.readUnsignedShort(); + this.anInt2482 = stream.readUnsignedShort(); + } + + if(~this.type == -8) { + this.aByte2341 = 3; + this.anIntArray2418 = new int[this.width * this.height]; + this.aByte2356 = 3; + this.anIntArray2400 = new int[this.width * this.height]; + this.anInt2312 = stream.readUnsignedByte(); + this.anInt2375 = stream.readUnsignedShort(); + if(this.anInt2375 == '\uffff') { + this.anInt2375 = -1; + } + + this.aBoolean2366 = stream.readUnsignedByte() == 1; + this.anInt2467 = stream.readInt(); + this.anInt2332 = stream.readShort(); + this.anInt2414 = stream.readShort(); + is = stream.readUnsignedByte(); + if(~is == -2) { + i_5_ |= 1073741824; + } + + this.aStringArray2363 = new String[5]; + + for(i_13_ = 0; i_13_ < 5; ++i_13_) { + String var101 = stream.readString(); + if(var101.length() > 0) { + this.aStringArray2363[i_13_] = var101; + i_5_ |= 1 << i_13_ + 23; + } + } + } + + if(~this.type == -9) { + this.aString2357 = stream.readString(); + } + + if(this.anInt2324 == 2 || ~this.type == -3) { + this.aString2463 = stream.readString(); + this.aString2373 = stream.readString(); + is = 63 & stream.readUnsignedShort(); + i_5_ |= is << -116905845; + } + + if(~this.anInt2324 == -2 || ~this.anInt2324 == -5 || this.anInt2324 == 5 || this.anInt2324 == 6) { + this.aString2329 = stream.readString(); + if(~this.aString2329.length() == -1) { + if(~this.anInt2324 == -2) { + this.aString2329 = "Ok"; + } + + if(~this.anInt2324 == -5) { + this.aString2329 = "Select"; + } + + if(~this.anInt2324 == -6) { + this.aString2329 = "Select"; + } + + if(~this.anInt2324 == -7) { + this.aString2329 = "Continue"; + } + } + } + + if(this.anInt2324 == 1 || this.anInt2324 == 4 || ~this.anInt2324 == -6) { + i_5_ |= 4194304; + } + + if(~this.anInt2324 == -7) { + i_5_ |= 1; + } + + this.settings = new IComponentSettings(i_5_, -1); + System.out.println("useScripts = " + this.useScripts); + System.out.println("type = " + this.type); + System.out.println("anInt2324 = " + this.anInt2324); + System.out.println("anInt2441 = " + this.anInt2441); + System.out.println("x = " + this.x); + System.out.println("y = " + this.y); + System.out.println("width = " + this.width); + System.out.println("height = " + this.height); + System.out.println("anInt2369 = " + this.anInt2369); + System.out.println("parentId = " + this.parentId); + System.out.println("anInt2448 = " + this.anInt2448); + + byte var11; + for(var11 = 0; var11 < this.anIntArray2407.length; ++i) { + System.out.println("anIntArray2407[" + var11 + "] = " + this.anIntArray2407[var11]); + } + + for(var11 = 0; var11 < this.aStringArray2363.length; ++i) { + System.out.println("aStringArray2363[" + var11 + "] = " + this.aStringArray2363[var11]); + } + + } + + public static int method2412(int arg0) { + return 127 & arg0 >> -809958741; + } +} diff --git a/src/com/alex/loaders/interfaces/IComponentSettings.java b/src/com/alex/loaders/interfaces/IComponentSettings.java new file mode 100644 index 0000000..4070eb6 --- /dev/null +++ b/src/com/alex/loaders/interfaces/IComponentSettings.java @@ -0,0 +1,11 @@ +package com.alex.loaders.interfaces; + +public final class IComponentSettings { + public int settingsHash; + public int defaultHash; + + public IComponentSettings(int settingsHash, int defaultHash) { + this.settingsHash = settingsHash; + this.defaultHash = defaultHash; + } +} diff --git a/src/com/alex/loaders/interfaces/Interface.java b/src/com/alex/loaders/interfaces/Interface.java new file mode 100644 index 0000000..53c6726 --- /dev/null +++ b/src/com/alex/loaders/interfaces/Interface.java @@ -0,0 +1,78 @@ +package com.alex.loaders.interfaces; + +import com.alex.io.InputStream; +import com.alex.loaders.interfaces.IComponent; +import com.alex.store.Store; +import com.alex.utils.Utils; + +import javax.swing.*; +import java.awt.*; +import java.awt.image.FilteredImageSource; +import java.awt.image.ReplicateScaleFilter; +import java.io.IOException; + +public class Interface { + public int id; + public Store cache; + public IComponent[] components; + public JComponent[] jcomponents; + + public static void main(String[] args) throws IOException { + Store rscache = new Store("cache/"); + + for(int i = 0; i < Utils.getInterfaceDefinitionsSize(rscache); ++i) { + try { + new Interface(i, rscache); + } catch (Throwable var4) { + } + } + + } + + public Interface(int id, Store cache) { + this(id, cache, true); + } + + public Interface(int id, Store cache, boolean load) { + this.id = id; + this.cache = cache; + if(load) { + this.getComponents(); + } + + } + + public void draw(JComponent parent) { + } + + public Image resizeImage(Image image, int width, int height, Component c) { + ReplicateScaleFilter replicate = new ReplicateScaleFilter(width, height); + FilteredImageSource prod = new FilteredImageSource(image.getSource(), replicate); + return c.createImage(prod); + } + + public void getComponents() { + if(Utils.getInterfaceDefinitionsSize(this.cache) <= this.id) { + throw new RuntimeException("Invalid interface id."); + } else { + this.components = new IComponent[Utils.getInterfaceDefinitionsComponentsSize(this.cache, this.id)]; + + for(int componentId = 0; componentId < this.components.length; ++componentId) { + this.components[componentId] = new IComponent(); + this.components[componentId].hash = this.id << 16 | componentId; + byte[] data = this.cache.getIndexes()[3].getFile(this.id, componentId); + if(data == null) { + throw new RuntimeException("Interface " + this.id + ", component " + componentId + " data is null."); + } + + System.out.println("Interface: " + this.id + " - ComponentId: " + componentId); + if(data[0] != -1) { + this.components[componentId].decodeNoscriptsFormat(new InputStream(data)); + } else { + this.components[componentId].decodeScriptsFormat(new InputStream(data)); + } + } + + } + } +} diff --git a/src/com/alex/loaders/interfaces/InterfaceName.java b/src/com/alex/loaders/interfaces/InterfaceName.java new file mode 100644 index 0000000..4deff52 --- /dev/null +++ b/src/com/alex/loaders/interfaces/InterfaceName.java @@ -0,0 +1,60 @@ +package com.alex.loaders.interfaces; + +import com.alex.store.Store; +import com.alex.utils.Utils; + +import java.io.IOException; + +public class InterfaceName { + public static final char[] VALID_CHARS = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; + + public static void printAllCombinations4Letters() { + } + + public static void main(String[] args) throws IOException { + Store rscache = new Store("C:/Users/yvonne � christer/Dropbox/Source/data/562cache/", false); + int hash = rscache.getIndexes()[3].getTable().getArchives()[884].getNameHash(); + char[] arr$ = VALID_CHARS; + int len$ = arr$.length; + + for(int i$ = 0; i$ < len$; ++i$) { + char l1 = arr$[i$]; + System.out.println(l1); + char[] arr$1 = VALID_CHARS; + int len$1 = arr$1.length; + + for(int i$1 = 0; i$1 < len$1; ++i$1) { + char l2 = arr$1[i$1]; + char[] arr$2 = VALID_CHARS; + int len$2 = arr$2.length; + + for(int i$2 = 0; i$2 < len$2; ++i$2) { + char l3 = arr$2[i$2]; + char[] arr$3 = VALID_CHARS; + int len$3 = arr$3.length; + + for(int i$3 = 0; i$3 < len$3; ++i$3) { + char l4 = arr$3[i$3]; + char[] arr$4 = VALID_CHARS; + int len$4 = arr$4.length; + + for(int i$4 = 0; i$4 < len$4; ++i$4) { + char l5 = arr$4[i$4]; + char[] arr$5 = VALID_CHARS; + int len$5 = arr$5.length; + + for(int i$5 = 0; i$5 < len$5; ++i$5) { + char l6 = arr$5[i$5]; + String name = new String(new char[]{l1, l2, l3, l4, l5, l6}); + if(Utils.getNameHash(name) == hash) { + System.out.println(name); + } + } + } + } + } + } + } + + } +} diff --git a/src/com/alex/loaders/items/ItemDefinitions.java b/src/com/alex/loaders/items/ItemDefinitions.java new file mode 100644 index 0000000..c4716a6 --- /dev/null +++ b/src/com/alex/loaders/items/ItemDefinitions.java @@ -0,0 +1,1063 @@ +package com.alex.loaders.items; + +import com.alex.io.InputStream; +import com.alex.io.OutputStream; +import com.alex.store.Store; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; + +public class ItemDefinitions implements Cloneable { + public int id; + public boolean loaded; + public int modelId; + public String name; + public int zoom2d; + public int xan2d; + public int yan2d; + public int xOffset2d; + public int yOffset2d; + public int equipSlot; + public int equipType; + public int stackable; + public int cost; + public boolean membersOnly; + public int maleEquip1; + public int femaleEquip1; + public int maleEquip2; + public int femaleEquip2; + public int maleEquipModelId3; + public int femaleEquipModelId3; + public String[] groundOptions; + public String[] inventoryOptions; + public int[] originalModelColors; + public int[] modifiedModelColors; + public short[] originalTextureColors; + public short[] modifiedTextureColors; + public byte[] recolorPalette; + public int[] unknownArray2; + public int[] unknownArray4; + public int[] unknownArray5; + public byte[] unknownArray6; + public byte[] unknownArray3; + public boolean unnoted; + public int primaryMaleDialogueHead; + public int primaryFemaleDialogueHead; + public int secondaryMaleDialogueHead; + public int secondaryFemaleDialogueHead; + public int Zan2d; + public int dummyItem; + public int switchNoteItemId; + public int notedItemId; + public int[] stackIds; + public int[] stackAmounts; + public int floorScaleX; + public int floorScaleY; + public int floorScaleZ; + public int ambience; + public int diffusion; + public int teamId; + public int switchLendItemId; + public int lendedItemId; + public int maleWieldX; + public int maleWieldY; + public int maleWieldZ; + public int femaleWieldX; + public int femaleWieldY; + public int femaleWieldZ; + public int unknownInt18; + public int unknownInt19; + public int unknownInt20; + public int unknownInt21; + public int unknownInt22; + public int unknownInt23; + public int unknownValue1; + public int unknownValue2; + private int opcode218; + private int opcode219; + public HashMap clientScriptData; + + public static ItemDefinitions getItemDefinition(Store cache, int itemId) { + return getItemDefinition(cache, itemId, true); + } + + public static ItemDefinitions getItemDefinition(Store cache, int itemId, boolean load) { + return new ItemDefinitions(cache, itemId, load); + } + + public ItemDefinitions(Store cache, int id) { + this(cache, id, true); + } + + public ItemDefinitions(Store cache, int id, boolean load) { + this.id = id; + this.setDefaultsVariableValules(); + this.setDefaultOptions(); + if(load) { + this.loadItemDefinition(cache); + } + + } + + public boolean isLoaded() { + return this.loaded; + } + + public int getCost() { + return this.cost; + } + + public int getTeamId() { + return this.teamId; + } + + public int getStackable() { + return this.stackable; + } + + public boolean isUnnoted() { + return this.unnoted; + } + + public int getLendedItemId() { + return this.lendedItemId; + } + + public int getXan2d() { + return this.xan2d; + } + + public void setXan2d(int xan2d) { + this.xan2d = xan2d; + } + + public int getYan2d() { + return this.yan2d; + } + + public void setYan2d(int yan2d) { + this.yan2d = yan2d; + } + + public int getxOffset2d() { + return this.xOffset2d; + } + + public void setxOffset2d(int xOffset2d) { + this.xOffset2d = xOffset2d; + } + + public int getyOffset2d() { + return this.yOffset2d; + } + + public void setyOffset2d(int yOffset2d) { + this.yOffset2d = yOffset2d; + } + + public int getMaleEquipModelId1() { + return this.maleEquip1; + } + + public void setMaleEquipModelId1(int maleEquipModelId1) { + this.maleEquip1 = maleEquipModelId1; + } + + public int getFemaleEquipModelId1() { + return this.femaleEquip1; + } + + public void setFemaleEquipModelId1(int femaleEquipModelId1) { + this.femaleEquip1 = femaleEquipModelId1; + } + + public int getMaleEquipModelId2() { + return this.maleEquip2; + } + + public void setMaleEquipModelId2(int maleEquipModelId2) { + this.maleEquip2 = maleEquipModelId2; + } + + public int getFemaleEquipModelId2() { + return this.femaleEquip2; + } + + public void setFemaleEquipModelId2(int femaleEquipModelId2) { + this.femaleEquip2 = femaleEquipModelId2; + } + + public int getMaleEquipModelId3() { + return this.maleEquipModelId3; + } + + public void setMaleEquipModelId3(int maleEquipModelId3) { + this.maleEquipModelId3 = maleEquipModelId3; + } + + public int getFemaleEquipModelId3() { + return this.femaleEquipModelId3; + } + + public void setFemaleEquipModelId3(int femaleEquipModelId3) { + this.femaleEquipModelId3 = femaleEquipModelId3; + } + + public int[] getOriginalModelColors() { + return this.originalModelColors; + } + + public void setOriginalModelColors(int[] originalModelColors) { + this.originalModelColors = originalModelColors; + } + + public int[] getModifiedModelColors() { + return this.modifiedModelColors; + } + + public void setModifiedModelColors(int[] modifiedModelColors) { + this.modifiedModelColors = modifiedModelColors; + } + + public int[] getStackAmounts() { + return this.stackAmounts; + } + + public void setStackAmounts(int[] stackAmounts) { + this.stackAmounts = stackAmounts; + } + + public int[] getStackIds() { + return this.stackIds; + } + + public void setStackIds(int[] stackIds) { + this.stackIds = stackIds; + } + + public void setStackable(int stackable) { + this.stackable = stackable; + } + + public void setCost(int cost) { + this.cost = cost; + } + + public void setTeamId(int teamId) { + this.teamId = teamId; + } + + public void setMembersOnly(boolean membersOnly) { + this.membersOnly = membersOnly; + } + + public void setUnnoted(boolean unnoted) { + this.unnoted = unnoted; + } + + public void setEquipSlot(int equipSlot) { + this.equipSlot = equipSlot; + } + + public void setEquipType(int equipType) { + this.equipType = equipType; + } + + public int getSwitchLendItemId() { + return this.switchLendItemId; + } + + public void setSwitchLendItemId(int switchLendItemId) { + this.switchLendItemId = switchLendItemId; + } + + public void setLendedItemId(int lendedItemId) { + this.lendedItemId = lendedItemId; + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public void write(Store store) { + store.getIndexes()[19].putFile(this.getArchiveId(), this.getFileId(), this.encode()); + } + + private void loadItemDefinition(Store cache) { + byte[] data = cache.getIndexes()[19].getFile(this.getArchiveId(), this.getFileId()); + if(data != null) { + try { + this.readOpcodeValues(new InputStream(data)); + } catch (RuntimeException var4) { + var4.printStackTrace(); + } + + if(this.notedItemId != -1) { + this.toNote(cache); + } + + if(this.lendedItemId != -1) { + this.toLend(cache); + } + + this.loaded = true; + } + } + + private void toNote(Store store) { + ItemDefinitions realItem = getItemDefinition(store, this.switchNoteItemId); + this.membersOnly = realItem.membersOnly; + this.cost = realItem.cost; + this.name = realItem.name; + this.stackable = 1; + } + + private void toLend(Store store) { + ItemDefinitions realItem = getItemDefinition(store, this.switchLendItemId); + this.originalModelColors = realItem.originalModelColors; + this.modifiedModelColors = realItem.modifiedModelColors; + this.teamId = realItem.teamId; + this.cost = 0; + this.membersOnly = realItem.membersOnly; + this.name = realItem.name; + this.inventoryOptions = new String[5]; + this.groundOptions = realItem.groundOptions; + if(realItem.inventoryOptions != null) { + System.arraycopy(realItem.inventoryOptions, 0, this.inventoryOptions, 0, 4); + } + + this.inventoryOptions[4] = "Discard"; + this.maleEquip1 = realItem.maleEquip1; + this.maleEquip2 = realItem.maleEquip2; + this.femaleEquip1 = realItem.femaleEquip1; + this.femaleEquip2 = realItem.femaleEquip2; + this.maleEquipModelId3 = realItem.maleEquipModelId3; + this.femaleEquipModelId3 = realItem.femaleEquipModelId3; + this.equipType = realItem.equipType; + this.equipSlot = realItem.equipSlot; + } + + public int getArchiveId() { + return this.id >>> 8; + } + + public int getFileId() { + return 0xff & this.id; + } + + public boolean hasSpecialBar() { + if(this.clientScriptData == null) { + return false; + } else { + Object specialBar = this.clientScriptData.get(Integer.valueOf(686)); + return specialBar != null && specialBar instanceof Integer && ((Integer)specialBar).intValue() == 1; + } + } + + public int getRenderAnimId() { + if(this.clientScriptData == null) { + return 1426; + } else { + Object animId = this.clientScriptData.get(Integer.valueOf(644)); + return animId != null && animId instanceof Integer?((Integer)animId).intValue():1426; + } + } + + public int getQuestId() { + if(this.clientScriptData == null) { + return -1; + } else { + System.out.println(this.clientScriptData); + Object questId = this.clientScriptData.get(Integer.valueOf(861)); + return questId != null && questId instanceof Integer?((Integer)questId).intValue():-1; + } + } + + public HashMap getWearingSkillRequiriments() { + if(this.clientScriptData == null) { + return null; + } else { + HashMap skills = new HashMap(); + int nextLevel = -1; + int nextSkill = -1; + Iterator var5 = this.clientScriptData.keySet().iterator(); + + while(var5.hasNext()) { + int key = ((Integer)var5.next()).intValue(); + Object value = this.clientScriptData.get(Integer.valueOf(key)); + if(!(value instanceof String)) { + if(key == 23) { + skills.put(Integer.valueOf(4), value); + skills.put(Integer.valueOf(11), Integer.valueOf(61)); + } else if(key >= 749 && key < 797) { + if(key % 2 == 0) { + nextLevel = ((Integer)value).intValue(); + } else { + nextSkill = ((Integer)value).intValue(); + } + + if(nextLevel != -1 && nextSkill != -1) { + skills.put(Integer.valueOf(nextSkill), Integer.valueOf(nextLevel)); + nextLevel = -1; + nextSkill = -1; + } + } + } + } + + return skills; + } + } + + public void printClientScriptData() { + Iterator key2 = this.clientScriptData.keySet().iterator(); + + while(key2.hasNext()) { + int requiriments = ((Integer)key2.next()).intValue(); + Object value = this.clientScriptData.get(Integer.valueOf(requiriments)); + System.out.println("KEY: " + requiriments + ", VALUE: " + value); + } + + HashMap requiriments1 = this.getWearingSkillRequiriments(); + if(requiriments1 == null) { + System.out.println("null."); + } else { + System.out.println(requiriments1.keySet().size()); + Iterator value1 = requiriments1.keySet().iterator(); + + while(value1.hasNext()) { + int key21 = ((Integer)value1.next()).intValue(); + Object value2 = requiriments1.get(Integer.valueOf(key21)); + System.out.println("SKILL: " + key21 + ", LEVEL: " + value2); + } + + } + } + + private void setDefaultOptions() { + this.groundOptions = new String[]{null, null, "Take", null, null}; + this.inventoryOptions = new String[]{null, null, null, null, "Drop"}; + } + + private void setDefaultsVariableValules() { + this.name = "null"; + this.maleEquip1 = -1; + this.maleEquip2 = -1; + this.femaleEquip1 = -1; + this.femaleEquip2 = -1; + this.zoom2d = 2000; + this.switchLendItemId = -1; + this.lendedItemId = -1; + this.switchNoteItemId = -1; + this.notedItemId = -1; + this.floorScaleZ = 128; + this.floorScaleX = 128; + this.floorScaleY = 128; + this.cost = 1; + this.maleEquipModelId3 = -1; + this.femaleEquipModelId3 = -1; + this.teamId = -1; + this.equipType = -1; + this.equipSlot = -1; + this.primaryMaleDialogueHead = -1; + this.secondaryMaleDialogueHead = -1; + this.primaryFemaleDialogueHead = -1; + this.secondaryFemaleDialogueHead = -1; + this.Zan2d = 0; + } + + public byte[] encode() { + OutputStream stream = new OutputStream(); + stream.writeByte(1); + stream.writeBigSmart(this.modelId); + if(!this.name.equals("null") && this.notedItemId == -1) { + stream.writeByte(2); + stream.writeString(this.name); + } + + if(this.zoom2d != 2000) { + stream.writeByte(4); + stream.writeShort(this.zoom2d); + } + + if(this.xan2d != 0) { + stream.writeByte(5); + stream.writeShort(this.xan2d); + } + + if(this.yan2d != 0) { + stream.writeByte(6); + stream.writeShort(this.yan2d); + } + + int data; + if(this.xOffset2d != 0) { + stream.writeByte(7); + int translateX = this.xOffset2d; + if (translateX < -32767) { + translateX += 65536; + } + stream.writeShort(translateX); + } + + if(this.yOffset2d != 0) { + stream.writeByte(8); + int translateY = this.yOffset2d; + if (translateY < -32767) { + translateY += 65536; + } + stream.writeShort(translateY); + } + + if(this.stackable >= 1 && this.notedItemId == -1) { + stream.writeByte(11); + } + + if(this.cost != 1 && this.lendedItemId == -1) { + stream.writeByte(12); + stream.writeInt(this.cost); + } + + if(this.equipSlot != -1) { + stream.writeByte(13); + stream.writeByte(this.equipSlot); + } + + if(this.equipType != -1) { + stream.writeByte(14); + stream.writeByte(this.equipType); + } + + if(this.membersOnly && this.notedItemId == -1) { + stream.writeByte(16); + } + + if(this.maleEquip1 != -1) { + stream.writeByte(23); + stream.writeBigSmart(this.maleEquip1); + } + + if(this.maleEquip2 != -1) { + stream.writeByte(24); + stream.writeBigSmart(this.maleEquip2); + } + + if(this.femaleEquip1 != -1) { + stream.writeByte(25); + stream.writeBigSmart(this.femaleEquip1); + } + + if(this.femaleEquip2 != -1) { + stream.writeByte(26); + stream.writeBigSmart(this.femaleEquip2); + } + + for(int index = 0; index < 5; index++) { + String option = this.groundOptions[index]; + if ((index == 5 && option.equals("Examine")) || (index == 2 && option.equals("Take")) || option == null) { + continue; + } + stream.writeByte(30 + index); + stream.writeString(this.groundOptions[index]); + } + + for(int index = 0; index < 5; index++) { + String option = this.inventoryOptions[index]; + if (index == 4 && option.equals("Drop") || option == null) { + continue; + } + stream.writeByte(35 + index); + stream.writeString(this.inventoryOptions[index]); + } + + if(this.originalModelColors != null && this.modifiedModelColors != null) { + stream.writeByte(40); + stream.writeByte(this.originalModelColors.length); + + for(data = 0; data < this.originalModelColors.length; ++data) { + stream.writeShort(this.originalModelColors[data]); + stream.writeShort(this.modifiedModelColors[data]); + } + } + + if(this.originalTextureColors != null && this.modifiedTextureColors != null) { + stream.writeByte(41); + stream.writeByte(this.originalTextureColors.length); + + for(data = 0; data < this.originalTextureColors.length; ++data) { + stream.writeShort(this.originalTextureColors[data]); + stream.writeShort(this.modifiedTextureColors[data]); + } + } + + if(this.recolorPalette != null) { + stream.writeByte(42); + stream.writeByte(this.recolorPalette.length); + + for(data = 0; data < this.recolorPalette.length; ++data) { + stream.writeByte(this.recolorPalette[data]); + } + } + + if(this.unnoted) { + stream.writeByte(65); + } + + if(this.maleEquipModelId3 != -1) { + stream.writeByte(78); + stream.writeBigSmart(this.maleEquipModelId3); + } + + if(this.femaleEquipModelId3 != -1) { + stream.writeByte(79); + stream.writeBigSmart(this.femaleEquipModelId3); + } + + if (this.primaryMaleDialogueHead != -1) { + stream.writeByte(90); + stream.writeBigSmart(this.primaryMaleDialogueHead); + } + + if (this.primaryFemaleDialogueHead != -1) { + stream.writeByte(91); + stream.writeBigSmart(this.primaryFemaleDialogueHead); + } + + if (this.secondaryMaleDialogueHead != -1) { + stream.writeByte(92); + stream.writeBigSmart(this.secondaryMaleDialogueHead); + } + + if (this.secondaryFemaleDialogueHead != -1) { + stream.writeByte(93); + stream.writeBigSmart(this.secondaryFemaleDialogueHead); + } + + if (this.Zan2d != 0) { + stream.writeByte(95); + stream.writeShort(this.Zan2d); + } + + if(this.switchNoteItemId != -1) { + stream.writeByte(97); + stream.writeShort(this.switchNoteItemId); + } + + if(this.notedItemId != -1) { + stream.writeByte(98); + stream.writeShort(this.notedItemId); + } + + if(this.stackIds != null && this.stackAmounts != null) { + for(data = 0; data < this.stackIds.length; ++data) { + if(this.stackIds[data] != 0 || this.stackAmounts[data] != 0) { + stream.writeByte(100 + data); + stream.writeShort(this.stackIds[data]); + stream.writeShort(this.stackAmounts[data]); + } + } + } + + if(this.floorScaleX != 128) { + stream.writeByte(110); + stream.writeShort(this.floorScaleX); + } + + if(this.floorScaleY != 128) { + stream.writeByte(111); + stream.writeShort(this.floorScaleY); + } + + if(this.floorScaleZ != 128) { + stream.writeByte(112); + stream.writeShort(this.floorScaleZ); + } + + if(this.ambience != 0) { + stream.writeByte(113); + stream.writeByte(this.ambience); + } + + if(this.diffusion != 0) { + stream.writeByte(114); + stream.writeByte(this.diffusion); + } + + if(this.teamId != 0) { + stream.writeByte(115); + stream.writeByte(this.teamId); + } + + if(this.switchLendItemId != -1) { + stream.writeByte(121); + stream.writeShort(this.switchLendItemId); + } + + if(this.lendedItemId != -1) { + stream.writeByte(122); + stream.writeShort(this.lendedItemId); + } + + if(this.maleWieldX != 0 || this.maleWieldY != 0 || this.maleWieldZ != 0) { + stream.writeByte(125); + stream.writeByte(this.maleWieldX); + stream.writeByte(this.maleWieldY); + stream.writeByte(this.maleWieldZ); + } + + if(this.femaleWieldX != 0 || this.femaleWieldY != 0 || this.femaleWieldZ != 0) { + stream.writeByte(126); + stream.writeByte(this.femaleWieldX); + stream.writeByte(this.femaleWieldY); + stream.writeByte(this.femaleWieldZ); + } + + if(this.unknownArray2 != null) { + stream.writeByte(132); + stream.writeByte(this.unknownArray2.length); + + for(data = 0; data < this.unknownArray2.length; ++data) { + stream.writeShort(this.unknownArray2[data]); + } + } + + if(this.clientScriptData != null) { + stream.writeByte(249); + stream.writeByte(this.clientScriptData.size()); + Iterator var5 = this.clientScriptData.keySet().iterator(); + + while(var5.hasNext()) { + data = ((Integer)var5.next()).intValue(); + Object value2 = this.clientScriptData.get(Integer.valueOf(data)); + stream.writeByte(value2 instanceof String?1:0); + stream.write24BitInt(data); + if(value2 instanceof String) { + stream.writeString((String)value2); + } else { + stream.writeInt(((Integer)value2).intValue()); + } + } + } + + stream.writeByte(0); + byte[] var6 = new byte[stream.getOffset()]; + stream.setOffset(0); + stream.getBytes(var6, 0, var6.length); + return var6; + } + + public int getInvModelId() { + return this.modelId; + } + + public void setInvModelId(int modelId) { + this.modelId = modelId; + } + + public int getInvModelZoom() { + return this.zoom2d; + } + + public void setInvModelZoom(int modelZoom) { + this.zoom2d = modelZoom; + } + + private final void readValues(InputStream stream, int opcode) { + if(opcode == 1) { + this.modelId = stream.readUnsignedShort();//stream.readBigSmart(); + } else if(opcode == 2) { + this.name = stream.readString(); + } else if(opcode == 4) { + this.zoom2d = stream.readUnsignedShort(); + } else if(opcode == 5) { + this.xan2d = stream.readUnsignedShort(); + } else if(opcode == 6) { + this.yan2d = stream.readUnsignedShort(); + } else if(opcode == 7) { + this.xOffset2d = stream.readUnsignedShort(); + if(this.xOffset2d > Short.MAX_VALUE) { + //if(this.modelOffset1 > 32767) { + this.xOffset2d -= 65536; + } + + } else if(opcode == 8) { + this.yOffset2d = stream.readUnsignedShort(); + if(this.yOffset2d > Short.MAX_VALUE) { + //if(this.modelOffset2 > 32767) { + this.yOffset2d -= 65536; + } + + } else if(opcode == 11) { + this.stackable = 1; + } else if(opcode == 12) { + this.cost = stream.readInt(); + } else if(opcode == 13) { + this.equipSlot = stream.readUnsignedByte(); + } else if(opcode == 14) { + this.equipType = stream.readUnsignedByte(); + } else if(opcode == 16) { + this.membersOnly = true; + } else if(opcode == 18) { + stream.readUnsignedShortLE(); + } else if(opcode == 23) { + this.maleEquip1 = stream.readUnsignedShort();//stream.readBigSmart(); + } else if(opcode == 24) { + this.maleEquip2 = stream.readUnsignedShort();//stream.readBigSmart(); + } else if(opcode == 25) { + this.femaleEquip1 = stream.readUnsignedShort();//stream.readBigSmart(); + } else if(opcode == 26) { + this.femaleEquip2 = stream.readUnsignedShort();//stream.readBigSmart(); + } else if(opcode == 27) { + stream.readUnsignedByte(); + } else if(opcode >= 30 && opcode < 35) { + this.groundOptions[opcode - 30] = stream.readString(); + } else if(opcode >= 35 && opcode < 40) { + this.inventoryOptions[opcode - 35] = stream.readString(); + } else { + int length; + int index; + if(opcode == 40) { + length = stream.readUnsignedByte(); + this.originalModelColors = new int[length]; + this.modifiedModelColors = new int[length]; + + for(index = 0; index < length; ++index) { + this.originalModelColors[index] = stream.readUnsignedShort(); + this.modifiedModelColors[index] = stream.readUnsignedShort(); + } + } else if(opcode == 41) { + length = stream.readUnsignedByte(); + this.originalTextureColors = new short[length]; + this.modifiedTextureColors = new short[length]; + + for(index = 0; index < length; ++index) { + this.originalTextureColors[index] = (short)stream.readUnsignedShort(); + this.modifiedTextureColors[index] = (short)stream.readUnsignedShort(); + } + } else if(opcode == 42) { + length = stream.readUnsignedByte(); + this.recolorPalette = new byte[length]; + + for(index = 0; index < length; ++index) { + this.recolorPalette[index] = (byte)stream.readByte(); + } + } else if(opcode == 65) { + this.unnoted = true; + } else if(opcode == 78) { + this.maleEquipModelId3 = stream.readUnsignedShort();//stream.readBigSmart(); + } else if(opcode == 79) { + this.femaleEquipModelId3 = stream.readUnsignedShort();//stream.readBigSmart(); + } else if(opcode == 90) { + this.primaryMaleDialogueHead = stream.readUnsignedShort();//stream.readBigSmart(); + } else if(opcode == 91) { + this.primaryFemaleDialogueHead = stream.readUnsignedShort();//stream.readBigSmart(); + } else if(opcode == 92) { + this.secondaryMaleDialogueHead = stream.readUnsignedShort();//stream.readBigSmart(); + } else if(opcode == 93) { + this.secondaryFemaleDialogueHead = stream.readUnsignedShort();//stream.readBigSmart(); + } else if(opcode == 95) { + this.Zan2d = stream.readUnsignedShort(); + } else if(opcode == 96) { + this.dummyItem = stream.readUnsignedByte(); + } else if(opcode == 97) { + this.switchNoteItemId = stream.readUnsignedShort(); + } else if(opcode == 98) { + this.notedItemId = stream.readUnsignedShort(); + } else if(opcode >= 100 && opcode < 110) { + if(this.stackIds == null) { + this.stackIds = new int[10]; + this.stackAmounts = new int[10]; + } + + this.stackIds[opcode - 100] = stream.readUnsignedShort(); + this.stackAmounts[opcode - 100] = stream.readUnsignedShort(); + } else if(opcode == 110) { + this.floorScaleX = stream.readUnsignedShort(); + } else if(opcode == 111) { + this.floorScaleY = stream.readUnsignedShort(); + } else if(opcode == 112) { + this.floorScaleZ = stream.readUnsignedShort(); + } else if(opcode == 113) { + this.ambience = stream.readByte(); + } else if(opcode == 114) { + this.diffusion = stream.readByte(); + } else if(opcode == 115) { + this.teamId = stream.readUnsignedByte(); + } else if(opcode == 121) { + this.switchLendItemId = stream.readUnsignedShort(); + } else if(opcode == 122) { + this.lendedItemId = stream.readUnsignedShort(); + } else if(opcode == 125) { + this.maleWieldX = stream.readByte(); + this.maleWieldY = stream.readByte(); + this.maleWieldZ = stream.readByte(); + } else if(opcode == 126) { + this.femaleWieldX = stream.readByte(); + this.femaleWieldY = stream.readByte(); + this.femaleWieldZ = stream.readByte(); + } else if(opcode == 127) { + this.unknownInt18 = stream.readUnsignedByte(); + this.unknownInt19 = stream.readUnsignedShort(); + } else if(opcode == 128) { + this.unknownInt20 = stream.readUnsignedByte(); + this.unknownInt21 = stream.readUnsignedShort(); + } else if(opcode == 129) { + this.unknownInt20 = stream.readUnsignedByte(); + this.unknownInt21 = stream.readUnsignedShort(); + } else if(opcode == 130) { + this.unknownInt22 = stream.readUnsignedByte(); + this.unknownInt23 = stream.readUnsignedShort(); + } else if(opcode == 132) { + length = stream.readUnsignedByte(); + this.unknownArray2 = new int[length]; + + for(index = 0; index < length; ++index) { + this.unknownArray2[index] = stream.readUnsignedShort(); + } + } else if(opcode == 134) { + stream.readUnsignedByte(); + } else if(opcode == 139) { + this.unknownValue2 = stream.readUnsignedShort(); + } else if(opcode == 140) { + this.unknownValue1 = stream.readUnsignedShort(); + }else if (opcode == 191) { + //int opcode191 = 0; + }else if (opcode == 218) { + //int opcode218 = 0; + }else if (opcode == 219) { + //int opcode219 = 0; + } else if(opcode == 249) { + length = stream.readUnsignedByte(); + if(this.clientScriptData == null) { + this.clientScriptData = new HashMap(length); + } + + for(index = 0; index < length; ++index) { + boolean stringInstance = stream.readUnsignedByte() == 1; + int key = stream.read24BitInt(); + Object value = stringInstance?stream.readString():Integer.valueOf(stream.readInt()); + this.clientScriptData.put(Integer.valueOf(key), value); + } + //} + } else { + throw new RuntimeException("MISSING OPCODE " + opcode + " FOR ITEM " + this.id); + } + } + + } + + private void readOpcodeValues(InputStream stream) { + while(true) { + int opcode = stream.readUnsignedByte(); + if(opcode == 0) { + return; + } + + this.readValues(stream, opcode); + } + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public void resetTextureColors() { + this.originalTextureColors = null; + this.modifiedTextureColors = null; + } + + public boolean isWearItem() { + return this.equipSlot != -1; + } + + public boolean isMembersOnly() { + return this.membersOnly; + } + + public void changeTextureColor(short originalModelColor, short modifiedModelColor) { + if(this.originalTextureColors != null) { + for(int newOriginalModelColors = 0; newOriginalModelColors < this.originalTextureColors.length; ++newOriginalModelColors) { + if(this.originalTextureColors[newOriginalModelColors] == originalModelColor) { + this.modifiedTextureColors[newOriginalModelColors] = modifiedModelColor; + return; + } + } + + short[] var5 = Arrays.copyOf(this.originalTextureColors, this.originalTextureColors.length + 1); + short[] newModifiedModelColors = Arrays.copyOf(this.modifiedTextureColors, this.modifiedTextureColors.length + 1); + var5[var5.length - 1] = originalModelColor; + newModifiedModelColors[newModifiedModelColors.length - 1] = modifiedModelColor; + this.originalTextureColors = var5; + this.modifiedTextureColors = newModifiedModelColors; + } else { + this.originalTextureColors = new short[]{originalModelColor}; + this.modifiedTextureColors = new short[]{modifiedModelColor}; + } + + } + + public void resetModelColors() { + this.originalModelColors = null; + this.modifiedModelColors = null; + } + + public void changeModelColor(int originalModelColor, int modifiedModelColor) { + if(this.originalModelColors != null) { + for(int newOriginalModelColors = 0; newOriginalModelColors < this.originalModelColors.length; ++newOriginalModelColors) { + if(this.originalModelColors[newOriginalModelColors] == originalModelColor) { + this.modifiedModelColors[newOriginalModelColors] = modifiedModelColor; + return; + } + } + + int[] var5 = Arrays.copyOf(this.originalModelColors, this.originalModelColors.length + 1); + int[] newModifiedModelColors = Arrays.copyOf(this.modifiedModelColors, this.modifiedModelColors.length + 1); + var5[var5.length - 1] = originalModelColor; + newModifiedModelColors[newModifiedModelColors.length - 1] = modifiedModelColor; + this.originalModelColors = var5; + this.modifiedModelColors = newModifiedModelColors; + } else { + this.originalModelColors = new int[]{originalModelColor}; + this.modifiedModelColors = new int[]{modifiedModelColor}; + } + + } + + public String[] getGroundOptions() { + return this.groundOptions; + } + + public String[] getInventoryOptions() { + return this.inventoryOptions; + } + + public int getEquipSlot() { + return this.equipSlot; + } + + public int getEquipType() { + return this.equipType; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException var2) { + var2.printStackTrace(); + return null; + } + } + + public String toString() { + return this.id + " - " + this.name; + } +} diff --git a/src/com/alex/loaders/npcs/NPCDefinitions.java b/src/com/alex/loaders/npcs/NPCDefinitions.java new file mode 100644 index 0000000..ab42c8f --- /dev/null +++ b/src/com/alex/loaders/npcs/NPCDefinitions.java @@ -0,0 +1,1252 @@ +package com.alex.loaders.npcs; + +import com.alex.io.InputStream; +import com.alex.io.OutputStream; +import com.alex.store.Store; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.concurrent.ConcurrentHashMap; + +public final class NPCDefinitions implements Cloneable { + private static final ConcurrentHashMap npcDefinitions = new ConcurrentHashMap(); + public boolean loaded; + public int id; + //public HashMap parameters; + public int unknownInt13; + public int unknownInt6; + public int unknownInt15; + public byte respawnDirection; + public int size = 1; + public int[][] unknownArray3; + public boolean unknownBoolean2; + public int unknownInt9; + public int unknownInt4; + public int[] unknownArray2; + public int unknownInt7; + public int renderEmote; + public boolean unknownBoolean5 = false; + public int unknownInt20; + public byte unknownByte1; + public boolean unknownBoolean3; + public int unknownInt3; + public byte unknownByte2; + public boolean unknownBoolean6; + public boolean unknownBoolean4; + public int[] originalModelColors; + public int combatLevel; + public byte[] unknownArray1; + public short unknownShort1; + public boolean unknownBoolean1; + public int npcHeight; + public String name; + public int[] modifiedTextureColors; + public byte walkMask; + public int[] modelIds; + public int unknownInt1; + public int unknownInt21; + public int unknownInt11; + public int unknownInt17; + public int unknownInt14; + public int unknownInt12; + public int unknownInt8; + public int headIcons; + public int unknownInt19; + public int[] originalTextureColors; + public int[][] anIntArrayArray882; + public int unknownInt10; + public int[] unknownArray4; + public int unknownInt5; + public int unknownInt16; + public boolean isVisibleOnMap; + public int[] npcChatHeads; + public short unknownShort2; + public String[] options; + public int[] modifiedModelColors; + public int unknownInt2; + public int npcWidth; + public int npcId; + public int unknownInt18; + public boolean unknownBoolean7; + public int[] unknownArray5; + public HashMap clientScriptData; + public int anInt833; + public int anInt836; + public int anInt837; + public int[][] anIntArrayArray840; + public boolean aBoolean841; + public int anInt842; + public int bConfig; + public int[] transformTo; + public int anInt846; + public boolean aBoolean849 = false; + public int anInt850; + public byte aByte851; + public boolean aBoolean852; + public int anInt853; + public byte aByte854; + public boolean aBoolean856; + public boolean aBoolean857; + public short[] aShortArray859; + public byte[] aByteArray861; + public short aShort862; + public boolean aBoolean863; + public int anInt864; + public short[] aShortArray866; + public int anInt869; + public int anInt870; + public int anInt871; + public int anInt872; + public int anInt874; + public int anInt875; + public int anInt876; + public int anInt879; + public short[] aShortArray880; + public int anInt884; + public int[] anIntArray885; + public int config; + public int anInt889; + public int[] anIntArray892; + public short aShort894; + public short[] aShortArray896; + public int anInt897; + public int anInt899; + public int anInt901; + public boolean aBoolean3190; + private byte[] aByteArray1293; + private byte[] aByteArray12930; + private int[] anIntArray2930; + + public static NPCDefinitions getNPCDefinitions(int id, Store store) { + NPCDefinitions def = (NPCDefinitions)npcDefinitions.get(Integer.valueOf(id)); + if(def == null) { + def = new NPCDefinitions(id); + def.method694(); + byte[] data = store.getIndexes()[18].getFile(id >>> 134238215, id & 127); + if(data != null) { + def.readValueLoop(new InputStream(data)); + } + + npcDefinitions.put(Integer.valueOf(id), def); + } + + return def; + } + + public static NPCDefinitions getNPCDefinition(Store cache, int npcId) { + return getNPCDefinition(cache, npcId, true); + } + + public static NPCDefinitions getNPCDefinition(Store cache, int npcId, boolean load) { + return new NPCDefinitions(cache, npcId, load); + } + + public NPCDefinitions(Store cache, int id, boolean load) { + this.id = id; + this.setDefaultVariableValues(); + this.setDefaultOptions(); + if(load) { + this.loadNPCDefinition(cache); + } + + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException var2) { + var2.printStackTrace(); + return null; + } + } + + private void setDefaultOptions() { + this.options = new String[]{"Talk-to", null, null, null, null}; + } + + private void setDefaultVariableValues() { + this.name = "null"; + this.combatLevel = 0; + this.isVisibleOnMap = true; + this.renderEmote = -1; + this.respawnDirection = 7; + //this.size = 1; + this.unknownInt9 = -1; + this.unknownInt4 = -1; + this.unknownInt15 = -1; + this.unknownInt7 = -1; + this.unknownInt3 = 32; + this.unknownInt6 = -1; + this.unknownInt1 = 0; + this.walkMask = 0; + this.unknownInt20 = 255; + this.unknownInt11 = -1; + this.unknownBoolean3 = true; + this.unknownShort1 = 0; + this.unknownInt8 = -1; + this.unknownByte1 = -96; + this.unknownInt12 = 0; + this.unknownInt17 = -1; + this.unknownBoolean4 = true; + this.unknownInt21 = -1; + this.unknownInt14 = -1; + this.unknownInt13 = -1; + this.npcHeight = 128; + this.headIcons = -1; + this.unknownBoolean6 = false; + this.unknownInt5 = -1; + this.unknownByte2 = -16; + this.unknownBoolean1 = false; + this.unknownInt16 = -1; + this.unknownInt10 = -1; + this.unknownBoolean2 = true; + this.unknownInt19 = -1; + this.npcWidth = 128; + this.unknownShort2 = 0; + this.unknownInt2 = 0; + this.unknownInt18 = -1; + } + + private void loadNPCDefinition(Store cache) { + byte[] data = cache.getIndexes()[18].getFile(this.getArchiveId(), this.getFileId()); + if(data != null) { + try { + this.readOpcodeValues(new InputStream(data)); + } catch (RuntimeException var4) { + var4.printStackTrace(); + } + + this.loaded = true; + } + + } + + private void readOpcodeValues(InputStream stream) { + while(true) { + int opcode = stream.readUnsignedByte(); + if(opcode == 0) { + return; + } + + this.readValues(stream, opcode); + } + } + + public int getArchiveId() { + return this.id >>> 134238215; + } + + public int getFileId() { + return 127 & this.id; + } + + public void write(Store store) { + store.getIndexes()[18].putFile(this.getArchiveId(), this.getFileId(), this.encode()); + } + + public void method694() { + if(this.modelIds == null) { + this.modelIds = new int[0]; + } + + } + + private void readValueLoop(InputStream stream) { + while(true) { + int opcode = stream.readUnsignedByte(); + if(opcode == 0) { + return; + } + + this.readValues2(stream, opcode); + } + } + + private void readValues2(InputStream stream, int opcode) { + if (opcode != 1) { + if (opcode == 2) + name = stream.readString(); + else if ((opcode ^ 0xffffffff) != -13) { + if (opcode >= 30 && (opcode ^ 0xffffffff) > -36) { + options[opcode - 30] = stream.readString(); + if (options[-30 + opcode].equalsIgnoreCase("Hidden")) + options[-30 + opcode] = null; + } else if ((opcode ^ 0xffffffff) != -41) { + if (opcode == 41) { + int i = stream.readUnsignedByte(); + aShortArray880 = new short[i]; + aShortArray866 = new short[i]; + for (int i_54_ = 0; (i_54_ ^ 0xffffffff) > (i ^ 0xffffffff); i_54_++) { + aShortArray880[i_54_] = (short) stream.readUnsignedShort(); + aShortArray866[i_54_] = (short) stream.readUnsignedShort(); + } + } else if (opcode == 44) { + int i_24_ = (short) stream.readUnsignedShort(); + int i_25_ = 0; + for (int i_26_ = i_24_; i_26_ > 0; i_26_ >>= 1) + i_25_++; + // aByteArray12930 = new byte[i_25_]; + byte i_27_ = 0; + for (int i_28_ = 0; i_28_ < i_25_; i_28_++) { + if ((i_24_ & 1 << i_28_) > 0) { + // aByteArray12930[i_28_] = i_27_; + i_27_++; + } + // aByteArray12930[i_28_] = (byte) -1; + } + } else if (45 == opcode) { + int i_29_ = (short) stream.readUnsignedShort(); + int i_30_ = 0; + for (int i_31_ = i_29_; i_31_ > 0; i_31_ >>= 1) + i_30_++; + // aByteArray1293 = new byte[i_30_]; + byte i_32_ = 0; + for (int i_33_ = 0; i_33_ < i_30_; i_33_++) { + if ((i_29_ & 1 << i_33_) > 0) { + // aByteArray1293[i_33_] = i_32_; + i_32_++; + } + // aByteArray1293[i_33_] = (byte) -1; + } + } else if ((opcode ^ 0xffffffff) == -43) { + int i = stream.readUnsignedByte(); + aByteArray861 = new byte[i]; + for (int i_55_ = 0; i > i_55_; i_55_++) + aByteArray861[i_55_] = (byte) stream.readByte(); + } else if ((opcode ^ 0xffffffff) != -61) { + if (opcode == 93) + isVisibleOnMap = false; + else if ((opcode ^ 0xffffffff) == -96) + combatLevel = stream.readUnsignedShort(); + else if (opcode != 97) { + if ((opcode ^ 0xffffffff) == -99) + anInt899 = stream.readUnsignedShort(); + else if ((opcode ^ 0xffffffff) == -100) + aBoolean863 = true; + else if (opcode == 100) + anInt869 = stream.readByte(); + else if ((opcode ^ 0xffffffff) == -102) + anInt897 = stream.readByte() * 5; + else if ((opcode ^ 0xffffffff) == -103) + headIcons = stream.readUnsignedShort(); + else if (opcode != 103) { + if (opcode == 106 || opcode == 118) { + bConfig = stream.readUnsignedShort(); + if (bConfig == 65535) + bConfig = -1; + config = stream.readUnsignedShort(); + if (config == 65535) + config = -1; + int i = -1; + if ((opcode ^ 0xffffffff) == -119) { + i = stream.readUnsignedShort(); + if ((i ^ 0xffffffff) == -65536) + i = -1; + } + int i_56_ = stream.readUnsignedByte(); + transformTo = new int[2 + i_56_]; + for (int i_57_ = 0; i_56_ >= i_57_; i_57_++) { + transformTo[i_57_] = stream.readUnsignedShort(); + if (transformTo[i_57_] == 65535) + transformTo[i_57_] = -1; + } + transformTo[i_56_ - -1] = i; + } else if ((opcode ^ 0xffffffff) != -108) { + if ((opcode ^ 0xffffffff) == -110) + aBoolean852 = false; + else if ((opcode ^ 0xffffffff) != -112) { + if (opcode != 113) { + if (opcode == 114) { + aByte851 = (byte) (stream.readByte()); + aByte854 = (byte) (stream.readByte()); + } else if (opcode == 115) { + stream.readUnsignedByte(); + stream.readUnsignedByte(); + } else if ((opcode ^ 0xffffffff) != -120) { + if (opcode != 121) { + if ((opcode ^ 0xffffffff) != -123) { + if (opcode == 123) + anInt846 = (stream.readUnsignedShort()); + else if (opcode != 125) { + if (opcode == 127) + renderEmote = (stream.readUnsignedShort()); + else if ((opcode ^ 0xffffffff) == -129) + stream.readUnsignedByte(); + else if (opcode != 134) { + if (opcode == 135) { + anInt833 = stream.readUnsignedByte(); + anInt874 = stream.readUnsignedShort(); + } else if (opcode != 136) { + if (opcode != 137) { + if (opcode != 138) { + if ((opcode ^ 0xffffffff) != -140) { + if (opcode == 140) + anInt850 = stream.readUnsignedByte(); + else if (opcode == 141) + aBoolean849 = true; + else if ((opcode ^ 0xffffffff) != -143) { + if (opcode == 143) + aBoolean856 = true; + else if ((opcode ^ 0xffffffff) <= -151 && opcode < 155) { + options[opcode - 150] = stream.readString(); + if (options[opcode - 150].equalsIgnoreCase("Hidden")) + options[opcode + -150] = null; + } else if ((opcode ^ 0xffffffff) == -161) { + int i = stream.readUnsignedByte(); + anIntArray885 = new int[i]; + for (int i_58_ = 0; i > i_58_; i_58_++) + anIntArray885[i_58_] = stream.readUnsignedShort(); + + // all + // added + // after + // here + } else if (opcode == 155) { + int aByte821 = stream.readByte(); + int aByte824 = stream.readByte(); + int aByte843 = stream.readByte(); + int aByte855 = stream.readByte(); + } else if (opcode == 158) { + byte aByte833 = (byte) 1; + } else if (opcode == 159) { + byte aByte833 = (byte) 0; + } else if (opcode == 162) { // added + // opcode + // aBoolean3190 + // = + // true; + } else if (opcode == 163) { // added + // opcode + int anInt864 = stream.readUnsignedByte(); + } else if (opcode == 164) { + int anInt848 = stream.readUnsignedShort(); + int anInt837 = stream.readUnsignedShort(); + } else if (opcode == 165) { + int anInt847 = stream.readUnsignedByte(); + } else if (opcode == 168) { + int anInt828 = stream.readUnsignedByte(); + } else if (opcode >= 170 && opcode < 176) { + // if + // (null + // == + // anIntArray2930) + // { + // anIntArray2930 + // = + // new + // int[6]; + // Arrays.fill(anIntArray2930, + // -1); + // } + int i_44_ = (short) stream.readUnsignedShort(); + if (i_44_ == 65535) + i_44_ = -1; + // anIntArray2930[opcode + // - + // 170] + // = + // i_44_; + } else if (opcode == 12) { + size = stream.readUnsignedByte(); + } else if (opcode == 249) { + int i = stream.readUnsignedByte(); + if (clientScriptData == null) { + clientScriptData = new HashMap(i); + } + for (int i_60_ = 0; i > i_60_; i_60_++) { + boolean stringInstance = stream.readUnsignedByte() == 1; + int key = stream.read24BitInt(); + Object value; + if (stringInstance) + value = stream.readString(); + else + value = stream.readInt(); + clientScriptData.put(key, value); + } + } + } else + anInt870 = stream.readUnsignedShort(); + } else + anInt879 = stream.readBigSmart(); + } else + anInt901 = stream.readBigSmart(); + } else + anInt872 = stream.readUnsignedShort(); + } else { + anInt837 = stream.readUnsignedByte(); + anInt889 = stream.readUnsignedShort(); + } + } else { + anInt876 = (stream.readUnsignedShort()); + if (anInt876 == 65535) + anInt876 = -1; + anInt842 = (stream.readUnsignedShort()); + if (anInt842 == 65535) + anInt842 = -1; + anInt884 = (stream.readUnsignedShort()); + if ((anInt884 ^ 0xffffffff) == -65536) + anInt884 = -1; + anInt871 = (stream.readUnsignedShort()); + if ((anInt871 ^ 0xffffffff) == -65536) + anInt871 = -1; + anInt875 = (stream.readUnsignedByte()); + } + } else + respawnDirection = (byte) (stream.readByte()); + } else + anInt836 = (stream.readBigSmart()); + } else { + anIntArrayArray840 = (new int[modelIds.length][]); + int i = (stream.readUnsignedByte()); + for (int i_62_ = 0; ((i_62_ ^ 0xffffffff) > (i ^ 0xffffffff)); i_62_++) { + int i_63_ = (stream.readUnsignedByte()); + int[] is = (anIntArrayArray840[i_63_] = (new int[3])); + is[0] = (stream.readByte()); + is[1] = (stream.readByte()); + is[2] = (stream.readByte()); + } + } + } else + walkMask = (byte) (stream.readByte()); + } else { + aShort862 = (short) (stream.readUnsignedShort()); + aShort894 = (short) (stream.readUnsignedShort()); + } + } else + aBoolean857 = false; + } else + aBoolean841 = false; + } else + anInt853 = stream.readUnsignedShort(); + } else + anInt864 = stream.readUnsignedShort(); + } else { + int i = stream.readUnsignedByte(); + anIntArray892 = new int[i]; + for (int i_64_ = 0; (i_64_ ^ 0xffffffff) > (i ^ 0xffffffff); i_64_++) + anIntArray892[i_64_] = stream.readBigSmart(); + } + } else { + int i = stream.readUnsignedByte(); + aShortArray859 = new short[i]; + aShortArray896 = new short[i]; + for (int i_65_ = 0; (i ^ 0xffffffff) < (i_65_ ^ 0xffffffff); i_65_++) { + aShortArray896[i_65_] = (short) stream.readUnsignedShort(); + aShortArray859[i_65_] = (short) stream.readUnsignedShort(); + } + } + //} else + //size = stream.readUnsignedByte(); + } else { + int i = stream.readUnsignedByte(); + modelIds = new int[i]; + for (int i_66_ = 0; i_66_ < i; i_66_++) { + modelIds[i_66_] = stream.readBigSmart(); + if ((modelIds[i_66_] ^ 0xffffffff) == -65536) + modelIds[i_66_] = -1; + } + } + } + } + + private void readValues(InputStream stream, int opcode) { + int i; + int i_66_; + if(opcode != 1) { + if(opcode == 2) { + this.name = stream.readString(); + } else if(~opcode != -13) { + if(opcode >= 30 && ~opcode > -36) { + this.options[opcode - 30] = stream.readString(); + if(this.options[-30 + opcode].equalsIgnoreCase("Hidden")) { + this.options[-30 + opcode] = null; + } + } else if(~opcode != -41) { + if(opcode == 41) { + i = stream.readUnsignedByte(); + this.aShortArray880 = new short[i]; + this.aShortArray866 = new short[i]; + + for(i_66_ = 0; ~i_66_ > ~i; ++i_66_) { + this.aShortArray880[i_66_] = (short)stream.readUnsignedShort(); + this.aShortArray866[i_66_] = (short)stream.readUnsignedShort(); + } + } else { + int i_63_; + int is; + short var8; + byte var9; + if(opcode == 44) { + var8 = (short)stream.readUnsignedShort(); + i_66_ = 0; + + for(i_63_ = var8; i_63_ > 0; i_63_ >>= 1) { + ++i_66_; + } + + this.aByteArray12930 = new byte[i_66_]; + var9 = 0; + + for(is = 0; is < i_66_; ++is) { + if((var8 & 1 << is) > 0) { + this.aByteArray12930[is] = var9++; + } else { + this.aByteArray12930[is] = -1; + } + } + } else if(45 == opcode) { + var8 = (short)stream.readUnsignedShort(); + i_66_ = 0; + + for(i_63_ = var8; i_63_ > 0; i_63_ >>= 1) { + ++i_66_; + } + + this.aByteArray1293 = new byte[i_66_]; + var9 = 0; + + for(is = 0; is < i_66_; ++is) { + if((var8 & 1 << is) > 0) { + this.aByteArray1293[is] = var9++; + } else { + this.aByteArray1293[is] = -1; + } + } + } else if(~opcode == -43) { + i = stream.readUnsignedByte(); + this.aByteArray861 = new byte[i]; + + for(i_66_ = 0; i > i_66_; ++i_66_) { + this.aByteArray861[i_66_] = (byte)stream.readByte(); + } + } else if(~opcode != -61) { + if(opcode == 93) { + this.isVisibleOnMap = false; + } else if(~opcode == -96) { + this.combatLevel = stream.readUnsignedShort(); + } else if(opcode != 97) { + if(~opcode == -99) { + this.anInt899 = stream.readUnsignedShort(); + } else if(~opcode == -100) { + this.aBoolean863 = true; + } else if(opcode == 100) { + this.anInt869 = stream.readByte(); + } else if(~opcode == -102) { + this.anInt897 = stream.readByte() * 5; + } else if(~opcode == -103) { + this.headIcons = stream.readUnsignedShort(); + } else if(opcode != 103) { + if(opcode != 106 && opcode != 118) { + if(~opcode != -108) { + if(~opcode == -110) { + this.aBoolean852 = false; + } else if(~opcode != -112) { + if(opcode != 113) { + if(opcode == 114) { + this.aByte851 = (byte)stream.readByte(); + this.aByte854 = (byte)stream.readByte(); + } else if(opcode == 115) { + stream.readUnsignedByte(); + stream.readUnsignedByte(); + } else if(~opcode != -120) { + if(opcode != 121) { + if(~opcode != -123) { + if(opcode == 123) { + this.anInt846 = stream.readUnsignedShort(); + } else if(opcode != 125) { + if(opcode == 127) { + this.renderEmote = stream.readUnsignedShort(); + } else if(~opcode == -129) { + stream.readUnsignedByte(); + } else if(opcode != 134) { + if(opcode == 135) { + this.anInt833 = stream.readUnsignedByte(); + this.anInt874 = stream.readUnsignedShort(); + } else if(opcode != 136) { + if(opcode != 137) { + if(opcode != 138) { + if(~opcode != -140) { + if(opcode == 140) { + this.anInt850 = stream.readUnsignedByte(); + } else if(opcode == 141) { + this.aBoolean849 = true; + } else if(~opcode != -143) { + if(opcode == 143) { + this.aBoolean856 = true; + } else if(~opcode <= -151 && opcode < 155) { + this.options[opcode - 150] = stream.readString(); + if(this.options[opcode - 150].equalsIgnoreCase("Hidden")) { + this.options[opcode + -150] = null; + } + } else if(~opcode == -161) { + i = stream.readUnsignedByte(); + this.anIntArray885 = new int[i]; + + for(i_66_ = 0; i > i_66_; ++i_66_) { + this.anIntArray885[i_66_] = stream.readUnsignedShort(); + } + } else if(opcode == 155) { + i = stream.readByte(); + i_66_ = stream.readByte(); + i_63_ = stream.readByte(); + is = stream.readByte(); + } else { + boolean var10; + if(opcode == 158) { + var10 = true; + } else if(opcode == 159) { + var10 = false; + } else if(opcode == 162) { + this.aBoolean3190 = true; + } else if(opcode == 163) { + i = stream.readUnsignedByte(); + } else if(opcode == 164) { + i = stream.readUnsignedShort(); + i_66_ = stream.readUnsignedShort(); + } else if(opcode == 165) { + i = stream.readUnsignedByte(); + } else if(opcode == 168) { + i = stream.readUnsignedByte(); + } else if(opcode >= 170 && opcode < 176) { + if(this.anIntArray2930 == null) { + this.anIntArray2930 = new int[6]; + Arrays.fill(this.anIntArray2930, -1); + } + + var8 = (short)stream.readUnsignedShort(); + if(var8 == '\uffff') { + var8 = -1; + } + + this.anIntArray2930[opcode - 170] = var8; + } else if(opcode == 249) { + i = stream.readUnsignedByte(); + if(this.clientScriptData == null) { + this.clientScriptData = new HashMap(i); + } + + for(i_66_ = 0; i > i_66_; ++i_66_) { + boolean var12 = stream.readUnsignedByte() == 1; + is = stream.read24BitInt(); + Object value; + if(var12) { + value = stream.readString(); + } else { + value = Integer.valueOf(stream.readInt()); + } + + this.clientScriptData.put(Integer.valueOf(is), value); + } + } + } + } else { + this.anInt870 = stream.readUnsignedShort(); + } + } else { + this.anInt879 = stream.readBigSmart(); + } + } else { + this.anInt901 = stream.readBigSmart(); + } + } else { + this.anInt872 = stream.readUnsignedShort(); + } + } else { + this.anInt837 = stream.readUnsignedByte(); + this.anInt889 = stream.readUnsignedShort(); + } + } else { + this.anInt876 = stream.readUnsignedShort(); + if(this.anInt876 == '\uffff') { + this.anInt876 = -1; + } + + this.anInt842 = stream.readUnsignedShort(); + if(this.anInt842 == '\uffff') { + this.anInt842 = -1; + } + + this.anInt884 = stream.readUnsignedShort(); + if(~this.anInt884 == -65536) { + this.anInt884 = -1; + } + + this.anInt871 = stream.readUnsignedShort(); + if(~this.anInt871 == -65536) { + this.anInt871 = -1; + } + + this.anInt875 = stream.readUnsignedByte(); + } + } else { + this.respawnDirection = (byte)stream.readByte(); + } + } else { + this.anInt836 = stream.readBigSmart(); + } + } else { + this.anIntArrayArray840 = new int[this.modelIds.length][]; + i = stream.readUnsignedByte(); + + for(i_66_ = 0; ~i_66_ > ~i; ++i_66_) { + i_63_ = stream.readUnsignedByte(); + int[] var11 = this.anIntArrayArray840[i_63_] = new int[3]; + var11[0] = stream.readByte(); + var11[1] = stream.readByte(); + var11[2] = stream.readByte(); + } + } + } else { + this.walkMask = (byte)stream.readByte(); + } + } else { + this.aShort862 = (short)stream.readUnsignedShort(); + this.aShort894 = (short)stream.readUnsignedShort(); + } + } else { + this.aBoolean857 = false; + } + } else { + this.aBoolean841 = false; + } + } else { + this.bConfig = stream.readUnsignedShort(); + if(this.bConfig == '\uffff') { + this.bConfig = -1; + } + + this.config = stream.readUnsignedShort(); + if(this.config == '\uffff') { + this.config = -1; + } + + i = -1; + if(~opcode == -119) { + i = stream.readUnsignedShort(); + if(~i == -65536) { + i = -1; + } + } + + i_66_ = stream.readUnsignedByte(); + this.transformTo = new int[2 + i_66_]; + + for(i_63_ = 0; i_66_ >= i_63_; ++i_63_) { + this.transformTo[i_63_] = stream.readUnsignedShort(); + if(this.transformTo[i_63_] == '\uffff') { + this.transformTo[i_63_] = -1; + } + } + + this.transformTo[i_66_ - -1] = i; + } + } else { + this.anInt853 = stream.readUnsignedShort(); + } + } else { + this.anInt864 = stream.readUnsignedShort(); + } + } else { + i = stream.readUnsignedByte(); + this.anIntArray892 = new int[i]; + + for(i_66_ = 0; ~i_66_ > ~i; ++i_66_) { + this.anIntArray892[i_66_] = stream.readBigSmart(); + } + } + } + } else { + i = stream.readUnsignedByte(); + this.aShortArray859 = new short[i]; + this.aShortArray896 = new short[i]; + + for(i_66_ = 0; ~i < ~i_66_; ++i_66_) { + this.aShortArray896[i_66_] = (short)stream.readUnsignedShort(); + this.aShortArray859[i_66_] = (short)stream.readUnsignedShort(); + } + } + } else { + this.size = stream.readUnsignedByte(); + } + } else { + int i1 = stream.readUnsignedByte(); + modelIds = new int[i1]; + for (int i_69_ = 0; i_69_ < i1; i_69_++) { + modelIds[i_69_] = stream.readUnsignedShort(); + if ((modelIds[i_69_] ^ 0xffffffff) == -65536) + modelIds[i_69_] = -1; + } + } + + } + + public static void clearNPCDefinitions() { + npcDefinitions.clear(); + } + + public NPCDefinitions(int id) { + this.id = id; + this.anInt842 = -1; + this.bConfig = -1; + this.anInt837 = -1; + this.anInt846 = -1; + this.anInt853 = 32; + this.combatLevel = -1; + this.anInt836 = -1; + this.name = "null"; + this.anInt869 = 0; + this.walkMask = 0; + this.anInt850 = 255; + this.anInt871 = -1; + this.aBoolean852 = true; + this.aShort862 = 0; + this.anInt876 = -1; + this.aByte851 = -96; + this.anInt875 = 0; + this.anInt872 = -1; + this.renderEmote = -1; + this.respawnDirection = 7; + this.aBoolean857 = true; + this.anInt870 = -1; + this.anInt874 = -1; + this.anInt833 = -1; + this.anInt864 = 128; + this.headIcons = -1; + this.aBoolean856 = false; + this.config = -1; + this.aByte854 = -16; + this.aBoolean863 = false; + this.isVisibleOnMap = true; + this.anInt889 = -1; + this.anInt884 = -1; + this.aBoolean841 = true; + this.anInt879 = -1; + this.anInt899 = 128; + this.aShort894 = 0; + this.options = new String[5]; + this.anInt897 = 0; + this.anInt901 = -1; + } + + public String toString() { + return this.id + " - " + this.name; + } + + public boolean hasMarkOption() { + String[] var4 = this.options; + int var3 = this.options.length; + + for(int var2 = 0; var2 < var3; ++var2) { + String option = var4[var2]; + if(option != null && option.equalsIgnoreCase("mark")) { + return true; + } + } + + return false; + } + + public boolean hasOption(String op) { + String[] var5 = this.options; + int var4 = this.options.length; + + for(int var3 = 0; var3 < var4; ++var3) { + String option = var5[var3]; + if(option != null && option.equalsIgnoreCase(op)) { + return true; + } + } + + return false; + } + + public byte getRespawnDirection() { + return this.respawnDirection; + } + + public void setRespawnDirection(byte respawnDirection) { + this.respawnDirection = respawnDirection; + } + + public int getSize() { + return this.size; + } + + public void setSize(int size) { + this.size = size; + } + + public int getRenderEmote() { + return this.renderEmote; + } + + public void setRenderEmote(int renderEmote) { + this.renderEmote = renderEmote; + } + + public boolean isVisibleOnMap() { + return this.isVisibleOnMap; + } + + public void setVisibleOnMap(boolean isVisibleOnMap) { + this.isVisibleOnMap = isVisibleOnMap; + } + + public String[] getOptions() { + return this.options; + } + + public void setOptions(String[] options) { + this.options = options; + } + + public int getNpcId() { + return this.npcId; + } + + public void setNpcId(int npcId) { + this.npcId = npcId; + } + + public boolean hasAttackOption() { + if(this.id == 14899) { + return true; + } else { + String[] var4 = this.options; + int var3 = this.options.length; + + for(int var2 = 0; var2 < var3; ++var2) { + String option = var4[var2]; + if(option != null && option.equalsIgnoreCase("attack")) { + return true; + } + } + + return false; + } + } + + public byte[] encode() { + OutputStream stream = new OutputStream(); + stream.writeByte(1); + stream.writeByte(this.modelIds.length); + + int data; + for(data = 0; data < this.modelIds.length; ++data) { + stream.writeBigSmart(this.modelIds[data]); + } + + if(!this.name.equals("null")) { + stream.writeByte(2); + stream.writeString(this.name); + } + + //if(this.size != 1) { + if(this.size > 1) { + stream.writeByte(12); + stream.writeByte(this.size); + } + + for(data = 0; data < this.options.length; ++data) { + if(this.options[data] != null && this.options[data] != "Hidden") { + stream.writeByte(30 + data); + stream.writeString(this.options[data]); + } + } + + if(this.originalModelColors != null && this.modifiedModelColors != null) { + stream.writeByte(40); + stream.writeByte(this.originalModelColors.length); + + for(data = 0; data < this.originalModelColors.length; ++data) { + stream.writeShort(this.originalModelColors[data]); + stream.writeShort(this.modifiedModelColors[data]); + } + } + + if(this.originalTextureColors != null && this.modifiedTextureColors != null) { + stream.writeByte(41); + stream.writeByte(this.originalTextureColors.length); + + for(data = 0; data < this.originalTextureColors.length; ++data) { + stream.writeShort(this.originalTextureColors[data]); + stream.writeShort(this.modifiedTextureColors[data]); + } + } + + if(this.unknownArray1 != null) { + stream.writeByte(42); + stream.writeByte(this.unknownArray1.length); + + for(data = 0; data < this.unknownArray1.length; ++data) { + stream.writeByte(this.unknownArray1[data]); + } + } + + if(this.npcChatHeads != null) { + stream.writeByte(60); + stream.writeByte(this.npcChatHeads.length); + + for(data = 0; data < this.npcChatHeads.length; ++data) { + stream.writeBigSmart(this.npcChatHeads[data]); + } + } + + if(!this.isVisibleOnMap) { + stream.writeByte(93); + } + + //if(this.combatLevel != 0) { + if(this.combatLevel > -1) { + stream.writeByte(95); + stream.writeShort(this.combatLevel); + } + + if(this.npcHeight != 0) { + stream.writeByte(97); + stream.writeShort(this.npcHeight); + } + + if(this.npcWidth != 0) { + stream.writeByte(98); + stream.writeShort(this.npcWidth); + } + + if(this.unknownBoolean1) { + stream.writeByte(99); + } + + if(this.unknownInt1 != 0) { + stream.writeByte(100); + stream.writeByte(this.unknownInt1); + } + + if(this.unknownInt2 != 0) { + stream.writeByte(101); + stream.writeByte(this.unknownInt2 / 5); + } + + if(this.headIcons != 0) { + stream.writeByte(102); + stream.writeShort(this.headIcons); + } + + if(this.walkMask != -1) { + stream.writeByte(119); + stream.writeByte(this.walkMask); + } + + if(this.respawnDirection != 7) { + stream.writeByte(125); + stream.writeByte(this.respawnDirection); + } + + if(this.renderEmote != -1) { + stream.writeByte(127); + stream.writeShort(this.renderEmote); + } + + if(this.clientScriptData != null) { + stream.writeByte(249); + stream.writeByte(this.clientScriptData.size()); + Iterator var6 = this.clientScriptData.keySet().iterator(); + + while(var6.hasNext()) { + int key = ((Integer)var6.next()).intValue(); + Object value = this.clientScriptData.get(Integer.valueOf(key)); + stream.writeByte(value instanceof String?1:0); + stream.write24BitInt(key); + if(value instanceof String) { + stream.writeString((String)value); + } else { + stream.writeInt(((Integer)value).intValue()); + } + } + } + + stream.writeByte(0); + byte[] var61 = new byte[stream.getOffset()]; + stream.setOffset(0); + stream.getBytes(var61, 0, var61.length); + return var61; + } + + public int getCombatLevel() { + return this.combatLevel; + } + + public void setCombatLevel(int combatLevel) { + this.combatLevel = combatLevel; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public void resetTextureColors() { + this.originalTextureColors = null; + this.modifiedTextureColors = null; + } + + public void changeTextureColor(int originalModelColor, int modifiedModelColor) { + if(this.originalTextureColors != null) { + for(int var5 = 0; var5 < this.originalTextureColors.length; ++var5) { + if(this.originalTextureColors[var5] == originalModelColor) { + this.modifiedTextureColors[var5] = modifiedModelColor; + return; + } + } + + int[] var51 = Arrays.copyOf(this.originalTextureColors, this.originalTextureColors.length + 1); + int[] newModifiedModelColors = Arrays.copyOf(this.modifiedTextureColors, this.modifiedTextureColors.length + 1); + var51[var51.length - 1] = originalModelColor; + newModifiedModelColors[newModifiedModelColors.length - 1] = modifiedModelColor; + this.originalTextureColors = var51; + this.modifiedTextureColors = newModifiedModelColors; + } else { + this.originalTextureColors = new int[]{originalModelColor}; + this.modifiedTextureColors = new int[]{modifiedModelColor}; + } + + } + + public void resetModelColors() { + this.originalModelColors = null; + this.modifiedModelColors = null; + } + + public void changeModelColor(int originalModelColor, int modifiedModelColor) { + if(this.originalModelColors != null) { + for(int var5 = 0; var5 < this.originalModelColors.length; ++var5) { + if(this.originalModelColors[var5] == originalModelColor) { + this.modifiedModelColors[var5] = modifiedModelColor; + return; + } + } + + int[] var51 = Arrays.copyOf(this.originalModelColors, this.originalModelColors.length + 1); + int[] newModifiedModelColors = Arrays.copyOf(this.modifiedModelColors, this.modifiedModelColors.length + 1); + var51[var51.length - 1] = originalModelColor; + newModifiedModelColors[newModifiedModelColors.length - 1] = modifiedModelColor; + this.originalModelColors = var51; + this.modifiedModelColors = newModifiedModelColors; + } else { + this.originalModelColors = new int[]{originalModelColor}; + this.modifiedModelColors = new int[]{modifiedModelColor}; + } + + } +} diff --git a/src/com/alex/loaders/objects/ObjectDefinitions.java b/src/com/alex/loaders/objects/ObjectDefinitions.java new file mode 100644 index 0000000..356447e --- /dev/null +++ b/src/com/alex/loaders/objects/ObjectDefinitions.java @@ -0,0 +1,908 @@ +package com.alex.loaders.objects; + +import com.alex.io.InputStream; +import com.alex.io.OutputStream; +import com.alex.store.Store; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; + +public class ObjectDefinitions { + private static final ConcurrentHashMap objectDefinitions = new ConcurrentHashMap(); + private short[] originalColors; + int[] toObjectIds; + static int anInt3832; + int[] anIntArray3833 = null; + public int anInt3834; + int anInt3835; + static int anInt3836; + public byte aByte3837; + int anInt3838 = -1; + boolean aBoolean3839; + public int anInt3840; + public int anInt3841; + static int anInt3842; + static int anInt3843; + int anInt3844; + boolean aBoolean3845; + public byte aByte3847; + public boolean ignoreClipOnAlternativeRoute; + int[] animations = null; + private byte[] possibleTypes; + private int[] anIntArray4534; + private byte[] unknownArray4; + private byte[] unknownArray3; + private int cflag; + public byte aByte3849; + int anInt3850; + int anInt3851; + public boolean secondBool; + public boolean aBoolean3853; + int anInt3855; + public boolean notCliped; + int anInt3857; + private byte[] aByteArray3858; + int[] anIntArray3859; + int anInt3860; + public String[] options; + int configFileId; + private short[] modifiedColors; + int anInt3865; + boolean aBoolean3866; + boolean aBoolean3867; + private int[] anIntArray3869; + boolean aBoolean3870; + public int sizeY; + boolean aBoolean3872; + boolean aBoolean3873; + public int thirdInt; + public int anInt3875; + public int objectAnimation; + public int anInt3877; + public int anInt3878; + public int clipType; + public int anInt3881; + public int anInt3882; + public int anInt3883; + Object loader; + public int anInt3889; + public int sizeX; + public boolean aBoolean3891; + int anInt3892; + public int secondInt; + boolean aBoolean3894; + boolean aBoolean3895; + int anInt3896; + int configId; + private byte[] aByteArray3899; + int anInt3900; + public String name; + public int anInt3902; + int anInt3904; + int anInt3905; + boolean aBoolean3906; + int[] anIntArray3908; + public byte aByte3912; + int anInt3913; + public byte aByte3914; + public int anInt3915; + public int[][] modelIds; + public int anInt3917; + public boolean loaded; + private short[] aShortArray3919; + private short[] aShortArray3920; + int anInt3921; + private HashMap parameters; + boolean aBoolean3923; + boolean aBoolean3924; + int anInt3925; + public int id; + public boolean aBool6886; + static int anInt3846; + public boolean projectileCliped; + + public ObjectDefinitions() { + this.anInt3835 = -1; + this.anInt3860 = -1; + this.configFileId = -1; + this.aBoolean3866 = false; + this.anInt3851 = -1; + this.anInt3865 = 255; + this.aBoolean3845 = false; + this.aBoolean3867 = false; + this.anInt3850 = 0; + this.anInt3844 = -1; + this.anInt3881 = 0; + this.anInt3857 = -1; + this.aBoolean3872 = true; + this.anInt3882 = -1; + this.anInt3834 = 0; + this.options = new String[5]; + this.anInt3875 = 0; + this.aBoolean3839 = false; + this.anIntArray3869 = null; + this.sizeY = 1; + this.thirdInt = -1; + this.anInt3883 = 0; + this.aBoolean3895 = true; + this.anInt3840 = 0; + this.aBoolean3870 = false; + this.anInt3889 = 0; + this.aBoolean3853 = true; + this.secondBool = false; + this.clipType = 2; + this.projectileCliped = true; + this.ignoreClipOnAlternativeRoute = false; + this.anInt3855 = -1; + this.anInt3878 = 0; + this.anInt3904 = 0; + this.sizeX = 1; + this.objectAnimation = -1; + this.aBoolean3891 = false; + this.anInt3905 = 0; + this.name = "null"; + this.anInt3913 = -1; + this.aBoolean3906 = false; + this.aBoolean3873 = false; + this.aByte3914 = 0; + this.anInt3915 = 0; + this.anInt3900 = 0; + this.secondInt = -1; + this.aBoolean3894 = false; + this.aByte3912 = 0; + this.anInt3921 = 0; + this.anInt3902 = 128; + this.configId = -1; + this.anInt3877 = 0; + this.anInt3925 = 0; + this.anInt3892 = 64; + this.aBoolean3923 = false; + this.aBoolean3924 = false; + this.anInt3841 = 128; + this.anInt3917 = 128; + } + + public String getFirstOption() { + return this.options != null && this.options.length >= 1?this.options[0]:""; + } + + public String getSecondOption() { + return this.options != null && this.options.length >= 2?this.options[1]:""; + } + + public String getOption(int option) { + return this.options != null && this.options.length >= option && option != 0?this.options[option - 1]:""; + } + + public String getThirdOption() { + return this.options != null && this.options.length >= 3?this.options[2]:""; + } + + private static int getArchiveId(int i_0_) { + return i_0_ >>> -1135990488; + } + + public int getSizeX() { + return this.sizeX; + } + + public int getSizeY() { + return this.sizeY; + } + + private Object getValue(Field field) throws Throwable { + field.setAccessible(true); + Class type = field.getType(); + return type == int[][].class?Arrays.toString((int[][])field.get(this)):(type == int[].class?Arrays.toString((int[])field.get(this)):(type == byte[].class?Arrays.toString((byte[])field.get(this)):(type == short[].class?Arrays.toString((short[])field.get(this)):(type == double[].class?Arrays.toString((double[])field.get(this)):(type == float[].class?Arrays.toString((float[])field.get(this)):(type == Object[].class?Arrays.toString((Object[])field.get(this)):field.get(this))))))); + } + + public boolean isProjectileCliped() { + return this.projectileCliped; + } + + public boolean containsOption(int i, String option) { + return this.options != null && this.options[i] != null && this.options.length > i && this.options[i].equals(option); + } + + public boolean containsOption(String o) { + if(this.options == null) { + return false; + } else { + String[] var5 = this.options; + int var4 = this.options.length; + + for(int var3 = 0; var3 < var4; ++var3) { + String option = var5[var3]; + if(option != null && option.equalsIgnoreCase(o)) { + return true; + } + } + + return false; + } + } + + final void method3287() { + if(this.secondInt == -1) { + this.secondInt = 0; + if(this.possibleTypes != null && this.possibleTypes.length == 1 && this.possibleTypes[0] == 10) { + this.secondInt = 1; + } + + for(int i_13_ = 0; i_13_ < 5; ++i_13_) { + if(this.options[i_13_] != null) { + this.secondInt = 1; + break; + } + } + } + + if(this.anInt3855 == -1) { + this.anInt3855 = this.clipType != 0?1:0; + } + + } + + public int getAccessBlockFlag() { + return this.cflag; + } + + private void readValues(InputStream stream, int opcode) { + boolean aBoolean1162; + int i_73_; + int i_74_; + int i_75_; + if(opcode != 1 && opcode != 5) { + if(opcode != 2) { + if(opcode != 14) { + if(opcode != 15) { + if(opcode == 17) { + this.projectileCliped = false; + this.clipType = 0; + } else if(opcode != 18) { + if(opcode == 19) { + this.secondInt = stream.readUnsignedByte(); + } else if(opcode == 21) { + this.aByte3912 = 1; + } else if(opcode != 22) { + if(opcode != 23) { + if(opcode != 24) { + if(opcode == 27) { + this.clipType = 1; + } else if(opcode == 28) { + this.anInt3892 = stream.readUnsignedByte() << 2; + } else if(opcode != 29) { + if(opcode != 39) { + if(opcode >= 30 && opcode < 35) { + this.options[-30 + opcode] = stream.readString(); + } else { + int var8; + if(opcode == 40) { + var8 = stream.readUnsignedByte(); + this.originalColors = new short[var8]; + this.modifiedColors = new short[var8]; + + for(i_73_ = 0; var8 > i_73_; ++i_73_) { + this.originalColors[i_73_] = (short)stream.readUnsignedShort(); + this.modifiedColors[i_73_] = (short)stream.readUnsignedShort(); + } + } else { + short var9; + byte var10; + if(44 == opcode) { + var9 = (short)stream.readUnsignedShort(); + i_73_ = 0; + + for(i_74_ = var9; i_74_ > 0; i_74_ >>= 1) { + ++i_73_; + } + + this.unknownArray3 = new byte[i_73_]; + var10 = 0; + + for(i_75_ = 0; i_75_ < i_73_; ++i_75_) { + if((var9 & 1 << i_75_) > 0) { + this.unknownArray3[i_75_] = var10++; + } else { + this.unknownArray3[i_75_] = -1; + } + } + } else if(opcode == 45) { + var9 = (short)stream.readUnsignedShort(); + i_73_ = 0; + + for(i_74_ = var9; i_74_ > 0; i_74_ >>= 1) { + ++i_73_; + } + + this.unknownArray4 = new byte[i_73_]; + var10 = 0; + + for(i_75_ = 0; i_75_ < i_73_; ++i_75_) { + if((var9 & 1 << i_75_) > 0) { + this.unknownArray4[i_75_] = var10++; + } else { + this.unknownArray4[i_75_] = -1; + } + } + } else if(opcode != 41) { + if(opcode != 42) { + if(opcode != 62) { + if(opcode != 64) { + if(opcode == 65) { + this.anInt3902 = stream.readUnsignedShort(); + } else if(opcode != 66) { + if(opcode != 67) { + if(opcode == 69) { + this.cflag = stream.readUnsignedByte(); + } else if(opcode != 70) { + if(opcode == 71) { + this.anInt3889 = stream.readShort() << 2; + } else if(opcode != 72) { + if(opcode == 73) { + this.secondBool = true; + } else if(opcode == 74) { + this.ignoreClipOnAlternativeRoute = true; + } else if(opcode != 75) { + if(opcode != 77 && opcode != 92) { + if(opcode == 78) { + this.anInt3860 = stream.readUnsignedShort(); + this.anInt3904 = stream.readUnsignedByte(); + } else if(opcode != 79) { + if(opcode == 81) { + this.aByte3912 = 2; + this.anInt3882 = 256 * stream.readUnsignedByte(); + } else if(opcode != 82) { + if(opcode == 88) { + this.aBoolean3853 = false; + } else if(opcode != 89) { + if(opcode == 90) { + this.aBoolean3870 = true; + } else if(opcode != 91) { + if(opcode != 93) { + if(opcode == 94) { + this.aByte3912 = 4; + } else if(opcode != 95) { + if(opcode != 96) { + if(opcode == 97) { + this.aBoolean3866 = true; + } else if(opcode == 98) { + this.aBoolean3923 = true; + } else if(opcode == 99) { + this.anInt3857 = stream.readUnsignedByte(); + this.anInt3835 = stream.readUnsignedShort(); + } else if(opcode == 100) { + this.anInt3844 = stream.readUnsignedByte(); + this.anInt3913 = stream.readUnsignedShort(); + } else if(opcode != 101) { + if(opcode == 102) { + this.anInt3838 = stream.readUnsignedShort(); + } else if(opcode == 103) { + this.thirdInt = 0; + } else if(opcode != 104) { + if(opcode == 105) { + this.aBoolean3906 = true; + } else if(opcode == 106) { + var8 = stream.readUnsignedByte(); + this.anIntArray3869 = new int[var8]; + this.animations = new int[var8]; + + for(i_73_ = 0; i_73_ < var8; ++i_73_) { + this.animations[i_73_] = stream.readBigSmart(); + i_74_ = stream.readUnsignedByte(); + this.anIntArray3869[i_73_] = i_74_; + this.anInt3881 += i_74_; + } + } else if(opcode == 107) { + this.anInt3851 = stream.readUnsignedShort(); + } else if(opcode >= 150 && opcode < 155) { + this.options[opcode + -150] = stream.readString(); + } else if(opcode != 160) { + if(opcode == 162) { + this.aByte3912 = 3; + this.anInt3882 = stream.readInt(); + } else if(opcode == 163) { + this.aByte3847 = (byte)stream.readByte(); + this.aByte3849 = (byte)stream.readByte(); + this.aByte3837 = (byte)stream.readByte(); + this.aByte3914 = (byte)stream.readByte(); + } else if(opcode != 164) { + if(opcode != 165) { + if(opcode != 166) { + if(opcode == 167) { + this.anInt3921 = stream.readUnsignedShort(); + } else if(opcode != 168) { + if(opcode == 169) { + this.aBoolean3845 = true; + } else if(opcode == 170) { + var8 = stream.readUnsignedSmart(); + } else if(opcode == 171) { + var8 = stream.readUnsignedSmart(); + } else if(opcode == 173) { + var8 = stream.readUnsignedShort(); + i_73_ = stream.readUnsignedShort(); + } else if(opcode == 177) { + aBoolean1162 = true; + } else if(opcode == 178) { + var8 = stream.readUnsignedByte(); + } else if(opcode == 189) { + aBoolean1162 = true; + } else if(opcode >= 190 && opcode < 196) { + if(this.anIntArray4534 == null) { + this.anIntArray4534 = new int[6]; + Arrays.fill(this.anIntArray4534, -1); + } + + this.anIntArray4534[opcode - 190] = stream.readUnsignedShort(); + } else if(opcode == 249) { + var8 = stream.readUnsignedByte(); + if(this.parameters == null) { + this.parameters = new HashMap(var8); + } + + for(i_73_ = 0; i_73_ < var8; ++i_73_) { + boolean var11 = stream.readUnsignedByte() == 1; + i_75_ = stream.read24BitInt(); + if(!var11) { + this.parameters.put(Integer.valueOf(i_75_), Integer.valueOf(stream.readInt())); + } else { + this.parameters.put(Integer.valueOf(i_75_), stream.readString()); + } + } + } + } else { + this.aBoolean3894 = true; + } + } else { + this.anInt3877 = stream.readShort(); + } + } else { + this.anInt3875 = stream.readShort(); + } + } else { + this.anInt3834 = stream.readShort(); + } + } else { + var8 = stream.readUnsignedByte(); + this.anIntArray3908 = new int[var8]; + + for(i_73_ = 0; var8 > i_73_; ++i_73_) { + this.anIntArray3908[i_73_] = stream.readUnsignedShort(); + } + } + } else { + this.anInt3865 = stream.readUnsignedByte(); + } + } else { + this.anInt3850 = stream.readUnsignedByte(); + } + } else { + this.aBoolean3924 = true; + } + } else { + this.aByte3912 = 5; + this.anInt3882 = stream.readShort(); + } + } else { + this.aByte3912 = 3; + this.anInt3882 = stream.readUnsignedShort(); + } + } else { + this.aBoolean3873 = true; + } + } else { + this.aBoolean3895 = false; + } + } else { + this.aBoolean3891 = true; + } + } else { + this.anInt3900 = stream.readUnsignedShort(); + this.anInt3905 = stream.readUnsignedShort(); + this.anInt3904 = stream.readUnsignedByte(); + var8 = stream.readUnsignedByte(); + this.anIntArray3859 = new int[var8]; + + for(i_73_ = 0; i_73_ < var8; ++i_73_) { + this.anIntArray3859[i_73_] = stream.readUnsignedShort(); + } + } + } else { + this.configFileId = stream.readUnsignedShort(); + if(this.configFileId == '\uffff') { + this.configFileId = -1; + } + + this.configId = stream.readUnsignedShort(); + if(this.configId == '\uffff') { + this.configId = -1; + } + + var8 = -1; + if(opcode == 92) { + var8 = stream.readBigSmart(); + } + + i_73_ = stream.readUnsignedByte(); + this.toObjectIds = new int[i_73_ - -2]; + + for(i_74_ = 0; i_73_ >= i_74_; ++i_74_) { + this.toObjectIds[i_74_] = stream.readBigSmart(); + } + + this.toObjectIds[i_73_ + 1] = var8; + } + } else { + this.anInt3855 = stream.readUnsignedByte(); + } + } else { + this.anInt3915 = stream.readShort() << 2; + } + } else { + this.anInt3883 = stream.readShort() << 2; + } + } else { + this.anInt3917 = stream.readUnsignedShort(); + } + } else { + this.anInt3841 = stream.readUnsignedShort(); + } + } else { + this.aBoolean3872 = false; + } + } else { + this.aBoolean3839 = true; + } + } else { + var8 = stream.readUnsignedByte(); + this.aByteArray3858 = new byte[var8]; + + for(i_73_ = 0; i_73_ < var8; ++i_73_) { + this.aByteArray3858[i_73_] = (byte)stream.readByte(); + } + } + } else { + var8 = stream.readUnsignedByte(); + this.aShortArray3920 = new short[var8]; + this.aShortArray3919 = new short[var8]; + + for(i_73_ = 0; var8 > i_73_; ++i_73_) { + this.aShortArray3920[i_73_] = (short)stream.readUnsignedShort(); + this.aShortArray3919[i_73_] = (short)stream.readUnsignedShort(); + } + } + } + } + } else { + this.anInt3840 = stream.readByte() * 5; + } + } else { + this.anInt3878 = stream.readByte(); + } + } else { + this.objectAnimation = stream.readBigSmart(); + } + } else { + this.thirdInt = 1; + } + } else { + this.aBoolean3867 = true; + } + } else { + this.projectileCliped = false; + } + } else { + this.sizeY = stream.readUnsignedByte(); + } + } else { + this.sizeX = stream.readUnsignedByte(); + } + } else { + this.name = stream.readString(); + } + } else { + aBoolean1162 = false; + if(opcode == 5 && aBoolean1162) { + this.skipReadModelIds(stream); + } + + i_73_ = stream.readUnsignedByte(); + this.modelIds = new int[i_73_][]; + this.possibleTypes = new byte[i_73_]; + + for(i_74_ = 0; i_74_ < i_73_; ++i_74_) { + this.possibleTypes[i_74_] = (byte)stream.readByte(); + i_75_ = stream.readUnsignedByte(); + this.modelIds[i_74_] = new int[i_75_]; + + for(int i_76_ = 0; i_75_ > i_76_; ++i_76_) { + this.modelIds[i_74_][i_76_] = stream.readIntLE(); //fix + } + } + + if(opcode == 5 && !aBoolean1162) { + this.skipReadModelIds(stream); + } + } + + } + + private void skipReadModelIds(InputStream stream) { + int length = stream.readUnsignedByte(); + + for(int index = 0; index < length; ++index) { + stream.skip(1); + int length2 = stream.readUnsignedByte(); + + for(int i = 0; i < length2; ++i) { + stream.readBigSmart(); + } + } + + } + + private void readValueLoop(InputStream stream) { + while(true) { + int opcode = stream.readUnsignedByte(); + if(opcode == 0) { + return; + } + + this.readValues(stream, opcode); + } + } + + public ObjectDefinitions(Store cache, int i) { + this.anInt3835 = -1; + this.anInt3860 = -1; + this.configFileId = -1; + this.aBoolean3866 = false; + this.anInt3851 = -1; + this.anInt3865 = 255; + this.aBoolean3845 = false; + this.aBoolean3867 = false; + this.anInt3850 = 0; + this.anInt3844 = -1; + this.anInt3881 = 0; + this.anInt3857 = -1; + this.aBoolean3872 = true; + this.anInt3882 = -1; + this.anInt3834 = 0; + this.options = new String[5]; + this.anInt3875 = 0; + this.aBoolean3839 = false; + this.anIntArray3869 = null; + this.sizeY = 1; + this.thirdInt = -1; + this.anInt3883 = 0; + this.aBoolean3895 = true; + this.anInt3840 = 0; + this.aBoolean3870 = false; + this.anInt3889 = 0; + this.aBoolean3853 = true; + this.secondBool = false; + this.clipType = 2; + this.projectileCliped = true; + this.notCliped = false; + this.anInt3855 = -1; + this.anInt3878 = 0; + this.anInt3904 = 0; + this.sizeX = 1; + this.objectAnimation = -1; + this.aBoolean3891 = false; + this.anInt3905 = 0; + this.name = "null"; + this.anInt3913 = -1; + this.aBoolean3906 = false; + this.aBoolean3873 = false; + this.aByte3914 = 0; + this.anInt3915 = 0; + this.anInt3900 = 0; + this.secondInt = -1; + this.aBoolean3894 = false; + this.aByte3912 = 0; + this.anInt3921 = 0; + this.anInt3902 = 128; + this.configId = -1; + this.anInt3877 = 0; + this.anInt3925 = 0; + this.anInt3892 = 64; + this.aBoolean3923 = false; + this.aBoolean3924 = false; + this.anInt3841 = 128; + this.anInt3917 = 128; + } + + public int getArchiveId() { + return this.id >>> -1135990488; + } + + public int getFileId() { + return 0xff & this.id; + } + + public static ObjectDefinitions getObjectDefinitions(int id, Store store) { + ObjectDefinitions def = (ObjectDefinitions)objectDefinitions.get(Integer.valueOf(id)); + if(def == null) { + def = new ObjectDefinitions(); + def.id = id; + byte[] data = store.getIndexes()[16].getFile(getArchiveId(id), id & 0xff); + if(data != null) { + def.readValueLoop(new InputStream(data)); + } + + def.method3287(); + objectDefinitions.put(Integer.valueOf(id), def); + } + + return def; + } + + private void loadObjectDefinition(Store store) { + byte[] data = store.getIndexes()[16].getFile(this.id >>> -1135990488, this.id & 0xff); + if(data == null) { + System.out.println("FAILED LOADING OBJECT " + this.id); + } else { + try { + this.readOpcodeValues(new InputStream(data)); + } catch (RuntimeException var4) { + var4.printStackTrace(); + } + + this.loaded = true; + } + + } + + private void readOpcodeValues(InputStream stream) { + while(true) { + int opcode = stream.readUnsignedByte(); + if(opcode == 0) { + return; + } + + this.readValues(stream, opcode); + } + } + + public static ObjectDefinitions getObjectDefinition(Store cache, int itemId) { + return getObjectDefinition(cache, itemId, true); + } + + public static ObjectDefinitions getObjectDefinition(Store cache, int itemId, boolean load) { + return new ObjectDefinitions(cache, itemId, load); + } + + public ObjectDefinitions(Store cache, int id, boolean load) { + this.id = id; + this.setDefaultVariableValues(); + this.setDefaultOptions(); + if(load) { + this.loadObjectDefinition(cache); + } + + } + + private void setDefaultOptions() { + this.options = new String[5]; + } + + private void setDefaultVariableValues() { + this.name = name; + this.sizeX = 1; + this.sizeY = 1; + this.projectileCliped = true; + this.clipType = 2; + this.objectAnimation = -1; + } + + public int getClipType() { + return this.clipType; + } + + public static void clearObjectDefinitions() { + objectDefinitions.clear(); + } + + public void printFields() { + Field[] arr$ = this.getClass().getDeclaredFields(); + int len$ = arr$.length; + + for(int i$ = 0; i$ < len$; ++i$) { + Field field = arr$[i$]; + if((field.getModifiers() & 8) == 0) { + try { + System.out.println(field.getName() + ": " + this.getValue(field)); + } catch (Throwable var6) { + var6.printStackTrace(); + } + } + } + + System.out.println("-- end of " + this.getClass().getSimpleName() + " fields --"); + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public byte[] encode() { + OutputStream stream = new OutputStream(); + stream.writeByte(1); + int i_73_ = this.modelIds.length; + this.modelIds = new int[i_73_][]; + this.aByteArray3899 = new byte[i_73_]; + + int data; + for(data = 0; data < i_73_; ++data) { + stream.write128Byte(this.aByteArray3899[data]); + int var6 = this.modelIds[data].length; + this.modelIds[data] = new int[var6]; + + for(int i_76_ = 0; var6 > i_76_; ++i_76_) { + stream.writeBigSmart(this.modelIds[data][i_76_]); + } + } + + if(!this.name.equals("null")) { + stream.writeByte(2); + stream.writeString(this.name); + } + + if(this.sizeX != 1) { + stream.writeByte(14); + stream.write128Byte(this.sizeX); + } + + if(this.sizeY != 1) { + stream.writeByte(15); + stream.writeByte(this.sizeY); + } + + if(this.objectAnimation != -1) { + stream.writeByte(24); + stream.writeBigSmart(this.objectAnimation); + } + + for(data = 0; data < this.options.length; ++data) { + if(this.options[data] != null && this.options[data] != "Hidden") { + stream.writeByte(30 + data); + stream.writeString(this.options[data]); + } + } + + if(this.originalColors != null && this.modifiedColors != null) { + stream.writeByte(40); + stream.writeByte(this.originalColors.length); + + for(data = 0; data < this.originalColors.length; ++data) { + stream.writeShort(this.originalColors[data]); + stream.writeShort(this.modifiedColors[data]); + } + } + + if(this.clipType == 0 && this.projectileCliped) { + stream.writeByte(17); + } + + if(this.projectileCliped) { + stream.writeByte(18); + } + + if(this.clipType == 1 || this.clipType == 2) { + stream.writeByte(27); + } + + stream.writeByte(0); + byte[] var61 = new byte[stream.getOffset()]; + stream.setOffset(0); + stream.getBytes(var61, 0, var61.length); + return var61; + } +} diff --git a/src/com/alex/store/Archive.java b/src/com/alex/store/Archive.java new file mode 100644 index 0000000..2af34d7 --- /dev/null +++ b/src/com/alex/store/Archive.java @@ -0,0 +1,166 @@ +package com.alex.store; + +import com.alex.io.InputStream; +import com.alex.io.OutputStream; +import com.alex.store.MainFile; +import com.alex.util.bzip2.BZip2Compressor; +import com.alex.util.bzip2.BZip2Decompressor; +import com.alex.util.crc32.CRC32HGenerator; +import com.alex.util.gzip.GZipCompressor; +import com.alex.util.gzip.GZipDecompressor; +import com.alex.util.whirlpool.Whirlpool; + +public class Archive { + private final int id; + private int revision; + private int compression; + private byte[] data; + private int[] keys; + + protected Archive(int id, byte[] archive, int[] keys) { + this.id = id; + this.keys = keys; + this.decompress(archive); + } + + public Archive(int id, int compression, int revision, byte[] data) { + this.id = id; + this.compression = compression; + this.revision = revision; + this.data = data; + } + + public byte[] compress() { + OutputStream stream = new OutputStream(); + stream.writeByte(this.compression); + byte[] compressedData1; + switch(this.compression) { + case 0: + compressedData1 = this.data; + stream.writeInt(this.data.length); + break; + case 1: + Object compressed = null; + compressedData1 = BZip2Compressor.compress(this.data); + stream.writeInt(compressedData1.length); + stream.writeInt(this.data.length); + default: + compressedData1 = GZipCompressor.compress(this.data); + stream.writeInt(compressedData1.length); + stream.writeInt(this.data.length); + } + + stream.writeBytes(compressedData1); + if(this.keys != null && this.keys.length == 4) { + stream.encodeXTEA(this.keys, 5, stream.getOffset()); + } + + if(this.revision != -1) { + stream.writeShort(this.revision); + } + + byte[] compressed1 = new byte[stream.getOffset()]; + stream.setOffset(0); + stream.getBytes(compressed1, 0, compressed1.length); + return compressed1; + } + + private void decompress(byte[] archive) { + InputStream stream = new InputStream(archive); + if(this.keys != null && this.keys.length == 4) { + stream.decodeXTEA(this.keys); + } + + this.compression = stream.readUnsignedByte(); + int compressedLength = stream.readInt(); + if(compressedLength >= 0 && compressedLength <= 1000000) { + int length; + switch(this.compression) { + case 0: + this.data = new byte[compressedLength]; + this.checkRevision(compressedLength, archive, stream.getOffset()); + stream.readBytes(this.data, 0, compressedLength); + break; + case 1: + length = stream.readInt(); + if(length <= 0) { + this.data = null; + } else { + this.data = new byte[length]; + this.checkRevision(compressedLength, archive, stream.getOffset()); + BZip2Decompressor.decompress(this.data, archive, compressedLength, 9); + } + break; + default: + length = stream.readInt(); + if(length > 0 && length <= 1000000000) { + this.data = new byte[length]; + this.checkRevision(compressedLength, archive, stream.getOffset()); + if(!GZipDecompressor.decompress(stream, this.data)) { + this.data = null; + } + } else { + this.data = null; + } + } + + } else { + throw new RuntimeException("INVALID ARCHIVE HEADER"); + } + } + + private void checkRevision(int compressedLength, byte[] archive, int o) { + InputStream stream = new InputStream(archive); + int offset = stream.getOffset(); + if(stream.getLength() - (compressedLength + o) >= 2) { + stream.setOffset(stream.getLength() - 2); + this.revision = stream.readUnsignedShort(); + stream.setOffset(offset); + } else { + this.revision = -1; + } + + } + + public Object[] editNoRevision(byte[] data, MainFile mainFile) { + this.data = data; + if(this.compression == 1) { + this.compression = 2; + } + + byte[] compressed = this.compress(); + return !mainFile.putArchiveData(this.id, compressed)?null:new Object[]{Integer.valueOf(CRC32HGenerator.getHash(compressed)), Whirlpool.getHash(compressed, 0, compressed.length)}; + } + + public int getId() { + return this.id; + } + + public byte[] getData() { + return this.data; + } + + public int getDecompressedLength() { + return this.data.length; + } + + public int getRevision() { + return this.revision; + } + + public void setRevision(int revision) { + this.revision = revision; + } + + public int getCompression() { + return this.compression; + } + + public int[] getKeys() { + return this.keys; + } + + public void setKeys(int[] keys) { + this.keys = keys; + } +} diff --git a/src/com/alex/store/ArchiveReference.java b/src/com/alex/store/ArchiveReference.java new file mode 100644 index 0000000..d9131cb --- /dev/null +++ b/src/com/alex/store/ArchiveReference.java @@ -0,0 +1,138 @@ +package com.alex.store; + +import com.alex.store.FileReference; + +import java.util.Arrays; + +public class ArchiveReference { + private int nameHash; + private byte[] whirpool; + private int crc; + private int revision; + private FileReference[] files; + private int[] validFileIds; + private boolean needsFilesSort; + private boolean updatedRevision; + + public void updateRevision() { + if(!this.updatedRevision) { + ++this.revision; + this.updatedRevision = true; + } + + } + + public int getNameHash() { + return this.nameHash; + } + + public void setNameHash(int nameHash) { + this.nameHash = nameHash; + } + + public byte[] getWhirpool() { + return this.whirpool; + } + + public void setWhirpool(byte[] whirpool) { + this.whirpool = whirpool; + } + + public int getCRC() { + return this.crc; + } + + public void setCrc(int crc) { + this.crc = crc; + } + + public int getRevision() { + return this.revision; + } + + public FileReference[] getFiles() { + return this.files; + } + + public void setFiles(FileReference[] files) { + this.files = files; + } + + public void setRevision(int revision) { + this.revision = revision; + } + + public int[] getValidFileIds() { + return this.validFileIds; + } + + public void setValidFileIds(int[] validFileIds) { + this.validFileIds = validFileIds; + } + + public boolean isNeedsFilesSort() { + return this.needsFilesSort; + } + + public void setNeedsFilesSort(boolean needsFilesSort) { + this.needsFilesSort = needsFilesSort; + } + + public void removeFileReference(int fileId) { + int[] newValidFileIds = new int[this.validFileIds.length - 1]; + int count = 0; + int[] arr$ = this.validFileIds; + int len$ = arr$.length; + + for(int i$ = 0; i$ < len$; ++i$) { + int id = arr$[i$]; + if(id != fileId) { + newValidFileIds[count++] = id; + } + } + + this.validFileIds = newValidFileIds; + this.files[fileId] = null; + } + + public void addEmptyFileReference(int fileId) { + this.needsFilesSort = true; + int[] newValidFileIds = Arrays.copyOf(this.validFileIds, this.validFileIds.length + 1); + newValidFileIds[newValidFileIds.length - 1] = fileId; + this.validFileIds = newValidFileIds; + if(this.files.length <= fileId) { + FileReference[] newFiles = Arrays.copyOf(this.files, fileId + 1); + newFiles[fileId] = new FileReference(); + this.files = newFiles; + } else { + this.files[fileId] = new FileReference(); + } + + } + + public void sortFiles() { + Arrays.sort(this.validFileIds); + this.needsFilesSort = false; + } + + public void reset() { + this.whirpool = null; + this.updatedRevision = true; + this.revision = 0; + this.nameHash = 0; + this.crc = 0; + this.files = new FileReference[0]; + this.validFileIds = new int[0]; + this.needsFilesSort = false; + } + + public void copyHeader(ArchiveReference fromReference) { + this.setCrc(fromReference.getCRC()); + this.setNameHash(fromReference.getNameHash()); + this.setWhirpool(fromReference.getWhirpool()); + int[] validFiles = fromReference.getValidFileIds(); + this.setValidFileIds(Arrays.copyOf(validFiles, validFiles.length)); + FileReference[] files = fromReference.getFiles(); + this.setFiles(Arrays.copyOf(files, files.length)); + } +} diff --git a/src/com/alex/store/FileReference.java b/src/com/alex/store/FileReference.java new file mode 100644 index 0000000..db59680 --- /dev/null +++ b/src/com/alex/store/FileReference.java @@ -0,0 +1,13 @@ +package com.alex.store; + +public class FileReference { + private int nameHash; + + public int getNameHash() { + return this.nameHash; + } + + public void setNameHash(int nameHash) { + this.nameHash = nameHash; + } +} diff --git a/src/com/alex/store/Index.java b/src/com/alex/store/Index.java new file mode 100644 index 0000000..91cf71f --- /dev/null +++ b/src/com/alex/store/Index.java @@ -0,0 +1,504 @@ +package com.alex.store; + +import com.alex.io.InputStream; +import com.alex.io.OutputStream; +import com.alex.store.*; +import com.alex.util.crc32.CRC32HGenerator; +import com.alex.util.whirlpool.Whirlpool; +import com.alex.utils.Utils; + +public final class Index { + private final MainFile mainFile; + private final MainFile index255; + private ReferenceTable table; + private byte[][][] cachedFiles; + private int crc; + private byte[] whirlpool; + + Index(MainFile index255, MainFile mainFile, int[] keys) { + this.mainFile = mainFile; + this.index255 = index255; + byte[] archiveData = index255.getArchiveData(this.getId()); + if(archiveData != null) { + this.crc = CRC32HGenerator.getHash(archiveData); + this.whirlpool = Whirlpool.getHash(archiveData, 0, archiveData.length); + Archive archive = new Archive(this.getId(), archiveData, keys); + this.table = new ReferenceTable(archive); + this.resetCachedFiles(); + } + + } + + public void resetCachedFiles() { + this.cachedFiles = new byte[this.getLastArchiveId() + 1][][]; + } + + public int getLastFileId(int archiveId) { + return !this.archiveExists(archiveId)?-1:this.table.getArchives()[archiveId].getFiles().length - 1; + } + + public int getLastArchiveId() { + return this.table.getArchives().length - 1; + } + + public int getValidArchivesCount() { + return this.table.getValidArchiveIds().length; + } + + public int getValidFilesCount(int archiveId) { + return !this.archiveExists(archiveId)?-1:this.table.getArchives()[archiveId].getValidFileIds().length; + } + + public boolean archiveExists(int archiveId) { + if(archiveId < 0) { + return false; + } else { + ArchiveReference[] archives = this.table.getArchives(); + return archives.length > archiveId && archives[archiveId] != null; + } + } + + public boolean fileExists(int archiveId, int fileId) { + if(!this.archiveExists(archiveId)) { + return false; + } else { + FileReference[] files = this.table.getArchives()[archiveId].getFiles(); + return files.length > fileId && files[fileId] != null; + } + } + + public int getArchiveId(String name) { + int nameHash = Utils.getNameHash(name); + ArchiveReference[] archives = this.table.getArchives(); + int[] validArchiveIds = this.table.getValidArchiveIds(); + int[] arr$ = validArchiveIds; + int len$ = validArchiveIds.length; + + for(int i$ = 0; i$ < len$; ++i$) { + int archiveId = arr$[i$]; + if(archives[archiveId].getNameHash() == nameHash) { + return archiveId; + } + } + + return -1; + } + + public int getFileId(int archiveId, String name) { + if(!this.archiveExists(archiveId)) { + return -1; + } else { + int nameHash = Utils.getNameHash(name); + FileReference[] files = this.table.getArchives()[archiveId].getFiles(); + int[] validFileIds = this.table.getArchives()[archiveId].getValidFileIds(); + + for(int index = 0; index < validFileIds.length; ++index) { + int fileId = validFileIds[index]; + if(files[fileId].getNameHash() == nameHash) { + return fileId; + } + } + + return -1; + } + } + + public byte[] getFile(int archiveId) { + return !this.archiveExists(archiveId)?null:this.getFile(archiveId, this.table.getArchives()[archiveId].getValidFileIds()[0]); + } + + public byte[] getFile(int archiveId, int fileId) { + return this.getFile(archiveId, fileId, null); + } + + public byte[] getFile(int archiveId, int fileId, int[] keys) { + try { + if(!this.fileExists(archiveId, fileId)) { + return null; + } else { + if(this.cachedFiles[archiveId] == null || this.cachedFiles[archiveId][fileId] == null) { + this.cacheArchiveFiles(archiveId, keys); + } + + byte[] var5 = this.cachedFiles[archiveId][fileId]; + this.cachedFiles[archiveId][fileId] = null; + return var5; + } + } catch (Throwable var51) { + var51.printStackTrace(); + return null; + } + } + + public boolean packIndex(Store originalStore) { + return this.packIndex(originalStore, false); + } + + public boolean packIndex(Store originalStore, boolean checkCRC) { + try { + return this.packIndex(this.getId(), originalStore, checkCRC); + } catch (Exception var4) { + return this.packIndex(this.getId(), originalStore, checkCRC); + } + } + + public boolean packIndex(int id, Store originalStore, boolean checkCRC) { + try { + Index var9 = originalStore.getIndexes()[id]; + int[] arr$ = var9.table.getValidArchiveIds(); + int len$ = arr$.length; + + for(int i$ = 0; i$ < len$; ++i$) { + int archiveId = arr$[i$]; + if((!checkCRC || !this.archiveExists(archiveId) || var9.table.getArchives()[archiveId].getCRC() != this.table.getArchives()[archiveId].getCRC()) && !this.putArchive(id, archiveId, originalStore, false, false)) { + return false; + } + } + + if(!this.rewriteTable()) { + return false; + } else { + this.resetCachedFiles(); + return true; + } + } catch (Exception var91) { + return true; + } + } + + public boolean putArchive(int archiveId, Store originalStore) { + return this.putArchive(this.getId(), archiveId, originalStore, true, true); + } + + public boolean putArchive(int archiveId, Store originalStore, boolean rewriteTable, boolean resetCache) { + return this.putArchive(this.getId(), archiveId, originalStore, rewriteTable, resetCache); + } + + public boolean putArchive(int id, int archiveId, Store originalStore, boolean rewriteTable, boolean resetCache) { + try { + Index var11 = originalStore.getIndexes()[id]; + byte[] data = var11.getMainFile().getArchiveData(archiveId); + if(data == null) { + return false; + } else { + if(!this.archiveExists(archiveId)) { + this.table.addEmptyArchiveReference(archiveId); + } + + ArchiveReference reference = this.table.getArchives()[archiveId]; + reference.updateRevision(); + ArchiveReference originalReference = var11.table.getArchives()[archiveId]; + reference.copyHeader(originalReference); + int revision = reference.getRevision(); + data[data.length - 2] = (byte)(revision >> 8); + data[data.length - 1] = (byte)revision; + if(!this.mainFile.putArchiveData(archiveId, data)) { + return false; + } else if(rewriteTable && !this.rewriteTable()) { + return false; + } else { + if(resetCache) { + this.resetCachedFiles(); + } + + return true; + } + } + } catch (Exception var111) { + return true; + } + } + + public boolean putFile(int archiveId, int fileId, byte[] data) { + return this.putFile(archiveId, fileId, 2, data, null, true, true, -1, -1); + } + + public boolean removeFile(int archiveId, int fileId) { + return this.removeFile(archiveId, fileId, 2, null); + } + + public boolean removeFile(int archiveId, int fileId, int compression, int[] keys) { + if(!this.fileExists(archiveId, fileId)) { + return false; + } else { + this.cacheArchiveFiles(archiveId, keys); + ArchiveReference reference = this.table.getArchives()[archiveId]; + reference.removeFileReference(fileId); + int filesCount = this.getValidFilesCount(archiveId); + byte[] archiveData; + if(filesCount == 1) { + archiveData = this.getFile(archiveId, reference.getValidFileIds()[0], keys); + } else { + int[] var13 = new int[filesCount]; + OutputStream var14 = new OutputStream(); + + int index; + int offset; + for(index = 0; index < filesCount; ++index) { + offset = reference.getValidFileIds()[index]; + byte[] fileData = this.getFile(archiveId, offset, keys); + var13[index] = fileData.length; + var14.writeBytes(fileData); + } + + for(index = 0; index < var13.length; ++index) { + offset = var13[index]; + if(index != 0) { + offset -= var13[index - 1]; + } + + var14.writeInt(offset); + } + + var14.writeByte(1); + archiveData = new byte[var14.getOffset()]; + var14.setOffset(0); + var14.getBytes(archiveData, 0, archiveData.length); + } + + reference.updateRevision(); + Archive var131 = new Archive(archiveId, compression, reference.getRevision(), archiveData); + byte[] var141 = var131.compress(); + reference.setCrc(CRC32HGenerator.getHash(var141, 0, var141.length - 2)); + reference.setWhirpool(Whirlpool.getHash(var141, 0, var141.length - 2)); + if(!this.mainFile.putArchiveData(archiveId, var141)) { + return false; + } else if(!this.rewriteTable()) { + return false; + } else { + this.resetCachedFiles(); + return true; + } + } + } + + public boolean putFile(int archiveId, int fileId, int compression, byte[] data, int[] keys, boolean rewriteTable, boolean resetCache, int archiveName, int fileName) { + if(!this.archiveExists(archiveId)) { + this.table.addEmptyArchiveReference(archiveId); + this.resetCachedFiles(); + this.cachedFiles[archiveId] = new byte[1][]; + } else { + this.cacheArchiveFiles(archiveId, keys); + } + + ArchiveReference reference = this.table.getArchives()[archiveId]; + if(!this.fileExists(archiveId, fileId)) { + reference.addEmptyFileReference(fileId); + } + + reference.sortFiles(); + int filesCount = this.getValidFilesCount(archiveId); + byte[] archiveData; + if(filesCount == 1) { + archiveData = data; + } else { + int[] var18 = new int[filesCount]; + OutputStream var19 = new OutputStream(); + + int index; + int offset; + for(index = 0; index < filesCount; ++index) { + offset = reference.getValidFileIds()[index]; + byte[] fileData; + if(offset == fileId) { + fileData = data; + } else { + fileData = this.getFile(archiveId, offset, keys); + } + + var18[index] = fileData.length; + var19.writeBytes(fileData); + } + + for(index = 0; index < filesCount; ++index) { + offset = var18[index]; + if(index != 0) { + offset -= var18[index - 1]; + } + + var19.writeInt(offset); + } + + var19.writeByte(1); + archiveData = new byte[var19.getOffset()]; + var19.setOffset(0); + var19.getBytes(archiveData, 0, archiveData.length); + } + + reference.updateRevision(); + Archive var181 = new Archive(archiveId, compression, reference.getRevision(), archiveData); + byte[] var191 = var181.compress(); + reference.setCrc(CRC32HGenerator.getHash(var191, 0, var191.length - 2)); + reference.setWhirpool(Whirlpool.getHash(var191, 0, var191.length - 2)); + if(archiveName != -1) { + reference.setNameHash(archiveName); + } + + if(fileName != -1) { + reference.getFiles()[fileId].setNameHash(fileName); + } + + if(!this.mainFile.putArchiveData(archiveId, var191)) { + return false; + } else if(rewriteTable && !this.rewriteTable()) { + return false; + } else { + if(resetCache) { + this.resetCachedFiles(); + } + + return true; + } + } + + public boolean encryptArchive(int archiveId, int[] keys) { + return this.encryptArchive(archiveId, null, keys, true, true); + } + + public boolean encryptArchive(int archiveId, int[] oldKeys, int[] keys, boolean rewriteTable, boolean resetCache) { + if(!this.archiveExists(archiveId)) { + return false; + } else { + Archive archive = this.mainFile.getArchive(archiveId, oldKeys); + if(archive == null) { + return false; + } else { + ArchiveReference reference = this.table.getArchives()[archiveId]; + if(reference.getRevision() != archive.getRevision()) { + throw new RuntimeException("ERROR REVISION"); + } else { + reference.updateRevision(); + archive.setRevision(reference.getRevision()); + archive.setKeys(keys); + byte[] closedArchive = archive.compress(); + reference.setCrc(CRC32HGenerator.getHash(closedArchive, 0, closedArchive.length - 2)); + reference.setWhirpool(Whirlpool.getHash(closedArchive, 0, closedArchive.length - 2)); + if(!this.mainFile.putArchiveData(archiveId, closedArchive)) { + return false; + } else if(rewriteTable && !this.rewriteTable()) { + return false; + } else { + if(resetCache) { + this.resetCachedFiles(); + } + + return true; + } + } + } + } + } + + public boolean rewriteTable() { + this.table.updateRevision(); + this.table.sortTable(); + Object[] hashes = this.table.encodeHeader(this.index255); + if(hashes == null) { + return false; + } else { + this.whirlpool = (byte[])hashes[1]; + return true; + } + } + + public void setKeys(int[] keys) { + this.table.setKeys(keys); + } + + public int[] getKeys() { + return this.table.getKeys(); + } + + private void cacheArchiveFiles(int archiveId, int[] keys) { + Archive archive = this.getArchive(archiveId, keys); + int lastFileId = this.getLastFileId(archiveId); + this.cachedFiles[archiveId] = new byte[lastFileId + 1][]; + if(archive != null) { + byte[] data = archive.getData(); + if(data != null) { + int filesCount = this.getValidFilesCount(archiveId); + if(filesCount == 1) { + this.cachedFiles[archiveId][lastFileId] = data; + } else { + int readPosition = data.length; + --readPosition; + int amtOfLoops = data[readPosition] & 255; + readPosition -= amtOfLoops * filesCount * 4; + InputStream stream = new InputStream(data); + stream.setOffset(readPosition); + int[] filesSize = new int[filesCount]; + + int sourceOffset; + int count; + for(int var18 = 0; var18 < amtOfLoops; ++var18) { + sourceOffset = 0; + + for(count = 0; count < filesCount; ++count) { + filesSize[count] += sourceOffset += stream.readInt(); + } + } + + byte[][] var181 = new byte[filesCount][]; + + for(sourceOffset = 0; sourceOffset < filesCount; ++sourceOffset) { + var181[sourceOffset] = new byte[filesSize[sourceOffset]]; + filesSize[sourceOffset] = 0; + } + + stream.setOffset(readPosition); + sourceOffset = 0; + + int len$; + for(count = 0; count < amtOfLoops; ++count) { + int var19 = 0; + + for(len$ = 0; len$ < filesCount; ++len$) { + var19 += stream.readInt(); + System.arraycopy(data, sourceOffset, var181[len$], filesSize[len$], var19); + sourceOffset += var19; + filesSize[len$] += var19; + } + } + + count = 0; + int[] var191 = this.table.getArchives()[archiveId].getValidFileIds(); + len$ = var191.length; + + for(int i$ = 0; i$ < len$; ++i$) { + int fileId = var191[i$]; + this.cachedFiles[archiveId][fileId] = var181[count++]; + } + } + } + } + + } + + public int getId() { + return this.mainFile.getId(); + } + + public ReferenceTable getTable() { + return this.table; + } + + public MainFile getMainFile() { + return this.mainFile; + } + + public Archive getArchive(int id) { + return this.mainFile.getArchive(id, null); + } + + public Archive getArchive(int id, int[] keys) { + return this.mainFile.getArchive(id, keys); + } + + public int getCRC() { + return this.crc; + } + + public byte[] getWhirlpool() { + return this.whirlpool; + } +} diff --git a/src/com/alex/store/MainFile.java b/src/com/alex/store/MainFile.java new file mode 100644 index 0000000..e1bd87a --- /dev/null +++ b/src/com/alex/store/MainFile.java @@ -0,0 +1,277 @@ +package com.alex.store; + +import com.alex.store.Archive; + +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; + +public final class MainFile { + public static final int IDX_BLOCK_LEN = 6; + public static final int HEADER_LEN = 8; + public static final int EXPANDED_HEADER_LEN = 10; + public static final int BLOCK_LEN = 512; + public static final int EXPANDED_BLOCK_LEN = 510; + public static final int TOTAL_BLOCK_LEN = 520; + private static final ByteBuffer tempBuffer = ByteBuffer.allocateDirect(520); + private final int id; + private final FileChannel index; + private final FileChannel data; + private final boolean newProtocol; + + MainFile(int id, RandomAccessFile data, RandomAccessFile index, boolean newProtocol) throws IOException { + this.id = id; + this.data = data.getChannel(); + this.index = index.getChannel(); + this.newProtocol = newProtocol; + } + + public Archive getArchive(int id) { + return this.getArchive(id, null); + } + + public Archive getArchive(int id, int[] keys) { + byte[] data = this.getArchiveData(id); + return data == null?null:new Archive(id, data, keys); + } + + public byte[] getArchiveData(int archiveId) { + FileChannel var2 = this.data; + FileChannel var3 = this.data; + synchronized(this.data) { + try { + tempBuffer.position(0).limit(6); + this.index.read(tempBuffer, archiveId * 6L); + tempBuffer.flip(); + int var16 = getMediumInt(tempBuffer); + int block = getMediumInt(tempBuffer); + Object var10000; + byte[] var100001; + if(var16 < 0) { + var10000 = null; + var100001 = (byte[])var10000; + return var100001; + } else if(block <= 0 || (long)block > this.data.size() / 520L) { + var10000 = null; + var100001 = (byte[])var10000; + return var100001; + } else { + ByteBuffer fileBuffer = ByteBuffer.allocate(var16); + int remaining = var16; + int chunk = 0; + int blockLen = this.newProtocol && archiveId > '\uffff'?510:512; + int headerLen = this.newProtocol && archiveId > '\uffff'?10:8; + + while(remaining > 0) { + if(block == 0) { + System.out.println(archiveId + ", " + this.newProtocol); + var10000 = null; + var100001 = (byte[])var10000; + return var100001; + } + + int blockSize = remaining > blockLen?blockLen:remaining; + tempBuffer.position(0).limit(blockSize + headerLen); + this.data.read(tempBuffer, block * 520L); + tempBuffer.flip(); + int currentFile; + int currentChunk; + int nextBlock; + int currentIndex; + if(this.newProtocol && archiveId > '\uffff') { + currentFile = tempBuffer.getInt(); + currentChunk = tempBuffer.getShort() & '\uffff'; + nextBlock = getMediumInt(tempBuffer); + currentIndex = tempBuffer.get() & 255; + } else { + currentFile = tempBuffer.getShort() & '\uffff'; + currentChunk = tempBuffer.getShort() & '\uffff'; + nextBlock = getMediumInt(tempBuffer); + currentIndex = tempBuffer.get() & 255; + } + + if((archiveId == currentFile || archiveId > '\uffff') && chunk == currentChunk && this.id == currentIndex) { + if(nextBlock >= 0 && (long)nextBlock <= this.data.size() / 520L) { + fileBuffer.put(tempBuffer); + remaining -= blockSize; + block = nextBlock; + ++chunk; + continue; + } + + var10000 = null; + var100001 = (byte[])var10000; + return var100001; + } + + var10000 = null; + var100001 = (byte[])var10000; + return var100001; + } + + byte[] var18 = (byte[])fileBuffer.flip().array(); + return var18; + } + } catch (Exception var181) { + return null; + } + } + } + + private static int getMediumInt(ByteBuffer buffer) { + return (buffer.get() & 255) << 16 | (buffer.get() & 255) << 8 | buffer.get() & 255; + } + + private static void putMediumInt(ByteBuffer buffer, int val) { + buffer.put((byte)(val >> 16)); + buffer.put((byte)(val >> 8)); + buffer.put((byte)val); + } + + public boolean putArchive(Archive archive) { + return this.putArchiveData(archive.getId(), archive.getData()); + } + + public boolean putArchiveData(int id, byte[] archive) { + ByteBuffer buffer = ByteBuffer.wrap(archive); + boolean done = this.putArchiveData(id, buffer, archive.length, true); + if(!done) { + done = this.putArchiveData(id, buffer, archive.length, false); + } + + return done; + } + + public boolean putArchiveData(int archiveId, ByteBuffer archive, int size, boolean exists) { + FileChannel var5 = this.data; + FileChannel var6 = this.data; + synchronized(this.data) { + try { + boolean var10000; + int var16; + boolean var100001; + if(exists) { + if((long)(archiveId * 6L + 6) > this.index.size()) { + var10000 = false; + var100001 = var10000; + return var100001; + } + + tempBuffer.position(0).limit(6); + this.index.read(tempBuffer, archiveId * 6L); + tempBuffer.flip().position(3); + var16 = getMediumInt(tempBuffer); + if(var16 <= 0 || (long)var16 > this.data.size() / 520L) { + var10000 = false; + var100001 = var10000; + return var100001; + } + } else { + var16 = (int)(this.data.size() + 520L - 1L) / 520; + if(var16 == 0) { + var16 = 1; + } + } + + tempBuffer.position(0); + putMediumInt(tempBuffer, size); + putMediumInt(tempBuffer, var16); + tempBuffer.flip(); + this.index.write(tempBuffer, archiveId * 6L); + int remaining = size; + int chunk = 0; + int blockLen = this.newProtocol && archiveId > '\uffff'?510:512; + + for(int headerLen = this.newProtocol && archiveId > '\uffff'?10:8; remaining > 0; ++chunk) { + int nextBlock = 0; + int blockSize; + if(exists) { + tempBuffer.position(0).limit(headerLen); + this.data.read(tempBuffer, var16 * 520L); + tempBuffer.flip(); + int currentChunk; + int currentIndex; + if(this.newProtocol && archiveId > '\uffff') { + blockSize = tempBuffer.getInt(); + currentChunk = tempBuffer.getShort() & '\uffff'; + nextBlock = getMediumInt(tempBuffer); + currentIndex = tempBuffer.get() & 255; + } else { + blockSize = tempBuffer.getShort() & '\uffff'; + currentChunk = tempBuffer.getShort() & '\uffff'; + nextBlock = getMediumInt(tempBuffer); + currentIndex = tempBuffer.get() & 255; + } + + if(archiveId != blockSize && archiveId <= '\uffff' || chunk != currentChunk || this.id != currentIndex) { + var10000 = false; + var100001 = var10000; + return var100001; + } + + if(nextBlock < 0 || (long)nextBlock > this.data.size() / 520L) { + var10000 = false; + var100001 = var10000; + return var100001; + } + } + + if(nextBlock == 0) { + exists = false; + nextBlock = (int)((this.data.size() + 520L - 1L) / 520L); + if(nextBlock == 0) { + nextBlock = 1; + } + + if(nextBlock == var16) { + ++nextBlock; + } + } + + if(remaining <= blockLen) { + nextBlock = 0; + } + + tempBuffer.position(0).limit(520); + if(this.newProtocol && archiveId > '\uffff') { + tempBuffer.putInt(archiveId); + tempBuffer.putShort((short)chunk); + putMediumInt(tempBuffer, nextBlock); + tempBuffer.put((byte)this.id); + } else { + tempBuffer.putShort((short)archiveId); + tempBuffer.putShort((short)chunk); + putMediumInt(tempBuffer, nextBlock); + tempBuffer.put((byte)this.id); + } + + blockSize = remaining > blockLen?blockLen:remaining; + archive.limit(archive.position() + blockSize); + tempBuffer.put(archive); + tempBuffer.flip(); + this.data.write(tempBuffer, var16 * 520L); + remaining -= blockSize; + var16 = nextBlock; + } + + var10000 = true; + return var10000; + } catch (Exception var17) { + return false; + } + } + } + + public int getId() { + return this.id; + } + + public int getArchivesCount() throws IOException { + FileChannel var1 = this.index; + FileChannel var2 = this.index; + synchronized(this.index) { + return (int)(this.index.size() / 6L); + } + } +} diff --git a/src/com/alex/store/ReferenceTable.java b/src/com/alex/store/ReferenceTable.java new file mode 100644 index 0000000..c415631 --- /dev/null +++ b/src/com/alex/store/ReferenceTable.java @@ -0,0 +1,317 @@ +package com.alex.store; + +import com.alex.io.InputStream; +import com.alex.io.OutputStream; +import com.alex.store.Archive; +import com.alex.store.ArchiveReference; +import com.alex.store.FileReference; +import com.alex.store.MainFile; + +import java.util.Arrays; + +public final class ReferenceTable { + private final Archive archive; + private int revision; + private boolean named; + private boolean usesWhirpool; + private ArchiveReference[] archives; + private int[] validArchiveIds; + private boolean updatedRevision; + private boolean needsArchivesSort; + + ReferenceTable(Archive archive) { + this.archive = archive; + this.decodeHeader(); + } + + public void setKeys(int[] keys) { + this.archive.setKeys(keys); + } + + public int[] getKeys() { + return this.archive.getKeys(); + } + + public void sortArchives() { + Arrays.sort(this.validArchiveIds); + this.needsArchivesSort = false; + } + + public void addEmptyArchiveReference(int archiveId) { + this.needsArchivesSort = true; + int[] newValidArchiveIds = Arrays.copyOf(this.validArchiveIds, this.validArchiveIds.length + 1); + newValidArchiveIds[newValidArchiveIds.length - 1] = archiveId; + this.validArchiveIds = newValidArchiveIds; + ArchiveReference reference; + if(this.archives.length <= archiveId) { + ArchiveReference[] newArchives = Arrays.copyOf(this.archives, archiveId + 1); + reference = newArchives[archiveId] = new ArchiveReference(); + this.archives = newArchives; + } else { + reference = this.archives[archiveId] = new ArchiveReference(); + } + + reference.reset(); + } + + public void sortTable() { + if(this.needsArchivesSort) { + this.sortArchives(); + } + + for(int index = 0; index < this.validArchiveIds.length; ++index) { + ArchiveReference archive = this.archives[this.validArchiveIds[index]]; + if(archive.isNeedsFilesSort()) { + archive.sortFiles(); + } + } + + } + + public Object[] encodeHeader(MainFile mainFile) { + OutputStream stream = new OutputStream(); + int protocol = this.getProtocol(); + stream.writeByte(protocol); + if(protocol >= 6) { + stream.writeInt(this.revision); + } + + stream.writeByte((this.named?1:0) | (this.usesWhirpool?2:0)); + if(protocol >= 7) { + stream.writeBigSmart(this.validArchiveIds.length); + } else { + stream.writeShort(this.validArchiveIds.length); + } + + int data; + int archive; + for(data = 0; data < this.validArchiveIds.length; ++data) { + archive = this.validArchiveIds[data]; + if(data != 0) { + archive -= this.validArchiveIds[data - 1]; + } + + if(protocol >= 7) { + stream.writeBigSmart(archive); + } else { + stream.writeShort(archive); + } + } + + if(this.named) { + for(data = 0; data < this.validArchiveIds.length; ++data) { + stream.writeInt(this.archives[this.validArchiveIds[data]].getNameHash()); + } + } + + if(this.usesWhirpool) { + for(data = 0; data < this.validArchiveIds.length; ++data) { + stream.writeBytes(this.archives[this.validArchiveIds[data]].getWhirpool()); + } + } + + for(data = 0; data < this.validArchiveIds.length; ++data) { + stream.writeInt(this.archives[this.validArchiveIds[data]].getCRC()); + } + + for(data = 0; data < this.validArchiveIds.length; ++data) { + stream.writeInt(this.archives[this.validArchiveIds[data]].getRevision()); + } + + for(data = 0; data < this.validArchiveIds.length; ++data) { + archive = this.archives[this.validArchiveIds[data]].getValidFileIds().length; + if(protocol >= 7) { + stream.writeBigSmart(archive); + } else { + stream.writeShort(archive); + } + } + + int index2; + ArchiveReference var8; + for(data = 0; data < this.validArchiveIds.length; ++data) { + var8 = this.archives[this.validArchiveIds[data]]; + + for(index2 = 0; index2 < var8.getValidFileIds().length; ++index2) { + int var9 = var8.getValidFileIds()[index2]; + if(index2 != 0) { + var9 -= var8.getValidFileIds()[index2 - 1]; + } + + if(protocol >= 7) { + stream.writeBigSmart(var9); + } else { + stream.writeShort(var9); + } + } + } + + if(this.named) { + for(data = 0; data < this.validArchiveIds.length; ++data) { + var8 = this.archives[this.validArchiveIds[data]]; + + for(index2 = 0; index2 < var8.getValidFileIds().length; ++index2) { + stream.writeInt(var8.getFiles()[var8.getValidFileIds()[index2]].getNameHash()); + } + } + } + + byte[] var91 = new byte[stream.getOffset()]; + stream.setOffset(0); + stream.getBytes(var91, 0, var91.length); + return this.archive.editNoRevision(var91, mainFile); + } + + public int getProtocol() { + if(this.archives.length > '\uffff') { + return 7; + } else { + for(int index = 0; index < this.validArchiveIds.length; ++index) { + if(index > 0 && this.validArchiveIds[index] - this.validArchiveIds[index - 1] > '\uffff') { + return 7; + } + + if(this.archives[this.validArchiveIds[index]].getValidFileIds().length > '\uffff') { + return 7; + } + } + + return this.revision == 0?5:6; + } + } + + public void setRevision(int revision) { + this.updatedRevision = true; + this.revision = revision; + } + + public void updateRevision() { + if(!this.updatedRevision) { + ++this.revision; + this.updatedRevision = true; + } + + } + + private void decodeHeader() { + InputStream stream = new InputStream(this.archive.getData()); + int protocol = stream.readUnsignedByte(); + if(protocol >= 5 && protocol <= 7) { + if(protocol >= 6) { + this.revision = stream.readInt(); + } + + int hash = stream.readUnsignedByte(); + this.named = (1 & hash) != 0; + this.usesWhirpool = (2 & hash) != 0; + int validArchivesCount = protocol >= 7?stream.readBigSmart():stream.readUnsignedShort(); + this.validArchiveIds = new int[validArchivesCount]; + int lastArchiveId = 0; + int biggestArchiveId = 0; + + int index; + int archive; + for(index = 0; index < validArchivesCount; ++index) { + archive = lastArchiveId += protocol >= 7?stream.readBigSmart():stream.readUnsignedShort(); + if(archive > biggestArchiveId) { + biggestArchiveId = archive; + } + + this.validArchiveIds[index] = archive; + } + + this.archives = new ArchiveReference[biggestArchiveId + 1]; + + for(index = 0; index < validArchivesCount; ++index) { + this.archives[this.validArchiveIds[index]] = new ArchiveReference(); + } + + if(this.named) { + for(index = 0; index < validArchivesCount; ++index) { + this.archives[this.validArchiveIds[index]].setNameHash(stream.readInt()); + } + } + + if(this.usesWhirpool) { + for(index = 0; index < validArchivesCount; ++index) { + byte[] index2 = new byte[64]; + stream.getBytes(index2, 0, 64); + this.archives[this.validArchiveIds[index]].setWhirpool(index2); + } + } + + for(index = 0; index < validArchivesCount; ++index) { + this.archives[this.validArchiveIds[index]].setCrc(stream.readInt()); + } + + for(index = 0; index < validArchivesCount; ++index) { + this.archives[this.validArchiveIds[index]].setRevision(stream.readInt()); + } + + for(index = 0; index < validArchivesCount; ++index) { + this.archives[this.validArchiveIds[index]].setValidFileIds(new int[protocol >= 7?stream.readBigSmart():stream.readUnsignedShort()]); + } + + ArchiveReference var14; + int var13; + for(index = 0; index < validArchivesCount; ++index) { + archive = 0; + var13 = 0; + var14 = this.archives[this.validArchiveIds[index]]; + + int index21; + for(index21 = 0; index21 < var14.getValidFileIds().length; ++index21) { + int fileId = archive += protocol >= 7?stream.readBigSmart():stream.readUnsignedShort(); + if(fileId > var13) { + var13 = fileId; + } + + var14.getValidFileIds()[index21] = fileId; + } + + var14.setFiles(new FileReference[var13 + 1]); + + for(index21 = 0; index21 < var14.getValidFileIds().length; ++index21) { + var14.getFiles()[var14.getValidFileIds()[index21]] = new FileReference(); + } + } + + if(this.named) { + for(index = 0; index < validArchivesCount; ++index) { + var14 = this.archives[this.validArchiveIds[index]]; + + for(var13 = 0; var13 < var14.getValidFileIds().length; ++var13) { + var14.getFiles()[var14.getValidFileIds()[var13]].setNameHash(stream.readInt()); + } + } + } + + } else { + throw new RuntimeException("INVALID PROTOCOL"); + } + } + + public int getRevision() { + return this.revision; + } + + public ArchiveReference[] getArchives() { + return this.archives; + } + + public int[] getValidArchiveIds() { + return this.validArchiveIds; + } + + public boolean isNamed() { + return this.named; + } + + public boolean usesWhirpool() { + return this.usesWhirpool; + } + + public int getCompression() { + return this.archive.getCompression(); + } +} diff --git a/src/com/alex/store/Store.java b/src/com/alex/store/Store.java new file mode 100644 index 0000000..4bec0d3 --- /dev/null +++ b/src/com/alex/store/Store.java @@ -0,0 +1,152 @@ +package com.alex.store; + +import com.alex.io.OutputStream; +import com.alex.store.Archive; +import com.alex.store.Index; +import com.alex.store.MainFile; +import com.alex.util.whirlpool.Whirlpool; +import com.alex.utils.Utils; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.math.BigInteger; +import java.util.Arrays; + +public final class Store { + private Index[] indexes; + private final MainFile index255; + private final String path; + private final RandomAccessFile data; + private final boolean newProtocol; + + public Store(String path) throws IOException { + this(path, true); + } + + public Store(String path, boolean newProtocol) throws IOException { + this(path, newProtocol, null); + } + + public Store(String path, boolean newProtocol, int[][] keys) throws IOException { + this.path = path; + this.newProtocol = newProtocol; + this.data = new RandomAccessFile(path + "main_file_cache.dat2", "rw"); + this.index255 = new MainFile(255, this.data, new RandomAccessFile(path + "main_file_cache.idx255", "rw"), newProtocol); + int idxsCount = this.index255.getArchivesCount(); + this.indexes = new Index[idxsCount]; + + for(int id = 0; id < idxsCount; ++id) { + Index index = new Index(this.index255, new MainFile(id, this.data, new RandomAccessFile(path + "main_file_cache.idx" + id, "rw"), newProtocol), keys == null?null:keys[id]); + if(index.getTable() != null) { + this.indexes[id] = index; + } + } + + } + + public byte[] generateIndex255Archive255Current(BigInteger grab_server_private_exponent, BigInteger grab_server_modulus) { + OutputStream stream = new OutputStream(); + stream.writeByte(this.getIndexes().length); + + for(int var9 = 0; var9 < this.getIndexes().length; ++var9) { + if(this.getIndexes()[var9] == null) { + stream.writeInt(0); + stream.writeInt(0); + stream.writeBytes(new byte[64]); + } else { + stream.writeInt(this.getIndexes()[var9].getCRC()); + stream.writeInt(this.getIndexes()[var9].getTable().getRevision()); + stream.writeBytes(this.getIndexes()[var9].getWhirlpool()); + if(this.getIndexes()[var9].getKeys() != null) { + int[] var10 = this.getIndexes()[var9].getKeys(); + int var12 = var10.length; + + for(int i$ = 0; i$ < var12; ++i$) { + int key = var10[i$]; + stream.writeInt(key); + } + } else { + for(int var11 = 0; var11 < 4; ++var11) { + stream.writeInt(0); + } + } + } + } + + byte[] var91 = new byte[stream.getOffset()]; + stream.setOffset(0); + stream.getBytes(var91, 0, var91.length); + OutputStream var111 = new OutputStream(65); + var111.writeByte(0); + var111.writeBytes(Whirlpool.getHash(var91, 0, var91.length)); + byte[] var121 = new byte[var111.getOffset()]; + var111.setOffset(0); + var111.getBytes(var121, 0, var121.length); + if(grab_server_private_exponent != null && grab_server_modulus != null) { + var121 = Utils.cryptRSA(var121, grab_server_private_exponent, grab_server_modulus); + } + + stream.writeBytes(var121); + var91 = new byte[stream.getOffset()]; + stream.setOffset(0); + stream.getBytes(var91, 0, var91.length); + return var91; + } + + public byte[] generateIndex255Archive255() { + return this.generateIndex255Archive255Current(null, null); + } + + public byte[] generateIndex255Archive255Outdated() { + OutputStream stream = new OutputStream(this.indexes.length * 8); + + for(int var3 = 0; var3 < this.indexes.length; ++var3) { + if(this.indexes[var3] == null) { + stream.writeInt(0); + stream.writeInt(0); + } else { + stream.writeInt(this.indexes[var3].getCRC()); + stream.writeInt(this.indexes[var3].getTable().getRevision()); + } + } + + byte[] var31 = new byte[stream.getOffset()]; + stream.setOffset(0); + stream.getBytes(var31, 0, var31.length); + return var31; + } + + public Index[] getIndexes() { + return this.indexes; + } + + public MainFile getIndex255() { + return this.index255; + } + + public int addIndex(boolean named, boolean usesWhirpool, int tableCompression) throws IOException { + int id = this.indexes.length; + Index[] newIndexes = Arrays.copyOf(this.indexes, this.indexes.length + 1); + this.resetIndex(id, newIndexes, named, usesWhirpool, tableCompression); + this.indexes = newIndexes; + return id; + } + + public void resetIndex(int id, boolean named, boolean usesWhirpool, int tableCompression) throws IOException { + this.resetIndex(id, this.indexes, named, usesWhirpool, tableCompression); + } + + public void resetIndex(int id, Index[] indexes, boolean named, boolean usesWhirpool, int tableCompression) throws IOException { + OutputStream stream = new OutputStream(4); + stream.writeByte(5); + stream.writeByte((named?1:0) | (usesWhirpool?2:0)); + stream.writeShort(0); + byte[] archiveData = new byte[stream.getOffset()]; + stream.setOffset(0); + stream.getBytes(archiveData, 0, archiveData.length); + Archive archive = new Archive(id, tableCompression, -1, archiveData); + this.index255.putArchiveData(id, archive.compress()); + indexes[id] = new Index(this.index255, new MainFile(id, this.data, new RandomAccessFile(this.path + "main_file_cache.idx" + id, "rw"), this.newProtocol), null); + } +} diff --git a/src/com/alex/tools/clientCacheUpdater/ArchiveValidation.java b/src/com/alex/tools/clientCacheUpdater/ArchiveValidation.java new file mode 100644 index 0000000..6c99c01 --- /dev/null +++ b/src/com/alex/tools/clientCacheUpdater/ArchiveValidation.java @@ -0,0 +1,48 @@ +package com.alex.tools.clientCacheUpdater; + +import com.alex.store.Archive; +import com.alex.store.ArchiveReference; +import com.alex.store.Index; +import com.alex.store.Store; + +import java.io.IOException; +import java.util.Random; + +public class ArchiveValidation { + public static void main(String[] args) throws IOException { + Store rscache = new Store("718/cache/"); + + for(int i = 0; i < rscache.getIndexes().length; ++i) { + if(i != 5) { + Index index = rscache.getIndexes()[i]; + System.out.println("checking index: " + i); + int[] arr$ = index.getTable().getValidArchiveIds(); + int len$ = arr$.length; + + for(int i$ = 0; i$ < len$; ++i$) { + int archiveId = arr$[i$]; + Archive archive = index.getArchive(archiveId); + if(archive == null) { + System.out.println("Missing:: " + i + ", " + archiveId); + } else { + ArchiveReference reference = index.getTable().getArchives()[archiveId]; + if(archive.getRevision() != reference.getRevision()) { + System.out.println("corrupted: " + i + ", " + archiveId); + } + } + } + } + } + + } + + public static int[] generateKeys() { + int[] keys = new int[4]; + + for(int index = 0; index < keys.length; ++index) { + keys[index] = (new Random()).nextInt(); + } + + return keys; + } +} diff --git a/src/com/alex/tools/clientCacheUpdater/CacheEditor.java b/src/com/alex/tools/clientCacheUpdater/CacheEditor.java new file mode 100644 index 0000000..de6fd33 --- /dev/null +++ b/src/com/alex/tools/clientCacheUpdater/CacheEditor.java @@ -0,0 +1,190 @@ +package com.alex.tools.clientCacheUpdater; + +import com.alex.loaders.items.ItemDefinitions; +import com.alex.store.Index; +import com.alex.store.Store; +import com.alex.tools.clientCacheUpdater.RSXteas; +import com.alex.utils.Utils; + +import javax.imageio.ImageIO; +import javax.imageio.stream.ImageOutputStream; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public class CacheEditor { + public static byte[] getBytesFromFile(File file) throws IOException { + FileInputStream is = new FileInputStream(file); + long length = file.length(); + if(length > 2147483647L) { + } + + byte[] bytes = new byte[(int)length]; + int offset = 0; + + int numRead1; + for(boolean numRead = false; offset < bytes.length && (numRead1 = is.read(bytes, offset, bytes.length - offset)) >= 0; offset += numRead1) { + } + + if(offset < bytes.length) { + throw new IOException("Could not completely read file " + file.getName()); + } else { + is.close(); + return bytes; + } + } + + public static int packCustomModel(Store cache, byte[] data) { + int archiveId = cache.getIndexes()[7].getLastArchiveId() + 1; + if(cache.getIndexes()[7].putFile(archiveId, 0, data)) { + return archiveId; + } else { + System.out.println("Failing packing model " + archiveId); + return -1; + } + } + + public static void packCustomItem(Store cache, int id, ItemDefinitions def) { + cache.getIndexes()[19].putFile(id >>> 8, 255 & id, def.encode()); + } + + public static void divideBackgrounds() throws IOException { + BufferedImage background = ImageIO.read(new File("718/sprites/bg.jpg")); + int id = 4139; + int sx = background.getWidth() / 4; + int sy = background.getHeight() / 2; + + int y; + for(int var8 = 0; var8 < 2; ++var8) { + for(y = 0; y < 4; ++y) { + BufferedImage var9 = background.getSubimage(y * sx, var8 * sy, sx, sy); + ImageIO.write(var9, "gif", new File("718/sprites/bg/" + id++ + ".gif")); + } + } + + BufferedImage var81 = ImageIO.read(new File("718/sprites/load.png")); + id = 3769; + sx = var81.getWidth() / 2; + sy = var81.getHeight() / 2; + + for(y = 0; y < 2; ++y) { + for(int var91 = 0; var91 < 2; ++var91) { + BufferedImage part = var81.getSubimage(var91 * sx, y * sy, sx, sy); + ImageIO.write(part, "png", new File("718/sprites/load/" + id + ".png")); + ImageIO.write(part, "gif", new File("718/sprites/load/" + id++ + ".gif")); + } + } + + } + + public static byte[] getImage(File file) throws IOException { + ImageOutputStream stream = ImageIO.createImageOutputStream(file); + byte[] data = new byte[(int)stream.length()]; + stream.read(data); + return data; + } + + public static void main(String[] args) throws IOException { + boolean beta = false; + boolean addNewItemDefinitions = false; + boolean divideBackgrounds = false; + if(divideBackgrounds) { + divideBackgrounds(); + } + + Store rscache = new Store(beta?"718/rsCacheBeta/":"718/rscache/"); + Store cache = new Store(beta?"718/cacheBeta/":"718/cache/"); + cache.resetIndex(7, false, false, 2); + + boolean result; + int regionId; + for(regionId = 0; regionId < cache.getIndexes().length; ++regionId) { + if(regionId != 3 && regionId != 5 && regionId != 12) { + result = cache.getIndexes()[regionId].packIndex(rscache, true); + System.out.println("Packed index archives: " + regionId + ", " + result); + } + } + + int regionY; + if(addNewItemDefinitions) { + System.out.println("Packing old item definitions..."); + Store var14 = new Store("cache667/", false); + short var15 = 30000; + regionY = Utils.getItemDefinitionsSize(var14); + + for(int data = var15; data < var15 + regionY; ++data) { + int var16 = data - var15; + cache.getIndexes()[19].putFile(data >>> 8, 255 & data, 2, var14.getIndexes()[19].getFile(var16 >>> 8, 255 & var16), null, false, false, -1, -1); + } + + result = cache.getIndexes()[19].rewriteTable(); + System.out.println("Packed old item definitions: " + result); + } + + System.out.println("Adding new interfaces..."); + + for(regionId = cache.getIndexes()[3].getLastArchiveId() + 1; regionId <= rscache.getIndexes()[3].getLastArchiveId(); ++regionId) { + if(regionId != 548 && regionId != 746 && rscache.getIndexes()[3].archiveExists(regionId)) { + cache.getIndexes()[3].putArchive(regionId, rscache, false, false); + } + } + + result = cache.getIndexes()[3].rewriteTable(); + System.out.println("Packed new interfaces: " + result); + RSXteas.loadUnpackedXteas("old"); + System.out.println("Updating Maps."); + + for(regionId = 0; regionId < 30000; ++regionId) { + int var13 = (regionId >> 8) * 64; + regionY = (regionId & 255) * 64; + String var141 = "m" + (var13 >> 3) / 8 + "_" + (regionY >> 3) / 8; + byte[] var151 = rscache.getIndexes()[5].getFile(rscache.getIndexes()[5].getArchiveId(var141)); + if(var151 != null) { + result = addMapFile(cache.getIndexes()[5], var141, var151); + System.out.println(var141 + ", " + result); + } + + var141 = "um" + (var13 >> 3) / 8 + "_" + (regionY >> 3) / 8; + var151 = rscache.getIndexes()[5].getFile(rscache.getIndexes()[5].getArchiveId(var141)); + if(var151 != null) { + result = addMapFile(cache.getIndexes()[5], var141, var151); + System.out.println(var141 + ", " + result); + } + + int[] var161 = RSXteas.getXteas(regionId); + var141 = "l" + (var13 >> 3) / 8 + "_" + (regionY >> 3) / 8; + var151 = rscache.getIndexes()[5].getFile(rscache.getIndexes()[5].getArchiveId(var141), 0, var161); + if(var151 != null) { + result = addMapFile(cache.getIndexes()[5], var141, var151); + System.out.println(var141 + ", " + result); + } + + var141 = "ul" + (var13 >> 3) / 8 + "_" + (regionY >> 3) / 8; + var151 = rscache.getIndexes()[5].getFile(rscache.getIndexes()[5].getArchiveId(var141), 0, var161); + if(var151 != null) { + result = addMapFile(cache.getIndexes()[5], var141, var151); + System.out.println(var141 + ", " + result); + } + + var141 = "n" + (var13 >> 3) / 8 + "_" + (regionY >> 3) / 8; + var151 = rscache.getIndexes()[5].getFile(rscache.getIndexes()[5].getArchiveId(var141), 0); + if(var151 != null) { + result = addMapFile(cache.getIndexes()[5], var141, var151); + System.out.println(var141 + ", " + result); + } + } + + result = cache.getIndexes()[5].rewriteTable(); + System.out.println("Updated maps: " + result); + } + + public static boolean addMapFile(Index index, String name, byte[] data) { + int archiveId = index.getArchiveId(name); + if(archiveId == -1) { + archiveId = index.getTable().getValidArchiveIds().length; + } + + return index.putFile(archiveId, 0, 2, data, null, false, false, Utils.getNameHash(name), -1); + } +} diff --git a/src/com/alex/tools/clientCacheUpdater/CacheEditormodels.java b/src/com/alex/tools/clientCacheUpdater/CacheEditormodels.java new file mode 100644 index 0000000..fef1bb4 --- /dev/null +++ b/src/com/alex/tools/clientCacheUpdater/CacheEditormodels.java @@ -0,0 +1,133 @@ +package com.alex.tools.clientCacheUpdater; + +import com.alex.loaders.items.ItemDefinitions; +import com.alex.store.Store; +import com.alex.utils.Utils; + +import javax.imageio.ImageIO; +import javax.imageio.stream.ImageOutputStream; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public class CacheEditormodels { + public static byte[] getBytesFromFile(File file) throws IOException { + FileInputStream is = new FileInputStream(file); + long length = file.length(); + if(length > 2147483647L) { + } + + byte[] bytes = new byte[(int)length]; + int offset = 0; + + int numRead1; + for(boolean numRead = false; offset < bytes.length && (numRead1 = is.read(bytes, offset, bytes.length - offset)) >= 0; offset += numRead1) { + } + + if(offset < bytes.length) { + throw new IOException("Could not completely read file " + file.getName()); + } else { + is.close(); + return bytes; + } + } + + public static int packCustomModel(Store cache, byte[] data) { + int archiveId = cache.getIndexes()[7].getLastArchiveId() + 1; + if(cache.getIndexes()[7].putFile(archiveId, 0, data)) { + return archiveId; + } else { + System.out.println("Failing packing model " + archiveId); + return -1; + } + } + + public static void packCustomItems(Store cache) throws IOException { + int modelID = packCustomModel(cache, getBytesFromFile(new File("pkcapefinalb.dat"))); + ItemDefinitions pkCape = ItemDefinitions.getItemDefinition(cache, 9747); + pkCape.setName("PK Cape"); + pkCape.femaleEquip1 = modelID; + pkCape.maleEquip1 = modelID; + pkCape.modelId = modelID; + pkCape.resetModelColors(); + packCustomItem(cache, 30000, pkCape); + } + + public static void packCustomItem(Store cache, int id, ItemDefinitions def) { + cache.getIndexes()[19].putFile(id >>> 8, 255 & id, def.encode()); + } + + public static void divideBackgrounds() throws IOException { + BufferedImage background = ImageIO.read(new File("718/sprites/bg.jpg")); + int id = 4139; + int sx = background.getWidth() / 4; + int sy = background.getHeight() / 2; + + int y; + for(int var8 = 0; var8 < 2; ++var8) { + for(y = 0; y < 4; ++y) { + BufferedImage var9 = background.getSubimage(y * sx, var8 * sy, sx, sy); + ImageIO.write(var9, "gif", new File("718/sprites/bg/" + id++ + ".gif")); + } + } + + BufferedImage var81 = ImageIO.read(new File("718/sprites/load.png")); + id = 3769; + sx = var81.getWidth() / 2; + sy = var81.getHeight() / 2; + + for(y = 0; y < 2; ++y) { + for(int var91 = 0; var91 < 2; ++var91) { + BufferedImage part = var81.getSubimage(var91 * sx, y * sy, sx, sy); + ImageIO.write(part, "png", new File("718/sprites/load/" + id + ".png")); + ImageIO.write(part, "gif", new File("718/sprites/load/" + id++ + ".gif")); + } + } + + } + + public static byte[] getImage(File file) throws IOException { + ImageOutputStream stream = ImageIO.createImageOutputStream(file); + byte[] data = new byte[(int)stream.length()]; + stream.read(data); + return data; + } + + public static void main(String[] args) throws IOException { + boolean beta = false; + boolean addNewItemDefinitions = false; + boolean divideBackgrounds = false; + if(divideBackgrounds) { + divideBackgrounds(); + } + + Store rscache = new Store(beta?"718/rsCacheBeta/":"718/rscache/"); + Store cache = new Store(beta?"718/cacheBeta/":"718/cache/"); + cache.resetIndex(7, false, false, 2); + + boolean result; + for(int var13 = 0; var13 < cache.getIndexes().length; ++var13) { + if(var13 != 3 && var13 != 5 && var13 != 12) { + result = cache.getIndexes()[var13].packIndex(rscache, true); + System.out.println("Packed index archives: " + var13 + ", " + result); + } + } + + if(addNewItemDefinitions) { + System.out.println("Packing old item definitions..."); + Store var12 = new Store("cache667/", false); + short currentSize = 30000; + int oldSize = Utils.getItemDefinitionsSize(var12); + + for(int i = currentSize; i < currentSize + oldSize; ++i) { + int oldItemId = i - currentSize; + cache.getIndexes()[19].putFile(i >>> 8, 255 & i, 2, var12.getIndexes()[19].getFile(oldItemId >>> 8, 255 & oldItemId), null, false, false, -1, -1); + } + + result = cache.getIndexes()[19].rewriteTable(); + System.out.println("Packed old item definitions: " + result); + } + + } +} diff --git a/src/com/alex/tools/clientCacheUpdater/CheckMap.java b/src/com/alex/tools/clientCacheUpdater/CheckMap.java new file mode 100644 index 0000000..a732765 --- /dev/null +++ b/src/com/alex/tools/clientCacheUpdater/CheckMap.java @@ -0,0 +1,96 @@ +package com.alex.tools.clientCacheUpdater; + +import com.alex.store.Store; +import com.alex.utils.Utils; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.Random; + +public class CheckMap { + public static void main(String[] args) throws IOException { + Store cache = new Store("C:/Users/yvonne � christer/Dropbox/Source/data/562cache/", false, null); + double land = 0.0D; + double map = 0.0D; + + for(int var11 = 0; var11 < 30000; ++var11) { + int regionX = (var11 >> 8) * 64; + int regionY = (var11 & 255) * 64; + String name1 = "l" + (regionX >> 3) / 8 + "_" + (regionY >> 3) / 8; + String name2 = "m" + (regionX >> 3) / 8 + "_" + (regionY >> 3) / 8; + if(cache.getIndexes()[5].getArchiveId(name1) != -1) { + ++land; + } + + if(cache.getIndexes()[5].getArchiveId(name2) != -1) { + ++map; + } + } + + System.out.println("land: " + land + ", newMaps: " + map); + double var111 = land * 100.0D / map; + System.out.println(var111 + "% complete!"); + } + + public static boolean passArchive(int regionId, Store store1, Store store2, String nameHash, int i, int[] keys1, int[] keys2) { + if(keys2 != null) { + System.out.println(keys2); + } + + int archiveId = store1.getIndexes()[i].getArchiveId(nameHash); + if(archiveId == -1) { + return false; + } else { + int oldArchiveId = store2.getIndexes()[i].getArchiveId(nameHash); + if(oldArchiveId == -1) { + oldArchiveId = store2.getIndexes()[i].getLastArchiveId() + 1; + } + + byte[] data = store1.getIndexes()[i].getFile(archiveId, 0, keys1); + if(data == null) { + return false; + } else { + try { + boolean var13 = store2.getIndexes()[i].putFile(oldArchiveId, 0, 2, data, keys2, false, false, Utils.getNameHash(nameHash), -1); + if(!var13) { + return false; + } else { + int[] keys = writeKeys(regionId); + return store2.getIndexes()[i].encryptArchive(oldArchiveId, keys2, keys, false, false); + } + } catch (Error var12) { + return false; + } catch (Exception var131) { + var131.printStackTrace(); + return false; + } + } + } + } + + public static int[] generateKeys() { + int[] keys = new int[4]; + + for(int index = 0; index < keys.length; ++index) { + keys[index] = (new Random()).nextInt(); + } + + return keys; + } + + public static int[] writeKeys(int regionId) throws IOException { + BufferedWriter writer = new BufferedWriter(new FileWriter("C:/Users/yvonne � christer/Desktop/LS/Xteas/xteas/742/" + regionId + ".txt")); + int[] keys = generateKeys(); + + for(int index = 0; index < keys.length; ++index) { + writer.write("" + keys[index]); + writer.newLine(); + writer.flush(); + } + + System.out.println("Region: " + regionId + ", " + Arrays.toString(keys)); + return keys; + } +} diff --git a/src/com/alex/tools/clientCacheUpdater/CopyCache.java b/src/com/alex/tools/clientCacheUpdater/CopyCache.java new file mode 100644 index 0000000..090d562 --- /dev/null +++ b/src/com/alex/tools/clientCacheUpdater/CopyCache.java @@ -0,0 +1,22 @@ +package com.alex.tools.clientCacheUpdater; + +import com.alex.store.Index; +import com.alex.store.Store; + +import java.io.IOException; + +public class CopyCache { + public static void main(String[] args) throws IOException { + Store cache = new Store("718/cache/"); + Store newCache = new Store("718/cacheCleaned/"); + + for(int i = 0; i < cache.getIndexes().length; ++i) { + Index index = cache.getIndexes()[i]; + newCache.addIndex(index.getTable().isNamed(), index.getTable().usesWhirpool(), 2); + newCache.getIndexes()[i].packIndex(cache); + newCache.getIndexes()[i].getTable().setRevision(cache.getIndexes()[i].getTable().getRevision()); + newCache.getIndexes()[i].rewriteTable(); + } + + } +} diff --git a/src/com/alex/tools/clientCacheUpdater/OriginalXteas.java b/src/com/alex/tools/clientCacheUpdater/OriginalXteas.java new file mode 100644 index 0000000..0d9b204 --- /dev/null +++ b/src/com/alex/tools/clientCacheUpdater/OriginalXteas.java @@ -0,0 +1,57 @@ +package com.alex.tools.clientCacheUpdater; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.HashMap; + +public final class OriginalXteas { + public static final HashMap mapContainersXteas = new HashMap(); + + public static int[] getXteas(int regionId) { + return (int[])mapContainersXteas.get(Integer.valueOf(regionId)); + } + + public static void init() { + loadUnpackedXteas(); + } + + public static void delete() { + } + + public static void loadUnpackedXteas() { + try { + File var11 = new File("cache667_protected/keys"); + File[] xteasFiles = var11.listFiles(); + File[] arr$ = xteasFiles; + int len$ = xteasFiles.length; + + for(int i$ = 0; i$ < len$; ++i$) { + File region = arr$[i$]; + String name = region.getName(); + if(!name.contains(".txt")) { + region.delete(); + } else { + short regionId = Short.parseShort(name.replace(".txt", "")); + if(regionId <= 0) { + region.delete(); + } else { + BufferedReader in = new BufferedReader(new FileReader(region)); + int[] xteas = new int[4]; + + for(int index = 0; index < 4; ++index) { + xteas[index] = Integer.parseInt(in.readLine()); + } + + mapContainersXteas.put(Integer.valueOf(regionId), xteas); + in.close(); + } + } + } + } catch (IOException var111) { + var111.printStackTrace(); + } + + } +} diff --git a/src/com/alex/tools/clientCacheUpdater/ProtectCache.java b/src/com/alex/tools/clientCacheUpdater/ProtectCache.java new file mode 100644 index 0000000..d4f232e --- /dev/null +++ b/src/com/alex/tools/clientCacheUpdater/ProtectCache.java @@ -0,0 +1,99 @@ +package com.alex.tools.clientCacheUpdater; + +import com.alex.store.Index; +import com.alex.store.Store; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.Random; + +public class ProtectCache { + public static void main(String[] args) throws IOException { + boolean encryptMaps = true; + boolean encryptTables = false; + Store cache = new Store("718/cacheEncrypted/"); + if(encryptMaps) { + Store var13 = new Store("718/rscache/"); + Index var14 = cache.getIndexes()[5]; + Index rsIndex = var13.getIndexes()[5]; + + for(int regionId = 0; regionId < 25000; ++regionId) { + int regionX = (regionId >> 8) * 64; + int regionY = (regionId & 255) * 64; + int[] keys1 = null; + String name = "l" + (regionX >> 3) / 8 + "_" + (regionY >> 3) / 8; + int archiveId; + if(rsIndex.getFile(rsIndex.getArchiveId(name), 0) == null) { + archiveId = var14.getArchiveId(name); + if(archiveId != -1) { + keys1 = writeKeys(regionId); + if(!var14.encryptArchive(archiveId, null, keys1, false, false)) { + throw new RuntimeException("FAIL"); + } + } + } + + name = "ul" + (regionX >> 3) / 8 + "_" + (regionY >> 3) / 8; + if(rsIndex.getFile(rsIndex.getArchiveId(name), 0) == null) { + archiveId = var14.getArchiveId(name); + if(archiveId != -1) { + if(keys1 == null) { + keys1 = writeKeys(regionId); + } + + if(!var14.encryptArchive(archiveId, null, keys1, false, false)) { + throw new RuntimeException("FAIL"); + } + } + } + } + + var14.rewriteTable(); + } + + if(encryptTables) { + int[][] var131 = new int[cache.getIndexes().length][]; + + int var141; + for(var141 = 0; var141 < var131.length; ++var141) { + var131[var141] = generateKeys(); + if(cache.getIndexes()[var141] != null) { + System.out.println("encrypting idx table: " + var141); + cache.getIndexes()[var141].setKeys(var131[var141]); + cache.getIndexes()[var141].rewriteTable(); + } + } + + for(var141 = 0; var141 < var131.length; ++var141) { + System.out.println(Arrays.toString(var131[var141])); + } + } + + } + + public static int[] generateKeys() { + int[] keys = new int[4]; + + for(int index = 0; index < keys.length; ++index) { + keys[index] = (new Random()).nextInt(); + } + + return keys; + } + + public static int[] writeKeys(int regionId) throws IOException { + BufferedWriter writer = new BufferedWriter(new FileWriter("718/maps/unpacked/" + regionId + ".txt")); + int[] keys = generateKeys(); + + for(int index = 0; index < keys.length; ++index) { + writer.write("" + keys[index]); + writer.newLine(); + writer.flush(); + } + + System.out.println("Region: " + regionId + ", " + Arrays.toString(keys)); + return keys; + } +} diff --git a/src/com/alex/tools/clientCacheUpdater/RSXteas.java b/src/com/alex/tools/clientCacheUpdater/RSXteas.java new file mode 100644 index 0000000..50fe697 --- /dev/null +++ b/src/com/alex/tools/clientCacheUpdater/RSXteas.java @@ -0,0 +1,49 @@ +package com.alex.tools.clientCacheUpdater; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.HashMap; + +public final class RSXteas { + public static final HashMap mapContainersXteas = new HashMap(); + + public static int[] getXteas(int regionId) { + return (int[])mapContainersXteas.get(Integer.valueOf(regionId)); + } + + public static void loadUnpackedXteas(String location) { + try { + File var12 = new File(location); + File[] xteasFiles = var12.listFiles(); + File[] arr$ = xteasFiles; + int len$ = xteasFiles.length; + + for(int i$ = 0; i$ < len$; ++i$) { + File region = arr$[i$]; + String name = region.getName(); + if(!name.contains(".txt")) { + region.delete(); + } else { + short regionId = Short.parseShort(name.replace(".txt", "")); + if(regionId <= 0) { + region.delete(); + } else { + BufferedReader in = new BufferedReader(new FileReader(region)); + int[] xteas = new int[4]; + + for(int index = 0; index < 4; ++index) { + xteas[index] = Integer.parseInt(in.readLine()); + } + + mapContainersXteas.put(Integer.valueOf(regionId), xteas); + in.close(); + } + } + } + } catch (Exception var121) { + var121.printStackTrace(); + } + + } +} diff --git a/src/com/alex/tools/clientCacheUpdater/SpritesDumper.java b/src/com/alex/tools/clientCacheUpdater/SpritesDumper.java new file mode 100644 index 0000000..cfef2db --- /dev/null +++ b/src/com/alex/tools/clientCacheUpdater/SpritesDumper.java @@ -0,0 +1,117 @@ +package com.alex.tools.clientCacheUpdater; + +import com.alex.store.Index; +import com.alex.store.Store; +import com.alex.tools.clientCacheUpdater.UpdateCache; + +import javax.imageio.ImageIO; +import javax.imageio.stream.ImageOutputStream; +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.awt.image.ImageObserver; +import java.io.File; +import java.io.IOException; + +public class SpritesDumper { + public static void main2(String[] args) throws IOException { + BufferedImage background = ImageIO.read(new File("bg/matrix.jpg")); + int id = 3769; + int sx = background.getWidth() / 2; + int sy = background.getHeight() / 2; + + for(int y = 0; y < 2; ++y) { + for(int x = 0; x < 2; ++x) { + System.out.println("id " + id); + BufferedImage part = background.getSubimage(x * sx, y * sy, sx, sy); + ImageIO.write(part, "gif", new File("bg/" + id++ + ".gif")); + } + } + + } + + public static void main3(String[] args) throws IOException { + Store cache = new Store("cache667_2/", false); + UpdateCache.packLogo(cache); + System.out.println("Adding donator icon..."); + UpdateCache.packDonatorIcon(cache); + System.out.println("Adding Matrix icon..."); + UpdateCache.packMatrixIcon(cache); + } + + public static byte[] getImage(File file) throws IOException { + ImageOutputStream stream = ImageIO.createImageOutputStream(file); + byte[] data = new byte[(int)stream.length()]; + stream.read(data); + return data; + } + + public static void main(String[] args) throws IOException { + Store cache = new Store("718/rscache/"); + Index sprites = cache.getIndexes()[32]; + int[] arr$ = sprites.getTable().getValidArchiveIds(); + int len$ = arr$.length; + + for(int i$ = 0; i$ < len$; ++i$) { + int archiveId = arr$[i$]; + int[] arr$1 = sprites.getTable().getArchives()[archiveId].getValidFileIds(); + int len$1 = arr$1.length; + + for(int i$1 = 0; i$1 < len$1; ++i$1) { + int fileId = arr$1[i$1]; + byte[] data = sprites.getFile(archiveId, fileId); + Image image = Toolkit.getDefaultToolkit().createImage(data); + String name = "sprites32/" + archiveId + "_" + fileId; + BufferedImage bi = toBufferedImage(image); + if(bi == null) { + System.out.println("failed " + name); + } else { + ImageIO.write(bi, "png", new File(name + ".png")); + } + } + } + + } + + public static BufferedImage toBufferedImage(Image image) { + if(image instanceof BufferedImage) { + return (BufferedImage)image; + } else { + image = (new ImageIcon(image)).getImage(); + boolean hasAlpha = true; + BufferedImage bimage = null; + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + + byte g; + try { + g = 1; + if(hasAlpha) { + g = 2; + } + + GraphicsDevice g1 = ge.getDefaultScreenDevice(); + GraphicsConfiguration gc = g1.getDefaultConfiguration(); + if(image.getWidth(null) < 0 || image.getHeight(null) < 0) { + return null; + } + + bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), g); + } catch (HeadlessException var7) { + } + + if(bimage == null) { + g = 1; + if(hasAlpha) { + g = 2; + } + + bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), g); + } + + Graphics2D g11 = bimage.createGraphics(); + g11.drawImage(image, 0, 0, null); + g11.dispose(); + return bimage; + } + } +} diff --git a/src/com/alex/tools/clientCacheUpdater/UpdateCache.java b/src/com/alex/tools/clientCacheUpdater/UpdateCache.java new file mode 100644 index 0000000..8139bd3 --- /dev/null +++ b/src/com/alex/tools/clientCacheUpdater/UpdateCache.java @@ -0,0 +1,355 @@ +package com.alex.tools.clientCacheUpdater; + +import com.alex.loaders.images.IndexedColorImageFile; +import com.alex.loaders.items.ItemDefinitions; +import com.alex.store.Index; +import com.alex.store.Store; +import com.alex.tools.clientCacheUpdater.RSXteas; +import com.alex.tools.clientCacheUpdater.SpritesDumper; +import com.alex.utils.Utils; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public class UpdateCache { + public static byte[] getBytesFromFile(File file) throws IOException { + FileInputStream is = new FileInputStream(file); + long length = file.length(); + if(length > 2147483647L) { + } + + byte[] bytes = new byte[(int)length]; + int offset = 0; + + int numRead1; + for(boolean numRead = false; offset < bytes.length && (numRead1 = is.read(bytes, offset, bytes.length - offset)) >= 0; offset += numRead1) { + } + + if(offset < bytes.length) { + throw new IOException("Could not completely read file " + file.getName()); + } else { + is.close(); + return bytes; + } + } + + public static void main6(String[] args) throws IOException { + Store cache = new Store("cache667_2/", false); + cache.getIndexes()[6].putFile(0, 0, getBytesFromFile(new File("0"))); + } + + public static void main5(String[] args) throws IOException { + Store rscache = new Store("cache697/"); + Store cache = new Store("cache667_2/", false); + boolean result = false; + result = cache.getIndexes()[3].putArchive(320, rscache, false, false); + System.out.println("Packed skill interface: 320, " + result); + result = cache.getIndexes()[3].putArchive(679, rscache, false, false); + System.out.println("Packed skill interface: 679, " + result); + cache.getIndexes()[3].rewriteTable(); + } + + public static void main555(String[] args) throws IOException { + Store cache = new Store("cache667_2/", false); + Store originalCache = new Store("rscache/", false); + cache.addIndex(false, false, 2); + int[] arr$ = originalCache.getIndexes()[19].getTable().getValidArchiveIds(); + int len$ = arr$.length; + + for(int i$ = 0; i$ < len$; ++i$) { + int i = arr$[i$]; + System.out.println(i); + int[] arr$1 = originalCache.getIndexes()[19].getTable().getArchives()[i].getValidFileIds(); + int len$1 = arr$1.length; + + for(int i$1 = 0; i$1 < len$1; ++i$1) { + int i2 = arr$1[i$1]; + + try { + cache.getIndexes()[37].putFile(i, i2, 2, originalCache.getIndexes()[19].getFile(i, i2), null, false, false, -1, -1); + } catch (Throwable var12) { + var12.printStackTrace(); + } + } + } + + cache.getIndexes()[37].rewriteTable(); + } + + public static void main77(String[] args) throws IOException { + Store originalCache = new Store("cache667/", false); + Store cache = new Store("cache667_2/", false); + + for(int i = 1610; i < 1616; ++i) { + cache.getIndexes()[17].putFile(i >>> 8, i & 255, originalCache.getIndexes()[17].getFile(i >>> 8, i & 255)); + } + + } + + public static void packLogo(Store cache) throws IOException { + short id = 2498; + IndexedColorImageFile f = null; + + try { + f = new IndexedColorImageFile(ImageIO.read(new File("bg/logo.png"))); + } catch (IOException var81) { + var81.printStackTrace(); + } + + byte[] data = f.encodeFile(); + cache.getIndexes()[8].putFile(id, 0, data); + + int i; + for(i = 4139; i <= 4146; ++i) { + try { + cache.getIndexes()[8].putFile(i, 0, (new IndexedColorImageFile(ImageIO.read(new File("bg/" + i + ".gif")))).encodeFile()); + } catch (IOException var7) { + var7.printStackTrace(); + } + } + + for(i = 0; i < 4; ++i) { + int realid = 3769 + i; + int var8 = 3769 + i; + cache.getIndexes()[8].putFile(var8, 0, (new IndexedColorImageFile(ImageIO.read(new File("bg/" + realid + ".gif")))).encodeFile()); + var8 = 3779 + i; + cache.getIndexes()[8].putFile(var8, 0, (new IndexedColorImageFile(ImageIO.read(new File("bg/" + realid + ".gif")))).encodeFile()); + var8 = 3783 + (i >= 2?i - 2:i + 2); + cache.getIndexes()[8].putFile(var8, 0, (new IndexedColorImageFile(ImageIO.read(new File("bg/" + realid + ".gif")))).encodeFile()); + var8 = 3769 + i; + cache.getIndexes()[34].putFile(var8, 0, (new IndexedColorImageFile(ImageIO.read(new File("bg/" + realid + ".gif")))).encodeFile()); + var8 = 3779 + i; + cache.getIndexes()[34].putFile(var8, 0, (new IndexedColorImageFile(ImageIO.read(new File("bg/" + realid + ".gif")))).encodeFile()); + var8 = 3783 + (i >= 2?i - 2:i + 2); + cache.getIndexes()[34].putFile(var8, 0, (new IndexedColorImageFile(ImageIO.read(new File("bg/" + realid + ".gif")))).encodeFile()); + var8 = 3769 + i; + cache.getIndexes()[32].putFile(var8, 0, SpritesDumper.getImage(new File("bg/" + realid + ".png"))); + var8 = 3779 + i; + cache.getIndexes()[32].putFile(var8, 0, SpritesDumper.getImage(new File("bg/" + realid + ".png"))); + var8 = 3783 + (i >= 2?i - 2:i + 2); + cache.getIndexes()[32].putFile(var8, 0, SpritesDumper.getImage(new File("bg/" + realid + ".png"))); + System.out.println("added file: " + i); + } + + } + + public static void packDonatorIcon(Store cache) { + short id = 1455; + IndexedColorImageFile f = null; + + try { + f = new IndexedColorImageFile(cache, id, 0); + BufferedImage var7 = ImageIO.read(new File("1455.png")); + System.out.println("Added icon: " + f.addImage(var7) + "."); + BufferedImage icon2 = ImageIO.read(new File("1455f.png")); + System.out.println("Added icon2: " + f.addImage(icon2) + "."); + BufferedImage icon3 = ImageIO.read(new File("crown_green.gif")); + System.out.println("Added icon3: " + f.addImage(icon3) + "."); + BufferedImage icon4 = ImageIO.read(new File("1455_11.png")); + System.out.println("Added icon4: " + f.addImage(icon4) + "."); + } catch (IOException var71) { + var71.printStackTrace(); + } + + cache.getIndexes()[8].putFile(id, 0, f.encodeFile()); + } + + public static void packMatrixIcon(Store cache) { + short id = 2173; + IndexedColorImageFile f = null; + + try { + f = new IndexedColorImageFile(ImageIO.read(new File("2173.png"))); + } catch (IOException var4) { + var4.printStackTrace(); + } + + byte[] data = f.encodeFile(); + cache.getIndexes()[8].putFile(id, 0, data); + } + + public static int packCustomModel(Store cache, byte[] data) { + int archiveId = cache.getIndexes()[7].getLastArchiveId() + 1; + if(cache.getIndexes()[7].putFile(archiveId, 0, data)) { + return archiveId; + } else { + System.out.println("Failing packing model " + archiveId); + return -1; + } + } + + public static void packCustomItems(Store cache) throws IOException { + int modelID = packCustomModel(cache, getBytesFromFile(new File("donatorCape.dat"))); + System.out.println("model id " + modelID); + ItemDefinitions donatorCape = ItemDefinitions.getItemDefinition(cache, 9747); + donatorCape.setName("Donator cape"); + donatorCape.femaleEquip1 = modelID; + donatorCape.maleEquip1 = modelID; + donatorCape.modelId = modelID; + donatorCape.resetModelColors(); + short newId = 29999; + System.out.println(cache.getIndexes()[19].putFile(newId >>> 8, 255 & newId, donatorCape.encode())); + } + + public static void main(String[] args) throws IOException { + boolean updateJustMaps = false; + boolean addOldItems = true; + Store rscache = new Store("cache697/"); + Store cache = new Store("cache667_2/", false); + Store originalCache = new Store("cache667/", false); + if(addOldItems) { + cache.resetIndex(19, false, false, 2); + } + + cache.resetIndex(7, false, false, 2); + cache.getIndexes()[7].packIndex(originalCache); + int regionId; + int regionX; + int regionY; + boolean var20; + int[] xteas; + if(!updateJustMaps) { + int var19; + for(var19 = 0; var19 < cache.getIndexes().length; ++var19) { + if(var19 != 3 && var19 != 5 && var19 != 12 && var19 != 33 && var19 != 30) { + boolean var21 = cache.getIndexes()[var19].packIndex(rscache, true); + System.out.println("Packed index archives: " + var19 + ", " + var21); + } + } + + System.out.println("Adding logo..."); + packLogo(cache); + System.out.println("Adding donator icon..."); + packDonatorIcon(cache); + System.out.println("Adding Matrix icon..."); + packMatrixIcon(cache); + System.out.println("Adding Custom items..."); + packCustomItems(cache); + int var22; + int var17; + if(addOldItems) { + System.out.println("Adding back old item definitions..."); + short var24 = 30000; + System.out.println(var24); + var22 = Utils.getItemDefinitionsSize(originalCache); + + for(var17 = var24; var17 < var24 + var22; ++var17) { + regionId = var17 - var24; + cache.getIndexes()[19].putFile(var17 >>> 8, 255 & var17, 2, originalCache.getIndexes()[19].getFile(regionId >>> 8, 255 & regionId), null, false, false, -1, -1); + } + + cache.getIndexes()[19].rewriteTable(); + } + + System.out.println("Recovering Client Script Maps..."); + int[] var211 = originalCache.getIndexes()[17].getTable().getValidArchiveIds(); + var22 = var211.length; + + for(var17 = 0; var17 < var22; ++var17) { + int data = var211[var17]; + xteas = originalCache.getIndexes()[17].getTable().getArchives()[data].getValidFileIds(); + regionX = xteas.length; + + for(regionY = 0; regionY < regionX; ++regionY) { + int name = xteas[regionY]; + if(!cache.getIndexes()[17].fileExists(data, name) || cache.getIndexes()[17].getFile(data, name).length == 1) { + cache.getIndexes()[17].putFile(data, name, originalCache.getIndexes()[17].getFile(data, name)); + } + } + } + + System.out.println("Recovering Bank Client Script Maps..."); + + for(var19 = 1610; var19 < 1616; ++var19) { + cache.getIndexes()[17].putFile(var19 >>> 8, var19 & 255, originalCache.getIndexes()[17].getFile(var19 >>> 8, var19 & 255)); + } + + System.out.println("Adding new interfaces..."); + + for(var19 = cache.getIndexes()[3].getLastArchiveId() + 1; var19 <= rscache.getIndexes()[3].getLastArchiveId(); ++var19) { + if(rscache.getIndexes()[3].archiveExists(var19)) { + cache.getIndexes()[3].putArchive(var19, rscache, false, false); + } + } + + cache.getIndexes()[3].putArchive(320, rscache, false, false); + cache.getIndexes()[3].putArchive(751, rscache, false, false); + cache.getIndexes()[3].putArchive(1092, rscache, false, false); + var20 = cache.getIndexes()[3].rewriteTable(); + cache.getIndexes()[8].rewriteTable(); + System.out.println("Packed new interfaces: " + var20); + } + + Index var18 = cache.getIndexes()[5]; + Index var191 = rscache.getIndexes()[5]; + Index var201 = originalCache.getIndexes()[5]; + RSXteas.loadUnpackedXteas("old"); + System.out.println("Updating Maps."); + + for(regionId = 0; regionId < 30000; ++regionId) { + regionX = (regionId >> 8) * 64; + regionY = (regionId & 255) * 64; + String var221 = "m" + (regionX >> 3) / 8 + "_" + (regionY >> 3) / 8; + byte[] var23 = var191.getFile(var191.getArchiveId(var221)); + if(var23 == null) { + var23 = var201.getFile(var201.getArchiveId(var221)); + } + + if(var23 != null) { + var20 = addMapFile(var18, var221, var23); + System.out.println(var221 + ", " + var20); + } + + var221 = "um" + (regionX >> 3) / 8 + "_" + (regionY >> 3) / 8; + var23 = var191.getFile(var191.getArchiveId(var221)); + if(var23 == null) { + var23 = var201.getFile(var201.getArchiveId(var221)); + } + + if(var23 != null) { + var20 = addMapFile(var18, var221, var23); + System.out.println(var221 + ", " + var20); + } + + xteas = RSXteas.getXteas(regionId); + var221 = "l" + (regionX >> 3) / 8 + "_" + (regionY >> 3) / 8; + var23 = var191.getFile(var191.getArchiveId(var221), 0, xteas); + if(var23 != null) { + var20 = addMapFile(var18, var221, var23); + System.out.println(var221 + ", " + var20); + } + + var221 = "ul" + (regionX >> 3) / 8 + "_" + (regionY >> 3) / 8; + var23 = var191.getFile(var191.getArchiveId(var221), 0, xteas); + if(var23 != null) { + var20 = addMapFile(var18, var221, var23); + System.out.println(var221 + ", " + var20); + } + + var221 = "n" + (regionX >> 3) / 8 + "_" + (regionY >> 3) / 8; + var23 = var191.getFile(var191.getArchiveId(var221), 0); + if(var23 == null) { + var23 = var201.getFile(var201.getArchiveId(var221), 0); + } + + if(var23 != null) { + var20 = addMapFile(var18, var221, var23); + System.out.println(var221 + ", " + var20); + } + } + + var18.rewriteTable(); + } + + public static boolean addMapFile(Index index, String name, byte[] data) { + int archiveId = index.getArchiveId(name); + if(archiveId == -1) { + archiveId = index.getTable().getValidArchiveIds().length; + } + + return index.putFile(archiveId, 0, 2, data, null, false, false, Utils.getNameHash(name), -1); + } +} diff --git a/src/com/alex/tools/itemsDefsEditor/Application.java b/src/com/alex/tools/itemsDefsEditor/Application.java new file mode 100644 index 0000000..a9cff49 --- /dev/null +++ b/src/com/alex/tools/itemsDefsEditor/Application.java @@ -0,0 +1,199 @@ +package com.alex.tools.itemsDefsEditor; + +import com.alex.loaders.items.ItemDefinitions; +import com.alex.store.Store; +import com.alex.tools.itemsDefsEditor.GeneratedUkeys; +import com.alex.tools.itemsDefsEditor.ItemDefsEditor; +import com.alex.utils.Utils; + +import javax.swing.*; +import javax.swing.UIManager.LookAndFeelInfo; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; + +public class Application { + public static Store STORE; + private JFrame frmCacheEditorV; + private JList itemsList; + private DefaultListModel itemsListmodel; + + public static void main(String[] args) throws IOException { + STORE = new Store("cache/", false); + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Application var2 = new Application(); + var2.frmCacheEditorV.setVisible(true); + } catch (Exception var21) { + var21.printStackTrace(); + } + + } + }); + } + + public Application() { + this.initialize(); + } + + private void setLook() { + boolean found = false; + LookAndFeelInfo[] e = UIManager.getInstalledLookAndFeels(); + int len$ = e.length; + + for(int var7 = 0; var7 < len$; ++var7) { + LookAndFeelInfo info = e[var7]; + if(info.getName().equals("Nimbus")) { + try { + UIManager.setLookAndFeel(info.getClassName()); + found = true; + } catch (Exception var8) { + var8.printStackTrace(); + } + } + } + + if(!found) { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (Exception var71) { + var71.printStackTrace(); + } + } + + } + + private void initialize() { + this.setLook(); + this.frmCacheEditorV = new JFrame(); + this.frmCacheEditorV.setTitle("Cache Editor V0.1"); + this.frmCacheEditorV.setBounds(100, 100, 352, 435); + this.frmCacheEditorV.setDefaultCloseOperation(3); + JTabbedPane tabbedPane = new JTabbedPane(1); + this.frmCacheEditorV.getContentPane().add(tabbedPane, "Center"); + JPanel panel = new JPanel(); + tabbedPane.addTab("Main", null, panel, null); + panel.setLayout(null); + JButton btnGenerateUkeys = new JButton("Generate Ukeys (614- Client Builts)"); + btnGenerateUkeys.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + byte[] ukeys = Utils.getArchivePacketData(255, 255, Application.STORE.generateIndex255Archive255Outdated()); + new GeneratedUkeys(Application.this.getFrame(), ukeys); + } + }); + btnGenerateUkeys.setBounds(33, 64, 257, 28); + panel.add(btnGenerateUkeys); + JLabel lblCreatedByAlexalso = new JLabel("Created By Alex(Also named Dragonkk)"); + lblCreatedByAlexalso.setFont(new Font("Tekton Pro Ext", 0, 15)); + lblCreatedByAlexalso.setBounds(6, 290, 322, 46); + panel.add(lblCreatedByAlexalso); + JPanel panel_1 = new JPanel(); + tabbedPane.addTab("Items", null, panel_1, null); + panel_1.setLayout(null); + this.itemsListmodel = new DefaultListModel(); + this.itemsList = new JList(this.itemsListmodel); + this.itemsList.setSelectionMode(1); + this.itemsList.setLayoutOrientation(0); + this.itemsList.setVisibleRowCount(-1); + JScrollPane itemListscrollPane = new JScrollPane(this.itemsList); + itemListscrollPane.setBounds(34, 49, 155, 254); + panel_1.add(itemListscrollPane); + JButton btnEdit = new JButton("Edit"); + btnEdit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ItemDefinitions defs = (ItemDefinitions)Application.this.itemsList.getSelectedValue(); + if(defs != null) { + new ItemDefsEditor(Application.this, defs); + } + + } + }); + btnEdit.setBounds(201, 48, 90, 28); + panel_1.add(btnEdit); + JButton btnAdd = new JButton("Add"); + btnAdd.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + new ItemDefsEditor(Application.this, new ItemDefinitions(Application.STORE, Utils.getItemDefinitionsSize(Application.STORE), false)); + } + }); + btnAdd.setBounds(201, 88, 90, 28); + panel_1.add(btnAdd); + JButton btnRemove = new JButton("Remove"); + btnRemove.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ItemDefinitions defs = (ItemDefinitions)Application.this.itemsList.getSelectedValue(); + if(defs != null) { + Application.STORE.getIndexes()[19].removeFile(defs.getArchiveId(), defs.getFileId()); + Application.this.removeItemDefs(defs); + } + + } + }); + btnRemove.setBounds(201, 128, 90, 28); + panel_1.add(btnRemove); + JLabel label = new JLabel("Cached Items:"); + label.setFont(new Font("Comic Sans MS", 0, 18)); + label.setBounds(34, 18, 155, 21); + panel_1.add(label); + JButton btnDuplicate = new JButton("Clone"); + btnDuplicate.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ItemDefinitions defs = (ItemDefinitions)Application.this.itemsList.getSelectedValue(); + if(defs != null) { + defs = (ItemDefinitions)defs.clone(); + if(defs != null) { + defs.id = Utils.getItemDefinitionsSize(Application.STORE); + new ItemDefsEditor(Application.this, defs); + } + } + + } + }); + btnDuplicate.setBounds(201, 168, 90, 28); + panel_1.add(btnDuplicate); + this.addAllItems(); + } + + public void addAllItems() { + for(int id = 0; id < Utils.getItemDefinitionsSize(STORE) - 22314; ++id) { + this.addItemDefs(ItemDefinitions.getItemDefinition(STORE, id)); + } + + } + + public void addItemDefs(final ItemDefinitions defs) { + EventQueue.invokeLater(new Runnable() { + public void run() { + Application.this.itemsListmodel.addElement(defs); + } + }); + } + + public void updateItemDefs(final ItemDefinitions defs) { + EventQueue.invokeLater(new Runnable() { + public void run() { + int index = Application.this.itemsListmodel.indexOf(defs); + if(index == -1) { + Application.this.itemsListmodel.addElement(defs); + } else { + Application.this.itemsListmodel.setElementAt(defs, index); + } + + } + }); + } + + public void removeItemDefs(final ItemDefinitions defs) { + EventQueue.invokeLater(new Runnable() { + public void run() { + Application.this.itemsListmodel.removeElement(defs); + } + }); + } + + public JFrame getFrame() { + return this.frmCacheEditorV; + } +} diff --git a/src/com/alex/tools/itemsDefsEditor/GeneratedUkeys.java b/src/com/alex/tools/itemsDefsEditor/GeneratedUkeys.java new file mode 100644 index 0000000..aa237b5 --- /dev/null +++ b/src/com/alex/tools/itemsDefsEditor/GeneratedUkeys.java @@ -0,0 +1,41 @@ +package com.alex.tools.itemsDefsEditor; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Arrays; + +public class GeneratedUkeys extends JDialog { + private static final long serialVersionUID = -4163755150981048484L; + + public GeneratedUkeys(JFrame frame, byte[] ukeys) { + super(frame, "Ukeys", true); + this.setBounds(100, 100, 450, 300); + this.getContentPane().setLayout(null); + final JEditorPane editorPane = new JEditorPane(); + editorPane.setText(Arrays.toString(ukeys)); + editorPane.setBounds(6, 6, 420, 213); + this.getContentPane().add(editorPane); + JButton btnClose = new JButton("Close"); + btnClose.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + GeneratedUkeys.this.dispose(); + } + }); + btnClose.setBounds(101, 221, 90, 28); + this.getContentPane().add(btnClose); + JButton btnCopy = new JButton("Copy"); + btnCopy.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ActionEvent nev = new ActionEvent(editorPane, 1001, "copy"); + editorPane.selectAll(); + editorPane.getActionMap().get(nev.getActionCommand()).actionPerformed(nev); + } + }); + btnCopy.setBounds(6, 221, 90, 28); + this.getContentPane().add(btnCopy); + this.setDefaultCloseOperation(2); + this.setVisible(true); + } +} diff --git a/src/com/alex/tools/itemsDefsEditor/ItemDefsEditor.java b/src/com/alex/tools/itemsDefsEditor/ItemDefsEditor.java new file mode 100644 index 0000000..631f193 --- /dev/null +++ b/src/com/alex/tools/itemsDefsEditor/ItemDefsEditor.java @@ -0,0 +1,352 @@ +package com.alex.tools.itemsDefsEditor; + +import com.alex.loaders.items.ItemDefinitions; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class ItemDefsEditor extends JDialog { + private static final long serialVersionUID = 779623426244652906L; + private final JPanel contentPanel = new JPanel(); + private final ItemDefinitions defs; + private final Application application; + private final JTextField modelIDField; + private final JTextField nameField; + private final JTextField modelZoomField; + private final JTextField groundOptionsField; + private final JTextField inventoryOptionsField; + private final JTextField femaleModelId2Field; + private final JTextField maleModelId1Field; + private final JTextField maleModelId2Field; + private final JTextField maleModelId3Field; + private final JTextField femaleModelId1Field; + private final JTextField femaleModelId3Field; + private final JTextField teamIdField; + private final JTextField notedItemIdField; + private final JTextField switchNotedItemField; + private final JTextField lendedItemIdField; + private final JTextField switchLendedItemField; + private final JTextField changedModelColorsField; + private final JTextField changedTextureColorsField; + private final JCheckBox membersOnlyCheck; + private JTextField price; + + public void save() { + this.defs.setInvModelId(Integer.valueOf(this.modelIDField.getText()).intValue()); + this.defs.setName(this.nameField.getText()); + this.defs.setInvModelZoom(Integer.valueOf(this.modelZoomField.getText()).intValue()); + String[] groundOptions = this.groundOptionsField.getText().split(";"); + + for(int var9 = 0; var9 < this.defs.getGroundOptions().length; ++var9) { + this.defs.getGroundOptions()[var9] = groundOptions[var9].equals("null")?null:groundOptions[var9]; + } + + String[] var91 = this.inventoryOptionsField.getText().split(";"); + + for(int t = 0; t < this.defs.getInventoryOptions().length; ++t) { + this.defs.getInventoryOptions()[t] = var91[t].equals("null")?null:var91[t]; + } + + this.defs.maleEquip1 = Integer.valueOf(this.maleModelId1Field.getText()).intValue(); + this.defs.maleEquip2 = Integer.valueOf(this.maleModelId2Field.getText()).intValue(); + this.defs.maleEquipModelId3 = Integer.valueOf(this.maleModelId3Field.getText()).intValue(); + this.defs.femaleEquip1 = Integer.valueOf(this.femaleModelId1Field.getText()).intValue(); + this.defs.femaleEquip2 = Integer.valueOf(this.femaleModelId2Field.getText()).intValue(); + this.defs.femaleEquipModelId3 = Integer.valueOf(this.femaleModelId3Field.getText()).intValue(); + this.defs.teamId = Integer.valueOf(this.teamIdField.getText()).intValue(); + this.defs.notedItemId = Integer.valueOf(this.notedItemIdField.getText()).intValue(); + this.defs.switchNoteItemId = Integer.valueOf(this.switchNotedItemField.getText()).intValue(); + this.defs.lendedItemId = Integer.valueOf(this.lendedItemIdField.getText()).intValue(); + this.defs.switchLendItemId = Integer.valueOf(this.switchLendedItemField.getText()).intValue(); + this.defs.resetModelColors(); + int var5; + int var6; + String[] var7; + String[] editedColor; + String[] var10; + String var101; + if(!this.changedModelColorsField.getText().equals("")) { + var10 = this.changedModelColorsField.getText().split(";"); + var7 = var10; + var6 = var10.length; + + for(var5 = 0; var5 < var6; ++var5) { + var101 = var7[var5]; + editedColor = var101.split("="); + this.defs.changeModelColor(Integer.valueOf(editedColor[0]).intValue(), Integer.valueOf(editedColor[1]).intValue()); + } + } + + this.defs.resetTextureColors(); + if(!this.changedTextureColorsField.getText().equals("")) { + var10 = this.changedTextureColorsField.getText().split(";"); + var7 = var10; + var6 = var10.length; + + for(var5 = 0; var5 < var6; ++var5) { + var101 = var7[var5]; + editedColor = var101.split("="); + this.defs.changeTextureColor(Short.valueOf(editedColor[0]).shortValue(), Short.valueOf(editedColor[1]).shortValue()); + } + } + + this.defs.membersOnly = this.membersOnlyCheck.isSelected(); + this.defs.cost = Integer.valueOf(this.price.getText()).intValue(); + this.defs.equipType = Integer.valueOf(this.modelIDField.getText()).intValue(); + this.defs.equipSlot = Integer.valueOf(this.modelIDField.getText()).intValue(); + this.defs.write(Application.STORE); + this.application.updateItemDefs(this.defs); + } + + public ItemDefsEditor(Application application, ItemDefinitions defs) { + super(application.getFrame(), "Item Definitions Editor", true); + this.defs = defs; + this.application = application; + this.setBounds(100, 100, 912, 354); + this.getContentPane().setLayout(new BorderLayout()); + this.contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + this.getContentPane().add(this.contentPanel, "Center"); + this.contentPanel.setLayout(null); + JLabel lblNewLabel = new JLabel("Model ID:"); + lblNewLabel.setFont(new Font("Comic Sans MS", 0, 14)); + lblNewLabel.setBounds(6, 43, 81, 21); + this.contentPanel.add(lblNewLabel); + this.modelIDField = new JTextField(); + this.modelIDField.setBounds(139, 40, 122, 28); + this.contentPanel.add(this.modelIDField); + this.modelIDField.setColumns(10); + this.modelIDField.setText("" + defs.getInvModelId()); + JLabel label = new JLabel("Name:"); + label.setFont(new Font("Comic Sans MS", 0, 14)); + label.setBounds(6, 76, 81, 21); + this.contentPanel.add(label); + this.nameField = new JTextField(); + this.nameField.setBounds(139, 73, 122, 28); + this.contentPanel.add(this.nameField); + this.nameField.setColumns(10); + this.nameField.setText(defs.getName()); + label = new JLabel("Model Zoom:"); + label.setFont(new Font("Comic Sans MS", 0, 14)); + label.setBounds(6, 109, 95, 21); + this.contentPanel.add(label); + this.modelZoomField = new JTextField(); + this.modelZoomField.setBounds(139, 106, 122, 28); + this.contentPanel.add(this.modelZoomField); + this.modelZoomField.setColumns(10); + this.modelZoomField.setText("" + defs.getInvModelZoom()); + label = new JLabel("Ground Options:"); + label.setFont(new Font("Comic Sans MS", 0, 14)); + label.setBounds(6, 142, 108, 21); + this.contentPanel.add(label); + this.groundOptionsField = new JTextField(); + this.groundOptionsField.setBounds(139, 139, 122, 28); + this.contentPanel.add(this.groundOptionsField); + this.groundOptionsField.setColumns(10); + String var14 = ""; + String[] label_1 = defs.getGroundOptions(); + int label_2 = label_1.length; + + int label_3; + String label_4; + for(label_3 = 0; label_3 < label_2; ++label_3) { + label_4 = label_1[label_3]; + var14 = var14 + (label_4 == null?"null":label_4) + ";"; + } + + this.groundOptionsField.setText(var14); + label = new JLabel("Inventory Options:"); + label.setFont(new Font("Comic Sans MS", 0, 14)); + label.setBounds(6, 175, 139, 21); + this.contentPanel.add(label); + this.inventoryOptionsField = new JTextField(); + this.inventoryOptionsField.setBounds(139, 172, 122, 28); + this.contentPanel.add(this.inventoryOptionsField); + this.inventoryOptionsField.setColumns(10); + var14 = ""; + label_1 = defs.getInventoryOptions(); + label_2 = label_1.length; + + for(label_3 = 0; label_3 < label_2; ++label_3) { + label_4 = label_1[label_3]; + var14 = var14 + (label_4 == null?"null":label_4) + ";"; + } + + this.inventoryOptionsField.setText(var14); + JButton var16 = new JButton("Save"); + var16.setBounds(6, 265, 55, 28); + this.contentPanel.add(var16); + var16.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ItemDefsEditor.this.save(); + ItemDefsEditor.this.dispose(); + } + }); + this.getRootPane().setDefaultButton(var16); + var16 = new JButton("Cancel"); + var16.setBounds(73, 265, 67, 28); + this.contentPanel.add(var16); + var16.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ItemDefsEditor.this.dispose(); + } + }); + var16.setActionCommand("Cancel"); + label = new JLabel("Interface / Droped"); + label.setFont(new Font("Comic Sans MS", 0, 18)); + label.setBounds(6, 6, 205, 21); + this.contentPanel.add(label); + JLabel var15 = new JLabel("Wearing"); + var15.setFont(new Font("Comic Sans MS", 0, 18)); + var15.setBounds(273, 6, 205, 21); + this.contentPanel.add(var15); + JLabel var17 = new JLabel("Male Model ID 1:"); + var17.setFont(new Font("Comic Sans MS", 0, 14)); + var17.setBounds(273, 43, 131, 21); + this.contentPanel.add(var17); + JLabel var18 = new JLabel("Male Model ID 2:"); + var18.setFont(new Font("Comic Sans MS", 0, 14)); + var18.setBounds(273, 76, 131, 21); + this.contentPanel.add(var18); + JLabel var19 = new JLabel("Male Model ID 3:"); + var19.setFont(new Font("Comic Sans MS", 0, 14)); + var19.setBounds(273, 112, 131, 21); + this.contentPanel.add(var19); + JLabel label_5 = new JLabel("Female Model ID 1:"); + label_5.setFont(new Font("Comic Sans MS", 0, 14)); + label_5.setBounds(273, 145, 131, 21); + this.contentPanel.add(label_5); + JLabel label_6 = new JLabel("Female Model ID 2:"); + label_6.setFont(new Font("Comic Sans MS", 0, 14)); + label_6.setBounds(273, 175, 131, 21); + this.contentPanel.add(label_6); + JLabel label_7 = new JLabel("Female Model ID 3:"); + label_7.setFont(new Font("Comic Sans MS", 0, 14)); + label_7.setBounds(273, 208, 131, 21); + this.contentPanel.add(label_7); + this.femaleModelId2Field = new JTextField(); + this.femaleModelId2Field.setBounds(411, 172, 122, 28); + this.contentPanel.add(this.femaleModelId2Field); + this.femaleModelId2Field.setColumns(10); + this.femaleModelId2Field.setText("" + defs.femaleEquip2); + this.maleModelId1Field = new JTextField(); + this.maleModelId1Field.setBounds(411, 40, 122, 28); + this.contentPanel.add(this.maleModelId1Field); + this.maleModelId1Field.setColumns(10); + this.maleModelId1Field.setText("" + defs.maleEquip1); + this.maleModelId2Field = new JTextField(); + this.maleModelId2Field.setBounds(411, 73, 122, 28); + this.contentPanel.add(this.maleModelId2Field); + this.maleModelId2Field.setColumns(10); + this.maleModelId2Field.setText("" + defs.maleEquip2); + this.maleModelId3Field = new JTextField(); + this.maleModelId3Field.setBounds(411, 106, 122, 28); + this.contentPanel.add(this.maleModelId3Field); + this.maleModelId3Field.setColumns(10); + this.maleModelId3Field.setText("" + defs.maleEquipModelId3); + this.femaleModelId1Field = new JTextField(); + this.femaleModelId1Field.setBounds(411, 139, 122, 28); + this.contentPanel.add(this.femaleModelId1Field); + this.femaleModelId1Field.setColumns(10); + this.femaleModelId1Field.setText("" + defs.femaleEquip1); + this.femaleModelId3Field = new JTextField(); + this.femaleModelId3Field.setBounds(411, 205, 122, 28); + this.contentPanel.add(this.femaleModelId3Field); + this.femaleModelId3Field.setColumns(10); + this.femaleModelId3Field.setText("" + defs.femaleEquipModelId3); + JLabel buttonPane = new JLabel("Team ID:"); + buttonPane.setFont(new Font("Comic Sans MS", 0, 14)); + buttonPane.setBounds(273, 241, 131, 21); + this.contentPanel.add(buttonPane); + this.teamIdField = new JTextField(); + this.teamIdField.setBounds(411, 238, 122, 28); + this.contentPanel.add(this.teamIdField); + this.teamIdField.setColumns(10); + this.teamIdField.setText("" + defs.teamId); + buttonPane = new JLabel("Others"); + buttonPane.setFont(new Font("Comic Sans MS", 0, 18)); + buttonPane.setBounds(539, 6, 205, 21); + this.contentPanel.add(buttonPane); + buttonPane = new JLabel("Noted Item ID:"); + buttonPane.setFont(new Font("Comic Sans MS", 0, 14)); + buttonPane.setBounds(545, 43, 131, 21); + this.contentPanel.add(buttonPane); + buttonPane = new JLabel("Switch Noted Item Id:"); + buttonPane.setFont(new Font("Comic Sans MS", 0, 14)); + buttonPane.setBounds(545, 76, 160, 21); + this.contentPanel.add(buttonPane); + buttonPane = new JLabel("Lended Item ID:"); + buttonPane.setFont(new Font("Comic Sans MS", 0, 14)); + buttonPane.setBounds(545, 109, 160, 21); + this.contentPanel.add(buttonPane); + buttonPane = new JLabel("Switch Lended Item Id:"); + buttonPane.setFont(new Font("Comic Sans MS", 0, 14)); + buttonPane.setBounds(545, 145, 160, 21); + this.contentPanel.add(buttonPane); + this.notedItemIdField = new JTextField(); + this.notedItemIdField.setBounds(707, 39, 122, 28); + this.contentPanel.add(this.notedItemIdField); + this.notedItemIdField.setColumns(10); + this.notedItemIdField.setText("" + defs.notedItemId); + this.switchNotedItemField = new JTextField(); + this.switchNotedItemField.setBounds(707, 73, 122, 28); + this.contentPanel.add(this.switchNotedItemField); + this.switchNotedItemField.setColumns(10); + this.switchNotedItemField.setText("" + defs.switchNoteItemId); + this.lendedItemIdField = new JTextField(); + this.lendedItemIdField.setBounds(707, 106, 122, 28); + this.contentPanel.add(this.lendedItemIdField); + this.lendedItemIdField.setColumns(10); + this.lendedItemIdField.setText("" + defs.lendedItemId); + this.switchLendedItemField = new JTextField(); + this.switchLendedItemField.setBounds(707, 139, 122, 28); + this.contentPanel.add(this.switchLendedItemField); + this.switchLendedItemField.setColumns(10); + this.switchLendedItemField.setText("" + defs.switchLendItemId); + buttonPane = new JLabel("Changed Model Colors:"); + buttonPane.setFont(new Font("Comic Sans MS", 0, 14)); + buttonPane.setBounds(545, 175, 160, 21); + this.contentPanel.add(buttonPane); + this.changedModelColorsField = new JTextField(); + this.changedModelColorsField.setBounds(707, 172, 122, 28); + this.contentPanel.add(this.changedModelColorsField); + this.changedModelColorsField.setColumns(10); + String var20 = ""; + int i; + if(defs.originalModelColors != null) { + for(i = 0; i < defs.originalModelColors.length; ++i) { + var20 = var20 + defs.originalModelColors[i] + "=" + defs.modifiedModelColors[i] + ";"; + } + } + + this.changedModelColorsField.setText(var20); + buttonPane = new JLabel("Changed Texture Colors:"); + buttonPane.setFont(new Font("Comic Sans MS", 0, 14)); + buttonPane.setBounds(545, 205, 160, 21); + this.contentPanel.add(buttonPane); + this.changedTextureColorsField = new JTextField(); + this.changedTextureColorsField.setBounds(707, 205, 122, 28); + this.contentPanel.add(this.changedTextureColorsField); + this.changedTextureColorsField.setColumns(10); + var20 = ""; + if(defs.originalTextureColors != null) { + for(i = 0; i < defs.originalTextureColors.length; ++i) { + var20 = var20 + defs.originalTextureColors[i] + "=" + defs.modifiedTextureColors[i] + ";"; + } + } + + this.changedTextureColorsField.setText(var20); + this.membersOnlyCheck = new JCheckBox("Members Only"); + this.membersOnlyCheck.setFont(new Font("Comic Sans MS", 0, 14)); + this.membersOnlyCheck.setBounds(545, 243, 131, 18); + this.membersOnlyCheck.setSelected(defs.membersOnly); + this.contentPanel.add(this.membersOnlyCheck); + JPanel var21 = new JPanel(); + var21.setLayout(new FlowLayout(2)); + this.getContentPane().add(var21, "South"); + this.setDefaultCloseOperation(2); + this.setVisible(true); + } +} diff --git a/src/com/alex/util/bzip2/BZip2BlockEntry.java b/src/com/alex/util/bzip2/BZip2BlockEntry.java new file mode 100644 index 0000000..20478b1 --- /dev/null +++ b/src/com/alex/util/bzip2/BZip2BlockEntry.java @@ -0,0 +1,36 @@ +package com.alex.util.bzip2; + +public class BZip2BlockEntry { + boolean[] aBooleanArray2205 = new boolean[16]; + boolean[] aBooleanArray2213 = new boolean[256]; + byte aByte2201; + byte[] aByteArray2204 = new byte[4096]; + byte[] aByteArray2211 = new byte[256]; + byte[] aByteArray2212; + byte[] aByteArray2214 = new byte[18002]; + byte[] aByteArray2219 = new byte[18002]; + byte[] aByteArray2224; + byte[][] aByteArrayArray2229 = new byte[6][258]; + int anInt2202; + int anInt2203 = 0; + int anInt2206; + int anInt2207; + int anInt2208; + int anInt2209 = 0; + int anInt2215; + int anInt2216; + int anInt2217; + int anInt2221; + int anInt2222; + int anInt2223; + int anInt2225; + int anInt2227; + int anInt2232; + int[] anIntArray2200 = new int[6]; + int[] anIntArray2220 = new int[257]; + int[] anIntArray2226 = new int[16]; + int[] anIntArray2228 = new int[256]; + int[][] anIntArrayArray2210 = new int[6][258]; + int[][] anIntArrayArray2218 = new int[6][258]; + int[][] anIntArrayArray2230 = new int[6][258]; +} diff --git a/src/com/alex/util/bzip2/BZip2Compressor.java b/src/com/alex/util/bzip2/BZip2Compressor.java new file mode 100644 index 0000000..7d2b22b --- /dev/null +++ b/src/com/alex/util/bzip2/BZip2Compressor.java @@ -0,0 +1,20 @@ +package com.alex.util.bzip2; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +public class BZip2Compressor { + public static final byte[] compress(byte[] data) { + ByteArrayOutputStream compressedBytes = new ByteArrayOutputStream(); + + try { + CBZip2OutputStream var3 = new CBZip2OutputStream(compressedBytes); + var3.write(data); + var3.close(); + return compressedBytes.toByteArray(); + } catch (IOException var31) { + var31.printStackTrace(); + return null; + } + } +} diff --git a/src/com/alex/util/bzip2/BZip2Constants.java b/src/com/alex/util/bzip2/BZip2Constants.java new file mode 100644 index 0000000..9a26e7c --- /dev/null +++ b/src/com/alex/util/bzip2/BZip2Constants.java @@ -0,0 +1,15 @@ +package com.alex.util.bzip2; + +public interface BZip2Constants { + int baseBlockSize = 100000; + int MAX_ALPHA_SIZE = 258; + int MAX_CODE_LEN = 23; + int RUNA = 0; + int RUNB = 1; + int N_GROUPS = 6; + int G_SIZE = 50; + int N_ITERS = 4; + int MAX_SELECTORS = 18002; + int NUM_OVERSHOOT_BYTES = 20; + int[] rNums = new int[]{619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 985, 724, 205, 454, 863, 491, 741, 242, 949, 214, 733, 859, 335, 708, 621, 574, 73, 654, 730, 472, 419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 878, 465, 811, 169, 869, 675, 611, 697, 867, 561, 862, 687, 507, 283, 482, 129, 807, 591, 733, 623, 150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 170, 607, 520, 932, 727, 476, 693, 425, 174, 647, 73, 122, 335, 530, 442, 853, 695, 249, 445, 515, 909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 641, 801, 220, 162, 819, 984, 589, 513, 495, 799, 161, 604, 958, 533, 221, 400, 386, 867, 600, 782, 382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 98, 553, 163, 354, 666, 933, 424, 341, 533, 870, 227, 730, 475, 186, 263, 647, 537, 686, 600, 224, 469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 184, 943, 795, 384, 383, 461, 404, 758, 839, 887, 715, 67, 618, 276, 204, 918, 873, 777, 604, 560, 951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 652, 934, 970, 447, 318, 353, 859, 672, 112, 785, 645, 863, 803, 350, 139, 93, 354, 99, 820, 908, 609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 653, 282, 762, 623, 680, 81, 927, 626, 789, 125, 411, 521, 938, 300, 821, 78, 343, 175, 128, 250, 170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 857, 956, 358, 619, 580, 124, 737, 594, 701, 612, 669, 112, 134, 694, 363, 992, 809, 743, 168, 974, 944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 344, 805, 988, 739, 511, 655, 814, 334, 249, 515, 897, 955, 664, 981, 649, 113, 974, 459, 893, 228, 433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 686, 754, 806, 760, 493, 403, 415, 394, 687, 700, 946, 670, 656, 610, 738, 392, 760, 799, 887, 653, 978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 680, 879, 194, 572, 640, 724, 926, 56, 204, 700, 707, 151, 457, 449, 797, 195, 791, 558, 945, 679, 297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 134, 108, 571, 364, 631, 212, 174, 643, 304, 329, 343, 97, 430, 751, 497, 314, 983, 374, 822, 928, 140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 170, 514, 364, 692, 829, 82, 855, 953, 676, 246, 369, 970, 294, 750, 807, 827, 150, 790, 288, 923, 804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 896, 831, 547, 261, 524, 462, 293, 465, 502, 56, 661, 821, 976, 991, 658, 869, 905, 758, 745, 193, 768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 61, 688, 793, 644, 986, 403, 106, 366, 905, 644, 372, 567, 466, 434, 645, 210, 389, 550, 919, 135, 780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 920, 176, 193, 713, 857, 265, 203, 50, 668, 108, 645, 990, 626, 197, 510, 357, 358, 850, 858, 364, 936, 638}; +} diff --git a/src/com/alex/util/bzip2/BZip2Decompressor.java b/src/com/alex/util/bzip2/BZip2Decompressor.java new file mode 100644 index 0000000..4185657 --- /dev/null +++ b/src/com/alex/util/bzip2/BZip2Decompressor.java @@ -0,0 +1,579 @@ +package com.alex.util.bzip2; + +import com.alex.util.bzip2.BZip2BlockEntry; + +public class BZip2Decompressor { + private static int[] anIntArray257; + private static BZip2BlockEntry entryInstance = new BZip2BlockEntry(); + + public static final void decompress(byte[] decompressedData, byte[] packedData, int containerSize, int blockSize) { + BZip2BlockEntry var4 = entryInstance; + BZip2BlockEntry var5 = entryInstance; + synchronized(entryInstance) { + entryInstance.aByteArray2224 = packedData; + entryInstance.anInt2209 = blockSize; + entryInstance.aByteArray2212 = decompressedData; + entryInstance.anInt2203 = 0; + entryInstance.anInt2206 = decompressedData.length; + entryInstance.anInt2232 = 0; + entryInstance.anInt2207 = 0; + entryInstance.anInt2217 = 0; + entryInstance.anInt2216 = 0; + method1793(entryInstance); + entryInstance.aByteArray2224 = null; + entryInstance.aByteArray2212 = null; + } + } + + private static final void method1785(BZip2BlockEntry entry) { + entry.anInt2215 = 0; + + for(int i = 0; i < 256; ++i) { + if(entry.aBooleanArray2213[i]) { + entry.aByteArray2211[entry.anInt2215] = (byte)i; + ++entry.anInt2215; + } + } + + } + + private static final void method1786(int[] ai, int[] ai1, int[] ai2, byte[] abyte0, int i, int j, int k) { + int l = 0; + + int i3; + int k2; + for(i3 = i; i3 <= j; ++i3) { + for(k2 = 0; k2 < k; ++k2) { + if(abyte0[k2] == i3) { + ai2[l] = k2; + ++l; + } + } + } + + for(i3 = 0; i3 < 23; ++i3) { + ai1[i3] = 0; + } + + for(i3 = 0; i3 < k; ++i3) { + ++ai1[abyte0[i3] + 1]; + } + + for(i3 = 1; i3 < 23; ++i3) { + ai1[i3] += ai1[i3 - 1]; + } + + for(i3 = 0; i3 < 23; ++i3) { + ai[i3] = 0; + } + + i3 = 0; + + for(k2 = i; k2 <= j; ++k2) { + i3 += ai1[k2 + 1] - ai1[k2]; + ai[k2] = i3 - 1; + i3 <<= 1; + } + + for(k2 = i + 1; k2 <= j; ++k2) { + ai1[k2] = (ai[k2 - 1] + 1 << 1) - ai1[k2]; + } + + } + + private static final void method1787(BZip2BlockEntry entry) { + byte byte4 = entry.aByte2201; + int i = entry.anInt2222; + int j = entry.anInt2227; + int k = entry.anInt2221; + int[] ai = anIntArray257; + int l = entry.anInt2208; + byte[] abyte0 = entry.aByteArray2212; + int i1 = entry.anInt2203; + int j1 = entry.anInt2206; + int l1 = entry.anInt2225 + 1; + + label63: + while(true) { + if(i > 0) { + while(true) { + if(j1 == 0) { + break label63; + } + + if(i == 1) { + if(j1 == 0) { + i = 1; + break label63; + } + + abyte0[i1] = byte4; + ++i1; + --j1; + break; + } + + abyte0[i1] = byte4; + --i; + ++i1; + --j1; + } + } + + boolean flag = true; + + byte byte1; + while(flag) { + flag = false; + if(j == l1) { + i = 0; + break label63; + } + + byte4 = (byte)k; + l = ai[l]; + byte1 = (byte)(l & 255); + l >>= 8; + ++j; + if(byte1 != k) { + k = byte1; + if(j1 == 0) { + i = 1; + break label63; + } + + abyte0[i1] = byte4; + ++i1; + --j1; + flag = true; + } else if(j == l1) { + if(j1 == 0) { + i = 1; + break label63; + } + + abyte0[i1] = byte4; + ++i1; + --j1; + flag = true; + } + } + + i = 2; + l = ai[l]; + byte1 = (byte)(l & 255); + l >>= 8; + ++j; + if(j != l1) { + if(byte1 != k) { + k = byte1; + } else { + i = 3; + l = ai[l]; + byte byte2 = (byte)(l & 255); + l >>= 8; + ++j; + if(j != l1) { + if(byte2 != k) { + k = byte2; + } else { + l = ai[l]; + byte byte3 = (byte)(l & 255); + l >>= 8; + ++j; + i = (byte3 & 255) + 4; + l = ai[l]; + k = (byte)(l & 255); + l >>= 8; + ++j; + } + } + } + } + } + + entry.anInt2216 += 0; + entry.aByte2201 = byte4; + entry.anInt2222 = i; + entry.anInt2227 = j; + entry.anInt2221 = k; + anIntArray257 = ai; + entry.anInt2208 = l; + entry.aByteArray2212 = abyte0; + entry.anInt2203 = i1; + entry.anInt2206 = j1; + } + + private static final byte method1788(BZip2BlockEntry entry) { + return (byte)method1790(1, entry); + } + + private static final byte method1789(BZip2BlockEntry entry) { + return (byte)method1790(8, entry); + } + + private static final int method1790(int i, BZip2BlockEntry entry) { + while(entry.anInt2232 < i) { + entry.anInt2207 = entry.anInt2207 << 8 | entry.aByteArray2224[entry.anInt2209] & 255; + entry.anInt2232 += 8; + ++entry.anInt2209; + ++entry.anInt2217; + } + + int k = entry.anInt2207 >> entry.anInt2232 - i & (1 << i) - 1; + entry.anInt2232 -= i; + return k; + } + + public static void clearBlockEntryInstance() { + entryInstance = null; + } + + private static final void method1793(BZip2BlockEntry entry) { + int j8 = 0; + int[] ai = null; + int[] ai1 = null; + int[] ai2 = null; + entry.anInt2202 = 1; + if(anIntArray257 == null) { + anIntArray257 = new int[entry.anInt2202 * 100000]; + } + + boolean flag18 = true; + + while(true) { + while(flag18) { + byte byte0 = method1789(entry); + if(byte0 == 23) { + return; + } + + byte0 = method1789(entry); + byte0 = method1789(entry); + byte0 = method1789(entry); + byte0 = method1789(entry); + byte0 = method1789(entry); + byte0 = method1789(entry); + byte0 = method1789(entry); + byte0 = method1789(entry); + byte0 = method1789(entry); + byte0 = method1788(entry); + entry.anInt2223 = 0; + byte0 = method1789(entry); + entry.anInt2223 = entry.anInt2223 << 8 | byte0 & 255; + byte0 = method1789(entry); + entry.anInt2223 = entry.anInt2223 << 8 | byte0 & 255; + byte0 = method1789(entry); + entry.anInt2223 = entry.anInt2223 << 8 | byte0 & 255; + + int i4; + for(i4 = 0; i4 < 16; ++i4) { + byte var28 = method1788(entry); + entry.aBooleanArray2205[i4] = var28 == 1; + } + + for(i4 = 0; i4 < 256; ++i4) { + entry.aBooleanArray2213[i4] = false; + } + + int var341; + for(i4 = 0; i4 < 16; ++i4) { + if(entry.aBooleanArray2205[i4]) { + for(var341 = 0; var341 < 16; ++var341) { + byte var29 = method1788(entry); + if(var29 == 1) { + entry.aBooleanArray2213[i4 * 16 + var341] = true; + } + } + } + } + + method1785(entry); + i4 = entry.anInt2215 + 2; + var341 = method1790(3, entry); + int var351 = method1790(15, entry); + + int l4; + byte i5; + for(int abyte0 = 0; abyte0 < var351; ++abyte0) { + l4 = 0; + + while(true) { + i5 = method1788(entry); + if(i5 == 0) { + entry.aByteArray2214[abyte0] = (byte)l4; + break; + } + + ++l4; + } + } + + byte[] var30 = new byte[6]; + + byte j5; + for(j5 = 0; j5 < var341; var30[j5] = j5++) { + } + + for(l4 = 0; l4 < var351; ++l4) { + i5 = entry.aByteArray2214[l4]; + + for(j5 = var30[i5]; i5 > 0; --i5) { + var30[i5] = var30[i5 - 1]; + } + + var30[0] = j5; + entry.aByteArray2219[l4] = j5; + } + + int var32; + int var33; + for(l4 = 0; l4 < var341; ++l4) { + var32 = method1790(5, entry); + + for(var33 = 0; var33 < i4; ++var33) { + while(true) { + byte var35 = method1788(entry); + if(var35 == 0) { + entry.aByteArrayArray2229[l4][var33] = (byte)var32; + break; + } + + var35 = method1788(entry); + if(var35 == 0) { + ++var32; + } else { + --var32; + } + } + } + } + + int var36; + for(l4 = 0; l4 < var341; ++l4) { + i5 = 32; + j5 = 0; + + for(var36 = 0; var36 < i4; ++var36) { + if(entry.aByteArrayArray2229[l4][var36] > j5) { + j5 = entry.aByteArrayArray2229[l4][var36]; + } + + if(entry.aByteArrayArray2229[l4][var36] < i5) { + i5 = entry.aByteArrayArray2229[l4][var36]; + } + } + + method1786(entry.anIntArrayArray2230[l4], entry.anIntArrayArray2218[l4], entry.anIntArrayArray2210[l4], entry.aByteArrayArray2229[l4], i5, j5, i4); + entry.anIntArray2200[l4] = i5; + } + + l4 = entry.anInt2215 + 1; + var32 = -1; + byte var34 = 0; + + for(var36 = 0; var36 <= 255; ++var36) { + entry.anIntArray2228[var36] = 0; + } + + var36 = 4095; + + int l5; + int l6; + for(l5 = 15; l5 >= 0; --l5) { + for(l6 = 15; l6 >= 0; --l6) { + entry.aByteArray2204[var36] = (byte)(l5 * 16 + l6); + --var36; + } + + entry.anIntArray2226[l5] = var36 + 1; + } + + l5 = 0; + if(var34 == 0) { + ++var32; + var34 = 50; + byte k7 = entry.aByteArray2219[var32]; + j8 = entry.anIntArray2200[k7]; + ai = entry.anIntArrayArray2230[k7]; + ai2 = entry.anIntArrayArray2210[k7]; + ai1 = entry.anIntArrayArray2218[k7]; + } + + var33 = var34 - 1; + l6 = j8; + + byte byte9; + int var37; + for(var37 = method1790(j8, entry); var37 > ai[l6]; var37 = var37 << 1 | byte9) { + ++l6; + byte9 = method1788(entry); + } + + int l2 = ai2[var37 - ai1[l6]]; + + while(true) { + while(l2 != l4) { + int var39; + byte j7; + int i8; + byte byte11; + int var38; + if(l2 != 0 && l2 != 1) { + var39 = l2 - 1; + byte var391; + if(var39 < 16) { + var38 = entry.anIntArray2226[0]; + + for(var391 = entry.aByteArray2204[var38 + var39]; var39 > 3; var39 -= 4) { + i8 = var38 + var39; + entry.aByteArray2204[i8] = entry.aByteArray2204[i8 - 1]; + entry.aByteArray2204[i8 - 1] = entry.aByteArray2204[i8 - 2]; + entry.aByteArray2204[i8 - 2] = entry.aByteArray2204[i8 - 3]; + entry.aByteArray2204[i8 - 3] = entry.aByteArray2204[i8 - 4]; + } + + while(var39 > 0) { + entry.aByteArray2204[var38 + var39] = entry.aByteArray2204[var38 + var39 - 1]; + --var39; + } + + entry.aByteArray2204[var38] = var391; + } else { + var38 = var39 / 16; + i8 = var39 % 16; + int var40 = entry.anIntArray2226[var38] + i8; + + for(var391 = entry.aByteArray2204[var40]; var40 > entry.anIntArray2226[var38]; --var40) { + entry.aByteArray2204[var40] = entry.aByteArray2204[var40 - 1]; + } + + ++entry.anIntArray2226[var38]; + + while(var38 > 0) { + --entry.anIntArray2226[var38]; + entry.aByteArray2204[entry.anIntArray2226[var38]] = entry.aByteArray2204[entry.anIntArray2226[var38 - 1] + 16 - 1]; + --var38; + } + + --entry.anIntArray2226[0]; + entry.aByteArray2204[entry.anIntArray2226[0]] = var391; + if(entry.anIntArray2226[0] == 0) { + int l9 = 4095; + + for(int j9 = 15; j9 >= 0; --j9) { + for(int k9 = 15; k9 >= 0; --k9) { + entry.aByteArray2204[l9] = entry.aByteArray2204[entry.anIntArray2226[j9] + k9]; + --l9; + } + + entry.anIntArray2226[j9] = l9 + 1; + } + } + } + + ++entry.anIntArray2228[entry.aByteArray2211[var391 & 255] & 255]; + anIntArray257[l5] = entry.aByteArray2211[var391 & 255] & 255; + ++l5; + if(var33 == 0) { + ++var32; + var33 = 50; + j7 = entry.aByteArray2219[var32]; + j8 = entry.anIntArray2200[j7]; + ai = entry.anIntArrayArray2230[j7]; + ai2 = entry.anIntArrayArray2210[j7]; + ai1 = entry.anIntArrayArray2218[j7]; + } + + --var33; + var38 = j8; + + for(i8 = method1790(j8, entry); i8 > ai[var38]; i8 = i8 << 1 | byte11) { + ++var38; + byte11 = method1788(entry); + } + + l2 = ai2[i8 - ai1[var38]]; + } else { + var39 = -1; + int byte6 = 1; + + do { + if(l2 == 0) { + var39 += byte6; + } else if(l2 == 1) { + var39 += 2 * byte6; + } + + byte6 *= 2; + if(var33 == 0) { + ++var32; + var33 = 50; + j7 = entry.aByteArray2219[var32]; + j8 = entry.anIntArray2200[j7]; + ai = entry.anIntArrayArray2230[j7]; + ai2 = entry.anIntArrayArray2210[j7]; + ai1 = entry.anIntArrayArray2218[j7]; + } + + --var33; + var38 = j8; + + for(i8 = method1790(j8, entry); i8 > ai[var38]; i8 = i8 << 1 | byte11) { + ++var38; + byte11 = method1788(entry); + } + + l2 = ai2[i8 - ai1[var38]]; + } while(l2 == 0 || l2 == 1); + + ++var39; + j7 = entry.aByteArray2211[entry.aByteArray2204[entry.anIntArray2226[0]] & 255]; + + for(entry.anIntArray2228[j7 & 255] += var39; var39 > 0; --var39) { + anIntArray257[l5] = j7 & 255; + ++l5; + } + } + } + + entry.anInt2222 = 0; + entry.aByte2201 = 0; + entry.anIntArray2220[0] = 0; + + for(l2 = 1; l2 <= 256; ++l2) { + entry.anIntArray2220[l2] = entry.anIntArray2228[l2 - 1]; + } + + for(l2 = 1; l2 <= 256; ++l2) { + entry.anIntArray2220[l2] += entry.anIntArray2220[l2 - 1]; + } + + for(l2 = 0; l2 < l5; ++l2) { + byte var381 = (byte)(anIntArray257[l2] & 255); + anIntArray257[entry.anIntArray2220[var381 & 255]] |= l2 << 8; + ++entry.anIntArray2220[var381 & 255]; + } + + entry.anInt2208 = anIntArray257[entry.anInt2223] >> 8; + entry.anInt2227 = 0; + entry.anInt2208 = anIntArray257[entry.anInt2208]; + entry.anInt2221 = (byte)(entry.anInt2208 & 255); + entry.anInt2208 >>= 8; + ++entry.anInt2227; + entry.anInt2225 = l5; + method1787(entry); + if(entry.anInt2227 == entry.anInt2225 + 1 && entry.anInt2222 == 0) { + flag18 = true; + break; + } + + flag18 = false; + break; + } + } + + return; + } + } +} diff --git a/src/com/alex/util/bzip2/CBZip2OutputStream.java b/src/com/alex/util/bzip2/CBZip2OutputStream.java new file mode 100644 index 0000000..e3b48a3 --- /dev/null +++ b/src/com/alex/util/bzip2/CBZip2OutputStream.java @@ -0,0 +1,1458 @@ +package com.alex.util.bzip2; + +import java.io.IOException; +import java.io.OutputStream; + +public class CBZip2OutputStream extends OutputStream implements BZip2Constants { + protected static final int SETMASK = 2097152; + protected static final int CLEARMASK = -2097153; + protected static final int GREATER_ICOST = 15; + protected static final int LESSER_ICOST = 0; + protected static final int SMALL_THRESH = 20; + protected static final int DEPTH_THRESH = 10; + protected static final int QSORT_STACK_SIZE = 1000; + int last; + int origPtr; + int blockSize100k; + boolean blockRandomised; + int bytesOut; + int bsBuff; + int bsLive; + CRC mCrc; + private final boolean[] inUse; + private int nInUse; + private final char[] seqToUnseq; + private final char[] unseqToSeq; + private final char[] selector; + private final char[] selectorMtf; + private char[] block; + private int[] quadrant; + private int[] zptr; + private short[] szptr; + private int[] ftab; + private int nMTF; + private final int[] mtfFreq; + private final int workFactor; + private int workDone; + private int workLimit; + private boolean firstAttempt; + private int nBlocksRandomised; + private int currentChar; + private int runLength; + boolean closed; + private int blockCRC; + private int combinedCRC; + private int allowableBlockSize; + private OutputStream bsStream; + private final int[] incs; + + private static void panic() { + System.out.println("panic"); + } + + private void makeMaps() { + this.nInUse = 0; + + for(int i = 0; i < 256; ++i) { + if(this.inUse[i]) { + this.seqToUnseq[this.nInUse] = (char)i; + this.unseqToSeq[i] = (char)this.nInUse; + ++this.nInUse; + } + } + + } + + protected static void hbMakeCodeLengths(char[] len, int[] freq, int alphaSize, int maxLen) { + int[] heap = new int[260]; + int[] weight = new int[516]; + int[] parent = new int[516]; + + int i; + for(i = 0; i < alphaSize; ++i) { + weight[i + 1] = (freq[i] == 0?1:freq[i]) << 8; + } + + while(true) { + int nNodes = alphaSize; + int nHeap = 0; + heap[0] = 0; + weight[0] = 0; + parent[0] = -2; + + int zz; + int tmp; + for(i = 1; i <= alphaSize; ++i) { + parent[i] = -1; + ++nHeap; + heap[nHeap] = i; + zz = nHeap; + + for(tmp = heap[nHeap]; weight[tmp] < weight[heap[zz >> 1]]; zz >>= 1) { + heap[zz] = heap[zz >> 1]; + } + + heap[zz] = tmp; + } + + if(nHeap >= 260) { + panic(); + } + + while(nHeap > 1) { + int tooLong = heap[1]; + heap[1] = heap[nHeap]; + --nHeap; + boolean j = false; + boolean k = false; + boolean tmp1 = false; + zz = 1; + int var20 = heap[zz]; + + while(true) { + tmp = zz << 1; + if(tmp > nHeap) { + break; + } + + if(tmp < nHeap && weight[heap[tmp + 1]] < weight[heap[tmp]]) { + ++tmp; + } + + if(weight[var20] < weight[heap[tmp]]) { + break; + } + + heap[zz] = heap[tmp]; + zz = tmp; + } + + heap[zz] = var20; + int n2 = heap[1]; + heap[1] = heap[nHeap]; + --nHeap; + j = false; + k = false; + tmp1 = false; + zz = 1; + var20 = heap[zz]; + + while(true) { + tmp = zz << 1; + if(tmp > nHeap) { + break; + } + + if(tmp < nHeap && weight[heap[tmp + 1]] < weight[heap[tmp]]) { + ++tmp; + } + + if(weight[var20] < weight[heap[tmp]]) { + break; + } + + heap[zz] = heap[tmp]; + zz = tmp; + } + + heap[zz] = var20; + ++nNodes; + parent[tooLong] = parent[n2] = nNodes; + weight[nNodes] = (weight[tooLong] & -256) + (weight[n2] & -256) | 1 + ((weight[tooLong] & 255) > (weight[n2] & 255)?weight[tooLong] & 255:weight[n2] & 255); + parent[nNodes] = -1; + ++nHeap; + heap[nHeap] = nNodes; + j = false; + k = false; + zz = nHeap; + + for(tmp = heap[nHeap]; weight[tmp] < weight[heap[zz >> 1]]; zz >>= 1) { + heap[zz] = heap[zz >> 1]; + } + + heap[zz] = tmp; + } + + if(nNodes >= 516) { + panic(); + } + + boolean var18 = false; + + int var19; + for(i = 1; i <= alphaSize; ++i) { + var19 = 0; + + for(int var201 = i; parent[var201] >= 0; ++var19) { + var201 = parent[var201]; + } + + len[i - 1] = (char)var19; + if(var19 > maxLen) { + var18 = true; + } + } + + if(!var18) { + return; + } + + for(i = 1; i < alphaSize; ++i) { + var19 = weight[i] >> 8; + var19 = 1 + var19 / 2; + weight[i] = var19 << 8; + } + } + } + + public CBZip2OutputStream(OutputStream inStream) throws IOException { + this(inStream, 9); + } + + public CBZip2OutputStream(OutputStream inStream, int inBlockSize) throws IOException { + this.mCrc = new CRC(); + this.inUse = new boolean[256]; + this.seqToUnseq = new char[256]; + this.unseqToSeq = new char[256]; + this.selector = new char[18002]; + this.selectorMtf = new char[18002]; + this.mtfFreq = new int[258]; + this.currentChar = -1; + this.runLength = 0; + this.closed = false; + this.incs = new int[]{1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 265720, 797161, 2391484}; + this.block = null; + this.quadrant = null; + this.zptr = null; + this.ftab = null; + this.bsSetStream(inStream); + this.workFactor = 50; + if(inBlockSize > 9) { + inBlockSize = 9; + } + + if(inBlockSize < 1) { + inBlockSize = 1; + } + + this.blockSize100k = inBlockSize; + this.allocateCompressStructures(); + this.initialize(); + this.initBlock(); + } + + public void write(int bv) throws IOException { + int b = (256 + bv) % 256; + if(this.currentChar != -1) { + if(this.currentChar == b) { + ++this.runLength; + if(this.runLength > 254) { + this.writeRun(); + this.currentChar = -1; + this.runLength = 0; + } + } else { + this.writeRun(); + this.runLength = 1; + this.currentChar = b; + } + } else { + this.currentChar = b; + ++this.runLength; + } + + } + + private void writeRun() throws IOException { + if(this.last < this.allowableBlockSize) { + this.inUse[this.currentChar] = true; + + for(int i = 0; i < this.runLength; ++i) { + this.mCrc.updateCRC((char)this.currentChar); + } + + switch(this.runLength) { + case 1: + ++this.last; + this.block[this.last + 1] = (char)this.currentChar; + break; + case 2: + ++this.last; + this.block[this.last + 1] = (char)this.currentChar; + ++this.last; + this.block[this.last + 1] = (char)this.currentChar; + break; + case 3: + ++this.last; + this.block[this.last + 1] = (char)this.currentChar; + ++this.last; + this.block[this.last + 1] = (char)this.currentChar; + ++this.last; + this.block[this.last + 1] = (char)this.currentChar; + break; + default: + this.inUse[this.runLength - 4] = true; + ++this.last; + this.block[this.last + 1] = (char)this.currentChar; + ++this.last; + this.block[this.last + 1] = (char)this.currentChar; + ++this.last; + this.block[this.last + 1] = (char)this.currentChar; + ++this.last; + this.block[this.last + 1] = (char)this.currentChar; + ++this.last; + this.block[this.last + 1] = (char)(this.runLength - 4); + } + } else { + this.endBlock(); + this.initBlock(); + this.writeRun(); + } + + } + + protected void finalize() throws Throwable { + this.close(); + super.finalize(); + } + + public void close() throws IOException { + if(!this.closed) { + if(this.runLength > 0) { + this.writeRun(); + } + + this.currentChar = -1; + this.endBlock(); + this.endCompression(); + this.closed = true; + super.close(); + this.bsStream.close(); + } + + } + + public void flush() throws IOException { + super.flush(); + this.bsStream.flush(); + } + + private void initialize() throws IOException { + this.bytesOut = 0; + this.setnBlocksRandomised(0); + this.bsPutUChar(104); + this.bsPutUChar(48 + this.blockSize100k); + this.combinedCRC = 0; + } + + private void initBlock() { + this.mCrc.initialiseCRC(); + this.last = -1; + + for(int i = 0; i < 256; ++i) { + this.inUse[i] = false; + } + + this.allowableBlockSize = 100000 * this.blockSize100k - 20; + } + + private void endBlock() throws IOException { + this.blockCRC = this.mCrc.getFinalCRC(); + this.combinedCRC = this.combinedCRC << 1 | this.combinedCRC >>> 31; + this.combinedCRC ^= this.blockCRC; + this.doReversibleTransformation(); + this.bsPutUChar(49); + this.bsPutUChar(65); + this.bsPutUChar(89); + this.bsPutUChar(38); + this.bsPutUChar(83); + this.bsPutUChar(89); + this.bsPutint(this.blockCRC); + if(this.blockRandomised) { + this.bsW(1, 1); + this.setnBlocksRandomised(this.getnBlocksRandomised() + 1); + } else { + this.bsW(1, 0); + } + + this.moveToFrontCodeAndSend(); + } + + private void endCompression() throws IOException { + this.bsPutUChar(23); + this.bsPutUChar(114); + this.bsPutUChar(69); + this.bsPutUChar(56); + this.bsPutUChar(80); + this.bsPutUChar(144); + this.bsPutint(this.combinedCRC); + this.bsFinishedWithStream(); + } + + private void hbAssignCodes(int[] code, char[] length, int minLen, int maxLen, int alphaSize) { + int vec = 0; + + for(int n = minLen; n <= maxLen; ++n) { + for(int i = 0; i < alphaSize; ++i) { + if(length[i] == n) { + code[i] = vec++; + } + } + + vec <<= 1; + } + + } + + private void bsSetStream(OutputStream f) { + this.bsStream = f; + this.bsLive = 0; + this.bsBuff = 0; + this.bytesOut = 0; + } + + private void bsFinishedWithStream() throws IOException { + while(this.bsLive > 0) { + int ch = this.bsBuff >> 24; + + try { + this.bsStream.write(ch); + } catch (IOException var3) { + throw var3; + } + + this.bsBuff <<= 8; + this.bsLive -= 8; + ++this.bytesOut; + } + + } + + private void bsW(int n, int v) throws IOException { + while(this.bsLive >= 8) { + int ch = this.bsBuff >> 24; + + try { + this.bsStream.write(ch); + } catch (IOException var5) { + throw var5; + } + + this.bsBuff <<= 8; + this.bsLive -= 8; + ++this.bytesOut; + } + + this.bsBuff |= v << 32 - this.bsLive - n; + this.bsLive += n; + } + + private void bsPutUChar(int c) throws IOException { + this.bsW(8, c); + } + + private void bsPutint(int u) throws IOException { + this.bsW(8, u >> 24 & 255); + this.bsW(8, u >> 16 & 255); + this.bsW(8, u >> 8 & 255); + this.bsW(8, u & 255); + } + + private void bsPutIntVS(int numBits, int c) throws IOException { + this.bsW(numBits, c); + } + + private void sendMTFValues() throws IOException { + char[][] len = new char[6][258]; + int nSelectors = 0; + int alphaSize = this.nInUse + 2; + + int v; + int t; + for(t = 0; t < 6; ++t) { + for(v = 0; v < alphaSize; ++v) { + len[t][v] = 15; + } + } + + if(this.nMTF <= 0) { + panic(); + } + + byte nGroups; + if(this.nMTF < 200) { + nGroups = 2; + } else if(this.nMTF < 600) { + nGroups = 3; + } else if(this.nMTF < 1200) { + nGroups = 4; + } else if(this.nMTF < 2400) { + nGroups = 5; + } else { + nGroups = 6; + } + + int rfreq = nGroups; + int fave = this.nMTF; + + int gs; + int ge; + int code; + for(gs = 0; rfreq > 0; fave -= code) { + int var29 = fave / rfreq; + ge = gs - 1; + + for(code = 0; code < var29 && ge < alphaSize - 1; code += this.mtfFreq[ge]) { + ++ge; + } + + if(ge > gs && rfreq != nGroups && rfreq != 1 && (nGroups - rfreq) % 2 == 1) { + code -= this.mtfFreq[ge]; + --ge; + } + + for(v = 0; v < alphaSize; ++v) { + if(v >= gs && v <= ge) { + len[rfreq - 1][v] = 0; + } else { + len[rfreq - 1][v] = 15; + } + } + + --rfreq; + gs = ge + 1; + } + + int[][] var25 = new int[6][258]; + int[] var30 = new int[6]; + short[] var32 = new short[6]; + + int i; + int var291; + for(int var31 = 0; var31 < 4; ++var31) { + for(t = 0; t < nGroups; ++t) { + var30[t] = 0; + } + + for(t = 0; t < nGroups; ++t) { + for(v = 0; v < alphaSize; ++v) { + var25[t][v] = 0; + } + } + + nSelectors = 0; + int var33 = 0; + + for(gs = 0; gs < this.nMTF; gs = ge + 1) { + ge = gs + 50 - 1; + if(ge >= this.nMTF) { + ge = this.nMTF - 1; + } + + for(t = 0; t < nGroups; ++t) { + var32[t] = 0; + } + + short var37; + if(nGroups == 6) { + short j = 0; + short var39 = 0; + short var36 = 0; + short nBytes = 0; + short selCtr = 0; + var37 = 0; + + for(i = gs; i <= ge; ++i) { + short icv = this.szptr[i]; + var37 = (short)(var37 + len[0][icv]); + selCtr = (short)(selCtr + len[1][icv]); + nBytes = (short)(nBytes + len[2][icv]); + var36 = (short)(var36 + len[3][icv]); + var39 = (short)(var39 + len[4][icv]); + j = (short)(j + len[5][icv]); + } + + var32[0] = var37; + var32[1] = selCtr; + var32[2] = nBytes; + var32[3] = var36; + var32[4] = var39; + var32[5] = j; + } else { + for(i = gs; i <= ge; ++i) { + var37 = this.szptr[i]; + + for(t = 0; t < nGroups; ++t) { + var32[t] = (short)(var32[t] + len[t][var37]); + } + } + } + + var291 = 999999999; + int var301 = -1; + + for(t = 0; t < nGroups; ++t) { + if(var32[t] < var291) { + var291 = var32[t]; + var301 = t; + } + } + + var33 += var291; + ++var30[var301]; + this.selector[nSelectors] = (char)var301; + ++nSelectors; + + for(i = gs; i <= ge; ++i) { + ++var25[var301][this.szptr[i]]; + } + } + + for(t = 0; t < nGroups; ++t) { + hbMakeCodeLengths(len[t], var25[t], alphaSize, 20); + } + } + + var25 = null; + Object var26 = null; + Object var27 = null; + if(nGroups >= 8) { + panic(); + } + + if(nSelectors >= 32768 || nSelectors > 18002) { + panic(); + } + + char[] var28 = new char[6]; + + for(i = 0; i < nGroups; ++i) { + var28[i] = (char)i; + } + + char var331; + char var34; + for(i = 0; i < nSelectors; ++i) { + char var311 = this.selector[i]; + var291 = 0; + + for(var34 = var28[var291]; var311 != var34; var28[var291] = var331) { + ++var291; + var331 = var34; + var34 = var28[var291]; + } + + var28[0] = var34; + this.selectorMtf[i] = (char)var291; + } + + int[][] var321 = new int[6][258]; + + for(t = 0; t < nGroups; ++t) { + var331 = 32; + var34 = 0; + + for(i = 0; i < alphaSize; ++i) { + if(len[t][i] > var34) { + var34 = len[t][i]; + } + + if(len[t][i] < var331) { + var331 = len[t][i]; + } + } + + if(var34 > 20) { + panic(); + } + + if(var331 < 1) { + panic(); + } + + this.hbAssignCodes(var321[t], len[t], var331, var34, alphaSize); + } + + boolean[] var35 = new boolean[16]; + + for(i = 0; i < 16; ++i) { + var35[i] = false; + + for(var291 = 0; var291 < 16; ++var291) { + if(this.inUse[i * 16 + var291]) { + var35[i] = true; + } + } + } + + int var371 = this.bytesOut; + + for(i = 0; i < 16; ++i) { + if(var35[i]) { + this.bsW(1, 1); + } else { + this.bsW(1, 0); + } + } + + for(i = 0; i < 16; ++i) { + if(var35[i]) { + for(var291 = 0; var291 < 16; ++var291) { + if(this.inUse[i * 16 + var291]) { + this.bsW(1, 1); + } else { + this.bsW(1, 0); + } + } + } + } + + var371 = this.bytesOut; + this.bsW(3, nGroups); + this.bsW(15, nSelectors); + + for(i = 0; i < nSelectors; ++i) { + for(var291 = 0; var291 < this.selectorMtf[i]; ++var291) { + this.bsW(1, 1); + } + + this.bsW(1, 0); + } + + var371 = this.bytesOut; + + int var361; + for(t = 0; t < nGroups; ++t) { + var361 = len[t][0]; + this.bsW(5, var361); + + for(i = 0; i < alphaSize; ++i) { + while(var361 < len[t][i]) { + this.bsW(2, 2); + ++var361; + } + + while(var361 > len[t][i]) { + this.bsW(2, 3); + --var361; + } + + this.bsW(1, 0); + } + } + + var371 = this.bytesOut; + var361 = 0; + + for(gs = 0; gs < this.nMTF; ++var361) { + ge = gs + 50 - 1; + if(ge >= this.nMTF) { + ge = this.nMTF - 1; + } + + for(i = gs; i <= ge; ++i) { + this.bsW(len[this.selector[var361]][this.szptr[i]], var321[this.selector[var361]][this.szptr[i]]); + } + + gs = ge + 1; + } + + if(var361 != nSelectors) { + panic(); + } + + } + + private void moveToFrontCodeAndSend() throws IOException { + this.bsPutIntVS(24, this.origPtr); + this.generateMTFValues(); + this.sendMTFValues(); + } + + private void simpleSort(int lo, int hi, int d) { + int bigN = hi - lo + 1; + if(bigN >= 2) { + int hp; + for(hp = 0; this.incs[hp] < bigN; ++hp) { + } + + --hp; + + for(; hp >= 0; --hp) { + int h = this.incs[hp]; + int i = lo + h; + + while(i <= hi) { + int v = this.zptr[i]; + int j = i; + + while(this.fullGtU(this.zptr[j - h] + d, v + d)) { + this.zptr[j] = this.zptr[j - h]; + j -= h; + if(j <= lo + h - 1) { + break; + } + } + + this.zptr[j] = v; + ++i; + if(i > hi) { + break; + } + + v = this.zptr[i]; + j = i; + + while(this.fullGtU(this.zptr[j - h] + d, v + d)) { + this.zptr[j] = this.zptr[j - h]; + j -= h; + if(j <= lo + h - 1) { + break; + } + } + + this.zptr[j] = v; + ++i; + if(i > hi) { + break; + } + + v = this.zptr[i]; + j = i; + + while(this.fullGtU(this.zptr[j - h] + d, v + d)) { + this.zptr[j] = this.zptr[j - h]; + j -= h; + if(j <= lo + h - 1) { + break; + } + } + + this.zptr[j] = v; + ++i; + if(this.workDone > this.workLimit && this.firstAttempt) { + return; + } + } + } + } + + } + + private void vswap(int p1, int p2, int n) { + for(boolean temp = false; n > 0; --n) { + int var5 = this.zptr[p1]; + this.zptr[p1] = this.zptr[p2]; + this.zptr[p2] = var5; + ++p1; + ++p2; + } + + } + + private char med3(char a, char b, char c) { + if(a > b) { + char t = a; + a = b; + b = t; + } + + if(b > c) { + b = c; + } + + if(a > b) { + b = a; + } + + return b; + } + + private void qSort3(int loSt, int hiSt, int dSt) { + CBZip2OutputStream.StackElem[] stack = new CBZip2OutputStream.StackElem[1000]; + + int temp; + for(temp = 0; temp < 1000; ++temp) { + stack[temp] = new CBZip2OutputStream.StackElem((CBZip2OutputStream.StackElem)null); + } + + byte sp = 0; + stack[sp].ll = loSt; + stack[sp].hh = hiSt; + stack[sp].dd = dSt; + int var17 = sp + 1; + + while(true) { + label55: + while(var17 > 0) { + if(var17 >= 1000) { + panic(); + } + + --var17; + int lo = stack[var17].ll; + int hi = stack[var17].hh; + int d = stack[var17].dd; + if(hi - lo >= 20 && d <= 10) { + char med = this.med3(this.block[this.zptr[lo] + d + 1], this.block[this.zptr[hi] + d + 1], this.block[this.zptr[lo + hi >> 1] + d + 1]); + int ltLo = lo; + int unLo = lo; + int gtHi = hi; + int unHi = hi; + + while(true) { + while(true) { + int n; + boolean var18; + if(unLo <= unHi) { + n = this.block[this.zptr[unLo] + d + 1] - med; + if(n == 0) { + var18 = false; + temp = this.zptr[unLo]; + this.zptr[unLo] = this.zptr[ltLo]; + this.zptr[ltLo] = temp; + ++ltLo; + ++unLo; + continue; + } + + if(n <= 0) { + ++unLo; + continue; + } + } + + while(unLo <= unHi) { + n = this.block[this.zptr[unHi] + d + 1] - med; + if(n == 0) { + var18 = false; + temp = this.zptr[unHi]; + this.zptr[unHi] = this.zptr[gtHi]; + this.zptr[gtHi] = temp; + --gtHi; + --unHi; + } else { + if(n < 0) { + break; + } + + --unHi; + } + } + + if(unLo > unHi) { + if(gtHi < ltLo) { + stack[var17].ll = lo; + stack[var17].hh = hi; + stack[var17].dd = d + 1; + ++var17; + } else { + n = ltLo - lo < unLo - ltLo?ltLo - lo:unLo - ltLo; + this.vswap(lo, unLo - n, n); + int m = hi - gtHi < gtHi - unHi?hi - gtHi:gtHi - unHi; + this.vswap(unLo, hi - m + 1, m); + n = lo + unLo - ltLo - 1; + m = hi - (gtHi - unHi) + 1; + stack[var17].ll = lo; + stack[var17].hh = n; + stack[var17].dd = d; + ++var17; + stack[var17].ll = n + 1; + stack[var17].hh = m - 1; + stack[var17].dd = d + 1; + ++var17; + stack[var17].ll = m; + stack[var17].hh = hi; + stack[var17].dd = d; + ++var17; + } + continue label55; + } + + var18 = false; + temp = this.zptr[unLo]; + this.zptr[unLo] = this.zptr[unHi]; + this.zptr[unHi] = temp; + ++unLo; + --unHi; + } + } + } else { + this.simpleSort(lo, hi, d); + if(this.workDone > this.workLimit && this.firstAttempt) { + return; + } + } + } + + return; + } + } + + private void mainSort() { + int[] runningOrder = new int[256]; + int[] copy = new int[256]; + boolean[] bigDone = new boolean[256]; + + int i; + for(i = 0; i < 20; ++i) { + this.block[this.last + i + 2] = this.block[i % (this.last + 1) + 1]; + } + + for(i = 0; i <= this.last + 20; ++i) { + this.quadrant[i] = 0; + } + + this.block[0] = this.block[this.last + 1]; + if(this.last < 4000) { + for(i = 0; i <= this.last; this.zptr[i] = i++) { + } + + this.firstAttempt = false; + this.workDone = this.workLimit = 0; + this.simpleSort(0, this.last, 0); + } else { + int numQSorted = 0; + + for(i = 0; i <= 255; ++i) { + bigDone[i] = false; + } + + for(i = 0; i <= 65536; ++i) { + this.ftab[i] = 0; + } + + char c1 = this.block[0]; + + char c2; + for(i = 0; i <= this.last; ++i) { + c2 = this.block[i + 1]; + ++this.ftab[(c1 << 8) + c2]; + c1 = c2; + } + + for(i = 1; i <= 65536; ++i) { + this.ftab[i] += this.ftab[i - 1]; + } + + c1 = this.block[1]; + + int j; + for(i = 0; i < this.last; this.zptr[this.ftab[j]] = i++) { + c2 = this.block[i + 2]; + j = (c1 << 8) + c2; + c1 = c2; + --this.ftab[j]; + } + + j = (this.block[this.last + 1] << 8) + this.block[1]; + --this.ftab[j]; + this.zptr[this.ftab[j]] = this.last; + + for(i = 0; i <= 255; runningOrder[i] = i++) { + } + + int bbSize = 1; + + do { + bbSize = 3 * bbSize + 1; + } while(bbSize <= 256); + + int bbStart; + do { + bbSize /= 3; + + for(i = bbSize; i <= 255; ++i) { + bbStart = runningOrder[i]; + j = i; + + while(this.ftab[runningOrder[j - bbSize] + 1 << 8] - this.ftab[runningOrder[j - bbSize] << 8] > this.ftab[bbStart + 1 << 8] - this.ftab[bbStart << 8]) { + runningOrder[j] = runningOrder[j - bbSize]; + j -= bbSize; + if(j <= bbSize - 1) { + break; + } + } + + runningOrder[j] = bbStart; + } + } while(bbSize != 1); + + for(i = 0; i <= 255; ++i) { + int ss = runningOrder[i]; + + int shifts; + for(j = 0; j <= 255; ++j) { + shifts = (ss << 8) + j; + if((this.ftab[shifts] & 2097152) != 2097152) { + bbStart = this.ftab[shifts] & -2097153; + bbSize = (this.ftab[shifts + 1] & -2097153) - 1; + if(bbSize > bbStart) { + this.qSort3(bbStart, bbSize, 2); + numQSorted += bbSize - bbStart + 1; + if(this.workDone > this.workLimit && this.firstAttempt) { + return; + } + } + + this.ftab[shifts] |= 2097152; + } + } + + bigDone[ss] = true; + if(i < 255) { + bbStart = this.ftab[ss << 8] & -2097153; + bbSize = (this.ftab[ss + 1 << 8] & -2097153) - bbStart; + + for(shifts = 0; bbSize >> shifts > '\ufffe'; ++shifts) { + } + + for(j = 0; j < bbSize; ++j) { + int a2update = this.zptr[bbStart + j]; + int qVal = j >> shifts; + this.quadrant[a2update] = qVal; + if(a2update < 20) { + this.quadrant[a2update + this.last + 1] = qVal; + } + } + + if(bbSize - 1 >> shifts > '\uffff') { + panic(); + } + } + + for(j = 0; j <= 255; ++j) { + copy[j] = this.ftab[(j << 8) + ss] & -2097153; + } + + for(j = this.ftab[ss << 8] & -2097153; j < (this.ftab[ss + 1 << 8] & -2097153); ++j) { + c1 = this.block[this.zptr[j]]; + if(!bigDone[c1]) { + this.zptr[copy[c1]] = this.zptr[j] == 0?this.last:this.zptr[j] - 1; + ++copy[c1]; + } + } + + for(j = 0; j <= 255; ++j) { + this.ftab[(j << 8) + ss] |= 2097152; + } + } + } + + } + + private void randomiseBlock() { + int rNToGo = 0; + int rTPos = 0; + + int i; + for(i = 0; i < 256; ++i) { + this.inUse[i] = false; + } + + for(i = 0; i <= this.last; ++i) { + if(rNToGo == 0) { + rNToGo = (char)rNums[rTPos]; + ++rTPos; + if(rTPos == 512) { + rTPos = 0; + } + } + + --rNToGo; + this.block[i + 1] = (char)(this.block[i + 1] ^ (rNToGo == 1?1:0)); + this.block[i + 1] = (char)(this.block[i + 1] & 255); + this.inUse[this.block[i + 1]] = true; + } + + } + + private void doReversibleTransformation() { + this.workLimit = this.workFactor * this.last; + this.workDone = 0; + this.blockRandomised = false; + this.firstAttempt = true; + this.mainSort(); + if(this.workDone > this.workLimit && this.firstAttempt) { + this.randomiseBlock(); + this.workLimit = this.workDone = 0; + this.blockRandomised = true; + this.firstAttempt = false; + this.mainSort(); + } + + this.origPtr = -1; + + for(int i = 0; i <= this.last; ++i) { + if(this.zptr[i] == 0) { + this.origPtr = i; + break; + } + } + + if(this.origPtr == -1) { + panic(); + } + + } + + private boolean fullGtU(int i1, int i2) { + char c1 = this.block[i1 + 1]; + char c2 = this.block[i2 + 1]; + if(c1 != c2) { + return c1 > c2; + } else { + ++i1; + ++i2; + c1 = this.block[i1 + 1]; + c2 = this.block[i2 + 1]; + if(c1 != c2) { + return c1 > c2; + } else { + ++i1; + ++i2; + c1 = this.block[i1 + 1]; + c2 = this.block[i2 + 1]; + if(c1 != c2) { + return c1 > c2; + } else { + ++i1; + ++i2; + c1 = this.block[i1 + 1]; + c2 = this.block[i2 + 1]; + if(c1 != c2) { + return c1 > c2; + } else { + ++i1; + ++i2; + c1 = this.block[i1 + 1]; + c2 = this.block[i2 + 1]; + if(c1 != c2) { + return c1 > c2; + } else { + ++i1; + ++i2; + c1 = this.block[i1 + 1]; + c2 = this.block[i2 + 1]; + if(c1 != c2) { + return c1 > c2; + } else { + ++i1; + ++i2; + int k = this.last + 1; + + do { + c1 = this.block[i1 + 1]; + c2 = this.block[i2 + 1]; + if(c1 != c2) { + return c1 > c2; + } + + int s1 = this.quadrant[i1]; + int s2 = this.quadrant[i2]; + if(s1 != s2) { + return s1 > s2; + } + + ++i1; + ++i2; + c1 = this.block[i1 + 1]; + c2 = this.block[i2 + 1]; + if(c1 != c2) { + return c1 > c2; + } + + s1 = this.quadrant[i1]; + s2 = this.quadrant[i2]; + if(s1 != s2) { + return s1 > s2; + } + + ++i1; + ++i2; + c1 = this.block[i1 + 1]; + c2 = this.block[i2 + 1]; + if(c1 != c2) { + return c1 > c2; + } + + s1 = this.quadrant[i1]; + s2 = this.quadrant[i2]; + if(s1 != s2) { + return s1 > s2; + } + + ++i1; + ++i2; + c1 = this.block[i1 + 1]; + c2 = this.block[i2 + 1]; + if(c1 != c2) { + return c1 > c2; + } + + s1 = this.quadrant[i1]; + s2 = this.quadrant[i2]; + if(s1 != s2) { + return s1 > s2; + } + + ++i1; + ++i2; + if(i1 > this.last) { + i1 -= this.last; + --i1; + } + + if(i2 > this.last) { + i2 -= this.last; + --i2; + } + + k -= 4; + ++this.workDone; + } while(k >= 0); + + return false; + } + } + } + } + } + } + } + + private void allocateCompressStructures() { + int n = 100000 * this.blockSize100k; + this.block = new char[n + 1 + 20]; + this.quadrant = new int[n + 20]; + this.zptr = new int[n]; + this.ftab = new int[65537]; + if(this.block != null && this.quadrant != null && this.zptr != null && this.ftab == null) { + } + + this.szptr = new short[2 * n]; + } + + private void generateMTFValues() { + char[] yy = new char[256]; + this.makeMaps(); + int EOB = this.nInUse + 1; + + int i; + for(i = 0; i <= EOB; ++i) { + this.mtfFreq[i] = 0; + } + + int wr = 0; + int zPend = 0; + + for(i = 0; i < this.nInUse; ++i) { + yy[i] = (char)i; + } + + for(i = 0; i <= this.last; ++i) { + char ll_i = this.unseqToSeq[this.block[this.zptr[i]]]; + int j = 0; + + char tmp; + char tmp2; + for(tmp = yy[j]; ll_i != tmp; yy[j] = tmp2) { + ++j; + tmp2 = tmp; + tmp = yy[j]; + } + + yy[0] = tmp; + if(j == 0) { + ++zPend; + } else { + if(zPend > 0) { + --zPend; + + while(true) { + switch(zPend % 2) { + case 0: + this.szptr[wr] = 0; + ++wr; + ++this.mtfFreq[0]; + break; + case 1: + this.szptr[wr] = 1; + ++wr; + ++this.mtfFreq[1]; + } + + if(zPend < 2) { + zPend = 0; + break; + } + + zPend = (zPend - 2) / 2; + } + } + + this.szptr[wr] = (short)(j + 1); + ++wr; + ++this.mtfFreq[j + 1]; + } + } + + if(zPend > 0) { + --zPend; + + while(true) { + switch(zPend % 2) { + case 0: + this.szptr[wr] = 0; + ++wr; + ++this.mtfFreq[0]; + break; + case 1: + this.szptr[wr] = 1; + ++wr; + ++this.mtfFreq[1]; + } + + if(zPend < 2) { + break; + } + + zPend = (zPend - 2) / 2; + } + } + + this.szptr[wr] = (short)EOB; + ++wr; + ++this.mtfFreq[EOB]; + this.nMTF = wr; + } + + public int getnBlocksRandomised() { + return this.nBlocksRandomised; + } + + public void setnBlocksRandomised(int nBlocksRandomised) { + this.nBlocksRandomised = nBlocksRandomised; + } + + private static class StackElem { + int ll; + int hh; + int dd; + + private StackElem() { + } + + StackElem(CBZip2OutputStream.SyntheticClass_1 x0) { + this(); + } + + // $FF: synthetic method + StackElem(CBZip2OutputStream.StackElem var1) { + this(); + } + } + + static class SyntheticClass_1 { + } +} diff --git a/src/com/alex/util/bzip2/CRC.java b/src/com/alex/util/bzip2/CRC.java new file mode 100644 index 0000000..2c4cfb7 --- /dev/null +++ b/src/com/alex/util/bzip2/CRC.java @@ -0,0 +1,35 @@ +package com.alex.util.bzip2; + +public class CRC { + public static int[] crc32Table = new int[]{0, 79764919, 159529838, 222504665, 319059676, 398814059, 445009330, 507990021, 638119352, 583659535, 797628118, 726387553, 890018660, 835552979, 1015980042, 944750013, 1276238704, 1221641927, 1167319070, 1095957929, 1595256236, 1540665371, 1452775106, 1381403509, 1780037320, 1859660671, 1671105958, 1733955601, 2031960084, 2111593891, 1889500026, 1952343757, -1742489888, -1662866601, -1851683442, -1788833735, -1960329156, -1880695413, -2103051438, -2040207643, -1104454824, -1159051537, -1213636554, -1284997759, -1389417084, -1444007885, -1532160278, -1603531939, -734892656, -789352409, -575645954, -646886583, -952755380, -1007220997, -827056094, -898286187, -231047128, -151282273, -71779514, -8804623, -515967244, -436212925, -390279782, -327299027, 881225847, 809987520, 1023691545, 969234094, 662832811, 591600412, 771767749, 717299826, 311336399, 374308984, 453813921, 533576470, 25881363, 88864420, 134795389, 214552010, 2023205639, 2086057648, 1897238633, 1976864222, 1804852699, 1867694188, 1645340341, 1724971778, 1587496639, 1516133128, 1461550545, 1406951526, 1302016099, 1230646740, 1142491917, 1087903418, -1398421865, -1469785312, -1524105735, -1578704818, -1079922613, -1151291908, -1239184603, -1293773166, -1968362705, -1905510760, -2094067647, -2014441994, -1716953613, -1654112188, -1876203875, -1796572374, -525066777, -462094256, -382327159, -302564546, -206542021, -143559028, -97365931, -17609246, -960696225, -1031934488, -817968335, -872425850, -709327229, -780559564, -600130067, -654598054, 1762451694, 1842216281, 1619975040, 1682949687, 2047383090, 2127137669, 1938468188, 2001449195, 1325665622, 1271206113, 1183200824, 1111960463, 1543535498, 1489069629, 1434599652, 1363369299, 622672798, 568075817, 748617968, 677256519, 907627842, 853037301, 1067152940, 995781531, 51762726, 131386257, 177728840, 240578815, 269590778, 349224269, 429104020, 491947555, -248556018, -168932423, -122852000, -60002089, -500490030, -420856475, -341238852, -278395381, -685261898, -739858943, -559578920, -630940305, -1004286614, -1058877219, -845023740, -916395085, -1119974018, -1174433591, -1262701040, -1333941337, -1371866206, -1426332139, -1481064244, -1552294533, -1690935098, -1611170447, -1833673816, -1770699233, -2009983462, -1930228819, -2119160460, -2056179517, 1569362073, 1498123566, 1409854455, 1355396672, 1317987909, 1246755826, 1192025387, 1137557660, 2072149281, 2135122070, 1912620623, 1992383480, 1753615357, 1816598090, 1627664531, 1707420964, 295390185, 358241886, 404320391, 483945776, 43990325, 106832002, 186451547, 266083308, 932423249, 861060070, 1041341759, 986742920, 613929101, 542559546, 756411363, 701822548, -978770311, -1050133554, -869589737, -924188512, -693284699, -764654318, -550540341, -605129092, -475935807, -413084042, -366743377, -287118056, -257573603, -194731862, -114850189, -35218492, -1984365303, -1921392450, -2143631769, -2063868976, -1698919467, -1635936670, -1824608069, -1744851700, -1347415887, -1418654458, -1506661409, -1561119128, -1129027987, -1200260134, -1254728445, -1309196108}; + int globalCrc; + + public CRC() { + this.initialiseCRC(); + } + + public void initialiseCRC() { + this.globalCrc = -1; + } + + public int getFinalCRC() { + return ~this.globalCrc; + } + + public int getGlobalCRC() { + return this.globalCrc; + } + + public void setGlobalCRC(int newCrc) { + this.globalCrc = newCrc; + } + + public void updateCRC(int inCh) { + int temp = this.globalCrc >> 24 ^ inCh; + if(temp < 0) { + temp += 256; + } + + this.globalCrc = this.globalCrc << 8 ^ crc32Table[temp]; + } +} diff --git a/src/com/alex/util/crc32/CRC32HGenerator.java b/src/com/alex/util/crc32/CRC32HGenerator.java new file mode 100644 index 0000000..323d01c --- /dev/null +++ b/src/com/alex/util/crc32/CRC32HGenerator.java @@ -0,0 +1,22 @@ +package com.alex.util.crc32; + +import java.util.zip.CRC32; + +public final class CRC32HGenerator { + public static final CRC32 CRC32Instance = new CRC32(); + + public static int getHash(byte[] data) { + return getHash(data, 0, data.length); + } + + public static int getHash(byte[] data, int offset, int length) { + CRC32 var3 = CRC32Instance; + CRC32 var4 = CRC32Instance; + synchronized(CRC32Instance) { + CRC32Instance.update(data, offset, length); + int hash = (int)CRC32Instance.getValue(); + CRC32Instance.reset(); + return hash; + } + } +} diff --git a/src/com/alex/util/gzip/GZipCompressor.java b/src/com/alex/util/gzip/GZipCompressor.java new file mode 100644 index 0000000..5c92949 --- /dev/null +++ b/src/com/alex/util/gzip/GZipCompressor.java @@ -0,0 +1,22 @@ +package com.alex.util.gzip; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.zip.GZIPOutputStream; + +public class GZipCompressor { + public static final byte[] compress(byte[] data) { + ByteArrayOutputStream compressedBytes = new ByteArrayOutputStream(); + + try { + GZIPOutputStream var3 = new GZIPOutputStream(compressedBytes); + var3.write(data); + var3.finish(); + var3.close(); + return compressedBytes.toByteArray(); + } catch (IOException var31) { + var31.printStackTrace(); + return null; + } + } +} diff --git a/src/com/alex/util/gzip/GZipDecompressor.java b/src/com/alex/util/gzip/GZipDecompressor.java new file mode 100644 index 0000000..2100504 --- /dev/null +++ b/src/com/alex/util/gzip/GZipDecompressor.java @@ -0,0 +1,30 @@ +package com.alex.util.gzip; + +import com.alex.io.Stream; + +import java.util.zip.Inflater; + +public class GZipDecompressor { + private static final Inflater inflaterInstance = new Inflater(true); + + public static final boolean decompress(Stream stream, byte[] data) { + Inflater var2 = inflaterInstance; + Inflater var3 = inflaterInstance; + synchronized(inflaterInstance) { + if(stream.getBuffer()[stream.getOffset()] == 31 && stream.getBuffer()[stream.getOffset() + 1] == -117) { + try { + inflaterInstance.setInput(stream.getBuffer(), stream.getOffset() + 10, -stream.getOffset() - 18 + stream.getBuffer().length); + inflaterInstance.inflate(data); + } catch (Exception var5) { + inflaterInstance.reset(); + return false; + } + + inflaterInstance.reset(); + return true; + } else { + return false; + } + } + } +} diff --git a/src/com/alex/util/whirlpool/Whirlpool.java b/src/com/alex/util/whirlpool/Whirlpool.java new file mode 100644 index 0000000..19bf1eb --- /dev/null +++ b/src/com/alex/util/whirlpool/Whirlpool.java @@ -0,0 +1,248 @@ +package com.alex.util.whirlpool; + +import java.util.Arrays; + +public class Whirlpool { + public static final int DIGESTBITS = 512; + public static final int DIGESTBYTES = 64; + protected static final int R = 10; + private static final String sbox = "ᠣ웨螸Å�㚦틵祯酒悼鮎ꌌ笵ᷠퟂ\u2e4b﹗ᕷ㟥\u9ff0䫚壉⤊놠殅ëµ�ჴ쬾է\ue427䆋ê�½é—˜ï¯®ç±¦\udd17äžžì¨\u00ad뼇굚茳挂ꩱ젙䧙\uf2e3守騦㊰\ue90fí–€ë»�㑈コé�Ÿ\u2068\u1aae둔錢擱猒䀈ì�¬\udba1贽需켫皂혛떯æ©�䗳ワ㽕ꋪ斺⿀\ude1c\ufd4d鉵ڊ닦ฟ拔ꢖ暈╙葲㥌幸㢌톥\ue261댡鰞ä�‡ï°„写æ´�\ufadf縤㮫츑轎럫ã²�铷뤓ⳓ\ue76eì�ƒå™„義⪻셓\udc0b鵬ㅴ\uf646겉ᓡᘺ椉炶íƒ\u00ad챂颤⡜\uf886"; + private static final long[][] C = new long[8][256]; + private static final long[] rc = new long[11]; + protected byte[] bitLength = new byte[32]; + protected byte[] buffer = new byte[64]; + protected int bufferBits = 0; + protected int bufferPos = 0; + protected long[] hash = new long[8]; + protected long[] K = new long[8]; + protected long[] L = new long[8]; + protected long[] block = new long[8]; + protected long[] state = new long[8]; + + static { + int r; + for(r = 0; r < 256; ++r) { + char var15 = "ᠣ웨螸Å�㚦틵祯酒悼鮎ꌌ笵ᷠퟂ\u2e4b﹗ᕷ㟥\u9ff0䫚壉⤊놠殅ëµ�ჴ쬾է\ue427䆋ê�½é—˜ï¯®ç±¦\udd17äžžì¨\u00ad뼇굚茳挂ꩱ젙䧙\uf2e3守騦㊰\ue90fí–€ë»�㑈コé�Ÿ\u2068\u1aae둔錢擱猒䀈ì�¬\udba1贽需켫皂혛떯æ©�䗳ワ㽕ꋪ斺⿀\ude1c\ufd4d鉵ڊ닦ฟ拔ꢖ暈╙葲㥌幸㢌톥\ue261댡鰞ä�‡ï°„写æ´�\ufadf縤㮫츑轎럫ã²�铷뤓ⳓ\ue76eì�ƒå™„義⪻셓\udc0b鵬ㅴ\uf646겉ᓡᘺ椉炶íƒ\u00ad챂颤⡜\uf886".charAt(r / 2); + long v1 = (r & 1) == 0?(long)(var15 >>> 8):(long)(var15 & 255); + long v2 = v1 << 1; + if(v2 >= 256L) { + v2 ^= 285L; + } + + long v4 = v2 << 1; + if(v4 >= 256L) { + v4 ^= 285L; + } + + long v5 = v4 ^ v1; + long v8 = v4 << 1; + if(v8 >= 256L) { + v8 ^= 285L; + } + + long v9 = v8 ^ v1; + C[0][r] = v1 << 56 | v1 << 48 | v4 << 40 | v1 << 32 | v8 << 24 | v5 << 16 | v2 << 8 | v9; + + for(int t = 1; t < 8; ++t) { + C[t][r] = C[t - 1][r] >>> 8 | C[t - 1][r] << 56; + } + } + + rc[0] = 0L; + + for(r = 1; r <= 10; ++r) { + int var151 = 8 * (r - 1); + rc[r] = C[0][var151] & -72057594037927936L ^ C[1][var151 + 1] & 71776119061217280L ^ C[2][var151 + 2] & 280375465082880L ^ C[3][var151 + 3] & 1095216660480L ^ C[4][var151 + 4] & 4278190080L ^ C[5][var151 + 5] & 16711680L ^ C[6][var151 + 6] & 65280L ^ C[7][var151 + 7] & 255L; + } + + } + + public static byte[] getHash(byte[] data, int off, int len) { + byte[] source; + if(off <= 0) { + source = data; + } else { + source = new byte[len]; + + System.arraycopy(data, off + 0, source, 0, len); + } + + Whirlpool var61 = new Whirlpool(); + var61.NESSIEinit(); + var61.NESSIEadd(source, len * 8L); + byte[] digest = new byte[64]; + var61.NESSIEfinalize(digest); + return digest; + } + + protected void processBuffer() { + int i = 0; + + int i1; + for(i1 = 0; i < 8; i1 += 8) { + this.block[i] = (long)this.buffer[i1] << 56 ^ ((long)this.buffer[i1 + 1] & 255L) << 48 ^ ((long)this.buffer[i1 + 2] & 255L) << 40 ^ ((long)this.buffer[i1 + 3] & 255L) << 32 ^ ((long)this.buffer[i1 + 4] & 255L) << 24 ^ ((long)this.buffer[i1 + 5] & 255L) << 16 ^ ((long)this.buffer[i1 + 6] & 255L) << 8 ^ (long)this.buffer[i1 + 7] & 255L; + ++i; + } + + for(i = 0; i < 8; ++i) { + this.state[i] = this.block[i] ^ (this.K[i] = this.hash[i]); + } + + for(i = 1; i <= 10; ++i) { + int t; + int s; + for(i1 = 0; i1 < 8; ++i1) { + this.L[i1] = 0L; + t = 0; + + for(s = 56; t < 8; s -= 8) { + this.L[i1] ^= C[t][(int)(this.K[i1 - t & 7] >>> s) & 255]; + ++t; + } + } + + for(i1 = 0; i1 < 8; ++i1) { + this.K[i1] = this.L[i1]; + } + + this.K[0] ^= rc[i]; + + for(i1 = 0; i1 < 8; ++i1) { + this.L[i1] = this.K[i1]; + t = 0; + + for(s = 56; t < 8; s -= 8) { + this.L[i1] ^= C[t][(int)(this.state[i1 - t & 7] >>> s) & 255]; + ++t; + } + } + + for(i1 = 0; i1 < 8; ++i1) { + this.state[i1] = this.L[i1]; + } + } + + for(i = 0; i < 8; ++i) { + this.hash[i] ^= this.state[i] ^ this.block[i]; + } + + } + + public void NESSIEinit() { + Arrays.fill(this.bitLength, (byte)0); + this.bufferBits = this.bufferPos = 0; + this.buffer[0] = 0; + Arrays.fill(this.hash, 0L); + } + + public void NESSIEadd(byte[] source, long sourceBits) { + int sourcePos = 0; + int sourceGap = 8 - ((int)sourceBits & 7) & 7; + int bufferRem = this.bufferBits & 7; + long value = sourceBits; + int i = 31; + + int b; + for(b = 0; i >= 0; --i) { + b += (this.bitLength[i] & 255) + ((int)value & 255); + this.bitLength[i] = (byte)b; + b >>>= 8; + value >>>= 8; + } + + while(sourceBits > 8L) { + b = source[sourcePos] << sourceGap & 255 | (source[sourcePos + 1] & 255) >>> 8 - sourceGap; + if(b < 0 || b >= 256) { + throw new RuntimeException("LOGIC ERROR"); + } + + byte[] var10000 = this.buffer; + int var10001 = this.bufferPos++; + var10000[var10001] = (byte)(var10000[var10001] | b >>> bufferRem); + this.bufferBits += 8 - bufferRem; + if(this.bufferBits == 512) { + this.processBuffer(); + this.bufferBits = this.bufferPos = 0; + } + + this.buffer[this.bufferPos] = (byte)(b << 8 - bufferRem & 255); + this.bufferBits += bufferRem; + sourceBits -= 8L; + ++sourcePos; + } + + if(sourceBits > 0L) { + b = source[sourcePos] << sourceGap & 255; + this.buffer[this.bufferPos] = (byte)(this.buffer[this.bufferPos] | b >>> bufferRem); + } else { + b = 0; + } + + if((long)bufferRem + sourceBits < 8L) { + this.bufferBits = (int)((long)this.bufferBits + sourceBits); + } else { + ++this.bufferPos; + this.bufferBits += 8 - bufferRem; + sourceBits -= 8 - bufferRem; + if(this.bufferBits == 512) { + this.processBuffer(); + this.bufferBits = this.bufferPos = 0; + } + + this.buffer[this.bufferPos] = (byte)(b << 8 - bufferRem & 255); + this.bufferBits += (int)sourceBits; + } + + } + + public void NESSIEfinalize(byte[] digest) { + this.buffer[this.bufferPos] = (byte)(this.buffer[this.bufferPos] | 128 >>> (this.bufferBits & 7)); + ++this.bufferPos; + if(this.bufferPos > 32) { + while(true) { + if(this.bufferPos >= 64) { + this.processBuffer(); + this.bufferPos = 0; + break; + } + + this.buffer[this.bufferPos++] = 0; + } + } + + while(this.bufferPos < 32) { + this.buffer[this.bufferPos++] = 0; + } + + System.arraycopy(this.bitLength, 0, this.buffer, 32, 32); + this.processBuffer(); + int i = 0; + + for(int j = 0; i < 8; j += 8) { + long h = this.hash[i]; + digest[j] = (byte)((int)(h >>> 56)); + digest[j + 1] = (byte)((int)(h >>> 48)); + digest[j + 2] = (byte)((int)(h >>> 40)); + digest[j + 3] = (byte)((int)(h >>> 32)); + digest[j + 4] = (byte)((int)(h >>> 24)); + digest[j + 5] = (byte)((int)(h >>> 16)); + digest[j + 6] = (byte)((int)(h >>> 8)); + digest[j + 7] = (byte)((int)h); + ++i; + } + + } + + public void NESSIEadd(String source) { + if(source.length() > 0) { + byte[] data = new byte[source.length()]; + + for(int i = 0; i < source.length(); ++i) { + data[i] = (byte)source.charAt(i); + } + + this.NESSIEadd(data, 8L * data.length); + } + + } +} diff --git a/src/com/alex/utils/Constants.java b/src/com/alex/utils/Constants.java new file mode 100644 index 0000000..c7b0ddc --- /dev/null +++ b/src/com/alex/utils/Constants.java @@ -0,0 +1,20 @@ +package com.alex.utils; + +public final class Constants { + public static final int NO_COMPRESSION = 0; + public static final int BZIP2_COMPRESSION = 1; + public static final int GZIP_COMPRESSION = 2; + public static final int MAX_VALID_ARCHIVE_LENGTH = 1000000; + public static final int INTERFACE_DEFINITIONS_INDEX = 3; + public static final int MAPS_INDEX = 5; + public static final int MODELS_INDEX = 7; + public static final int SPRITES_INDEX = 8; + public static final int INDEXED_IMAGES_INDEX = 8; + public static final int OBJECTS_DEFINITIONS_INDEX = 18; + public static final int ITEM_DEFINITIONS_INDEX = 19; + public static final int LOADER_IMAGES_INDEX = 32; + public static final int LOADER_INDEXED_IMAGES_INDEX = 34; + public static final int CLIENT_BUILD = 562; + public static final boolean ENCRYPTED_CACHE = true; + public static final int NPC_DEFINITIONS_INDEX = 18; +} diff --git a/src/com/alex/utils/Utils.java b/src/com/alex/utils/Utils.java new file mode 100644 index 0000000..7c0702f --- /dev/null +++ b/src/com/alex/utils/Utils.java @@ -0,0 +1,73 @@ +package com.alex.utils; + +import com.alex.io.OutputStream; +import com.alex.store.Store; + +import java.math.BigInteger; + +public final class Utils { + public static byte[] cryptRSA(byte[] data, BigInteger exponent, BigInteger modulus) { + return (new BigInteger(data)).modPow(exponent, modulus).toByteArray(); + } + + public static byte[] getArchivePacketData(int indexId, int archiveId, byte[] archive) { + OutputStream stream = new OutputStream(archive.length + 4); + stream.writeByte(indexId); + stream.writeShort(archiveId); + stream.writeByte(0); + stream.writeInt(archive.length); + int offset = 8; + + for(int var6 = 0; var6 < archive.length; ++var6) { + if(offset == 512) { + stream.writeByte(-1); + offset = 1; + } + + stream.writeByte(archive[var6]); + ++offset; + } + + byte[] var61 = new byte[stream.getOffset()]; + stream.setOffset(0); + stream.getBytes(var61, 0, var61.length); + return var61; + } + + public static int getNameHash(String name) { + return name.toLowerCase().hashCode(); + } + + public static int getInterfaceDefinitionsSize(Store store) { + return store.getIndexes()[3].getLastArchiveId() + 1; + } + + public static int getInterfaceDefinitionsComponentsSize(Store store, int interfaceId) { + return store.getIndexes()[3].getLastFileId(interfaceId) + 1; + } + + public static int getAnimationDefinitionsSize(Store store) { + int lastArchiveId = store.getIndexes()[20].getLastArchiveId(); + return lastArchiveId * 128 + store.getIndexes()[20].getValidFilesCount(lastArchiveId); + } + + public static int getItemDefinitionsSize(Store store) { + int lastArchiveId = store.getIndexes()[19].getLastArchiveId(); + return lastArchiveId * 256 + store.getIndexes()[19].getValidFilesCount(lastArchiveId); + } + + public static int getNPCDefinitionsSize(Store store) { + int lastArchiveId = store.getIndexes()[18].getLastArchiveId(); + return lastArchiveId * 128 + store.getIndexes()[18].getValidFilesCount(lastArchiveId); + } + + public static int getObjectDefinitionsSize(Store store) { + int lastArchiveId = store.getIndexes()[16].getLastArchiveId(); + return lastArchiveId * 256 + store.getIndexes()[16].getValidFilesCount(lastArchiveId); + } + + public static int getGraphicDefinitionsSize(Store store) { + int lastArchiveId = store.getIndexes()[21].getLastArchiveId(); + return lastArchiveId * 256 + store.getIndexes()[21].getValidFilesCount(lastArchiveId); + } +} diff --git a/src/com/editor/Console.java b/src/com/editor/Console.java new file mode 100644 index 0000000..300b2da --- /dev/null +++ b/src/com/editor/Console.java @@ -0,0 +1,91 @@ +package com.editor; + +import javax.swing.*; +import javax.swing.GroupLayout.Alignment; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.URL; + +public class Console extends JFrame { + private static final long serialVersionUID = -4693540915136770583L; + public static JTextArea output; + + public Console() { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (Exception e) { + e.printStackTrace(); + } + this.setTitle("Console"); + this.setResizable(false); + this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + this.setLocationRelativeTo(null); + this.initComponents(); + Main.log("Console", "Console Started."); + } + + private void initComponents() { + JScrollPane jScrollPane1 = new JScrollPane(); + output = new JTextArea(); + JMenuBar jMenuBar1 = new JMenuBar(); + JMenu jMenu1 = new JMenu(); + JMenuItem jMenuItem1 = new JMenuItem(); + JMenuItem jMenuItem2 = new JMenuItem(); + this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + output.setEditable(false); + output.setColumns(20); + output.setLineWrap(true); + output.setRows(5); + jScrollPane1.setViewportView(output); + jMenu1.setText("File"); + jMenuItem1.setText("Close Console"); + jMenuItem1.addActionListener(Console.this::jMenuItem1ActionPerformed); + jMenu1.add(jMenuItem1); + jMenuItem2.setText("Exit Program"); + jMenuItem2.addActionListener(Console.this::jMenuItem2ActionPerformed); + jMenu1.add(jMenuItem2); + jMenuBar1.add(jMenu1); + this.setJMenuBar(jMenuBar1); + GroupLayout layout = new GroupLayout(this.getContentPane()); + this.getContentPane().setLayout(layout); + layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING).addComponent(jScrollPane1, -1, 618, 32767)); + layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING).addComponent(jScrollPane1, -1, 240, 32767)); + this.pack(); + } + + private void jMenuItem2ActionPerformed(ActionEvent evt) { + System.exit(0); + } + + private void jMenuItem1ActionPerformed(ActionEvent evt) { + this.dispose(); + } + + public static void main(String[] args) { + EventQueue.invokeLater(() -> (new Console()).setVisible(true)); + } + + private static void updateTextArea(final String text) { + SwingUtilities.invokeLater(() -> Console.output.append(text)); + } + + public static void redirectSystemStreams() { + OutputStream out = new OutputStream() { + public void write(int b) { + Console.updateTextArea(String.valueOf((char)b)); + } + + public void write(byte[] b, int off, int len) { + Console.updateTextArea(new String(b, off, len)); + } + + public void write(byte[] b) { + this.write(b, 0, b.length); + } + }; + System.setOut(new PrintStream(out, true)); + System.setErr(new PrintStream(out, true)); + } +} diff --git a/src/com/editor/Main.java b/src/com/editor/Main.java new file mode 100644 index 0000000..654577e --- /dev/null +++ b/src/com/editor/Main.java @@ -0,0 +1,60 @@ +package com.editor; + +import com.editor.Console; +import com.editor.ToolSelection; + +import java.awt.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Date; + +public class Main { + + public static Image iconImage; + + public static void main(String[] args) { + URL url = ClassLoader.getSystemResource("com/editor/resources/ico32.png"); + Toolkit kit = Toolkit.getDefaultToolkit(); + iconImage = kit.createImage(url); + Console.redirectSystemStreams(); + new Console().setVisible(true); + new ToolSelection().setVisible(true); + log("Main", "2009Scape Item Definition Editor"); + log("Main", "Based on Frosty's Cache Editor"); + } + + public static void log(String className, String message) { + System.out.println("[" + className + "]: " + message); + printDebug(className, message); + } + + private static void printDebug(String className, String message) { + File f = new File(System.getProperty("user.home") + "/FCE/logs/"); + File f1 = new File(System.getProperty("user.home") + "/FCE/logs/" + 2 + 5 + 1 + 11 + ".txt"); + f.mkdirs(); + + try { + f1.createNewFile(); + } catch (IOException var10) { + log("Main", "Could not create log file."); + } + + String strFilePath = System.getProperty("user.home") + "/FCE/logs/" + 2 + 5 + 1 + 11 + ".txt"; + + try { + FileOutputStream var9 = new FileOutputStream(strFilePath, true); + String strContent = new Date() + ": [" + className + "]: " + message; + String lineSep = System.getProperty("line.separator"); + var9.write(strContent.getBytes()); + var9.write(lineSep.getBytes()); + } catch (FileNotFoundException var8) { + log("Main", "FileNotFoundException : " + var8); + } catch (IOException var91) { + log("Main", "IOException : " + var91); + } + + } +} diff --git a/src/com/editor/ToolSelection.java b/src/com/editor/ToolSelection.java new file mode 100644 index 0000000..617e6b5 --- /dev/null +++ b/src/com/editor/ToolSelection.java @@ -0,0 +1,124 @@ +package com.editor; + +import com.editor.item.ItemSelection; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; + +public class ToolSelection extends JFrame { + private static final long serialVersionUID = 2024943190858205332L; + private String cache = ""; + private JButton loadCacheButton; + private JComboBox selectionBox; + + public static void main(String[] args) { + EventQueue.invokeLater(() -> (new ToolSelection()).setVisible(true)); + } + + public ToolSelection() { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (Exception e) { + e.printStackTrace(); + } + this.setIconImage(Main.iconImage); + this.setTitle("Tool Selection"); + this.setResizable(false); + this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + this.setLocationRelativeTo(null); + this.initComponents(); + Main.log("Main", "ToolSelection Started"); + } + + private void initComponents() { + JPanel alignmentPanel1 = new JPanel(new FlowLayout()); + JPanel alignmentPanel2 = new JPanel(new FlowLayout()); + JPanel alignmentPanel3 = new JPanel(new FlowLayout()); + + this.setPreferredSize(new Dimension(250, 200)); + JLabel selectYourEditorLabel = new JLabel("Select your editor:"); + this.selectionBox = new JComboBox(); + JButton submitButton = new JButton(); + JMenuBar jMenuBar1 = new JMenuBar(); + JMenu jMenu1 = new JMenu(); + this.loadCacheButton = new JButton(); + JMenuItem exitButton = new JMenuItem(); + this.setDefaultCloseOperation(3); + this.loadCacheButton.setText("Load Cache"); + this.loadCacheButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + loadCacheButtonHandler(e); + } + }); + this.loadCacheButton.setPreferredSize(new Dimension(125, 30)); + alignmentPanel1.add(loadCacheButton, BorderLayout.CENTER); + + alignmentPanel2.add(selectYourEditorLabel); + + this.selectionBox.setModel(new DefaultComboBoxModel(new String[]{"Items"})); + submitButton.setText("Submit"); + submitButton.addActionListener(ToolSelection.this::submitButtonActionPerformed); + + alignmentPanel3.add(this.selectionBox); + alignmentPanel3.add(submitButton); + + jMenu1.setText("File"); + exitButton.setText("Exit Program"); + exitButton.addActionListener(ToolSelection.this::exitButtonActionPerformed); + jMenu1.add(exitButton); + jMenuBar1.add(jMenu1); + this.setJMenuBar(jMenuBar1); + GridLayout layout = new GridLayout(3, 1, 5, 10); + this.getContentPane().setLayout(layout); + this.add(alignmentPanel1); + this.add(alignmentPanel2); + this.add(alignmentPanel3); + this.pack(); + } + + private void submitButtonActionPerformed(ActionEvent evt) { + if (this.cache.isEmpty()) { + try { + Main.log("ToolSelection", "No Cache Set!"); + } catch (ArrayIndexOutOfBoundsException e) { + Main.log("ToolSelection", "No Cache Set!"); + } + } else if (this.selectionBox.getSelectedIndex() == 0) { + try { + (new ItemSelection(this.cache)).setVisible(true); + Main.log("ToolSelection", "ItemSelection Started"); + } catch (IOException var4) { + Main.log("ToolSelection", "No Cache Set!"); + } + } else { + Main.log("ToolSelection", "No Tool Selected!"); + } + } + + private void loadCacheButtonHandler(ActionEvent evt) { + JFileChooser fc = new JFileChooser(); + fc.setFileSelectionMode(1); + if (evt.getSource() == this.loadCacheButton) { + int returnVal = fc.showOpenDialog(this); + if (returnVal == 0) { + File file = fc.getSelectedFile(); + this.cache = file.getPath() + "/"; + } + } + } + + private void exitButtonActionPerformed(ActionEvent evt) { + JDialog.setDefaultLookAndFeelDecorated(true); + int response = JOptionPane.showConfirmDialog(null, "Do you want to continue?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + if (response == 0) { + System.exit(0); + } + } +} diff --git a/src/com/editor/Utils.java b/src/com/editor/Utils.java new file mode 100644 index 0000000..0c1db40 --- /dev/null +++ b/src/com/editor/Utils.java @@ -0,0 +1,49 @@ +package com.editor; + +import com.alex.store.Store; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public class Utils { + public static byte[] getBytesFromFile(File file) throws IOException { + FileInputStream is = new FileInputStream(file); + long length = file.length(); + if (length > 2147483647L) { + } + + byte[] bytes = new byte[(int)length]; + int offset = 0; + + int numRead1; + for (boolean numRead = false; offset < bytes.length && (numRead1 = is.read(bytes, offset, bytes.length - offset)) >= 0; offset += numRead1) { + } + + if (offset < bytes.length) { + throw new IOException("Could not completely read file " + file.getName()); + } else { + is.close(); + return bytes; + } + } + + public static int packCustomModel(Store cache, byte[] data) { + int archiveId = cache.getIndexes()[7].getLastArchiveId() + 1; + if (cache.getIndexes()[7].putFile(archiveId, 0, data)) { + return archiveId; + } else { + System.out.println("Failed packing model " + archiveId); + return -1; + } + } + + public static int packCustomModel(Store cache, byte[] data, int modelId) { + if (cache.getIndexes()[7].putFile(modelId, 0, data)) { + return modelId; + } else { + System.out.println("Failed packing model " + modelId); + return -1; + } + } +} diff --git a/src/com/editor/item/ItemEditor.java b/src/com/editor/item/ItemEditor.java new file mode 100644 index 0000000..052af85 --- /dev/null +++ b/src/com/editor/item/ItemEditor.java @@ -0,0 +1,1410 @@ +package com.editor.item; + +import com.alex.loaders.items.ItemDefinitions; +import com.editor.Main; +import com.editor.Utils; +import com.editor.util.SpringUtilities; + +import javax.swing.*; +import javax.swing.GroupLayout.Alignment; +import javax.swing.LayoutStyle.ComponentPlacement; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Iterator; + +public class ItemEditor extends JFrame { + private static final long serialVersionUID = -3870086097297420720L; + private final ItemDefinitions defs; + private final ItemSelection is; + private JTextField xOffset2dField; + private JTextField yan2dField; + private JMenuItem addModelMenuBtn; + private JTextField array1; + private JTextField array2; + private JTextField array3; + private JTextField array4; + private JTextField array5; + private JTextField array6; + private JTextArea clientScriptOutput; + private JTextField csk1; + private JTextField csk2; + private JTextField csk3; + private JTextField csk4; + private JTextField csk5; + private JTextField csk6; + private JTextField csk7; + private JTextField csv1; + private JTextField csv2; + private JTextField csv3; + private JTextField csv4; + private JTextField csv5; + private JTextField csv6; + private JTextField csv7; + private JLabel currentViewLabel; + private JTextField equipSlot; + private JTextField equipType; + private JMenuItem exitMenuBtn; + private JMenuItem exportMenuBtn; + private JTextField femaleEquip1Field; + private JTextField femaleEquip2Field; + private JTextField femaleEquip3Field; + private JTextField groundOptions; + private JTextField maleDialogueHeadPrimaryField; + private JTextField ambienceTextField; + private JTextField diffusionTextField; + private JTextField mWieldXTextField; + private JTextField mWieldYTextField; + private JTextField mWieldZTextField; + private JTextField fWieldXTextField; + private JTextField fWieldYTextField; + private JTextField fWieldZTextField; + private JTextField int18; + private JTextField int19; + private JTextField femaleDialogueHeadPrimaryField; + private JTextField int20; + private JTextField int21; + private JTextField int22; + private JTextField int23; + private JTextField maleDialogueHeadAccessoryField; + private JTextField femaleDialogueHeadAccessoryField; + private JTextField zan2dField; + private JTextField int6; + private JTextField fScaleXTextField; + private JTextField fScaleYTextField; + private JTextField fScaleZTextField; + private JTextField inventoryModelField; + private JTextField Zoom2dField; + private JTextField invOptions; + private JTextField itemName; + private JLabel jLabel1; + private JLabel maleEquip1Label; + private JLabel femaleEquip1Label; + private JLabel maleEquip2Label; + private JLabel femaleEquip2Label; + private JLabel maleEquip3Label; + private JLabel femaleEquip3Label; + private JLabel jLabel16; + private JLabel jLabel17; + private JLabel jLabel18; + private JLabel jLabel19; + private JLabel jLabel2; + private JLabel jLabel20; + private JLabel jLabel21; + private JLabel jLabel22; + private JLabel jLabel23; + private JLabel jLabel24; + private JLabel jLabel25; + private JLabel jLabel26; + private JLabel jLabel27; + private JLabel jLabel28; + private JLabel jLabel29; + private JLabel jLabel3; + private JLabel jLabel30; + private JLabel jLabel31; + private JLabel maleDialogueHeadPrimaryLabel; + private JLabel femaleDialogueHeadPrimaryLabel; + private JLabel maleDialogueHeadAccessoryLabel; + private JLabel femaleDialogueHeadAccessoryLabel; + private JLabel zan2dLabel; + private JLabel jLabel37; + private JLabel jLabel38; + private JLabel jLabel39; + private JLabel Zoom2dLabel; + private JLabel jLabel40; + private JLabel jLabel41; + private JLabel jLabel42; + private JLabel maleWieldXLabel; + private JLabel maleWieldYLabel; + private JLabel maleWieldZLabel; + private JLabel fWieldXLabel; + private JLabel fWieldYLabel; + private JLabel fWieldZLabel; + private JLabel jLabel49; + private JLabel xan2dLabel; + private JLabel jLabel50; + private JLabel jLabel51; + private JLabel jLabel52; + private JLabel jLabel53; + private JLabel jLabel54; + private JLabel jLabel55; + private JLabel jLabel56; + private JLabel jLabel57; + private JLabel jLabel58; + private JLabel jLabel59; + private JLabel yan2dLabel; + private JLabel jLabel60; + private JLabel jLabel61; + private JLabel xOffset2dLabel; + private JLabel yOffset2dLabel; + private JLabel inventoryModelLabel; + private JMenu jMenu1; + private JMenuBar jMenuBar1; + private JPanel jPanel1; + private JPanel jPanel2; + private JPanel helperPanel2; + private JPanel helperPanel3; + private JPanel jPanel8; + private JPanel helperPanel8; + private JPanel helperPanel9; + private JPanel helperPanel10; + private JPanel helperPanel11; + private JPanel jPanel3; + private JPanel jPanel5; + private JPanel jPanel6; + private JPanel jPanel7; + private JScrollPane jScrollPane1; + private JTabbedPane jTabbedPane1; + private JTextField lend; + private JTextField maleEquip1Field; + private JTextField maleEquip2Field; + private JTextField maleEquip3Field; + private JCheckBox membersOnly; + private JTextField modelColors; + private JTextField yOffset2dField; + private JTextField xan2dField; + private JTextField note; + private JMenuItem reloadMenuBtn; + private JMenuItem saveMenuBtn; + private JTextField stackAmts; + private JTextField stackIDs; + private JCheckBox stackable; + public JTextField switchLend; + public JTextField switchNote; + public JTextField teamId; + public JTextField textureColors; + public JCheckBox unnoted; + public JTextField value; + + public ItemEditor(ItemSelection is, ItemDefinitions defs) { + this.defs = defs; + this.is = is; + this.setIconImage(Main.iconImage); + this.initComponents(); + this.setResizable(false); + this.setTitle("Item Editor"); + this.setDefaultCloseOperation(1); + this.setLocationRelativeTo(null); + this.setVisible(true); + } + + private void initComponents() { + this.jTabbedPane1 = new JTabbedPane(); + this.jPanel1 = new JPanel(); + this.jLabel1 = new JLabel(); + this.itemName = new JTextField(); + this.jLabel2 = new JLabel(); + this.value = new JTextField(); + this.teamId = new JTextField(); + this.jLabel3 = new JLabel(); + this.membersOnly = new JCheckBox(); + this.jLabel20 = new JLabel(); + this.equipSlot = new JTextField(); + this.jLabel21 = new JLabel(); + this.equipType = new JTextField(); + this.jLabel22 = new JLabel(); + this.stackIDs = new JTextField(); + this.jLabel23 = new JLabel(); + this.stackAmts = new JTextField(); + this.jLabel24 = new JLabel(); + this.stackable = new JCheckBox(); + this.jLabel58 = new JLabel(); + this.switchNote = new JTextField(); + this.jLabel59 = new JLabel(); + this.note = new JTextField(); + this.unnoted = new JCheckBox(); + this.jLabel60 = new JLabel(); + this.jLabel61 = new JLabel(); + this.switchLend = new JTextField(); + this.lend = new JTextField(); + this.jPanel2 = new JPanel(); + this.helperPanel2 = new JPanel(); + this.helperPanel3 = new JPanel(); + this.jPanel8 = new JPanel(); + this.helperPanel8 = new JPanel(); + this.helperPanel9 = new JPanel(); + this.helperPanel10 = new JPanel(); + this.helperPanel11 = new JPanel(); + this.Zoom2dLabel = new JLabel("Zoom2d", JLabel.TRAILING); + this.Zoom2dField = new JTextField(10); + this.xan2dLabel = new JLabel("xAngle2d", JLabel.TRAILING); + this.xan2dField = new JTextField(10); + this.yan2dLabel = new JLabel("yAngle2d", JLabel.TRAILING); + this.yan2dField = new JTextField(10); + this.zan2dLabel = new JLabel("zAngle2d", JLabel.TRAILING); + this.zan2dField = new JTextField(10); + this.xOffset2dLabel = new JLabel("xOffset2d", JLabel.TRAILING); + this.xOffset2dField = new JTextField(10); + this.yOffset2dLabel = new JLabel("yOffset2d", JLabel.TRAILING); + this.yOffset2dField = new JTextField(10); + this.inventoryModelLabel = new JLabel(); + this.inventoryModelField = new JTextField(); + this.maleDialogueHeadPrimaryLabel = new JLabel("Male Dialogue Head", JLabel.TRAILING); + this.maleDialogueHeadPrimaryField = new JTextField(10); + this.maleDialogueHeadAccessoryLabel = new JLabel("Male Dialogue Head Accessory", JLabel.TRAILING); + this.maleDialogueHeadAccessoryField = new JTextField(10); + this.maleEquip1Label = new JLabel("Male Equip Primary", JLabel.TRAILING); + this.maleEquip1Field = new JTextField(10); + this.maleEquip2Label = new JLabel("Male Equip Secondary", JLabel.TRAILING); + this.maleEquip2Field = new JTextField(10); + this.maleEquip3Label = new JLabel("Male Equip Tertiary", JLabel.TRAILING); + this.maleEquip3Field = new JTextField(10); + this.femaleDialogueHeadPrimaryLabel = new JLabel("Female Dialogue Head", JLabel.TRAILING); + this.femaleDialogueHeadPrimaryField = new JTextField(10); + this.femaleDialogueHeadAccessoryLabel = new JLabel("Female Dialogue Head Accessory", JLabel.TRAILING); + this.femaleDialogueHeadAccessoryField = new JTextField(10); + this.femaleEquip1Label = new JLabel("Female Equip Primary", JLabel.TRAILING); + this.femaleEquip1Field = new JTextField(10); + this.femaleEquip2Label = new JLabel("Female Equip Secondary", JLabel.TRAILING); + this.femaleEquip2Field = new JTextField(10); + this.femaleEquip3Label = new JLabel("Female Equip Tertiary", JLabel.TRAILING); + this.femaleEquip3Field = new JTextField(10); + this.jPanel3 = new JPanel(); + this.jLabel16 = new JLabel(); + this.invOptions = new JTextField(); + this.jLabel17 = new JLabel(); + this.groundOptions = new JTextField(); + this.jLabel18 = new JLabel(); + this.modelColors = new JTextField(); + this.jLabel19 = new JLabel(); + this.textureColors = new JTextField(); + this.jPanel5 = new JPanel(); + this.jLabel25 = new JLabel(); + this.array1 = new JTextField(); + this.jLabel27 = new JLabel(); + this.jLabel28 = new JLabel(); + this.jLabel29 = new JLabel(); + this.jLabel30 = new JLabel(); + this.jLabel31 = new JLabel(); + this.array2 = new JTextField(); + this.array3 = new JTextField(); + this.array4 = new JTextField(); + this.array5 = new JTextField(); + this.array6 = new JTextField(); + this.jLabel37 = new JLabel(); + this.int6 = new JTextField(); + this.jLabel38 = new JLabel(); + this.fScaleXTextField = new JTextField(); + this.jLabel39 = new JLabel(); + this.fScaleYTextField = new JTextField(); + this.jLabel40 = new JLabel(); + this.fScaleZTextField = new JTextField(); + this.jLabel41 = new JLabel(); + this.ambienceTextField = new JTextField(); + this.jLabel42 = new JLabel(); + this.diffusionTextField = new JTextField(); + this.maleWieldXLabel = new JLabel(); + this.mWieldXTextField = new JTextField(); + this.maleWieldYLabel = new JLabel(); + this.mWieldYTextField = new JTextField(); + this.maleWieldZLabel = new JLabel(); + this.mWieldZTextField = new JTextField(); + this.jPanel6 = new JPanel(); + this.fWieldXLabel = new JLabel(); + this.fWieldXTextField = new JTextField(); + this.fWieldYLabel = new JLabel(); + this.fWieldYTextField = new JTextField(); + this.fWieldZLabel = new JLabel(); + this.fWieldZTextField = new JTextField(); + this.jLabel49 = new JLabel(); + this.int18 = new JTextField(); + this.jLabel50 = new JLabel(); + this.int19 = new JTextField(); + this.jLabel51 = new JLabel(); + this.int20 = new JTextField(); + this.jLabel52 = new JLabel(); + this.int21 = new JTextField(); + this.jLabel53 = new JLabel(); + this.int22 = new JTextField(); + this.jLabel54 = new JLabel(); + this.int23 = new JTextField(); + this.jPanel7 = new JPanel(); + this.jScrollPane1 = new JScrollPane(); + this.clientScriptOutput = new JTextArea(); + this.jLabel26 = new JLabel(); + this.jLabel55 = new JLabel(); + this.jLabel56 = new JLabel(); + this.jLabel57 = new JLabel(); + this.csk1 = new JTextField(); + this.csk2 = new JTextField(); + this.csk3 = new JTextField(); + this.csk4 = new JTextField(); + this.csk5 = new JTextField(); + this.csk6 = new JTextField(); + this.csk7 = new JTextField(); + this.csv1 = new JTextField(); + this.csv2 = new JTextField(); + this.csv3 = new JTextField(); + this.csv4 = new JTextField(); + this.csv5 = new JTextField(); + this.csv6 = new JTextField(); + this.csv7 = new JTextField(); + this.currentViewLabel = new JLabel(); + this.jMenuBar1 = new JMenuBar(); + this.jMenu1 = new JMenu(); + this.reloadMenuBtn = new JMenuItem(); + this.saveMenuBtn = new JMenuItem(); + this.addModelMenuBtn = new JMenuItem(); + this.exportMenuBtn = new JMenuItem(); + this.exitMenuBtn = new JMenuItem(); + this.setDefaultCloseOperation(3); + this.jLabel1.setText("Name"); + this.itemName.setText(this.defs.getName()); + this.jLabel2.setText("Value"); + this.value.setText("" + this.defs.getCost()); + this.teamId.setText("" + this.defs.getTeamId()); + this.jLabel3.setText("Team"); + this.membersOnly.setSelected(this.defs.isMembersOnly()); + this.membersOnly.setText("Members Only"); + this.jLabel20.setText("Equip Slot"); + this.equipSlot.setText("" + this.defs.getEquipSlot()); + this.jLabel21.setText("Equip Type"); + this.equipType.setText("" + this.defs.getEquipType()); + this.jLabel22.setText("Stack IDs"); + this.stackIDs.setText(this.getStackIDs()); + this.jLabel23.setText("Stack Amounts"); + this.stackAmts.setText(this.getStackAmts()); + this.jLabel24.setText("Stackable"); + this.stackable.setSelected(this.defs.getStackable() == 1); + this.jLabel58.setText("Switch Note Item ID"); + this.switchNote.setText("" + this.defs.switchNoteItemId); + this.jLabel59.setText("Noted Item ID"); + this.note.setText("" + this.defs.notedItemId); + this.unnoted.setSelected(this.defs.isUnnoted()); + this.unnoted.setText("Unnoted"); + this.jLabel60.setText("Switch Lend Item ID"); + this.jLabel61.setText("Lent Item ID"); + this.switchLend.setText("" + this.defs.getSwitchLendItemId()); + this.lend.setText("" + this.defs.getLendedItemId()); + GroupLayout jPanel1Layout = new GroupLayout(this.jPanel1); + this.jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addComponent(this.unnoted).addComponent(this.membersOnly).addGroup(jPanel1Layout.createSequentialGroup().addComponent(this.jLabel20).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(this.equipSlot, -2, 100, -2)).addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addComponent(this.jLabel1).addGap(18, 18, 18).addComponent(this.itemName, -2, 100, -2)).addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addComponent(this.jLabel2).addComponent(this.jLabel3)).addGap(18, 18, 18).addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addComponent(this.teamId, -2, 100, -2).addComponent(this.value, -2, 100, -2))).addGroup(jPanel1Layout.createSequentialGroup().addComponent(this.jLabel24).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.stackable, -2, 100, -2))).addGap(126, 126, 126).addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addComponent(this.stackAmts, -2, 300, -2).addComponent(this.stackIDs, -2, 300, -2).addComponent(this.jLabel22).addComponent(this.jLabel23))).addGroup(jPanel1Layout.createSequentialGroup().addComponent(this.jLabel21).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.equipType, -2, 100, -2)).addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addComponent(this.jLabel58).addComponent(this.jLabel59)).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING, false).addComponent(this.switchNote, -1, 100, 32767).addComponent(this.note)).addGap(18, 18, 18).addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addComponent(this.jLabel60).addComponent(this.jLabel61)).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING, false).addComponent(this.switchLend, -1, 100, 32767).addComponent(this.lend)))).addContainerGap(36, 32767))); + jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel1).addComponent(this.itemName, -2, -1, -2).addComponent(this.jLabel22)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.value, -2, -1, -2).addComponent(this.jLabel2)).addComponent(this.stackIDs, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.teamId, -2, -1, -2).addComponent(this.jLabel3).addComponent(this.jLabel23)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addComponent(this.stackAmts, -2, -1, -2).addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel24).addComponent(this.stackable, -2, -1, -2))).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.membersOnly).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel20).addComponent(this.equipSlot, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel21).addComponent(this.equipType, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel58).addComponent(this.switchNote, -2, -1, -2).addComponent(this.jLabel60).addComponent(this.switchLend, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel59).addComponent(this.note, -2, -1, -2).addComponent(this.jLabel61).addComponent(this.lend, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.unnoted).addContainerGap(13, 32767))); + this.jTabbedPane1.addTab("General", this.jPanel1); + this.Zoom2dLabel.setText("Zoom2d"); + this.Zoom2dField.setText("" + this.defs.getInvModelZoom()); + this.xan2dLabel.setText("xAngle2d"); + this.xan2dField.setText("" + this.defs.getXan2d()); + this.yan2dLabel.setText("yAngle2d"); + this.yan2dField.setText("" + this.defs.getYan2d()); + this.zan2dLabel.setText("zAngle2d"); + this.zan2dField.setText("" + this.defs.Zan2d); + this.xOffset2dLabel.setText("xOffset2d"); + this.xOffset2dField.setText("" + this.defs.getxOffset2d()); + this.yOffset2dLabel.setText("yOffset2d"); + this.yOffset2dField.setText("" + this.defs.getyOffset2d()); + this.inventoryModelLabel.setText("Inventory Model"); + this.inventoryModelField.setText("" + this.defs.getInvModelId()); + this.maleDialogueHeadPrimaryLabel.setText("Male Dialogue Head"); + this.maleDialogueHeadPrimaryField.setText("" + this.defs.primaryMaleDialogueHead); + this.maleDialogueHeadAccessoryLabel.setText("Male Dialogue Head Accessory"); + this.maleDialogueHeadAccessoryField.setText("" + this.defs.secondaryMaleDialogueHead); + this.maleEquip1Label.setText("Male Equip 1"); + this.maleEquip1Field.setText("" + this.defs.getMaleEquipModelId1()); + this.maleEquip2Label.setText("Male Equip 2"); + this.maleEquip2Field.setText("" + this.defs.getMaleEquipModelId2()); + this.maleEquip3Label.setText("Male Equip 3"); + this.maleEquip3Field.setText("" + this.defs.getMaleEquipModelId3()); + this.femaleDialogueHeadPrimaryLabel.setText("Female Dialogue Head"); + this.femaleDialogueHeadPrimaryField.setText("" + this.defs.primaryFemaleDialogueHead); + this.femaleDialogueHeadAccessoryLabel.setText("Female Dialogue Head Accessory"); + this.femaleDialogueHeadAccessoryField.setText("" + this.defs.secondaryFemaleDialogueHead); + this.femaleEquip1Label.setText("Female Equip 1"); + this.femaleEquip1Field.setText("" + this.defs.getFemaleEquipModelId1()); + this.femaleEquip2Label.setText("Female Equip 2"); + this.femaleEquip2Field.setText("" + this.defs.getFemaleEquipModelId2()); + this.femaleEquip3Label.setText("Female Equip 3"); + this.femaleEquip3Field.setText("" + this.defs.getFemaleEquipModelId3()); + + + this.jPanel2.setLayout(new BorderLayout()); + this.jPanel2.setPreferredSize(new Dimension(300, 300)); + this.helperPanel3.setPreferredSize(new Dimension(300, 300)); + SpringLayout experimentLayout = new SpringLayout(); + this.helperPanel2.setPreferredSize(new Dimension(300, 300)); + this.helperPanel2.setLayout(experimentLayout); + this.helperPanel2.add(this.Zoom2dLabel); + this.Zoom2dLabel.setLabelFor(this.Zoom2dField); + this.helperPanel2.add(this.Zoom2dField);// + + this.helperPanel2.add(this.xan2dLabel); + this.xan2dLabel.setLabelFor(this.xan2dField); + this.helperPanel2.add(this.xan2dField);// + + this.helperPanel2.add(this.yan2dLabel); + this.yan2dLabel.setLabelFor(this.yan2dField); + this.helperPanel2.add(this.yan2dField);// + + this.helperPanel2.add(this.zan2dLabel); + this.zan2dLabel.setLabelFor(this.zan2dField); + this.helperPanel2.add(this.zan2dField);// + + this.helperPanel2.add(this.xOffset2dLabel); + this.xOffset2dLabel.setLabelFor(this.xOffset2dField); + this.helperPanel2.add(this.xOffset2dField);// + + this.helperPanel2.add(this.yOffset2dLabel); + this.yOffset2dLabel.setLabelFor(this.yOffset2dField); + this.helperPanel2.add(this.yOffset2dField);// + + SpringUtilities.makeCompactGrid(this.helperPanel2, + 6, 2, //rows, cols + 12, 12, //initX, initY + 24, 24); //xPad, yPad + + this.helperPanel2.setOpaque(true); + this.jPanel2.add(this.helperPanel3, BorderLayout.CENTER); + this.jPanel2.add(this.helperPanel2, BorderLayout.LINE_START); + + + this.jPanel8.setLayout(new BorderLayout()); + //this.jPanel8.setPreferredSize(new Dimension(300, 300)); + + // !-- THIS GETS ADDED TO PAGE_START --! + this.helperPanel10.setPreferredSize(new Dimension(700, 30)); + this.helperPanel10.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + + c.fill = GridBagConstraints.HORIZONTAL; + c.ipadx = 0; //reset to default + c.ipady = 10; //reset to default + c.weightx = 0.0; + c.weighty = 0.0; + c.gridwidth = 10; + c.anchor = GridBagConstraints.LAST_LINE_START; //bottom of space + c.insets = new Insets(15, 98, 30, 0); //top padding + c.gridx = 8; //aligned with button 2 + c.gridy = 5; //third row + this.helperPanel10.add(this.inventoryModelLabel, c); + this.inventoryModelLabel.setLabelFor(this.inventoryModelField); + c.ipadx = 0; //reset to default + c.ipady = 10; //reset to default + c.weightx = 1.0; + c.weighty = 0.0; + c.gridheight = 30; + c.gridwidth = 30; + c.anchor = GridBagConstraints.PAGE_END; //bottom of space + c.insets = new Insets(15, 210, 30, 388); //top padding + c.gridx = 8; //aligned with button 2 + c.gridy = 5; //third row + this.helperPanel10.add(this.inventoryModelField, c); + + + // !-- THIS GETS ADDED TO CENTER --! + // MALE MODEL EDITS + SpringLayout experiment2Layout = new SpringLayout(); + //this.helperPanel8.setPreferredSize(new Dimension(300, 300)); + this.helperPanel8.setLayout(experiment2Layout); + + this.helperPanel8.add(this.maleDialogueHeadPrimaryLabel); + this.maleDialogueHeadPrimaryLabel.setLabelFor(this.maleDialogueHeadPrimaryField); + this.helperPanel8.add(this.maleDialogueHeadPrimaryField);// + + this.helperPanel8.add(this.maleDialogueHeadAccessoryLabel); + this.maleDialogueHeadAccessoryLabel.setLabelFor(this.maleDialogueHeadAccessoryField); + this.helperPanel8.add(this.maleDialogueHeadAccessoryField);// + + this.helperPanel8.add(this.maleEquip1Label); + this.maleEquip1Label.setLabelFor(this.maleEquip1Field); + this.helperPanel8.add(this.maleEquip1Field);// + + this.helperPanel8.add(this.maleEquip2Label); + this.maleEquip2Label.setLabelFor(this.maleEquip2Field); + this.helperPanel8.add(this.maleEquip2Field);// + + this.helperPanel8.add(this.maleEquip3Label); + this.maleEquip3Label.setLabelFor(this.maleEquip3Field); + this.helperPanel8.add(this.maleEquip3Field);// + + SpringUtilities.makeCompactGrid(this.helperPanel8, 5, 2, //rows, cols + 12, 12, //initX, initY + 24, 24); //xPad, yPad + + // !-- THIS GETS ADDED TO CENTER --! + // FEMALE MODEL EDITS + SpringLayout experiment3Layout = new SpringLayout(); + //this.helperPanel9.setPreferredSize(new Dimension(300, 300)); + this.helperPanel9.setLayout(experiment3Layout); + + this.helperPanel9.add(this.femaleDialogueHeadPrimaryLabel); + this.femaleDialogueHeadPrimaryLabel.setLabelFor(this.femaleDialogueHeadPrimaryField); + this.helperPanel9.add(this.femaleDialogueHeadPrimaryField);// + + this.helperPanel9.add(this.femaleDialogueHeadAccessoryLabel); + this.femaleDialogueHeadAccessoryLabel.setLabelFor(this.femaleDialogueHeadAccessoryField); + this.helperPanel9.add(this.femaleDialogueHeadAccessoryField);// + + this.helperPanel9.add(this.femaleEquip1Label); + this.femaleEquip1Label.setLabelFor(this.femaleEquip1Field); + this.helperPanel9.add(this.femaleEquip1Field);// + + this.helperPanel9.add(this.femaleEquip2Label); + this.femaleEquip2Label.setLabelFor(this.femaleEquip2Field); + this.helperPanel9.add(this.femaleEquip2Field);// + + this.helperPanel9.add(this.femaleEquip3Label); + this.femaleEquip3Label.setLabelFor(this.femaleEquip3Field); + this.helperPanel9.add(this.femaleEquip3Field);// + + SpringUtilities.makeCompactGrid(this.helperPanel9, 5, 2, //rows, cols + 12, 12, //initX, initY + 24, 24); //xPad, yPad + + + this.helperPanel8.setOpaque(true); + this.helperPanel9.setOpaque(true); + + this.helperPanel11.setLayout(new GridLayout(1, 0)); + this.helperPanel11.add(helperPanel8); + this.helperPanel11.add(helperPanel9); + this.jPanel8.add(this.helperPanel10, BorderLayout.PAGE_START); + this.jPanel8.add(this.helperPanel11, BorderLayout.CENTER); + this.jTabbedPane1.addTab("Item Sprite", this.jPanel2); + this.jTabbedPane1.addTab("Models", this.jPanel8); + this.jLabel16.setText("Inventory Options"); + this.invOptions.setText(this.getInventoryOpts()); + this.jLabel17.setText("Ground Options"); + this.groundOptions.setText(this.getGroundOpts()); + this.jLabel18.setText("Model Colors"); + this.modelColors.setText(this.getChangedModelColors()); + this.jLabel19.setText("Texture Colors"); + this.textureColors.setText(this.getChangedTextureColors()); + GroupLayout jPanel3Layout = new GroupLayout(this.jPanel3); + this.jPanel3.setLayout(jPanel3Layout); + jPanel3Layout.setHorizontalGroup(jPanel3Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout.createParallelGroup(Alignment.LEADING).addComponent(this.jLabel16).addComponent(this.invOptions, -2, 300, -2).addComponent(this.jLabel17).addComponent(this.groundOptions, -2, 300, -2).addComponent(this.jLabel18).addComponent(this.modelColors, -2, 300, -2).addComponent(this.jLabel19).addComponent(this.textureColors, -2, 300, -2)).addContainerGap(312, 32767))); + jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addComponent(this.jLabel16).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.invOptions, -2, -1, -2).addGap(18, 18, 18).addComponent(this.jLabel17).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.groundOptions, -2, -1, -2).addGap(18, 18, 18).addComponent(this.jLabel18).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.modelColors, -2, -1, -2).addGap(18, 18, 18).addComponent(this.jLabel19).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.textureColors, -2, -1, -2).addContainerGap(47, 32767))); + this.jTabbedPane1.addTab("Options", this.jPanel3); + this.jLabel25.setText("unknownArray1"); + this.array1.setText(this.getUnknownArray1()); + this.jLabel27.setText("unknownArray2"); + this.jLabel28.setText("unknownArray3"); + this.jLabel29.setText("unknownArray4"); + this.jLabel30.setText("unknownArray5"); + this.jLabel31.setText("unknownArray6"); + this.array2.setText(this.getUnknownArray2()); + this.array3.setText(this.getUnknownArray3()); + this.array4.setText(this.getUnknownArray4()); + this.array5.setText(this.getUnknownArray5()); + this.array6.setText(this.getUnknownArray6()); + + this.jLabel37.setText("unknownInt6"); + this.int6.setText("" + this.defs.dummyItem); + this.jLabel38.setText("Floor Scale X"); + this.fScaleXTextField.setText("" + this.defs.floorScaleX); + this.jLabel39.setText("Floor Scale Y"); + this.fScaleYTextField.setText("" + this.defs.floorScaleY); + this.jLabel40.setText("Floor Scale Z"); + this.fScaleZTextField.setText("" + this.defs.floorScaleZ); + this.jLabel41.setText("Ambience"); + this.ambienceTextField.setText("" + this.defs.ambience); + this.jLabel42.setText("Diffusion"); + this.diffusionTextField.setText("" + this.defs.diffusion); + this.maleWieldXLabel.setText("Male Wield X"); + this.mWieldXTextField.setText("" + this.defs.maleWieldX); + this.maleWieldYLabel.setText("Male Wield Y"); + this.mWieldYTextField.setText("" + this.defs.maleWieldY); + this.maleWieldZLabel.setText("Male Wield Z"); + this.mWieldZTextField.setText("" + this.defs.maleWieldZ); + this.fWieldXLabel.setText("Female Wield X"); + this.fWieldXTextField.setText("" + this.defs.femaleWieldX); + this.fWieldYLabel.setText("Female Wield Y"); + this.fWieldYTextField.setText("" + this.defs.femaleWieldY); + this.fWieldZLabel.setText("Female Wield Z"); + this.fWieldZTextField.setText("" + this.defs.femaleWieldZ); + + GroupLayout jPanel5Layout = new GroupLayout(this.jPanel5); + this.jPanel5.setLayout(jPanel5Layout); + jPanel5Layout.setHorizontalGroup(jPanel5Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel5Layout.createSequentialGroup().addContainerGap().addGroup(jPanel5Layout.createParallelGroup(Alignment.LEADING, false).addGroup(jPanel5Layout.createSequentialGroup().addGroup(jPanel5Layout.createParallelGroup(Alignment.LEADING).addComponent(this.fWieldZLabel)).addGap(18, 18, 18).addGroup(jPanel5Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel5Layout.createSequentialGroup().addComponent(this.fWieldZTextField, -2, 200, -2).addPreferredGap(ComponentPlacement.RELATED, -1, 32767).addComponent(this.jLabel41).addGap(18, 18, 18).addComponent(this.ambienceTextField, -2, 100, -2)).addGroup(jPanel5Layout.createSequentialGroup().addComponent(this.jLabel42).addGap(18, 18, 18).addComponent(this.diffusionTextField, -2, 100, -2)))).addGroup(jPanel5Layout.createSequentialGroup().addComponent(this.fWieldYLabel).addGap(18, 18, 18).addComponent(this.fWieldYTextField, -2, 200, -2).addPreferredGap(ComponentPlacement.RELATED, -1, 32767).addComponent(this.jLabel40).addGap(18, 18, 18).addComponent(this.fScaleZTextField, -2, 100, -2)).addGroup(jPanel5Layout.createSequentialGroup().addComponent(this.fWieldXLabel).addGap(18, 18, 18).addComponent(this.fWieldXTextField, -2, 200, -2).addPreferredGap(ComponentPlacement.RELATED, -1, 32767).addComponent(this.jLabel39).addGap(18, 18, 18).addComponent(this.fScaleYTextField, -2, 100, -2)).addGroup(jPanel5Layout.createSequentialGroup().addComponent(this.maleWieldZLabel).addGap(18, 18, 18).addComponent(this.mWieldZTextField, -2, 200, -2).addPreferredGap(ComponentPlacement.RELATED, -1, 32767).addComponent(this.jLabel38).addGap(18, 18, 18).addComponent(this.fScaleXTextField, -2, 100, -2)).addGroup(jPanel5Layout.createSequentialGroup().addComponent(this.maleWieldYLabel).addGap(18, 18, 18).addComponent(this.mWieldYTextField, -2, 200, -2).addPreferredGap(ComponentPlacement.RELATED, -1, 32767).addComponent(this.jLabel37).addGap(18, 18, 18).addComponent(this.int6, -2, 100, -2)).addGroup(jPanel5Layout.createSequentialGroup().addComponent(this.maleWieldXLabel).addGap(18, 18, 18).addComponent(this.mWieldXTextField, -2, 200, -2).addGap(73, 73, 73))).addContainerGap(64, 32767))); + jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel5Layout.createSequentialGroup().addContainerGap().addGroup(jPanel5Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.maleWieldXLabel).addComponent(this.mWieldXTextField, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel5Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.maleWieldYLabel).addComponent(this.mWieldYTextField, -2, -1, -2).addComponent(this.jLabel37).addComponent(this.int6, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel5Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.maleWieldZLabel).addComponent(this.mWieldZTextField, -2, -1, -2).addComponent(this.jLabel38).addComponent(this.fScaleXTextField, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel5Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.fWieldXLabel).addComponent(this.fWieldXTextField, -2, -1, -2).addComponent(this.jLabel39).addComponent(this.fScaleYTextField, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel5Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.fWieldYLabel).addComponent(this.fWieldYTextField, -2, -1, -2).addComponent(this.jLabel40).addComponent(this.fScaleZTextField, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel5Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.fWieldZLabel).addComponent(this.fWieldZTextField, -2, -1, -2).addComponent(this.jLabel41).addComponent(this.ambienceTextField, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel5Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel42).addComponent(this.diffusionTextField, -2, -1, -2)).addContainerGap(-1, 32767))); + + this.jTabbedPane1.addTab("Offsets/Scale", this.jPanel5); + this.jLabel49.setText("unknownInt18"); + this.int18.setText("" + this.defs.unknownInt18); + this.jLabel50.setText("unknownInt19"); + this.int19.setText("" + this.defs.unknownInt19); + this.jLabel51.setText("unknownInt20"); + this.int20.setText("" + this.defs.unknownInt20); + this.jLabel52.setText("unknownInt21"); + this.int21.setText("" + this.defs.unknownInt21); + this.jLabel53.setText("unknownInt22"); + this.int22.setText("" + this.defs.unknownInt22); + this.jLabel54.setText("unknownInt23"); + this.int23.setText("" + this.defs.unknownInt23); + this.clientScriptOutput.setColumns(20); + this.clientScriptOutput.setRows(5); + this.clientScriptOutput.setText(this.getClientScripts()); + this.jScrollPane1.setViewportView(this.clientScriptOutput); + this.jLabel26.setText("KEY"); + this.jLabel55.setText("VALUE"); + this.jLabel56.setText("Add the keys to the left to the boxes to edit them."); + this.jLabel57.setText("Add new keys in the boxes to give the item new clientscripts."); + GroupLayout jPanel7Layout = new GroupLayout(this.jPanel7); + this.jPanel7.setLayout(jPanel7Layout); + jPanel7Layout.setHorizontalGroup(jPanel7Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel7Layout.createSequentialGroup().addContainerGap().addComponent(this.jScrollPane1, -2, 305, -2).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel7Layout.createParallelGroup(Alignment.LEADING).addComponent(this.jLabel57).addGroup(jPanel7Layout.createParallelGroup(Alignment.TRAILING).addGroup(jPanel7Layout.createSequentialGroup().addGroup(jPanel7Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel7Layout.createParallelGroup(Alignment.TRAILING).addComponent(this.csk2, -2, 75, -2).addComponent(this.csk1, -2, 75, -2).addComponent(this.csk3, -2, 75, -2).addComponent(this.csk4, -2, 75, -2).addComponent(this.csk5, -2, 75, -2).addComponent(this.csk6, -2, 75, -2).addComponent(this.csk7, -2, 75, -2)).addComponent(this.jLabel26)).addGap(58, 58, 58).addGroup(jPanel7Layout.createParallelGroup(Alignment.LEADING).addComponent(this.csv1, -2, 75, -2).addComponent(this.csv2, -2, 75, -2).addComponent(this.csv3, -2, 75, -2).addComponent(this.csv4, -2, 75, -2).addComponent(this.csv5, -2, 75, -2).addComponent(this.csv6, -2, 75, -2).addComponent(this.csv7, -2, 75, -2).addComponent(this.jLabel55))).addComponent(this.jLabel56))).addContainerGap(-1, 32767))); + jPanel7Layout.setVerticalGroup(jPanel7Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel7Layout.createSequentialGroup().addContainerGap().addGroup(jPanel7Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel7Layout.createSequentialGroup().addGroup(jPanel7Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel26).addComponent(this.jLabel55)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel7Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.csk1, -2, -1, -2).addComponent(this.csv1, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel7Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.csk2, -2, -1, -2).addComponent(this.csv2, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel7Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.csk3, -2, -1, -2).addComponent(this.csv3, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel7Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.csk4, -2, -1, -2).addComponent(this.csv4, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel7Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.csk5, -2, -1, -2).addComponent(this.csv5, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel7Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.csk6, -2, -1, -2).addComponent(this.csv6, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel7Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.csk7, -2, -1, -2).addComponent(this.csv7, -2, -1, -2)).addPreferredGap(ComponentPlacement.RELATED, 20, 32767).addComponent(this.jLabel56).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.jLabel57)).addComponent(this.jScrollPane1)).addContainerGap())); + this.jTabbedPane1.addTab("Clientscripts", this.jPanel7); + this.currentViewLabel.setText("Currently Viewing Definitions of Item: " + this.defs.getId() + " - " + this.defs.getName()); + this.jMenu1.setText("File"); + this.reloadMenuBtn.setText("Reload"); + this.reloadMenuBtn.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + ItemEditor.this.reloadMenuBtnActionPerformed(evt); + } + }); + this.jMenu1.add(this.reloadMenuBtn); + this.saveMenuBtn.setText("Save"); + this.saveMenuBtn.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + ItemEditor.this.saveMenuBtnActionPerformed(evt); + } + }); + this.jMenu1.add(this.saveMenuBtn); + this.addModelMenuBtn.setText("Add Model"); + this.addModelMenuBtn.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + ItemEditor.this.addModelMenuBtnActionPerformed(evt); + } + }); + this.jMenu1.add(this.addModelMenuBtn); + this.exportMenuBtn.setText("Export to .txt"); + this.exportMenuBtn.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + ItemEditor.this.exportMenuBtnActionPerformed(evt); + } + }); + this.jMenu1.add(this.exportMenuBtn); + this.exitMenuBtn.setText("Exit"); + this.exitMenuBtn.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + ItemEditor.this.exitMenuBtnActionPerformed(evt); + } + }); + this.jMenu1.add(this.exitMenuBtn); + this.jMenuBar1.add(this.jMenu1); + this.setJMenuBar(this.jMenuBar1); + + GroupLayout layout = new GroupLayout(this.getContentPane()); + this.getContentPane().setLayout(layout); + layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING).addComponent(this.jTabbedPane1).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(this.currentViewLabel).addContainerGap(-1, 32767))); + layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, layout.createSequentialGroup().addGap(0, 11, 32767).addComponent(this.currentViewLabel).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.jTabbedPane1, -2, 300, -2))); + this.pack(); + } + + private void exitMenuBtnActionPerformed(ActionEvent evt) { + this.dispose(); + } + + private void exportMenuBtnActionPerformed(ActionEvent evt) { + this.export(); + } + + private void addModelMenuBtnActionPerformed(ActionEvent evt) { + this.addModel(); + } + + private void saveMenuBtnActionPerformed(ActionEvent evt) { + this.save(); + } + + private void reloadMenuBtnActionPerformed(ActionEvent evt) { + this.itemName.setText(this.defs.getName()); + this.value.setText("" + this.defs.getCost()); + this.teamId.setText("" + this.defs.getTeamId()); + this.membersOnly.setSelected(this.defs.isMembersOnly()); + this.equipSlot.setText("" + this.defs.getEquipSlot()); + this.equipType.setText("" + this.defs.getEquipType()); + this.stackIDs.setText(this.getStackIDs()); + this.stackAmts.setText(this.getStackAmts()); + this.stackable.setSelected(this.defs.getStackable() == 1); + this.Zoom2dField.setText("" + this.defs.getInvModelZoom()); + this.xan2dField.setText("" + this.defs.getXan2d()); + this.yan2dField.setText("" + this.defs.getYan2d()); + this.xOffset2dField.setText("" + this.defs.getxOffset2d()); + this.yOffset2dField.setText("" + this.defs.getyOffset2d()); + this.inventoryModelField.setText("" + this.defs.getInvModelId()); + this.maleEquip1Field.setText("" + this.defs.getMaleEquipModelId1()); + this.femaleEquip1Field.setText("" + this.defs.getFemaleEquipModelId1()); + this.maleEquip2Field.setText("" + this.defs.getMaleEquipModelId2()); + this.femaleEquip2Field.setText("" + this.defs.getFemaleEquipModelId2()); + this.maleEquip3Field.setText("" + this.defs.getMaleEquipModelId3()); + this.femaleEquip3Field.setText("" + this.defs.getFemaleEquipModelId3()); + this.invOptions.setText(this.getInventoryOpts()); + this.groundOptions.setText(this.getGroundOpts()); + this.modelColors.setText(this.getChangedModelColors()); + this.textureColors.setText(this.getChangedTextureColors()); + this.switchNote.setText("" + this.defs.switchNoteItemId); + this.note.setText("" + this.defs.notedItemId); + this.unnoted.setSelected(this.defs.isUnnoted()); + this.switchLend.setText("" + this.defs.getSwitchLendItemId()); + this.lend.setText("" + this.defs.getLendedItemId()); + this.array1.setText(this.getUnknownArray1()); + this.array2.setText(this.getUnknownArray2()); + this.array3.setText(this.getUnknownArray3()); + this.array4.setText(this.getUnknownArray4()); + this.array5.setText(this.getUnknownArray5()); + this.array6.setText(this.getUnknownArray6()); + this.maleDialogueHeadPrimaryField.setText("" + this.defs.primaryMaleDialogueHead); + this.femaleDialogueHeadPrimaryField.setText("" + this.defs.primaryFemaleDialogueHead); + this.maleDialogueHeadAccessoryField.setText("" + this.defs.secondaryMaleDialogueHead); + this.femaleDialogueHeadAccessoryField.setText("" + this.defs.secondaryFemaleDialogueHead); + this.zan2dField.setText("" + this.defs.Zan2d); + this.int6.setText("" + this.defs.dummyItem); + this.fScaleXTextField.setText("" + this.defs.floorScaleX); + this.fScaleYTextField.setText("" + this.defs.floorScaleY); + this.fScaleZTextField.setText("" + this.defs.floorScaleZ); + this.ambienceTextField.setText("" + this.defs.ambience); + this.diffusionTextField.setText("" + this.defs.diffusion); + this.mWieldXTextField.setText("" + this.defs.maleWieldX); + this.mWieldYTextField.setText("" + this.defs.maleWieldY); + this.mWieldZTextField.setText("" + this.defs.maleWieldZ); + this.fWieldXTextField.setText("" + this.defs.femaleWieldX); + this.fWieldYTextField.setText("" + this.defs.femaleWieldY); + this.fWieldZTextField.setText("" + this.defs.femaleWieldZ); + this.int18.setText("" + this.defs.unknownInt18); + this.int19.setText("" + this.defs.unknownInt19); + this.int20.setText("" + this.defs.unknownInt20); + this.int21.setText("" + this.defs.unknownInt21); + this.int22.setText("" + this.defs.unknownInt22); + this.int23.setText("" + this.defs.unknownInt23); + this.clientScriptOutput.setText(this.getClientScripts()); + } + + private void export() { + File f = new File(System.getProperty("user.home") + "/FCE/items/"); + f.mkdirs(); + String lineSep = System.getProperty("line.separator"); + BufferedWriter writer = null; + + try { + writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(System.getProperty("user.home") + "/FCE/items/" + this.defs.id + ".txt"), StandardCharsets.UTF_8)); + writer.write("name = " + this.defs.getName()); + writer.write(lineSep); + writer.write("value = " + this.defs.getCost()); + writer.write(lineSep); + writer.write("team id = " + this.defs.getTeamId()); + writer.write(lineSep); + writer.write("members only = " + this.defs.isMembersOnly()); + writer.write(lineSep); + writer.write("equip slot = " + this.defs.getEquipSlot()); + writer.write(lineSep); + writer.write("equip type = " + this.defs.getEquipType()); + writer.write(lineSep); + writer.write("stack ids = " + this.getStackIDs()); + writer.write(lineSep); + writer.write("stack amounts = " + this.getStackAmts()); + writer.write(lineSep); + writer.write("stackable = " + this.defs.getStackable()); + writer.write(lineSep); + writer.write("inv model zoom = " + this.defs.getInvModelZoom()); + writer.write(lineSep); + writer.write("model rotation 1 = " + this.defs.getXan2d()); + writer.write(lineSep); + writer.write("model rotation 2 = " + this.defs.getYan2d()); + writer.write(lineSep); + writer.write("model offset 1 = " + this.defs.getxOffset2d()); + writer.write(lineSep); + writer.write("model offset 2 = " + this.defs.getyOffset2d()); + writer.write(lineSep); + writer.write("inv model id = " + this.defs.getInvModelId()); + writer.write(lineSep); + writer.write("male equip model id 1 = " + this.defs.getMaleEquipModelId1()); + writer.write(lineSep); + writer.write("female equip model id 1 = " + this.defs.getFemaleEquipModelId1()); + writer.write(lineSep); + writer.write("male equip model id 2 = " + this.defs.getMaleEquipModelId2()); + writer.write(lineSep); + writer.write("female equip model id 2 = " + this.defs.getFemaleEquipModelId2()); + writer.write(lineSep); + writer.write("male equip model id 3 = " + this.defs.getMaleEquipModelId3()); + writer.write(lineSep); + writer.write("female equip model id 3 = " + this.defs.getFemaleEquipModelId3()); + writer.write(lineSep); + writer.write("inventory options = " + this.getInventoryOpts()); + writer.write(lineSep); + writer.write("ground options = " + this.getGroundOpts()); + writer.write(lineSep); + writer.write("changed model colors = " + this.getChangedModelColors()); + writer.write(lineSep); + writer.write("changed texture colors = " + this.getChangedTextureColors()); + writer.write(lineSep); + writer.write("switch note item id = " + this.defs.switchNoteItemId); + writer.write(lineSep); + writer.write("noted item id = " + this.defs.notedItemId); + writer.write(lineSep); + writer.write("unnoted = " + this.defs.isUnnoted()); + writer.write(lineSep); + writer.write("switch lend item id = " + this.defs.getSwitchLendItemId()); + writer.write(lineSep); + writer.write("lended item id = " + this.defs.getLendedItemId()); + writer.write(lineSep); + writer.write("unknownArray1 = " + this.getUnknownArray1()); + writer.write(lineSep); + writer.write("unknownArray2 = " + this.getUnknownArray2()); + writer.write(lineSep); + writer.write("unknownArray3 = " + this.getUnknownArray3()); + writer.write(lineSep); + writer.write("unknownArray4 = " + this.getUnknownArray4()); + writer.write(lineSep); + writer.write("unknownArray5 = " + this.getUnknownArray5()); + writer.write(lineSep); + writer.write("unknownArray6 = " + this.getUnknownArray6()); + writer.write(lineSep); + writer.write("unknownInt1 = " + this.defs.primaryMaleDialogueHead); + writer.write(lineSep); + writer.write("unknownInt2 = " + this.defs.primaryFemaleDialogueHead); + writer.write(lineSep); + writer.write("unknownInt3 = " + this.defs.secondaryMaleDialogueHead); + writer.write(lineSep); + writer.write("unknownInt4 = " + this.defs.secondaryFemaleDialogueHead); + writer.write(lineSep); + writer.write("spriteCameraYaw = " + this.defs.Zan2d); + writer.write(lineSep); + writer.write("unknownInt6 = " + this.defs.dummyItem); + writer.write(lineSep); + writer.write("unknownInt7 = " + this.defs.floorScaleX); + writer.write(lineSep); + writer.write("unknownInt8 = " + this.defs.floorScaleY); + writer.write(lineSep); + writer.write("unknownInt9 = " + this.defs.floorScaleZ); + writer.write(lineSep); + writer.write("unknownInt10 = " + this.defs.ambience); + writer.write(lineSep); + writer.write("unknownInt11 = " + this.defs.diffusion); + writer.write(lineSep); + writer.write("unknownInt12 = " + this.defs.maleWieldX); + writer.write(lineSep); + writer.write("unknownInt13 = " + this.defs.maleWieldY); + writer.write(lineSep); + writer.write("unknownInt14 = " + this.defs.maleWieldZ); + writer.write(lineSep); + writer.write("unknownInt15 = " + this.defs.femaleWieldX); + writer.write(lineSep); + writer.write("unknownInt16 = " + this.defs.femaleWieldY); + writer.write(lineSep); + writer.write("unknownInt17 = " + this.defs.femaleWieldZ); + writer.write(lineSep); + writer.write("unknownInt18 = " + this.defs.unknownInt18); + writer.write(lineSep); + writer.write("unknownInt19 = " + this.defs.unknownInt19); + writer.write(lineSep); + writer.write("unknownInt20 = " + this.defs.unknownInt20); + writer.write(lineSep); + writer.write("unknownInt21 = " + this.defs.unknownInt21); + writer.write(lineSep); + writer.write("unknownInt22 = " + this.defs.unknownInt22); + writer.write(lineSep); + writer.write("unknownInt23 = " + this.defs.unknownInt23); + writer.write(lineSep); + writer.write("Clientscripts"); + writer.write(lineSep); + if (this.defs.clientScriptData != null) { + Iterator var15 = this.defs.clientScriptData.keySet().iterator(); + + while (var15.hasNext()) { + int key = ((Integer)var15.next()).intValue(); + Object value = this.defs.clientScriptData.get(Integer.valueOf(key)); + writer.write("KEY: " + key + ", VALUE: " + value); + writer.write(lineSep); + } + } + } catch (IOException var151) { + Main.log("ItemEditor", "Failed to export Item Defs to .txt"); + } finally { + try { + writer.close(); + } catch (Exception var14) { + } + + } + + } + + private void save() { + try { + this.defs.setName(this.itemName.getText()); + this.defs.setCost(Integer.parseInt(this.value.getText())); + this.defs.setTeamId(Integer.parseInt(this.teamId.getText())); + this.defs.setMembersOnly(this.membersOnly.isSelected()); + this.defs.setEquipSlot(Integer.parseInt(this.equipSlot.getText())); + this.defs.setEquipType(Integer.parseInt(this.equipType.getText())); + String[] var17; + int invOpts; + if (!this.stackIDs.getText().equals("")) { + var17 = this.stackIDs.getText().split(";"); + + for (invOpts = 0; invOpts < this.defs.getStackIds().length; ++invOpts) { + this.defs.getStackIds()[invOpts] = Integer.parseInt(var17[invOpts]); + } + } + + if (!this.stackAmts.getText().equals("")) { + var17 = this.stackAmts.getText().split(";"); + + for (invOpts = 0; invOpts < this.defs.getStackAmounts().length; ++invOpts) { + this.defs.getStackAmounts()[invOpts] = Integer.parseInt(var17[invOpts]); + } + } + + //this.defs.setStackable(Integer.parseInt(this.stackable.getText())); + this.defs.setStackable((this.stackable.isSelected()) ? 1 : 0); + this.defs.setInvModelZoom(Integer.parseInt(this.Zoom2dField.getText())); + this.defs.setXan2d(Integer.parseInt(this.xan2dField.getText())); + this.defs.setYan2d(Integer.parseInt(this.yan2dField.getText())); + this.defs.setxOffset2d(Integer.parseInt(this.xOffset2dField.getText())); + this.defs.setyOffset2d(Integer.parseInt(this.yOffset2dField.getText())); + this.defs.setInvModelId(Integer.parseInt(this.inventoryModelField.getText())); + this.defs.maleEquip1 = Integer.parseInt(this.maleEquip1Field.getText()); + this.defs.maleEquip2 = Integer.parseInt(this.maleEquip2Field.getText()); + this.defs.maleEquipModelId3 = Integer.parseInt(this.maleEquip3Field.getText()); + this.defs.femaleEquip1 = Integer.parseInt(this.femaleEquip1Field.getText()); + this.defs.femaleEquip2 = Integer.parseInt(this.femaleEquip2Field.getText()); + this.defs.femaleEquipModelId3 = Integer.parseInt(this.femaleEquip3Field.getText()); + var17 = this.groundOptions.getText().split(";"); + + for (invOpts = 0; invOpts < this.defs.getGroundOptions().length; ++invOpts) { + this.defs.getGroundOptions()[invOpts] = var17[invOpts].equals("null") ? null : var17[invOpts]; + } + + String[] var19 = this.invOptions.getText().split(";"); + + for (int i = 0; i < this.defs.getInventoryOptions().length; ++i) { + this.defs.getInventoryOptions()[i] = var19[i].equals("null") ? null : var19[i]; + } + + this.defs.resetModelColors(); + int len$; + int i$; + String t; + String[] editedColor; + String[] var18; + String[] var21; + if (!this.modelColors.getText().equals("")) { + var18 = this.modelColors.getText().split(";"); + var21 = var18; + len$ = var18.length; + + for (i$ = 0; i$ < len$; ++i$) { + t = var21[i$]; + editedColor = t.split("="); + this.defs.changeModelColor(Integer.valueOf(editedColor[0]).intValue(), Integer.valueOf(editedColor[1]).intValue()); + } + } + + this.defs.resetTextureColors(); + if (!this.textureColors.getText().equals("")) { + var18 = this.textureColors.getText().split(";"); + var21 = var18; + len$ = var18.length; + + for (i$ = 0; i$ < len$; ++i$) { + t = var21[i$]; + editedColor = t.split("="); + this.defs.changeTextureColor(Short.valueOf(editedColor[0]).shortValue(), Short.valueOf(editedColor[1]).shortValue()); + } + } + + this.defs.notedItemId = Integer.valueOf(this.note.getText()).intValue(); + this.defs.switchNoteItemId = Integer.valueOf(this.switchNote.getText()).intValue(); + this.defs.lendedItemId = Integer.valueOf(this.lend.getText()).intValue(); + this.defs.switchLendItemId = Integer.valueOf(this.switchLend.getText()).intValue(); + this.defs.setUnnoted(this.unnoted.isSelected()); + int var20; + if (!this.array1.getText().equals("")) { + var18 = this.array1.getText().split(";"); + + for (var20 = 0; var20 < this.defs.recolorPalette.length; ++var20) { + this.defs.recolorPalette[var20] = (byte)Integer.parseInt(var18[var20]); + } + } + + if (!this.array2.getText().equals("")) { + var18 = this.array2.getText().split(";"); + + for (var20 = 0; var20 < this.defs.unknownArray2.length; ++var20) { + this.defs.unknownArray2[var20] = Integer.parseInt(var18[var20]); + } + } + + if (!this.array3.getText().equals("")) { + var18 = this.array3.getText().split(";"); + + for (var20 = 0; var20 < this.defs.unknownArray3.length; ++var20) { + this.defs.unknownArray3[var20] = (byte)Integer.parseInt(var18[var20]); + } + } + + if (!this.array4.getText().equals("")) { + var18 = this.array4.getText().split(";"); + + for (var20 = 0; var20 < this.defs.unknownArray4.length; ++var20) { + this.defs.unknownArray4[var20] = Integer.parseInt(var18[var20]); + } + } + + if (!this.array5.getText().equals("")) { + var18 = this.array5.getText().split(";"); + + for (var20 = 0; var20 < this.defs.unknownArray5.length; ++var20) { + this.defs.unknownArray5[var20] = Integer.parseInt(var18[var20]); + } + } + + if (!this.array6.getText().equals("")) { + var18 = this.array6.getText().split(";"); + + for (var20 = 0; var20 < this.defs.unknownArray6.length; ++var20) { + this.defs.unknownArray6[var20] = (byte)Integer.parseInt(var18[var20]); + } + } + + this.defs.primaryMaleDialogueHead = Integer.parseInt(this.maleDialogueHeadPrimaryField.getText()); + this.defs.primaryFemaleDialogueHead = Integer.parseInt(this.femaleDialogueHeadPrimaryField.getText()); + this.defs.secondaryMaleDialogueHead = Integer.parseInt(this.maleDialogueHeadAccessoryField.getText()); + this.defs.secondaryFemaleDialogueHead = Integer.parseInt(this.femaleDialogueHeadAccessoryField.getText()); + this.defs.Zan2d = Integer.parseInt(this.zan2dField.getText()); + this.defs.dummyItem = Integer.parseInt(this.int6.getText()); + this.defs.floorScaleX = Integer.parseInt(this.fScaleXTextField.getText()); + this.defs.floorScaleY = Integer.parseInt(this.fScaleYTextField.getText()); + this.defs.floorScaleZ = Integer.parseInt(this.fScaleZTextField.getText()); + this.defs.ambience = Integer.parseInt(this.ambienceTextField.getText()); + this.defs.diffusion = Integer.parseInt(this.diffusionTextField.getText()); + this.defs.maleWieldX = Integer.parseInt(this.mWieldXTextField.getText()); + this.defs.maleWieldY = Integer.parseInt(this.mWieldYTextField.getText()); + this.defs.maleWieldZ = Integer.parseInt(this.mWieldZTextField.getText()); + this.defs.femaleWieldX = Integer.parseInt(this.fWieldXTextField.getText()); + this.defs.femaleWieldY = Integer.parseInt(this.fWieldYTextField.getText()); + this.defs.femaleWieldZ = Integer.parseInt(this.fWieldZTextField.getText()); + this.defs.unknownInt18 = Integer.parseInt(this.int18.getText()); + this.defs.unknownInt19 = Integer.parseInt(this.int19.getText()); + this.defs.unknownInt20 = Integer.parseInt(this.int20.getText()); + this.defs.unknownInt21 = Integer.parseInt(this.int21.getText()); + this.defs.unknownInt22 = Integer.parseInt(this.int22.getText()); + this.defs.unknownInt23 = Integer.parseInt(this.int23.getText()); + + try { + if (!this.csk1.getText().equals("") && !this.csv1.getText().equals("")) { + try { + this.defs.clientScriptData.remove(this.csk1); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk1.getText())), Integer.valueOf(Integer.parseInt(this.csv1.getText()))); + } catch (Exception var181) { + this.defs.clientScriptData.remove(this.csk1); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk1.getText())), this.csv1.getText()); + } + } + + if (!this.csk2.getText().equals("") && !this.csv2.getText().equals("")) { + try { + this.defs.clientScriptData.remove(this.csk2); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk2.getText())), Integer.valueOf(Integer.parseInt(this.csv2.getText()))); + } catch (Exception var171) { + this.defs.clientScriptData.remove(this.csk2); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk2.getText())), this.csv2.getText()); + } + } + + if (!this.csk3.getText().equals("") && !this.csv3.getText().equals("")) { + try { + this.defs.clientScriptData.remove(this.csk3); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk3.getText())), Integer.valueOf(Integer.parseInt(this.csv3.getText()))); + } catch (Exception var16) { + this.defs.clientScriptData.remove(this.csk3); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk3.getText())), this.csv3.getText()); + } + } + + if (!this.csk4.getText().equals("") && !this.csv4.getText().equals("")) { + try { + this.defs.clientScriptData.remove(this.csk4); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk4.getText())), Integer.valueOf(Integer.parseInt(this.csv4.getText()))); + } catch (Exception var15) { + this.defs.clientScriptData.remove(this.csk4); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk4.getText())), this.csv4.getText()); + } + } + + if (!this.csk5.getText().equals("") && !this.csv5.getText().equals("")) { + try { + this.defs.clientScriptData.remove(this.csk5); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk5.getText())), Integer.valueOf(Integer.parseInt(this.csv5.getText()))); + } catch (Exception var14) { + this.defs.clientScriptData.remove(this.csk5); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk5.getText())), this.csv5.getText()); + } + } + + if (!this.csk6.getText().equals("") && !this.csv6.getText().equals("")) { + try { + this.defs.clientScriptData.remove(this.csk6); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk6.getText())), Integer.valueOf(Integer.parseInt(this.csv6.getText()))); + } catch (Exception var13) { + this.defs.clientScriptData.remove(this.csk6); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk6.getText())), this.csv6.getText()); + } + } + + if (!this.csk7.getText().equals("") && !this.csv7.getText().equals("")) { + try { + this.defs.clientScriptData.remove(this.csk7); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk7.getText())), Integer.valueOf(Integer.parseInt(this.csv7.getText()))); + } catch (Exception var12) { + this.defs.clientScriptData.remove(this.csk7); + this.defs.clientScriptData.put(Integer.valueOf(Integer.parseInt(this.csk7.getText())), this.csv7.getText()); + } + } + } catch (Exception var191) { + this.defs.clientScriptData = new HashMap(1); + } + + ItemSelection var10001 = this.is; + this.defs.write(ItemSelection.STORE); + this.is.updateItemDefs(this.defs); + } catch (Exception var201) { + Main.log("ItemEditor", "Cannot save. Please check for mistypes."); + } + + } + + private void addModel() { + JFrame frame = new JFrame(); + int result = JOptionPane.showConfirmDialog(frame, "Do you want to specify a model ID?"); + StringBuilder var10001; + ItemSelection var10002; + if (result == 0) { + JFrame fc1 = new JFrame(); + String returnVal1 = JOptionPane.showInputDialog(fc1, "Enter new model ID:"); + if (Integer.parseInt(returnVal1) != -1) { + JFileChooser file2 = new JFileChooser(); + file2.setFileSelectionMode(0); + int var9 = file2.showOpenDialog(this); + if (var9 == 0) { + File file1 = file2.getSelectedFile(); + + try { + var10001 = (new StringBuilder()).append("The model ID of the recently packed model is: "); + var10002 = this.is; + Main.log("ItemEditor", var10001.append(Utils.packCustomModel(ItemSelection.STORE, Utils.getBytesFromFile(new File(file1.getPath())), Integer.parseInt(returnVal1))).toString()); + } catch (IOException var12) { + Main.log("ItemEditor", "There was an error packing the model."); + } + } + } + } else if (result == 1) { + JFileChooser fc11 = new JFileChooser(); + fc11.setFileSelectionMode(0); + int returnVal11 = fc11.showOpenDialog(this); + if (returnVal11 == 0) { + File file21 = fc11.getSelectedFile(); + + try { + var10001 = (new StringBuilder()).append("The model ID of the recently packed model is: "); + var10002 = this.is; + Main.log("ItemEditor", var10001.append(Utils.packCustomModel(ItemSelection.STORE, Utils.getBytesFromFile(new File(file21.getPath())))).toString()); + } catch (IOException var11) { + Main.log("ItemEditor", "There was an error packing the model."); + } + } + } + + } + + public String getInventoryOpts() { + String text = ""; + String[] arr$ = this.defs.getInventoryOptions(); + int len$ = arr$.length; + + for (int i$ = 0; i$ < len$; ++i$) { + String option = arr$[i$]; + text = text + (option == null ? "null" : option) + ";"; + } + + return text; + } + + public String getGroundOpts() { + String text = ""; + String[] arr$ = this.defs.getGroundOptions(); + int len$ = arr$.length; + + for (int i$ = 0; i$ < len$; ++i$) { + String option = arr$[i$]; + text = text + (option == null ? "null" : option) + ";"; + } + + return text; + } + + public String getChangedModelColors() { + String text = ""; + if (this.defs.originalModelColors != null) { + for (int i = 0; i < this.defs.originalModelColors.length; ++i) { + text = text + this.defs.originalModelColors[i] + "=" + this.defs.modifiedModelColors[i] + ";"; + } + } + + return text; + } + + public String getChangedTextureColors() { + String text = ""; + if (this.defs.originalTextureColors != null) { + for (int i = 0; i < this.defs.originalTextureColors.length; ++i) { + text = text + this.defs.originalTextureColors[i] + "=" + this.defs.modifiedTextureColors[i] + ";"; + } + } + + return text; + } + + public String getStackIDs() { + String text = ""; + + try { + int[] e = this.defs.getStackIds(); + int len$ = e.length; + + for (int i$ = 0; i$ < len$; ++i$) { + int index = e[i$]; + text = text + index + ";"; + } + } catch (Exception var6) { + } + + return text; + } + + public String getClientScripts() { + String text = ""; + String lineSep = System.getProperty("line.separator"); + if (this.defs.clientScriptData != null) { + for (Iterator i$ = this.defs.clientScriptData.keySet().iterator(); i$.hasNext(); text = text + lineSep) { + int key = ((Integer)i$.next()).intValue(); + Object value = this.defs.clientScriptData.get(Integer.valueOf(key)); + text = text + "KEY: " + key + ", VALUE: " + value; + } + } + + return text; + } + + public String getStackAmts() { + String text = ""; + + try { + int[] e = this.defs.getStackAmounts(); + int len$ = e.length; + + for (int i$ = 0; i$ < len$; ++i$) { + int index = e[i$]; + text = text + index + ";"; + } + } catch (Exception var6) { + } + + return text; + } + + public String getUnknownArray1() { + String text = ""; + + try { + byte[] e = this.defs.recolorPalette; + int len$ = e.length; + + for (int i$ = 0; i$ < len$; ++i$) { + byte index = e[i$]; + text = text + index + ";"; + } + } catch (Exception var6) { + } + + return text; + } + + public String getUnknownArray2() { + String text = ""; + + try { + int[] e = this.defs.unknownArray2; + int len$ = e.length; + + for (int i$ = 0; i$ < len$; ++i$) { + int index = e[i$]; + text = text + index + ";"; + } + } catch (Exception var6) { + } + + return text; + } + + public String getUnknownArray3() { + String text = ""; + + try { + byte[] e = this.defs.unknownArray3; + int len$ = e.length; + + for (int i$ = 0; i$ < len$; ++i$) { + byte index = e[i$]; + text = text + index + ";"; + } + } catch (Exception var6) { + } + + return text; + } + + public String getUnknownArray4() { + String text = ""; + + try { + int[] e = this.defs.unknownArray4; + int len$ = e.length; + + for (int i$ = 0; i$ < len$; ++i$) { + int index = e[i$]; + text = text + index + ";"; + } + } catch (Exception var6) { + } + + return text; + } + + public String getUnknownArray5() { + String text = ""; + + try { + int[] e = this.defs.unknownArray5; + int len$ = e.length; + + for (int i$ = 0; i$ < len$; ++i$) { + int index = e[i$]; + text = text + index + ";"; + } + } catch (Exception var6) { + } + + return text; + } + + public String getUnknownArray6() { + String text = ""; + + try { + byte[] e = this.defs.unknownArray6; + int len$ = e.length; + + for (int i$ = 0; i$ < len$; ++i$) { + byte index = e[i$]; + text = text + index + ";"; + } + } catch (Exception var6) { + } + + return text; + } +} diff --git a/src/com/editor/item/ItemSelection.java b/src/com/editor/item/ItemSelection.java new file mode 100644 index 0000000..efd9cd0 --- /dev/null +++ b/src/com/editor/item/ItemSelection.java @@ -0,0 +1,182 @@ +package com.editor.item; + +import com.alex.loaders.items.ItemDefinitions; +import com.alex.store.Store; +import com.alex.utils.Utils; +import com.editor.Main; + +import javax.swing.*; +import javax.swing.GroupLayout.Alignment; +import javax.swing.LayoutStyle.ComponentPlacement; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.net.URL; + +public class ItemSelection extends JFrame { + private static final long serialVersionUID = -3059309913196024742L; + public static Store STORE; + private JButton addButton; + private JButton duplicateButton; + private JButton editButton; + private DefaultListModel itemsListmodel; + private JList itemsList; + private JMenu jMenu1; + private JMenuBar jMenuBar1; + private JMenuItem exitButton; + private JButton deleteButton; + + public ItemSelection(String cache) throws IOException { + STORE = new Store(cache); + this.setIconImage(Main.iconImage); + this.setTitle("Item Selection"); + this.setResizable(false); + this.setDefaultCloseOperation(1); + this.setLocationRelativeTo(null); + this.initComponents(); + } + + public ItemSelection() { + this.initComponents(); + } + + private void initComponents() { + this.editButton = new JButton(); + this.addButton = new JButton(); + this.duplicateButton = new JButton(); + this.deleteButton = new JButton(); + this.jMenuBar1 = new JMenuBar(); + this.jMenu1 = new JMenu(); + this.exitButton = new JMenuItem(); + this.setDefaultCloseOperation(1); + this.itemsListmodel = new DefaultListModel(); + this.itemsList = new JList(this.itemsListmodel); + this.itemsList.setSelectionMode(1); + this.itemsList.setLayoutOrientation(0); + this.itemsList.setVisibleRowCount(-1); + JScrollPane jScrollPane1 = new JScrollPane(this.itemsList); + this.editButton.setText("Edit"); + this.editButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ItemDefinitions defs = (ItemDefinitions)ItemSelection.this.itemsList.getSelectedValue(); + if (defs != null) { + new ItemEditor(ItemSelection.this, defs); + } + + } + }); + this.addButton.setText("Add New"); + this.addButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ItemDefinitions defs = new ItemDefinitions(ItemSelection.STORE, ItemSelection.this.getNewItemID(), false); + if (defs != null && defs.id != -1) { + new ItemEditor(ItemSelection.this, defs); + } + + } + }); + this.duplicateButton.setText("Duplicate"); + this.duplicateButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ItemDefinitions defs = (ItemDefinitions)ItemSelection.this.itemsList.getSelectedValue(); + if (defs != null) { + defs = (ItemDefinitions)defs.clone(); + if (defs != null) { + defs.id = ItemSelection.this.getNewItemID(); + if (defs.id != -1) { + new ItemEditor(ItemSelection.this, defs); + } + } + } + + } + }); + this.deleteButton.setText("Delete"); + this.deleteButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ItemDefinitions defs = (ItemDefinitions)ItemSelection.this.itemsList.getSelectedValue(); + JFrame frame = new JFrame(); + int result = JOptionPane.showConfirmDialog(frame, "Do you really want to delete item " + defs.id); + if (result == 0) { + if (defs == null) { + return; + } + + ItemSelection.STORE.getIndexes()[19].removeFile(defs.getArchiveId(), defs.getFileId()); + ItemSelection.this.removeItemDefs(defs); + Main.log("ItemSelection", "Item " + defs.id + " removed."); + } + + } + }); + this.jMenu1.setText("File"); + this.exitButton.setText("Close"); + this.exitButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + ItemSelection.this.exitButtonActionPerformed(evt); + } + }); + this.jMenu1.add(this.exitButton); + this.jMenuBar1.add(this.jMenu1); + this.setJMenuBar(this.jMenuBar1); + GroupLayout layout = new GroupLayout(this.getContentPane()); + this.getContentPane().setLayout(layout); + layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.LEADING, false).addComponent(jScrollPane1, -2, 200, -2).addGroup(layout.createSequentialGroup().addComponent(this.editButton).addPreferredGap(ComponentPlacement.RELATED, -1, 32767).addComponent(this.addButton))).addGap(0, 0, 32767)).addGroup(layout.createSequentialGroup().addComponent(this.duplicateButton).addPreferredGap(ComponentPlacement.RELATED, -1, 32767).addComponent(this.deleteButton))).addContainerGap(-1, 32767))); + layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jScrollPane1, -2, 279, -2).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(this.editButton).addComponent(this.addButton)).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(this.duplicateButton).addComponent(this.deleteButton)).addContainerGap(-1, 32767))); + this.pack(); + this.addAllItems(); + } + + public static void main(String[] args) throws IOException { + STORE = new Store("cache/", false); + EventQueue.invokeLater(() -> (new ItemSelection()).setVisible(true)); + } + + private void exitButtonActionPerformed(ActionEvent evt) { + this.dispose(); + } + + public int getNewItemID() { + return Utils.getItemDefinitionsSize(STORE); + } + + public void addAllItems() { + int id; + if (Utils.getItemDefinitionsSize(STORE) > 30000) { + for (id = 0; id < Utils.getItemDefinitionsSize(STORE) - 22314; ++id) { + this.addItemDefs(ItemDefinitions.getItemDefinition(STORE, id)); + } + } else { + for (id = 0; id < Utils.getItemDefinitionsSize(STORE); ++id) { + this.addItemDefs(ItemDefinitions.getItemDefinition(STORE, id)); + } + } + + Main.log("ItemSelection", "All Items Loaded"); + } + + public void addItemDefs(final ItemDefinitions defs) { + EventQueue.invokeLater(() -> ItemSelection.this.itemsListmodel.addElement(defs)); + } + + public void updateItemDefs(final ItemDefinitions defs) { + EventQueue.invokeLater(() -> { + int index = ItemSelection.this.itemsListmodel.indexOf(defs); + if (index == -1) { + ItemSelection.this.itemsListmodel.addElement(defs); + } else { + ItemSelection.this.itemsListmodel.setElementAt(defs, index); + } + + }); + } + + public void removeItemDefs(final ItemDefinitions defs) { + EventQueue.invokeLater(new Runnable() { + public void run() { + ItemSelection.this.itemsListmodel.removeElement(defs); + } + }); + } +} diff --git a/src/com/editor/resources/ico32.png b/src/com/editor/resources/ico32.png new file mode 100644 index 0000000..1f3250c Binary files /dev/null and b/src/com/editor/resources/ico32.png differ diff --git a/src/com/editor/util/SpringUtilities.java b/src/com/editor/util/SpringUtilities.java new file mode 100644 index 0000000..fdba5d9 --- /dev/null +++ b/src/com/editor/util/SpringUtilities.java @@ -0,0 +1,225 @@ +package com.editor.util; + +/* + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Oracle or the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import javax.swing.*; +import javax.swing.SpringLayout; +import java.awt.*; + +/** + * A 1.4 file that provides utility methods for + * creating form- or grid-style layouts with SpringLayout. + * These utilities are used by several programs, such as + * SpringBox and SpringCompactGrid. + */ +public class SpringUtilities { + /** + * A debugging utility that prints to stdout the component's + * minimum, preferred, and maximum sizes. + */ + public static void printSizes(Component c) { + System.out.println("minimumSize = " + c.getMinimumSize()); + System.out.println("preferredSize = " + c.getPreferredSize()); + System.out.println("maximumSize = " + c.getMaximumSize()); + } + + /** + * Aligns the first rows * cols + * components of parent in + * a grid. Each component is as big as the maximum + * preferred width and height of the components. + * The parent is made just big enough to fit them all. + * + * @param rows number of rows + * @param cols number of columns + * @param initialX x location to start the grid at + * @param initialY y location to start the grid at + * @param xPad x padding between cells + * @param yPad y padding between cells + */ + public static void makeGrid(Container parent, + int rows, int cols, + int initialX, int initialY, + int xPad, int yPad) { + SpringLayout layout; + try { + layout = (SpringLayout)parent.getLayout(); + } catch (ClassCastException exc) { + System.err.println("The first argument to makeGrid must use SpringLayout."); + return; + } + + Spring xPadSpring = Spring.constant(xPad); + Spring yPadSpring = Spring.constant(yPad); + Spring initialXSpring = Spring.constant(initialX); + Spring initialYSpring = Spring.constant(initialY); + int max = rows * cols; + + //Calculate Springs that are the max of the width/height so that all + //cells have the same size. + Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0)). + getWidth(); + Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0)). + getHeight(); + for (int i = 1; i < max; i++) { + SpringLayout.Constraints cons = layout.getConstraints( + parent.getComponent(i)); + + maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth()); + maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight()); + } + + //Apply the new width/height Spring. This forces all the + //components to have the same size. + for (int i = 0; i < max; i++) { + SpringLayout.Constraints cons = layout.getConstraints( + parent.getComponent(i)); + + cons.setWidth(maxWidthSpring); + cons.setHeight(maxHeightSpring); + } + + //Then adjust the x/y constraints of all the cells so that they + //are aligned in a grid. + SpringLayout.Constraints lastCons = null; + SpringLayout.Constraints lastRowCons = null; + for (int i = 0; i < max; i++) { + SpringLayout.Constraints cons = layout.getConstraints( + parent.getComponent(i)); + if (i % cols == 0) { //start of new row + lastRowCons = lastCons; + cons.setX(initialXSpring); + } else { //x position depends on previous component + cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST), + xPadSpring)); + } + + if (i / cols == 0) { //first row + cons.setY(initialYSpring); + } else { //y position depends on previous row + cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH), + yPadSpring)); + } + lastCons = cons; + } + + //Set the parent's size. + SpringLayout.Constraints pCons = layout.getConstraints(parent); + pCons.setConstraint(SpringLayout.SOUTH, + Spring.sum( + Spring.constant(yPad), + lastCons.getConstraint(SpringLayout.SOUTH))); + pCons.setConstraint(SpringLayout.EAST, + Spring.sum( + Spring.constant(xPad), + lastCons.getConstraint(SpringLayout.EAST))); + } + + /* Used by makeCompactGrid. */ + private static SpringLayout.Constraints getConstraintsForCell( + int row, int col, + Container parent, + int cols) { + SpringLayout layout = (SpringLayout) parent.getLayout(); + Component c = parent.getComponent(row * cols + col); + return layout.getConstraints(c); + } + + /** + * Aligns the first rows * cols + * components of parent in + * a grid. Each component in a column is as wide as the maximum + * preferred width of the components in that column; + * height is similarly determined for each row. + * The parent is made just big enough to fit them all. + * + * @param rows number of rows + * @param cols number of columns + * @param initialX x location to start the grid at + * @param initialY y location to start the grid at + * @param xPad x padding between cells + * @param yPad y padding between cells + */ + public static void makeCompactGrid(Container parent, + int rows, int cols, + int initialX, int initialY, + int xPad, int yPad) { + SpringLayout layout; + try { + layout = (SpringLayout)parent.getLayout(); + } catch (ClassCastException exc) { + System.err.println("The first argument to makeCompactGrid must use SpringLayout."); + return; + } + + //Align all cells in each column and make them the same width. + Spring x = Spring.constant(initialX); + for (int c = 0; c < cols; c++) { + Spring width = Spring.constant(0); + for (int r = 0; r < rows; r++) { + width = Spring.max(width, + getConstraintsForCell(r, c, parent, cols). + getWidth()); + } + for (int r = 0; r < rows; r++) { + SpringLayout.Constraints constraints = + getConstraintsForCell(r, c, parent, cols); + constraints.setX(x); + constraints.setWidth(width); + } + x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad))); + } + + //Align all cells in each row and make them the same height. + Spring y = Spring.constant(initialY); + for (int r = 0; r < rows; r++) { + Spring height = Spring.constant(0); + for (int c = 0; c < cols; c++) { + height = Spring.max(height, + getConstraintsForCell(r, c, parent, cols). + getHeight()); + } + for (int c = 0; c < cols; c++) { + SpringLayout.Constraints constraints = + getConstraintsForCell(r, c, parent, cols); + constraints.setY(y); + constraints.setHeight(height); + } + y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad))); + } + + //Set the parent's size. + SpringLayout.Constraints pCons = layout.getConstraints(parent); + pCons.setConstraint(SpringLayout.SOUTH, y); + pCons.setConstraint(SpringLayout.EAST, x); + } +}