append() public méthode

public append ( byte data ) : void
data byte
Résultat void
Exemple #1
0
        public byte[] changeRsi(string part, int value)
        {
            string[] keys = { "sex", "body", "hat", "face", "shirt", "coat", "pants", "shoes", "gloves", "glasses", "hair", "facialdetail", "shirtcolor", "pantscolor", "coatcolor", "shoecolor", "glassescolor", "haircolor", "skintone", "tattoo", "facialdetailcolor", "leggins" };

            int pos = -1;

            for (int i = 0; i < keys.Length; i++)
            {
                if (part.Equals(keys[i].ToLower()))
                {
                    pos = i;
                    break;
                }
            }

            if (pos >= 0)
            {
                int[] current = Store.currentClient.playerData.getRsiValues();
                current[pos] = value;
                Store.currentClient.playerData.setRsiValues(current);
                byte[] rsiData = PacketsUtils.getRSIBytes(current);

                DynamicArray din             = new DynamicArray();
                byte[]       rsiChangeHeader = { 0x02, 0x00, 0x02, 0x80, 0x89 };
                din.append(rsiChangeHeader);
                din.append(rsiData);

                return(din.getBytes());
            }
            else
            {
                throw new FormatException("body part or clothes not found");
            }
        }
Exemple #2
0
        public void processUpdateExp()
        {
            Random    rand    = new Random();
            UInt32    expval  = (UInt32)rand.Next(1000, 200000);
            ArrayList content = new ArrayList();

            // ToDo  : Save new EXP Value in the Database and update mpm exp
            // ToDo2 : Check if exp events are running to multiple the EXP
            // The Animation
            DynamicArray expanim = new DynamicArray();

            expanim.append(0x80);
            expanim.append(0xe6);
            expanim.append(NumericalUtils.uint32ToByteArray(expval, 1));
            expanim.append(0x01); // Gain Type
            expanim.append(StringUtils.hexStringToBytes("000000"));
            Store.currentClient.messageQueue.addRpcMessage(expanim.getBytes());

            // The BAR
            DynamicArray expbar = new DynamicArray();

            expbar.append(0x80);
            expbar.append(0xe5);
            expbar.append(NumericalUtils.uint32ToByteArray(expval, 1));
            expbar.append(0x01); // Gain Type
            expbar.append(StringUtils.hexStringToBytes("000000"));
            Store.currentClient.messageQueue.addRpcMessage(expbar.getBytes());
        }
Exemple #3
0
        public byte[] changeRsi(string part, int value)
        {
            string[] keys = { "sex", "body", "hat", "face", "shirt", "coat", "pants", "shoes", "gloves", "glasses", "hair", "facialdetail", "shirtcolor", "pantscolor", "coatcolor", "shoecolor", "glassescolor", "haircolor", "skintone", "tattoo", "facialdetailcolor", "leggins" };

            int pos = -1;

            for (int i = 0; i < keys.Length; i++)
            {
                if (part.Equals(keys[i].ToLower()))
                {
                    pos = i;
                    break;
                }
            }

            if (pos >= 0)
            {
                int[] current = Store.currentClient.playerData.getRsiValues();
                current[pos] = value;
                Store.currentClient.playerData.setRsiValues(current);
                byte[] rsiData = PacketsUtils.getRSIBytes(current);

                DynamicArray din = new DynamicArray();
                byte[] rsiChangeHeader = { 0x02, 0x00, 0x02, 0x80, 0x89 };
                din.append(rsiChangeHeader);
                din.append(rsiData);

                return din.getBytes();

            }
            else
            {
                throw new FormatException("body part or clothes not found");
            }
        }
Exemple #4
0
        public void sendTCPVariableLenPacket(byte[] packet, NetworkStream client)
        {
            byte[] size     = { };
            byte[] bytesize = { };

            if (packet.Length > 127)
            {
                //Do NOT reverse here :P
                bytesize = NumericalUtils.uint16ToByteArray((UInt16)(packet.Length + 0x8000), 0);
            }
            else
            {
                bytesize = NumericalUtils.uint16ToByteArrayShort((ushort)packet.Length);
            }

            byte[] finalPacket = new byte[packet.Length + bytesize.Length];

            DynamicArray din = new DynamicArray();

            din.append(bytesize);
            din.append(packet);

            finalPacket = din.getBytes();

            try
            {
                client.Write(finalPacket, 0, finalPacket.Length);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR ex: " + ex.ToString());
                throw;
            }
            client.Flush();
        }
Exemple #5
0
        public byte[] getBytesWithHeader(bool timedRPC)
        {
            DynamicArray rpcStructure = new DynamicArray();
            byte[] noTimedHeader = {0x04};
            byte[] timedHeader = new byte[6];
            byte[] time = TimeUtils.getUnixTime();

            timedHeader[0] = 0x82;

            ArrayUtils.copy(time,0,timedHeader,1,4);
            timedHeader[5] = 0x04; // This makes it "82aabbccdd04"

            if(timedRPC)
                rpcStructure.append(timedHeader);
            else
                rpcStructure.append(noTimedHeader);

            // Calculate blocks number

            if (rpcInside==0){ // Is just 1 group of msgblocks
                rpcInside=1;
                rpcStructure.append(NumericalUtils.uint16ToByteArrayShort((UInt16)rpcInside));
                rpcStructure.append(getBytes()); //Append our own content
            }
            else{
                rpcStructure.append(NumericalUtils.uint16ToByteArrayShort((UInt16)rpcInside));
                rpcStructure.append(din.getBytes()); //Append our own content
            }

            return rpcStructure.getBytes();
        }
Exemple #6
0
        public static byte[] createTeleportPacket(int x, int y, int z)
        {
            // Adjust coords between human view and mxo format
            x = x * 100;
            y = y * 100;
            z = z * 100;
            // End adjust

            byte[] xHex = NumericalUtils.floatToByteArray(x + 0.0f, 1);
            byte[] yHex = NumericalUtils.floatToByteArray(y + 0.0f, 1);
            byte[] zHex = NumericalUtils.floatToByteArray(z + 0.0f, 1);


            byte[] header = StringUtils.hexStringToBytes("0200011c11f7025c00030000");
            byte[] tail   = StringUtils.hexStringToBytes("0000");

            DynamicArray din = new DynamicArray();

            din.append(header);
            din.append(xHex);
            din.append(yHex);
            din.append(zHex);
            din.append(tail);

            return(din.getBytes());
        }
Exemple #7
0
 public byte[] getByteContents()
 {
     DynamicArray response = new DynamicArray();
     byte[] numWorldsH = NumericalUtils.uint16ToByteArray((UInt16)numWorlds, 1);
     response.append(numWorldsH);
     response.append(worlds.getBytes());
     return response.getBytes();
 }
Exemple #8
0
        public byte[] encrypt(byte[] packet)
        {
            // Get timestamp
            byte[] timestamp = TimeUtils.getUnixTime();

            // get size
            int psize = packet.Length;
            byte[] size = NumericalUtils.uint16ToByteArray((UInt16)psize,1);

            //showPacket(size, " Size ");

            // final Packet

            DynamicArray temp = new DynamicArray();
            temp.append(size);
            temp.append(timestamp);
            temp.append(packet);

            // compute CRC32
            byte[] crc32pax = crc32.checksumB(temp.getBytes(),1);

            // Padding
            int totalLength = temp.getSize() + 4;
            int padding = 16 - (totalLength % 16);

            byte[] paddingBytes = new byte[padding];

            for (int i = 0; i < padding; i++)
            {
                paddingBytes[i] = (byte)padding;
            }

            temp.append(paddingBytes);
            tf.setIV(IV);
            tf.setKey(TF_Key);

            // We init with 2 more than needed, so no memory reservation is done on dyn array
            DynamicArray finalPlainData = new DynamicArray();

            finalPlainData.append(crc32pax);
            finalPlainData.append(temp.getBytes());

            temp = null; // Cleaning the house

            byte[] encryptedData = new byte[finalPlainData.getSize()];
            tf.encrypt(finalPlainData.getBytes(),encryptedData);

            finalPlainData = null; // Cleaning the house (2)

            // add IV before the results

            DynamicArray response = new DynamicArray();
            response.append(IV);
            response.append(encryptedData);

            // Display HEX Values after Encryption
            return response.getBytes();
        }
Exemple #9
0
        public byte[] getByteContents()
        {
            DynamicArray response = new DynamicArray();

            byte[] numWorldsH = NumericalUtils.uint16ToByteArray((UInt16)numWorlds, 1);
            response.append(numWorldsH);
            response.append(worlds.getBytes());
            return(response.getBytes());
        }
Exemple #10
0
        static public byte[] doublesToLtVector3d(double x, double y, double z)
        {
            DynamicArray din = new DynamicArray();

            din.append(NumericalUtils.doubleToByteArray(x, 1));
            din.append(NumericalUtils.doubleToByteArray(y, 1));
            din.append(NumericalUtils.doubleToByteArray(z, 1));
            return(din.getBytes());
        }
