public static PropertyCollection getDefaultStructValue(string className, bool stripTransients) { bool isImmutable = UnrealObjectInfo.IsImmutable(className, Mod.MEGame.ME2); if (Structs.ContainsKey(className)) { ClassInfo info = Structs[className]; try { PropertyCollection structProps = new PropertyCollection(); ClassInfo tempInfo = info; while (tempInfo != null) { foreach ((string propName, PropertyInfo propInfo) in tempInfo.properties) { if (stripTransients && propInfo.Transient) { continue; } if (getDefaultProperty(propName, propInfo, stripTransients, isImmutable) is UProperty uProp) { structProps.Add(uProp); } } if (!Structs.TryGetValue(tempInfo.baseClass, out tempInfo)) { tempInfo = null; } } structProps.Add(new NoneProperty()); string filepath = Path.Combine(ME2Directory.gamePath, "BioGame", info.pccPath); if (File.Exists(info.pccPath)) { filepath = info.pccPath; //Used for dynamic lookup } if (File.Exists(filepath)) { IMEPackage importPCC = MEPackageHandler.OpenMEPackage(filepath); var exportToRead = importPCC.getUExport(info.exportIndex); byte[] buff = exportToRead.Data.Skip(0x30).ToArray(); PropertyCollection defaults = PropertyCollection.ReadProps(exportToRead, new MemoryStream(buff), className); foreach (var prop in defaults) { structProps.TryReplaceProp(prop); } } return(structProps); } catch { return(null); } } return(null); }
public static PropertyCollection getDefaultStructValue(string className) { if (Structs.ContainsKey(className)) { bool immutable = isImmutable(className); ClassInfo info = Structs[className]; try { string filepath = (Path.Combine(ME3Directory.gamePath, @"BIOGame\" + info.pccPath)); if (File.Exists(info.pccPath)) { filepath = info.pccPath; //Used for dynamic lookup } using (ME3Package importPCC = MEPackageHandler.OpenME3Package(filepath)) { byte[] buff; //Plane and CoverReference inherit from other structs, meaning they don't have default values (who knows why) //thus, I have hardcoded what those default values should be if (className == "Plane") { buff = PlaneDefault; } else if (className == "CoverReference") { buff = CoverReferenceDefault; } else { buff = importPCC.Exports[info.exportIndex].Data.Skip(0x24).ToArray(); } PropertyCollection props = PropertyCollection.ReadProps(importPCC, new MemoryStream(buff), className); List <UProperty> toRemove = new List <UProperty>(); foreach (var prop in props) { //remove transient props if (!info.properties.ContainsKey(prop.Name) && info.baseClass == "Class") { toRemove.Add(prop); } } foreach (var prop in toRemove) { props.Remove(prop); } return(props); } } catch { return(null); } } return(null); }