Beispiel #1
0
        public byte[] ConvertToFile()
        {
            byte[] actual = new byte[] { };

            int fileStart = XfbinParser.GetFileSectionIndex(fileBytes) + 0x28;

            actual = Main.b_AddBytes(actual, fileBytes, 0, 0, fileStart + 0x10);
            actual = Main.b_AddBytes(actual, new byte[0xD8 * EntryCount]);

            for (int x = 0; x < EntryCount; x++)
            {
                int entryIndex = fileStart + 0x10 + (x * 0xD8);
                actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes(actual.Length - entryIndex), entryIndex);
                actual = Main.b_AddString(actual, CharacterList[x]);
                actual = Main.b_AddBytes(actual, new byte[0x8 - CharacterList[x].Length]);

                if (ChaList[x] != "")
                {
                    int entryChaIndex = entryIndex + 0x18;
                    actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes(actual.Length - entryChaIndex), entryChaIndex);
                    actual = Main.b_AddString(actual, ChaList[x]);
                    actual = Main.b_AddBytes(actual, new byte[0x10 - ChaList[x].Length]);
                }

                if (AccessoryList[x] != "")
                {
                    int entryAccIndex = entryIndex + 0x20;
                    actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes(actual.Length - entryAccIndex), entryAccIndex);
                    actual = Main.b_AddString(actual, AccessoryList[x]);
                    actual = Main.b_AddBytes(actual, new byte[0x10 - AccessoryList[x].Length]);
                }

                if (NewIdList[x] != "")
                {
                    int entryIdIndex = entryIndex + 0x28;
                    actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes(actual.Length - entryIdIndex), entryIdIndex);
                    actual = Main.b_AddString(actual, NewIdList[x]);
                    actual = Main.b_AddBytes(actual, new byte[0x8 - NewIdList[x].Length]);
                }

                actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes(PageList[x]), 0x140 + 0xD8 * x + 8);
                actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes(PositionList[x]), 0x140 + 0xD8 * x + 12);
                actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes(CostumeList[x]), 0x140 + 0xD8 * x + 16);

                // Add positions and all that crap
                actual = Main.b_ReplaceBytes(actual, GibberishBytes[x], 0x140 + 0xD8 * x + 48);
            }

            int totalSize = actual.Length - fileStart;

            // Add EOF
            actual = Main.b_AddBytes(actual, new byte[] { 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x79, 0x18, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 });

            // Fix sizes
            actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes((short)(EntryCount)), fileStart + 0x2C - 0x28);
            actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes(totalSize), fileStart + 0x24 - 0x28, 1);
            actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes(totalSize + 4), fileStart + 0x18 - 0x28, 1);

            return(actual);
        }
        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;
            }

            filePath = o.FileName;
            fileOpen = true;
            byte[] fileBytes = File.ReadAllBytes(filePath);

            fileStart = XfbinParser.GetFileSectionIndex(fileBytes);
            header    = Main.b_AddBytes(header, fileBytes, 0, fileStart, 0x38);
            fileStart = fileStart + 0x28;

            entryCount = Main.b_ReadInt(fileBytes, fileStart + 0x4);

            for (int x = 0; x < entryCount; x++)
            {
            }
        }
Beispiel #3
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;
        }
