Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (!(obj is SwitchTitle))
            {
                return(false);
            }

            SwitchTitle other = obj as SwitchTitle;

            if (TitleID == null && other.TitleID == null)
            {
                return(true);
            }

            if (TitleID == null || other.TitleID == null)
            {
                return(false);
            }

            return(TitleID.Equals(other.TitleID));
        }
Ejemplo n.º 2
0
    public static bool IsOnGame(TitleID titleID, MPStringAddr mpStringAddr)
    {
        bool isOnGame = false;

        if (!IsConnected())
        {
            return(isOnGame);
        }

        isOnGame = GetCurrentTitleID() == (uint)titleID && ReadString((uint)mpStringAddr, 11) == "multiplayer";

        return(isOnGame);
    }
Ejemplo n.º 3
0
        public byte[] Serialize()
        {
            byte[]     newHeader = new byte[HeaderSize];
            SpanWriter sw        = new SpanWriter(newHeader, Endian.Big);

            sw.WriteBytes(HeaderMagic);
            sw.WriteUInt32(TOCEntryIndex);
            sw.WriteUInt32(CompressedTOCSize);
            sw.WriteUInt32(TOCSize);
            sw.WriteUInt64(Unk);
            sw.WriteUInt64(TotalVolumeSize);

            if (HasCustomGameID)
            {
                sw.WriteStringRaw(TitleID);
            }
            else
            {
                string newTitle = TitleID.Split('|')[0].TrimEnd() + $" | Last repacked with GTToolsSharp: {DateTimeOffset.UtcNow:G}";
                sw.WriteStringRaw(newTitle.Length < 128 ? newTitle : TitleID);
            }

            return(newHeader);
        }
Ejemplo n.º 4
0
        private byte[] GenXML()
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new XmlTextWriter(stream, Encoding.UTF8))
                {
                    writer.Formatting = Formatting.Indented;
                    writer.WriteStartDocument();
                    {
                        writer.WriteStartElement("ContentMeta");
                        {
                            writer.WriteStartElement("Type");
                            writer.WriteString(Type.ToString());
                            writer.WriteEndElement();

                            writer.WriteStartElement("Id");
                            writer.WriteString("0x" + TitleID.ToHexString());
                            writer.WriteEndElement();

                            writer.WriteStartElement("Version");
                            writer.WriteString(Version.ToString());
                            writer.WriteEndElement();

                            writer.WriteStartElement("RequiredDownloadSystemVersion");
                            writer.WriteString(DLSystemVersion.ToString());
                            writer.WriteEndElement();

                            var entries = Parse();
                            foreach (var entry in entries)
                            {
                                writer.WriteStartElement("Content");
                                {
                                    writer.WriteStartElement("Type");
                                    writer.WriteString(entry.Type.ToString());
                                    writer.WriteEndElement();

                                    writer.WriteStartElement("Id");
                                    writer.WriteString(entry.ID.ToHexString());
                                    writer.WriteEndElement();

                                    writer.WriteStartElement("Size");
                                    writer.WriteString(entry.Size.ToString());
                                    writer.WriteEndElement();

                                    writer.WriteStartElement("Hash");
                                    writer.WriteString(entry.Hash.ToHexString());
                                    writer.WriteEndElement();

                                    writer.WriteStartElement("KeyGeneration");
                                    writer.WriteString(MKeyRev.ToString());
                                    writer.WriteEndElement();
                                }
                                writer.WriteEndElement();
                            }

                            writer.WriteStartElement("Content");
                            {
                                writer.WriteStartElement("Type");
                                writer.WriteString(ncaTypes.Meta.ToString());
                                writer.WriteEndElement();

                                CnmtFileData = File.ReadAllBytes(Path);
                                var hash = SHA256.Create().ComputeHash(CnmtFileData);

                                CnmtFileName = hash.Take(16).ToArray().ToHexString() + ".cnmt.nca";
                                XmlFileName  = hash.Take(16).ToArray().ToHexString() + ".cnmt.xml";

                                writer.WriteStartElement("Id");
                                writer.WriteString(hash.Take(16).ToArray().ToHexString());
                                writer.WriteEndElement();

                                writer.WriteStartElement("Size");
                                writer.WriteString(CnmtFileData.Length.ToString());
                                writer.WriteEndElement();

                                writer.WriteStartElement("Hash");
                                writer.WriteString(hash.ToHexString());
                                writer.WriteEndElement();

                                writer.WriteStartElement("KeyGeneration");
                                writer.WriteString(MKeyRev.ToString());
                                writer.WriteEndElement();
                            }
                            writer.WriteEndElement();

                            writer.WriteStartElement("Digest");
                            writer.WriteString(Digest.ToHexString());
                            writer.WriteEndElement();

                            writer.WriteStartElement("KeyGenerationMin");
                            writer.WriteString(MKeyRev.ToString());
                            writer.WriteEndElement();

                            writer.WriteStartElement("RequiredSystemVersion");
                            writer.WriteString(SystemVersion.ToString());
                            writer.WriteEndElement();

                            writer.WriteStartElement("PatchId");
                            {
                                var id = TitleID[6] << 8 | TitleID[7];
                                id &= 0x1FFF;
                                var patchID = "0x" + TitleID.ToHexString().Substring(0, 13) +
                                              (id == 0x800 ? "000" : "800");

                                writer.WriteString(patchID);
                            }
                            writer.WriteEndElement();
                        }
                        writer.WriteEndElement();
                    }
                    writer.WriteEndDocument();
                }

                var output = Encoding.UTF8.GetString(stream.GetBuffer());
                var index  = output.IndexOf("\0", StringComparison.Ordinal);
                if (index > 0)
                {
                    output = output.Substring(0, index);
                }

                return(Encoding.UTF8.GetBytes(output).Skip(3).ToArray());
            }
        }
