Exemple #1
0
        public static uint[] DumpSaveSlots(TCPGecko gecko, uint diff, uint start, uint size)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                // dump all save slots
                gecko.Dump(start + diff, start + diff + size, memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);

                // convert to a uint array
                uint[] saveSlots = new uint[size / 4];
                for (int i = 0; i < saveSlots.Length; i++)
                {
                    Byte[] buffer = new Byte[4];
                    memoryStream.Read(buffer, 0, 4);
                    saveSlots[i] = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 0));
                }

                return(saveSlots);
            }
        }
Exemple #2
0
        public BaseResult send_msg(Message message)
        {
            try
            {
                message.sender = clientID;
                int    len  = message.message.buf.Length + (4 * 4);
                Byte[] data = new Byte[len];
                ByteSwap.swapTo((uint)message.sender, data, 1 * 4); // An welcher Stelle kommt der Sender rein???
                ByteSwap.swapTo((uint)message.Type, data, 2 * 4);
                ByteSwap.swapTo((uint)message.message.buf.Length, data, 3 * 4);
                message.message.buf.CopyTo(data, 4 * 4);
                TcpClient.GetStream().Write(data, 0, len);

                return(new BaseResult());
            }
            catch (Exception e)
            {
                log.Fatal("Method send_msg is Crashed!" + e);

                return(new BaseResult(e));
            }
        }
Exemple #3
0
        public void ByteSwap_ReplaceBytesTest()
        {
            byte[] buffer    = new byte[sizeof(ulong)];
            byte[] buffer_bc = null;
            ulong  value     = kBeforeValue;

            // UInt64
            ByteSwap.ReplaceBytes(buffer, 0, value);
            buffer_bc = BitConverter.GetBytes(value);
            Assert.IsTrue(buffer_bc.EqualsArray(buffer));

            // UInt40
            value = kBeforeValueUInt40;
            Array.Clear(buffer, 0, buffer.Length);
            ByteSwap.ReplaceBytesUInt40(buffer, 0, value);
            buffer_bc = BitConverter.GetBytes(value);
            Assert.IsTrue(buffer_bc.EqualsArray(buffer));

            // UInt32
            value >>= 32;
            Array.Clear(buffer, 0, buffer.Length);
            ByteSwap.ReplaceBytes(buffer, 0, (uint)value);
            buffer_bc = BitConverter.GetBytes((uint)value);
            Assert.IsTrue(buffer_bc.EqualsArray(buffer));

            // UInt24
            value = kBeforeValueUInt24;
            Array.Clear(buffer, 0, buffer.Length);
            ByteSwap.ReplaceBytesUInt24(buffer, 0, (uint)value);
            buffer_bc = BitConverter.GetBytes((uint)value);
            Assert.IsTrue(buffer_bc.EqualsArray(buffer));

            // UInt16
            value >>= 16;
            Array.Clear(buffer, 0, buffer.Length);
            ByteSwap.ReplaceBytes(buffer, 0, (ushort)value);
            buffer_bc = BitConverter.GetBytes((ushort)value);
            Assert.IsTrue(buffer_bc.EqualsArray(buffer));
        }