Exemple #11
0
        static public byte[] floatsToLtVector3f(float x, float y, float z)
        {
            DynamicArray din = new DynamicArray();

            din.append(NumericalUtils.floatToByteArray(x, 1));
            din.append(NumericalUtils.floatToByteArray(y, 1));
            din.append(NumericalUtils.floatToByteArray(z, 1));
            return(din.getBytes());
        }
Exemple #12
0
        public byte[] getByteContents()
        {
            DynamicArray response = new DynamicArray();

            byte[] totalCharsH = NumericalUtils.uint16ToByteArray((UInt16)totalChars, 1);
            response.append(totalCharsH);
            response.append(charData.getBytes());
            response.append(charNames.getBytes());
            return(response.getBytes());
        }
Exemple #13
0
        public void sendMarketPlaceList(WorldClient client)
        {
            // ToDo: make it dynamic with database later (but the "handler" should give the items as arguments for this method
            // List Marketplace Items

            byte[] headerSeperator = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

            // Should foreach this later on "Real Server"
            DynamicArray listItems = new DynamicArray();

            listItems.append(StringUtils.hexStringToBytes("8703000000000034bdcf1200401f00000310db6a4a")); // Foot Wear
            listItems.append(0x00);                                                                       // Seperate each item

            listItems.append(StringUtils.hexStringToBytes("2e00000003a04a000bd012000000FFFF01aedc6a4a")); // Google
            listItems.append(0x00);                                                                       // Seperate each item

            listItems.append(StringUtils.hexStringToBytes("721a000003a04a000bd012000000FFFF01aedc6a4a")); // Item Data
            listItems.append(0x00);                                                                       // Seperate each item

            listItems.append(StringUtils.hexStringToBytes("2e00000003a04a000bd01200000000FF01aedc6a4a")); // Item Data
            listItems.append(0x00);                                                                       // Seperate each item

            // get data size
            byte[] itemSize = NumericalUtils.uint16ToByteArray((UInt16)listItems.getBytes().Length, 1);

            PacketContent pak = new PacketContent();

            pak.addUint16((UInt16)RPCResponseHeaders.SERVER_LOAD_MARKERPLACE, 0);
            pak.addUintShort(9); // list offset
            pak.addByteArray(headerSeperator);
            pak.addUint16((UInt16)listItems.getBytes().Length, 1);
            pak.addByteArray(listItems.getBytes());
            client.messageQueue.addRpcMessage(pak.returnFinalPacket());
        }
Exemple #14
0
        public void sendMarketPlaceList(WorldClient client)
        {
            // ToDo: make it dynamic with database later (but the "handler" should give the items as arguments for this method
            // List Marketplace Items

            byte[] headerSeperator = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

            // Should foreach this later on "Real Server"
            DynamicArray listItems = new DynamicArray();
            listItems.append(StringUtils.hexStringToBytes("8703000000000034bdcf1200401f00000310db6a4a")); // Foot Wear
            listItems.append(0x00); // Seperate each item

            listItems.append(StringUtils.hexStringToBytes("2e00000003a04a000bd012000000FFFF01aedc6a4a")); // Google
            listItems.append(0x00); // Seperate each item

            listItems.append(StringUtils.hexStringToBytes("721a000003a04a000bd012000000FFFF01aedc6a4a")); // Item Data
            listItems.append(0x00); // Seperate each item

            listItems.append(StringUtils.hexStringToBytes("2e00000003a04a000bd01200000000FF01aedc6a4a")); // Item Data
            listItems.append(0x00); // Seperate each item

            // get data size
            byte[] itemSize = NumericalUtils.uint16ToByteArray((UInt16)listItems.getBytes().Length, 1);

            PacketContent pak = new PacketContent();
            pak.addUint16((UInt16)RPCResponseHeaders.SERVER_LOAD_MARKERPLACE, 0);
            pak.addUintShort(9); // list offset
            pak.addByteArray(headerSeperator);
            pak.addUint16((UInt16)listItems.getBytes().Length,1);
            pak.addByteArray(listItems.getBytes());
            client.messageQueue.addRpcMessage(pak.returnFinalPacket());
        }
Exemple #15
0
        public byte[] loadKnownAbilities()
        {
            DynamicArray din = new DynamicArray();

            foreach (MarginAbilityItem ability in Abilities)
            {
                Int32 finalAblityID = ability.getAbilityID() + ability.getLevel();

                string debugAbility = StringUtils.bytesToString(NumericalUtils.int32ToByteArray(finalAblityID, 1));
                din.append(NumericalUtils.uint16ToByteArray(ability.getSlot(), 1)); // slot
                din.append(NumericalUtils.int32ToByteArray(finalAblityID, 1));
            }

            return(din.getBytes());
        }
Exemple #16
0
        public byte[] getBytes()
        {
            DynamicArray rpcStructure = new DynamicArray();
            byte [] totalMsgBlocks= NumericalUtils.uint16ToByteArrayShort((UInt16)addedMsgBlocks);
            byte [] currentCounter =  getRpcBytes();

            rpcStructure.append(currentCounter);
            rpcStructure.append(totalMsgBlocks);
            rpcStructure.append(din.getBytes());

            // Increment RPC Counter

            incrementRpcCounter(addedMsgBlocks);

            return rpcStructure.getBytes();
        }
Exemple #17
0
        public void addWorld(string worldName, int worldId, int worldStatus, int worldStyle, int worldPopulation)
        {
            byte[] world = new byte[32];
            world[0] = 0x00;
            world[1] = (byte)worldId;

            for (int i = 0; i < worldName.Length; i++)
            {
                world[3 + i] = (byte)worldName[i];
            }


            world[23] = (byte)worldStatus;
            world[24] = (byte)worldStyle;


            world[25] = 0xd9;
            world[26] = 0x21;
            world[27] = 0x07;
            world[28] = 0x00;
            world[29] = 0x01;
            world[30] = 0x00;

            world[31] = (byte)worldPopulation;

            worlds.append(world);
            numWorlds++;
        }
Exemple #18
0
        public void processSelfUpdateHealthIS(UInt16 viewID, UInt16 healthC, UInt16 isC)
        {
            DynamicArray din = new DynamicArray();

            din.append(0x03);
            din.append(NumericalUtils.uint16ToByteArray(viewID, 1));
            din.append(0x02);
            din.append(0x80);
            din.append(0x80);
            din.append(0x80);
            din.append(0x50);
            din.append(NumericalUtils.uint16ToByteArray(isC, 1));
            din.append(NumericalUtils.uint16ToByteArray(healthC, 1));
            din.append(0x00);
            // ToDO SEND PAK and get real health and IS
        }
Exemple #19
0
        public void processDecreaseCash(UInt16 amount, UInt16 type)
        {
            // send 02 04 01 00 16 01 0a 80 e4 ff 00 00 00 02 00 00 00;
            byte[] header = { 0x80, 0xe4 };
            long newCash = Store.currentClient.playerData.getInfo() - (long)amount;
            Store.currentClient.playerData.setInfo(newCash);

            Store.dbManager.WorldDbHandler.savePlayer(Store.currentClient);

            DynamicArray din = new DynamicArray();
            din.append(header);
            din.append(NumericalUtils.uint32ToByteArray((UInt32)newCash, 1));
            din.append(NumericalUtils.uint16ToByteArray(type, 1));
            din.append(0x00);
            din.append(0x00);
            Store.currentClient.messageQueue.addRpcMessage(din.getBytes());
        }
Exemple #20
0
        public byte[] getBytes()
        {
            DynamicArray rpcStructure = new DynamicArray();

            byte [] totalMsgBlocks = NumericalUtils.uint16ToByteArrayShort((UInt16)addedMsgBlocks);
            byte [] currentCounter = getRpcBytes();

            rpcStructure.append(currentCounter);
            rpcStructure.append(totalMsgBlocks);
            rpcStructure.append(din.getBytes());

            // Increment RPC Counter

            incrementRpcCounter(addedMsgBlocks);

            return(rpcStructure.getBytes());
        }
Exemple #21
0
        /*
         * Add a RPC Message with size byte automatically to the queue
         */
        public void addRpcMessage(byte[] messageBlock)
        {
            byte[] rpcSizeByte;
            if (messageBlock.Length > 127)
            {
                rpcSizeByte = NumericalUtils.uint16ToByteArray((UInt16)(messageBlock.Length + 0x8000), 0);
            }
            else
            {
                rpcSizeByte = NumericalUtils.uint16ToByteArrayShort((UInt16)messageBlock.Length);
            }
            DynamicArray content = new DynamicArray();
            content.append(rpcSizeByte);
            content.append(messageBlock);

            SequencedMessage message = new SequencedMessage(content.getBytes());
            RPCMessagesQueue.Add(message);
        }
