Thread: Converting Hyperion to #484

Results 1 to 5 of 5
  1. #1 Converting Hyperion to #484 
    Banned

    Join Date
    Sep 2010
    Age
    29
    Posts
    859
    Thanks given
    303
    Thanks received
    203
    Rep Power
    0
    Pretty much having troubles converting hyperion to 484. Stuck at getting correct login request data (username & password obviously)

    Hyperion login:

    Code:
    		case STATE_PRECRYPTED:
    			if(in.remaining() >= 2) {
    				/*
    				 * We read the type of login.
    				 * 
    				 * 16 = normal
    				 * 18 = reconnection
    				 */
    				final int loginOpcode = in.get() & 0xFF;
    				if(loginOpcode != 16 && loginOpcode != 18) {
    					logger.info("Invalid login opcode : " + loginOpcode);
    					session.close(false);
    					in.rewind();
    					return false;
    				}
    				
    				/*
    				 * We read the size of the login packet.
    				 */
    				final int loginSize = in.get() & 0xFF;
    				
    				/*
    				 * And calculated how long the encrypted block will be.
    				 */
    				final int loginEncryptSize = loginSize - (36 + 1 + 1 + 2);
    				
    				/*
    				 * This could be invalid so if it is we ignore it.
    				 */
    				if (loginEncryptSize <= 0) {
    					logger.info("Encrypted packet size zero or negative : " + loginEncryptSize);
    					session.close(false);
    					in.rewind();
    					return false;
    				}
    				session.setAttribute("state", STATE_CRYPTED);
    				session.setAttribute("size", loginSize);
    				session.setAttribute("encryptSize", loginEncryptSize);
    				return true;
    			}
    			break;
    		case STATE_CRYPTED:
    			int size = (Integer) session.getAttribute("size");
    			int encryptSize = (Integer) session.getAttribute("encryptSize");
    			if (in.remaining() >= size) {
    				/*
    				 * We now read a short which is the client version and
    				 * check if it equals 484.
    				 */
    				final int version = in.getInt();
    				if(version != Server.VERSION) {
    					logger.info("Incorrect version : " + version);
    					session.close(false);
    					in.rewind();
    					return false;
    				}
    				
    				/*
    				 * Is the player using a low memory version of the game?
    				 */
    				boolean lowMemoryVersion = (in.get() & 0xFF) == 1;
    				
    				/*
    				 * The cache indexes.
    				 */
    				for (int a = 0; a < 24; a++) {
    					final int cacheIndexes = in.get();
    				}
    				
    				/*
    				 * Gathers up all the junk integers.
    				 */
    				for (int b = 0; b < 16; b++) {
    					final int junk = in.getInt();
    				}
    				
    				/*
    				 * The encrypted size includes the size byte which we don't
    				 * need.
    				 */
    				encryptSize--;
    				
    				/*
    				 * We now read the encrypted block opcode (although in most
    				 * 317 clients and this server the RSA is disabled) and
    				 * check it is equal to 10.
    				 */
    				final int blockOpcode = in.get() & 0xFF;
    				if (blockOpcode != 10) {
    					logger.info("Invalid login block opcode : " + blockOpcode);
    					session.close(false);
    					in.rewind();
    					return false;
    				}
    
    				/*
    				 * We read the client's session key.
    				 */
    				long clientKey = in.getLong();
    				
    				/*
    				 * And verify it has the correct server session key.
    				 */
    				long serverKey = (Long) session.getAttribute("serverKey");
    				long reportedServerKey = in.getLong();
    				if (reportedServerKey != serverKey) {
    					logger.info("Server key mismatch (expected : " + serverKey + ", reported : " + reportedServerKey + ")");
    					session.close(false);
    					in.rewind();
    					return false;
    				}
    				
    				/*
    				 * We read and format the name and passwords.
    				 */
    				final String name = NameUtils.longToName(in.getLong());
    				final String pass = IoBufferUtils.getRS2String(in);
    				logger.info("Login request : username=" + name + " password=" + pass);
    				
    				/*
    				 * And setup the ISAAC cipher which is used to encrypt and
    				 * decrypt opcodes.
    				 * 
    				 * However, without RSA, this is rendered useless anyway.
    				 */
    				int[] sessionKey = new int[4];
    				sessionKey[0] = (int) (clientKey >> 32);
    				sessionKey[1] = (int) clientKey;
    				sessionKey[2] = (int) (serverKey >> 32);
    				sessionKey[3] = (int) serverKey;
    				
    				session.removeAttribute("state");
    				session.removeAttribute("serverKey");
    				session.removeAttribute("size");
    				session.removeAttribute("encryptSize");
    				
    				ISAACCipher inCipher = new ISAACCipher(sessionKey);
    				for(int i = 0; i < 4; i++) {
    					sessionKey[i] += 50;
    				}
    				ISAACCipher outCipher = new ISAACCipher(sessionKey);
    				
    				/*
    				 * Now, the login has completed, and we do the appropriate
    				 * things to fire off the chain of events which will load
    				 * and check the saved games etc.
    				 */
    				session.getFilterChain().remove("protocol");
    				session.getFilterChain().addFirst("protocol", new ProtocolCodecFilter(RS2CodecFactory.GAME));
    				
    				PlayerDetails pd = new PlayerDetails(session, name, pass,  inCipher, outCipher);
    				//World.getWorld().load(pd);
    			}
    			break;
    RS2HD login:

    Code:
    				case 1: // here's where we get the username and
    					// password
    					@SuppressWarnings("unused")
    					int loginType = -1,
    					loginPacketSize = -1;
    					if (3 <= in.remaining()) {
    						loginType = in.get() & 0xff; // should
    						// be
    						// 16
    						// or
    						// 18
    						loginPacketSize = in.get() & 0xff;
    						// Logger.log("loginType="+loginType);
    					} else {
    						in.rewind();
    						return false;
    					}
    					if (loginPacketSize <= in.remaining()) {
    						byte[] payload = new byte[loginPacketSize];
    						in.get(payload);
    						Packet p = new Packet(session, -1, payload);
    						@SuppressWarnings("unused")
    						int loginEncryptPacketSize = loginPacketSize - (36 + 1 + 1 + 2); // can't
    						// be
    						// negative
    						int clientVersion = p.readInt();
    						if (clientVersion != 484) {
    							logger.warning("Client is using wrong revision: " + clientVersion + "!");
    						}
    						@SuppressWarnings("unused")
    						int lowMemoryVersion = p.readByte() & 0xff;
    
    						for (int n = 0; n < 24; n++) {
    							@SuppressWarnings("unused")
    							int cachIDX = p.readByte();
    						}
    						for (int n = 0; n < 16; n++) {
    							@SuppressWarnings("unused")
    							int junk = p.readInt();
    						}
    						int tmpEncryptPacketSize = p.readByte() & 0xff; // hopefully
    						// same as
    						// (--loginEncryptPacketSize)
    						if (tmpEncryptPacketSize != 10) {
    							@SuppressWarnings("unused")
    							int encryptPacketId = p.readByte() & 0xff; // hopefully
    							// 10
    						}
    						long clientSessionKey = p.readLong();
    						long serverSessionKey = p.readLong();
    						// int uid = p.readInt();
    						// //unique identifier for this
    						// session i think ?
    						String user = Misc.longToPlayerName(p.readLong()), // given
    						// username
    						pass = p.readRS2String(); // given
    						// password
    
    						int sessionKey[] = new int[4];
    						sessionKey[0] = (int) (clientSessionKey >> 32);
    						sessionKey[1] = (int) clientSessionKey;
    						sessionKey[2] = (int) (serverSessionKey >> 32);
    						sessionKey[3] = (int) serverSessionKey;
    
    						// session.setAttribute("ISAAC_IN",
    						// new
    						// ISAACCipher(sessionKey));
    						for (int i = 0; i < 4; i++) {
    							sessionKey[i] += 50;
    						}
    						// session.setAttribute("ISAAC_OUT",
    						// new
    						// ISAACCipher(sessionKey));
    
    						session.removeAttribute("LOGIN_STAGE");
    
    						/**
    						 * Here's where we add the user
    						 * to the login queue, and if
    						 * the login is accepted, we
    						 * change their session filter
    						 * to a standard
    						 * RS2ProtocolCodec.
    						 */
    						logger.debug("Login request: [username = " + user + ",password = " + pass + "].");
    
    						PlayerDetails d = new PlayerDetails(user, pass, session);
    						workerThread.loadPlayer(d);
    
    						session.setIdleTime(IdleStatus.BOTH_IDLE, Constants.SESSION_IDLE_TIME);
    
    						session.getFilterChain().remove("protocolFilter");
    						session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new CodecFactory()));
    
    						return true;
    					} else {
    						in.rewind();
    						return false;
    					}
    Debug login request hyperion:

    Code:
    19-feb-2011 14:49:29 org.espeon.rs2.net.codec.RS2LoginDecoder doDecode
    INFO: Login request : username=lol password=lol[]


    HALP
     

  2. #2  
    Community Veteran


    Join Date
    Jan 2008
    Posts
    2,659
    Thanks given
    494
    Thanks received
    627
    Rep Power
    980
    Make sure you change getRS2String() so that it stops reading after it reaches the null character (0) instead of the newline character (10).
    Code:
    public static String getRS2String(IoBuffer buf) {
    	StringBuilder bldr = new StringBuilder();
    	byte b;
    	while(buf.hasRemaining() && (b = buf.get()) != 0) {
    		bldr.append((char) b);
    	}
    	return bldr.toString();
    }
    Edit: Not sure what you're doing here:
    Code:
    /*
     * The cache indexes.
     */
    for (int a = 0; a < 24; a++) {
    	final int cacheIndexes = in.get();
    }
    	
    /*
     * Gathers up all the junk integers.
     */
    for (int b = 0; b < 16; b++) {
    	final int junk = in.getInt();
    }
    You should only be reading the checksums. How many .idx files (excluding .idx255) are there in your cache?
    ~iKilem
     

  3. #3  
    Banned

    Join Date
    Sep 2010
    Age
    29
    Posts
    859
    Thanks given
    303
    Thanks received
    203
    Rep Power
    0
    Quote Originally Posted by iKilem View Post
    Make sure you change getRS2String() so that it stops reading after it reaches the null character (0) instead of the newline character (10).
    Code:
    public static String getRS2String(IoBuffer buf) {
    	StringBuilder bldr = new StringBuilder();
    	byte b;
    	while(buf.hasRemaining() && (b = buf.get()) != 0) {
    		bldr.append((char) b);
    	}
    	return bldr.toString();
    }
    Thank you, It worked.

    Neither do I actually, I just read up what rs2hd had and did the same thing. Doesn't matter to me anyway as long it's all correct. 16 idx files btw.
     

  4. #4  
    Community Veteran


    Join Date
    Jan 2008
    Posts
    2,659
    Thanks given
    494
    Thanks received
    627
    Rep Power
    980
    Ah right I know now. I didn't think the 24 byte thing was present in clients as early as #484. They're not cache indexes btw and the ints you labelled junk are the checksums of the file information tables.
    ~iKilem
     

  5. #5  
     

    Vastiko's Avatar
    Join Date
    Dec 2006
    Posts
    5,700
    Thanks given
    300
    Thanks received
    663
    Rep Power
    5000
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [PJA/Hyperion] Custom Object Loading [PJA/Hyperion]
    By helloevery1 in forum Snippets
    Replies: 20
    Last Post: 11-06-2012, 12:25 AM
  2. Replies: 6
    Last Post: 06-16-2010, 01:45 PM
  3. Help converting to Hyperion.
    By Lord Military in forum Help
    Replies: 1
    Last Post: 04-23-2010, 02:09 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •