Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSRS Integration #473

Open
wants to merge 63 commits into
base: kotlin-experiments
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
0930e66
Cache definitions, update server and most of login done for rev 181.
Feb 29, 2020
910a9c6
Replaced numeric constant '181' with the release revision.
Feb 29, 2020
36ee4c0
Bumped the JDK version in the azure-pipelines.yml to 11 from 1.8.
Feb 29, 2020
1f6041c
Binding on the same port is now filtered out. This occurs when the ne…
Feb 29, 2020
662570e
Login decoding updated to OSRS.
Mar 1, 2020
b901cb5
Documented user stats.
Mar 1, 2020
0cf9710
Updated UserStats to revision 8.
Mar 1, 2020
86cc048
Worldlist is now available. Currently it's just magic constants until…
Mar 1, 2020
72292a2
Worldlist is now available. Currently it's just magic constants until…
Mar 2, 2020
071b04d
Added the following encode messages: Varp
Mar 2, 2020
570745a
Player options decoders.
Mar 3, 2020
a45b4d3
Npc options decoders.
Mar 3, 2020
e0e3bd7
Refractored the directories in which each file lives. This seems more…
Mar 3, 2020
b0c0918
Refractored the directories in which each file lives. This seems more…
Mar 3, 2020
1e133f6
Changes the writeString(...) method's in BufferUtil.java to use Windo…
Mar 4, 2020
b4a3a62
Login to World complete.
Mar 11, 2020
3ef4250
InterfaceSet.java is updated to support osrs functionality.
Mar 15, 2020
4362b4f
Reduces the move-toplevel code.
Mar 15, 2020
db9a443
Experience and Weight Encoder messages.
Mar 15, 2020
ccc7e0f
Added the run-energy message.
Mar 15, 2020
9fcb2fd
Organized imports.
Mar 15, 2020
3ac6b6b
Added the plugins for shops back with proper npc ids.
Mar 15, 2020
7fe0272
Added the plugins for shops back with proper npc ids.
Mar 15, 2020
f972fd1
Fixes spawns with modern names.
Mar 15, 2020
a0d9869
Gets rid of leak from the ondemand response encoder.
Mar 15, 2020
060053e
Added SetPlayerActionMessageEncoder message.
Mar 22, 2020
948fad1
Inventory messages are complete.
Mar 22, 2020
ac27c8e
Item-interface interactions complete.
Mar 24, 2020
ef75cda
Ground items interactions complete.
Mar 25, 2020
62bd614
Moved around some decoder messages.
Mar 25, 2020
48e3fc4
Did a ton of encoder messages for interfaces.
Mar 26, 2020
a9ea8d2
Standard field names.
Mar 26, 2020
0f7a35e
Added logout message and set flag message.
Mar 26, 2020
8d3c198
Added logout message and set flag message.
Mar 26, 2020
677e994
Action support for clicks.
Mar 27, 2020
8a3db74
Moved a ton of messages.
Mar 27, 2020
1cd9a17
GPI nearly complete. Still need masks. Going to clean up the code more.
Apr 5, 2020
0a1ef20
GPI nearly complete. Still need masks. Going to clean up the code more.
Apr 10, 2020
f96ef85
Gpi done.
Apr 12, 2020
d00c6b4
Fixes compiler error on chat (somehow didn't get versioned)
Apr 12, 2020
028663d
Teleport happens post-tick.
Apr 12, 2020
65309ab
Added tutorial island wood and oak tree identifiers.
Apr 12, 2020
15833bf
Fixes title mask flag.
Apr 12, 2020
bbc0e13
Keyboard event added.
Apr 12, 2020
ac00bc2
ChatFilterSettingsMessage added.
Apr 12, 2020
c858ac4
Removed item option, we should have one consistent message for that.
Apr 13, 2020
5037fff
Fixes issue with inventory and component id being swapped.
Apr 13, 2020
88928e9
Removed some debug statements from GPI.
Apr 13, 2020
deb1a17
Zone packets, add and remove object messages.
Apr 13, 2020
c9f5e73
Added proper priorities and the UpdateZonePartialEnclosedEncoder.
Apr 13, 2020
0c92c9f
Finished supported map zone packets.
Apr 14, 2020
a15165b
Added unsupported map zone packets.
Apr 15, 2020
d56d375
Fixes issue with crash when changing regions.
Apr 15, 2020
4cbe700
Adds more packets to queue, previous limit was 25 packets. Osrs can h…
Apr 15, 2020
7b5b158
Adds huffman codec class to properly compress/decompress mesasges.
Apr 20, 2020
4af53e9
Fixes problem that broke pub chat. Still need to fix compression for …
Apr 20, 2020
4bddfe2
Fixes issue with HuffmanCodec
Apr 22, 2020
04ab087
Fixes codec issues.
Apr 22, 2020
79ac1a8
Fixes issue with HuffmanCodec
Apr 22, 2020
ba28a23
Friends list interactions complete.
Apr 22, 2020
e393743
Ignores list complete.
Apr 22, 2020
bfb2619
All the changes that sfix has asked for.
Apr 26, 2020
ba35a57
Code review pass #2 osrs-proposal
May 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion cache/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
implementation group: 'org.tukaani', name: 'xz', version: '1.8'
implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.1'
implementation group: 'org.apache.ant', name: 'ant', version: '1.10.7'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we depending on ant?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... can it be removed?

implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.11.0.rc1'

test.useJUnitPlatform()
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitJupiterVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ private ObjectDefinition decode(int id, CacheBuffer buffer) {

definition.getMorphisms()[1 + length] = model;
} else if (opcode == 78) {
definition.setF2117(buffer.readUShort());
definition.setF2118(buffer.readUByte());
definition.setSound(buffer.readUShort());
definition.setSoundRadius(buffer.readUByte());
} else if (opcode == 79) {
definition.setF2119(buffer.readUShort());
definition.setF2120(buffer.readUShort());
definition.setF2118(buffer.readUByte());
definition.setSoundDelayMinDuration(buffer.readUShort());
definition.setSoundDelayMaxDuration(buffer.readUShort());
definition.setSoundRadius(buffer.readUByte());
final int count = buffer.readUByte();
definition.setF2121(new int[count]);
definition.setSounds(new int[count]);
for (int i = 0; i < count; i++)
definition.getF2121()[i] = buffer.readUShort();
definition.getSounds()[i] = buffer.readUShort();
} else if (opcode == 81) {
definition.setAdjustValue(buffer.readUByte() * 256);
} else if (opcode == 82) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package org.apollo.cache.decoder.rsenum;

import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.apollo.cache.Archive;
import org.apollo.cache.Cache;
import org.apollo.cache.CacheBuffer;
import org.apollo.cache.RSFile;
import org.apollo.cache.def.EnumDefinition;

import java.util.HashMap;

/**
* Decodes item data from the {@code obj.dat} file into {@link EnumDefinition}s.
* Decodes archive two folder eight into {@link EnumDefinition}s.
*
* @author Graham
* @author Cjay0091
*/
public final class EnumDefinitionDecoder implements Runnable {

Expand Down Expand Up @@ -65,14 +65,14 @@ private EnumDefinition decode(int id, CacheBuffer buffer) {
def.setDefaultInt(buffer.readInt());
} else if (opcode == 5) {
final var size = buffer.readUShort();
final var values = new Int2ObjectOpenHashMap<String>(size);
final var values = new HashMap<Integer, String>(size);
for (int index = 0; index < size; index++) {
values.put(buffer.readInt(), buffer.readString());
}
def.setStringValues(values);
} else if (opcode == 6) {
final var size = buffer.readUShort();
final var values = new Int2IntOpenHashMap(size);
final var values = new HashMap<Integer, Integer>(size);
for (int index = 0; index < size; index++) {
values.put(buffer.readInt(), buffer.readInt());
}
Expand Down
14 changes: 6 additions & 8 deletions cache/src/main/java/org/apollo/cache/def/EnumDefinition.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.apollo.cache.def;

import com.google.common.base.Preconditions;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.apollo.cache.decoder.rsenum.ScriptVarType;

import java.util.HashMap;
Expand Down Expand Up @@ -60,8 +58,8 @@ public static EnumDefinition lookup(int id) {
private ScriptVarType valType = ScriptVarType.INTEGER;
private int defaultInt = 0;
private String defaultString = "";
private Int2IntOpenHashMap intValues;
private Int2ObjectOpenHashMap<String> stringValues;
private HashMap<Integer, Integer> intValues;
private HashMap<Integer, String> stringValues;

/**
* Creates a new enum definition.
Expand Down Expand Up @@ -122,19 +120,19 @@ public void setDefaultString(String defaultString) {
this.defaultString = defaultString;
}

public Int2IntOpenHashMap getIntValues() {
public HashMap<Integer, Integer> getIntValues() {
return intValues;
}

public void setIntValues(Int2IntOpenHashMap intValues) {
public void setIntValues(HashMap<Integer, Integer> intValues) {
this.intValues = intValues;
}

public Int2ObjectOpenHashMap<String> getStringValues() {
public HashMap<Integer, String> getStringValues() {
return stringValues;
}

public void setStringValues(Int2ObjectOpenHashMap<String> stringValues) {
public void setStringValues(HashMap<Integer, String> stringValues) {
this.stringValues = stringValues;
}
}
Expand Down
184 changes: 184 additions & 0 deletions cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
package org.apollo.cache.def;

/**
* @author Khaled Abdeljaber
*/
public final class HuffmanCodec {

private static HuffmanCodec codec;

public static void init(int[] codes, byte[] codeLengths, int[] tree) {
codec = new HuffmanCodec(codes, codeLengths, tree);
}

public static String decompress(byte[] compressed) {
return codec.decompress_(compressed);
}

public static byte[] compress(String str) {
return codec.compress_(str, str.length() + 1);
}

/**
* The codes of the huffman.
*/
private final int[] codes;

/**
* The frequencies of the codes.
*/
private final byte[] codeLengths;

/**
* The indicies of the tree.
*/
private final int[] tree;

public HuffmanCodec(int[] codes, byte[] codeLengths, int[] tree) {
this.codes = codes;
this.codeLengths = codeLengths;
this.tree = tree;
}

/**
* Decompress a string.
*
* @param compressed the compressed string.
* @return the decompressed string.
*/
String decompress_(byte[] compressed) {
if (compressed.length == 0) return "";

var len = compressed[0] & 0xFF;
var off = 1;
StringBuilder builder = new StringBuilder();

var index = 0;
for (; ; ) {
var compressedByte = compressed[off++];
for (var mask = 0x80; mask != 0; mask >>= 1) {
if ((compressedByte & mask) == 0) {
index++;
} else {
index = tree[index];
}

var chr = tree[index];
if (chr < 0) {
builder.append((char) ((chr & 0xFF) ^ 0xFF));
if (builder.length() >= len) return builder.toString();

index = 0;
}
}
}
}

/**
* Compress a string.
*
* @param str the str
* @return the length
*/
byte[] compress_(String str, int compressedLength) {
var uncompressedLength = str.length();
var dest = new byte[compressedLength];

var bitPos = 8;
dest[0] = (byte) uncompressedLength;
if (uncompressedLength >= 0xFF) {
bitPos += 8;
dest[1] = (byte) ((uncompressedLength >> 16) & 0xFF);
}

var key = 0;
for (var i = 0; i < uncompressedLength; i++) {
var character = lookup(str.charAt(i)) & 0xFF;
var code = codes[character];
var length = codeLengths[character];

var off = bitPos >> 3;
var remainder = bitPos & 0x7;
var end = off + (length + remainder - 1 >> 3);

key &= (-remainder >> 31);
bitPos += length;

remainder += 24;
dest[off] = (byte) (key |= code >>> remainder);

for (var j = 0; j < 4 && off < end; j++) {
remainder -= 8;
if (j == 3) {
dest[++off] = (byte) (key = code << -remainder);
} else {
dest[++off] = (byte) (key = code >>> remainder);
}
}
}

return dest;
}

private static byte lookup(char character) {
if (character > 0 && character < 128 || character >= 160 && character <= 255) {
return (byte) character;
} else if (character == 8364) {
return -128;
} else if (character == 8218) {
return -126;
} else if (character == 402) {
return -125;
} else if (character == 8222) {
return -124;
} else if (character == 8230) {
return -123;
} else if (character == 8224) {
return -122;
} else if (character == 8225) {
return -121;
} else if (character == 710) {
return -120;
} else if (character == 8240) {
return -119;
} else if (character == 352) {
return -118;
} else if (character == 8249) {
return -117;
} else if (character == 338) {
return -116;
} else if (character == 381) {
return -114;
} else if (character == 8216) {
return -111;
} else if (character == 8217) {
return -110;
} else if (character == 8220) {
return -109;
} else if (character == 8221) {
return -108;
} else if (character == 8226) {
return -107;
} else if (character == 8211) {
return -106;
} else if (character == 8212) {
return -105;
} else if (character == 732) {
return -104;
} else if (character == 8482) {
return -103;
} else if (character == 353) {
return -102;
} else if (character == 8250) {
return -101;
} else if (character == 339) {
return -100;
} else if (character == 382) {
return -98;
} else if (character == 376) {
return -97;
} else {
return 63;
}
}
}
50 changes: 25 additions & 25 deletions cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ public static ObjectDefinition lookup(int id) {
private int varbit;
private int varp;
private int[] morphisms;
private int f2117;
private int f2118;
private int f2119;
private int f2120;
private int[] f2121;
private int sound;
private int soundRadius;
private int soundDelayMinDuration;
private int soundDelayMaxDuration;
private int[] sounds;
private boolean members;
private int mapSceneType;
private int[] animations;
Expand Down Expand Up @@ -562,44 +562,44 @@ public void setMorphisms(int[] morphisms) {
this.morphisms = morphisms;
}

public int getF2117() {
return f2117;
public int getSound() {
return sound;
}

public void setF2117(int f2117) {
this.f2117 = f2117;
public void setSound(int f2117) {
this.sound = f2117;
}

public int getF2118() {
return f2118;
public int getSoundRadius() {
return soundRadius;
}

public void setF2118(int f2118) {
this.f2118 = f2118;
public void setSoundRadius(int soundRadius) {
this.soundRadius = soundRadius;
}

public int getF2119() {
return f2119;
public int getSoundDelayMinDuration() {
return soundDelayMinDuration;
}

public void setF2119(int f2119) {
this.f2119 = f2119;
public void setSoundDelayMinDuration(int soundDelayMinDuration) {
this.soundDelayMinDuration = soundDelayMinDuration;
}

public int getF2120() {
return f2120;
public int getSoundDelayMaxDuration() {
return soundDelayMaxDuration;
}

public void setF2120(int f2120) {
this.f2120 = f2120;
public void setSoundDelayMaxDuration(int soundDelayMaxDuration) {
this.soundDelayMaxDuration = soundDelayMaxDuration;
}

public int[] getF2121() {
return f2121;
public int[] getSounds() {
return sounds;
}

public void setF2121(int[] f2121) {
this.f2121 = f2121;
public void setSounds(int[] sounds) {
this.sounds = sounds;
}

public boolean isMembers() {
Expand Down
Loading