Files
runelite/runescape-client/src/main/java/NetSocket.java
2021-12-09 15:21:52 +02:00

330 lines
7.9 KiB
Java

import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import net.runelite.mapping.Export;
import net.runelite.mapping.Implements;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
@ObfuscatedName("ff")
@Implements("NetSocket")
public final class NetSocket extends AbstractSocket implements Runnable {
@ObfuscatedName("er")
@ObfuscatedSignature(
descriptor = "Lkz;"
)
@Export("archive9")
static Archive archive9;
@ObfuscatedName("c")
@Export("inputStream")
InputStream inputStream;
@ObfuscatedName("b")
@Export("outputStream")
OutputStream outputStream;
@ObfuscatedName("p")
@Export("socket")
Socket socket;
@ObfuscatedName("m")
@Export("isClosed")
boolean isClosed;
@ObfuscatedName("t")
@ObfuscatedSignature(
descriptor = "Leb;"
)
@Export("taskHandler")
TaskHandler taskHandler;
@ObfuscatedName("s")
@ObfuscatedSignature(
descriptor = "Lfk;"
)
@Export("task")
Task task;
@ObfuscatedName("j")
@Export("outBuffer")
byte[] outBuffer;
@ObfuscatedName("w")
@ObfuscatedGetter(
intValue = -1984666421
)
@Export("outLength")
int outLength;
@ObfuscatedName("n")
@ObfuscatedGetter(
intValue = 773716871
)
@Export("outOffset")
int outOffset;
@ObfuscatedName("r")
@Export("exceptionWriting")
boolean exceptionWriting;
@ObfuscatedName("o")
@ObfuscatedGetter(
intValue = 1772673061
)
@Export("bufferLength")
final int bufferLength;
@ObfuscatedName("v")
@ObfuscatedGetter(
intValue = -19944007
)
@Export("maxPacketLength")
final int maxPacketLength;
@ObfuscatedSignature(
descriptor = "(Ljava/net/Socket;Leb;I)V"
)
public NetSocket(Socket var1, TaskHandler var2, int var3) throws IOException {
this.isClosed = false; // L: 16
this.outLength = 0; // L: 20
this.outOffset = 0; // L: 21
this.exceptionWriting = false; // L: 22
this.taskHandler = var2;
this.socket = var1; // L: 29
this.bufferLength = var3; // L: 30
this.maxPacketLength = var3 - 100; // L: 31
this.socket.setSoTimeout(30000);
this.socket.setTcpNoDelay(true);
this.socket.setReceiveBufferSize(65536);
this.socket.setSendBufferSize(65536);
this.inputStream = this.socket.getInputStream();
this.outputStream = this.socket.getOutputStream();
}
@ObfuscatedName("c")
@ObfuscatedSignature(
descriptor = "(I)V",
garbageValue = "-2099219864"
)
@Export("close")
public void close() {
if (!this.isClosed) { // L: 41
synchronized(this) { // L: 42
this.isClosed = true; // L: 43
this.notifyAll(); // L: 44
} // L: 45
if (this.task != null) { // L: 46
while (this.task.status == 0) { // L: 47
Bounds.method6608(1L); // L: 48
}
if (this.task.status == 1) { // L: 50
try {
((Thread)this.task.result).join(); // L: 52
} catch (InterruptedException var3) { // L: 54
}
}
}
this.task = null; // L: 57
}
} // L: 58
@ObfuscatedName("b")
@ObfuscatedSignature(
descriptor = "(B)I",
garbageValue = "-44"
)
@Export("readUnsignedByte")
public int readUnsignedByte() throws IOException {
return this.isClosed ? 0 : this.inputStream.read(); // L: 65 66
}
@ObfuscatedName("p")
@ObfuscatedSignature(
descriptor = "(I)I",
garbageValue = "-1579083707"
)
@Export("available")
public int available() throws IOException {
return this.isClosed ? 0 : this.inputStream.available(); // L: 70 71
}
@ObfuscatedName("m")
@ObfuscatedSignature(
descriptor = "(II)Z",
garbageValue = "1654551476"
)
@Export("isAvailable")
public boolean isAvailable(int var1) throws IOException {
if (this.isClosed) { // L: 75
return false;
} else {
return this.inputStream.available() >= var1; // L: 76
}
}
@ObfuscatedName("t")
@ObfuscatedSignature(
descriptor = "([BIIS)I",
garbageValue = "909"
)
@Export("read")
public int read(byte[] var1, int var2, int var3) throws IOException {
if (this.isClosed) { // L: 80
return 0;
} else {
int var4;
int var5;
for (var4 = var3; var3 > 0; var3 -= var5) { // L: 81 82 86
var5 = this.inputStream.read(var1, var2, var3); // L: 83
if (var5 <= 0) { // L: 84
throw new EOFException();
}
var2 += var5; // L: 85
}
return var4; // L: 88
}
}
@ObfuscatedName("s")
@ObfuscatedSignature(
descriptor = "([BIIB)V",
garbageValue = "-34"
)
@Export("write0")
void write0(byte[] var1, int var2, int var3) throws IOException {
if (!this.isClosed) { // L: 92
if (this.exceptionWriting) { // L: 93
this.exceptionWriting = false; // L: 94
throw new IOException(); // L: 95
} else {
if (this.outBuffer == null) { // L: 97
this.outBuffer = new byte[this.bufferLength];
}
synchronized(this) { // L: 98
for (int var5 = 0; var5 < var3; ++var5) { // L: 99
this.outBuffer[this.outOffset] = var1[var5 + var2]; // L: 100
this.outOffset = (this.outOffset + 1) % this.bufferLength; // L: 101
if ((this.maxPacketLength + this.outLength) % this.bufferLength == this.outOffset) { // L: 102
throw new IOException(); // L: 103
}
}
if (this.task == null) { // L: 106
this.task = this.taskHandler.newThreadTask(this, 3); // L: 107
}
this.notifyAll(); // L: 109
}
}
}
} // L: 111
@ObfuscatedName("j")
@ObfuscatedSignature(
descriptor = "([BIII)V",
garbageValue = "-1320460000"
)
@Export("write")
public void write(byte[] var1, int var2, int var3) throws IOException {
this.write0(var1, var2, var3); // L: 161
} // L: 162
public void run() {
try {
while (true) {
label84: {
int var1;
int var2;
synchronized(this) { // L: 118
if (this.outOffset == this.outLength) { // L: 119
if (this.isClosed) { // L: 120
break label84;
}
try {
this.wait(); // L: 122
} catch (InterruptedException var10) { // L: 124
}
}
var2 = this.outLength; // L: 126
if (this.outOffset >= this.outLength) { // L: 127
var1 = this.outOffset - this.outLength;
} else {
var1 = this.bufferLength - this.outLength; // L: 128
}
}
if (var1 <= 0) { // L: 130
continue;
}
try {
this.outputStream.write(this.outBuffer, var2, var1); // L: 132
} catch (IOException var9) { // L: 134
this.exceptionWriting = true; // L: 135
}
this.outLength = (var1 + this.outLength) % this.bufferLength; // L: 137
try {
if (this.outLength == this.outOffset) { // L: 139
this.outputStream.flush();
}
} catch (IOException var8) { // L: 141
this.exceptionWriting = true; // L: 142
}
continue;
}
try {
if (this.inputStream != null) { // L: 147
this.inputStream.close();
}
if (this.outputStream != null) { // L: 148
this.outputStream.close();
}
if (this.socket != null) { // L: 149
this.socket.close();
}
} catch (IOException var7) { // L: 151
}
this.outBuffer = null; // L: 152
break;
}
} catch (Exception var12) { // L: 154
AccessFile.RunException_sendStackTrace((String)null, var12); // L: 155
}
} // L: 157
protected void finalize() {
this.close(); // L: 61
} // L: 62
@ObfuscatedName("b")
@ObfuscatedSignature(
descriptor = "(CI)Z",
garbageValue = "320078998"
)
static final boolean method3119(char var0) {
return var0 == 160 || var0 == ' ' || var0 == '_' || var0 == '-'; // L: 28
}
@ObfuscatedName("b")
@ObfuscatedSignature(
descriptor = "(Lku;IIIZI)V",
garbageValue = "1774445817"
)
public static void method3118(AbstractArchive var0, int var1, int var2, int var3, boolean var4) {
class260.musicPlayerStatus = 1; // L: 32
class124.musicTrackArchive = var0; // L: 33
VarcInt.musicTrackGroupId = var1; // L: 34
class260.musicTrackFileId = var2; // L: 35
ChatChannel.musicTrackVolume = var3; // L: 36
DynamicObject.musicTrackBoolean = var4; // L: 37
class260.pcmSampleLength = 10000; // L: 38
} // L: 39
}