private void BtnTranslate_Click(object sender, EventArgs e) { if (multiworker != null && multiworker.IsBusy) { multiworker.CancelAsync(); } try { if (File.Exists(TranslationTargetFile)) { GboxTranslator.Enabled = false; RunWithWorker(((o, args) => { //BackgroundWorker backgroundWorker = o as BackgroundWorker; BDat bdat = new BDat(); bdat.Translate(TranslateRepackPath, TranslationTargetFile, TranslateIs64); GboxTranslator.Enabled = true; })); } else { MessageBox.Show("Translation files not exist please select source and merge files first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void BtnExport_Click(object sender, EventArgs e) { if (multiworker != null && multiworker.IsBusy) { multiworker.CancelAsync(); } try { if (File.Exists(TranslationBinFile)) { GboxTranslator.Enabled = false; RunWithWorker(((o, args) => { BDat bdat = new BDat(); bdat.ExportTranslate(TranslationBinFile, TranslationExportFile, BXML_TYPE.BXML_PLAIN, TranslateIs64); GboxTranslator.Enabled = true; })); } else { MessageBox.Show(".bin not exist please extract first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void btnDump_Click(object sender, EventArgs e) { if (!File.Exists(FullBinPath)) { MessageBox.Show("Select .bin file to dump.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { RunWithWorker(((o, args) => { BDat bdat = new BDat(); bdat.Dump(FullBinPath, OutPathBin, BXML_TYPE.BXML_PLAIN, binIs64); })); } }
static BDAT_SUBARCHIVE ApplyFilter(BDAT_SUBARCHIVE sub, Filter filter) { var filtered = sub.Fields .Zip(sub.Lookups, ValueTuple.Create) .Where(zipped => { var(field, lookup) = zipped; var words = new BDat().LookupSplitToWords(lookup.Data, lookup.Size); var alias = words[0]; var text = words[1]; return(filter.Matches(alias)); }) .ToArray(); if (filtered.Length == 0) { return(null); } else if (filtered.Length == sub.FieldLookupCount) { return(sub); } else { var fields = filtered.Select(zipped => zipped.Item1).ToArray(); var lookups = filtered.Select(zipped => zipped.Item2).ToArray(); var startEnd = new byte[16]; using (var stream = new MemoryStream(startEnd)) using (var writer = new BinaryWriter(stream)) { writer.Write((long)fields.First().ID); writer.Write((long)fields.Last().ID); } return(new BDAT_SUBARCHIVE { Fields = fields, Lookups = lookups, FieldLookupCount = fields.Length, StartAndEndFieldId = startEnd }); } }
public static string FilterLocalBinInPlace(string binfile, Filter filter) { var is64 = binfile.EndsWith("64.bin"); var bdat = new BDat(); using (var stream = new FileStream(binfile, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var reader = new BinaryReader(stream)) { bdat.Load(reader, BXML_TYPE.BXML_BINARY, is64); } var text = bdat.Content.Lists .Select(list => list.Collection.Archive) .SingleOrDefault(archive => archive != null); if (text == null) { throw new Exception($"Could not find text table in {binfile}"); } var filtered = text.SubArchives .Select(sub => ApplyFilter(sub, filter)) .Where(x => x != null) .ToArray(); var countBefore = text.SubArchives.Sum(sub => sub.FieldLookupCount); var countAfter = filtered.Sum(sub => sub.FieldLookupCount); //Console.WriteLine($"Kept {countAfter} out of {countBefore} text strings ({countAfter / (float)countBefore:P})"); string outprint = $"Kept {countAfter} out of {countBefore} text strings ({countAfter / (float)countBefore:P})"; text.SubArchives = filtered; text.SubArchiveCount = filtered.Length; using (var stream = new FileStream(binfile, FileMode.Create, FileAccess.Write)) using (var writer = new BinaryWriter(stream)) { bdat.Save(writer, BXML_TYPE.BXML_BINARY, is64); } return(outprint); }
private void btnExportTranslate_Click(object sender, EventArgs e) { string saveFolder = OutPathBinTranslate + (tIs64 ? @"Translation64.xml" : @"Translation.xml"); //original translation xml string usedfilepath = FullBinPathTranslate; //original bin file if (!File.Exists(usedfilepath)) { MessageBox.Show("bin file not found make sure you have unpacked local file and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Directory.CreateDirectory(OutPathBinTranslate); // Console.WriteLine("\rMerging translation..."); RunWithWorker(((o, args) => { //BackgroundWorker backgroundWorker = o as BackgroundWorker; BDat bdat = new BDat(); bdat.ExportTranslate(usedfilepath, saveFolder, BXML_TYPE.BXML_PLAIN, tIs64); })); } }
private void btn_Translate_Click(object sender, EventArgs e) { string local = DatPathTranslate; //extracetd local folder string xml = OutPathBinTranslate + (tIs64 ? @"Translation64.xml" : @"Translation.xml"); //translated xml if (!File.Exists(xml)) { MessageBox.Show("Original translation.xml file not found make sure you have unpacked local file and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (!Directory.Exists(local)) { MessageBox.Show("Unpacked local files not found make sure you have unpacked it and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { RunWithWorker(((o, args) => { BDat bdat = new BDat(); bdat.Translate(local, xml, tIs64); })); } }
private static void InitializeBoard(int size, Action callback) { SetSize(size); // Sets Size of the console, etc. // Initializes the 2D Array var dat = new BDat[size, size]; for (var i = 0; i < dat.GetLength(0); i++) { for (var j = 0; j < dat.GetLength(1); j++) { var d = new BDat(j, i); d.OnStateChanged += (s, g) => { RenderBoard(); }; dat[i, j] = d; } } // Subscribe to selection changed event BoardData.Selection.OnVectorChange += (s, g) => { RenderBoard(); }; // Set board data to dat (temp data) BoardData.Data = dat; BoardData.OnWinnerSelected += (s, g) => { var win = new WinnerData { Winner = g, WinTime = DateTime.Now }; BoardData.Winner = win; //RenderBoard(); }; BoardData.OnPlaceChanged += (s, g) => { // Check neighbors and check winner BoardData.Data.CheckNeighbors(g, 5, (i, state) => { var c = state.StateChar; if (HighestScoreData.Data.ContainsKey(c) && HighestScoreData.Data[c] is HighestScoreData score) { if (score.Score > i) { return; } var tempD = new HighestScoreData { Score = i, Character = state }; HighestScoreData.Data[c] = tempD; } if (i >= 5) // Check if any winner { BoardData.CallWinnerSelected(state); } TitleEditor.RefreshTitle(); }); if (!BoardData.Data.IsFilled()) { RenderBoard(); } }; // Invoke callback callback?.Invoke(); }
void TranslateFile(object sender, EventArgs e) { BDat bdat = new BDat(); bdat.Translate(TargetlocaldatPath, TargetMergeFile, tIs64); }
void SourceExport(object sender, EventArgs e) { BDat bdat = new BDat(); bdat.ExportTranslate(SourceBinFile, SourceMergeFile, BXML_TYPE.BXML_PLAIN, tIs64); }
private void TargetExport(object sender, EventArgs e) { BDat bdat = new BDat(); bdat.ExportTranslate(TargetBinFile, TargetMergeFile, BXML_TYPE.BXML_PLAIN, tIs64); }