SiniSoul
November 2nd, 2010, 16:12
Since I resigned from doing Perplexity at all I have resided to doing a shit load of tutorials in the next month along with the release of Unity/Harmony/Infinity.
If you don't know how to use these, don't ask me how to.
Special Note: You will get a RSString Error EVERY TIME, do this to your StreamBuffer
final String readGJString(byte i) {
anInt6813++;
byte i_66_ = (buffer[position++]);
System.out.println("ReadGJString: "+i_66_);
/*if (i_66_ != 0)
throw new IllegalStateException("Bad version number in gjstr2");*/
if (i < 45)
readShort(-105);
int i_67_ = position;
while ((buffer[position++]) != 0) {
/* empty */
}
I have no idea why, but it will send me that error. It works when you remove that.
Decrypt File:
public void execute(Player player, int size, Instream in) {
Outstream opcode = new Outstream(1);
/* PacketSize Verification */
int packetSize = in.readShort();
if(packetSize != in.getRemaining()) {
return;
}
/* Incorrect Version Verification */
int version = in.readInt();
if(version != LoginConstants.VERSION) {
opcode.writeByte(LoginConstants.OUT_OF_DATE);
player.isocket.writeOutstream(opcode);
return;
}
int a = in.readInt() & 0xff;
int b = in.readInt() & 0xff;
in.skip(20);
in.readString();
in.readInt();
/* TODO Cache Idx Verification */
int[] CacheIdxs = new int[34];
for(int i = 0; i < 34; i++) {
CacheIdxs[i] = in.readInt();
}
for(;;) {
if(in.readByte() == 10) {
break;
}
}
in.readLong();
in.readLong();
String user = Misc.formatPlayerNameForServer(Misc.longToPlayerNa me(in.readLong()));
System.out.println(user);
String pass = in.readString();
in.readLong();
in.readLong();
player.loginPlayer(user);
}
Login Reponse
public void sendLoginPacket() {
Outstream out = new Outstream(300);
Outstream out1 = new Outstream(500);
out.writeByte(player.getCredentials().getRights()) ;
out1.writeByte(2);
out1.writeByte(2);
out1.writeByte(0);
out1.writeByte(0);
out1.writeByte(0);
out1.writeShort(31);
out1.writeShort(1);
out1.writeShort(0);
out1.writeShort(player.getCredentials().getLastLog gedIn());
out1.writeInt(Misc.IPAddressToNumber("68.33.152.118"));
out1.writeByte(0);
out1.writeShort(0);
out1.writeShort(1);
out1.writeByte(0);
out1.putGJString2(player.getCredentials().getUsern ame());
out1.writeByte(0);
out1.writeInt(1);
out1.writeShort(1);
out1.putGJString2("68.33.152.118");
int length = out.getOffset();
out.writeByte((byte) length);
out.addBytes(out.buffer(), 0, length);
player.isocket.writeOutstream(out);
player.frames.sendWorldList(true);
player.frames.sendUnlockIgnoreList();
player.frames.sendUnlockFriendList();
player.frames.sendChatMessage(0, "Welcome To Perplexity!");
player.frames.sendChatMessage(11, "Welcome To Perplexity!");
}
OH And btw the world list is EXACTLY, the same as 602. So really no need to post. But here it is anyway.
Packet
public void sendWorldList(boolean getWorldConfiguration) {
Outstream worldbuffer = new Outstream(2000);
Outstream out = new Outstream(1000);
HarmonyServer.Lobby.getWorldList().loadWorldList(w orldbuffer, getWorldConfiguration);
out.writePacketVarShort(48);
out.writeByte(1);
out.addBytes(worldbuffer.getBuffer(), 0, worldbuffer.getOffset());
out.endPacketVarShort();
player.isocket.writeOutstream(out);
}
WorldList
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Harmony.util;
import Harmony.io.Outstream;
import java.util.ArrayList;
/**
* @author Hadyn Fitzgerald
* @version 1.0
*/
public class WorldList {
private static final ArrayList<WorldDef> worldList = new ArrayList<WorldDef>();
public WorldList() {
worldList.add(new WorldDef(1, 1, 1, "Alpha", "68.33.152.118", "USA", 76));
worldList.add(new WorldDef(2, 1, 1, "Beta", "68.33.152.118", "USA", 76));
worldList.add(new WorldDef(3, 1, 1, "Perplexity", "68.33.152.118", "USA", 76));
}
public void loadWorldList(Outstream out, boolean b) {
if (b == true)
getData(out, true, true);
else
getData(out, false, true);
}
public void getData(Outstream stream, boolean worldConfiguration, boolean worldStatus) {
stream.writeByte(worldStatus ? 2 : 0);
stream.writeByte(worldConfiguration ? 1 : 0);
if (worldConfiguration)
populateConfiguration(stream);
if (worldStatus)
populateStatus(stream);
}
/* COOORRREEEECCCCTTT */
private void populateConfiguration(Outstream buffer) {
putSmart(buffer, worldList.size());
setCountry(buffer);
putSmart(buffer, 0);
putSmart(buffer, (worldList.size() + 1));
putSmart(buffer, worldList.size());
for (WorldDef w : worldList) {
putSmart(buffer, w.getWorldId());
buffer.writeByte(w.getLocation());
buffer.writeInt(w.getFlag());
System.out.println("Offset Start: "+buffer.getOffset());
buffer.putGJString2(w.getActivity()); // activity
buffer.putGJString2(w.getIp()); // ip address
System.out.println("Offset End: "+buffer.getOffset());
}
buffer.writeInt(0x94DA4A87); // != 0
}
/* Correct... */
private void populateStatus(Outstream buffer) {
for (WorldDef w : worldList) {
putSmart(buffer, w.getWorldId()); // world id
int online = 0;
buffer.writeShort(online); // player count
}
}
private void putSmart(Outstream buffer, int value) {
if (value > -128)
buffer.writeByte((byte) value);
else
buffer.writeShort((short) value);
}
private void setCountry(Outstream buffer) {
for (WorldDef w : worldList) {
putSmart(buffer, w.getCountry());
buffer.putGJString2(w.getRegion());
}
}
}
WorldDef
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Harmony.util;
/**
* @author Hadyn Fitzgerald
* @version 1.0
*/
public class WorldDef {
private int worldId;
private String activity;
private int location;
private String ip;
private int flag;
private String region;
private int country;
public WorldDef(int worldId, int location, int flag, String activity, String ip, String region, int country) {
this.worldId = worldId;
this.location = location;
this.flag = flag;
this.activity = activity;
this.ip = ip;
this.region = region;
this.country = country;
}
public String getRegion() {
return region;
}
public int getCountry() {
return country;
}
public int getFlag() {
return flag;
}
public int getLocation() {
return location;
}
public String getIp() {
return ip;
}
public int getWorldId() {
return worldId;
}
public String getActivity() {
return activity;
}
}
Enjoy.
If you don't know how to use these, don't ask me how to.
Special Note: You will get a RSString Error EVERY TIME, do this to your StreamBuffer
final String readGJString(byte i) {
anInt6813++;
byte i_66_ = (buffer[position++]);
System.out.println("ReadGJString: "+i_66_);
/*if (i_66_ != 0)
throw new IllegalStateException("Bad version number in gjstr2");*/
if (i < 45)
readShort(-105);
int i_67_ = position;
while ((buffer[position++]) != 0) {
/* empty */
}
I have no idea why, but it will send me that error. It works when you remove that.
Decrypt File:
public void execute(Player player, int size, Instream in) {
Outstream opcode = new Outstream(1);
/* PacketSize Verification */
int packetSize = in.readShort();
if(packetSize != in.getRemaining()) {
return;
}
/* Incorrect Version Verification */
int version = in.readInt();
if(version != LoginConstants.VERSION) {
opcode.writeByte(LoginConstants.OUT_OF_DATE);
player.isocket.writeOutstream(opcode);
return;
}
int a = in.readInt() & 0xff;
int b = in.readInt() & 0xff;
in.skip(20);
in.readString();
in.readInt();
/* TODO Cache Idx Verification */
int[] CacheIdxs = new int[34];
for(int i = 0; i < 34; i++) {
CacheIdxs[i] = in.readInt();
}
for(;;) {
if(in.readByte() == 10) {
break;
}
}
in.readLong();
in.readLong();
String user = Misc.formatPlayerNameForServer(Misc.longToPlayerNa me(in.readLong()));
System.out.println(user);
String pass = in.readString();
in.readLong();
in.readLong();
player.loginPlayer(user);
}
Login Reponse
public void sendLoginPacket() {
Outstream out = new Outstream(300);
Outstream out1 = new Outstream(500);
out.writeByte(player.getCredentials().getRights()) ;
out1.writeByte(2);
out1.writeByte(2);
out1.writeByte(0);
out1.writeByte(0);
out1.writeByte(0);
out1.writeShort(31);
out1.writeShort(1);
out1.writeShort(0);
out1.writeShort(player.getCredentials().getLastLog gedIn());
out1.writeInt(Misc.IPAddressToNumber("68.33.152.118"));
out1.writeByte(0);
out1.writeShort(0);
out1.writeShort(1);
out1.writeByte(0);
out1.putGJString2(player.getCredentials().getUsern ame());
out1.writeByte(0);
out1.writeInt(1);
out1.writeShort(1);
out1.putGJString2("68.33.152.118");
int length = out.getOffset();
out.writeByte((byte) length);
out.addBytes(out.buffer(), 0, length);
player.isocket.writeOutstream(out);
player.frames.sendWorldList(true);
player.frames.sendUnlockIgnoreList();
player.frames.sendUnlockFriendList();
player.frames.sendChatMessage(0, "Welcome To Perplexity!");
player.frames.sendChatMessage(11, "Welcome To Perplexity!");
}
OH And btw the world list is EXACTLY, the same as 602. So really no need to post. But here it is anyway.
Packet
public void sendWorldList(boolean getWorldConfiguration) {
Outstream worldbuffer = new Outstream(2000);
Outstream out = new Outstream(1000);
HarmonyServer.Lobby.getWorldList().loadWorldList(w orldbuffer, getWorldConfiguration);
out.writePacketVarShort(48);
out.writeByte(1);
out.addBytes(worldbuffer.getBuffer(), 0, worldbuffer.getOffset());
out.endPacketVarShort();
player.isocket.writeOutstream(out);
}
WorldList
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Harmony.util;
import Harmony.io.Outstream;
import java.util.ArrayList;
/**
* @author Hadyn Fitzgerald
* @version 1.0
*/
public class WorldList {
private static final ArrayList<WorldDef> worldList = new ArrayList<WorldDef>();
public WorldList() {
worldList.add(new WorldDef(1, 1, 1, "Alpha", "68.33.152.118", "USA", 76));
worldList.add(new WorldDef(2, 1, 1, "Beta", "68.33.152.118", "USA", 76));
worldList.add(new WorldDef(3, 1, 1, "Perplexity", "68.33.152.118", "USA", 76));
}
public void loadWorldList(Outstream out, boolean b) {
if (b == true)
getData(out, true, true);
else
getData(out, false, true);
}
public void getData(Outstream stream, boolean worldConfiguration, boolean worldStatus) {
stream.writeByte(worldStatus ? 2 : 0);
stream.writeByte(worldConfiguration ? 1 : 0);
if (worldConfiguration)
populateConfiguration(stream);
if (worldStatus)
populateStatus(stream);
}
/* COOORRREEEECCCCTTT */
private void populateConfiguration(Outstream buffer) {
putSmart(buffer, worldList.size());
setCountry(buffer);
putSmart(buffer, 0);
putSmart(buffer, (worldList.size() + 1));
putSmart(buffer, worldList.size());
for (WorldDef w : worldList) {
putSmart(buffer, w.getWorldId());
buffer.writeByte(w.getLocation());
buffer.writeInt(w.getFlag());
System.out.println("Offset Start: "+buffer.getOffset());
buffer.putGJString2(w.getActivity()); // activity
buffer.putGJString2(w.getIp()); // ip address
System.out.println("Offset End: "+buffer.getOffset());
}
buffer.writeInt(0x94DA4A87); // != 0
}
/* Correct... */
private void populateStatus(Outstream buffer) {
for (WorldDef w : worldList) {
putSmart(buffer, w.getWorldId()); // world id
int online = 0;
buffer.writeShort(online); // player count
}
}
private void putSmart(Outstream buffer, int value) {
if (value > -128)
buffer.writeByte((byte) value);
else
buffer.writeShort((short) value);
}
private void setCountry(Outstream buffer) {
for (WorldDef w : worldList) {
putSmart(buffer, w.getCountry());
buffer.putGJString2(w.getRegion());
}
}
}
WorldDef
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Harmony.util;
/**
* @author Hadyn Fitzgerald
* @version 1.0
*/
public class WorldDef {
private int worldId;
private String activity;
private int location;
private String ip;
private int flag;
private String region;
private int country;
public WorldDef(int worldId, int location, int flag, String activity, String ip, String region, int country) {
this.worldId = worldId;
this.location = location;
this.flag = flag;
this.activity = activity;
this.ip = ip;
this.region = region;
this.country = country;
}
public String getRegion() {
return region;
}
public int getCountry() {
return country;
}
public int getFlag() {
return flag;
}
public int getLocation() {
return location;
}
public String getIp() {
return ip;
}
public int getWorldId() {
return worldId;
}
public String getActivity() {
return activity;
}
}
Enjoy.