/// <summary> /// 解析tbl文件。 /// </summary> /// <returns></returns> public List <TblModel> Parser() { var dic = new List <TblModel>(); while (reader.BaseStream.Position < reader.BaseStream.Length) { var key = ParserKey(); var value = ParserValue(); if (value.Length <= 0) { continue; } dic.Add(new TblModel { Key = key, Value = value }); } reader.Close(); return(dic); }
/// <summary> /// 翻译。 /// </summary> /// <param name="items"></param> /// <returns></returns> public byte[] Transform(TblModel[] items) { if (!items.Any()) { return(null); } while (reader.BaseStream.Position < reader.BaseStream.Length) { var key = ParserKey(); FileBytes.AddRange(keysBytes); TransformEventHandler?.Invoke(1, null); var value = ParserValue(); if (value.Length <= 0) { GetNextPosition(FileBytes); continue; } var info = items.FirstOrDefault(x => x.Key == key && x.Transform.Length > 0); if (info == null) { //如果当前的value没有汉化,这使用原来的 FileBytes.AddRange(valuesBytes); GetNextPosition(FileBytes); continue; } if (info.Value != value) { //如果字库中的韩文不等于解析出来的话,还是使用解析的 FileBytes.AddRange(valuesBytes); GetNextPosition(FileBytes); continue; } if (info.Transform.Length > 0) { var tranBytes = Encoding.UTF8.GetBytes(info.Transform); if (tranBytes.Length > valuesBytes.Length) { //翻译后的字节数大于韩文字节数,跳过 FileBytes.AddRange(valuesBytes); GetNextPosition(FileBytes); continue; } if (tranBytes.Length < valuesBytes.Length) { var tranList = tranBytes.ToList(); while (tranList.Count < valuesBytes.Length) { tranList.Add(0); } tranBytes = tranList.ToArray(); } FileBytes.AddRange(tranBytes); } else { FileBytes.AddRange(valuesBytes); } GetNextPosition(FileBytes); } reader.Close(); headBytes.AddRange(FileBytes); return(headBytes.ToArray()); }