public string TryDetectCI(string packageName) { try { using (var pkg = UnrealLoader.LoadFullPackage(Path.Combine(GetContentDir(), packageName + ".upk"), FileAccess.Read)) { foreach (var obj in pkg.Objects) { if (obj.Class.Name == "Hat_ChapterInfo") { if (obj.Outer == null) { return($"{obj.Package.PackageName}.{obj.Name}"); } else { return($"{obj.Package.PackageName}.{obj.Outer.Name}.{obj.Name}"); } } } } } catch (Exception e) { Debug.WriteLine(e.Message + Environment.NewLine + e.ToString()); } return(null); }
/// <summary> /// Loads the package that this object instance resides in. /// /// Note: The package closes when the Owner is done with importing objects data. /// </summary> protected UnrealPackage LoadImportPackage() { UnrealPackage pkg = null; try { var outer = Outer; while (outer != null) { if (outer.Outer == null) { pkg = UnrealLoader.LoadCachedPackage(Path.GetDirectoryName(Package.FullPackageName) + "\\" + outer.Name + ".u"); break; } outer = outer.Outer; } } catch (IOException) { if (pkg != null) { pkg.Dispose(); } return(null); } return(pkg); }
static UPackage_Info LoadInfo_fromFile(string file_path) { var pkg = UnrealLoader.LoadFullPackage(file_path); var _R = new UPackage_Info(); var imp = new List <UPortedItem_Info>(); foreach (var v in pkg.Imports) { UPortedItem_Info upi; if (Get_UPIInfo(v.ClassName, v.OuterName, v.ObjectName, out upi, _R)) { imp.Add(upi); } } var exp = new List <UPortedItem_Info>(); foreach (var v in pkg.Exports) { UPortedItem_Info upi; if (Get_UPIInfo(v.ClassName, v.OuterName, v.ObjectName, out upi, _R)) { exp.Add(upi); } } _R.PackageName = Get_PkgName(file_path).ToLower(); _R.Imports = imp; _R.Exports = exp; return(_R); }
public UnrealPackage LoadPackage(string name) { foreach (KeyValuePair <string, List <string> > kvp in Files) { foreach (string f in kvp.Value) { if (Path.GetFileName(f).StartsWith(name)) { var package = _CachedPackages.Find(pkg => pkg.PackageName == Path.GetFileNameWithoutExtension(f)); if (package != null) { return(package); } if (IsLineage(f)) { package = UnrealLoader.LoadPackage(f, new LineageDecoder(), FileAccess.Read); } else { package = UnrealLoader.LoadPackage(f, FileAccess.Read); } PreInit(package); _CachedPackages.Add(package); return(package); } } } return(null); }
private static void PreloadBasicPackages(string baseFolder) { var basicPackageNames = new List <string>() { "Core.upk", "Engine.upk", "ProjectX.upk", "AkAudio.upk", "TAGame.upk" }; foreach (var packageName in basicPackageNames) { try { Console.WriteLine($"Preloading {packageName}"); string packagePath = Path.Combine(baseFolder, packageName); UnrealLoader.LoadFullPackage(packagePath, System.IO.FileAccess.Read); } catch (FileNotFoundException e) { Console.WriteLine( $"Did not find {packageName} in the current directory." + "This is optional, but recommended. " + "Preloading this package improves type recognition."); } } }
private static void ProcessPackage(string pathToPackages, string file, Options options) { var packagePath = Path.Combine(pathToPackages, file); var package = UnrealLoader.LoadFullPackage(packagePath, System.IO.FileAccess.Read); var packageName = Path.GetFileNameWithoutExtension(packagePath); var outputMainFolder = Path.Combine("Extracted", packageName); //Init the asset extractor Log.DeserializationErrors = 0; assetExtractor = new AssetExtractor(package); Console.WriteLine($"Processing: {file}"); if (options.ExtractClasses) { assetExtractor.ExportClasses(outputMainFolder); } if (options.ExtractData) { assetExtractor.ExportData(outputMainFolder); } if (options.ExtractMeshInfo) { assetExtractor.ExportMeshObjects(outputMainFolder); } assetExtractor.ExportDummyAssets(outputMainFolder); string deserializationErrors = $"Total deserialization errors: {Log.DeserializationErrors}"; Log.Debug(deserializationErrors); Console.WriteLine(deserializationErrors); }
public void LoadMapPackage_DecompileObjects_ShouldBeValidJson(string mapPath, string objectTypeName) { var package = UnrealLoader.LoadFullPackage(mapPath); for (var i = 0; i < package.Objects.Count; i++) { var obj = package.Objects[i]; // obj.Name.Length > objectTypeName.Length is to include only instances, not bare class types if (!obj.Name.StartsWith(objectTypeName) && obj.Name.Length > objectTypeName.Length) { continue; } try { var json = obj.Decompile(); TestContext.Out.Write(json); Assert.False(string.IsNullOrEmpty(json)); Assert.IsTrue(JsonConvert.DeserializeObject(json) != null); } catch (Exception e) { // catch for a breakpoint Console.WriteLine(e); } } }
private void BgWorkerPackageGen_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { btnGenerate.Text = "Generating ..."; splitContainer1.Panel1.Enabled = false; if (!File.Exists(filePath)) { return; } var fileName = Path.GetFileNameWithoutExtension(filePath); if (fileName == null) { return; } Console.Write("Loading package ... "); var package = UnrealLoader.LoadFullPackage(filePath, FileAccess.Read); Console.WriteLine("Done."); var finalString = "Begin Map\r\n" + "\tBegin Level\r\n"; foreach (var obj in package.Objects) { if (obj.ExportTable == null || obj.Name == "None") { continue; } if (lstBoxTypesToGenerate.SelectedItems.Count == 0 || lstBoxTypesToGenerate.SelectedItems.Contains(obj.NameTable.Name)) { //if (obj.NameTable.Name == "StaticMeshActor_SMC") // Only use one NameTable during my tests until they're all implemented //if (obj.Name == "StaticMeshActor_SMC_39") //{ var nameTable = NameTableFactory.GetNameTable(obj, fileName, chckBoxInvisitek.Checked, chckBoxLayers.Checked); if (nameTable != null) { finalString += nameTable.ProcessString(); } //} } continue; } finalString += "\tEnd Level\r\n" + "\tBegin Surface\r\n" + "\tEnd Surface\r\n" + "End Map"; generatedText = finalString; }
private void AnalyzePotraits(string path) { var package = UnrealLoader.LoadFullPackage(path); foreach (var content in package.Objects) { Console.WriteLine("Name: {0}, Class: {1}, Outer: {2}", content.Name, content.Class.Name, content.Outer == null ? "null" : content.Outer.Name); } }
private UProperty FindProperty(out UStruct outer) { //If the object is from the import table. Try to find the export object in the package it originates from. UStruct GetRealObject(UObject _object) { if (_object.ExportTable == null) { var realClass = UnrealLoader.FindClassInCache(_object.Name); //var realClass = UnrealLoader.FindClassInPackage(_object.Outer.Name, _object.Name); return(realClass); } return(_object as UStruct); } UProperty property = null; outer = _Outer ?? _Container.Class as UStruct; //outer = GetRealObject(outer); for (var structField = outer; structField != null; structField = structField.Super as UStruct) { structField = GetRealObject(structField); if (structField.Variables == null || !structField.Variables.Any()) { continue; } property = structField.Variables.Find(i => i.Name == Name); if (property == null) { continue; } switch (property.Type) { case PropertyType.StructProperty: outer = ((UStructProperty)property).StructObject; break; case PropertyType.ArrayProperty: var arrayField = property as UArrayProperty; Debug.Assert(arrayField != null, "arrayField != null"); var arrayInnerField = arrayField.InnerProperty; if (arrayInnerField.Type == PropertyType.StructProperty) { _Outer = ((UStructProperty)arrayInnerField).StructObject; } break; default: outer = structField; break; } break; } return(property); }
public void LoadPackageTest() { string testPackagePath = Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "upk", "TestUC2", "TestUC2.u"); var package = UnrealLoader.LoadPackage(testPackagePath); Assert.IsNotNull(package); // FIXME: UELib is dependent on WinForms //package.InitializePackage(); //var testClass = package.FindObject("Test", typeof(UClass)); //Assert.IsNotNull(testClass); //string testClassContent = testClass.Decompile(); //Assert.AreNotSame("", testClassContent); }
private void mButton1_Click(object sender, EventArgs e) { // SoundCue'HatinTime_Voice_SubconNoose.SoundCues.01_why_hello_there' var pattern = new Regex(@"([A-Za-z0-9]{1,255})\'([A-Za-z_0-9\.]{1,255})\'$"); var match = pattern.Matches(mTextBox1.Text); if (match.Count != 1 || match[0].Groups.Count != 3) { GUI.MessageBox.Show(this, "Invalid input!"); } try { var type = match[0].Groups[1].Value; var objName = match[0].Groups[2].Value; var spl = objName.Split('.'); var package = spl[0]; var parserType = (UModelFacade.ExportType)Enum.Parse(typeof(UModelFacade.ExportType), type); var pkg = Utils.FindPackage(package); var loader = UnrealLoader.LoadFullPackage(pkg, System.IO.FileAccess.Read); if (loader != null) { foreach (var o in loader.Objects) { if (o.Name.Equals(spl.Last(), StringComparison.InvariantCultureIgnoreCase) && o.Class.Name.Equals(type, StringComparison.InvariantCultureIgnoreCase)) { if (spl.Count() == 3) { if (!o.Outer.Name.Equals(spl[1], StringComparison.InvariantCultureIgnoreCase)) { Debug.WriteLine(o.Outer.Name + " >> Outer invalid"); continue; } } SaveFileDialog dlg = new SaveFileDialog(); var ext = UModelFacade.GetExtensionForType(parserType); if (ext == null) { GUI.MessageBox.Show(this, "Unsupported type: " + parserType); return; } dlg.DefaultExt = ext.TrimStart('.'); dlg.FileName = objName; dlg.Filter = $"{parserType} (*{ext})|*{ext}"; if (dlg.ShowDialog() == DialogResult.OK) { var facade = new UModelFacade(); var result = facade.Export(package, spl.Last(), parserType, dlg.FileName); GUI.MessageBox.Show(this, result ? "File exported sucessfully!" : "Export failed!"); } return; } } } GUI.MessageBox.Show(this, "Asset not found!"); } catch (Exception ex) { GUI.MessageBox.Show(ex.Message + "\n\n" + ex); } }
static void Init() { UnrealLoader window = (UnrealLoader)EditorWindow.GetWindow(typeof(UnrealLoader)); window.Show(); }
public void LoadDecryptedPackage() { //Just testing for no unhandled exceptions string testPackage = "TestData\\AkAudio_decrypted.upk"; var package = UnrealLoader.LoadFullPackage(testPackage, System.IO.FileAccess.Read); }