private void CheckFile(string file, out ulong path, out ulong language, out ulong extension) { language = 0; path = 0; extension = 0; string[] pieces = file.Split('.'); if (pieces.Length == 3) { path = Hash64.HashString(pieces[0]); extension = Hash64.HashString(pieces[2]); language = ulong.Parse(pieces[1]); } else if (pieces.Length == 2) { path = Hash64.HashString(pieces[0]); extension = Hash64.HashString(pieces[1]); } else { this.Error( "Filename did not appear to be valid. It must be either path/to/file.ext or path/to/file.language.ext in format."); } if (index.Entry2Id(path, extension, 0).Count == 0) { this.Error("Could not find the file in the file index. Please check the spelling and that you used / and not \\."); } }
public Material(uint sec_id, string mat_name) { id = sec_id; size = 0U; hashname = Hash64.HashString(mat_name, 0UL); skipped = new byte[48]; count = 0U; }
internal static async Task SearchForCubelights(Dictionary <uint, FileEntry> fileEntries, string outPath, IProgress <ProgressRecord> progress, CancellationToken ct) { var s = new System.Diagnostics.Stopwatch(); s.Start(); progress.Report(new ProgressRecord("Looking for worlds", 0, 0)); var levels = fileEntries.Values .Where(fe => fe.PathIds.HasUnHashed) .Where(fe => fe.ExtensionIds.ToString() == "world") .Select(fe => fe.Parent.EntryPath) .ToList(); var files = ImmutableHashSet.CreateRange(fileEntries.Select(i => i.Value.PathIds.Hashed)); var interestingPaths = new ConcurrentBag <string>(); var total = levels.Count; var completed = 0; var progressReporter = Task.Run(async() => { while (completed < total && !ct.IsCancellationRequested) { await Task.Delay(100); progress.Report(new ProgressRecord("Checking cubelight names", total, completed)); } }); var opts = new ParallelOptions(); opts.CancellationToken = ct; Parallel.ForEach(levels, levelname => { for (var i = 1000; i <= 1000000; i++) { var path = $"{levelname}/cube_lights/{i}"; var hsh = Hash64.HashString(path); if (files.Contains(hsh)) { interestingPaths.Add(path); } } var domeocc = $"{levelname}/cube_lights/dome_occlusion"; if (files.Contains(Hash64.HashString(domeocc))) { interestingPaths.Add(domeocc); } Interlocked.Increment(ref completed); }); File.WriteAllLines(outPath, interestingPaths, new UTF8Encoding()); completed = total; s.Stop(); Console.WriteLine("Bruteforced {1} combinations in {0} ms", s.ElapsedMilliseconds, total * 999000); await progressReporter; }
internal static async Task SearchForStreams(Dictionary <uint, FileEntry> fileEntries, string outPath, IProgress <ProgressRecord> progress, CancellationToken ct) { var s = new System.Diagnostics.Stopwatch(); s.Start(); progress.Report(new ProgressRecord("Loading bank/stream names", 0, 0)); var pendingBankfile = File.ReadAllLinesAsync("Data/banknames", ct); var pendingStreamfile = File.ReadAllLinesAsync("Data/streamnames", ct); // It's immutable. Very threadsafe. var files = ImmutableHashSet.CreateRange(fileEntries.Select(i => i.Value.PathIds.Hashed)); var interestingBanks = (await pendingBankfile) .Where(i => files.Contains(Hash64.HashString(i))) .Select(i => i.Split("/").Last()) .ToList(); var streamNames = await pendingStreamfile; var interestingPaths = new ConcurrentBag <string>(); int completed = 0; int total = streamNames.Length; var progressReporter = Task.Run(async() => { while (completed < total && !ct.IsCancellationRequested) { await Task.Delay(100); progress.Report(new ProgressRecord("Checking stream names", total, completed)); } }); var opts = new ParallelOptions(); opts.CancellationToken = ct; Parallel.ForEach(streamNames, opts, (s) => { for (var i = 0; i < interestingBanks.Count; i++) { var path = $"soundbanks/streamed/{interestingBanks[i]}/{s}"; var hsh = Hash64.HashString(path); if (files.Contains(hsh)) { interestingPaths.Add(path); } } Interlocked.Increment(ref completed); }); File.WriteAllLines(outPath, interestingPaths, new UTF8Encoding()); completed = total; s.Stop(); Console.WriteLine("Bruteforced {1} combinations in {0} ms", s.ElapsedMilliseconds, total * interestingBanks.Count); }
public Topology(uint sec_id, obj_data obj) { id = sec_id; size = 0U; unknown1 = 0U; count1 = (uint)(obj.faces.Count / 3); facelist = obj.faces; count2 = 0U; items2 = new byte[0]; hashname = Hash64.HashString(obj.object_name + ".Topology", 0UL); }
public Object3D(string object_name, uint parent) { id = 0U; size = 0U; hashname = Hash64.HashString(object_name, 0UL); count = 0U; items = new List <Vector3D>(); rotation = new Matrix3D(1f, 0.0f, 0.0f, 0.0f, 0.0f, 1f, 0.0f, 0.0f, 0.0f, 0.0f, 1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); position = new Vector3D(0.0f, 0.0f, 0.0f); parentID = parent; }
public Geometry(uint sec_id, obj_data newobject) { this.id = sec_id; this.size = 0U; this.vert_count = (uint)newobject.verts.Count; this.header_count = 5U; this.headers.Add(new GeometryHeader(3U, 1U)); this.headers.Add(new GeometryHeader(2U, 7U)); this.headers.Add(new GeometryHeader(3U, 2U)); this.headers.Add(new GeometryHeader(3U, 20U)); this.headers.Add(new GeometryHeader(3U, 21U)); this.verts = newobject.verts; this.uvs = newobject.uv; this.normals = newobject.normals; this.hashname = Hash64.HashString(newobject.object_name + ".Geometry", 0UL); }
/// <summary> /// The load local mods. /// </summary> /// public void LoadMods(bool overrride = false) { var watch = Stopwatch.StartNew(); if (Directory.Exists(modsDirectory)) { watch.Restart(); if (overrride) this._modsList.Clear(); List<string> leftovers = this.modsList.Keys.ToList(); string[] pdmods = Directory.GetFiles(modsDirectory, "*.pdmod"); //System.Threading.Tasks.Parallel.ForEach(pdmods, file => foreach (string file in pdmods) { if (!File.Exists(file)) return;//continue; if (LoadSingleMod(file)) { leftovers.Remove(file); } }//); watch.Stop(); Console.WriteLine("LoadLocalMods.pdmods - " + watch.ElapsedMilliseconds + " ms"); watch.Restart(); foreach (string left in leftovers) RemoveModsList(left); watch.Stop(); Console.WriteLine("LoadLocalMods.pdmods.leftovers - " + watch.ElapsedMilliseconds + " ms"); } else { if (this.CanCreateDirectory(modsDirectory)) { Directory.CreateDirectory(modsDirectory); } } watch.Restart(); //load in override folder if (Directory.Exists(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides"))) { List<BundleMod> mod_overrides_mods = new List<BundleMod>(); string[] mod_overrides = Directory.EnumerateDirectories(Path.Combine(StaticStorage.settings.AssetsFolder, "mod_overrides")).ToArray(); foreach (string mo in mod_overrides) { if (!Directory.Exists(mo)) continue;//continue; if (new DirectoryInfo(mo).Name == "Bundle_Modder_Shared") continue;//continue; string[] allfiles = System.IO.Directory.GetFiles(mo, "*.*", System.IO.SearchOption.AllDirectories); BundleMod mo_mod = new BundleMod(); mo_mod.Name = new DirectoryInfo(mo).Name; mo_mod.Author = "<UNKNOWN>"; mo_mod.Description = "This mod is installed in \"mod_overrides\" folder. No description for this mod is availiable. This mod was not matched with any local mods. You can only uninstall this mod."; mo_mod.file = mo; mo_mod.status = BundleMod.ModStatus.Unrecognized; mo_mod.type = BundleMod.ModType.mod_override; mo_mod.actionStatus = BundleMod.ModActionStatus.Missing; mo_mod.UtilizesOverride = true; if (File.Exists(Path.Combine(mo, "mod.txt"))) { try { OverrideMod overrideModInformation = OverrideMod.Deserialize(File.ReadAllText(Path.Combine(mo, "mod.txt"))); if(!String.IsNullOrWhiteSpace(overrideModInformation.Name)) mo_mod.Name = overrideModInformation.Name; if(!String.IsNullOrWhiteSpace(overrideModInformation.Author)) mo_mod.Author = overrideModInformation.Author; if (!String.IsNullOrWhiteSpace(overrideModInformation.Description)) mo_mod.Description = overrideModInformation.Description; mo_mod.status = BundleMod.ModStatus.Installed; mo_mod.actionStatus = BundleMod.ModActionStatus.None; } catch(Exception exc) { } } foreach (string mo_entry in allfiles) { if (mo_entry.EndsWith("mod.txt")) continue; BundleRewriteItem mo_bri = new BundleRewriteItem(); string filepath = mo_entry.Substring(mo.Length + 1).Replace('\\', '/'); string[] pathelements = filepath.Split('.'); if (pathelements.Length > 3) continue; string entrypath = pathelements[0]; if (pathelements.Length == 2) { mo_bri.BundlePath = Hash64.HashString(pathelements[0]); mo_bri.BundleExtension = Hash64.HashString(pathelements[1]); } else if (pathelements.Length == 3) { mo_bri.BundlePath = Hash64.HashString(pathelements[0]); UInt32 lang = 0; if (UInt32.TryParse(pathelements[1], out lang)) mo_bri.BundleLanguage = lang; mo_bri.BundleExtension = Hash64.HashString(pathelements[2]); mo_bri.IsLanguageSpecific = true; } else continue; mo_bri.ModName = mo_mod.Name; mo_bri.ModAuthor = mo_mod.Author; mo_bri.ModDescription = mo_mod.Description; mo_bri.ReplacementFile = ""; if (mo_bri.isOverrideable() //&& !bri.ReplacementFile.EndsWith(".script") ) { if (string.IsNullOrEmpty(HashIndex.GetUnhashed(mo_bri.BundlePath)) || string.IsNullOrEmpty(HashIndex.GetUnhashed(mo_bri.BundleExtension)) ) { continue; } } mo_mod.ItemQueue.Add(mo_bri); } mod_overrides_mods.Add(mo_mod); } //check vs others Dictionary<string, BundleMod> temporarylocalModsList_master = this.modsList; foreach (BundleMod mo_bm in mod_overrides_mods) { bool modMatch = false; List<BundleMod> matched_mods = temporarylocalModsList_master.Values.Where(mod => mod.getEscapedName().Equals(mo_bm.Name) || mod.Name.Equals(mo_bm.Name)).ToList(); foreach (BundleMod bm in matched_mods) { modMatch = true; if (mo_bm.ItemQueue.Count > bm.ItemQueue.Count) //the override mod contains too many files, not equal { mo_bm.canInstall = false; mo_bm.canUninstall = true; mo_bm.actionStatus = BundleMod.ModActionStatus.Missing; mo_bm.status = BundleMod.ModStatus.Unrecognized; AddModsList(mo_bm.file, mo_bm); } else { bool[] mo_checklist = new bool[mo_bm.ItemQueue.Count]; int checklist_i = 0; bool mo_onlyfolder = !(bm.ItemQueue.Any(x => !x.isOverrideable())); //isOverradable foreach (BundleRewriteItem mo_bri in mo_bm.ItemQueue) { if (bm.ItemQueue.Any(x => x.BundlePath == mo_bri.BundlePath && x.BundleExtension == mo_bri.BundleExtension)) mo_checklist[checklist_i] = true; checklist_i++; } bool mo_equal = !mo_checklist.Any(x => !x); /* for (checklist_i = 0; mo_equal && checklist_i < mo_bm.ItemQueue.Count; checklist_i++) if (!mo_checklist[checklist_i]) mo_equal = false; */ if (!mo_equal) { mo_bm.canInstall = false; mo_bm.canUninstall = true; mo_bm.actionStatus = BundleMod.ModActionStatus.Missing; mo_bm.status = BundleMod.ModStatus.Unrecognized; AddModsList(mo_bm.file, mo_bm); } else { if (mo_onlyfolder || InstalledModsListContains(bm) > -1) { bm.status = BundleMod.ModStatus.Installed;//installed } else { bm.actionStatus = BundleMod.ModActionStatus.ForcedReinstall; bm.status = BundleMod.ModStatus.ParticallyInstalled;//installed foreach (BundleRewriteItem bri in bm.ItemQueue) bri.toReinstall = true; } } } } if (!modMatch) { mo_bm.canInstall = false; mo_bm.canUninstall = true; AddModsList(mo_bm.file, mo_bm); } } } watch.Stop(); Console.WriteLine("LoadLocalMods.overrides - " + watch.ElapsedMilliseconds + " ms"); watch.Restart(); //BLT Mods if ( Directory.Exists( Path.Combine( StaticStorage.settings.AssetsFolder, "..", "mods") ) ) { if( Directory.Exists( Path.Combine( StaticStorage.settings.AssetsFolder, "..", "mods", "base") ) ) { List<string> bltmods = Directory.EnumerateDirectories(Path.Combine(StaticStorage.settings.AssetsFolder, "..", "mods")).ToList(); foreach (string bltmod in bltmods) { if (!Directory.Exists(bltmod)) continue; if (Path.GetFileNameWithoutExtension(bltmod).Equals("log") || Path.GetFileNameWithoutExtension(bltmod).Equals("base")) continue; if (!File.Exists(Path.Combine(bltmod, "mod.txt"))) continue; BundleMod blt_mod = new BundleMod(); blt_mod.Name = new DirectoryInfo(bltmod).Name; blt_mod.Author = "<UNKNOWN>"; blt_mod.Description = "This is a BLT Hook mod. No description for this mod is availiable. This mod doesn't have a proper description. You can enable/disable this mod as well as uninstall it."; blt_mod.file = bltmod; blt_mod.status = BundleMod.ModStatus.Installed; blt_mod.type = BundleMod.ModType.lua; blt_mod.actionStatus = BundleMod.ModActionStatus.None; blt_mod.UtilizesOverride = false; blt_mod.UtilizesBundles = false; blt_mod.enabled = true; try { FileStream bltModfs = new FileStream(Path.Combine(bltmod, "mod.txt"), FileMode.Open); using (StreamReader bltModsr = new StreamReader(bltModfs)) { try { //JsonConvert dynamic jsonDe = JsonConvert.DeserializeObject(bltModsr.ReadToEnd()); //dynamic jsonDe = null; if (jsonDe != null) { if (jsonDe.name != null) { blt_mod.Name = jsonDe.name; } if (jsonDe.author != null) { blt_mod.Author = jsonDe.author; } if (jsonDe.description != null) { blt_mod.Description = jsonDe.description; } } } catch (Exception exc) { blt_mod.Description += " Failed parsing mods.txt of " + Path.GetFileNameWithoutExtension(bltmod) + ", Message: " + exc.Message; } } } catch (Exception e) { blt_mod.Description += " Failed parsing mods.txt of " + Path.GetFileNameWithoutExtension(bltmod) + ", Message: " + e.Message; } AddModsList(bltmod, blt_mod, true); } } LoadBLTModManagement(); } watch.Stop(); Console.WriteLine("LoadLocalMods.blt_mods - " + watch.ElapsedMilliseconds + " ms"); }
public void writePackage(String name) { UInt64 hashed_name = Hash64.HashString(name); }
public static bool ImportNewObjPatternUV(FullModelData fm, string filepath) { Log.Default.Info("Importing new obj with file for UV patterns: {0}", filepath); //Preload the .obj List <obj_data> objects = new List <obj_data>(); try { using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read)) { using (StreamReader sr = new StreamReader(fs)) { string line; obj_data obj = new obj_data(); bool reading_faces = false; int prevMaxVerts = 0; int prevMaxUvs = 0; int prevMaxNorms = 0; while ((line = sr.ReadLine()) != null) { //preloading objects if (line.StartsWith("#")) { continue; } else if (line.StartsWith("o ") || line.StartsWith("g ")) { if (reading_faces) { reading_faces = false; prevMaxVerts += obj.verts.Count; prevMaxUvs += obj.uv.Count; prevMaxNorms += obj.normals.Count; objects.Add(obj); obj = new obj_data(); } obj.object_name = line.Substring(2); } else if (line.StartsWith("usemtl ")) { obj.material_name = line.Substring(2); } else if (line.StartsWith("v ")) { if (reading_faces) { reading_faces = false; prevMaxVerts += obj.verts.Count; prevMaxUvs += obj.uv.Count; prevMaxNorms += obj.normals.Count; objects.Add(obj); obj = new obj_data(); } String[] verts = line.Replace(" ", " ").Split(' '); Vector3 vert = new Vector3(); vert.X = Convert.ToSingle(verts[1], CultureInfo.InvariantCulture); vert.Y = Convert.ToSingle(verts[2], CultureInfo.InvariantCulture); vert.Z = Convert.ToSingle(verts[3], CultureInfo.InvariantCulture); obj.verts.Add(vert); } else if (line.StartsWith("vt ")) { if (reading_faces) { reading_faces = false; prevMaxVerts += obj.verts.Count; prevMaxUvs += obj.uv.Count; prevMaxNorms += obj.normals.Count; objects.Add(obj); obj = new obj_data(); } String[] uvs = line.Split(' '); Vector2 uv = new Vector2(); uv.X = Convert.ToSingle(uvs[1], CultureInfo.InvariantCulture); uv.Y = Convert.ToSingle(uvs[2], CultureInfo.InvariantCulture); obj.uv.Add(uv); } else if (line.StartsWith("vn ")) { if (reading_faces) { reading_faces = false; prevMaxVerts += obj.verts.Count; prevMaxUvs += obj.uv.Count; prevMaxNorms += obj.normals.Count; objects.Add(obj); obj = new obj_data(); } String[] norms = line.Split(' '); Vector3 norm = new Vector3(); norm.X = Convert.ToSingle(norms[1], CultureInfo.InvariantCulture); norm.Y = Convert.ToSingle(norms[2], CultureInfo.InvariantCulture); norm.Z = Convert.ToSingle(norms[3], CultureInfo.InvariantCulture); obj.normals.Add(norm); } else if (line.StartsWith("f ")) { reading_faces = true; String[] faces = line.Substring(2).Split(' '); for (int x = 0; x < 3; x++) { ushort fa = 0, fb = 0, fc = 0; if (obj.verts.Count > 0) { fa = (ushort)(Convert.ToUInt16(faces[x].Split('/')[0]) - prevMaxVerts - 1); } if (obj.uv.Count > 0) { fb = (ushort)(Convert.ToUInt16(faces[x].Split('/')[1]) - prevMaxUvs - 1); } if (obj.normals.Count > 0) { fc = (ushort)(Convert.ToUInt16(faces[x].Split('/')[2]) - prevMaxNorms - 1); } if (fa < 0 || fb < 0 || fc < 0) { throw new Exception("What the actual flapjack, something is *VERY* wrong"); } obj.faces.Add(new Face(fa, fb, fc)); } } } if (!objects.Contains(obj)) { objects.Add(obj); } } } //Read each object foreach (obj_data obj in objects) { //Locate the proper model uint modelSectionid = 0; foreach (KeyValuePair <uint, ISection> pair in fm.parsed_sections) { if (modelSectionid != 0) { break; } if (pair.Value is Model) { UInt64 tryp; if (UInt64.TryParse(obj.object_name, out tryp)) { if (tryp == ((Model)pair.Value).HashName.Hash) { modelSectionid = pair.Key; } } else { if (Hash64.HashString(obj.object_name) == ((Model)pair.Value).HashName.Hash) { modelSectionid = pair.Key; } } } } //Apply new changes if (modelSectionid == 0) { continue; } Model model_data_section = (Model)fm.parsed_sections[modelSectionid]; PassthroughGP passthrough_section = model_data_section.PassthroughGP; Geometry geometry_section = passthrough_section.Geometry; Topology topology_section = passthrough_section.Topology; //Arrange UV and Normals Vector2[] new_arranged_UV = new Vector2[geometry_section.verts.Count]; for (int x = 0; x < new_arranged_UV.Length; x++) { new_arranged_UV[x] = new Vector2(100f, 100f); } Vector2 sentinel = new Vector2(100f, 100f); if (topology_section.facelist.Count != obj.faces.Count / 3) { return(false); } for (int fcount = 0; fcount < topology_section.facelist.Count; fcount += 3) { Face f1 = obj.faces[fcount + 0]; Face f2 = obj.faces[fcount + 1]; Face f3 = obj.faces[fcount + 2]; //UV if (obj.uv.Count > 0) { if (new_arranged_UV[topology_section.facelist[fcount / 3 + 0].a].Equals(sentinel)) { new_arranged_UV[topology_section.facelist[fcount / 3 + 0].a] = obj.uv[f1.b]; } if (new_arranged_UV[topology_section.facelist[fcount / 3 + 0].b].Equals(sentinel)) { new_arranged_UV[topology_section.facelist[fcount / 3 + 0].b] = obj.uv[f2.b]; } if (new_arranged_UV[topology_section.facelist[fcount / 3 + 0].c].Equals(sentinel)) { new_arranged_UV[topology_section.facelist[fcount / 3 + 0].c] = obj.uv[f3.b]; } } } geometry_section.UVs[1] = new_arranged_UV.ToList(); passthrough_section.Geometry.UVs[1] = new_arranged_UV.ToList(); } } catch (Exception exc) { System.Windows.Forms.MessageBox.Show(exc.ToString()); return(false); } return(true); }