protected AI_AssetDumpHelper(TextDump plugin) : base(plugin) { TitleAssetCols = new AssetDumpColumnInfo { CombineWithParentBundle = true }; ListEntryDumpers.Add(TryDumpTitleSkillName); }
protected virtual IEnumerable <ITranslationDumper> GetHPositionDumpers() { const string rootPath = "list/h/animationinfo"; var hTypeNames = GetHTypeNames(); bool IsHPositionList(string assetName) { return(hTypeNames.Any(n => assetName.StartsWith($"{n}_", StringComparison.OrdinalIgnoreCase))); } var assetDumpColumnInfo = new AssetDumpColumnInfo(new KeyValuePair <int, int>(0, -1)); foreach (var assetBundleName in GetAssetBundleNameListFromPath(rootPath, true)) { foreach (var assetName in GetAssetNamesFromBundle(assetBundleName)) { if (!IsHPositionList(assetName)) { continue; } var filePath = BuildAssetFilePath(assetBundleName, assetName); IDictionary <string, string> AssetDumper() { var translations = new OrderedDictionary <string, string>(); var done = false; foreach (var tryDump in ListEntryDumpers) { GetAssetBundleNameListFromPath(rootPath, true); GetAssetNamesFromBundle(assetBundleName); done = tryDump(assetBundleName, assetName, assetDumpColumnInfo, translations); if (done) { break; } } if (!done) { Logger.LogWarning($"Unable to dump '{rootPath}': '{assetBundleName}': {assetName}"); } return(translations); } yield return(new StringTranslationDumper(filePath, AssetDumper)); } } }
protected AI_HS2_AssetDumpHelper(TextDump plugin) : base(plugin) { ItemLookup = new AssetDumpColumnInfo(null, null, true, new[] { "アイテム名", "名前(メモ)", }); ItemLookupAndAssetCols = new AssetDumpColumnInfo(null, StdExcelAssetCols.NameMappings, true, ItemLookup.ItemLookupColumns); }
protected virtual bool TryDumpTextAsset(string assetBundleName, string assetName, AssetDumpColumnInfo assetDumpColumnInfo, IDictionary <string, string> translations) { var textAsset = ManualLoadAsset <TextAsset>(assetBundleName, assetName, "abdata"); if (textAsset is null) { return(false); } //Logger.LogError($"Trying to dump (text): '{assetBundleName}': {assetName}: {textAsset.name}"); if (string.IsNullOrEmpty(textAsset.text)) // may be messagepack in bytes { foreach (var entry in DumpListBytes(textAsset, assetDumpColumnInfo)) { var key = entry.Key; var value = entry.Value ?? string.Empty; value = value != "0" ? value : string.Empty; AddLocalizationToResults(translations, key, value); } } else { foreach (var cols in assetDumpColumnInfo.NumericMappings) { var jpCol = cols.Key; var transCol = cols.Value; foreach (var row in TableHelper.SplitTableToRows(textAsset)) { var cells = TableHelper.SplitRowToCells(row).ToArray(); if (cells.Length <= jpCol) { continue; } var orig = cells[jpCol]; var trans = string.Empty; if (transCol >= 0 && cells.Length > transCol) { trans = cells[transCol]; } AddLocalizationToResults(translations, orig, trans); } } } return(true); }
protected virtual IEnumerable <KeyValuePair <string, string> > DumpListBytes(TextAsset asset, AssetDumpColumnInfo assetDumpColumnInfo) { var scanBytes = asset.bytes.Take(30); if (ArrayContains(scanBytes, Encoding.UTF8.GetBytes(ChaListData.ChaListDataMark))) { foreach (var entry in HandleChaListData(asset, assetDumpColumnInfo)) { yield return(entry); } } }
protected AssetDumpHelper(TextDump plugin) : base(plugin) { StdTextAssetCols = new AssetDumpColumnInfo(new Dictionary <string, string> { { "Name", "EN_US" } }); StdStudioAssetCols = new AssetDumpColumnInfo(null, null, true, new[] { "名称", "表示名" }); AssetDumpGenerators = new List <TranslationGenerator> { GetRandomNameListDumpers, GetCommunicationTextDumpers, GetListTextDumpers, GetScenarioTextDumpers, GetHTextDumpers, GetMapInfoDumpers }; //RawAssetDumpGenerators = new List<RawTranslationGenerator> { }; StdExcelAssetCols = new AssetDumpColumnInfo(new Dictionary <string, string> { { "Name", "EN_US" }, { "Text", "Text _EnUS" }, { "タイトル(日本語)", "タイトル(英語)" }, { "サブタイトル(日本語)", "サブタイトル(英語)" }, { "タイトル", "英語" }, { "日本語", "英語" }, { "本文(日本語)", "本文(英語?)" }, { "日本語(0)", "英語" }, { "選択肢1", "選択肢1(英語)" }, { "選択肢2", "選択肢2(英語)" }, { "選択肢3", "選択肢3(英語)" }, { "名前(メモ)", string.Empty } }); ListEntryDumpers = new List <TryDumpListEntry> { TryDumpExcelData, TryDumpTextAsset }; }
protected override IEnumerable <KeyValuePair <string, string> > HandleChaListData(TextAsset asset, AssetDumpColumnInfo assetDumpColumnInfo) { if (!TextDump.IsReadyForFinalDump()) { foreach (var result in base.HandleChaListData(asset, assetDumpColumnInfo)) { yield return(result); } } else { // now try and redump/populate if (!TextDump.IsReadyForFinalDump()) { yield break; } var categoryName = asset.name.Substring(0, asset.name.LastIndexOf("_", StringComparison.Ordinal)); var category = (ChaListDefine.CategoryNo)Enum.Parse(typeof(ChaListDefine.CategoryNo), categoryName); var catInfo = Singleton <Character> .Instance.chaListCtrl.GetCategoryInfo(category); var lookupDict = new Dictionary <string, string>(); foreach (var value in catInfo.Select(c => c.Value)) { if (!value.Name.IsNullOrEmpty()) { lookupDict[$"{value.Kind}_{value.Id}"] = value.Name; } } var chaListData = MessagePackSerializer.Deserialize <ChaListData>(asset.bytes); foreach (var entry in chaListData.dictList.Values) { foreach (var id in chaListData.dictList.Keys) { var key = chaListData.GetInfo(id, "Name"); if (string.IsNullOrEmpty(key)) { continue; } var val = lookupDict.GetOrInit($"{chaListData.GetInfo(id, "Kind")}_{id}", string.Empty); yield return(new KeyValuePair <string, string>(key, val)); } } } }
/* * protected virtual IEnumerable<KeyValuePair<string, string>> DumpListBytes(byte[] bytes, AssetDumpColumnInfo assetDumpColumnInfo) * { * return new Dictionary<string, string>(); * } */ protected virtual IEnumerable <KeyValuePair <string, string> > HandleChaListData(TextAsset asset, AssetDumpColumnInfo assetDumpColumnInfo) { var chaListData = MessagePackSerializer.Deserialize <ChaListData>(asset.bytes); foreach (var chaListEntry in chaListData.dictList) { var id = chaListEntry.Key; var entry = chaListEntry.Value; foreach (var mapping in assetDumpColumnInfo.NumericMappings) { var jpCol = mapping.Key; var transCol = mapping.Value; if (entry.Count < jpCol) { continue; } var key = entry[jpCol]; var val = string.Empty; if (transCol >= 0 && entry.Count > Math.Max(11, transCol)) { val = entry[transCol]; } //Logger.LogWarning($"match: {key}={val}"); yield return(new KeyValuePair <string, string>(key, IsValidChaListDataLocalization(id, entry, key, val) ? val : string.Empty)); } foreach (var mapping in assetDumpColumnInfo.NameMappings) { var key = chaListData.GetInfo(id, mapping.Key); if (string.IsNullOrEmpty(key)) { continue; } var val = chaListData.GetInfo(id, mapping.Value); yield return(new KeyValuePair <string, string>(key, IsValidChaListDataLocalization(id, entry, key, val) ? val : string.Empty)); } } }
protected virtual bool TryDumpExcelData(string assetBundleName, string assetName, AssetDumpColumnInfo assetDumpColumnInfo, IDictionary <string, string> translations) { var excelAsset = ManualLoadAsset <ExcelData>(assetBundleName, assetName, null); if (excelAsset is null) { return(false); } if (excelAsset.list == null || excelAsset.MaxCell <= 0) { return(true); } var mappings = new Dictionary <int, int>(); var skipName = new Dictionary <int, string>(); assetDumpColumnInfo.NumericMappings.ToList().ForEach(x => mappings[x.Key] = x.Value); int firstRow; var itemLookupColumns = new List <int[]>(); foreach (var headers in ResourceHelper.GetExcelHeaderRows(excelAsset, out firstRow)) { foreach (var entry in assetDumpColumnInfo.NameMappings) { var src = headers.IndexOf(entry.Key); var dest = -1; if (src != -1) { if (!string.IsNullOrEmpty(entry.Value)) { dest = headers.IndexOf(entry.Value); } mappings[src] = dest; skipName[src] = entry.Key; } } foreach (var entry in assetDumpColumnInfo.ItemLookupColumns) { var lookup = ResourceHelper.GetItemLookupColumns(headers, entry); if (lookup.Length > 0) { itemLookupColumns.Add(lookup); } Logger.DebugLogDebug( $"[TextDump] TryDumpExcelData: {assetBundleName}, {assetName}: {entry} => {string.Join(", ", lookup.Select(i => i.ToString()).ToArray())}"); } } foreach (var mapping in mappings.Where(m => m.Key > -1)) { for (var i = firstRow; i < excelAsset.list.Count; i++) { var row = excelAsset.GetRow(i); if (row.Count == 0 || row[0] == "no" || row.Count <= mapping.Key) { continue; } var key = row[mapping.Key]; var value = string.Empty; if (skipName.TryGetValue(mapping.Key, out var checkKey) && checkKey == key) { continue; } if (!ContainsNonAscii(key)) { continue; } if (mapping.Value > -1 && row.Count > mapping.Value) { var possibleTranslation = row[mapping.Value]; if (IsValidExcelLocalization(assetBundleName, assetName, firstRow, i, key, possibleTranslation)) { value = possibleTranslation; } } AddLocalizationToResults(translations, key, value); } } foreach (var mapping in itemLookupColumns) { for (var i = firstRow; i < excelAsset.list.Count; i++) { var row = excelAsset.GetRow(i); var translatedName = ResourceHelper.PerformNameLookup(row, mapping); var key = translatedName.Key; var value = translatedName.Value; AddLocalizationToResults(translations, key, value); } } return(true); }
protected virtual IEnumerable <ITranslationDumper> MakeListTextCollectors(string path, AssetDumpColumnInfo assetDumpColumnInfo, string baseDir = "list") { var rootPath = baseDir.IsNullOrEmpty() ? path : CombinePaths(baseDir, path); Logger.DebugLogDebug($"MakeListTextCollectors: {rootPath}"); foreach (var assetBundleName in GetAssetBundleNameListFromPath(rootPath, true)) { Logger.DebugLogDebug($"MakeListTextCollectors: {rootPath} {assetBundleName}"); foreach (var assetName in GetAssetNamesFromBundle(assetBundleName)) { Logger.DebugLogDebug($"MakeListTextCollectors: {rootPath} {assetBundleName} {assetName}"); var filePath = BuildAssetFilePath(assetBundleName, assetName); var translations = new OrderedDictionary <string, string>(); IDictionary <string, string> AssetDumper() { var done = false; foreach (var tryDump in ListEntryDumpers) { GetAssetBundleNameListFromPath(rootPath, true); GetAssetNamesFromBundle(assetBundleName); done = tryDump(assetBundleName, assetName, assetDumpColumnInfo, translations); if (done) { break; } } if (!done) { Logger.LogWarning($"Unable to dump '{rootPath}': '{assetBundleName}': {assetName}"); } return(translations); } yield return(new StringTranslationDumper(filePath, AssetDumper)); if (!assetDumpColumnInfo.CombineWithParentBundle) { continue; } // treat foo_bar_01 as foo_bar var parentAssetName = assetName; var nameParts = parentAssetName.Split('_'); if (nameParts.Length > 1 && int.TryParse(Path.GetFileNameWithoutExtension(nameParts.Last()), out _)) { parentAssetName = string.Join("_", nameParts.Take(nameParts.Length - 1).ToArray()) + Path.GetExtension(assetName); } var parentFile = BuildAssetFilePath(Path.GetDirectoryName(assetBundleName), parentAssetName); yield return(new StringTranslationDumper(parentFile, () => translations)); } } }
protected virtual bool TryDumpTitleSkillName(string assetBundleName, string assetName, AssetDumpColumnInfo _, IDictionary <string, string> translations) { var titleSkillName = ManualLoadAsset <TitleSkillName>(assetBundleName, assetName, "abdata"); if (titleSkillName is null) { return(false); } foreach (var entry in titleSkillName.param) { var key = entry.name0; var value = entry.name1; ResourceHelper.AddLocalizationToResults(translations, key, value); } LocalizationDumpHelper?.AddAutoLocalizer( $"{assetBundleName.Replace(".unity3d", string.Empty)}/{Path.GetFileNameWithoutExtension(assetName)}", new Dictionary <string, string>(translations)); return(true); }
public virtual IEnumerable <KeyValuePair <string, string> > DumpListBytes(byte[] bytes, AssetDumpColumnInfo assetDumpColumnInfo) { return(new Dictionary <string, string>()); }