Exemple #22
0
        private static void playerRSIPacket(out DynamicArray rsiPacket, out DynamicArray creationPacket,
                                            WorldClient client, ushort spawnIdCounter)
        {
            //Create the packet for the player

            rsiPacket = new DynamicArray();
            byte[] rsi = PacketsUtils.getRSIBytes(client.playerData.getRsiValues());

            byte[] CurCombatExclusiveAbility = { 0x00, 0x10, 0x00, 0x00 };

            //TODO: fix this 03 01 00
            rsiPacket.append(new byte[] { 0x01, 0x00 });
            /////////////////////////////////////////////
            client.playerInstance.DisableAllAttributes(); //Predisable to just send what we need to spawn

            client.playerInstance.RealFirstName.enable();
            client.playerInstance.RealLastName.enable();
            client.playerInstance.Health.enable();
            client.playerInstance.MaxHealth.enable();
            client.playerInstance.YawInterval.enable(); //ROTATION
            client.playerInstance.OrganizationID.enable();

            client.playerInstance.StealthAwareness.setValue(0x01); // TODO: See what's stealth awareness
            client.playerInstance.InnerStrengthAvailable.enable();
            client.playerInstance.CharacterName.enable();

            client.playerInstance.TitleAbility.enable();
            client.playerInstance.CharacterID.enable(); // It was set when grabbing from database
            client.playerInstance.RSIDescription.setValue(rsi);
            client.playerInstance.InnerStrengthMax.enable();
            client.playerInstance.Position.enable();
            client.playerInstance.Level.enable();
            client.playerInstance.CombatantMode.setValue((byte)0x22);  //TODO: see what's combatantmode

            client.playerInstance.ReputationCypherites.enable();
            client.playerInstance.ReputationGMOrganization.enable();
            client.playerInstance.ReputationNiobe.enable();
            client.playerInstance.ReputationZionMilitary.enable();


            if (NumericalUtils.ByteArrayToUint32(client.playerInstance.FactionID.getValue(), 1) > 0)
            {
                client.playerInstance.FactionID.enable();
            }

            if (NumericalUtils.ByteArrayToUint32(client.playerInstance.CrewID.getValue(), 1) > 0)
            {
                client.playerInstance.CrewID.enable();
            }


            client.playerInstance.CurExclusiveAbility.setValue(CurCombatExclusiveAbility); //TODO: see what's this

            // ok we set all our values - lets get the generated packet for us
            creationPacket =
                Store.world.objMan.GenerateCreationPacket(client.playerInstance, 0x0000, (byte)spawnIdCounter);
        }
Exemple #23
0
 public byte[] getByteContents()
 {
     DynamicArray response = new DynamicArray();
     byte[] totalCharsH = NumericalUtils.uint16ToByteArray((UInt16)totalChars, 1);
     response.append(totalCharsH);
     response.append(charData.getBytes());
     response.append(charNames.getBytes());
     return response.getBytes();
 }
Exemple #24
0
        public byte[] loadEquippedAbilities()
        {
            DynamicArray din = new DynamicArray();

            //AbilityItem abTemp = AbilityDB.Find(delegate(AbilityItem a) { return a.getAbilityID() == id; });


            foreach (MarginAbilityItem ability in Abilities)
            {
                if (ability.getLoaded() == true)
                {
                    Int32 finalAblityID = ability.getAbilityID() + ability.getLevel();
                    din.append(NumericalUtils.uint16ToByteArray(ability.getSlot(), 1)); // slot
                    din.append(NumericalUtils.int32ToByteArray(finalAblityID, 1));
                }
            }
            return(din.getBytes());
        }
Exemple #25
0
        public void processSelfUpdateHealth(UInt16 viewId, UInt16 healthC)
        {
            // ToDo: proove to remove
            DynamicArray din = new DynamicArray();

            din.append(0x03);
            din.append(NumericalUtils.uint16ToByteArray(viewId, 1));
            din.append(0x02);
            din.append(0x80);
            din.append(0x80);
            din.append(0x80);
            din.append(0x40);
            din.append(NumericalUtils.uint16ToByteArray(healthC, 1));
            din.append(0x00);
        }
Exemple #26
0
        public void processDecreaseCash(UInt16 amount, UInt16 type)
        {
            // send 02 04 01 00 16 01 0a 80 e4 ff 00 00 00 02 00 00 00;
            byte[] header  = { 0x80, 0xe4 };
            long   newCash = Store.currentClient.playerData.getInfo() - (long)amount;

            Store.currentClient.playerData.setInfo(newCash);

            Store.dbManager.WorldDbHandler.savePlayer(Store.currentClient);

            DynamicArray din = new DynamicArray();

            din.append(header);
            din.append(NumericalUtils.uint32ToByteArray((UInt32)newCash, 1));
            din.append(NumericalUtils.uint16ToByteArray(type, 1));
            din.append(0x00);
            din.append(0x00);
            Store.currentClient.messageQueue.addRpcMessage(din.getBytes());
        }
Exemple #27
0
        public static byte[] createSystemMessage(string message, WorldClient client)
        {
            byte[] messageBytes = StringUtils.stringToBytes(message + "\x00");

            DynamicArray din = new DynamicArray();

            UInt16 messageSize = (UInt16)(message.Length + 1);

            byte[] messageSizeHex = NumericalUtils.uint16ToByteArray(messageSize, 1);

            byte[] hexContents = StringUtils.hexStringToBytes("0700000000000000000024000000000000000000000000000000000000000000000000");

            din.append((byte)RPCResponseHeaders.SERVER_CHAT_MESSAGE_RESPONSE);
            din.append(hexContents);
            din.append(messageSizeHex);
            din.append(messageBytes);


            return(din.getBytes());
        }
Exemple #28
0
        /*
         * Add a RPC Message with size byte automatically to the queue
         */
        public void addRpcMessage(byte[] messageBlock)
        {
            byte[] rpcSizeByte;
            if (messageBlock.Length > 127)
            {
                rpcSizeByte = NumericalUtils.uint16ToByteArray((UInt16)(messageBlock.Length + 0x8000), 0);
            }
            else
            {
                rpcSizeByte = NumericalUtils.uint16ToByteArrayShort((UInt16)messageBlock.Length);
            }
            DynamicArray content = new DynamicArray();

            content.append(rpcSizeByte);
            content.append(messageBlock);

            SequencedMessage message = new SequencedMessage(content.getBytes());

            RPCMessagesQueue.Add(message);
        }
Exemple #29
0
 // ToDo: Move it to player Packets and make a ?moa command for it
 public void processChangeMoaRSI(byte[] rsi)
 {
     DynamicArray din = new DynamicArray();
     din.append(0x03);
     din.append(0x02);
     din.append(0x00);
     din.append(StringUtils.hexStringToBytes("028100808080b052c7de12ab04"));
     din.append(rsi);
     din.append(0x41);
     din.append(0x00);
 }
Exemple #30
0
        // Shows the Animation of a target Player
        public void processFXfromPlayer(UInt16 viewID, byte[] animation)
        {
            Random rand = new Random();
            ushort updateViewCounter = (ushort)rand.Next(3, 200);

            byte[] updateCount = NumericalUtils.uint16ToByteArrayShort(updateViewCounter);

            DynamicArray din = new DynamicArray();

            din.append(NumericalUtils.uint16ToByteArray(viewID, 1));
            din.append(0x00);
            din.append(0x80);
            din.append(0x80);
            din.append(0x80);
            din.append(0x0c);
            din.append(animation); // uint32 anim ID
            din.append(updateCount);
            din.append(0x00);
            din.append(0x00);

            Store.currentClient.messageQueue.addObjectMessage(din.getBytes(), false);
        }
Exemple #31
0
        public void addCharacter(string charName, int charId, int status, int serverId)
        {
            byte[] charNameB = new byte[charName.Length + 3];
            byte[] hexSize   = NumericalUtils.uint16ToByteArray((UInt16)(charName.Length + 1), 1);
            charNameB[0] = hexSize[0];
            charNameB[1] = hexSize[1];
            charNameB[charName.Length + 2] = 0x00;
            for (int i = 0; i < charName.Length; i++)
            {
                charNameB[2 + i] = (byte)charName[i];
            }


            byte[] charDataB = new byte[14];
            byte[] charIdB   = NumericalUtils.uint32ToByteArray((UInt32)charId, 1);
            charDataB[3]  = charIdB[0];
            charDataB[4]  = charIdB[1];
            charDataB[5]  = charIdB[2];
            charDataB[6]  = charIdB[3];
            charDataB[9]  = 0x00;
            charDataB[10] = (byte)status;
            charDataB[11] = 0x00;
            charDataB[12] = (byte)serverId;

            numChars++; // Lets say we have done one ;)

            int offset = 0;

            // Use formula to calculate offset here

            offset = 14 + (14 * (totalChars - numChars));

            if (numChars == 1)
            {
                offset += 0;
            }
            else
            {
                offset += charNames.getSize();
            }

            // End of formula

            byte[] offsetH = NumericalUtils.uint16ToByteArray((UInt16)offset, 1);
            charDataB[1] = offsetH[0];
            charDataB[2] = offsetH[1];

            // After all calculations, append it to the dynamic arrays
            charData.append(charDataB);
            charNames.append(charNameB);
        }
