Esempio n. 1
0
        public Title(byte[] bytes)
        {
            TitlePacket title = DataHandler.ByteArrayToStructure <TitlePacket>(bytes);

            Magic = title.magic;

            if (title.programId == 0)
            {
                ProgramId = 0x0100000000001000;
                Name      = "Home Menu";
            }
            else
            {
                ProgramId = title.programId;
                Name      = Encoding.UTF8.GetString(title.name, 0, title.name.Length).Split('\0')[0];
            }
            if (title.programId == 0xffaadd23)
            {
                if (Utils.QuestOverrides.ContainsKey(Name) && Utils.QuestOverrides[Name].CustomName != null)
                {
                    Name = Utils.QuestOverrides[Name].CustomName;
                }
            }
            else
            {
                if (Utils.SwitchOverrides.ContainsKey($"0{ProgramId:x}") && Utils.SwitchOverrides[$"0{ProgramId:x}"].CustomName != null)
                {
                    Name = Utils.SwitchOverrides[$"0{ProgramId:x}"].CustomName;
                }
            }
        }
        public Title(byte[] bytes)
        {
            TitlePacket title = DataHandler.ByteArrayToStructure <TitlePacket>(bytes);

            Magic     = title.magic;
            ProgramId = title.programId;
            Name      = Encoding.UTF8.GetString(title.name, 0, title.name.Length).Split('\0')[0];
        }
Esempio n. 3
0
        public Title(byte[] bytes)
        {
            TitlePacket title = DataHandler.ByteArrayToStructure <TitlePacket>(bytes);

            Magic     = title.magic;
            Index     = title.index;
            TitleID   = Encoding.UTF8.GetString(title.titleid, 0, title.titleid.Length).Split('\0')[0];
            TitleName = Encoding.UTF8.GetString(title.title, 0, title.title.Length).Split('\0')[0];
        }
Esempio n. 4
0
        private void DataListen()
        {
            string     LastGame = "";
            Timestamps time     = null;

            while (true)
            {
                try
                {
                    byte[]      bytes = new byte[800];
                    int         cnt   = client.Receive(bytes);
                    TitlePacket title = Utils.ByteArrayToStructure <TitlePacket>(bytes);
                    if (rpc.CurrentPresence == null || LastGame != title.name)
                    {
                        time = Timestamps.Now;
                    }
                    if (title.magic == 0xffaadd23 && (rpc.CurrentPresence == null || LastGame != title.name) || ManualUpdate)
                    {
                        if (title.name == "NULL")
                        {
                            Assets ass = new Assets()
                            {
                                LargeImageText = "Home Menu",
                                SmallImageKey  = smallKeyBox.Text,
                                SmallImageText = "Switch-Presence Rewritten"
                            };

                            if (!string.IsNullOrWhiteSpace(bigTextBox.Text))
                            {
                                ass.LargeImageText = bigTextBox.Text;
                            }
                            else
                            {
                                ass.LargeImageText = "Home Menu";
                            }

                            if (!string.IsNullOrWhiteSpace(bigKeyBox.Text))
                            {
                                ass.LargeImageKey = bigKeyBox.Text;
                            }
                            else
                            {
                                ass.LargeImageKey = string.Format("0{0:x}", 0x0100000000001000);
                            }

                            RichPresence presence = new RichPresence()
                            {
                                Details = "In the home menu",
                                State   = stateBox.Text,
                                Assets  = ass
                            };

                            if (checkTime.Checked)
                            {
                                presence.Timestamps = time;
                            }
                            rpc.SetPresence(presence);
                            ManualUpdate = false;
                        }
                        else
                        {
                            Assets ass = new Assets()
                            {
                                SmallImageKey  = smallKeyBox.Text,
                                SmallImageText = "Switch-Presence Rewritten"
                            };

                            if (!string.IsNullOrWhiteSpace(bigTextBox.Text))
                            {
                                ass.LargeImageText = bigTextBox.Text;
                            }
                            else
                            {
                                ass.LargeImageText = title.name;
                            }

                            if (!string.IsNullOrWhiteSpace(bigKeyBox.Text))
                            {
                                ass.LargeImageKey = bigKeyBox.Text;
                            }
                            else
                            {
                                ass.LargeImageKey = string.Format("0{0:x}", title.tid);
                            }

                            RichPresence presence = new RichPresence()
                            {
                                Details = $"Playing {title.name}",
                                State   = stateBox.Text,
                                Assets  = ass
                            };

                            if (checkTime.Checked)
                            {
                                presence.Timestamps = time;
                            }
                            rpc.SetPresence(presence);
                            ManualUpdate = false;
                        }
                        LastGame = title.name;
                    }
                }
                catch (SocketException)
                {
                    client.Close();
                    rpc.Dispose();
                    t = new Thread(DataListen);
                    MessageBox.Show("A socket error occured please try again.", "Socket", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MethodInvoker inv = () =>
                    {
                        button1.Text      = "Connect";
                        ipBox.Enabled     = true;
                        clientBox.Enabled = true;
                    };
                    Invoke(inv);
                    return;
                }
            }
        }
Esempio n. 5
0
        private void DataListen()
        {
            while (true)
            {
                try
                {
                    byte[] bytes = new byte[800];
                    int    cnt   = client.Receive(bytes);
                    UpdateStatus("Connected to the server!", Color.Green);
                    trayIcon.Icon = Resources.Connected;
                    trayIcon.Text = "SwitchPresence (Connected)";
                    EnableMacButton(true);
                    TitlePacket title = Utils.ByteArrayToStructure <TitlePacket>(bytes);
                    if (title.magic == 0xffaadd23)
                    {
                        if (LastGame != title.name)
                        {
                            time = Timestamps.Now;
                        }
                        if ((rpc != null && rpc.CurrentPresence == null) || LastGame != title.name || ManualUpdate)
                        {
                            Assets ass = new Assets
                            {
                                SmallImageKey  = smallKeyBox.Text,
                                SmallImageText = "Switch-Presence Rewritten"
                            };
                            RichPresence presence = new RichPresence
                            {
                                State = stateBox.Text
                            };

                            if (title.name == "NULL")
                            {
                                ass.LargeImageText = "Home Menu";
                                ass.LargeImageText = !string.IsNullOrWhiteSpace(bigTextBox.Text) ? bigTextBox.Text : "Home Menu";
                                ass.LargeImageKey  = !string.IsNullOrWhiteSpace(bigKeyBox.Text) ? bigKeyBox.Text : string.Format("0{0:x}", 0x0100000000001000);
                                presence.Details   = "In the home menu";
                            }
                            else
                            {
                                ass.LargeImageText = !string.IsNullOrWhiteSpace(bigTextBox.Text) ? bigTextBox.Text : title.name;
                                ass.LargeImageKey  = !string.IsNullOrWhiteSpace(bigKeyBox.Text) ? bigKeyBox.Text : string.Format("0{0:x}", title.tid);
                                presence.Details   = $"Playing {title.name}";
                            }

                            presence.Assets = ass;
                            if (checkTime.Checked)
                            {
                                presence.Timestamps = time;
                            }
                            rpc.SetPresence(presence);

                            ManualUpdate = false;
                            LastGame     = title.name;
                        }
                    }
                    else
                    {
                        if (rpc != null && !rpc.IsDisposed)
                        {
                            rpc.ClearPresence();
                        }
                        client.Close();
                        return;
                    }
                }
                catch (SocketException)
                {
                    if (rpc != null && !rpc.IsDisposed)
                    {
                        rpc.ClearPresence();
                    }
                    client.Close();
                    return;
                }
            }
        }