uint32ToByteArray() public static method

public static uint32ToByteArray ( UInt32 data, int reversed ) : byte[]
data System.UInt32
reversed int
return byte[]
Esempio n. 1
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());
        }
Esempio n. 2
0
        public void processPlayFX(UInt32 fxID)
        {
            Output.writeToLogForConsole("PLAY FX FOR " + fxID.ToString());
            DynamicArray din = new DynamicArray();

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

            Random rand = new Random();
            ushort updateViewCounter = (ushort)rand.Next(3, 200);

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

            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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public static byte[] getUnixTime(int seconds)
        {
            TimeSpan ts       = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
            UInt32   unixTime = (UInt32)(ts.TotalSeconds + seconds);

            byte[] result = NumericalUtils.uint32ToByteArray(unixTime, 1);
            return(result);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public StaticWorldObject getObjectValues(UInt32 objectId)
        {
            Output.WriteLine("REQUEST OBJECT WITH ID :" +
                             StringUtils.bytesToString_NS(NumericalUtils.uint32ToByteArray(objectId, 0)));
            StaticWorldObject worldObject = null;

            worldObject = WorldObjectsDB.Find(delegate(StaticWorldObject temp)
            {
                return(temp.mxoStaticId == objectId);
            });
            if (worldObject == null)
            {
                worldObject = new StaticWorldObject();
            }

            return(worldObject);
        }
Esempio n. 7
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());
        }
Esempio n. 8
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());
        }
Esempio n. 9
0
        private void charNameRequest(byte[] packet, NetworkStream client)
        {
            // Get the handle text
            byte[] handleSize = new byte[2];
            handleSize[0] = packet[5];
            handleSize[1] = packet[6];

            int size = (int)NumericalUtils.ByteArrayToUint16(handleSize, 1);

            byte[] handleB = new byte[size - 1];
            ArrayUtils.copy(packet, 7, handleB, 0, size - 1);
            string handleBStr = StringUtils.bytesToString_NS(handleB);             // Handle as "414141"
            string handleStr  = StringUtils.charBytesToString(handleB);            // Handle as "AAA"

            // Process DB to answer the client - we directly create the character
            UInt32 dbResult = Store.dbManager.MarginDbHandler.getNewCharnameID(handleStr, userID);

            // Add the new charId so that we can work with it

            // Create the answer
            string nameRequestResponse = "";

            if (dbResult == 0)
            {
                nameRequestResponse += "0b0f00010000110000000000000000";
                nameRequestResponse += StringUtils.bytesToString_NS(handleSize);
                nameRequestResponse += handleBStr + "00";
            }
            else
            {
                newCharID            = dbResult;
                nameRequestResponse += "0b0f0000000000";
                nameRequestResponse += StringUtils.bytesToString_NS(NumericalUtils.uint32ToByteArray((UInt32)dbResult, 1));
                nameRequestResponse += "0000000000";
                nameRequestResponse += StringUtils.bytesToString_NS(handleSize);
                nameRequestResponse += handleBStr + "00";
            }

            Output.writeToLogForConsole(nameRequestResponse);
            sendMarginData(nameRequestResponse, client);
        }
Esempio n. 10
0
 public void addUint32(UInt32 value, int reversed)
 {
     packet.append(NumericalUtils.uint32ToByteArray(value, reversed));
 }
