public void Translate(string dir, string lang, bool is64) { Console.Write("\rTranslating: Content..."); string bin = is64 ? @"local64.dat.files\localfile64.bin" : @"local.dat.files\localfile.bin"; FileStream fs = new FileStream(dir + bin, FileMode.Open); BinaryReader br = new BinaryReader(fs); Load(br, BXML_TYPE.BXML_BINARY, is64); TranslateReader translateControl = new TranslateReader(); translateControl.Load(lang); TranslateGeneral(translateControl); br.Close(); BinaryWriter bw = new BinaryWriter(File.Open(dir + (is64 ? "localfile64_new.bin" : "localfile_new.bin"), FileMode.Create)); Save(bw, BXML_TYPE.BXML_BINARY, is64); bw.Close(); Console.WriteLine("\rDone!!"); }
public void TranslateGeneral(TranslateReader translator) { if (_indexCommons > -1) { int index = 0; int index2 = index; BDAT_LIST blist = _content.Lists[_indexCommons]; if (blist.Collection.Compressed > 0) { BDAT_ARCHIVE barchive = blist.Collection.Archive; BDAT_SUBARCHIVE bsubarchive; List <BDAT_SUBARCHIVE> subNews = new List <BDAT_SUBARCHIVE>(); for (int s = 0; s < barchive.SubArchiveCount; s++) { bsubarchive = barchive.SubArchives[s]; // Console.Write("\rTranslateGeneral SubArchive: {0}/{1}", (s + 1), barchive.SubArchiveCount); for (int f = 0; f < bsubarchive.FieldLookupCount; f++) { //Console.Write("\rTranslateGeneral FieldLookup: {0}/{1}", (f + 1), bsubarchive.FieldLookupCount); BDAT_FIELDTABLE field = bsubarchive.Fields[f]; BDAT_LOOKUPTABLE blookup = bsubarchive.Lookups[f]; string[] words = LookupSplitToWords(blookup.Data, blookup.Size); string translated = translator.Translate(words[1], words[0]); // alias //Buffer.BlockCopy(BitConverter.GetBytes(words[0].Length), 0, field.Data, 12, 4); //translate if (translated != null) { words[1] = translated; blookup.Data = LookupWorldsToBytes(words); blookup.Size = blookup.Data.Length; // set new test size //Buffer.BlockCopy(BitConverter.GetBytes(words[1].Length), 0, field.Data, 8, 4); } } if (bsubarchive.NeedSplit(ref index)) { BDAT_SUBARCHIVE bClone1 = new BDAT_SUBARCHIVE() { StartAndEndFieldId = new byte[16], Fields = new BDAT_FIELDTABLE[index], Lookups = new BDAT_LOOKUPTABLE[index], FieldLookupCount = index }; Array.Copy(bsubarchive.Fields, 0, bClone1.Fields, 0, index); Array.Copy(bsubarchive.Lookups, 0, bClone1.Lookups, 0, index); // set new start field id Buffer.BlockCopy(BitConverter.GetBytes(bClone1.Fields[0].ID), 0, bClone1.StartAndEndFieldId, 0, 4); // set new end field id Buffer.BlockCopy(BitConverter.GetBytes(bClone1.Fields[index - 1].ID), 0, bClone1.StartAndEndFieldId, 8, 4); subNews.Add(bClone1); //part 2 index2 = bsubarchive.FieldLookupCount - index; BDAT_SUBARCHIVE bClone2 = new BDAT_SUBARCHIVE() { StartAndEndFieldId = new byte[16], Fields = new BDAT_FIELDTABLE[index2], Lookups = new BDAT_LOOKUPTABLE[index2], FieldLookupCount = index2 }; Array.Copy(bsubarchive.Fields, index, bClone2.Fields, 0, index2); Array.Copy(bsubarchive.Lookups, index, bClone2.Lookups, 0, index2); // set new start field id Buffer.BlockCopy(BitConverter.GetBytes(bClone2.Fields[0].ID), 0, bClone2.StartAndEndFieldId, 0, 4); // set new end field id Buffer.BlockCopy(BitConverter.GetBytes(bClone2.Fields[index2 - 1].ID), 0, bClone2.StartAndEndFieldId, 8, 4); subNews.Add(bClone2); Console.WriteLine("A:{0}<>B:{1}.OK!", m_bnsDat.BytesToHex(bClone1.StartAndEndFieldId), m_bnsDat.BytesToHex(bClone2.StartAndEndFieldId)); } else { subNews.Add(bsubarchive); } } barchive.SubArchiveCount = subNews.Count; barchive.SubArchives = subNews.ToArray(); // Console.WriteLine("IF A==B that mean have something wrong! Check source code and fix it."); //Console.WriteLine("\rDone!!"); } else { BDAT_LOOSE bloose = blist.Collection.Loose; BDAT_LOOKUPTABLE blookup = bloose.Lookup; string[] words = LookupSplitToWords(bloose.Lookup.Data, bloose.SizeLookup); for (int w = 0; w < words.Length; w += 2) { string translated = translator.Translate(words[w + 1], words[w]); if (translated != null) { words[w + 1] = translated; } //Console.WriteLine("words[w + 1]: " + words[w + 1]); } blookup.Data = LookupWorldsToBytes(words); blookup.Size = blookup.Data.Length; } } }