Exemplo n.º 1
0
        public void OpenFile(string path = "")
        {
            OpenFileDialog o = new OpenFileDialog();

            o.DefaultExt = "xfbin";

            if (path == "")
            {
                o.ShowDialog();
            }
            else
            {
                o.FileName = path;
            }

            if (!(o.FileName != "") || !File.Exists(o.FileName))
            {
                return;
            }

            ListBox1.Items.Clear();
            FilePath  = o.FileName;
            fileBytes = File.ReadAllBytes(FilePath);

            // Check for NUCC in header
            if (!(fileBytes.Length > 0x44 && Main.b_ReadString(fileBytes, 0, 4) == "NUCC"))
            {
                MessageBox.Show("Not a valid .xfbin file.");
                return;
            }

            if (XfbinParser.GetNameList(fileBytes)[0] == "characode")
            {
                int fileStart = XfbinParser.GetFileSectionIndex(fileBytes);
                CharacterCount = Main.b_ReadInt(fileBytes, fileStart + 0x1C);

                CharacterList = new List <string>();
                for (int x = 0; x < CharacterCount; x++)
                {
                    string character = Main.b_ReadString(fileBytes, fileStart + 0x20 + (x * 8));
                    CharacterList.Add(character);
                    ListBox1.Items.Add((x + 1).ToString("X2") + " = " + character);
                }

                FileOpen = true;
                if (this.Visible)
                {
                    MessageBox.Show("Characode contains " + CharacterCount + " character IDs.");
                }
            }
            else
            {
                MessageBox.Show("Please select a valid characode file.");
                FilePath  = "";
                fileBytes = new byte[0];
                FileOpen  = false;
            }
        }
        void OpenFile()
        {
            OpenFileDialog o = new OpenFileDialog();

            o.ShowDialog();

            if (o.FileName == "" || File.Exists(o.FileName) == false)
            {
                return;
            }
            fileName = o.FileName;

            fileBytes = File.ReadAllBytes(fileName);
            int fileSectionIndex = XfbinParser.GetFileSectionIndex(fileBytes);
            int startIndex       = fileSectionIndex + 0x1C;
            int fileIndex        = startIndex;

            // Check for NUCC in header
            if (!(fileBytes.Length > 0x44 && Main.b_ReadString(fileBytes, 0, 4) == "NUCC"))
            {
                MessageBox.Show("Not a valid .xfbin file.");
                return;
            }

            // Get character name
            prmName       = XfbinParser.GetNameList(fileBytes)[0];
            prmName       = prmName.Substring(0, prmName.Length - 0x8);
            textBox3.Text = prmName;

            // Get entry count
            entryCount = fileBytes[fileSectionIndex + 0x1C];

            for (int x = 0; x < entryCount; x++)
            {
                fileIndex = startIndex + (0x50 * x);

                int    strIndex = fileIndex + 0x8;
                string path     = Main.b_ReadString(fileBytes, strIndex);
                pathList.Add(path);

                strIndex = strIndex + 0x20;
                string name = Main.b_ReadString(fileBytes, strIndex);
                nameList.Add(name);

                listBox1.Items.Add(path + "/" + name);

                strIndex = strIndex + 0x20;
                typeList.Add(fileBytes[strIndex]);

                strIndex = strIndex + 0x8;
                loadcondList.Add(new byte[] { fileBytes[strIndex], fileBytes[strIndex + 1] });
            }

            fileOpen = true;
        }