Esempio n. 11
0
        private void loadCharacter(byte[] packet, NetworkStream client, UInt32 theCharId)
        {
            byte[] charIDB = new byte[4];

            if (theCharId == 0)
            {
                ArrayUtils.copy(packet, 3, charIDB, 0, 4); //Offset for charID is 3 in request
                uint charId = (uint)NumericalUtils.ByteArrayToUint32(charIDB, 1);
                // Remove current instances for this character
                if (Store.margin.isAnotherClientActive(charId) == true)
                {
                    CharacterAlreadyInUseReply(client);
                    return;
                }
                this.newCharID = charId;
            }


            charIDB = NumericalUtils.uint32ToByteArray(this.newCharID, 1);

            //New harcoded sessionID is: ac 53 02 00
            //Old is: 28 A9 02 00
            string [] marginValues = new string[0x0e];
            marginValues[8]   = "000b10001e000700000001000800000000000a00000003000d00000000001c0000000100";
            marginValues[0xc] = "000e10000000";
            marginValues[0xd] = "010f10000000";

            // Some Items
            string itemData = "0170A7000000000010" + "020B8F00000000001803B80200000000001804EE9900000000000005F399000000000000065F0900000000100007C80900000000000008D59D000000000C0009EA040000000000480AD61E0000000000380BF21800000000001C0C66900000000000140DB30400000000001C0E04A80000000018000F3743000000000028108D2200000000002411441A00000000004415808C00000000004462EB0300000000001C63CC5A00000000004464ECB2000000000048651CB3000000000038663E9500000000006868EA0400000000001C";

            byte[] inventory = StringUtils.hexStringToBytes(itemData);

            // Loaded Abilities
            string loadedAbs = "000032080080070000E400800B0000E002800C00006403800E0000340180110032B400801600322C0080290032D404802B0000DC04802F00322800803000323000803E0001E404804200322005805D0000E800805E0032D000805F00327C01806B00008801806F00001C0580990001280580A40000A40080A60000AC0080AC0000EC0080B00000000180B10000040180B80032240180BB0032300180BC00004C0180C50000A00080D80001EC0480DD00012C0580EA0001E80480F400013005800D01013405801D0101680780200132740580280100E004802C01013805803601018C05803801017805803A01325C0780490100840180520100D8088056010124";

            byte[] loadAbilitys = StringUtils.hexStringToBytes(loadedAbs);

            // Known Abilities
            string abilityData = "0000320800800100014800800200017C0080030000080280040000140380050001300480060001B40080070000E4008008000018038009000F9400800A0000E002800B0000E002800C00006403800D00009000800E00003401800F00018C00801000006C0080110032B40080120000E402801300001003801400016400801500322004801600322C0080170001AC09801800012C008019000F9400801A0032C401801B00010800801C00018400801D0000F803801E001A3802801F00010400802000006C0280210001240580220032B40980230032640680240001680080250087DF11842600000400802700001C0080280032540480290032D404802A003210";

            byte[] knownAbilitiys = StringUtils.hexStringToBytes(abilityData);


            // Known Hardlines
            string hardlineData = "0207000000021f000000022300000002240000000225000000022600000002270000000229000000022b000000022f00000002300000000231000000023200000002340000000235000000023600000002370000000238000000023b000000023f000000024000000002410000000243000000024500000002480000000249000000024a000000024b000000024d000000024e000000024f000000025000000002510000000252000000025400000002550000000256000000025700000002580000000259000000025a000000025b000000025c000000025d000000025e000000025f000000026000000002610000000262000000026300000002640000000265000000026600000002670000000269000000026a000000026b000000026c000000026d000000026e000000026f000000027000000002710000000130000000013100000001370000000141000000014500000001480000000149000000014a000000014b000000014c000000014e000000014f0000000150000000015100000001520000000163000000016400000001650000000166000000016700000001680000000169000000016a000000016b000000016d000000016f00000001700000000171000000017200000001730000000174000000017700000001780000000179000000017a000000017b000000017c000000017d000000017e000000017f000000018000000001810000000182000000018300000001840000000185000000018600000001870000000188000000018a000000018b000000018c000000018d000000018e000000019000000001910000000192000000019300000001940000000195000000019600000001970000000198000000019900000003020000000303000000030400000003050000000306000000030700000003080000000309000000030a000000030b000000030c000000030d000000030e000000030f000000031000000003110000000312000000031300000003140000000315000000031600000003170000000318000000";

            //string hardlineData = Store.dbManager.MarginDbHandler.loadAllHardlines();
            byte[] knownHardlines = StringUtils.hexStringToBytes(hardlineData);


            // Contacts
            string missionContacts = "0700000001000800000000000a00000003000d00000000001c0000000100";

            byte[] knownContacts = StringUtils.hexStringToBytes(missionContacts);

            byte[] codeArchiveTest = StringUtils.hexStringToBytes("04000000A7010000AC010000CC010000D1010000D60100001302000019020000650200006602000068020000B4020000B5020000B6020000BB020000BC020000C2020000C4020000D5020000D6020000DE020000E2020000E3020000E6020000E7020000E90200003F03000086030000A0030000AA030000E3030000FC030000FE030000030400000604000008040000090400000A040000270400004C0400004E040000BB040000C2040000CE040000EB040000EC040000EE040000F5040000F6040000F7040000F9040000540900005F09000082090000BE090000BF090000C1090000C4090000C7090000C8090000C9090000040A0000080A0000B0120000");

            byte[] empty = new byte[0];

            // New Margin Method to send Data

            // Pre-Load Abilities so that we just need to filter the result later
            loadAbilities((int)this.newCharID);

            sendMarginCharData(empty, 0x01, client);
            sendMarginCharData(loadBackgroundInfo((int)this.newCharID), 0x02, client);
            sendMarginCharData(empty, 0x03, client);                                  // BuddyList (but old one)
            sendMarginCharData(empty, 0x04, client);                                  // Unknown - no one has data there so ignore it
            //sendMarginCharData(loadInventory((int)this.newCharID), 0x05, client);            // Inventory
            sendMarginCharData(StringUtils.hexStringToBytes(itemData), 0x05, client); // Inventory CR1
            sendMarginCharData(loadEquippedAbilities(), 0x06, client);                // Loaded Abilitys
            //sendMarginCharData(empty, 0x06, client);          // Loaded Abilitys CR1
            sendMarginCharData(loadKnownAbilities(), 0x07, client);                   // Known Abilities
            sendMarginCharData(knownHardlines, 0x08, client);                         // Hardlines
            sendMarginCharData(empty, 0x09, client);                                  // Access Nodes?
            //sendMarginCharData(codeArchiveTest, 0x0a, client);                  // Code Storage
            sendMarginCharData(empty, 0x0a, client);                                  // Code Storage CR1
            sendMarginCharData(knownContacts, 0x0b, client);                          // Contacts
            sendMarginCharData(empty, 0x0e, client);

            // ModT (has a seperate format)
            sendMarginData("1000000000" + StringUtils.bytesToString_NS(charIDB) + "10270d010f10000000", client);

            /* This is the server MOTD announcement (its disabled now) */

            /*DynamicArray announcement = new DynamicArray();
             * byte[] header = {0x10,0x00,0x00,0x00,0x00,0xac,0x53,0x02,0x00,0x10,0x27,0x0E,0x01,0x0D,0x10,0x00};
             * TimeUtils tim = new TimeUtils();
             * byte[] currentTime = tim.getUnixTime();
             * //Load motd from file
             * XmlParser xmlP = new XmlParser();
             * string[] data=xmlP.loadDBParams("Config.xml");
             * string motd=data[5];
             *
             * if (!motd.Equals("")){ // if MOTD not empty
             *      byte[] text = StringUtils.stringToBytes(motd);
             *      byte[] size = NumericalUtils.uint16ToByteArray((UInt16)(currentTime.Length+text.Length),1);
             *
             *      announcement.append(header);
             *      announcement.append(size);
             *      announcement.append(currentTime);
             *      announcement.append(text);
             *
             * byte[] encryptedResponse14 = marginEncr.encrypt(announcement.getBytes());
             * sendTCPVariableLenPacket(encryptedResponse14, client);
             * }*/
            /* End of the MOTD */

            //Output.WriteLine("[MARGIN] UserID "+this.userID+" waiting for session reply from world");
            //waitForWorldReply(); //TODO: enabling this outputted the "no usage" bug
            //Output.WriteLine("[MARGIN] World Session Reply OK for UserID "+this.userID);

            //System.Threading.Thread.Sleep(1000);
            //EstablishUDPSessionReply(packet, client);
        }
