示例#1
0
        public static void LoadCharList(string txtName, BiDictionaryOneToOne <byte, string> charList,
                                        Dictionary <string, uint> sizeList)
        {
            string filename = Path.Combine(Application.StartupPath, txtName);
            string text     = File.ReadAllText(filename);

            string[] lines = text.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < lines.Length; i++)
            {
                // Ignore comments
                if (lines[i].ToCharArray()[0] == '#')
                {
                    continue;
                }

                string[] pair = lines[i].Split('=');
                if (pair.Length < 3)
                {
                    continue;
                }

                try {
                    charList.Add(byte.Parse(pair[0]), pair[2]);
                    sizeList.Add(pair[2], uint.Parse(pair[1]));
                }
                catch (Exception e) { MessageBox.Show("Error in " + filename + "\n\n" + "Line " + i + "\n\n" +
                                                      pair[0] + "\t" + pair[1] + "\t" + pair[2] + "\n\n" + e.Message); }
            }
        }
示例#2
0
        /* Reads in the list of known Global Collision Type values
         */
        private void loadGlobalCLPSTypes()
        {
            GLOBAL_CLPS_TYPES = new BiDictionaryOneToOne <string, byte[]>(new ByteArrayComparer());
            string entryName = "";

            byte[] entryValue = new byte[8];
            int    valueCount = 0;

            // Create an XML reader for this file.
            using (XmlReader reader = XmlReader.Create(Path.Combine(Application.StartupPath, "CLPS_Types.xml")))
            {
                reader.MoveToContent();

                while (reader.Read())
                {
                    if (reader.NodeType.Equals(XmlNodeType.Element))
                    {
                        switch (reader.LocalName)
                        {
                        case "Entry":
                            entryName = reader.GetAttribute("name");
                            break;

                        case "Value":
                            entryValue = new byte[8];
                            valueCount = 0;
                            break;

                        case "Byte":
                            entryValue[valueCount] = Byte.Parse(reader.ReadElementContentAsString());
                            valueCount++;
                            break;
                        }
                    }
                    else if (reader.NodeType.Equals(XmlNodeType.EndElement))
                    {
                        switch (reader.LocalName)
                        {
                        case "Entry":
                            GLOBAL_CLPS_TYPES.Add(entryName, entryValue);
                            break;
                        }
                    }
                }
            }
        }
        public void UpdateStrings()
        {
            NitroFile msgFile;

            try
            {
                msgFile = GetFileFromName("data/message/msg_data_nes.bin");
                Console.WriteLine(" !Any Other!");
            }
            catch (Exception)
            {
                try
                {
                    msgFile = GetFileFromName("data/message/msg_data_eng.bin");
                    Console.WriteLine(" !European!");
                }
                catch (Exception)
                {
                    Console.WriteLine(" !Not Supported!");
                    return;
                }
            }
            BiDictionaryOneToOne <byte, string> BASIC_EUR_US_CHARS = new BiDictionaryOneToOne <byte, string>();
            Dictionary <string, uint>           BASIC_EUR_US_SIZES = new Dictionary <string, uint>();

            TextEditorForm.LoadCharList("basic_eur_us_chars.txt", BASIC_EUR_US_CHARS, BASIC_EUR_US_SIZES);

            // Most of this is copied from TextEditorForm.ReadStrings()!

            uint   inf1size   = msgFile.Read32(0x24);
            ushort numentries = msgFile.Read16(0x28);

            m_MsgData = new string[numentries];

            for (int i = 0; i < m_MsgData.Length; i++)
            {
                uint straddr = msgFile.Read32((uint)(0x30 + i * 8));
                straddr += 0x20 + inf1size + 0x8;

                int length = 0;

                string thetext = "";
                for (; ;)
                {
                    byte cur;
                    try
                    {
                        cur = msgFile.Read8(straddr);
                    }
                    catch
                    {
                        break;
                    }
                    straddr++;
                    length++;
                    char thechar = '\0';

                    if ((cur >= 0x00 && cur <= 0x4F) || (cur >= 0xEE && cur <= 0xFB))
                    {
                        thetext += BASIC_EUR_US_CHARS.GetByFirst(cur);
                        straddr += (BASIC_EUR_US_SIZES[BASIC_EUR_US_CHARS.GetByFirst(cur)] - 1);
                        //length += (int)(BASIC_EUR_US_SIZES[BASIC_EUR_US_CHARS.GetByFirst(cur)] - 1);
                    }
                    //I don't care about these for now

                    /*
                     * else if (cur >= 0x50 && cur <= 0xCF)
                     * {
                     *  thetext += EXTENDED_ASCII_CHARS.GetByFirst(cur);
                     *  straddr += (EXTENDED_ASCII_SIZES[EXTENDED_ASCII_CHARS.GetByFirst(cur)] - 1);
                     *  length += (int)(EXTENDED_ASCII_SIZES[EXTENDED_ASCII_CHARS.GetByFirst(cur)] - 1);
                     * }
                     */

                    if (thechar != '\0')
                    {
                        thetext += thechar;
                    }
                    else if (cur == 0xFD)
                    {
                        thetext += "\r\n";
                    }
                    else if (cur == 0xFF)
                    {
                        break;
                    }
                    else if (cur == 0xFE)// Special Character
                    {
                        int len = msgFile.Read8(straddr);
                        thetext += "[\\r]";
                        thetext += String.Format("{0:X2}", cur);
                        for (int spec = 0; spec < len - 1; spec++)
                        {
                            thetext += String.Format("{0:X2}", msgFile.Read8((uint)(straddr + spec)));
                        }
                        //length += (len - 1);// Already increased by 1 at start
                        straddr += (uint)(len - 1);
                    }
                }

                m_MsgData[i] = thetext;
            }
        }