Exemple #32
0
        // ToDo: Move it to player Packets and make a ?moa command for it
        public void processChangeMoaRSI(byte[] rsi)
        {
            DynamicArray din = new DynamicArray();

            din.append(0x03);
            din.append(0x02);
            din.append(0x00);
            din.append(StringUtils.hexStringToBytes("028100808080b052c7de12ab04"));
            din.append(rsi);
            din.append(0x41);
            din.append(0x00);
        }
Exemple #33
0
        private static void playerRSIPacket(out DynamicArray rsiPacket, out DynamicArray creationPacket, WorldClient client, ushort spawnIdCounter)
        {
            //Create the packet for the player

            rsiPacket = new DynamicArray();
            byte[] rsi = PacketsUtils.getRSIBytes(client.playerData.getRsiValues());

            byte[] CurCombatExclusiveAbility = { 0x00, 0x10, 0x00, 0x00 };

            //TODO: fix this 03 01 00
            rsiPacket.append(new byte[] { 0x01, 0x00 });
            /////////////////////////////////////////////
            client.playerInstance.disableAllAttributes(); //Predisable to just send what we need to spawn

            client.playerInstance.RealFirstName.enable();
            client.playerInstance.RealLastName.enable();
            client.playerInstance.Health.enable();
            client.playerInstance.MaxHealth.enable();
            client.playerInstance.YawInterval.enable(); //ROTATION
            client.playerInstance.OrganizationID.enable();

            client.playerInstance.StealthAwareness.setValue((byte)0x01); // TODO: See what's stealth awareness
            client.playerInstance.InnerStrengthAvailable.enable();
            client.playerInstance.CharacterName.enable();

            client.playerInstance.TitleAbility.enable();
            client.playerInstance.CharacterID.enable(); // It was set when grabbing from database
            client.playerInstance.RSIDescription.setValue(rsi);
            client.playerInstance.InnerStrengthMax.enable();
            client.playerInstance.Position.enable();
            client.playerInstance.Level.enable();
            client.playerInstance.CombatantMode.setValue((byte)0x22); //TODO: see what's combatantmode

            client.playerInstance.CurExclusiveAbility.setValue(CurCombatExclusiveAbility); //TODO: see what's this

            // ok we set all our values - lets get the generated packet for us
            DynamicArray creationPacketWithoutView = Store.world.objMan.generateCreationPacket(client.playerInstance, 0x0000,(byte)spawnIdCounter);
            creationPacket = Store.world.objMan.generateCreationPacket(client.playerInstance, 0x0000,(byte)spawnIdCounter);
        }
Exemple #34
0
        public byte[] loadInventory(int charID)
        {
            List <MarginInventoryItem> Inventory = new List <MarginInventoryItem>();

            Inventory = Store.dbManager.MarginDbHandler.loadInventory(charID);

            DynamicArray din = new DynamicArray();

            foreach (MarginInventoryItem item in Inventory)
            {
                din.append(NumericalUtils.uint16ToByteArrayShort(item.getSlot())); // slot
                din.append(NumericalUtils.uint32ToByteArray(item.getItemID(), 1));

                din.append(0x00);
                din.append(0x00);
                din.append(0x00); // ToDo : Figure out the bit flags shit thing for amount
                din.append(0x0c); // ToDo : same for purity
            }
            return(din.getBytes());
        }
Exemple #35
0
        public byte[] getBytesWithHeader(bool timedRPC)
        {
            DynamicArray rpcStructure = new DynamicArray();

            byte[] noTimedHeader = { 0x04 };
            byte[] timedHeader   = new byte[6];
            byte[] time          = TimeUtils.getUnixTime();

            timedHeader[0] = 0x82;

            ArrayUtils.copy(time, 0, timedHeader, 1, 4);
            timedHeader[5] = 0x04;             // This makes it "82aabbccdd04"

            if (timedRPC)
            {
                rpcStructure.append(timedHeader);
            }
            else
            {
                rpcStructure.append(noTimedHeader);
            }

            // Calculate blocks number


            if (rpcInside == 0)            // Is just 1 group of msgblocks
            {
                rpcInside = 1;
                rpcStructure.append(NumericalUtils.uint16ToByteArrayShort((UInt16)rpcInside));
                rpcStructure.append(getBytes());                 //Append our own content
            }
            else
            {
                rpcStructure.append(NumericalUtils.uint16ToByteArrayShort((UInt16)rpcInside));
                rpcStructure.append(din.getBytes());                 //Append our own content
            }


            return(rpcStructure.getBytes());
        }
Exemple #36
0
        public byte[] loadInventory(int charID)
        {
            List<MarginInventoryItem> Inventory = new List<MarginInventoryItem>();
            Inventory = Store.dbManager.MarginDbHandler.loadInventory(charID);

            DynamicArray din = new DynamicArray();
            foreach (MarginInventoryItem item in Inventory)
            {
                din.append(NumericalUtils.uint16ToByteArrayShort(item.getSlot())); // slot
                din.append(NumericalUtils.uint32ToByteArray(item.getItemID(),1));

                din.append(0x00);
                din.append(0x00);
                din.append(0x00); // ToDo : Figure out the bit flags shit thing for amount
                din.append(0x0c); // ToDo : same for purity

            }
            return din.getBytes();
        }
Exemple #37
0
        public byte[] loadEquippedAbilities()
        {
            DynamicArray din = new DynamicArray();

            //AbilityItem abTemp = AbilityDB.Find(delegate(AbilityItem a) { return a.getAbilityID() == id; });

            foreach (MarginAbilityItem ability in Abilities)
            {
                if (ability.getLoaded() == true)
                {
                    Int32 finalAblityID = ability.getAbilityID() + ability.getLevel();
                    din.append(NumericalUtils.uint16ToByteArray(ability.getSlot(), 1)); // slot
                    din.append(NumericalUtils.int32ToByteArray(finalAblityID, 1));
                }

            }
            return din.getBytes();
        }