Esempio n. 12
0
        private void sendMarginCharData(byte[] data, byte opcode, NetworkStream client)
        {
            // This Method will be used to send the real Data to the client

            // Format for general LoadCharacterReply Responses:
            // 10 00 00 00 <- everytime the same
            // 00 f9 76 04 <- uint32 Char ID
            // 00 00 00 09 <- uint32 number of Character Replys (just raise one up)
            // 00 05 <- viewData opcode (what data is inside) uint16
            // 10 00 <- if it has Data it is 10 00 if not is just 00 00 (and no Data can follow up and packet ends here)
            // e1 00 <- short / uint16 data size
            // DATA

            byte[] header = { 0x10, 0x00, 0x00, 0x00 };
            // Raise one up
            loadCharCounter++;

            // Add the counter
            byte[] counterByte = new byte[4];
            counterByte = NumericalUtils.uint32ToByteArray(loadCharCounter, 1);

            // get the datasize for the packet
            byte[] dataSize = NumericalUtils.uint16ToByteArray((UInt16)data.Length, 1);

            // charId
            byte[] charID = NumericalUtils.uint32ToByteArray(this.newCharID, 0);

            // viewData code
            byte[] responseCode = { 0x00, opcode };

            string pakData = StringUtils.bytesToString_NS(header) +
                             StringUtils.bytesToString_NS(charID) +
                             StringUtils.bytesToString_NS(counterByte) +
                             StringUtils.bytesToString_NS(responseCode);

            string hasData;

            // this needs improvement...
            if (data.Length == 0 && opcode == 0x01)
            {
                hasData = "0000";
            }
            else
            {
                hasData = "1000" + StringUtils.bytesToString_NS(dataSize) + StringUtils.bytesToString_NS(data);
            }

            pakData += hasData;
            PacketContent pak = new PacketContent();

            // Dump the Packet Data to see whats in
            //Console.WriteLine("Response Load Pak : " + pakData);

            // Do the viewData
            byte[] response = StringUtils.hexStringToBytes(pakData);
            Output.WritePacketLog(StringUtils.bytesToString(response), "MARGINSERVER", "0", "0", "0");
            Output.WriteDebugLog("[MARGIN SERVER RESPONSE] for OPCODE " + opcode + " : " + StringUtils.bytesToString(response));
            byte[] encryptedResponse = marginEncr.encrypt(response);
            sendTCPVariableLenPacket(encryptedResponse, client);
            System.Threading.Thread.Sleep(50);
        }
