static void ShowEngItemName() // search and show the name of an nmt using msbt parser. Note the padding chars { const string toLookFor = "05851"; string rootPath = PathHelper.GetItemDirectory(PathHelper.Languages["en"]); List <MSBT> loadedItemsEng = new List <MSBT>(TableProcessor.LoadAllMSBTs(rootPath)); List <string> foundItems = new List <string>(); foreach (MSBT loaded in loadedItemsEng) { for (int i = 0; i < loaded.LBL1.Labels.Count; ++i) { if (loaded.LBL1.Labels[i].ToString().Contains(toLookFor)) { foundItems.Add(loaded.LBL1.Labels[i].ToString() + ": " + loaded.FileEncoding.GetString(loaded.LBL1.Labels[i].Value).Replace("\n", "\r\n").TrimEnd('\0').Replace("\0", @"\0") + "\0"); } } } // print loaded items foreach (string itm in foundItems) { Console.WriteLine(toLookFor + " is " + itm); } }
public static string[] CreateItemList(string language, bool writeToFile = true) { string rootPath = PathHelper.GetItemDirectory(PathHelper.Languages[language]); List <MSBT> loadedItemsEng = new List <MSBT>(TableProcessor.LoadAllMSBTs(rootPath)); Dictionary <int, string> ID_ItemTable = new Dictionary <int, string>(getOutfits(language)); //preload with outfits // Add stuff not available ID_ItemTable.Add(0, string.Format("({0})", PathHelper.NoneNames[language])); // nothing ID_ItemTable.Add(5795, "DIY recipe\r\n"); // diy recipe int padAmount = PathHelper.LangPadAmount[language]; foreach (MSBT loaded in loadedItemsEng) { for (int i = 0; i < loaded.LBL1.Labels.Count; ++i) { string keyLabel = loaded.LBL1.Labels[i].ToString(); if (keyLabel.keyLabelShouldBeDiscarded()) { continue; } string[] keyVars = keyLabel.Split('_', StringSplitOptions.RemoveEmptyEntries); // item name string itemName = loaded.FileEncoding.GetString(loaded.LBL1.Labels[i].Value); itemName = itemName.processString(keyVars[0], language, padAmount); itemName += "\r\n"; // item index string itemIndex = keyVars[1]; int itemNumber = int.Parse(itemIndex); itemNumber += 1; // to match file line number ID_ItemTable.Add(itemNumber, itemName); } } // how big should we make our text file? int largestNumber = 0; foreach (var kvpItem in ID_ItemTable) { if (kvpItem.Key > largestNumber) { largestNumber = kvpItem.Key; } } // write to file using empties where there are no items // but first get everything we didn't find from the ItemParam table var table = TableProcessor.LoadTable(PathHelper.BCSVItemParamItem, (char)9, "0x54706054"); Dictionary <int, string> itemNameJapNameDic = new Dictionary <int, string>(); Dictionary <int, string> translationTypes = new Dictionary <int, string>(); foreach (DataRow row in table.Rows) { string itemId = row["0x54706054"].ToString(); int itemAsId = int.Parse(itemId) + 1; // get jap name string japName = row["0xB8CC232C"].ToString().Replace("\0", string.Empty); itemNameJapNameDic.Add(itemAsId, japName); //get type string type = row["0xFC275E86"].ToString().Replace("\0", string.Empty); translationTypes.Add(itemAsId, type); } int paramLargestNumber = itemNameJapNameDic.ElementAt(itemNameJapNameDic.Count - 1).Key; largestNumber = Math.Max(largestNumber, paramLargestNumber); // load the translation master string[] translationMaster = File.ReadAllLines(PathHelper.MasterTranslator); string[] lines = new string[largestNumber + 1]; List <string> translationsTemp = new List <string>(); List <string> translationsTempWithType = new List <string>(); List <string> translationsHexes = new List <string>(); // this can and should be cleaned up int translationRequests = 0; for (int i = 0; i < largestNumber + 1; ++i) { if (ID_ItemTable.ContainsKey(i)) { if (i < translationMaster.Length) { // the below if statement is incorrect (indexes are wrong) but I haven't had time to clean it up if (i != 0 && ID_ItemTable[i].JapanesePercentage() > 0.3f && translationMaster[i - 1] != string.Empty && (language != "jp" && language != "zht" && language != "zhs" && language != "ko")) { // this is probably japanese in the msbt string n = translationMaster[i - 1]; if (!n.EndsWith("(internal)", StringComparison.OrdinalIgnoreCase)) { n += " (internal)"; } lines[i] = n + "\r\n"; translationsTemp.Add(n + ", " + (i - 1).ToString("X").PadLeft(4, '0') + " \r\n"); translationsHexes.Add((i - 1).ToString("X") + "\r\n"); translationsTempWithType.Add(n.PadRight(60, ' ') + (char)2 + itemNameJapNameDic[i].PadRight(30, ' ') + (char)2 + translationTypes[i].PadRight(25, ' ') + (char)2 + (i - 1).ToString("X").PadLeft(4, '0') + (char)2 + (i - 1).ToString().PadLeft(5, '0') + " \r\n"); // char 2 is easier to split } else { lines[i] = ID_ItemTable[i]; } } else { lines[i] = ID_ItemTable[i]; } } else if (itemNameJapNameDic.ContainsKey(i)) { if (i < translationMaster.Length) { if (translationMaster[i - 1] != string.Empty && (language != "jp" && language != "zht" && language != "zhs" && language != "ko")) { string n = translationMaster[i - 1]; if (!n.EndsWith("(internal)", StringComparison.OrdinalIgnoreCase)) { n += " (internal)"; } lines[i] = n + "\r\n"; translationsTemp.Add(n + ", " + (i - 1).ToString("X").PadLeft(4, '0') + " \r\n"); translationsHexes.Add((i - 1).ToString("X") + "\r\n"); translationsTempWithType.Add(n.PadRight(60, ' ') + (char)2 + itemNameJapNameDic[i].PadRight(30, ' ') + (char)2 + translationTypes[i].PadRight(25, ' ') + (char)2 + (i - 1).ToString("X").PadLeft(4, '0') + (char)2 + (i - 1).ToString().PadLeft(5, '0') + " \r\n"); // char 2 is easier to split } else { lines[i] = itemNameJapNameDic[i] + "\r\n"; } } else { lines[i] = itemNameJapNameDic[i] + "\r\n"; } translationRequests++; } else { lines[i] = "\r\n"; } } Console.WriteLine("{0} translation requests: {1}", language, translationRequests); // sort by name then type translationsTempWithType = translationsTempWithType.OrderBy(x => x.Split((char)2)[0]).ToList(); translationsTempWithType = translationsTempWithType.OrderBy(x => x.Split((char)2)[2]).ToList(); for (int i = 0; i < translationsTempWithType.Count; ++i) { translationsTempWithType[i] = "| " + translationsTempWithType[i].Replace(((char)2).ToString(), " | ").Replace("\r\n", " |\r\n"); // github markdown } if (writeToFile) { WriteOutFile(PathHelper.OutputPath, language, itemListRootName + language + ".txt", string.Join("", lines)); } if (language == "en") { WriteOutFile(PathHelper.OutputPath, "strings", "InternalItemList.txt", string.Join("", translationsTemp)); WriteOutFile(PathHelper.OutputPath, "strings", "InternalHexList.txt", string.Join("", translationsHexes)); WriteOutFile(PathHelper.OutputPath, "strings", "InternalItemListSorted.txt", string.Join("", translationsTempWithType)); } if (language == "en") { itemLines = lines; } return(lines); }