Exemple #38
0
        public void parseCommand(string data)
        {
            Output.WriteLine("[Chat Command helper] Chat command is: '" + data + "'");
            string[] commands = data.Split(' ');

            string command = commands[0].ToLower();

            try{
                if (command.Equals("?fix") && commands.Length > 1)
                {
                    int maxRPC = int.Parse(commands[1]);
                    for (int i = 0; i < maxRPC; i++)
                    {
                        Store.currentClient.playerData.setRPCCounter((UInt16)i);
                        Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("Trying to fix! " + i, Store.currentClient));
                    }
                }

                if (command.Equals("?teleport") && commands.Length == 4)
                {
                    // parse the coord parameters parameters as int
                    Store.currentClient.messageQueue.addObjectMessage(new PlayerHelper().teleport(int.Parse(commands[1]), int.Parse(commands[2]), int.Parse(commands[3])), false);
                    Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("Teleported!", Store.currentClient));
                }

                if (command.Equals("?rsi") && commands.Length == 3)
                {
                    //parse the rsi part and value
                    Store.currentClient.messageQueue.addObjectMessage(new PlayerHelper().changeRsi(commands[1], int.Parse(commands[2])), false);
                    Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("Rsi changed!", Store.currentClient));
                }


                if (command.StartsWith("?message"))
                {
                    Output.WriteLine("[COMMAND HELPER]MESSAGE RECEIVED");
                    byte[] theMessage = PacketsUtils.createSystemMessageWithoutRPC(commands[1]);
                    Store.world.sendRPCToAllPlayers(theMessage);
                }

                if (command.Equals("?playanim"))
                {
                    string animId = commands[1];
                    if (animId.Length == 4)
                    {
                        ServerPackets pak = new ServerPackets();
                        pak.sendPlayerAnimation(Store.currentClient, animId);
                    }
                }

                if (command.StartsWith("?playfx"))
                {
                    string       fxHEDID = commands[1];
                    DynamicArray din     = new DynamicArray();


                    byte[] animationId = StringUtils.hexStringToBytes(fxHEDID);
                    byte[] viewID      = { 0x02, 0x00 };

                    Random rand = new Random();
                    ushort updateViewCounter = (ushort)rand.Next(3, 200);
                    byte[] updateCount       = NumericalUtils.uint16ToByteArrayShort(updateViewCounter);

                    Output.WriteLine("Check if its really one byte or two : " + StringUtils.bytesToString(updateCount));


                    din.append(viewID);
                    din.append(0x02);
                    din.append(0x80);
                    din.append(0x80);
                    din.append(0x80);
                    din.append(0x90);
                    din.append(0xed);
                    din.append(0x00);
                    din.append(0x30);
                    din.append(animationId);
                    din.append(updateCount);

                    Store.currentClient.messageQueue.addObjectMessage(din.getBytes(), false);
                }

                if (command.Contains("?send"))
                {
                    // Sends a packet from a file
                    string     filename   = "packet.txt";
                    TextReader tr         = new StreamReader(filename);
                    string     hexContent = tr.ReadToEnd();
                    hexContent = hexContent.Replace(" ", string.Empty);
                    hexContent = hexContent.Replace(" ", Environment.NewLine);
                    tr.Close();

                    if (hexContent.Length > 0)
                    {
                        Store.currentClient.messageQueue.addObjectMessage(StringUtils.hexStringToBytes(hexContent), false);
                        Output.writeToLogForConsole("[SENDPACK FROM FILE] Content : " + hexContent);
                    }
                }

                if (command.Contains("?combat"))
                {
                    byte[]          dummypak = new byte[4];
                    TestUnitHandler test     = new TestUnitHandler();
                    test.testCloseCombat(ref dummypak);
                }

                if (command.Contains("?mob"))
                {
                    UInt32[] rsiIDs = new UInt32[10];
                    rsiIDs[0] = 0xB7010058;
                    rsiIDs[1] = 0x89090058;
                    rsiIDs[2] = 0xB5010058;
                    rsiIDs[3] = 0x3A030008;
                    rsiIDs[4] = 0x32030008;
                    rsiIDs[5] = 0xD0010058;
                    rsiIDs[6] = 0xD4010058;
                    rsiIDs[7] = 0xB8040004; // Smith
                    rsiIDs[8] = 0x92010058; // Seraph
                    rsiIDs[9] = 0x56050004;
                    Random rand  = new Random();
                    int    index = rand.Next(0, 9);

                    double x = 0; double y = 0; double z = 0;
                    byte[] Ltvector3d = Store.currentClient.playerInstance.Position.getValue();
                    NumericalUtils.LtVector3dToDoubles(Ltvector3d, ref x, ref y, ref z);

                    byte[] xPos = NumericalUtils.floatToByteArray((float)x, 1);
                    byte[] yPos = NumericalUtils.floatToByteArray((float)y, 1);
                    byte[] zPos = NumericalUtils.floatToByteArray((float)z, 1);

                    UInt64 currentEntityId = WorldSocket.entityIdCounter;
                    WorldSocket.entityIdCounter++;
                    uint rotation = 0;

                    npc theMob = new npc();
                    theMob.setEntityId(currentEntityId);
                    theMob.setDistrict(Convert.ToUInt16(data[0].ToString()));
                    theMob.setDistrictName(Store.currentClient.playerData.getDistrict());
                    theMob.setName("HD Protector");
                    theMob.setLevel(255);
                    theMob.setHealthM(UInt16.Parse(data[4].ToString()));
                    theMob.setHealthC(UInt16.Parse(data[5].ToString()));
                    theMob.setMobId((ushort)rsiIDs[index]);
                    theMob.setRsiHex(StringUtils.bytesToString_NS(NumericalUtils.uint32ToByteArray(rsiIDs[index], 1)));
                    theMob.setXPos(x);
                    theMob.setYPos(y);
                    theMob.setZPos(z);
                    theMob.xBase = x;
                    theMob.yBase = y;
                    theMob.zBase = z;
                    theMob.setRotation(rotation);
                    theMob.setIsDead(false);
                    theMob.setIsLootable(false);
                    WorldSocket.npcs.Add(theMob);

                    // we use this for a test to see if we can spawn mobs and how we can handle them
                    // We refactor this
                }



                if (command.Contains("?sendrpc"))
                {
                    // sends a RPC Packet from a File
                    string     filename   = "rpcpacket.txt";
                    TextReader tr         = new StreamReader(filename);
                    string     hexContent = tr.ReadToEnd();
                    hexContent = hexContent.Replace(" ", string.Empty);
                    hexContent = hexContent.Replace(" ", Environment.NewLine);
                    Output.Write("SEND RPC COMMAND : CONTENT : " + hexContent);
                    tr.Close();

                    if (hexContent.Length > 0)
                    {
                        Store.currentClient.messageQueue.addRpcMessage(StringUtils.hexStringToBytes(hexContent));
                        Output.writeToLogForConsole("[SENDRPC FROM FILE] Content : " + hexContent);
                    }
                }

                if (command.Contains("?checkrpc"))
                {
                    DynamicArray din = new DynamicArray();
                    din.append(StringUtils.hexStringToBytes("2E1000FF7D020024000000310000000000000000000000000000000000000000000000000B0053796E61707A65373737001D004F6E2079656168204920646F2072656D656D62657220796F75203A2900"));
                    Store.currentClient.messageQueue.addRpcMessage(din.getBytes());
                }

                if (command.Contains("?testrpc"))
                {
                    UInt16 maxRPC = 33279;
                    // Just to reference
                    if (Store.currentClient.playerData.currentTestRPC <= maxRPC)
                    {
                        // Only if it is below we send it - we test with a 5 size packet
                        DynamicArray din = new DynamicArray();
                        if (Store.currentClient.playerData.currentTestRPC < 127)
                        {
                            din.append(NumericalUtils.uint16ToByteArrayShort(Store.currentClient.playerData.currentTestRPC));
                        }
                        else
                        {
                            din.append(NumericalUtils.uint16ToByteArray(Store.currentClient.playerData.currentTestRPC, 0));
                        }

                        din.append(0x00);
                        din.append(0x00);
                        din.append(0x00);

                        Store.currentClient.messageQueue.addRpcMessage(din.getBytes());

                        ServerPackets pak = new ServerPackets();
                        pak.sendSystemChatMessage(Store.currentClient, "Test RPC Header : " + Store.currentClient.playerData.currentTestRPC.ToString(), "MODAL");

                        Store.currentClient.playerData.currentTestRPC++;
                    }
                }

                if (command.Equals("?save"))
                {
                    new PlayerHelper().savePlayerInfo(Store.currentClient);

                    ServerPackets pak = new ServerPackets();
                    pak.sendSaveCharDataMessage(Store.currentClient, StringUtils.charBytesToString_NZ(Store.currentClient.playerInstance.CharacterName.getValue()));
                }
            }
            catch (Exception e) {
                Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("Error parsing command!", Store.currentClient));
                Output.WriteLine("[CHAT COMMAND PARSER] Error parsing request: " + data);
                Output.WriteLine("[CHAT COMMAND PARSER] DEBUG: " + e.Message + "\n" + e.StackTrace);
            }
        }
Exemple #39
0
        public byte[] encrypt(byte[] packet)
        {
            // Get timestamp
            byte[] timestamp = TimeUtils.getUnixTime();


            // get size
            int psize = packet.Length;

            byte[] size = NumericalUtils.uint16ToByteArray((UInt16)psize, 1);

            //showPacket(size, " Size ");

            // final Packet

            DynamicArray temp = new DynamicArray();

            temp.append(size);
            temp.append(timestamp);
            temp.append(packet);


            // compute CRC32
            byte[] crc32pax = crc32.checksumB(temp.getBytes(), 1);


            // Padding
            int totalLength = temp.getSize() + 4;
            int padding     = 16 - (totalLength % 16);

            byte[] paddingBytes = new byte[padding];

            for (int i = 0; i < padding; i++)
            {
                paddingBytes[i] = (byte)padding;
            }

            temp.append(paddingBytes);
            tf.setIV(IV);
            tf.setKey(TF_Key);

            // We init with 2 more than needed, so no memory reservation is done on dyn array
            DynamicArray finalPlainData = new DynamicArray();

            finalPlainData.append(crc32pax);
            finalPlainData.append(temp.getBytes());

            temp = null;             // Cleaning the house


            byte[] encryptedData = new byte[finalPlainData.getSize()];
            tf.encrypt(finalPlainData.getBytes(), encryptedData);


            finalPlainData = null;             // Cleaning the house (2)

            // add IV before the results

            DynamicArray response = new DynamicArray();

            response.append(IV);
            response.append(encryptedData);

            // Display HEX Values after Encryption
            return(response.getBytes());
        }
Exemple #40
0
        public void processUpdateExp()
        {
            Random rand = new Random();
            UInt32 expval = (UInt32)rand.Next(1000, 200000);
            ArrayList content = new ArrayList();

            // ToDo  : Save new EXP Value in the Database and update mpm exp
            // ToDo2 : Check if exp events are running to multiple the EXP
            // The Animation
            DynamicArray expanim = new DynamicArray();
            expanim.append(0x80);
            expanim.append(0xe6);
            expanim.append(NumericalUtils.uint32ToByteArray(expval, 1));
            expanim.append(0x01); // Gain Type
            expanim.append(StringUtils.hexStringToBytes("000000"));
            Store.currentClient.messageQueue.addRpcMessage(expanim.getBytes());

            // The BAR
            DynamicArray expbar = new DynamicArray();
            expbar.append(0x80);
            expbar.append(0xe5);
            expbar.append(NumericalUtils.uint32ToByteArray(expval, 1));
            expbar.append(0x01); // Gain Type
            expbar.append(StringUtils.hexStringToBytes("000000"));
            Store.currentClient.messageQueue.addRpcMessage(expbar.getBytes());
        }