Esempio n. 13
0
        public void processOpenDoor(StaticWorldObject door)
        {
            UInt16 typeId = NumericalUtils.ByteArrayToUint16(door.type, 1);

            byte[] masterViewId = { 0x01, 0x00 };
            byte[] seperator    = { 0xcd, 0xab };

            Store.currentClient.playerData.newViewIdCounter++; // It is just for a test Later we will change this to have a List with Views and Object IDs

            byte[] disarmDifficultyMaybe = { 0x03, 0x84 };
            byte[] endViewID             = { 0x00, 0x00 };

            byte[] spawnCounter = NumericalUtils.uint16ToByteArrayShort(Store.currentClient.playerData.assignSpawnIdCounter());
            Output.WriteLine("[DOOR]POS X : " + door.pos_x.ToString() + " POS Y: " + door.pos_y.ToString() + " POS Z: " + door.pos_z.ToString() + ", TypeId: " + StringUtils.bytesToString_NS(door.type));

            switch (typeId)
            {
            case 417:
            case 419:
                // ToDo: Packet Format for Elevator
                // 02 03 01 00
                // 08
                // a3 01
                // 6b 01 f0 3d be
                // cd ab 03 88 00 00 00 00 ff ff 7f 3f 00 00 00 00 f3 04 35 33
                // 22 00 00 00 00 40 f4 fb 40 00 00 00 00 00 90 75 40 00 00 00 00 00 40 af 40 ff ff ff ff 19 00 00
                // 11 00 01 00 04 61 97 e1 47 f0 bf 2d 44 de 30 35 45 00 00
                PacketContent content = new PacketContent();
                content.addByteArray(masterViewId);
                content.addByte(0x08);
                content.addByteArray(door.type);
                content.addByteArray(NumericalUtils.uint32ToByteArray(door.mxoId, 1));
                content.addByteArray(spawnCounter);                            // Spawn Object Counter
                content.addByteArray(seperator);
                content.addByte(0x03);                                         // Number of Attributes to parse (3)
                content.addByte(0x88);                                         // GROUP 1 - more groups ON, Attribute 4 (305,Orientation,LTQuaternion,16) SET (10001000)
                content.addByteArray(StringUtils.hexStringToBytes(door.quat)); // ToDo: replace it later with the real LTQuaternion
                content.addByte(0x22);                                         // GROUP 2 - more groups OFF, Attribute 2,6  SET (00100010)
                content.addDoubleLtVector3d(door.pos_x, door.pos_y, door.pos_z);
                content.addByteArray(new byte[] { 0xff, 0xff, 0xff, 0xff });
                content.addByteArray(NumericalUtils.uint16ToByteArray(Store.currentClient.playerData.newViewIdCounter, 1));
                content.addByteArray(endViewID);
                content.addByte(0x00);
                Store.currentClient.messageQueue.addObjectMessage(content.returnFinalPacket(), false);
                break;

            case 2506:
                // ToDo: Packet Format for Elevator


                break;

            default:

                PacketContent contentDefault = new PacketContent();
                contentDefault.addByteArray(masterViewId);
                contentDefault.addByte(0x08);
                contentDefault.addByteArray(door.type);
                contentDefault.addByteArray(NumericalUtils.uint32ToByteArray(door.mxoId, 1));
                contentDefault.addByteArray(spawnCounter);     // Spawn Object Counter
                contentDefault.addByteArray(seperator);
                contentDefault.addByteArray(disarmDifficultyMaybe);
                contentDefault.addByte(0x00);                                                                  // isZionAligned?
                contentDefault.addByteArray(StringUtils.hexStringToBytes("0000000000803F000000000000000041")); // ToDo: replace it later with the real values from the object
                contentDefault.addDoubleLtVector3d(door.pos_x, door.pos_y, door.pos_z);
                contentDefault.addByteArray(StringUtils.hexStringToBytes("34080000"));
                contentDefault.addByteArray(NumericalUtils.uint16ToByteArray(Store.currentClient.playerData.newViewIdCounter, 1));
                contentDefault.addByteArray(endViewID);
                contentDefault.addByte(0x00);
                Store.currentClient.messageQueue.addObjectMessage(contentDefault.returnFinalPacket(), false);
                break;
            }
        }