Exemple #4
0
        public async Task <BaseResult> Read()
        {
            try
            {
                var buffer = new byte[64000];
                var ns     = TcpClient.GetStream();

                while (true)
                {
                    int len = 0;

                    while (len < 16)
                    {
                        if (ns.DataAvailable)
                        {
                            var numRead = await ns.ReadAsync(buffer, len, 16 - len);

                            if (numRead == 0)
                            {
                                return(new BaseResult());
                            }
                            len += numRead;
                        }
                    }
                    int msgType = BitConverter.ToInt32(buffer, 2 * 4);
                    int length  = BitConverter.ToInt32(buffer, 3 * 4);
                    length  = (int)ByteSwap.swap((uint)length);
                    msgType = (int)ByteSwap.swap((uint)msgType);
                    len     = 0;
                    var msgBuffer = new byte[length];
                    while (len < length)
                    {
                        try
                        {
                            var numRead = await ns.ReadAsync(msgBuffer, len, length - len);

                            if (numRead == 0)
                            {
                                return(new BaseResult());
                            }
                            len += numRead;
                        }
                        catch (System.IO.IOException e)
                        {
                        }
                    }

                    Message m = new Message(new MessageBuffer(msgBuffer), (Message.MessagesType)msgType);

                    switch (m.Type)
                    {
                    case Message.MessagesType.COVISE_MESSAGE_VRBC_SEND_SESSIONS:
                        int sessioncount = m.message.readInt();
                        MessageHandler.RoomList.Clear();
                        RoomList.Clear();
                        for (int i = 0; i < sessioncount; i++)
                        {
                            SessionID room = new SessionID();
                            SharedStateSerializer.deserialize(ref m.message, ref room);
                            if (room.m_isPrivate == false)
                            {
                                RoomList.Add(room);
                            }
                            else
                            {
                                RoomsViewModel.privateSession = room;
                            }
                        }
                        MessageHandler.addCurrentRooms(RoomList);
                        break;

                    case Message.MessagesType.COVISE_MESSAGE_VRBC_SET_SESSION:
                        SessionID currentSession = new SessionID();
                        SharedStateSerializer.deserialize(ref m.message, ref currentSession);
                        MessageHandler.addCurrentSession(currentSession);
                        SharedStateManager.Instance.update(new SessionID(clientID, clientID.ToString(), true), currentSession, false, false);
                        break;

                    case Message.MessagesType.COVISE_MESSAGE_VRB_REGISTRY_ENTRY_CHANGED:
                        int           senderID  = m.message.readInt();
                        string        className = m.message.readString();
                        string        variable  = m.message.readString();
                        MessageBuffer mb4       = m.message.readMessageBuffer();
                        SharedStateManager.Instance.updateSharedState(className, variable, mb4);
                        break;


                    case Message.MessagesType.COVISE_MESSAGE_VRB_SET_USERINFO:
                        int sessionSwitchUserId = m.message.readInt();
                        break;

                    case Message.MessagesType.COVISE_MESSAGE_VRB_QUIT:
                        int    disconnectedUserId  = m.message.readInt();
                        string msgDisconnectedUser = "******" + disconnectedUserId.ToString() + "|";
                        SendDisconnecteUser(msgDisconnectedUser);
                        break;

                    case Message.MessagesType.COVISE_MESSAGE_VRB_MESSAGE:
                        int msgIdentifyer = m.message.readInt();

                        // Head Position
                        if (msgIdentifyer == 100)
                        {
                            int    senderId  = m.message.readInt();
                            string ipAddress = m.message.readString();
                            int    positionX = m.message.readInt();
                            int    positionY = m.message.readInt();
                            int    positionZ = m.message.readInt();
                            int    rotationX = m.message.readInt();
                            int    rotationY = m.message.readInt();
                            int    rotationZ = m.message.readInt();

                            string msgHead = "HEAD:" + senderId.ToString() + " " + positionX.ToString() + " " + positionY.ToString() + " " + positionZ.ToString() + " " + rotationX.ToString() + " " + rotationY + " " + rotationZ.ToString() + "|";
                            SendHmdPosition(msgHead);
                            break;
                        }

                        //ControllerPosition
                        if (msgIdentifyer == 101)
                        {
                            int senderId             = m.message.readInt();
                            int handId               = m.message.readInt();
                            int Controller_PositionX = m.message.readInt();
                            int Controller_PositionY = m.message.readInt();
                            int Controller_PositionZ = m.message.readInt();

                            int Controller_RotationX = m.message.readInt();
                            int Controller_RotationY = m.message.readInt();
                            int Controller_RotationZ = m.message.readInt();

                            int Controller_OffSetRotationZ = m.message.readInt();

                            var    ControllerDataIntArray = new int[] { senderId, msgType, handId, Controller_PositionX, Controller_PositionY, Controller_PositionZ, Controller_RotationX, Controller_RotationY, Controller_RotationZ };
                            string msgController          = "CONTROLLER:" + senderId.ToString() + " " + handId.ToString() + " " + Controller_PositionX.ToString() + " " + Controller_PositionY.ToString() + " " + Controller_PositionZ + " " + Controller_RotationX + " " + Controller_RotationY + " " + Controller_RotationZ + " " + Controller_OffSetRotationZ + "|";
                            SendControllerPosition(msgController);
                            break;
                        }
                        if (msgIdentifyer == 103)
                        {
                            int    disconnectedUserId_SessionChanged = m.message.readInt();
                            string msgDisconnectedUser2 = "DISCONNECTEDUSER:"******"|";
                            SendDisconnecteUser(msgDisconnectedUser2);
                            break;
                        }
                        if (msgIdentifyer == 102)
                        {
                            int buttonId = m.message.readInt();
                            int handId   = m.message.readInt();
                            int senderId = m.message.readInt();
                            // TODO need unter Type für Controller solange solte es so gehen
                            if (senderId < 100)
                            {
                                int[] intArrayControllerInput = new int[3];
                                intArrayControllerInput[0] = buttonId;
                                intArrayControllerInput[1] = handId;
                                intArrayControllerInput[2] = senderId;
                                string msgControllerInput = "CONTROLLERINPUT:" + buttonId.ToString() + " " + handId.ToString() + " " + senderId.ToString() + "|";
                                SendControllerInput(msgControllerInput);
                                break;
                            }
                            break;
                        }
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                log.Fatal("Method Read is Crashed!" + e);
                return(new BaseResult());
            }
        }
Exemple #5
0
        public void Update(bool fast)
        {
            MemoryStream miniDump = new MemoryStream();
            int          oldColumnIndex, oldRowIndex;

            if (gView.SelectedCells.Count > 0)
            {
                oldColumnIndex = gView.SelectedCells[0].ColumnIndex;
                oldRowIndex    = gView.SelectedCells[0].RowIndex;
            }
            else
            {
                oldColumnIndex = 1;
                oldRowIndex    = 1;
            }

            UInt32 sAddress = cAddress & 0xFFFFFFF0;
            UInt32 offset   = cAddress - sAddress;

            try
            {
                gecko.Dump(sAddress, sAddress + 0x100, miniDump);

                //gView.Rows.Add(16);
                // Only clear and re-load gView.Rows when it's != 16
                // This was one thing slowing us down...
                if (gView.Rows.Count != 16)
                {
                    gView.Rows.Clear();
                    gView.Rows.Add(16);
                }

                miniDump.Seek(0, SeekOrigin.Begin);
                UInt32 value, bValue;
                Byte[] buffer = new Byte[4];
                UInt16 hwInput;
                UInt32 pValue = 0;
                for (int i = 0; i < 16; i++)
                {
                    gView.Rows[i].Cells[0].Value = GlobalFunctions.toHex(sAddress + i * 16);
                    for (int j = 1; j < 5; j++)
                    {
                        miniDump.Read(buffer, 0, 4);
                        bValue = BitConverter.ToUInt32(buffer, 0);
                        value  = ByteSwap.Swap(bValue);
                        if (sAddress + i * 0x10 + (j - 1) * 4 == selAddress)
                        {
                            pValue = value;
                        }
                        DataGridViewCell cell = gView.Rows[i].Cells[j];
                        if (PViewMode == MemoryViewMode.Hex)
                        {
                            cell.Value = GlobalFunctions.toHex(value);
                        }
                        else if (PViewMode == MemoryViewMode.ASCII)
                        {
                            cell.Value = DecodeASCII(buffer);
                        }
                        else if (PViewMode == MemoryViewMode.ANSI)
                        {
                            cell.Value = DecodeANSI(buffer);
                        }
                        else if (PViewMode == MemoryViewMode.Unicode)
                        {
                            cell.Value = DecodeUnicode(buffer);
                        }
                        else if (PViewMode == MemoryViewMode.Single)
                        {
                            cell.Value = PrettyFloat(GlobalFunctions.UIntToSingle(value));
                        }
                        else if (PViewMode == MemoryViewMode.AutoZero || PViewMode == MemoryViewMode.AutoDot)
                        {
                            // if it might be a pointer, cast it as hex
                            if (ValidMemory.validAddress(value))
                            {
                                cell.Value = GlobalFunctions.toHex(value);
                            }
                            else
                            {
                                // If it's a float, and it's not too big or small, cast it as a Single
                                Single singleCast = GlobalFunctions.UIntToSingle(value);
                                if (!Single.IsNaN(singleCast) && Math.Abs(singleCast) > 1e-7 && Math.Abs(singleCast) < 1e10)
                                {
                                    cell.Value = PrettyFloat(GlobalFunctions.UIntToSingle(value));
                                }
                                else
                                {
                                    if (IsASCII(buffer))
                                    {
                                        if (PViewMode == MemoryViewMode.AutoZero && value == 0)
                                        {
                                            // Cast 0 as hex in auto zero mode
                                            cell.Value = GlobalFunctions.toHex(value);
                                        }
                                        else
                                        {
                                            // If all characters are valid printable ASCII, cast it as char
                                            cell.Value = DecodeASCII(buffer);
                                        }
                                    }
                                    else
                                    {
                                        // When all else fails, cast as hex
                                        cell.Value = GlobalFunctions.toHex(value);
                                    }
                                }
                            }
                        }
                    }
                }
                oldRow = (int)offset / 0x10;
                oldCol = (int)(offset & 0xC) / 4 + 1;
                if (!fast)
                {
                    gView.Rows[oldRowIndex].Cells[oldColumnIndex].Selected = true;
                    // Don't update the poke value during auto-updates
                    // This way the user can still poke things

                    // TODO: Ignore this if the poke operation isn't write?
                    //pokeValue.Text = GlobalFunctions.toHex(pValue);
                }

                pokeAddress.Text = GlobalFunctions.toHex(selAddress);
                fpValue.Text     = GlobalFunctions.UIntToSingle(pValue).ToString("G6");
            }
            catch (ETCPGeckoException e)
            {
                exceptionHandling.HandleException(e);
            }
        }
Exemple #6
0
 private UInt32 ReadStream(Stream input)
 {
     Byte[] buffer = new Byte[4];
     input.Read(buffer, 0, 4);
     return((UInt32)ByteSwap.Swap(BitConverter.ToUInt32(buffer, 0)));
 }
Exemple #7
0
        public override ulong ReadUInt64()
        {
            var value = base.ReadUInt64();

            return(IsLittleEndian ? value : ByteSwap.SwapBytes(value));
        }
Exemple #8
0
        public override int ReadInt32()
        {
            var value = base.ReadInt32();

            return(IsLittleEndian ? value : ByteSwap.SwapBytes(value));
        }
Exemple #9
0
        public override ushort ReadUInt16()
        {
            var value = base.ReadUInt16();

            return(IsLittleEndian ? value : ByteSwap.SwapBytes(value));
        }
Exemple #10
0
        public void DumpTree()
        {
            //address will be alligned to 4
            UInt32 paddress = 0x80000038;

            //Create a memory stream for the actual dump
            MemoryStream stream = new MemoryStream();

            try
            {
                //dump data
                gecko.Dump(paddress, paddress + 8, stream);

                //go to beginning
                stream.Seek(0, SeekOrigin.Begin);
                Byte[] buffer = new Byte[8];
                stream.Read(buffer, 0, 8);

                //Stream can be cleared now
                stream.Close();

                //Read buffer
                UInt32 fstadd  = BitConverter.ToUInt32(buffer, 0);
                UInt32 fstsize = BitConverter.ToUInt32(buffer, 4);

                //Swap to machine endianness and return
                fstadd  = ByteSwap.Swap(fstadd);
                fstsize = ByteSwap.Swap(fstsize);

                stream = new MemoryStream();
                gecko.Dump(fstadd, fstadd + fstsize + 1, stream);
                stream.Seek(-1, SeekOrigin.End);
                buffer = new Byte[] { 0xFF };
                stream.Write(buffer, 0, 1);

                stream.Seek(0, SeekOrigin.Begin);
                buffer = new Byte[0xC];
                stream.Read(buffer, 0, 12);

                Byte   flag = buffer[0];
                UInt32 truenameoff;
                buffer[0] = 0;
                UInt32 nameoff = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 0));
                UInt32 offset  = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 4));
                UInt32 entries = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 8));
                long   fstpos  = stream.Position;
                UInt32 strpos  = entries * 0x0C;
                UInt32 endpos  = strpos;

                //List<TreeNode> rootArr = new List<TreeNode>();
                List <fileStructure> rootArr = new List <fileStructure>();
                List <UInt32>        dirSize = new List <UInt32>();
                dirSize.Add(0);

                fstTextPositions.Clear();
                sourceFile                = null;
                targetFile                = null;
                generatedSwapCode.Text    = "";
                targetFileName.Text       = "";
                sourceFileName.Text       = "";
                setAsSourceButton.Enabled = false;
                setAsTargetButton.Enabled = false;
                generateFileSwap.Enabled  = false;
                swapFilesNow.Enabled      = false;
                selectedFile              = -1;

                //TreeNode current = treeView.Nodes.Add("Root");
                fileStructure current = new fileStructure("Root", -1);
                root = current;

                int tag;
                int curDir = 0;
                rootArr.Add(current);
                String nname;
                do
                {
                    stream.Seek(fstpos, SeekOrigin.Begin);
                    stream.Read(buffer, 0, 12);

                    flag        = buffer[0];
                    truenameoff = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 0));
                    buffer[0]   = 0;
                    nameoff     = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 0));
                    offset      = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 4));
                    entries     = ByteSwap.Swap(BitConverter.ToUInt32(buffer, 8));

                    fstTextPositions.Add(new fstEntry((UInt32)fstpos + fstadd,
                                                      truenameoff, offset, entries, (UInt32)fstpos + strpos + nameoff));
                    tag = fstTextPositions.Count - 1;

                    fstpos = stream.Position;

                    stream.Seek(strpos + nameoff, SeekOrigin.Begin);
                    //fstTextPositions.Add((UInt32)stream.Position + fstadd);
                    nname = ReadString(stream);

                    do
                    {
                        if (fstpos == dirSize[curDir] * 0x0C + 0x0C && curDir > 0)
                        {
                            dirSize[curDir] = 0;
                            curDir--;
                        }
                    } while (curDir != 0 && fstpos >= dirSize[curDir] * 0x0C + 0x0C);

                    if (flag == 0)
                    {
                        //current = rootArr[curDir].Nodes.Add(nname);
                        rootArr[curDir].addFile(nname, tag);
                        //image crap
                    }
                    else
                    {
                        curDir++;
                        current = rootArr[curDir - 1].addSubFolder(nname, tag);
                        //current = rootArr[curDir-1].Nodes.Add(nname);
                        //image crap
                        if (rootArr.Count > curDir)
                        {
                            rootArr[curDir] = current;
                            dirSize[curDir] = entries;
                        }
                        else
                        {
                            rootArr.Add(current);
                            dirSize.Add(entries);
                        }
                    }
                } while (fstpos < endpos);
                stream.Close();

                root.Sort();
                root.ToTreeView(treeView);
            }
            catch (EUSBGeckoException e)
            {
                exceptionHandling.HandleException(e);
            }
            catch
            {
            }
        }
