Ejemplo n.º 1
0
        private bool DeserializeImports()
        {
            for (int n = 0; n < _importCount; n++)
            {
                var import = new ImportTableEntry(this,
                                                  Data.GetReader(_importOffset + (UInt32)(n * ImportTableEntry.SizeInBytes),
                                                                 ImportTableEntry.SizeInBytes));

                if (!import.Deserialize())
                {
                    return(false);
                }

                Imports.Add(import);
                if (!ImportPackageNames.Contains(import.SourcePCCName))
                {
                    ImportPackageNames.Add(import.SourcePCCName);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool DeserializeImports()
        {
            for (int n = 0; n < _importCount; n++)
            {
                var import = new ImportTableEntry(this,
                    Data.GetReader(_importOffset + (UInt32)(n * ImportTableEntry.SizeInBytes),
                    ImportTableEntry.SizeInBytes));

                if (!import.Deserialize())
                    return false;

                Imports.Add(import);
                if (!ImportPackageNames.Contains(import.SourcePCCName))
                    ImportPackageNames.Add(import.SourcePCCName);
            }

            return true;
        }
Ejemplo n.º 3
0
        public static ExportTableEntry GetExportFromImport(ImportTableEntry entry)
        {
            if (entry.ClassName == "Package")
            {
                return(new ExportTableEntry(null, null));
                // TODO: this imports the whole package?
            }

            var OuterTree = entry.GetOuterTreeString().Split(new char[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries);

            if (OuterTree[0] == entry.CurrentPCC.Name ||
                _NativeOnlyPackages.Contains(OuterTree[0]) ||
                _CoreObjectTypes.Contains(entry.ObjectName))
            {
                if (entry.ClassName == "Class")
                {
                    // Quick hack until all classes are mapped
                    var nativeClass = new ExportTableEntry(null, null);
                    nativeClass.ObjectName  = entry.ObjectName;
                    nativeClass.OuterName   = "object";
                    nativeClass.ClassName   = "Class";
                    nativeClass.Object      = new NativeME3Class(entry.ObjectName);
                    nativeClass.FullyNative = true;
                    return(nativeClass);
                }

                // Quick hack until all objects are mapped
                var native = new ExportTableEntry(null, null);
                native.ObjectName  = entry.ObjectName;
                native.OuterName   = "object";
                native.ClassName   = "Class";
                native.Object      = new NativeME3Class(entry.ObjectName);
                native.FullyNative = true;
                return(native);
                //Console.WriteLine(entry.SourcePCCName + " to " + entry.CurrentPCC.Name + " | " + entry.ClassName + " | " + entry.GetOuterTreeString() + "." + entry.ObjectName);
                // TODO: this means its a fully native object, we should create those for all types required by ME3.
            }

            if (entry.SourcePCCName != OuterTree[0])
            {
                var realPCC = entry.CurrentPCC.ImportPackages.FirstOrDefault(x => x.Name == OuterTree[0]);
                if (realPCC == null)
                {
                    return(null); // Error, missing import?
                }
                entry.SourcePCC = realPCC;
            }

            var objects = entry.SourcePCC.Exports.Where(x => // TODO: can probably be much quicker, perhaps by outer tree traversal?
                                                        String.Equals(x.ObjectName, entry.ObjectName, StringComparison.OrdinalIgnoreCase) &&
                                                        String.Equals(x.ClassName, entry.ClassName, StringComparison.OrdinalIgnoreCase));

            if (objects.Count() > 1)
            {
                if (OuterTree.Length == 2)
                {
                    objects = objects.Where(x => String.Equals(x.GetOuterTreeString(), OuterTree[1], StringComparison.OrdinalIgnoreCase));
                }
                else
                {
                    objects = objects.Where(x => x.GetOuterTreeString() == String.Empty); // should not happen?
                }
            }
            if (objects.Count() != 1)
            {
                return(null); // This should not happen unless we have a faulty import.
            }
            return(objects.First());
        }
Ejemplo n.º 4
0
        public static ExportTableEntry GetExportFromImport(ImportTableEntry entry)
        {
            if (entry.ClassName == "Package")
            {
                return new ExportTableEntry(null, null);
                // TODO: this imports the whole package?
            }

            var OuterTree = entry.GetOuterTreeString().Split(new char[] {'.'}, 2, StringSplitOptions.RemoveEmptyEntries);
            if (OuterTree[0] == entry.CurrentPCC.Name
                || _NativeOnlyPackages.Contains(OuterTree[0])
                || _CoreObjectTypes.Contains(entry.ObjectName))
            {
                if (entry.ClassName == "Class")
                {
                    // Quick hack until all classes are mapped
                    var nativeClass = new ExportTableEntry(null, null);
                    nativeClass.ObjectName = entry.ObjectName;
                    nativeClass.OuterName = "object";
                    nativeClass.ClassName = "Class";
                    nativeClass.Object = new NativeME3Class(entry.ObjectName);
                    nativeClass.FullyNative = true;
                    return nativeClass;
                }

                // Quick hack until all objects are mapped
                var native = new ExportTableEntry(null, null);
                native.ObjectName = entry.ObjectName;
                native.OuterName = "object";
                native.ClassName = "Class";
                native.Object = new NativeME3Class(entry.ObjectName);
                native.FullyNative = true;
                return native;
                //Console.WriteLine(entry.SourcePCCName + " to " + entry.CurrentPCC.Name + " | " + entry.ClassName + " | " + entry.GetOuterTreeString() + "." + entry.ObjectName);
                // TODO: this means its a fully native object, we should create those for all types required by ME3.
            }

            if (entry.SourcePCCName != OuterTree[0])
            {
                var realPCC = entry.CurrentPCC.ImportPackages.FirstOrDefault(x => x.Name == OuterTree[0]);
                if (realPCC == null)
                    return null; // Error, missing import?

                entry.SourcePCC = realPCC;
            }

            var objects = entry.SourcePCC.Exports.Where(x => // TODO: can probably be much quicker, perhaps by outer tree traversal?
                String.Equals(x.ObjectName, entry.ObjectName, StringComparison.OrdinalIgnoreCase) &&
                String.Equals(x.ClassName, entry.ClassName, StringComparison.OrdinalIgnoreCase));
            if (objects.Count() > 1)
            {
                if (OuterTree.Length == 2)
                {
                    objects = objects.Where(x => String.Equals(x.GetOuterTreeString(), OuterTree[1], StringComparison.OrdinalIgnoreCase));
                }
                else
                {
                    objects = objects.Where(x => x.GetOuterTreeString() == String.Empty); // should not happen?
                }
            }
            if (objects.Count() != 1)
            {
                return null; // This should not happen unless we have a faulty import.
            }
            return objects.First();
        }