public MapperWindow(GpkStore gpkStore) { InitializeComponent(); var vm = new MapperViewModel(gpkStore); vm.CloseRequested += Close; DataContext = vm; MinimizeCommand = new RelayCommand(_ => { WindowState = WindowState.Minimized; }); CloseCommand = new RelayCommand(_ => { Close(); }); }
public FormMapperView(GpkStore store) { InitializeComponent(); this.store = store; treeMapperView.SetStore(store); IDisposable subscription = Observable .FromEventPattern( h => boxSearch.TextChanged += h, h => boxSearch.TextChanged -= h) .Select(x => boxSearch.Text) .Throttle(TimeSpan.FromMilliseconds(300)) .Select(x => Observable.Start(() => x)) .Switch() .ObserveOn(this) .Subscribe(x => boxSearch_TextChanged()); }
public static void DumpMassIcons(GpkStore store, String outdir, Dictionary <String, List <CompositeMapEntry> > filterList) { logger.Info("Started dumping textures to " + outdir); Directory.CreateDirectory(outdir); SynchronizedCollection <Task> runningTasks = new SynchronizedCollection <Task>(); int MAX_TASKS = 100; foreach (var file in filterList) { if (!file.Value.Any(x => x.UID.StartsWith("Icon_"))) { continue; } //throttle thread creation while (runningTasks.Count > MAX_TASKS) { Thread.Sleep(1000); } //limit to 5 threads by default foreach (var entry in file.Value) { if (!entry.UID.StartsWith("Icon_")) { continue; } Task newTask = null; newTask = new Task(() => { string path = string.Format("{0}\\{1}.gpk", store.BaseSearchPath, entry.SubGPKName); var fullName = entry.UID.Split('.'); //create out dir var fileOutPath = string.Format("{0}\\{1}\\", outdir, fullName[0]); Directory.CreateDirectory(fileOutPath); if (!File.Exists(path)) { logger.Warn("GPK to load not found. Searched for: " + path); return; } Reader r = new Reader(); var package = r.ReadSubGpkFromComposite(path, entry.UID, entry.FileOffset, entry.FileLength); package.LowMemMode = true; //extract var exports = package.GetExportsByClass("Core.Texture2D"); foreach (var export in exports) { //UID->Composite UID //S1UI_Chat2.Chat2,c7a706fb_6a349a6f_1d212.Chat2_dup | //we use this uid from pkgmapper //var imagePath = string.Format("{0}{1}_{2}.dds", fileOutPath, entry.UID, export.UID); var imagePath = string.Format("{0}{1}.dds", fileOutPath, fullName[1]); TextureTools.exportTexture(export, imagePath); logger.Info("Extracted texture {0} to {1}", entry.UID, imagePath); } //remove ref to ease gc exports.Clear(); package = null; runningTasks.Remove(newTask); }); newTask.Start(); runningTasks.Add(newTask); } } Task.WaitAll(runningTasks.ToArray()); NLogConfig.EnableFormLogging(); logger.Info("Dumping done"); }
public static void WriteMappings(string path, GpkStore store, bool writeCompMapper, bool writePkgMapper) { logger.Debug("WriteMappings for " + path); try { string compMapperPath = path + "CompositePackageMapper.dat" + CoreSettings.Default.SaveFileSuffix; string pkgMapperPath = path + "PkgMapper.dat" + CoreSettings.Default.SaveFileSuffix; var writer = new StringBuilder(); foreach (var entry in store.ObjectMapperList) { //S1UI_SelectServer.SelectServer_I4C,ffe86d35_cb268950_1e082.SelectServer_I4C_dup| //Key = CompositeUID, Value=Nórmal UID writer.Append(entry.Value + ","); writer.Append(entry.Key); writer.Append("|"); } File.WriteAllText(pkgMapperPath + "_decrypt", writer.ToString()); //final output var data = Encoding.UTF8.GetBytes(writer.ToString()); EncryptFile(data); File.WriteAllBytes(pkgMapperPath, data); //-- logger.Debug("writing CompositePackageMapper"); writer = new StringBuilder(); foreach (var fileName in store.CompositeMap.Keys) { writer.Append(fileName + "?"); foreach (var entry in store.CompositeMap[fileName]) { writer.Append(entry.CompositeUID + ","); writer.Append(entry.CompPackageName + ","); writer.Append(entry.FileOffset + ","); writer.Append(entry.FileLength + ","); writer.Append("|"); } writer.Append("!"); } File.WriteAllText(compMapperPath + "_decrypt", writer.ToString()); //encryption magic data = Encoding.UTF8.GetBytes(writer.ToString()); EncryptFile(data); File.WriteAllBytes(compMapperPath, data); logger.Info("Wrote PkgMapper to " + pkgMapperPath); logger.Info("Wrote CompositePackageMapper to " + compMapperPath); } catch (Exception ex) { logger.Info("Loading of mappings failed"); logger.Error(ex); } }
public static void ParseMappings(string folder, GpkStore store) { logger.Debug("ParseMappings for " + folder); try { string pkgMapper = folder + "\\PkgMapper.dat"; string compMapper = folder + "\\CompositePackageMapper.dat"; if (!File.Exists(pkgMapper) || !File.Exists(compMapper)) { logger.Info("Not all .dat files found"); return; } var pkgMapperData = File.ReadAllBytes(pkgMapper); DecryptFile(pkgMapperData); StreamReader reader = new StreamReader(new MemoryStream(pkgMapperData)); var pkgMapperText = reader.ReadToEnd(); reader.Close(); store.ObjectMapperList = new Dictionary <string, string>(); var objectEntries = pkgMapperText.Split('|'); foreach (var entry in objectEntries) { var split = entry.Split(','); if (split.Length < 2) { continue; } var uid = split[0]; var compositeUID = split[1]; logger.Trace("entry {0}:{1}", uid, compositeUID); store.ObjectMapperList.Add(compositeUID, uid); } logger.Debug("parsing CompositePackageMapper"); var compPkgMapper = File.ReadAllBytes(compMapper); DecryptFile(compPkgMapper); reader = new StreamReader(new MemoryStream(compPkgMapper)); var comppPackMapperText = reader.ReadToEnd(); reader.Close(); store.CompositeMap = new Dictionary <string, List <CompositeMapEntry> >(); var fileEntries = comppPackMapperText.Split('!'); for (int i = 0; i < fileEntries.Length; i += 1) { var baseSplit = fileEntries[i].Split('?'); if (baseSplit.Length < 2) { continue; } var fileName = baseSplit[0]; var fileContent = baseSplit[1]; //Composite UID, Unkown Object ID, Sub-GPK File offset, Sub-GPK File length //c7a706fb_6a349a6f_1d212.Chat2_dup,c7a706fb_6a349a6f_1d212,92291307,821218,| var subGPKEntries = baseSplit[1].Split('|'); foreach (var entry in subGPKEntries) { var split = entry.Split(','); if (split.Length < 5) { continue; } var tmp = new CompositeMapEntry(); tmp.CompositeUID = split[0]; tmp.CompPackageName = split[1]; tmp.FileOffset = Convert.ToInt32(split[2]); tmp.FileLength = Convert.ToInt32(split[3]); //sanity if (!store.ObjectMapperList.ContainsKey(tmp.CompositeUID)) { logger.Debug("ObjectMapping for {0} not found", tmp.CompositeUID); continue; } //enrich tmp.SubGPKName = fileName; tmp.UID = store.ObjectMapperList[tmp.CompositeUID]; if (!store.CompositeMap.ContainsKey(fileName)) { store.CompositeMap.Add(fileName, new List <CompositeMapEntry>()); } store.CompositeMap[fileName].Add(tmp); var unk = split[4]; if (unk != "") { logger.Warn("unk not empty!!!!!!! " + unk); } } } } catch (Exception ex) { logger.Info("Loading of mappings failed"); logger.Error(ex); } }
public void SetStore(GpkStore store) { this.store = store; OnDrawNodes(); }