Exemple #41
0
        public byte[] getFinalData(ClientData playerData)
        {
            // TODO: Sim Time with Client (not real time) on every 4 Local SSEQ we send


            playerData.IncrementSseq();
            this.neededAckSSeq = playerData.getSseq();

            if ((NumericalUtils.ByteArrayToUint32(TimeUtils.getCurrentSimTime(), 1) - playerData.lastSimTimeUpdate) > 3)
            {
                timed = true;
                playerData.lastSimTimeUpdate = NumericalUtils.ByteArrayToUint32(TimeUtils.getCurrentSimTime(), 1);
            }


            playerData.getRPCShutDown();
            if (timed)
            {
                if (playerData.waitForRPCShutDown == true)
                {
                    content.append((byte)0xc2);
                }
                else
                {
                    content.append((byte)0x82);
                }

                content.append(TimeUtils.getCurrentSimTime());
            }
            else
            {
                if (playerData.waitForRPCShutDown == true)
                {
                    content.append((byte)0x42);
                }
                else
                {
                    content.append((byte)0x02);
                }
            }

            // Merge all Message together and generate the Final Packet Header
            generateObjectMessageData();
            generateRpcMessageData();
            Output.WriteDebugLog("PACKET DATA (getFinalData):" + StringUtils.bytesToString(content.getBytes()));
            return(content.getBytes());
        }
Exemple #42
0
        public void sendTCPVariableLenPacket(byte[] packet, NetworkStream client)
        {
            byte[] size = { };
            byte[] bytesize = { };

            if (packet.Length > 127){
                //Do NOT reverse here :P
                bytesize = NumericalUtils.uint16ToByteArray((UInt16)(packet.Length + 0x8000),0);
            }
            else{
                bytesize = NumericalUtils.uint16ToByteArrayShort((ushort)packet.Length);
            }

            byte[] finalPacket = new byte[packet.Length+bytesize.Length];

            DynamicArray din = new DynamicArray();
            din.append(bytesize);
            din.append(packet);

            finalPacket = din.getBytes();

            try
            {
                client.Write(finalPacket, 0, finalPacket.Length);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR ex: " + ex.ToString());
                throw;
            }
            client.Flush();
        }
Exemple #43
0
 public static byte[] floatsToLtVector3f(float x,float y,float z)
 {
     DynamicArray din = new DynamicArray();
     din.append(NumericalUtils.floatToByteArray(x,1));
     din.append(NumericalUtils.floatToByteArray(y,1));
     din.append(NumericalUtils.floatToByteArray(z,1));
     return din.getBytes();
 }
Exemple #44
0
 public static byte[] doublesToLtVector3d(double x,double y,double z)
 {
     DynamicArray din = new DynamicArray();
     din.append(NumericalUtils.doubleToByteArray(x,1));
     din.append(NumericalUtils.doubleToByteArray(y,1));
     din.append(NumericalUtils.doubleToByteArray(z,1));
     return din.getBytes();
 }
Exemple #45
0
        public void processHyperJumpTest(ref byte[] packet)
        {
            // The working pak : send 82 9a f3 25 49 03 02 00 03 08 f3 fa 84 46 bb 2e 0d 46 3e 22 51 c6 33 f9 83 28 ff 01 64 01 00 00 00 00 00 00 00 00 00 00 00 08 41 6e 64 65 72 73 6f 6e 06 54 68 6f 6d 61 73 ff 04 80 73 1a e9 82 80 60 04 00 02 8e 00 00 00 01 00 00 00 00 00 00 8f 01 00 02 00 2a 03 02 ff 28 0a 32 00 f0 20 46 04 00 8e 16 84 28 00 00 00 60 50 85 d6 40 00 00 00 00 00 7e a3 40 00 00 00 80 25 da c9 c0 00 ff 00 00 00 00 00 f7 00 00 00 eb 00 00 00 00 00 28 0a ff 00 31 5e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff 00 00 00 00 00 00 00 00 00 00 00 00 80 3f 11 00 00 00 4b b1 00 00 71 02 00 00 3f 00 00 00 01 22 00 00 00 00 00 00 00 05 00 01 00 04 f3 fa 84 46 bb 2e 0d 46 3e 22 51 c6 00 00;
            //this.testHyperJumpPaket();
            //return;

            // REMOVE THIS LATER!!!
            /*
            destX = (string.join(data[9:17],"")).decode('hex')
            destY = (string.join(data[17:25],"")).decode('hex')
            destZ = (string.join(data[25:33],"")).decode('hex')
            maxHeight = (string.join(data[39:43],"")).decode('hex')
            lastBytes = (string.join(data[-4:],"")).decode('hex')

            (viewData,newX,newY,newZ) = self.hyperjMan.processHyperJump(x,y,z,destX,destY,destZ,maxHeight,lastBytes)
             */
            byte[] destXBytes = new byte[8];
            byte[] destYBytes = new byte[8];
            byte[] destZBytes = new byte[8];
            byte[] maxHeight = new byte[4];

            DynamicArray restBytes = new DynamicArray();

            ArrayUtils.copy(packet, 0, destXBytes, 0, 8);
            ArrayUtils.copy(packet, 0, destYBytes, 8, 8);
            ArrayUtils.copy(packet, 0, destZBytes, 16, 8);
            ArrayUtils.copy(packet, 0, maxHeight, 30, 4);
            /*
            int packetSize = packet.Length - 28;
            byte[] restBytes = new byte[packetSize];
            ArrayUtils.copy(packet, 0, restBytes, 28, packetSize);
             */

            // Players current X Z Y
            double x = 0; double y = 0; double z = 0;
            byte[] Ltvector3d = Store.currentClient.playerInstance.Position.getValue();
            NumericalUtils.LtVector3dToDoubles(Ltvector3d, ref x, ref y, ref z);
            int rotation = (int)Store.currentClient.playerInstance.YawInterval.getValue()[0];

            float xPos = (float)x;
            float yPos = (float)y;
            float zPos = (float)z;
            Store.currentClient.playerData.incrementJumpID();

            // Okay we know have what we need to test hyperjump - lets do it
            // Normally we would loop and increase the player pos..but for test we dont do it
            DynamicArray din = new DynamicArray();
            din.append(StringUtils.hexStringToBytes("02000308")); // The 03 header (update myself)
            din.append(NumericalUtils.floatToByteArray(xPos, 1)); // Current X
            din.append(NumericalUtils.floatToByteArray(yPos, 1)); // Current Y
            din.append(NumericalUtils.floatToByteArray(zPos, 1)); // Current Z
            din.append(StringUtils.hexStringToBytes("00008328FF016401000000000000000000000008416E646572736F6E0654686F6D6173FFE018400C4105E0020400CD01000000010000000000008F010002002A0302FF280A3200"));
            din.append(StringUtils.hexStringToBytes("F0204604")); // Max height
            //din.append(maxHeight); // From Source Packet
            din.append(StringUtils.hexStringToBytes("00"));
            din.append(NumericalUtils.uint16ToByteArray(Store.currentClient.playerData.getJumpID(), 0)); // Must be increment in the loop
            din.append(StringUtils.hexStringToBytes("8428"));
            din.append(destXBytes);
            din.append(destYBytes);
            din.append(destZBytes);
            din.append(StringUtils.hexStringToBytes("00FF0000000000F7000000E70000000000280AFF00315E00000000000000000000000000000000FF000000000000000000000000803F110000004BB10000710200003F0000000022000000000000000500010004"));
            din.append(NumericalUtils.floatToByteArray(xPos, 1)); // Current X
            din.append(NumericalUtils.floatToByteArray(yPos, 1)); // Current Y
            din.append(NumericalUtils.floatToByteArray(zPos, 1)); // Current Z
            din.append(0x00);
            din.append(0x00);
            Output.writeToLogForConsole("HJ PACKET DUMP : " + StringUtils.bytesToString(din.getBytes()));

            Store.currentClient.messageQueue.addObjectMessage(din.getBytes(), true);
        }
Exemple #46
0
        // Shows the Animation of a target Player
        public void processFXfromPlayer(UInt16 viewID, byte[] animation)
        {
            Random rand = new Random();
            ushort updateViewCounter = (ushort)rand.Next(3, 200);
            byte[] updateCount = NumericalUtils.uint16ToByteArrayShort(updateViewCounter);

            DynamicArray din = new DynamicArray();
            din.append(NumericalUtils.uint16ToByteArray(viewID, 1));
            din.append(0x00);
            din.append(0x80);
            din.append(0x80);
            din.append(0x80);
            din.append(0x0c);
            din.append(animation); // uint32 anim ID
            din.append(updateCount);
            din.append(0x00);
            din.append(0x00);

            Store.currentClient.messageQueue.addObjectMessage(din.getBytes(), false);
        }
Exemple #47
0
        public byte[] loadKnownAbilities()
        {
            DynamicArray din = new DynamicArray();

            foreach (MarginAbilityItem ability in Abilities)
            {
                Int32 finalAblityID = ability.getAbilityID() + ability.getLevel();

                string debugAbility = StringUtils.bytesToString(NumericalUtils.int32ToByteArray(finalAblityID, 1));
                din.append(NumericalUtils.uint16ToByteArray(ability.getSlot(),1)); // slot
                din.append(NumericalUtils.int32ToByteArray(finalAblityID, 1));
            }

            return din.getBytes();
        }