Beispiel #5
0
        public byte[] ConvertToFile()
        {
            byte[] actual      = new byte[0];
            int    startOfFile = XfbinParser.GetFileSectionIndex(fileBytes);

            for (int x = 0; x < startOfFile + 0x20; x++)
            {
                actual = Main.b_AddBytes(actual, new byte[] { fileBytes[x] });
            }

            actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes(CharacterCount), startOfFile + 0x20 - 0x4);
            actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes((CharacterCount * 8) + 0x4), startOfFile + 0x20 - 0x8, 1);
            actual = Main.b_ReplaceBytes(actual, BitConverter.GetBytes((CharacterCount * 8) + 0x8), startOfFile + 0x20 - 0x8 - 0xC, 1);

            for (int x = 0; x < CharacterCount; x++)
            {
                actual = Main.b_AddBytes(actual, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 });
                actual = Main.b_ReplaceString(actual, CharacterList[x], startOfFile + 0x20 + (0x8 * x));
            }

            byte[] finalBytes = new byte[20]
            {
                0,
                0,
                0,
                8,
                0,
                0,
                0,
                2,
                0,
                99,
                0,
                0,
                0,
                0,
                0,
                4,
                0,
                0,
                0,
                0
            };

            actual = Main.b_AddBytes(actual, finalBytes);
            return(actual);
        }
        void SaveFile(string oldname = "")
        {
            if (fileOpen == false)
            {
                return;
            }

            if (oldname == "")
            {
                oldname = fileName;
                // Do backup
                if (File.Exists(oldname + ".bak"))
                {
                    File.Delete(oldname + ".bak");
                }
                File.Copy(oldname, oldname + ".bak");
            }

            // Create new file
            List <byte> newFile = new List <byte>();

            // Copy old header
            int pathSectionIndex = XfbinParser.GetPathSectionIndex(fileBytes) + 1;

            for (int x = 0; x < pathSectionIndex; x++)
            {
                newFile.Add(fileBytes[x]);
            }

            byte[] actualFile = newFile.ToArray();
            int    totalSize  = actualFile.Length;

            // Create xfbin path and xfbin name strings
            string xfbinPathString = "Z:/param/player/converter/bin/" + prmName + "/" + prmName + "prm_load.bin";
            string xfbinNameString = prmName + "prm_load";

            // Add path section of xfbin
            int newPathSectionSize = xfbinPathString.Length + 1;

            actualFile = Main.b_AddString(actualFile, xfbinPathString);
            actualFile = Main.b_AddBytes(actualFile, new byte[] { 0 });

            totalSize = totalSize + newPathSectionSize;

            // Add name section of xfbin
            int newNameSectionSize = 1 + xfbinNameString.Length + 1 + "Page0".Length + 1 + "Index".Length + 1;

            actualFile = Main.b_AddBytes(actualFile, new byte[] { 0 });
            actualFile = Main.b_AddString(actualFile, xfbinNameString);
            actualFile = Main.b_AddBytes(actualFile, new byte[] { 0 });

            actualFile = Main.b_AddString(actualFile, "Page0");
            actualFile = Main.b_AddBytes(actualFile, new byte[] { 0 });

            actualFile = Main.b_AddString(actualFile, "index");
            actualFile = Main.b_AddBytes(actualFile, new byte[] { 0 });

            totalSize = totalSize + newNameSectionSize;

            // Add extra bytes to have a size divisible by 4
            while (totalSize % 4 != 0)
            {
                actualFile = Main.b_AddBytes(actualFile, new byte[] { 0 });
                totalSize++;
            }

            // Add binary 1 section of xfbin
            int newBin1SectionSize  = 0x30;
            int newBin1SectionIndex = totalSize;

            for (int x = 0; x < 0x30; x++)
            {
                actualFile = Main.b_AddBytes(actualFile, new byte[] { 0 });
            }
            actualFile[totalSize + 0xF]  = 0x1;
            actualFile[totalSize + 0x13] = 0x1;
            actualFile[totalSize + 0x17] = 0x1;
            actualFile[totalSize + 0x1B] = 0x2;
            actualFile[totalSize + 0x23] = 0x2;
            actualFile[totalSize + 0x27] = 0x3;
            actualFile[totalSize + 0x2F] = 0x3;
            totalSize = totalSize + newBin1SectionSize;

            // Add binary 2 section of xfbin
            int newBin2SectionSize  = 0x10;
            int newBin2SectionIndex = totalSize;

            actualFile = Main.b_AddBytes(actualFile, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03 });
            totalSize  = totalSize + newBin2SectionSize;

            // Add file header
            actualFile = Main.b_AddBytes(actualFile, new byte[] { 00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x00, 0x08, 0x78,
                                                                  0x00, 0x00, 0x00, 0x01, 0x00, 0x63, 0x00, 0x00, 0x00, 0x00, 0x08, 0x74 });
            totalSize = totalSize + 0x1C;

            int prmLoadIndex = totalSize;

            actualFile = Main.b_AddBytes(actualFile, new byte[] { (byte)pathList.Count });
            actualFile = Main.b_AddBytes(actualFile, new byte[] { 0x00, 0x00, 0x00 });

            for (int x = 0; x < pathList.Count; x++)
            {
                // Add path
                actualFile = Main.b_AddBytes(actualFile, new byte[] { 0x3F, 0x00, 0x00, 0x00 });
                actualFile = Main.b_AddString(actualFile, pathList[x]);
                for (int y = 0; y < 0x20 - pathList[x].Length; y++)
                {
                    actualFile = Main.b_AddBytes(actualFile, new byte[] { 0 });
                }

                // Add name
                actualFile = Main.b_AddString(actualFile, nameList[x]);
                for (int y = 0; y < 0x20 - nameList[x].Length; y++)
                {
                    actualFile = Main.b_AddBytes(actualFile, new byte[] { 0 });
                }

                // Add type and loading state
                actualFile = Main.b_AddBytes(actualFile, new byte[] { typeList[x] });
                actualFile = Main.b_AddBytes(actualFile, new byte[] { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF });
                actualFile = Main.b_AddBytes(actualFile, loadcondList[x]);

                // Add end of entry
                actualFile = Main.b_AddBytes(actualFile, new byte[] { 0x0, 0x0 });
            }

            // Add EOF
            actualFile = Main.b_AddBytes(actualFile, new byte[] { 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 });

            // Fix sizes
            actualFile = Main.b_ReplaceBytes(actualFile, BitConverter.GetBytes(newPathSectionSize + 1), 0x28, 1);
            actualFile = Main.b_ReplaceBytes(actualFile, BitConverter.GetBytes(newNameSectionSize), 0x30, 1);
            actualFile = Main.b_ReplaceBytes(actualFile, BitConverter.GetBytes(4 + (pathList.Count * 0x50)), prmLoadIndex - 0x4, 1);
            actualFile = Main.b_ReplaceBytes(actualFile, BitConverter.GetBytes(8 + (pathList.Count * 0x50)), prmLoadIndex - 0x4 - 0xC, 1);
            // Save file
            File.WriteAllBytes(fileName, actualFile);
            MessageBox.Show("File saved.");
        }