Esempio n. 14
0
        private void loadCharacter(byte[] packet, NetworkStream client, UInt32 theCharId)
        {
            byte[] charIDB = new byte[4];

            if (theCharId == 0)
            {
                ArrayUtils.copy(packet, 3, charIDB, 0, 4); //Offset for charID is 3 in request
                uint charId = (uint)NumericalUtils.ByteArrayToUint32(charIDB, 1);
                // Remove current instances for this character
                if (Store.margin.isAnotherClientActive(charId) == true)
                {
                    CharacterAlreadyInUseReply(client);
                    return;
                }
                this.newCharID = charId;
            }


            charIDB = NumericalUtils.uint32ToByteArray(this.newCharID, 1);

            //New harcoded sessionID is: ac 53 02 00
            //Old is: 28 A9 02 00
            string [] marginValues = new string[0x0e];
            marginValues[8]   = "000b10001e000700000001000800000000000a00000003000d00000000001c0000000100";
            marginValues[0xc] = "000e10000000";
            marginValues[0xd] = "010f10000000";

            // Some Items
            string itemData = "0170A7000000000010" + "020B8F00000000001803B80200000000001804EE9900000000000005F399000000000000065F0900000000100007C80900000000000008D59D000000000C0009EA040000000000480AD61E0000000000380BF21800000000001C0C66900000000000140DB30400000000001C0E04A80000000018000F3743000000000028108D2200000000002411441A00000000004415808C00000000004462EB0300000000001C63CC5A00000000004464ECB2000000000048651CB3000000000038663E9500000000006868EA0400000000001C";

            byte[] inventory = StringUtils.hexStringToBytes(itemData);

            // Loaded Abilities
            string loadedAbs = "000032080080070000E400800B0000E002800C00006403800E0000340180110032B400801600322C0080290032D404802B0000DC04802F00322800803000323000803E0001E404804200322005805D0000E800805E0032D000805F00327C01806B00008801806F00001C0580990001280580A40000A40080A60000AC0080AC0000EC0080B00000000180B10000040180B80032240180BB0032300180BC00004C0180C50000A00080D80001EC0480DD00012C0580EA0001E80480F400013005800D01013405801D0101680780200132740580280100E004802C01013805803601018C05803801017805803A01325C0780490100840180520100D8088056010124";

            byte[] loadAbilitys = StringUtils.hexStringToBytes(loadedAbs);

            // Known Abilities
            string abilityData = "0000320800800100014800800200017C0080030000080280040000140380050001300480060001B40080070000E4008008000018038009000F9400800A0000E002800B0000E002800C00006403800D00009000800E00003401800F00018C00801000006C0080110032B40080120000E402801300001003801400016400801500322004801600322C0080170001AC09801800012C008019000F9400801A0032C401801B00010800801C00018400801D0000F803801E001A3802801F00010400802000006C0280210001240580220032B40980230032640680240001680080250087DF11842600000400802700001C0080280032540480290032D404802A003210";

            byte[] knownAbilitiys = StringUtils.hexStringToBytes(abilityData);


            // Known Hardlines
            //string hardlineData = "0207000000021f000000022300000002240000000225000000022600000002270000000229000000022b000000022f00000002300000000231000000023200000002340000000235000000023600000002370000000238000000023b000000023f000000024000000002410000000243000000024500000002480000000249000000024a000000024b000000024d000000024e000000024f000000025000000002510000000252000000025400000002550000000256000000025700000002580000000259000000025a000000025b000000025c000000025d000000025e000000025f000000026000000002610000000262000000026300000002640000000265000000026600000002670000000269000000026a000000026b000000026c000000026d000000026e000000026f000000027000000002710000000130000000013100000001370000000141000000014500000001480000000149000000014a000000014b000000014c000000014e000000014f0000000150000000015100000001520000000163000000016400000001650000000166000000016700000001680000000169000000016a000000016b000000016d000000016f00000001700000000171000000017200000001730000000174000000017700000001780000000179000000017a000000017b000000017c000000017d000000017e000000017f000000018000000001810000000182000000018300000001840000000185000000018600000001870000000188000000018a000000018b000000018c000000018d000000018e000000019000000001910000000192000000019300000001940000000195000000019600000001970000000198000000019900000003020000000303000000030400000003050000000306000000030700000003080000000309000000030a000000030b000000030c000000030d000000030e000000030f000000031000000003110000000312000000031300000003140000000315000000031600000003170000000318000000";
            //string hardlineData = Store.dbManager.MarginDbHandler.loadAllHardlines();
            string hardlineData = "0130000000013100000001370000000141000000014500000001480000000149000000014A000000014B000000014C000000014E000000014F00000001500000000151000000015200000001530000000163000000016400000001650000000166000000016700000001680000000169000000016A000000016B000000016D000000016F00000001700000000171000000017200000001730000000174000000017700000001780000000179000000017A000000017B000000017C000000017D000000017E000000017F000000018000000001810000000182000000018300000001840000000185000000018600000001870000000188000000018A000000018B000000018C000000018D000000018E000000018F00000001900000000191000000019200000001930000000194000000019500000001960000000197000000019800000001990000000207000000021F000000022300000002240000000225000000022600000002270000000229000000022B000000022F00000002300000000231000000023200000002340000000235000000023600000002370000000238000000023B000000023F000000024000000002410000000243000000024500000002480000000249000000024A000000024B000000024D000000024E000000024F000000025000000002510000000252000000025400000002550000000256000000025700000002580000000259000000025A000000025B000000025C000000025D000000025E000000025F000000026000000002610000000262000000026300000002640000000265000000026600000002670000000269000000026A000000026B000000026C000000026D000000026E000000026F0000000270000000027100000003020000000303000000030400000003050000000306000000030700000003080000000309000000030A000000030B000000030C000000030D000000030E000000030F00000003100000000311000000031200000003130000000314000000031500000003160000000317000000031800000011010000000E010000000F0100000010020000000C010000000D01000000";

            byte[] knownHardlines = StringUtils.hexStringToBytes(hardlineData);


            // Contacts
            string missionContacts = "0700000001000800000000000a00000003000d00000000001c0000000100";

            byte[] knownContacts = StringUtils.hexStringToBytes(missionContacts);

            byte[] codeArchiveTest = StringUtils.hexStringToBytes("04000000A7010000AC010000CC010000D1010000D60100001302000019020000650200006602000068020000B4020000B5020000B6020000BB020000BC020000C2020000C4020000D5020000D6020000DE020000E2020000E3020000E6020000E7020000E90200003F03000086030000A0030000AA030000E3030000FC030000FE030000030400000604000008040000090400000A040000270400004C0400004E040000BB040000C2040000CE040000EB040000EC040000EE040000F5040000F6040000F7040000F9040000540900005F09000082090000BE090000BF090000C1090000C4090000C7090000C8090000C9090000040A0000080A0000B0120000");

            byte[] empty = new byte[0];

            // New Margin Method to send Data

            // Pre-Load Abilities so that we just need to filter the result later
            loadAbilities((int)this.newCharID);

            sendMarginCharData(empty, 0x01, client, 0, false);
            sendMarginCharData(loadBackgroundInfo((int)this.newCharID), 0x02, client, 0, false);
            sendMarginCharData(empty, 0x03, client, 0, false);                              // BuddyList (but old one)
            sendMarginCharData(empty, 0x04, client, 0, false);                              // Unknown - no one has data there so ignore it
            sendMarginCharData(loadInventory((int)this.newCharID), 0x05, client, 0, false); // Inventory
            //sendMarginCharData(StringUtils.hexStringToBytes(itemData), 0x05, client);            // Inventory CR1
            sendMarginCharData(loadEquippedAbilities(), 0x06, client, 0, false);            // Loaded Abilitys
            //sendMarginCharData(empty, 0x06, client);                          // Loaded Abilitys CR1
            sendMarginCharData(loadKnownAbilities(), 0x07, client, 0, false);               // Known Abilities
            sendMarginCharData(knownHardlines, 0x08, client, 0, false);                     // Hardlines
            sendMarginCharData(empty, 0x09, client, 0, false);                              // Access Nodes?
            //sendMarginCharData(codeArchiveTest, 0x0a, client);                // Code Storage
            sendMarginCharData(empty, 0x0a, client, 0, false);                              // Code Storage CR1
            sendMarginCharData(knownContacts, 0x0b, client, 0, false);                      // Contacts
            sendMarginCharData(empty, 0x0e, client, 0, false);

            // MotD has a special handling
            DbParams _dbParams;

            XmlParser.loadDBParams("Config.xml", out _dbParams);
            string motd = _dbParams.Motd;

            if (!motd.Equals(""))              // if MOTD not empty
            {
                DynamicArray announcement = new DynamicArray();
                byte[]       currentTime  = TimeUtils.getUnixTime();
                //Load motd from file
                byte[] text = StringUtils.stringToBytes(motd);
                byte[] size = NumericalUtils.uint16ToByteArrayShort((UInt16)(currentTime.Length + text.Length));

                //announcement.append(size);
                announcement.append(currentTime);
                announcement.append(text);

                sendMarginCharData(announcement.getBytes(), 0x0d, client, 10000, true);
            }
            /* End of the MOTD */
        }
Esempio n. 15
0
 public void setValue(UInt32 newValue)
 {
     byte[] t = NumericalUtils.uint32ToByteArray(newValue, 1);
     setValue(t);
 }
Esempio n. 16
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);
            }
        }
Esempio n. 17
0
        public byte[] checksumB(byte[] block, int reversed)
        {
            UInt32 temp = checksum(block);

            return(NumericalUtils.uint32ToByteArray(temp, reversed));
        }