Ejemplo n.º 5
0
 private string GetPath()
 {
     //return string.Format(@"Controls\{0}.bin", TitleID.ToString("X16"));
     return(MainForm.TEMP_PATH + TitleID.ToString("X16") + ".bin");
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Log.Initialize("DWServer.log", LogLevel.Data | LogLevel.Info | LogLevel.Error | LogLevel.Debug | LogLevel.Verbose, true);
            Log.Info("Starting DW server");

            var game = (args.Length == 1) ? args[0] : "t5";

            if (game == "t5")
            {
                Game = TitleID.T5;
            }
            else if (game == "iw5")
            {
                Game = TitleID.IW5;
            }

            /*
             * TCPHandler ipServer = new TCPHandler(3074);
             * ipServer.Start();
             * TCPHandler ipServer3 = new TCPHandler(3077);
             * ipServer3.Start();
             */
            Database.Initialize();
            DWRouter.OnStart();
            //TCPHandler.OnStart();

            var handler = new TCPHandler();

            //default: 3074, deviain
            handler.Start((game == "t5") ? 3074 : 3078);

            Heatmap.StartThread();

            HttpHandler.Start();

            /*MessageData server2 = new MessageData("none");
             * server2.Arguments["name"] = "demonware2";
             * server2.Arguments["port"] = (int)3077;
             * TCPHandler.Net_TcpListen("none", server2);*/

            new Thread(() =>
            {
                while (true)
                {
                    Thread.Sleep(30000);

                    try
                    {
                        DWMatch.CleanSessions();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e.ToString());
                    }
                }
            }).Start();

            new Thread(() =>
            {
                while (true)
                {
                    Thread.Sleep(30000);//30000

                    try
                    {
                        DWGroups.updateCache();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e.ToString());
                    }
                }
            }).Start();

            while (true)
            {
                try
                {
                    Log.WriteAway();
                }
                catch (Exception e) { Log.Error(e.ToString()); }

                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 7
0
        public override void Awake()
        {
            //base.Awake();
            positions   = new List <Position>();
            departments = new List <Department>();
            titles      = new List <Title>();
            var notchoose = new Dropdown.OptionData("未选中");
            List <Dropdown.OptionData> list = new List <Dropdown.OptionData>();

            positions.AddRange(Kernel.Current.Sql.LoadEntitys <Position>());
            foreach (var item in positions)
            {
                list.Add(new Dropdown.OptionData(item.Name));
            }
            PositionID.ClearOptions();
            list.Add(notchoose);
            PositionID.AddOptions(list);
            //Debug.Log(PositionID.options.Count + " " + PositionID.value);
            PositionID.value = PositionID.options.Count - 1;


            list.Clear();
            departments.AddRange(Kernel.Current.Sql.LoadEntitys <Department>());
            foreach (var item in departments)
            {
                list.Add(new Dropdown.OptionData(item.Name));
            }
            DepartmentID.ClearOptions();
            list.Add(notchoose);
            DepartmentID.AddOptions(list);
            DepartmentID.value = DepartmentID.options.Count - 1;

            list.Clear();
            titles.AddRange(Kernel.Current.Sql.LoadEntitys <Title>());
            foreach (var item in titles)
            {
                list.Add(new Dropdown.OptionData(item.Name));
            }
            TitleID.ClearOptions();
            list.Add(notchoose);
            TitleID.AddOptions(list);
            TitleID.value = TitleID.options.Count - 1;

            query.onClick.AddListener(() =>
            {
                string sql    = null;
                bool oneWhere = true;
                if (NationText.input.text.IsNotEmpty())
                {
                    sql     += $"Nation like \'%{NationText.input.text}%\' ";
                    oneWhere = false;
                }
                if (BirthDay.transform.Find("PickButton").GetComponent <Button>().interactable)
                {
                    string and = null;
                    if (oneWhere == true)
                    {
                        oneWhere = false;
                    }
                    else
                    {
                        and = "and";
                    }
                    sql += $"{and} BirthDay=\'{(new SqlDateTime(BirthDay.DateTime)).ToSqlString()}\' ";
                }
                if (NameText.input.text.IsNotEmpty())
                {
                    string and = null;
                    if (oneWhere == true)
                    {
                        oneWhere = false;
                    }
                    else
                    {
                        and = "and";
                    }
                    sql += $"{and} Name=\'{NameText.input.text}\' ";
                }
                if (PoliticalOutlookText.input.text.IsNotEmpty())
                {
                    string and = null;
                    if (oneWhere == true)
                    {
                        oneWhere = false;
                    }
                    else
                    {
                        and = "and";
                    }
                    sql += $"{and} PoliticalOutlook like \'%{PoliticalOutlookText.input.text}%\' ";
                }
                if (EducationText.input.text.IsNotEmpty())
                {
                    string and = null;
                    if (oneWhere == true)
                    {
                        oneWhere = false;
                    }
                    else
                    {
                        and = "and";
                    }
                    sql += $"{and} Education=\'{EducationText.input.text}\' ";
                }
                if (AddressText.input.text.IsNotEmpty())
                {
                    string and = null;
                    if (oneWhere == true)
                    {
                        oneWhere = false;
                    }
                    else
                    {
                        and = "and";
                    }
                    sql += $"{and} Address like \'%{AddressText.input.text}%\' ";
                }
                if (infoText.input.text.IsNotEmpty())
                {
                    string and = null;
                    if (oneWhere == true)
                    {
                        oneWhere = false;
                    }
                    else
                    {
                        and = "and";
                    }
                    sql += $"{and} Info like \'%{infoText.input.text}%\' ";
                }
                if (PositionID.value != PositionID.options.Count - 1)
                {
                    string and = null;
                    if (oneWhere == true)
                    {
                        oneWhere = false;
                    }
                    else
                    {
                        and = "and";
                    }
                    sql += $"{and} PositionID={positions[PositionID.value].ID} ";
                }
                if (TitleID.value != TitleID.options.Count - 1)
                {
                    string and = null;
                    if (oneWhere == true)
                    {
                        oneWhere = false;
                    }
                    else
                    {
                        and = "and";
                    }
                    sql += $"{and} TitleID={titles[TitleID.value].ID} ";
                }
                if (DepartmentID.value != DepartmentID.options.Count - 1)
                {
                    string and = null;
                    if (oneWhere == true)
                    {
                        oneWhere = false;
                    }
                    else
                    {
                        and = "and";
                    }
                    sql += $"{and} DepartmentID={departments[DepartmentID.value].ID} ";
                }
                try
                {
                    Debug.Log(sql);
                    var result = Kernel.Current.Sql.QueryWhere <Personnel>(sql);

                    Kernel.Current.Desktop.OpenNew <SearchResultForm>().AddItems(new List <Personnel>(result));
                }
                catch (Exception e)
                {
                    Debug.Log(e.Message);
                    Kernel.Current.Desktop.OpenNew <DialogForm>().SetDialog(null, "错误!", "输入的数据全为空或格式有错误!");
                }
            });
            datetimeToggle.onValueChanged.AddListener(x =>
            {
                BirthDay.transform.Find("PickButton").GetComponent <Button>().interactable = x;
            });

            datetimeToggle.isOn = false;

            goBack.onClick.AddListener(() => Kernel.Current.Desktop.GoBack());
        }
Ejemplo n.º 8
0
        public void generate(string OutDir)
        {
            string hacpack = "--type nca";

            hacpack += " -k \"\"" + KeyFile + "\"\"";
            hacpack += " --tempdir \"\"" + Utils.TemporaryDirectory + "\\bin\\temp\"\"";
            hacpack += " -o \"\"" + OutDir + "\"\"";
            hacpack += " --keygeneration " + KeyGeneration.ToString();
            hacpack += " --titleid " + TitleID.ToString();
            switch (Type)
            {
            case NCAType.CNMT:
                hacpack += " --ncatype meta";
                switch (Options.TitleType)
                {
                case CNMTTitleType.AddOn:
                    hacpack += " --titletype addon";
                    break;

                case CNMTTitleType.Application:
                    hacpack += " --titletype application";
                    break;
                }
                hacpack += " --titleversion 0";
                if (!string.IsNullOrEmpty(Options.ProgramNCA))
                {
                    hacpack += " --programnca \"\"" + Options.ProgramNCA + "\"\"";
                }
                if (!string.IsNullOrEmpty(Options.ControlNCA))
                {
                    hacpack += " --controlnca \"\"" + Options.ControlNCA + "\"\"";
                }
                if (!string.IsNullOrEmpty(Options.LegalInformationNCA))
                {
                    hacpack += " --legalnca \"\"" + Options.LegalInformationNCA + "\"\"";
                }
                if (!string.IsNullOrEmpty(Options.OfflineHTMLNCA))
                {
                    hacpack += " --htmldocnca \"\"" + Options.OfflineHTMLNCA + "\"\"";
                }
                if (!string.IsNullOrEmpty(Options.DataNCA))
                {
                    hacpack += " --datanca \"\"" + Options.DataNCA + "\"\"";
                }
                break;

            case NCAType.Control:
                hacpack += " --ncatype control";
                hacpack += " --romfsdir \"\"" + RomFS + "\"\"";
                break;

            case NCAType.LegalInformation:
            case NCAType.OfflineHTML:
                hacpack += " --ncatype manual";
                hacpack += " --romfsdir \"\"" + RomFS + "\"\"";
                break;

            case NCAType.Data:
                hacpack += " --ncatype data";
                hacpack += " --romfsdir \"\"" + RomFS + "\"\"";
                break;

            case NCAType.PublicData:
                hacpack += " --ncatype publicdata";
                hacpack += " --romfsdir \"\"" + RomFS + "\"\"";
                break;

            case NCAType.Program:
                hacpack += " --ncatype program";
                hacpack += " --exefsdir \"\"" + ExeFS + "\"\"";
                if (!string.IsNullOrEmpty(RomFS))
                {
                    hacpack += " --romfsdir \"\"" + RomFS + "\"\"";
                }
                if (!string.IsNullOrEmpty(Logo))
                {
                    hacpack += " --logodir \"\"" + Logo + "\"\"";
                }
                break;
            }
            try
            {
                Utils.executeCommand(Utils.TemporaryDirectory + "\\bin\\hacpack.exe", hacpack, true);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Error processing hacPack command", "Brew.NET - NCA build error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
        }
Ejemplo n.º 9
0
 public override int GetHashCode()
 {
     return(TitleID?.GetHashCode() ?? 0);
 }
Ejemplo n.º 10
0
        public void generate(string Out)
        {
            if (Contents.Count <= 0)
            {
                return;
            }
            string outdir = Utils.TemporaryDirectory + "\\gen\\" + TitleID;

            if (Directory.Exists(outdir))
            {
                Directory.Delete(outdir, true);
            }
            Directory.CreateDirectory(outdir);
            List <NCAType> types  = new List <NCAType>();
            byte           keygen = Contents[0].KeyGeneration;

            foreach (NCA cnt in Contents)
            {
                if (cnt.TitleID != TitleID)
                {
                    continue;
                }
                types.Add(cnt.Type);
                cnt.generate(outdir + "\\" + cnt.Type.ToString());
            }
            NCA cnmt = new NCA(KeyFile);

            cnmt.TitleID           = TitleID;
            cnmt.KeyGeneration     = keygen;
            cnmt.Type              = NCAType.CNMT;
            cnmt.TitleID           = TitleID;
            cnmt.Options.TitleType = CNMTTitleType.Application;
            foreach (NCAType t in types)
            {
                string[] ncas = Directory.GetFiles(outdir + "\\" + t.ToString());
                if (ncas.Length <= 0)
                {
                    continue;
                }
                string curnca = ncas[0];
                switch (t)
                {
                case NCAType.Control:
                    cnmt.Options.ControlNCA = curnca;
                    break;

                case NCAType.Data:
                    cnmt.Options.DataNCA = curnca;
                    break;

                case NCAType.LegalInformation:
                    cnmt.Options.LegalInformationNCA = curnca;
                    break;

                case NCAType.OfflineHTML:
                    cnmt.Options.OfflineHTMLNCA = curnca;
                    break;

                case NCAType.Program:
                    cnmt.Options.ProgramNCA = curnca;
                    break;
                }
            }
            cnmt.generate(outdir);
            foreach (NCAType t in types)
            {
                string[] ncas = Directory.GetFiles(outdir + "\\" + t.ToString());
                if (ncas.Length <= 0)
                {
                    continue;
                }
                string curnca = ncas[0];
                File.Move(curnca, outdir + "\\" + Path.GetFileName(curnca));
            }
            string hacpack = "--type nsp";

            hacpack += " -k \"\"" + KeyFile + "\"\"";
            hacpack += " --tempdir \"\"" + Utils.TemporaryDirectory + "\\bin\\temp\"\"";
            hacpack += " -o \"\"" + outdir + "\"\"";
            hacpack += " --keygeneration " + keygen.ToString();
            hacpack += " --titleid " + TitleID.ToString();
            hacpack += " --ncadir \"\"" + outdir + "\"\"";
            Console.WriteLine(hacpack);
            try
            {
                Utils.executeCommand(Utils.TemporaryDirectory + "\\bin\\hacpack.exe", hacpack, true);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Error processing hacPack command", "Brew.NET - NSP build error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                Directory.Delete(outdir, true);
                return;
            }
            File.Move(outdir + "\\" + TitleID + ".nsp", Out);
            // Directory.Delete(outdir, true);
        }
Ejemplo n.º 11
0
        private void UserInfo()
        {
            string Name;
            string Surname;
            string PhoneNumber;
            string EmailAddress;
            string UserName;
            string UserPassword;
            int    PrivilegeID;
            int    GenderID;
            int    TitleID;
            string GenderDescription;
            int    UserTypeID;
            string PrivilegeDescription;
            string UserTypeDescription;
            string TitleDescription;


            SqlConnection sqlcon = new SqlConnection(Globals.ConnectionString);

            sqlcon.Open();
            string        cmd    = "SELECT * FROM Users Where UserID ='" + Globals.SelectedUserID.ToString() + "'";
            SqlCommand    sqlcom = new SqlCommand(cmd, sqlcon);
            SqlDataReader dr     = sqlcom.ExecuteReader();

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    //    try
                    //    {
                    Name         = (dr["Name"].ToString());
                    Surname      = (dr["Surname"].ToString());
                    PhoneNumber  = (dr["PhoneNumber"].ToString());
                    UserName     = (dr["UserName"].ToString());
                    UserPassword = (dr["UserPassword"].ToString());
                    PrivilegeID  = Convert.ToInt32((dr["PrivilegeID"]));
                    GenderID     = Convert.ToInt32((dr["GenderID"]));
                    TitleID      = Convert.ToInt32((dr["TitleID"]));
                    UserTypeID   = Convert.ToInt32((dr["UserTypeID"]));
                    EmailAddress = (dr["EmailAddress"].ToString());

                    txtName.Text         = Name;
                    txtSurname.Text      = Surname;
                    txtPhoneNumber.Text  = PhoneNumber;
                    txtUsername.Text     = UserName;
                    txtPassword.Text     = UserPassword;
                    txtEmailAddress.Text = EmailAddress;

                    //Get Gender
                    SqlConnection sqlcon2 = new SqlConnection(Globals.ConnectionString);
                    sqlcon2.Open();
                    string        cmd2    = "SELECT GenderDescription FROM Gender WHERE GenderID ='" + GenderID.ToString() + "'";
                    SqlCommand    sqlcom2 = new SqlCommand(cmd2, sqlcon2);
                    SqlDataReader dr2;
                    dr2 = sqlcom2.ExecuteReader();
                    if (dr2.HasRows)
                    {
                        while (dr2.Read())
                        {
                            GenderDescription = (dr2["GenderDescription"].ToString());
                            cbxGender.Text    = GenderDescription;
                        }
                    }
                    dr2.Close();
                    sqlcon2.Close();

                    //Get Title
                    SqlConnection sqlcon3 = new SqlConnection(Globals.ConnectionString);
                    sqlcon3.Open();
                    string        cmd3    = "SELECT TitleDescription FROM Title WHERE TitleID ='" + TitleID.ToString() + "'";
                    SqlCommand    sqlcom3 = new SqlCommand(cmd3, sqlcon3);
                    SqlDataReader dr3;
                    dr3 = sqlcom3.ExecuteReader();
                    if (dr3.HasRows)
                    {
                        while (dr3.Read())
                        {
                            TitleDescription = (dr3["TitleDescription"].ToString());
                            cbxTitle.Text    = TitleDescription;
                        }
                    }
                    dr3.Close();
                    sqlcon3.Close();

                    //Get Privilege
                    SqlConnection sqlcon4 = new SqlConnection(Globals.ConnectionString);
                    sqlcon4.Open();
                    string        cmd4    = "SELECT PrivilegeDescription FROM Privilege WHERE PrivilegeID ='" + PrivilegeID.ToString() + "'";
                    SqlCommand    sqlcom4 = new SqlCommand(cmd4, sqlcon4);
                    SqlDataReader dr4;
                    dr4 = sqlcom4.ExecuteReader();
                    if (dr4.HasRows)
                    {
                        while (dr4.Read())
                        {
                            PrivilegeDescription  = (dr4["PrivilegeDescription"].ToString());
                            cbxPrivilegeType.Text = PrivilegeDescription;
                        }
                    }
                    dr4.Close();
                    sqlcon4.Close();

                    //Get UserType
                    SqlConnection sqlcon5 = new SqlConnection(Globals.ConnectionString);
                    sqlcon5.Open();
                    string        cmd5    = "SELECT UserDescription FROM UserType WHERE UserTypeID ='" + UserTypeID.ToString() + "'";
                    SqlCommand    sqlcom5 = new SqlCommand(cmd5, sqlcon5);
                    SqlDataReader dr5;
                    dr5 = sqlcom5.ExecuteReader();
                    if (dr5.HasRows)
                    {
                        while (dr5.Read())
                        {
                            UserTypeDescription = (dr5["UserDescription"].ToString());
                            cbxUserType.Text    = UserTypeDescription;
                        }
                    }
                    dr5.Close();
                    sqlcon5.Close();
                    //     }
                    //    catch
                    //    {


                    //   }
                }
            }
            dr.Close();
            sqlcon.Close();
        }