public override MSB1.Event Serialize(GameObject parent) { var evt = new MSB1.Event.Environment(); _Serialize(evt, parent); evt.UnkT00 = UnkT00; evt.UnkT04 = UnkT04; evt.UnkT08 = UnkT08; evt.UnkT0C = UnkT0C; evt.UnkT10 = UnkT10; evt.UnkT14 = UnkT14; return(evt); }
static void translateMsbs(string a) { string msbDir = a.EndsWith("\\") ? a.Substring(a.Length - 1, 1) : a; string[] msbFileList = Directory.GetFiles(msbDir); List <string> msbFileNameList = new List <string>(); List <MSB1> msbs = new List <MSB1>(); Console.WriteLine("### " + msbDir); for (int i = 0; i < msbFileList.Length; i++) { string fn = msbFileList[i].Substring(msbDir.Length + 1, msbFileList[i].Length - (msbDir.Length + 1)); msbFileNameList.Add(fn); msbs.Add(MSB1.Read(File.ReadAllBytes(msbFileList[i]))); } TranslationClient client = TranslationClient.Create(GoogleCredential.FromFile("C:\\Users\\dmtin\\google-translate-api-key.txt")); /* I could also translate the region names but I'd have to build a map of all the original names -> translated names and apply the new names to the right events */ /* A lot of work and potentially buggy so I'm not going to do it right now. */ for (int i = 0; i < msbs.Count; i++) { MSB1 msb = msbs[i]; Console.WriteLine("\n\n\n\n==================" + msbFileNameList[i] + "=================="); Console.WriteLine("\n\n#### EventType: Environment ####"); for (int j = 0; j < msb.Events.Environments.Count; j++) { MSB1.Event.Environment evto = msb.Events.Environments[j]; try { if (evto.Name != null && !evto.Name.Trim().Equals("")) { TranslationResult response = client.TranslateText(evto.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0) { evto.Name = response.TranslatedText; } } } catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); } Console.WriteLine(evto.EventID + ":: " + evto.Name); } Console.WriteLine("\n\n#### EventType: Generator ####"); for (int j = 0; j < msb.Events.Generators.Count; j++) { MSB1.Event.Generator evto = msb.Events.Generators[j]; try { if (evto.Name != null && !evto.Name.Trim().Equals("")) { TranslationResult response = client.TranslateText(evto.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0) { evto.Name = response.TranslatedText; } } } catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); } Console.WriteLine(evto.EventID + ":: " + evto.Name); } Console.WriteLine("\n\n#### EventType: Navmesh ####"); for (int j = 0; j < msb.Events.Navmeshes.Count; j++) { MSB1.Event.Navmesh evto = msb.Events.Navmeshes[j]; try { if (evto.Name != null && !evto.Name.Trim().Equals("")) { TranslationResult response = client.TranslateText(evto.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0) { evto.Name = response.TranslatedText; } } } catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); } Console.WriteLine(evto.EventID + ":: " + evto.Name); } Console.WriteLine("\n\n#### EventType: Light ####"); for (int j = 0; j < msb.Events.Lights.Count; j++) { MSB1.Event.Light evto = msb.Events.Lights[j]; try { if (evto.Name != null && !evto.Name.Trim().Equals("")) { TranslationResult response = client.TranslateText(evto.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0) { evto.Name = response.TranslatedText; } } } catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); } Console.WriteLine(evto.EventID + ":: " + evto.Name); } Console.WriteLine("\n\n#### EventType: Message ####"); for (int j = 0; j < msb.Events.Messages.Count; j++) { MSB1.Event.Message evto = msb.Events.Messages[j]; try { if (evto.Name != null && !evto.Name.Trim().Equals("")) { TranslationResult response = client.TranslateText(evto.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0) { evto.Name = response.TranslatedText; } } } catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); } Console.WriteLine(evto.EventID + ":: " + evto.Name); } Console.WriteLine("\n\n#### EventType: ObjAct ####"); for (int j = 0; j < msb.Events.ObjActs.Count; j++) { MSB1.Event.ObjAct evto = msb.Events.ObjActs[j]; try { if (evto.Name != null && !evto.Name.Trim().Equals("")) { TranslationResult response = client.TranslateText(evto.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0) { evto.Name = response.TranslatedText; } } } catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); } Console.WriteLine(evto.EventID + ":: " + evto.Name); } Console.WriteLine("\n\n#### EventType: SFX ####"); for (int j = 0; j < msb.Events.SFX.Count; j++) { MSB1.Event.SFX evto = msb.Events.SFX[j]; try { if (evto.Name != null && !evto.Name.Trim().Equals("")) { TranslationResult response = client.TranslateText(evto.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0) { evto.Name = response.TranslatedText; } } } catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); } Console.WriteLine(evto.EventID + ":: " + evto.Name); } Console.WriteLine("\n\n#### EventType: Sound ####"); for (int j = 0; j < msb.Events.Sounds.Count; j++) { MSB1.Event.Sound evto = msb.Events.Sounds[j]; try { if (evto.Name != null && !evto.Name.Trim().Equals("")) { TranslationResult response = client.TranslateText(evto.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0) { evto.Name = response.TranslatedText; } } } catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); } Console.WriteLine(evto.EventID + ":: " + evto.Name); } Console.WriteLine("\n\n#### EventType: SpawnPoint ####"); for (int j = 0; j < msb.Events.SpawnPoints.Count; j++) { MSB1.Event.SpawnPoint evto = msb.Events.SpawnPoints[j]; try { if (evto.Name != null && !evto.Name.Trim().Equals("")) { TranslationResult response = client.TranslateText(evto.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0) { evto.Name = response.TranslatedText; } } } catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); } Console.WriteLine(evto.EventID + ":: " + evto.Name); } Console.WriteLine("\n\n#### EventType: Treasure ####"); for (int j = 0; j < msb.Events.Treasures.Count; j++) { MSB1.Event.Treasure evto = msb.Events.Treasures[j]; try { if (evto.Name != null && !evto.Name.Trim().Equals("")) { TranslationResult response = client.TranslateText(evto.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0) { evto.Name = response.TranslatedText; } } } catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); } Console.WriteLine(evto.EventID + ":: " + evto.Name); } Console.WriteLine("\n\n#### EventType: Wind ####"); for (int j = 0; j < msb.Events.Wind.Count; j++) { MSB1.Event.Wind evto = msb.Events.Wind[j]; try { if (evto.Name != null && !evto.Name.Trim().Equals("")) { TranslationResult response = client.TranslateText(evto.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0) { evto.Name = response.TranslatedText; } } } catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); } Console.WriteLine(evto.EventID + ":: " + evto.Name); } } Directory.CreateDirectory(msbDir + "\\translated\\"); for (int i = 0; i < msbs.Count; i++) { string outPath = msbDir + "\\translated\\" + msbFileNameList[i]; byte[] outData = msbs[i].Write(); File.WriteAllBytes(outPath, outData); } Console.WriteLine("\n\n Done!"); }