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; } }
public void ReadStrings(String fileName) { file = Program.m_ROM.GetFileFromName(fileName); inf1size = file.Read32(0x24); ushort numentries = file.Read16(0x28); m_MsgData = new string[numentries]; m_StringLengths = new int[numentries]; m_ShortVersions = new string[numentries]; m_FileSize = file.Read32(0x08); m_StringHeaderAddr = new uint[numentries]; m_StringHeaderData = new uint[numentries]; m_DAT1Start = 0x20 + inf1size + 0x08; for (int i = 0; i < numentries; i++) { m_StringHeaderAddr[i] = (uint)(0x20 + 0x10 + (i * 8)); m_StringHeaderData[i] = file.Read32(m_StringHeaderAddr[i]); } lbxMsgList.Items.Clear(); //Reset list of messages lbxMsgList.BeginUpdate(); // Only draw when EndUpdate is called, much faster, expecially for Mono for (int i = 0; i < m_MsgData.Length; i++) { uint straddr = file.Read32((uint)(0x30 + i * 8)); straddr += 0x20 + inf1size + 0x8; int length = 0; string thetext = ""; for (; ;) { byte cur; try { cur = file.Read8(straddr); } catch { break; } straddr++; length++; char thechar = '\0'; /*if ((cur >= 0x00) && (cur <= 0x09)) * thechar = (char)('0' + cur); * else if ((cur >= 0x0A) && (cur <= 0x23)) * thechar = (char)('A' + cur - 0x0A); * else if ((cur >= 0x2D) && (cur <= 0x46)) * thechar = (char)('a' + cur - 0x2D); * else if ((cur >= 0x50) && (cur <= 0xCF))//Extended ASCII Characters * thechar = (char)(0x30 + cur);*/ // Some characters are two bytes long, can skip the second if (langNames[langIndex] == "jpn") { if (JAP_CHARS.GetFirstToSecond().ContainsKey(cur)) { thetext += JAP_CHARS.GetByFirst(cur); straddr += (JAP_SIZES[JAP_CHARS.GetByFirst(cur)] - 1); length += (int)(JAP_SIZES[JAP_CHARS.GetByFirst(cur)] - 1); } } else { 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); } 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 = file.Read8(straddr); thetext += "[\\r]"; thetext += String.Format("{0:X2}", cur); for (int spec = 0; spec < len - 1; spec++) { thetext += String.Format("{0:X2}", file.Read8((uint)(straddr + spec))); } length += (len - 1);// Already increased by 1 at start straddr += (uint)(len - 1); } } m_MsgData[i] = thetext; m_StringLengths[i] = length; m_ShortVersions[i] = ShortVersion(m_MsgData[i], i); lbxMsgList.Items.Add(m_ShortVersions[i]); btnImport.Enabled = true; btnExport.Enabled = true; } lbxMsgList.EndUpdate(); }