Exemple #11
0
        public void Update(bool fast)
        {
            MemoryStream miniDump = new MemoryStream();
            int          oldColumnIndex, oldRowIndex;

            if (gView.SelectedCells.Count > 0)
            {
                oldColumnIndex = gView.SelectedCells[0].ColumnIndex;
                oldRowIndex    = gView.SelectedCells[0].RowIndex;
            }
            else
            {
                oldColumnIndex = 1;
                oldRowIndex    = 1;
            }

            uint sAddress = cAddress & 0xFFFFFFF0;
            uint offset   = cAddress - sAddress;

            try
            {
                gecko.Dump(sAddress, sAddress + 0x100, miniDump);

                if (gView.Rows.Count != 16)
                {
                    gView.Rows.Clear();
                    gView.Rows.Add(16);
                }

                miniDump.Seek(0, SeekOrigin.Begin);
                uint   value, bValue;
                byte[] buffer = new byte[4];
                uint   pValue = 0;
                for (int i = 0; i < 16; i++)
                {
                    gView.Rows[i].Cells[0].Value = GlobalFunctions.toHex(sAddress + i * 16);
                    for (int j = 1; j < 5; j++)
                    {
                        miniDump.Read(buffer, 0, 4);
                        bValue = BitConverter.ToUInt32(buffer, 0);
                        value  = ByteSwap.Swap(bValue);
                        if (sAddress + i * 0x10 + (j - 1) * 4 == selectedAddress)
                        {
                            pValue = value;
                        }
                        DataGridViewCell cell = gView.Rows[i].Cells[j];
                        if (viewMode == MemoryViewMode.Hex)
                        {
                            cell.Value = GlobalFunctions.toHex(value);
                        }
                        else if (viewMode == MemoryViewMode.ASCII)
                        {
                            cell.Value = DecodeASCII(buffer);
                        }
                        else if (viewMode == MemoryViewMode.ANSI)
                        {
                            cell.Value = DecodeANSI(buffer);
                        }
                        else if (viewMode == MemoryViewMode.Unicode)
                        {
                            cell.Value = DecodeUnicode(buffer);
                        }
                        else if (viewMode == MemoryViewMode.Single)
                        {
                            cell.Value = PrettyFloat(GlobalFunctions.UIntToSingle(value));
                        }
                        else if (viewMode == MemoryViewMode.AutoZero || viewMode == MemoryViewMode.AutoDot)
                        {
                            if (ValidMemory.validAddress(value))
                            {
                                cell.Value = GlobalFunctions.toHex(value);
                            }
                            else
                            {
                                float singleCast = GlobalFunctions.UIntToSingle(value);
                                if (!float.IsNaN(singleCast) && Math.Abs(singleCast) > 1e-7 && Math.Abs(singleCast) < 1e10)
                                {
                                    cell.Value = PrettyFloat(GlobalFunctions.UIntToSingle(value));
                                }
                                else
                                {
                                    if (IsASCII(buffer))
                                    {
                                        if (viewMode == MemoryViewMode.AutoZero && value == 0)
                                        {
                                            cell.Value = GlobalFunctions.toHex(value);
                                        }
                                        else
                                        {
                                            cell.Value = DecodeASCII(buffer);
                                        }
                                    }
                                    else
                                    {
                                        cell.Value = GlobalFunctions.toHex(value);
                                    }
                                }
                            }
                        }
                    }
                }
                oldRow = (int)offset / 0x10;
                oldCol = (int)(offset & 0xC) / 4 + 1;
                if (!fast)
                {
                    gView.Rows[oldRowIndex].Cells[oldColumnIndex].Selected = true;
                }

                pokeAddress.Text = GlobalFunctions.toHex(selectedAddress);
                fpValue.Text     = GlobalFunctions.UIntToSingle(pValue).ToString("G6");
            }
            catch (ETCPGeckoException e)
            {
                exceptionHandling.HandleException(e);
            }
        }
        public void SendPacketMail(PacketIn packet)
        {
            Player plr = GetPlayer();

            if (plr == null)
            {
                return;
            }

            if (_nextSend >= TCPManager.GetTimeStamp())
            {
                SendResult(MailResult.TEXT_MAIL_RESULT6);
                return;
            }

            // Recipient read
            packet.Skip(1);
            byte   nameSize = packet.GetUint8();
            string name     = packet.GetString(nameSize);



            // Subject (client is limited to send 30 chars but its probably a ushort anyway)
            ushort subjectSize = ByteSwap.Swap(packet.GetUint16());
            string subject     = packet.GetString(subjectSize);

            // Message
            ushort messageSize = ByteSwap.Swap(packet.GetUint16());
            string message     = packet.GetString(messageSize);

            // Money
            uint money = ByteSwap.Swap(packet.GetUint32());

            // COD?
            byte cr = packet.GetUint8();

            // Item
            byte itemsToSendCount = packet.GetUint8();

            var isBlackMarket = ((name.ToLower() == "black market") || (name.ToLower() == "blackmarket"));

            List <ushort> itemSlots = new List <ushort>();
            var           itemList  = new List <Item>();

            for (byte i = 0; i < itemsToSendCount; ++i)
            {
                ushort itemSlot = ByteSwap.Swap(packet.GetUint16());
                packet.Skip(2);

                Item item = plr.ItmInterface.GetItemInSlot(itemSlot);
                if (item == null || item.Info == null)
                {
                    SendResult(MailResult.TEXT_MAIL_RESULT16);
                    return;
                }

                // Allow black market items to be sent in mail
                if (!isBlackMarket)
                {
                    if (item.BoundtoPlayer || item.Info.Bind == 1)
                    {
                        SendResult(MailResult.TEXT_MAIL_RESULT9);
                        return;
                    }
                }

                itemSlots.Add(itemSlot);
                itemList.Add(item);
            }

            if (isBlackMarket)
            {
                _logger.Debug($"Sending mail to the BLACK MARKET. Number items {itemsToSendCount}");

                // Ensure that what is being sent is a warlord item
                if (itemsToSendCount == 0)
                {
                    SendResult(MailResult.TEXT_MAIL_RESULT9);
                    return;
                }

                var blackMarketManager = new BlackMarketManager();

                // Sending multiple items.
                foreach (var item in itemList)
                {
                    if (blackMarketManager.IsItemOnBlackMarket(item.Info.Entry))
                    {
                        _logger.Info($"Sending {item.Info.Name} ({item.Info.Entry}) to BlackMarket");
                        blackMarketManager.SendBlackMarketReward(plr, item.Info.Entry);
                        plr.SendClientMessage($"Trusting to your luck, you have sent {string.Join(",", itemList.Select(x => x.Info.Name))} to the Black Market, hoping for just recompense.");
                        _logger.Debug($"Email Sent.");
                        plr.ItmInterface.RemoveItems(item.Info.Entry, 1);
                        _logger.Info($"Removed {item.Info.Name} ({item.Info.Entry}) from {plr.Name}");
                        plr.SendClientMessage($"A suspicious looking package has arrived in your mail.", ChatLogFilters.CHATLOGFILTERS_LOOT);
                    }
                    else
                    {
                        _logger.Debug($"{MailResult.TEXT_MAIL_RESULT9}");
                        return;
                    }
                }

                SendResult(MailResult.TEXT_MAIL_RESULT4);
            }
            else
            {
                Character receiver = CharMgr.GetCharacter(Player.AsCharacterName(name), false);

                if (receiver == null || receiver.Realm != (byte)plr.Realm)
                {
                    SendResult(MailResult.TEXT_MAIL_RESULT7);
                    return;
                }
                if (receiver.Name == plr.Name) // You cannot mail yourself
                {
                    plr.SendLocalizeString("", ChatLogFilters.CHATLOGFILTERS_USER_ERROR, Localized_text.TEXT_PLAYER_CANT_MAIL_YOURSELF);
                    return;
                }
                if ((cr == 0 && !plr.HasMoney(money)) || !plr.RemoveMoney((cr == 0 ? money : 0) + MAIL_PRICE))
                {
                    SendResult(MailResult.TEXT_MAIL_RESULT8);
                    return;
                }

                SendMail(receiver, subject, message, money, cr == 1, itemSlots);

                _logger.Info($"Sending mail {subject} to {receiver.Name} from {plr.Name}. Money={money}, Item Count={itemSlots.Count}");
                foreach (var itemSlot in itemSlots)
                {
                    _logger.Info($"Item : {itemSlot}");
                }
            }
        }