Exemple #48
0
        public void parseCommand(string data)
        {
            Output.WriteLine("[Chat Command helper] Chat command is: '"+data+"'");
            string[] commands = data.Split(' ');

            string command = commands[0].ToLower();

            try{

                if (command.Equals("?fix") && commands.Length>1){
                    int maxRPC = int.Parse(commands[1]);
                    for(int i = 0;i<maxRPC;i++){
                        Store.currentClient.playerData.setRPCCounter((UInt16)i);
                        Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("Trying to fix! " + i, Store.currentClient));
                    }

                }

                if (command.Equals("?teleport") && commands.Length==4){
                    // parse the coord parameters parameters as int
                    Store.currentClient.messageQueue.addObjectMessage(new PlayerHelper().teleport(int.Parse(commands[1]), int.Parse(commands[2]), int.Parse(commands[3])), false);
                    Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("Teleported!", Store.currentClient));

                }

                if (command.Equals("?rsi") && commands.Length==3){
                    //parse the rsi part and value
                    Store.currentClient.messageQueue.addObjectMessage(new PlayerHelper().changeRsi(commands[1], int.Parse(commands[2])), false);
                    Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("Rsi changed!", Store.currentClient));
                }

                if (command.StartsWith("?message"))
                {
                    Output.WriteLine("[COMMAND HELPER]MESSAGE RECEIVED");
                    byte[] theMessage = PacketsUtils.createSystemMessageWithoutRPC(commands[1]);
                    Store.world.sendRPCToAllPlayers(theMessage);

                }

                if (command.Equals("?playanim"))
                {
                    string animId = commands[1];
                    if (animId.Length == 4)
                    {
                        ServerPackets pak = new ServerPackets();
                        pak.sendPlayerAnimation(Store.currentClient, animId);

                    }

                }

                if (command.StartsWith("?playfx"))
                {
                    string fxHEDID =  commands[1];
                    DynamicArray din = new DynamicArray();

                    byte[] animationId = StringUtils.hexStringToBytes(fxHEDID);
                    byte[] viewID = { 0x02, 0x00 };

                    Random rand = new Random();
                    ushort updateViewCounter = (ushort)rand.Next(3, 200);
                    byte[] updateCount = NumericalUtils.uint16ToByteArrayShort(updateViewCounter);

                    Output.WriteLine("Check if its really one byte or two : " + StringUtils.bytesToString(updateCount));

                    din.append(viewID);
                    din.append(0x02);
                    din.append(0x80);
                    din.append(0x80);
                    din.append(0x80);
                    din.append(0x90);
                    din.append(0xed);
                    din.append(0x00);
                    din.append(0x30);
                    din.append(animationId);
                    din.append(updateCount);

                    Store.currentClient.messageQueue.addObjectMessage(din.getBytes(), false);

                }

                if (command.Contains("?send"))
                {
                    // Sends a packet from a file
                    string filename = "packet.txt";
                    TextReader tr = new StreamReader(filename);
                    string hexContent = tr.ReadToEnd();
                    hexContent = hexContent.Replace(" ", string.Empty);
                    hexContent = hexContent.Replace(" ", Environment.NewLine);
                    tr.Close();

                    if (hexContent.Length > 0)
                    {
                        Store.currentClient.messageQueue.addObjectMessage(StringUtils.hexStringToBytes(hexContent), false);
                        Output.writeToLogForConsole("[SENDPACK FROM FILE] Content : " + hexContent);
                    }

                }

                if (command.Contains("?combat"))
                {
                    byte[] dummypak = new byte[4];
                    TestUnitHandler test = new TestUnitHandler();
                    test.testCloseCombat(ref dummypak);
                }

                if (command.Contains("?mob"))
                {

                    UInt32[] rsiIDs = new UInt32[10];
                    rsiIDs[0] = 0xB7010058;
                    rsiIDs[1] = 0x89090058;
                    rsiIDs[2] = 0xB5010058;
                    rsiIDs[3] = 0x3A030008;
                    rsiIDs[4] = 0x32030008;
                    rsiIDs[5] = 0xD0010058;
                    rsiIDs[6] = 0xD4010058;
                    rsiIDs[7] = 0xB8040004; // Smith
                    rsiIDs[8] = 0x92010058; // Seraph
                    rsiIDs[9] = 0x56050004;
                    Random rand = new Random();
                    int index = rand.Next(0, 9);

                    double x = 0; double y = 0; double z = 0;
                    byte[] Ltvector3d = Store.currentClient.playerInstance.Position.getValue();
                    NumericalUtils.LtVector3dToDoubles(Ltvector3d, ref x, ref y, ref z);

                    byte[] xPos = NumericalUtils.floatToByteArray((float)x, 1);
                    byte[] yPos = NumericalUtils.floatToByteArray((float)y, 1);
                    byte[] zPos = NumericalUtils.floatToByteArray((float)z, 1);

                    UInt64 currentEntityId = WorldSocket.entityIdCounter;
                    WorldSocket.entityIdCounter++;
                    uint rotation = 0;

                    npc theMob = new npc();
                    theMob.setEntityId(currentEntityId);
                    theMob.setDistrict(Convert.ToUInt16(data[0].ToString()));
                    theMob.setDistrictName(Store.currentClient.playerData.getDistrict());
                    theMob.setName("HD Protector");
                    theMob.setLevel(255);
                    theMob.setHealthM(UInt16.Parse(data[4].ToString()));
                    theMob.setHealthC(UInt16.Parse(data[5].ToString()));
                    theMob.setMobId((ushort)rsiIDs[index]);
                    theMob.setRsiHex(StringUtils.bytesToString_NS(NumericalUtils.uint32ToByteArray(rsiIDs[index],1)));
                    theMob.setXPos(x);
                    theMob.setYPos(y);
                    theMob.setZPos(z);
                    theMob.xBase = x;
                    theMob.yBase = y;
                    theMob.zBase = z;
                    theMob.setRotation(rotation);
                    theMob.setIsDead(false);
                    theMob.setIsLootable(false);
                    WorldSocket.npcs.Add(theMob);

                    // we use this for a test to see if we can spawn mobs and how we can handle them
                    // We refactor this
                }

                if (command.Contains("?sendrpc"))
                {

                    // sends a RPC Packet from a File
                    string filename = "rpcpacket.txt";
                    TextReader tr = new StreamReader(filename);
                    string hexContent = tr.ReadToEnd();
                    hexContent = hexContent.Replace(" ", string.Empty);
                    hexContent = hexContent.Replace(" ", Environment.NewLine);
                    Output.Write("SEND RPC COMMAND : CONTENT : "+ hexContent);
                    tr.Close();

                    if (hexContent.Length > 0)
                    {
                        Store.currentClient.messageQueue.addRpcMessage(StringUtils.hexStringToBytes(hexContent));
                        Output.writeToLogForConsole("[SENDRPC FROM FILE] Content : " + hexContent);
                    }
                }

                if (command.Contains("?checkrpc"))
                {
                    DynamicArray din = new DynamicArray();
                    din.append(StringUtils.hexStringToBytes("2E1000FF7D020024000000310000000000000000000000000000000000000000000000000B0053796E61707A65373737001D004F6E2079656168204920646F2072656D656D62657220796F75203A2900"));
                    Store.currentClient.messageQueue.addRpcMessage(din.getBytes());
                }

                if (command.Contains("?testrpc")){

                    UInt16 maxRPC = 33279;
                    // Just to reference
                    if (Store.currentClient.playerData.currentTestRPC <= maxRPC){

                        // Only if it is below we send it - we test with a 5 size packet
                        DynamicArray din = new DynamicArray();
                        if (Store.currentClient.playerData.currentTestRPC < 127)
                        {
                            din.append(NumericalUtils.uint16ToByteArrayShort(Store.currentClient.playerData.currentTestRPC));
                        }
                        else
                        {
                            din.append(NumericalUtils.uint16ToByteArray(Store.currentClient.playerData.currentTestRPC, 0));
                        }

                        din.append(0x00);
                        din.append(0x00);
                        din.append(0x00);

                        Store.currentClient.messageQueue.addRpcMessage(din.getBytes());

                        ServerPackets pak = new ServerPackets();
                        pak.sendSystemChatMessage(Store.currentClient, "Test RPC Header : " + Store.currentClient.playerData.currentTestRPC.ToString(),"MODAL");

                        Store.currentClient.playerData.currentTestRPC++;
                    }
                }

                if (command.Equals("?save")){
                    new PlayerHelper().savePlayerInfo(Store.currentClient);

                    ServerPackets pak = new ServerPackets();
                    pak.sendSaveCharDataMessage(Store.currentClient, StringUtils.charBytesToString_NZ(Store.currentClient.playerInstance.CharacterName.getValue()));
                }

            }
            catch(Exception e){
                Store.currentClient.messageQueue.addRpcMessage(PacketsUtils.createSystemMessage("Error parsing command!", Store.currentClient));
                Output.WriteLine("[CHAT COMMAND PARSER] Error parsing request: "+data);
                Output.WriteLine("[CHAT COMMAND PARSER] DEBUG: "+e.Message+"\n"+e.StackTrace);
            }
        }
