public static void Initialize() { mFilesystem = new RARCFilesystem(Program.sGame.mFilesystem.OpenFile("/LocalizeData/UsEnglish/MessageData/SystemMessage.arc")); mGalaxyNames = new MSBT(mFilesystem.OpenFile("/boop/GalaxyName.msbt")); mScenarioNames = new MSBT(mFilesystem.OpenFile("/boop/ScenarioName.msbt")); }
// int array is 0: item ushort 1: accessory table val private static Dictionary <int[], string> getOutfitColors(string language) { string rootPath = PathHelper.GetOutfitColorDirectory(PathHelper.Languages[language]); Dictionary <string, MSBT> loadedItems = TableProcessor.LoadAllMSBTs_GiveNames(rootPath); Dictionary <int[], string> toRet = new Dictionary <int[], string>(); foreach (var loadPair in loadedItems) { MSBT loaded = loadPair.Value; 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); string ItemName = loaded.FileEncoding.GetString(loaded.LBL1.Labels[i].Value); if (keyVars.Length != 3) { throw new Exception("This isn't an OutfitColorGroup " + loadPair.Key); } toRet.Add(new int[2] { int.Parse(keyVars[2]), int.Parse(keyVars[0]) }, ItemName); } } return(toRet); }
public override T ReadFile <T>(string inputFile) { if (!typeof(T).IsAssignableFrom(typeof(MsbtDatabase))) { throw new Exception($"Tried to use MsbtResourceProvider with wrong mapping type '{nameof(MsbtDatabase)}'"); } try { _logger.LogDebug("Reading msbt file {InputFile}", inputFile); var output = new MsbtDatabase() { Entries = new Dictionary <string, string>() }; var msbtFile = new MSBT(inputFile); foreach (var msbtEntry in msbtFile.LBL1.Labels) { var value = msbtFile.TXT2.OriginalStrings.FirstOrDefault(p => p.Index == msbtEntry.Index); output.Entries.Add(((Label)msbtEntry).Name, Encoding.Unicode.GetString(value.Value).TrimEnd('\0')); } return((T)(object)output); } catch (Exception e) { _logger.LogError(e, "Error while reading prc file {InputFile}", inputFile); return(default);
protected Dictionary <Language, Dictionary <string, string> > ReadMsbts(BinaryDataReader reader) { Dictionary <Language, Dictionary <string, string> > msbts = new Dictionary <Language, Dictionary <string, string> >(); // Read the MSBTs foreach (Language language in Container.LanguageOrder) { // Read the MSBT MSBT msbt = new MSBT(this.ReadDataEntry(reader)); // Create a Dictionary for this MSBT Dictionary <string, string> textMapping = new Dictionary <string, string>(); // Loop over every string for (int i = 0; i < msbt.TXT2.NumberOfStrings; i++) { // Get the IEntry IEntry entry = msbt.HasLabels ? msbt.LBL1.Labels[i] : msbt.TXT2.Strings[i]; // Parse the value and trim the zero-byte string str = msbt.FileEncoding.GetString(entry.Value).Trim('\0'); // Add this label and text to the mapping textMapping.Add(entry.ToString(), str); } // Add this mapping to the Dictionary msbts.Add(language, textMapping); } return(msbts); }
private void zoneNamesComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (zoneNamesComboBox.SelectedIndex != -1) { labelsComboBox.Items.Clear(); string name = (string)zoneNamesComboBox.SelectedItem; mSelectedZone = name; mCurMessages = mGalaxy.GetZone(name).GetMessages(); Dictionary <string, List <MessageBase> > dur = mCurMessages.GetMessages(); foreach (string str in dur.Keys) { labelsComboBox.Items.Add(str); } flowNamesList.Items.Clear(); if (mGalaxy.GetZone(name).HasFlows()) { ((Control)tabPage2).Enabled = true; mCurFlow = mGalaxy.GetZone(name).GetFlows(); mCurFlow.GetFlowNames().ForEach(l => flowNamesList.Items.Add(l)); } else { ((Control)tabPage2).Enabled = false; } } }
static void RepackMSBT(string path, string output) { System.IO.FileInfo file = new System.IO.FileInfo(output); file.Directory.Create(); // If the directory already exists, this method does nothing. MSBT _msbt = new MSBT(); string jsonText = System.IO.File.ReadAllText(path); MainJSON json = JsonConvert.DeserializeObject <MainJSON>(jsonText, new Newtonsoft.Json.JsonSerializerSettings { TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, }); _msbt.Header = json.header; _msbt.SectionOrder = json.SectionOrder; _msbt.TXT2.NumberOfStrings = json.TXT2.NumberOfStrings; _msbt.TXT2.Identifier = json.TXT2.Identifier; _msbt.TXT2.Padding1 = json.TXT2.Padding1; _msbt.LBL1.NumberOfGroups = json.LBL1.NumberOfGroups; _msbt.LBL1.Padding1 = json.LBL1.Padding1; _msbt.LBL1.Identifier = json.LBL1.Identifier; _msbt.ATO1 = json.ATO1; _msbt.ATR1 = json.ATR1; _msbt.NLI1 = json.NLI1; _msbt.TSY1 = json.TSY1; _msbt.LBL1.Groups.Clear(); for (int i = 0; i < json.LBL1.NumberOfGroups; i++) { Group tmp = new Group(); tmp.NumberOfLabels = json.LBL1.Groups[i].NumberOfLabels; _msbt.LBL1.Groups.Add(tmp); } int total = 0; foreach (Group grp in json.LBL1.Groups) { for (int i = 0; i < grp.NumberOfLabels; i++) { _msbt.AddLabelFromJson(json.strings[total].label, json.strings[total].value, (uint)json.LBL1.Groups.IndexOf(grp)); total += 1; } } // Tie in LBL1 labels foreach (Label lbl in _msbt.LBL1.Labels) { lbl.String = _msbt.TXT2.Strings[(int)lbl.Index]; } _msbt.File = new FileInfo(output); _msbt.Save(); }
public static void TestTurnip() { var data = Resources.STR_ItemName_41_Turnip; var obj = new MSBT(data); obj.SectionOrder.Count.Should().Be(3); obj.TXT2.Strings.Count.Should().BeGreaterThan(0); obj.DebugDumpLines(); }
public CharacterStringsMSBT(SmashProjectManager project, bool createNew = true) { if (createNew || !File.Exists(PathHelper.FolderEditorMods + "data/ui/message/melee.msbt")) { _SmashProjectManager = project; _SmashProjectManager.ExtractResource("data/ui/message/melee.msbt", PathHelper.FolderEditorMods, true); } msbt = new MSBT(PathHelper.FolderEditorMods + "data/ui/message/melee.msbt"); }
//int array should be value of 2 (first and last) and we'll attach the two values private static List <string> createTabbedLabelList(MSBT loaded, string language = "en", string space = "\t", int[] splitEntry = null) { List <string> entries = new List <string>(); for (int i = 0; i < loaded.LBL1.Labels.Count; ++i) { entries.Add(createTabbedLabel(loaded, i, language, space, splitEntry)); } return(entries); }
public static void CreateVillagerPhraseList(string language) { MSBT loadedMSBT = TableProcessor.LoadMSBT(PathHelper.GetVillagerNPCPhraseItem(PathHelper.Languages[language])); List <string> entries = createTabbedLabelList(loadedMSBT, language); entries.Sort(); WriteOutFile(PathHelper.OutputPath, language, villagerPhraseRootName + language + ".txt", string.Join("", entries)); }
public void DumpAllMSBT() { var files = Directory.GetFiles(path, "*.msbt", SearchOption.AllDirectories); foreach (var f in files) { var data = File.ReadAllBytes(f); var msbt = new MSBT(data); DumpMSBT(f, msbt); } }
public static void CreateReaction() { var table = TableProcessor.LoadTable(PathHelper.BCSVHumanAnimItem, (char)9, 3); MSBT loadedMSBT = TableProcessor.LoadMSBT(PathHelper.GetReactionNameItem(PathHelper.Languages["en"])); string templatePath = PathHelper.GetFullTemplatePathTo(itemReactionRootName); string outputPath = PathHelper.GetFullOutputPathTo(templatePath); string preClass = File.ReadAllText(templatePath); // player animations only Dictionary <int, string> tableEntries = new Dictionary <int, string>(); foreach (DataRow row in table.Rows) { if (row["0x2C447591"].ToString().StartsWith("MaRe")) { tableEntries.Add(int.Parse(row["0x54706054"].ToString()), row["0x2C447591"].ToString()); } } var dicSort = tableEntries.OrderBy(a => a.Key).ToList(); tableEntries = new Dictionary <int, string>(); foreach (var kvp in dicSort) { tableEntries.Add(kvp.Key, kvp.Value); } List <string> entries = new List <string>(); // fill with empties for (int i = 0; i < tableEntries.Count + 1; ++i) { entries.Add(string.Format("\t\tUNUSED_{0},\r\n", i)); } // now instert with correct indexes for (int i = 0; i < loadedMSBT.LBL1.Labels.Count; ++i) { var currLabel = loadedMSBT.LBL1.Labels[i]; string comment = currLabel.ToString(); var find = tableEntries.First(x => x.Value.Replace("MaRe", "").TrimEnd('\0') == comment); int index = tableEntries.ToList().IndexOf(find); string enumVal = loadedMSBT.FileEncoding.GetString(currLabel.Value); enumVal = new string(enumVal.Where(c => char.IsLetterOrDigit(c)).ToArray()); entries[index] = string.Format("\t\t{0}, // {1} \r\n", enumVal, comment); } entries[0] = "\t\tNone,\r\n"; preClass = replaceData(preClass, string.Join("", entries.ToArray())); writeOutFile(outputPath, preClass); }
public static void TestTownDefaultNames() { var data = Resources.STR_TownName; var obj = new MSBT(data); obj.SectionOrder.Count.Should().Be(3); obj.TXT2.Strings.Count.Should().BeGreaterThan(0); var str = obj.TXT2.Strings[8].ToString(obj.FileEncoding).TrimEnd('\0'); str.Should().Be("Awesome Beach"); obj.DebugDumpLines(); }
public void LoadMessages() { if (mFilesystem.DoesFileExist($"/LocalizeData/UsEnglish/MessageData/{mZoneName}.arc")) { RARCFilesystem msg = new RARCFilesystem(mFilesystem.OpenFile($"/LocalizeData/UsEnglish/MessageData/{mZoneName}.arc")); if (msg.DoesFileExist($"/root/{mZoneName}.msbt")) { mMessages = new MSBT(msg.OpenFile($"/root/{mZoneName}.msbt")); } if (msg.DoesFileExist($"/root/{mZoneName}.msbf")) { mMessageFlows = new MSBF(msg.OpenFile($"/root/{mZoneName}.msbf")); } } }
private static Dictionary <string, string> LoadMsbt(byte[] rawMsbt) { // Create a new dictionary to hold the text Dictionary <string, string> textMappings = new Dictionary <string, string>(); // Parse the MSBT MSBT msbt = new MSBT(rawMsbt); // Loop over every TXT2 entry for (int i = 0; i < msbt.TXT2.NumberOfStrings; i++) { IEntry entry = msbt.HasLabels ? msbt.LBL1.Labels[i] : msbt.TXT2.Strings[i]; textMappings.Add(entry.ToString(), msbt.FileEncoding.GetString(entry.Value).Trim('\0')); } return(textMappings); }
public static void CreateVillagerList(string language) { MSBT[] loadedMSBTs = new MSBT[2] { TableProcessor.LoadMSBT(PathHelper.GetVillagerNameItem(PathHelper.Languages[language])), TableProcessor.LoadMSBT(PathHelper.GetVillagerNPCNameItem(PathHelper.Languages[language])) }; List <string> rawEntries = new List <string>(); foreach (MSBT loaded in loadedMSBTs) { List <string> entries = createTabbedLabelList(loaded, language); entries.Sort(); rawEntries.AddRange(entries); } WriteOutFile(PathHelper.OutputPath, language, villagerListRootName + language + ".txt", string.Join("", rawEntries)); }
public void LoadMSBT(MSBT msbt) { activeMessageFile = msbt; if (msbt.header.Text2 != null) { foreach (var text in msbt.header.Text2.TextData) { string listText = text.GetTextLabel(ShowPreviewText, msbt.header.StringEncoding); if (listText.Length > 25) { listText = $"{listText.Substring(0, 25)}......"; } listViewCustom1.Items.Add(listText); } } }
public void LoadMSBT(MSBT msbt) { listViewCustom1.BeginUpdate(); listViewCustom1.Items.Clear(); activeMessageFile = msbt; if (msbt.header.Text2 != null) { if (ShowLabels && msbt.HasLabels) { foreach (var lbl in msbt.header.Label1.Labels) { ListViewItem item = new ListViewItem(); item.Text = lbl.Name; item.Tag = msbt.header.Text2.TextData[(int)lbl.Index]; listViewCustom1.Items.Add(item); } listViewCustom1.Sorting = SortOrder.Ascending; listViewCustom1.Sort(); } else { foreach (var text in msbt.header.Text2.TextData) { ListViewItem item = new ListViewItem(); string listText = text.GetTextLabel(ShowPreviewText, msbt.header.StringEncoding); if (listText.Length > 25) { listText = $"{listText.Substring(0, 25)}......"; } item.Text = listText; item.Tag = text; listViewCustom1.Items.Add(item); } } } listViewCustom1.EndUpdate(); }
public bool GenerateNewEntries(List <MsbtNewEntryModel> newMsbtEntries, string inputMsbtFile, string outputMsbtFile) { try { File.Copy(inputMsbtFile, outputMsbtFile); var msbtFile = new MSBT(outputMsbtFile); foreach (var newMsbtEntry in newMsbtEntries) { var newEntry = msbtFile.AddLabel(newMsbtEntry.Label); newEntry.Value = Encoding.Unicode.GetBytes(newMsbtEntry.Value + "\0"); } msbtFile.Save(); } catch (Exception e) { _logger.LogError(e, "MSBT Generation error"); } return(true); }
public static Dictionary <string, MSBT> LoadAllMSBTs_GiveNames(string rootPath) { string[] items = Directory.GetFiles(rootPath); string[] msbtItems = items.Where(x => x.EndsWith(".msbt") || x.EndsWith(".msbt".ToUpper())).ToArray(); MSBT[] msbts = new MSBT[msbtItems.Length]; for (int i = 0; i < msbtItems.Length; ++i) { msbts[i] = LoadMSBT(msbtItems[i]); } Dictionary <string, MSBT> toReturn = new Dictionary <string, MSBT>(); for (int i = 0; i < msbts.Length; ++i) { toReturn.Add(Path.GetFileName(msbtItems[i]), msbts[i]); } return(toReturn); }
private static void DumpMSBT(string f, MSBT msbt) { var destPath = f.Replace(path, outDir); var dir = new FileInfo(destPath).Directory.FullName; Directory.CreateDirectory(dir); var file = Path.Combine(dir, Path.GetFileNameWithoutExtension(destPath)); var x = msbt.GetOrderedLines(); File.WriteAllLines(file + "_raw.txt", x); var y = msbt.GetOrderedLinesTab(); File.WriteAllLines(file + "_tab.txt", y); var z = msbt.GetOrderedLinesSingle(); File.WriteAllLines(file + ".txt", z); }
public static void CreateBodyFabricColorPartsList(string language, bool writeToFile = true) { MSBT[] loadedMSBTs = new MSBT[4] { TableProcessor.LoadMSBT(PathHelper.GetBodyColorNameItem(PathHelper.Languages[language])), // needs to be 0 because I'm lazy TableProcessor.LoadMSBT(PathHelper.GetBodyPartsNameItem(PathHelper.Languages[language])), TableProcessor.LoadMSBT(PathHelper.GetFabricColorNameItem(PathHelper.Languages[language])), // as above, but 2 this time TableProcessor.LoadMSBT(PathHelper.GetFabricPartsNameItem(PathHelper.Languages[language])) }; int[][] separators = new int[][] // how much of a string we want between two separators in the msbt. "_" in this case { new int [] { 1, 2 }, new int [] { 1 }, new int [] { 1, 2 }, new int [] { 1 } }; string[] filenames = new string[4] { bodyColorRootName, bodyPartsRootName, fabricColorRootName, fabricPartsRootName }; for (int i = 0; i < loadedMSBTs.Length; ++i) { MSBT loaded = loadedMSBTs[i]; List <string> entries = createTabbedLabelList(loaded, language, "\t", separators[i]); entries.Sort(); if (writeToFile) { WriteOutFile(PathHelper.OutputPath, language, filenames[i] + language + ".txt", string.Join("", entries)); } if (i == 0) { bodyColorLines = entries.ToArray(); } if (i == 2) { fabricColorLines = entries.ToArray(); } } }
private static Dictionary <int, string> getOutfits(string language) { string rootPath = PathHelper.GetOutfiteNameDirectory(PathHelper.Languages[language]); Dictionary <string, MSBT> loadedItems = TableProcessor.LoadAllMSBTs_GiveNames(rootPath); Dictionary <int[], string> outfitColors = getOutfitColors(language); Dictionary <int, string> toRet = new Dictionary <int, string>(); int padAmount = PathHelper.LangPadAmount[language]; foreach (var loadPair in loadedItems) { MSBT loaded = loadPair.Value; for (int i = 0; i < loaded.LBL1.Labels.Count; ++i) { string keyLabel = loaded.LBL1.Labels[i].ToString(); if (keyLabel.keyLabelShouldBeDiscarded()) { continue; } // item name string itemName = loaded.FileEncoding.GetString(loaded.LBL1.Labels[i].Value); itemName = itemName.processString(keyLabel, language, padAmount); // get all possible variations var itemVariations = outfitColors.Where(x => x.Key[1] == int.Parse(keyLabel)); foreach (var kvpVariations in itemVariations) { string colorValueName = kvpVariations.Value.processString(keyLabel, language, 0); string variationItemName = string.Format(itemName + " ({0})", colorValueName); int itemNumber = kvpVariations.Key[0]; itemNumber += 1; // to match file line number variationItemName += "\r\n"; toRet.Add(itemNumber, variationItemName); } } } return(toRet); }
private static string createTabbedLabel(MSBT loaded, int entry, string language = "en", string space = "\t", int[] splitEntry = null) { string keyLabel = loaded.LBL1.Labels[entry].ToString(); string villagerName = loaded.FileEncoding.GetString(loaded.LBL1.Labels[entry].Value); string toUseAsKey = keyLabel; if (splitEntry != null) { string[] tmpSplit = keyLabel.Split('_'); string tmp; if (splitEntry.Length == 1) { tmp = tmpSplit[splitEntry[0]]; } else { tmp = tmpSplit[splitEntry[0]] + "_" + tmpSplit[splitEntry[1]]; } toUseAsKey = tmp; } return(toUseAsKey + space + villagerName.processString(toUseAsKey, language, PathHelper.LangPadAmount[language]) + "\r\n"); }
private void LoadActors() { //Setup a list of nodes based on category TreeNode ArmourFolder = new TreeNode("Armours"); TreeNode WeaponsFolder = new TreeNode("Weapons"); TreeNode ItemsFolder = new TreeNode("Items"); TreeNode EnemyFolder = new TreeNode("Enemies"); if (!Directory.Exists(Runtime.BotwGamePath)) { bool IsValid = NotifySetGamePath(); if (!IsValid) //Give up loading it if it's wrong { return; } } Dictionary <string, TreeNode> ActorIDS = new Dictionary <string, TreeNode>(); Dictionary <string, ActorInfo> Actors = new Dictionary <string, ActorInfo>(); if (File.Exists($"{Runtime.BotwGamePath}{ActorInfoTable}")) { var byml = EveryFileExplorer.YAZ0.Decompress($"{Runtime.BotwGamePath}{ActorInfoTable}"); var actorInfoProductRoot = ByamlExt.Byaml.ByamlFile.FastLoadN(new MemoryStream(byml)).RootNode; if (actorInfoProductRoot.ContainsKey("Actors")) { foreach (var actor in actorInfoProductRoot["Actors"]) { ActorInfo info = new ActorInfo(actor); if (info.Name != string.Empty) { Actors.Add(info.Name, info); } } } } //Parse message data for our actor names, and additional info to add to the editor Console.WriteLine("msbtEXT " + File.Exists($"{Runtime.BotwGamePath}{ActorMessageData}")); Console.WriteLine($"{Runtime.BotwGamePath}{ActorMessageData}"); if (File.Exists($"{Runtime.BotwGamePath}{ActorMessageData}")) { var msgPack = SARCExt.SARC.UnpackRamN(File.Open($"{Runtime.BotwGamePath}{ActorMessageData}", FileMode.Open)); //Get the other sarc inside foreach (var pack in msgPack.Files) { var msgProductPack = SARCExt.SARC.UnpackRamN(EveryFileExplorer.YAZ0.Decompress(pack.Value)); //Folders are setup with actors foreach (var msbtFile in msgProductPack.Files) { using (var stream = new MemoryStream(msbtFile.Value)) { MSBT msbt = new MSBT(); if (!msbt.Identify(stream)) { continue; } msbt.Load(new MemoryStream(msbtFile.Value)); //Get our labels and match up with our actors if (msbt.header.Label1 != null) { for (int i = 0; i < msbt.header.Label1.Labels.Count; i++) { var lbl = msbt.header.Label1.Labels[i]; if (lbl.Name.Contains("_Name")) { string actorName = lbl.Name.Replace("_Name", string.Empty); if (Actors.ContainsKey(actorName)) { Actors[actorName].MessageFile = Path.GetFileNameWithoutExtension(msbtFile.Key); Actors[actorName].MessageName = lbl.String.GetText(msbt.header.StringEncoding); } } if (lbl.Name.Contains("_Desc")) { string actorName = lbl.Name.Replace("_Desc", string.Empty); if (Actors.ContainsKey(actorName)) { Actors[actorName].MessageFile = Path.GetFileNameWithoutExtension(msbtFile.Key); Actors[actorName].MessageDescription = lbl.String.GetText(msbt.header.StringEncoding); } } } } msbt.Unload(); } } } } Dictionary <string, TreeNode> Categories = new Dictionary <string, TreeNode>(); foreach (var info in Actors) { if (info.Value.MessageName != string.Empty) { //Temp atm. Use message file name for organing string catgeory = info.Value.MessageFile; if (!Categories.ContainsKey(catgeory)) { TreeNode node = new TreeNode(catgeory); editor.AddNode(node); Categories.Add(catgeory, node); } ActorEntry entry = new ActorEntry(); entry.Info = info.Value; entry.Text = info.Value.MessageName; Categories[catgeory].Nodes.Add(entry); entry.ReloadActorProperties(); } } Categories.Clear(); GC.Collect(); }
public string GetKuriimuString(string str) { try { // [0] System Codes ------------------ // 0,0 = System.Ruby(Type8 rt) // 0,1 = System.Font(Type8 face) // 0,2 = System.Size(Type1 percent) // 0,3 = System.Color(Type0 r, Type0 g, Type0 b, Type0 a, Type8 name) // 0,4 = PageBreak() // [1] Cmd Codes --------------------- // 1,0 = Cmd.once_stop() // 1,1 = Cmd.key() // 1,2 = Cmd.event(no) // 1,3 = Cmd.wait(frame) // 1,4 = Cmd.deprecated_event_ff(Type9<Enum0> Cmd_deprecated_event_ff_id) // 1,5 = Cmd.event_ff(Type9<Enum1> Cmd_event_ff_id) // 1,6 = Cmd.event_scout(Type9<Enum2> Cmd_event_scout_id) // 1,7 = Cmd.voice(Type8 sound_id) // 1,8 = Cmd.wait_voice() // [2] Style Codes ------------------- // 2,0 = Style.ScaleX(Type4 scale_x) // 2,1 = Style.VSpace(Type4 space_v) // [3] Replace Codes ----------------- // 3,0 = Replace.Num(Type3 id, Type9<Enum3> Replace_Num_char_type, Type3 length) // 3,1 = Replace.Name(Type3 id) // 3,2 = Replace.Year(Type3 id) // 3,3 = Replace.Month(Type3 id) // 3,4 = Replace.MonthZero(Type3 id) // 3,5 = Replace.Day(Type3 id) // 3,6 = Replace.DayZero(Type3 id) // 3,7 = Replace.Hour(Type3 id) // 3,8 = Replace.HourZero(Type3 id) // 3,9 = Replace.Minute(Type3 id) // 3,A = Replace.MinuteZero(Type3 id) // 3,B = Replace.String(Type3 id, Type9<Enum4> Replace_String_char_type, Type9<Enum5> Replace_String_length_type, x) // [Enum values] --------------------- // Enum0[32] = none,SaluteSeq,Profile,Dlg_ProfileOK,MovePaper_Photo,CameraSequence,SwitchBalloon_toLower,SingerOn,SwitchBalloon_toUpper,SingerOff,BarbaraOn,BarbaraOff,FacePreview,Dlg_FaceOK,HairSelect,ColorSelect,VocaloidExteriorMenu,Dlg_IsVoiceRecordable,VoiceRecording,VoiceEstimation,VoiceEstimation_Hamoduo,VoiceEstimation_Result,VoiceEstimation_NoVoice,ToVocaloVoiceSequence,VocaloVoice,VocaloidStyleGamePlay,Signature,ShimobeSequence,Dlg_WaveOut,WaveOut_Tune_Play,Dlg_WaveOut_Really,SceneEnd // Enum1[20] = none,CameraSequence,PlayBGM,NameInput,BarbaraOn,BarbaraOff,BarbaraNormal,BarbaraAngry,BarbaraSmile,DialogKickMe,DialogYes,VoiceRecording,VoiceEstimation,ShowNamePlate,HideNamePlate,Signature,SingerSalute,BlackOut,BlackIn,SceneEnd // Enum2[6] = none,Dlg_WhoMakeSinger,GoToRegistFlow,CameraSequence,MySingerRemakeConfirm,SceneEnd_WithoutSave // Enum3[2] = hankaku,zenkaku // Enum4[3] = plain,hankaku,zenkaku // Enum5[7] = Default,Specify,ShortInstName,ShortInstName_Num,SongPostID,SongDB_ID,BandName // [Other type information] // Type0 = uint8 // Type1 = uint16, then divided by 100 // Type4 = int16, then divided by 100 // Type8 = no length / hidden? // Type9 = Enum str = string.Concat(MSBT.ToAtoms(str).Select(atom => { if (atom.type == MSBT.Atom.Type.Char) { return(atom.ToReadableString()); } else if (atom.type == MSBT.Atom.Type.EndCode) { return("</>"); } switch (atom.id1 * 10 + atom.id2) { case 02: return($"<s{BitConverter.ToInt16(atom.bytes, 0)}>"); // System.Size case 03: return($"<c{colours[BitConverter.ToUInt32(atom.bytes, 0)]}>"); // System.Color case 10: return($"<v>"); // Cmd.once_stop case 17: return($"<v{Encoding.Unicode.GetString(atom.bytes).Substring(1)}>"); // Cmd.voice case 20: return($"<w{BitConverter.ToInt16(atom.bytes, 0)}>"); // Style.ScaleX case 21: return($"<h{BitConverter.ToInt16(atom.bytes, 0)}>"); // Style.VSpace } return($"<r{(ReplaceCode)atom.id2}:{BitConverter.ToString(atom.bytes)}>"); // Replace.* })); return(symbols.Aggregate(str, (s, kvp) => s.Replace(kvp.Key, kvp.Value))); } catch { return(str); } }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("No file specified. Please drag-and-drop an MSBT file onto the .exe."); Console.WriteLine("Press any key to exit."); Console.ReadKey(); return; } string path = args[0]; if (!File.Exists(path)) { Console.WriteLine("Couldn't find specified file. Please drag-and-drop an MSBT file onto the .exe."); Console.WriteLine("Press any key to exit."); Console.ReadKey(); return; } Stream fileStream = File.Open(path, FileMode.Open); MSBT msbt = new MSBT(fileStream); List <Thread> threads = new List <Thread>(); int busyThreads = 0; if (msbt.HasLabels) { Console.WriteLine("Found " + msbt.LBL1.Labels.Count + " Labels. Translating..."); int curLabel = 0; foreach (Label lb in msbt.LBL1.Labels) { while (busyThreads >= THREAD_LIMIT) { busyThreads = 0; foreach (Thread th in threads) { busyThreads += th.IsAlive ? 1 : 0; } } Thread t = new Thread(() => { string txt = lb.Text; string translated = BadlyTranslate(txt); lb.Text = translated; Console.WriteLine("Translated Label '" + lb.Name + "' (" + (++curLabel) + " out of " + msbt.LBL1.Labels.Count + ")"); }); threads.Add(t); t.Start(); busyThreads++; } } else if (msbt.HasIDs) { Console.WriteLine("IDs"); } else { Console.WriteLine("Other"); } while (busyThreads != 0) { busyThreads = 0; foreach (Thread th in threads) { busyThreads += th.IsAlive ? 1 : 0; } } Console.WriteLine("Saving..."); Stream outStream = File.Open(path, FileMode.OpenOrCreate); msbt.Save(outStream); Console.WriteLine("MSBT Saved. Press any key to exit."); Console.ReadKey(); }
public FlowEmulator(MSBT msgs, MSBF flows) { mMessages = msgs; mFlows = flows; }
static void ExtractMSBT(string path, string output) { System.IO.FileInfo file = new System.IO.FileInfo(output); file.Directory.Create(); // If the directory already exists, this method does nothing. MSBT _msbt = new MSBT(path); MSBTList lstStrings = new MSBTList(); MainJSON main = new MainJSON(); main.header = _msbt.Header; main.SectionOrder = _msbt.SectionOrder; main.TXT2.NumberOfStrings = _msbt.TXT2.NumberOfStrings; main.TXT2.Identifier = _msbt.TXT2.Identifier; main.TXT2.Padding1 = _msbt.TXT2.Padding1; main.LBL1.NumberOfGroups = _msbt.LBL1.NumberOfGroups; main.LBL1.Groups = _msbt.LBL1.Groups; main.LBL1.Identifier = _msbt.LBL1.Identifier; main.LBL1.Padding1 = _msbt.LBL1.Padding1; main.ATO1 = _msbt.ATO1; main.ATR1 = _msbt.ATR1; main.NLI1 = _msbt.NLI1; main.TSY1 = _msbt.TSY1; List <JsonMSBT> json = new List <JsonMSBT>(); for (int i = 0; i < _msbt.TXT2.NumberOfStrings; i++) { if (_msbt.HasLabels) { lstStrings.Sorted = true; lstStrings.Items.Add(_msbt.LBL1.Labels[i]); } else { lstStrings.Sorted = false; lstStrings.Items.Add(_msbt.TXT2.Strings[i]); } } //if (lstStrings.Sorted) //{ // for (int i = 0; i < lstStrings.Items.Count; i++) // { // var x = lstStrings.Items[i]; // var j = i; // while (j > 0 && lstStrings.Items[j - 1].LabelName.CompareTo(x.LabelName) > 0) // { // lstStrings.Items[j] = lstStrings.Items[j - 1]; // j = j - 1; // } // lstStrings.Items[j] = x; // } //} foreach (MsbtEditor.Label label in lstStrings.Items) { string TMPlabel = label.Name; string TMPvalue = _msbt.FileEncoding.GetString(label.Value).Replace("\n", "\r\n").TrimEnd('\0').Replace("\0", @"\0") + "\0"; JsonMSBT tmpJson = new JsonMSBT(); tmpJson.label = TMPlabel; tmpJson.value = TMPvalue.Replace("\u0000", ""); json.Add(tmpJson); } main.strings = json; Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer(); serializer.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; serializer.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto; serializer.Formatting = Newtonsoft.Json.Formatting.Indented; using (StreamWriter sw = new StreamWriter(output)) using (Newtonsoft.Json.JsonWriter writer = new Newtonsoft.Json.JsonTextWriter(sw)) { serializer.Serialize(writer, main, typeof(MainJSON)); } }