private TFString ReadString(ItemData item, int index) { var stringOffset = item.Offset + index; var value = new TFString { FileId = Id, Offset = stringOffset, Visible = false }; var array = new byte[item.Size - index]; Array.Copy(item.BinaryContent, index, array, 0, array.Length); using (var ms = new MemoryStream(array)) { var str = ms.ReadStringZ(Encoding); if (!string.IsNullOrEmpty(str.TrimEnd('\0'))) { str = DisgaeaProject.ReadingReplacements(str); } value.Original = str; value.Translation = ReplaceToAscii(str); value.Visible = !string.IsNullOrWhiteSpace(str); } return(value); }
public static Project GetProject(string projectPath) { if (projectPath.EndsWith("tf_yak0")) { return(Yakuza0Project.GetProject(projectPath)); } if (projectPath.EndsWith("tf_shm")) { return(ShenmueProject.GetProject(projectPath)); } if (projectPath.EndsWith("tf_sao_hf")) { return(SAOProject.GetProject(projectPath)); } if (projectPath.EndsWith("tf_srr")) { return(SRRProject.GetProject(projectPath)); } if (projectPath.EndsWith("tf_dsg")) { return(DisgaeaProject.GetProject(projectPath)); } if (projectPath.EndsWith("tf_btr")) { return(BattleRealmsProject.GetProject(projectPath)); } if (projectPath.EndsWith("tf_spf2")) { return(Spellforce2Project.GetProject(projectPath)); } if (projectPath.EndsWith("tf_jjm")) { return(JJMacfieldProject.GetProject(projectPath)); } if (projectPath.EndsWith("tf_nightcry")) { return(NightCryProject.GetProject(projectPath)); } throw new Exception(); }
private int WriteItemContent(Stream s, ItemData item, IList <TFString> strings, ExportOptions options) { var result = 0; const byte stringStart = 0x01; var i = 0; while (i < item.Size) { if (item.BinaryContent[i] != stringStart) { s.WriteByte(item.BinaryContent[i]); result++; i++; } else { if (i < item.Size - 2) { if (IsValidShiftJis(item.BinaryContent[i + 1], item.BinaryContent[i + 2])) { var tfString = strings.FirstOrDefault(x => x.Offset == item.Offset + i + 1); if (tfString.Visible) { var str = tfString.Translation; if (options.CharReplacement != 0) { str = Utils.ReplaceChars(str, options.CharReplacementList); } str = DisgaeaProject.WritingReplacements(str); str = ReplaceToShiftJis(str); var bytes = Encoding.GetBytes(str); s.WriteByte(stringStart); s.WriteBytes(bytes); s.WriteByte(0); var originalLength = tfString.Original.GetLength(Encoding) + 1; var newLength = bytes.Length + 2; i = i + originalLength + 1; result = result + newLength; } else { s.WriteByte(item.BinaryContent[i]); result++; i++; } } else { s.WriteByte(item.BinaryContent[i]); result++; i++; } } else { s.WriteByte(item.BinaryContent[i]); result++; i++; } } } return(result); }