Exemple #13
0
        public void DumpTree(params String[] folders)
        {
            UInt32 FSInit;
            UInt32 FSAddClient;
            UInt32 FSDelClient;
            UInt32 FSInitCmdBlock;
            UInt32 FSOpenDir;
            UInt32 FSCloseDir;
            UInt32 FSReadDir;
            UInt32 memalign;
            UInt32 free;

            switch (gecko.OsVersionRequest())
            {
            case 400:
            case 410:
                FSInit         = 0x01060d70;
                FSAddClient    = 0x01061290;
                FSDelClient    = 0x0106129c;
                FSInitCmdBlock = 0x01061498;
                FSOpenDir      = 0x01066f3c;
                FSCloseDir     = 0x01066fac;
                FSReadDir      = 0x0106702c;
                memalign       = gecko.peek(0x10049edc);
                free           = gecko.peek(0x100adc2c);
                break;

            case 500:
            case 510:
                FSInit         = 0x010666fc;
                FSAddClient    = 0x01066d80;
                FSDelClient    = 0x01066d8c;
                FSInitCmdBlock = 0x01066fec;
                FSOpenDir      = 0x0106db58;
                FSCloseDir     = 0x0106dbc8;
                FSReadDir      = 0x0106dc48;
                memalign       = gecko.peek(0x1004e2d0);
                free           = gecko.peek(0x100b41fc);
                break;

            case 532:
            case 540:
                FSInit         = 0x010683C8;
                FSAddClient    = 0x010689FC;
                FSDelClient    = 0x01068A08;
                FSInitCmdBlock = 0x01068C54;
                FSOpenDir      = 0x0106F690;
                FSCloseDir     = 0x0106F700;
                FSReadDir      = 0x0106F780;
                memalign       = gecko.peek(0x100b4878);
                free           = gecko.peek(0x100b487c);
                break;

            default:
                MessageBox.Show("Unsupported Wii U OS version.", "Version mismatch", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                UInt32 ret;
                ret = gecko.rpc(FSInit);

                UInt32 pClient = gecko.rpc(memalign, 0x1700, 0x20);
                if (pClient == 0)
                {
                    goto noClient;
                }
                UInt32 pCmd = gecko.rpc(memalign, 0xA80, 0x20);
                if (pCmd == 0)
                {
                    goto noCmd;
                }

                ret = gecko.rpc(FSAddClient, pClient, 0);
                ret = gecko.rpc(FSInitCmdBlock, pCmd);

                UInt32 pDh = gecko.rpc(memalign, 4, 4);
                if (pDh == 0)
                {
                    goto noDh;
                }
                UInt32 pPath = gecko.rpc(memalign, 0x200, 0x20);
                if (pPath == 0)
                {
                    goto noPath;
                }
                UInt32 pBuf = gecko.rpc(memalign, 0x200, 0x20);
                if (pBuf == 0)
                {
                    goto noBuf;
                }

                root = new fileStructure("vol", -1);
                Queue <fileStructure> scanQueue = new Queue <fileStructure>();
                foreach (String item in folders)
                {
                    scanQueue.Enqueue(root.addSubFolder(item, -1));
                }
                while (scanQueue.Count > 0)
                {
                    fileStructure current = scanQueue.Dequeue();
                    using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(current.Path + "\0")))
                    {
                        gecko.Upload(pPath, pPath + (uint)ms.Length, ms);
                    }


                    ret = gecko.rpc(FSOpenDir, pClient, pCmd, pPath, pDh, 0xffffffff);
                    if (ret != 0)
                    {
                        goto noDir;
                    }

                    UInt32 dh = gecko.peek(pDh);

                    do
                    {
                        ret = gecko.rpc(FSReadDir, pClient, pCmd, dh, pBuf, 0xffffffff);
                        if (ret != 0)
                        {
                            break;
                        }

                        using (MemoryStream ms = new MemoryStream())
                        {
                            gecko.Dump(pBuf, pBuf + 0x200, ms);

                            Byte[] data = ms.ToArray();
                            UInt32 attr = ByteSwap.Swap(BitConverter.ToUInt32(data, 0));
                            UInt32 size = ByteSwap.Swap(BitConverter.ToUInt32(data, 8));

                            String name = new String(Encoding.ASCII.GetChars(data, 0x64, 0x100));
                            name = name.Remove(name.IndexOf('\0'));

                            if ((attr & 0x80000000) != 0)
                            {
                                scanQueue.Enqueue(current.addSubFolder(name, -1));
                            }
                            else
                            {
                                current.addFile(name, -1, size);
                            }
                        }
                    } while (true);

                    gecko.rpc(FSCloseDir, pClient, pCmd, dh, 0);
noDir:
                    continue;
                }

                gecko.rpc(free, pBuf);
noBuf:
                gecko.rpc(free, pPath);
noPath:
                gecko.rpc(free, pDh);
noDh:

                ret = gecko.rpc(FSDelClient, pClient);

                gecko.rpc(free, pCmd);
noCmd:
                gecko.rpc(free, pClient);
noClient:

                if (root != null)
                {
                    root.Sort();
                    root.ToTreeView(treeView);
                }
            }
            catch (ETCPGeckoException e)
            {
                exceptionHandling.HandleException(e);
            }
            catch
            {
            }
        }
 private byte[] toStream(uint value)
 {
     return(BitConverter.GetBytes(ByteSwap.Swap(value)));
 }
 private Byte[] toStream(UInt32 value)
 {
     return(BitConverter.GetBytes(ByteSwap.Swap(value)));
 }
        public void SendPacketMail(PacketIn packet)
        {
            Player plr = GetPlayer();

            if (plr == null)
            {
                return;
            }

            if (_nextSend >= TCPManager.GetTimeStamp())
            {
                SendResult(MailResult.TEXT_MAIL_RESULT6);
                return;
            }

            // Recipient read
            packet.Skip(1);
            byte   nameSize = packet.GetUint8();
            string name     = packet.GetString(nameSize);

            Character receiver = CharMgr.GetCharacter(Player.AsCharacterName(name), false);

            if (receiver == null || receiver.Realm != (byte)plr.Realm)
            {
                SendResult(MailResult.TEXT_MAIL_RESULT7);
                return;
            }

            if (receiver.Name == plr.Name) // You cannot mail yourself
            {
                plr.SendLocalizeString("", ChatLogFilters.CHATLOGFILTERS_USER_ERROR, Localized_text.TEXT_PLAYER_CANT_MAIL_YOURSELF);
                return;
            }

            // Subject (client is limited to send 30 chars but its probably a ushort anyway)
            ushort subjectSize = ByteSwap.Swap(packet.GetUint16());
            string subject     = packet.GetString(subjectSize);

            // Message
            ushort messageSize = ByteSwap.Swap(packet.GetUint16());
            string message     = packet.GetString(messageSize);

            // Money
            uint money = ByteSwap.Swap(packet.GetUint32());

            // COD?
            byte cr = packet.GetUint8();

            // Item
            byte itemcounts = packet.GetUint8();

            Log.Debug("Mail", "Itemcount: " + itemcounts + "");

            List <ushort> itemSlots = new List <ushort>();

            for (byte i = 0; i < itemcounts; ++i)
            {
                ushort itmslot = ByteSwap.Swap(packet.GetUint16());
                packet.Skip(2);

                Item itm = plr.ItmInterface.GetItemInSlot(itmslot);
                if (itm == null || itm.Info == null)
                {
                    SendResult(MailResult.TEXT_MAIL_RESULT16);
                    return;
                }
                if (itm.BoundtoPlayer || itm.Info.Bind == 1)
                {
                    SendResult(MailResult.TEXT_MAIL_RESULT9);
                    return;
                }

                itemSlots.Add(itmslot);
            }

            if ((cr == 0 && !plr.HasMoney(money)) || !plr.RemoveMoney((cr == 0 ? money : 0) + MAIL_PRICE))
            {
                SendResult(MailResult.TEXT_MAIL_RESULT8);
                return;
            }

            SendMail(receiver, subject, message, money, cr == 1, itemSlots);
        }