Exemple #49
0
        public void packetHandler(byte[] packet, NetworkStream client )
        {
            bool encrypted = true;
            byte opcode = packet[2];
            byte[] data = { };
            byte pointer = packet[0];

            if (opcode == 0x01){
                // Packet is unencrypted
                encrypted = false;
                data = packet;
            }

            // This overrides the above IF for packets where 3rd position is a "01"
            // Happened someday, and screwed login... yeah, really
            if(pointer!=0x81){
                encrypted=true;
            }

            if (encrypted == true)
            {
                byte[] encryptedPacket = { };
                if (packet[0] >= 0x80)
                {
                    // try to readjust the packet for one byte less if the lenght is too long
                    // just a crappy way
                    encryptedPacket = new byte[packet.Length-1];
                    ArrayUtils.copy(packet,1,encryptedPacket,0,packet.Length-1);
                }
                else{
                    encryptedPacket = packet;
                }
                // Get the IV from encrypted Packet and set it in encryptor/decryptor
                byte[] decrypted = marginEncr.decryptMargin(encryptedPacket);
                // Just 2 zero bytes for opcode handling later (As we use third byte for both state, encrypted or not
                byte[] spacer = { 0x00, 0x00 };

                DynamicArray din = new DynamicArray();
                din.append(spacer);
                din.append(decrypted);

                data = din.getBytes();

            }else{
                data = packet;
            }
            Output.WritePacketLog(StringUtils.bytesToString(data), "MARGINCLIENT", "0", "0", "0");
            opcode = data[2];

            //TODO: check if this needs "packet" or "data"
            switch (opcode)
            {
                case 0x01:
                    certConnectRequest(packet, client);

                break;

                case 0x03:
                    certConnectReply(packet, client);

                break;

                case 0x06:
                    connectChallenge(packet, client);

                break;

                case 0x08:
                    ConnectChallengeResponse(packet, client);
                break;

                case 0x0a:
                    //CharNameRequest
                    charNameRequest(data,client);
                break;

                case 0x0c:
                    //TODO: this is creation. must be done someday
                    Output.writeToLogForConsole("CREATECHAR RSI VALUES:"+ StringUtils.bytesToString(data));
                    //loadCharacter(data, client);
                    createCharacterRSI(data, client);
                    // Add the first abilitys
                    // AbilityID : 2147485696 (Awakened) Level 2
                    // AbilityID :

                break;

                case 0x0d:
                    // Delete Charname Request
                    deleteCharName(data, client);
                break;

                case 0x0f:
                    loadCharacter(data, client, 0);
                break;
            }
        }
Exemple #50
0
        public void processSelfAnimation(UInt16 abilityID)
        {
            DynamicArray din = new DynamicArray();
            //byte[] animationId = {0x22, 0x0a, 0x00, 0x28}; // Repair RSI
            //byte[] animationId = { 0x39, 0x0a, 0x00, 0x28 }; // Jackout


            /*
             * Array fxIDs = Enum.GetValues(typeof(FXList));
             * Random randAnim = new Random();
             * UInt32 randAnimID = (UInt32)fxIDs.GetValue(randAnim.Next(fxIDs.Length));
             */
            UInt32 randAnimID = (UInt32)FXList.FX_VIRUSCAST_SPLIT_CODE_NUKE_CODENUKE_START;

            byte[] animationId = NumericalUtils.uint32ToByteArray(randAnimID, 0);
            byte[] viewID      = { 0x02, 0x00 };

            byte[] updateCount = NumericalUtils.uint16ToByteArrayShort(Store.currentClient.playerData.assignSpawnIdCounter());

            din.append(viewID);
            din.append(0x02);
            din.append(0x80);
            din.append(0x80);
            din.append(0x80);
            din.append(0x90);
            din.append(0xed);
            din.append(0x00);
            din.append(0x30);
            din.append(animationId);
            din.append(updateCount);

            Store.currentClient.messageQueue.addObjectMessage(din.getBytes(), false);
        }
Exemple #51
0
        public void certConnectRequest(byte[] packet, NetworkStream client)
        {
            int firstnum = BitConverter.ToInt16(packet, 3);
            int authstart = BitConverter.ToInt16(packet, 5);
            if (firstnum != 3)
            {
                //showMarginDebug("FirstNum is not 3, it is" + firstnum);

            }

            if (authstart != 310)
            {
                //showMarginDebug("AuthStart is not 0x3601");

            }

            // Get the Signature
            byte[] signature= new byte[128];

            ArrayUtils.copy(packet,7,signature,0,128);

            // TODO MD5 Signature and verify it with RSA to check if everything is correct

            // Get the signedData
            byte[] signedData = new byte[packet.Length - 135];
            ArrayUtils.copy(packet,135,signedData,0,packet.Length-135);
            int userid = BitConverter.ToInt32(signedData, 1);
            this.userID = (UInt32)userid;

            // Stripout Exponent and Modulus

            byte[] exponent = {0x00, 0x00, 0x00, 0x11};
            byte[] modulus = new byte[96];

            ArrayUtils.copy(signedData,82,modulus,0,96);

            // Init our encryptor with users modulus and exponent
            marginEncr.setUserPubKey(exponent, modulus);
            // build the final packet, it consists of 1 byte 0x00 + twofish key for world and margin + encryptIV

            byte[] encryptMeResponse = new byte[33];
            encryptMeResponse[0] = 0x00;

            ArrayUtils.copy(marginEncr.getTFKey(),0,encryptMeResponse,1,16);
            ArrayUtils.copy(marginEncr.getIV(),0,encryptMeResponse,17,16);

            byte[] encryptedShit = { };
            encryptedShit = marginEncr.encryptUsersPublic(encryptMeResponse);

            byte[] blobSize = NumericalUtils.uint16ToByteArray((UInt16)encryptedShit.Length,1);

            byte[] header = { 0x02, 0x03, 0x00 };
            // Write final packet

            DynamicArray din = new DynamicArray();
            din.append(header);
            din.append(blobSize);
            din.append(encryptedShit);

            sendTCPVariableLenPacket(din.getBytes(), client);
        }
Exemple #52
0
        public byte[] getFinalData(ClientData playerData)
        {
            // TODO: Sim Time with Client (not real time) on every 4 Local SSEQ we send


            playerData.IncrementSseq();
            this.neededAckSSeq = playerData.getSseq();

            if ((playerData.getSseq() - playerData.lastSimTimeSEQ) >= 4)
            {
                timed = true;
            }

            playerData.getRPCShutDown();
            if (timed)
            {
                if (playerData.waitForRPCShutDown == true)
                {
                    content.append((byte)0xc2);
                }
                else
                {
                    content.append((byte)0x82);
                }

                content.append(TimeUtils.getCurrentSimTime(2000));
            }
            else
            {
                if (playerData.waitForRPCShutDown == true)
                {
                    content.append((byte)0x42);
                }
                else
                {
                    content.append((byte)0x02);
                }
            }

            // Merge all Message together and generate the Final Packet Header
            generateObjectMessageData();
            generateRpcMessageData();

            return(content.getBytes());
        }
Exemple #53
0
        public static byte[] createMessage(string message, string type, WorldClient client)
        {
            byte typeByte;

            switch (type)
            {
            case "TEAM":
                typeByte = 0x05;
                break;

            case "CREW":
                typeByte = 0x02;
                break;

            case "FACTION":
                typeByte = 0x03;
                break;

            case "SYSTEM":
                typeByte = 0x07;
                break;

            case "MODAL":
                typeByte = 0x17;
                break;

            case "FRAMEMODAL":
                typeByte = 0xd7;
                break;

            case "BROADCAST":
                typeByte = 0xc7;
                break;

            case "AREA":
                typeByte = 0x10;
                break;

            default:
                typeByte = 0x07;
                break;
            }

            byte[] messageBytes = StringUtils.stringToBytes(message + "\x00");

            DynamicArray din = new DynamicArray();

            UInt16 messageSize = (UInt16)(message.Length + 1);

            byte[] messageSizeHex = NumericalUtils.uint16ToByteArray(messageSize, 1);
            byte[] hexContents    = StringUtils.hexStringToBytes("00000000000000000024000000000000000000000000000000000000000000000000");



            din.append((byte)RPCResponseHeaders.SERVER_CHAT_MESSAGE_RESPONSE); // Response header
            din.append(typeByte);
            din.append(hexContents);
            din.append(messageSizeHex);
            din.append(messageBytes);


            return(din.getBytes());
        }
Exemple #54
0
 public void processSelfUpdateHealthIS(UInt16 viewID, UInt16 healthC, UInt16 isC)
 {
     DynamicArray din = new DynamicArray();
     din.append(0x03);
     din.append(NumericalUtils.uint16ToByteArray(viewID, 1));
     din.append(0x02);
     din.append(0x80);
     din.append(0x80);
     din.append(0x80);
     din.append(0x50);
     din.append(NumericalUtils.uint16ToByteArray(isC, 1));
     din.append(NumericalUtils.uint16ToByteArray(healthC, 1));
     din.append(0x00);
     // ToDO SEND PAK and get real health and IS
 }