Ejemplo n.º 1
0
        public static RichTextBox LoadMSDInTexEditorForm(RichTextBox texbox, MSDEntry msde)
        {
            texbox.Text = "";


            //Fills in the entries using a hopefully more efficient method based on what I see from Anotak and co's MSD Editor from a few years back.
            using (MemoryStream mstream = new MemoryStream(msde.UncompressedData))
            {
                using (BinaryReader bnr = new BinaryReader(mstream))
                {
                    bnr.BaseStream.Position = 8;
                    msde.EntryList          = new List <MessageEntries>();
                    StringBuilder SBuild = new StringBuilder();
                    msde.TextBackup = new List <string>(msde.EntryCount);
                    //Encoding ShouldBeShiftJIS = Encoding.GetEncoding(932);
                    //string Atr = "";
                    //string AtrB = "";
                    byte[] TestArray = new byte[2];
                    int    BPTest    = 0;
                    int    ITChar    = 0;

                    while (bnr.BaseStream.Position < bnr.BaseStream.Length)
                    {
                        MessageEntries me = new MessageEntries();
                        me.MSLength = bnr.ReadInt16();
                        SBuild.Clear();

                        for (int i = 0; i < me.MSLength; i++)
                        {
                            BPTest = Convert.ToInt32(bnr.BaseStream.Position);
                            ITChar = bnr.ReadInt16();
                            string TChar;
                            if (ITChar == -2)
                            {
                                TChar = "[line break]";
                            }
                            else
                            {
                                TChar = ITChar.ToString("X4");

                                try
                                {
                                    using (var sr = new StreamReader("MSDTable.cfg"))
                                    {
                                        while (!sr.EndOfStream)
                                        {
                                            var keyword = Console.ReadLine() ?? TChar;
                                            var line    = sr.ReadLine();
                                            if (String.IsNullOrEmpty(line))
                                            {
                                                continue;
                                            }
                                            if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                            {
                                                TChar = line;
                                                TChar = TChar.Split(' ')[1];
                                                break;
                                            }
                                        }
                                    }
                                }
                                catch (FileNotFoundException)
                                {
                                    MessageBox.Show("I cannot find archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                                    using (StreamWriter sw = File.AppendText("Log.txt"))
                                    {
                                        sw.WriteLine("Cannot find archive_filetypes.cfg so I cannot continue parsing the file.");
                                    }
                                }
                                if (TChar == "")
                                {
                                    TChar = " ";
                                }
                            }
                            SBuild.Append(TChar);
                        }
                        me.contents = SBuild.ToString();
                        msde.TextBackup.Add((me.contents));
                        texbox.Text = texbox.Text + me.contents + "\n";
                        short termchar = bnr.ReadInt16();
                        if (termchar != -1)
                        {
                        }

                        msde.EntryList.Add(me);
                    }
                }
            }

            return(texbox);
        }
Ejemplo n.º 2
0
        public static RichTextBox LoadMSDInTexEditorForm(RichTextBox texbox, MSDEntry msde)
        {
            texbox.Text = "";


            //Fills in the entries using a hopefully more efficient method based on what I see from Anotak and co's MSD Editor from a few years back.
            using (MemoryStream mstream = new MemoryStream(msde.UncompressedData))
            {
                using (BinaryReader bnr = new BinaryReader(mstream))
                {
                    bnr.BaseStream.Position = 8;
                    msde.EntryList          = new List <MessageEntries>();
                    StringBuilder SBuild = new StringBuilder();
                    msde.TextBackup = new List <string>(msde.EntryCount);
                    MessageEntries me        = new MessageEntries();
                    byte[]         TestArray = new byte[2];
                    int            ITChar    = 0;
                    string         TChar     = "";

                    while (bnr.BaseStream.Position < bnr.BaseStream.Length)
                    {
                        SBuild.Clear();
                        me.MSLength = bnr.ReadInt32();

                        for (int i = 0; i < me.MSLength; i++)
                        {
                            ITChar = bnr.ReadInt16();
                            TChar  = ITChar.ToString("X4");

                            try
                            {
                                using (var sr = new StreamReader("MSDTable.cfg"))
                                {
                                    while (!sr.EndOfStream)
                                    {
                                        var keyword = Console.ReadLine() ?? TChar;
                                        var line    = sr.ReadLine();
                                        if (String.IsNullOrEmpty(line))
                                        {
                                            continue;
                                        }
                                        if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                        {
                                            TChar = line;
                                            TChar = TChar.Split(' ')[1];
                                            break;
                                        }
                                    }
                                }
                            }
                            catch (FileNotFoundException)
                            {
                                MessageBox.Show("I cannot find MSDTable.cfg and cannot continue.\n Restart with this file in the same directory as the exe file itself.", "Oh Boy");
                                using (StreamWriter sw = File.AppendText("Log.txt"))
                                {
                                    sw.WriteLine("Cannot find MSDTable.cfg so I cannot load the MSD file.");
                                }
                                Process.GetCurrentProcess().Kill();
                            }

                            //For Irregular cases.
                            switch (TChar)
                            {
                            case "FFFFFF01":
                                TChar = "[*1DPAD*]";
                                break;

                            case "FFFFFF05":
                                TChar = "[*5LTRIG*]";
                                break;

                            case "FFFFFF06":
                                TChar = "[*6BUMPERL*]";
                                break;

                            case "FFFFFF09":
                                TChar = "[*9ABTN*]";
                                break;

                            case "FFFFFF0A":
                                TChar = "[*AYBTN*]";
                                break;

                            case "FFFFFF0B":
                                TChar = "[*BXBTN*]";
                                break;

                            case "FFFFFF0C":
                                TChar = "[*CBBTN*]";
                                break;

                            case "FFFFFF0D":
                                TChar = "[*DRTRIG*]";
                                break;

                            case "FFFFFF0E":
                                TChar = "[*ERBUMPER*]";
                                break;

                            case "FFFFFFFE":
                                TChar = "[*line break*]";
                                break;

                            case "FFFFFFFF":
                                TChar = "";
                                break;

                            case "":
                                TChar = " ";
                                break;

                            default:
                                break;
                            }

                            SBuild.Append(TChar);
                        }

                        me.contents = SBuild.ToString();
                        msde.TextBackup.Add((me.contents));
                        texbox.Text = texbox.Text + me.contents + "\n";

                        msde.EntryList.Add(me);
                    }
                }
            }

            return(texbox);
        }