Ejemplo n.º 1
0
        public void Read(AssetReader reader)
        {
            if (IsReadBuildTargetString(reader.Version))
            {
                string buildTarget = reader.ReadStringAligned();
                BuildTarget = StringToBuildGroup(buildTarget);
            }
            else
            {
                BuildTarget = (BuildTargetGroup)reader.ReadInt32();
            }
            if (IsReadTier(reader.Version))
            {
                Tier = (GraphicsTier)reader.ReadInt32();
            }

            if (IsReadPlatfromSettings(reader.Version))
            {
                PlatformShaderSettings settings = reader.Read <PlatformShaderSettings>();
                Settings = new TierGraphicsSettingsEditor(settings, reader.Version, reader.Flags);
            }
            else
            {
                Settings.Read(reader);
            }

            Automatic = reader.ReadBoolean();
            reader.AlignStream(AlignType.Align4);
        }
Ejemplo n.º 2
0
        public override void Read(AssetReader reader)
        {
            base.Read(reader);

            int fileCount = reader.ReadInt32();

            FilenameEntry[] files = new FilenameEntry[fileCount];
            for (int i = 0; i < fileCount; i++)
            {
                int    fileId = reader.ReadInt32();
                string file   = reader.ReadString();
                files[i] = new FilenameEntry(fileId, file);
            }

            int unknown = reader.ReadInt32();

            int hashCount = reader.ReadInt32();

            HashEntry[] hashes = new HashEntry[hashCount];
            try
            {
                for (int i = 0; i < hashCount; i++)
                {
                    int    fileId    = reader.ReadInt32();
                    byte[] hashBytes = reader.ReadBytes(16);

                    int trailer = reader.ReadInt32();
                    if (trailer != 0)
                    {
                        throw new InvalidDataException($"Expected trailer (0), got {trailer}");
                    }

                    hashes[i] = new HashEntry(fileId, hashBytes);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogType.Info, LogCategory.Import, $"Failed to read hashes from asset bundle manifest, hash-table is incomplete: {ex.GetType().Name} -> {ex.Message}");
                byte[] buffer = new byte[4096];
                while (reader.Read(buffer, 0, buffer.Length) != 0)
                {
                    //yeet the remaining bytes into nowhere
                }

                for (int i = 0; i < hashes.Length; i++)
                {
                    if (hashes[i] == null)
                    {
                        hashes[i] = new HashEntry(-1, new byte[0]);
                    }
                }
            }

            FileEntries = files;
            HashEntries = hashes;
        }
Ejemplo n.º 3
0
        public override void Read(AssetReader reader)
        {
            base.Read(reader);

            if (IsReadSubEmitters(reader.Version))
            {
                m_subEmitters = reader.ReadArray <SubEmitterData>();
            }
            else
            {
                List <SubEmitterData> subEmitters     = new List <SubEmitterData>();
                PPtr <ParticleSystem> subEmitterBirth = reader.Read <PPtr <ParticleSystem> >();
                if (!subEmitterBirth.IsNull)
                {
                    subEmitters.Add(new SubEmitterData(ParticleSystemSubEmitterType.Birth, subEmitterBirth));
                }
                if (IsReadSecond(reader.Version))
                {
                    PPtr <ParticleSystem> subEmitterBirth1 = reader.Read <PPtr <ParticleSystem> >();
                    if (!subEmitterBirth1.IsNull)
                    {
                        subEmitters.Add(new SubEmitterData(ParticleSystemSubEmitterType.Birth, subEmitterBirth1));
                    }
                }

                PPtr <ParticleSystem> subEmitterDeath = reader.Read <PPtr <ParticleSystem> >();
                if (!subEmitterDeath.IsNull)
                {
                    subEmitters.Add(new SubEmitterData(ParticleSystemSubEmitterType.Death, subEmitterDeath));
                }
                if (IsReadSecond(reader.Version))
                {
                    PPtr <ParticleSystem> subEmitterDeath1 = reader.Read <PPtr <ParticleSystem> >();
                    if (!subEmitterDeath1.IsNull)
                    {
                        subEmitters.Add(new SubEmitterData(ParticleSystemSubEmitterType.Death, subEmitterDeath1));
                    }
                }

                PPtr <ParticleSystem> subEmitterCollision = reader.Read <PPtr <ParticleSystem> >();
                if (!subEmitterCollision.IsNull)
                {
                    subEmitters.Add(new SubEmitterData(ParticleSystemSubEmitterType.Collision, subEmitterCollision));
                }
                if (IsReadSecond(reader.Version))
                {
                    PPtr <ParticleSystem> subEmitterCollision1 = reader.Read <PPtr <ParticleSystem> >();
                    if (!subEmitterCollision1.IsNull)
                    {
                        subEmitters.Add(new SubEmitterData(ParticleSystemSubEmitterType.Collision, subEmitterCollision1));
                    }
                }

                if (subEmitters.Count == 0)
                {
                    subEmitters.Add(new SubEmitterData(ParticleSystemSubEmitterType.Birth, default));
                }
                m_subEmitters = subEmitters.ToArray();
            }
        }
Ejemplo n.º 4
0
        public void Build(string manifestFile, string outputFolder)
        {
            IEnumerable <IAsset> unresolvedAssets = null;
            var assets = AssetReader.Read(manifestFile);

            if (assets?.Any() == true)
            {
                foreach (var asset in assets)
                {
                    _assetManager.Add(asset);
                    unresolvedAssets = _assetManager.EvaluateUnfulfilledComponents(asset);
                }
            }

            if (unresolvedAssets?.Any() == true)
            {
                foreach (var asset in unresolvedAssets)
                {
                    _logger.LogWarning($"Unable to resolve {asset.Type}");
                    var missingDependencyTypes = asset.Dependencies.Where(d =>
                                                                          string.IsNullOrEmpty(d.Key))
                                                 .Select(d => d.Type);
                    _logger.LogWarning($"Unresolved components: {string.Join(",", missingDependencyTypes)}");
                }
            }

            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            var sortedComponents = _assetManager.GetAllAssetsWithObjPath();
            var valueYamlFile    = Path.Combine(outputFolder, "values.yaml");

            if (File.Exists(valueYamlFile))
            {
                _logger.LogInformation(new FileInfo(valueYamlFile).FullName);

                File.Delete(valueYamlFile);
            }

            using (var writer = new StreamWriter(File.OpenWrite(valueYamlFile)))
            {
                foreach (var asset in sortedComponents)
                {
                    asset.WriteYaml(writer, _assetManager, _loggerFactory);
                }
            }
        }
Ejemplo n.º 5
0
        public override void Read(AssetReader reader)
        {
            base.Read(reader);

            if (IsReadEditorData(reader.Flags))
            {
                EditorData = reader.Read <SpriteAtlasEditorData>();
                MasterAtlas.Read(reader);
            }
            m_packedSprites            = reader.ReadArray <PPtr <Sprite> >();
            m_packedSpriteNamesToIndex = reader.ReadStringArray();
            if (IsReadRenderDataMap(reader.Flags))
            {
                m_renderDataMap.Read(reader);
            }
            Tag       = reader.ReadString();
            IsVariant = reader.ReadBoolean();
            reader.AlignStream(AlignType.Align4);
        }
        public override void Read(AssetReader reader)
        {
            base.Read(reader);

            if (IsReadStaticAreas(reader.Version))
            {
                m_areas = new NavMeshAreaData[32];
                for (int i = 0; i < 32; i++)
                {
                    m_areas[i] = reader.Read <NavMeshAreaData>();
                }
            }
            else
            {
                m_areas = reader.ReadArray <NavMeshAreaData>();
            }
            if (IsReadLastAgentTypeID(reader.Version))
            {
                LastAgentTypeID = reader.ReadInt32();
                m_settings      = reader.ReadArray <NavMeshBuildSettings>();
                m_settingNames  = reader.ReadStringArray();
            }
        }
Ejemplo n.º 7
0
        public override void Read(AssetReader reader)
        {
            if (IsSerialized(reader.Version))
            {
                ReadBase(reader);

                ParsedForm.Read(reader);

                m_platforms = reader.ReadEnum32Array((t) => (GPUPlatform)t);
                uint[] offsets             = reader.ReadUInt32Array();
                uint[] compressedLengths   = reader.ReadUInt32Array();
                uint[] decompressedLengths = reader.ReadUInt32Array();
                byte[] compressedBlob      = reader.ReadByteArray();
                reader.AlignStream(AlignType.Align4);

                m_subProgramBlobs = new ShaderSubProgramBlob[m_platforms.Length];
                using (MemoryStream memStream = new MemoryStream(compressedBlob))
                {
                    for (int i = 0; i < m_platforms.Length; i++)
                    {
                        uint offset             = offsets[i];
                        uint compressedLength   = compressedLengths[i];
                        uint decompressedLength = decompressedLengths[i];

                        memStream.Position = offset;
                        byte[] decompressedBuffer = new byte[decompressedLength];
                        using (Lz4DecodeStream lz4Stream = new Lz4DecodeStream(memStream, (int)compressedLength))
                        {
                            int read = lz4Stream.Read(decompressedBuffer, 0, decompressedBuffer.Length);
                            if (read != decompressedLength)
                            {
                                throw new Exception($"Can't properly decode shader blob. Read {read} but expected {decompressedLength}");
                            }
                        }

                        using (MemoryStream blobMem = new MemoryStream(decompressedBuffer))
                        {
                            using (AssetReader blobReader = new AssetReader(blobMem, reader.Version, reader.Platform, reader.Flags))
                            {
                                ShaderSubProgramBlob blob = new ShaderSubProgramBlob();
                                blob.Read(blobReader);
                                m_subProgramBlobs[i] = blob;
                            }
                        }
                    }
                }
            }
            else
            {
                base.Read(reader);

                if (IsEncoded(reader.Version))
                {
                    uint decompressedSize = reader.ReadUInt32();
                    int  comressedSize    = reader.ReadInt32();

                    byte[] subProgramBlob = new byte[comressedSize];
                    reader.Read(subProgramBlob, 0, comressedSize);
                    reader.AlignStream(AlignType.Align4);

                    if (comressedSize > 0 && decompressedSize > 0)
                    {
                        byte[] decompressedBuffer = new byte[decompressedSize];
                        using (MemoryStream memStream = new MemoryStream(subProgramBlob))
                        {
                            using (Lz4DecodeStream lz4Stream = new Lz4DecodeStream(memStream))
                            {
                                int read = lz4Stream.Read(decompressedBuffer, 0, decompressedBuffer.Length);
                                if (read != decompressedSize)
                                {
                                    throw new Exception($"Can't properly decode sub porgram blob. Read {read} but expected {decompressedSize}");
                                }
                            }
                        }

                        using (MemoryStream memStream = new MemoryStream(decompressedBuffer))
                        {
                            using (AssetReader blobReader = new AssetReader(memStream, reader.Version, reader.Platform, reader.Flags))
                            {
                                SubProgramBlob.Read(blobReader);
                            }
                        }
                    }
                }

                if (IsReadFallback(reader.Version))
                {
                    Fallback.Read(reader);
                }
                if (IsReadDefaultProperties(reader.Version))
                {
                    DefaultProperties.Read(reader);
                }
                if (IsReadStaticProperties(reader.Version))
                {
                    StaticProperties.Read(reader);
                }
            }

            if (IsReadDependencies(reader.Version))
            {
                m_dependencies = reader.ReadAssetArray <PPtr <Shader> >();
            }
            if (IsReadNonModifiableTextures(reader.Version))
            {
                m_nonModifiableTextures = reader.ReadAssetArray <PPtr <Texture> >();
            }
            if (IsReadShaderIsBaked(reader.Version))
            {
                ShaderIsBaked = reader.ReadBoolean();
                reader.AlignStream(AlignType.Align4);
            }
        }
Ejemplo n.º 8
0
        /*
         *  Game plan:
         *  1. Find the Level category
         *  2. Find the link with the Property SceneComponent
         *  3. Dig into the vanilla pak and the mod pak, try to find the connecting actor, add its nodes in the SimpleConstructionScript under BlueprintCreatedComponents (garbage1 = 0 no problem)
         *  4. Create the SceneComponent (garbage1 = 0), no RelativeLocation or UCSModifiedProperties, CreationMethod = EComponentCreationMethod::SimpleConstructionScript, bNetAddressable = 1
         *  5. Create the new Actor_C category, set its Linkage to the Level category, set the garbage1 to 0 (maybe random number idk), DefaultSceneRoot & RootComponent = the matching SceneComponent
         */

        public MemoryStream Bake(string[] newComponents, string[] newTrailheads, byte[] superRawData)
        {
            BinaryReader yReader = new BinaryReader(new MemoryStream(superRawData));
            AssetWriter  y       = new AssetWriter
            {
                WillStoreOriginalCopyInMemory = true, WillWriteSectionSix = true, data = new AssetReader()
            };

            y.data.Read(yReader);
            y.OriginalCopy = superRawData;

            // Missions
            if (newTrailheads.Length > 0)
            {
                for (int cat = 0; cat < y.data.categories.Count; cat++)
                {
                    if (y.data.categories[cat] is NormalCategory normalCat)
                    {
                        if (y.data.GetHeaderReference(y.data.GetLinkReference(normalCat.ReferenceData.connection)) != "AstroSettings")
                        {
                            continue;
                        }

                        for (int i = 0; i < normalCat.Data.Count; i++)
                        {
                            if (normalCat.Data[i].Name == "MissionData" && normalCat.Data[i] is ArrayPropertyData arrDat && arrDat.ArrayType == "ObjectProperty")
                            {
                                y.data.AddHeaderReference("AstroMissionDataAsset");

                                PropertyData[] usArrData = arrDat.Value;
                                int            oldLen    = usArrData.Length;
                                Array.Resize(ref usArrData, usArrData.Length + newTrailheads.Length);
                                for (int j = 0; j < newTrailheads.Length; j++)
                                {
                                    string realName      = newTrailheads[j];
                                    string softClassName = Path.GetFileNameWithoutExtension(realName);

                                    y.data.AddHeaderReference(realName);
                                    y.data.AddHeaderReference(softClassName);
                                    Link newLink    = new Link("/Script/Astro", "AstroMissionDataAsset", y.data.AddLink("/Script/CoreUObject", "Package", 0, realName).Index, softClassName, y.data);
                                    int  bigNewLink = y.data.AddLink(newLink);

                                    usArrData[oldLen + j] = new ObjectPropertyData(arrDat.Name, y.data)
                                    {
                                        LinkValue = bigNewLink
                                    };
                                }
                                arrDat.Value = usArrData;
                                break;
                            }
                        }
                        break;
                    }
                }
            }

            if (newComponents.Length == 0)
            {
                return(y.WriteData(new BinaryReader(new MemoryStream(y.OriginalCopy))));
            }

            LevelCategory levelCategory = null;
            int           levelLocation = -1;

            for (int i = 0; i < y.data.categories.Count; i++)
            {
                Category baseUs = y.data.categories[i];
                if (baseUs is LevelCategory levelUs)
                {
                    levelCategory = levelUs;
                    levelLocation = i;
                    break;
                }
            }
            if (levelLocation < 0)
            {
                throw new FormatException("Unable to find Level category");
            }

            // Preliminary header reference additions
            y.data.AddHeaderReference("bHidden");
            y.data.AddHeaderReference("bNetAddressable");
            y.data.AddHeaderReference("CreationMethod");
            y.data.AddHeaderReference("EComponentCreationMethod");
            y.data.AddHeaderReference("EComponentCreationMethod::SimpleConstructionScript");
            y.data.AddHeaderReference("BlueprintCreatedComponents");
            y.data.AddHeaderReference("AttachParent");
            y.data.AddHeaderReference("RootComponent");

            foreach (string componentPathRaw in newComponents)
            {
                CategoryReference refData1      = new CategoryReference(refData1B);
                string            componentPath = componentPathRaw;
                string            component     = Path.GetFileNameWithoutExtension(componentPathRaw);
                if (componentPathRaw.Contains("."))
                {
                    string[] tData = componentPathRaw.Split(new char[] { '.' });
                    componentPath = tData[0];
                    component     = tData[1].Remove(tData[1].Length - 2);
                }
                y.data.AddHeaderReference(componentPath);
                y.data.AddHeaderReference(component + "_C");

                Link newLink    = new Link("/Script/Engine", "BlueprintGeneratedClass", y.data.AddLink("/Script/CoreUObject", "Package", 0, componentPath).Index, component + "_C", y.data);
                int  bigNewLink = y.data.AddLink(newLink);
                refData1.connection = bigNewLink;
                refData1.typeIndex  = y.data.AddHeaderReference(component);

                // Note that category links are set to one more than you'd think since categories in the category list index from 1 instead of 0

                refData1.garbage1 = 0;
                refData1.link     = levelLocation + 1; // Level category

                // First we see if we can find the actual asset it's referring to
                List <SCS_Node> allBlueprintCreatedComponents = new List <SCS_Node>();
                byte[]          foundData = ParentIntegrator.SearchInAllPaksForPath(componentPath.ConvertGamePathToAbsolutePath(), Extractor);
                if (foundData != null && foundData.Length > 0)
                {
                    // If we can find the asset, then we read the asset and hop straight to the SimpleConstructionScript
                    AssetReader foundDataReader = new AssetReader();
                    foundDataReader.Read(new BinaryReader(new MemoryStream(foundData)), null, null);

                    int scsLocation = -1;
                    for (int i = 0; i < foundDataReader.categories.Count; i++)
                    {
                        Category foundCategory = foundDataReader.categories[i];
                        if (foundCategory is NormalCategory normalFoundCategory)
                        {
                            string nm = foundDataReader.GetHeaderReference(foundDataReader.GetLinkReference(normalFoundCategory.ReferenceData.connection));
                            switch (nm)
                            {
                            case "SimpleConstructionScript":
                                scsLocation = i;
                                break;
                            }
                        }
                    }

                    if (scsLocation >= 0)
                    {
                        List <int>     knownNodeCategories = new List <int>();
                        NormalCategory scsCategory         = (NormalCategory)foundDataReader.categories[scsLocation];
                        for (int j = 0; j < scsCategory.Data.Count; j++)
                        {
                            PropertyData bit = scsCategory.Data[j];
                            if (bit is ArrayPropertyData arrBit && arrBit.ArrayType == "ObjectProperty" && bit.Name == "AllNodes")
                            {
                                foreach (ObjectPropertyData objProp in arrBit.Value)
                                {
                                    if (objProp.LinkValue > 0)
                                    {
                                        knownNodeCategories.Add(objProp.LinkValue);
                                    }
                                }
                            }
                        }

                        Dictionary <int, int> knownParents = new Dictionary <int, int>();
                        foreach (int knownNodeCategory in knownNodeCategories)
                        {
                            Category knownCat = foundDataReader.categories[knownNodeCategory - 1];
                            string   nm       = foundDataReader.GetHeaderReference(foundDataReader.GetLinkReference(knownCat.ReferenceData.connection));
                            if (nm != "SCS_Node")
                            {
                                continue;
                            }
                            if (knownCat is NormalCategory knownNormalCat)
                            {
                                SCS_Node newSCS = new SCS_Node();
                                newSCS.InternalVariableName = "Unknown";
                                newSCS.OriginalCategory     = knownNodeCategory;
                                Link knownTypeLink1 = null;
                                Link knownTypeLink2 = null;

                                foreach (PropertyData knownNormalCatProp in knownNormalCat.Data)
                                {
                                    switch (knownNormalCatProp.Name)
                                    {
                                    case "InternalVariableName":
                                        if (knownNormalCatProp is NamePropertyData)
                                        {
                                            newSCS.InternalVariableName = ((NamePropertyData)knownNormalCatProp).Value;
                                        }
                                        break;

                                    case "ComponentClass":
                                        if (knownNormalCatProp is ObjectPropertyData)
                                        {
                                            knownTypeLink1 = ((ObjectPropertyData)knownNormalCatProp).Value;
                                        }
                                        knownTypeLink2 = foundDataReader.GetLinkAt(knownTypeLink1.Linkage);
                                        break;

                                    case "ChildNodes":
                                        if (knownNormalCatProp is ArrayPropertyData arrData2 && arrData2.ArrayType == "ObjectProperty")
                                        {
                                            foreach (ObjectPropertyData knownNormalCatPropChildren in arrData2.Value)
                                            {
                                                knownParents.Add(knownNormalCatPropChildren.LinkValue, knownNodeCategory);
                                            }
                                        }
                                        break;
                                    }
                                }

                                if (knownTypeLink1 != null && knownTypeLink2 != null)
                                {
                                    Link prospectiveLink2 = new Link();
                                    prospectiveLink2.Base     = (ulong)y.data.AddHeaderReference(foundDataReader.GetHeaderReference((int)knownTypeLink2.Base));
                                    prospectiveLink2.Class    = (ulong)y.data.AddHeaderReference(foundDataReader.GetHeaderReference((int)knownTypeLink2.Class));
                                    prospectiveLink2.Linkage  = knownTypeLink2.Linkage;
                                    prospectiveLink2.Property = (ulong)y.data.AddHeaderReference(foundDataReader.GetHeaderReference((int)knownTypeLink2.Property));

                                    int addedLink = y.data.SearchForLink(prospectiveLink2.Base, prospectiveLink2.Class, prospectiveLink2.Linkage, prospectiveLink2.Property);
                                    if (addedLink >= 0)
                                    {
                                        addedLink = y.data.AddLink(prospectiveLink2);
                                    }

                                    Link prospectiveLink1 = new Link();
                                    prospectiveLink1.Base     = (ulong)y.data.AddHeaderReference(foundDataReader.GetHeaderReference((int)knownTypeLink1.Base));
                                    prospectiveLink1.Class    = (ulong)y.data.AddHeaderReference(foundDataReader.GetHeaderReference((int)knownTypeLink1.Class));
                                    prospectiveLink1.Property = (ulong)y.data.AddHeaderReference(foundDataReader.GetHeaderReference((int)knownTypeLink1.Property));
                                    prospectiveLink1.Linkage  = addedLink;

                                    int newTypeLink = y.data.SearchForLink(prospectiveLink1.Base, prospectiveLink1.Class, prospectiveLink1.Linkage, prospectiveLink1.Property);
                                    if (newTypeLink >= 0)
                                    {
                                        newTypeLink = y.data.AddLink(prospectiveLink1);
                                    }
                                    newSCS.TypeLink = newTypeLink;
                                }

                                allBlueprintCreatedComponents.Add(newSCS);
                            }
                        }

                        foreach (SCS_Node node in allBlueprintCreatedComponents)
                        {
                            if (knownParents.ContainsKey(node.OriginalCategory))
                            {
                                node.AttachParent = knownParents[node.OriginalCategory];
                            }
                        }
                    }
                }

                // Then we add all our child components
                int templateCategoryPointer = y.data.categories.Count + allBlueprintCreatedComponents.Count + 1;

                List <ObjectPropertyData> BlueprintCreatedComponentsSerializedList = new List <ObjectPropertyData>();
                List <ObjectPropertyData> AttachParentDueForCorrection             = new List <ObjectPropertyData>();
                Dictionary <string, int>  NodeNameToCatIndex = new Dictionary <string, int>();
                Dictionary <int, int>     OldCatToNewCat     = new Dictionary <int, int>();
                foreach (SCS_Node blueprintCreatedComponent in allBlueprintCreatedComponents)
                {
                    CategoryReference refData2 = new CategoryReference(refData2B);

                    refData2.connection = blueprintCreatedComponent.TypeLink;
                    refData2.typeIndex  = y.data.AddHeaderReference(blueprintCreatedComponent.InternalVariableName);
                    refData2.garbage1   = 0;                       // unknown if this needs to be randomized or something
                    refData2.link       = templateCategoryPointer; // Template category

                    var determinedPropData = new List <PropertyData>
                    {
                        new BoolPropertyData("bNetAddressable", y.data)
                        {
                            Value = true,
                        },
                        new EnumPropertyData("CreationMethod", y.data)
                        {
                            EnumType = "EComponentCreationMethod",
                            Value    = "EComponentCreationMethod::SimpleConstructionScript"
                        }
                    };

                    if (blueprintCreatedComponent.AttachParent >= 0)
                    {
                        var nextOPD = new ObjectPropertyData("AttachParent", y.data)
                        {
                            LinkValue = blueprintCreatedComponent.AttachParent
                        };
                        AttachParentDueForCorrection.Add(nextOPD);
                        determinedPropData.Add(nextOPD);
                    }

                    y.data.categories.Add(new NormalCategory(determinedPropData, refData2, y.data, new byte[4] {
                        0, 0, 0, 0
                    }));
                    BlueprintCreatedComponentsSerializedList.Add(new ObjectPropertyData("BlueprintCreatedComponents", y.data)
                    {
                        LinkValue = y.data.categories.Count
                    });
                    NodeNameToCatIndex.Add(blueprintCreatedComponent.InternalVariableName, y.data.categories.Count);
                    OldCatToNewCat.Add(blueprintCreatedComponent.OriginalCategory, y.data.categories.Count);

                    y.data.AddLink(new Link((ulong)y.data.AddHeaderReference("/Script/Engine"), y.data.GetLinkAt(blueprintCreatedComponent.TypeLink).Property, refData1.connection, (ulong)y.data.AddHeaderReference(blueprintCreatedComponent.InternalVariableName + "_GEN_VARIABLE")));
                }

                foreach (ObjectPropertyData attachParentCorrecting in AttachParentDueForCorrection)
                {
                    attachParentCorrecting.LinkValue = OldCatToNewCat[attachParentCorrecting.LinkValue];
                }

                // Then we add the template category
                var templateDeterminedPropData = new List <PropertyData>
                {
                    new BoolPropertyData("bHidden", y.data)
                    {
                        Value = true
                    },
                    new ArrayPropertyData("BlueprintCreatedComponents", y.data)
                    {
                        ArrayType = "ObjectProperty",
                        Value     = BlueprintCreatedComponentsSerializedList.ToArray()
                    }
                };

                foreach (KeyValuePair <string, int> entry in NodeNameToCatIndex)
                {
                    if (entry.Key == "DefaultSceneRoot")
                    {
                        templateDeterminedPropData.Add(new ObjectPropertyData("RootComponent", y.data)
                        {
                            LinkValue = entry.Value
                        });
                    }
                    templateDeterminedPropData.Add(new ObjectPropertyData(entry.Key, y.data)
                    {
                        LinkValue = entry.Value
                    });
                }

                y.data.categories.Add(new NormalCategory(templateDeterminedPropData, refData1, y.data, new byte[4] {
                    0, 0, 0, 0
                }));

                // Add the template category to the level category
                levelCategory.IndexData.Add(y.data.categories.Count);
            }

            return(y.WriteData(new BinaryReader(new MemoryStream(y.OriginalCopy))));
        }
Ejemplo n.º 9
0
        public void BuildInfraSetupScript(string manifestFile, string outputFolder)
        {
            IEnumerable <IAsset> unresolvedAssets = null;
            var assets = AssetReader.Read(manifestFile);

            if (assets?.Any() == true)
            {
                foreach (var asset in assets)
                {
                    _assetManager.Add(asset);
                    unresolvedAssets = _assetManager.EvaluateUnfulfilledComponents(asset);
                }
            }

            if (unresolvedAssets?.Any() == true)
            {
                foreach (var asset in unresolvedAssets)
                {
                    _logger.LogWarning($"Unable to resolve {asset.Type}");
                    var missingDependencyTypes = asset.Dependencies.Where(d =>
                                                                          string.IsNullOrEmpty(d.Key))
                                                 .Select(d => d.Type);
                    _logger.LogWarning($"Unresolved components: {string.Join(",", missingDependencyTypes)}");
                }
            }

            var sortedComponents = _assetManager.GetAllAssetsWithObjPath()
                                   .Where(c => c.Kind == AssetKind.Infra || c.Kind == AssetKind.Shared)
                                   .OrderBy(c => c.SortOrder)
                                   .ToList();
            var validator = new AssetValidator(_assetManager, _loggerFactory);

            validator.TryToValidateAssets(sortedComponents);
            var envName   = "dev";
            var spaceName = Environment.UserName;

            if (sortedComponents.FirstOrDefault(c => c.Type == AssetType.Global) is Global global)
            {
                envName   = global.EnvName;
                spaceName = global.SpaceName;
            }

            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }
            var envFolder = Path.Join(outputFolder, "env", envName);

            if (!Directory.Exists(envFolder))
            {
                Directory.CreateDirectory(envFolder);
            }

            var spaceFolder = envFolder;

            if (!string.IsNullOrEmpty(spaceName))
            {
                spaceFolder = Path.Join(envFolder, spaceName);
            }
            if (!Directory.Exists(spaceFolder))
            {
                Directory.CreateDirectory(spaceFolder);
            }

            var zipFilePath = Path.Join("Evidence", "scripts.zip");

            if (!File.Exists(zipFilePath))
            {
                throw new Exception($"Unable to find script bundle: {new FileInfo(zipFilePath).FullName}");
            }
            ZipFile.ExtractToDirectory(zipFilePath, outputFolder, true);

            var valueYamlFile = Path.Combine(spaceFolder, "values.yaml");

            _logger.LogInformation($"Set values yaml file to '{new FileInfo(valueYamlFile).FullName}'");
            if (File.Exists(valueYamlFile))
            {
                File.Delete(valueYamlFile);
            }

            using (var writer = new StreamWriter(File.OpenWrite(valueYamlFile)))
            {
                foreach (var asset in sortedComponents)
                {
                    asset.WriteYaml(writer, _assetManager, _loggerFactory);
                }
            }

            // replace "True" and "False"
            var yamlContent = File.ReadAllText(valueYamlFile);
            var trueRegex   = new Regex("\\bTrue\\b");

            yamlContent = trueRegex.Replace(yamlContent, "true");
            var falseRegex = new Regex("\\bFalse\\b");

            yamlContent = falseRegex.Replace(yamlContent, "false");
            File.WriteAllText(valueYamlFile, yamlContent);
        }
Ejemplo n.º 10
0
        public void GenerateCode(string manifestFile, string solutionFolder)
        {
            IEnumerable <IAsset> unresolvedAssets = null;
            var assets = AssetReader.Read(manifestFile);

            if (assets?.Any() == true)
            {
                foreach (var asset in assets)
                {
                    _assetManager.Add(asset);
                    unresolvedAssets = _assetManager.EvaluateUnfulfilledComponents(asset);
                }
            }

            if (unresolvedAssets?.Any() == true)
            {
                foreach (var asset in unresolvedAssets)
                {
                    _logger.LogWarning($"Unable to resolve {asset.Type}");
                    var missingDependencyTypes = asset.Dependencies.Where(d =>
                                                                          string.IsNullOrEmpty(d.Key))
                                                 .Select(d => d.Type);
                    _logger.LogWarning($"Unresolved components: {string.Join(",", missingDependencyTypes)}");
                }
            }

            var sortedComponents = _assetManager.GetAllAssetsWithObjPath()
                                   .Where(c => c.Kind == AssetKind.Code || c.Kind == AssetKind.Shared)
                                   .OrderBy(c => c.SortOrder)
                                   .ToList();
            var validator = new AssetValidator(_assetManager, _loggerFactory);

            validator.TryToValidateAssets(sortedComponents);

            // update solution file
            var product = _assetManager.Get(AssetType.Prodct) as Product;

            if (product == null)
            {
                throw new Exception("Missing dependency [Product]");
            }
            var defaultSolutionFile = Path.Join(solutionFolder, $"{product.Name}.sln");

            if (sortedComponents.FirstOrDefault(c => c.Type == AssetType.Service) is Services services)
            {
                foreach (var service in services.Items.OfType <Service>())
                {
                    service.SolutionFile = service.SolutionFile ?? defaultSolutionFile;
                }
            }

            if (!Directory.Exists(solutionFolder))
            {
                Directory.CreateDirectory(solutionFolder);
            }
            var zipFilePath = Path.Join("Evidence", "solution.zip");

            if (!File.Exists(zipFilePath))
            {
                throw new Exception($"Unable to find solution bundle: {new FileInfo(zipFilePath).FullName}");
            }
            ZipFile.ExtractToDirectory(zipFilePath, solutionFolder, true);
            var solutionFile = Directory.GetFiles(solutionFolder, "*.sln", SearchOption.TopDirectoryOnly)
                               .FirstOrDefault();

            if (!string.IsNullOrEmpty(solutionFile))
            {
                File.Copy(solutionFile, defaultSolutionFile, true);
                File.Delete(solutionFile);
            }

            var manifestYamlFile = Path.Combine(solutionFolder, "services.yaml");

            _logger.LogInformation($"Set manifest file to '{new FileInfo(manifestYamlFile).FullName}'");
            if (File.Exists(manifestYamlFile))
            {
                File.Delete(manifestYamlFile);
            }

            using (var writer = new StreamWriter(File.OpenWrite(manifestYamlFile)))
            {
                foreach (var asset in sortedComponents)
                {
                    asset.WriteYaml(writer, _assetManager, _loggerFactory);
                }
            }

            // replace "True" and "False"
            var yamlContent = File.ReadAllText(manifestYamlFile);
            var trueRegex   = new Regex("\\bTrue\\b");

            yamlContent = trueRegex.Replace(yamlContent, "true");
            var falseRegex = new Regex("\\bFalse\\b");

            yamlContent = falseRegex.Replace(yamlContent, "false");
            File.WriteAllText(manifestYamlFile, yamlContent);
        }
Ejemplo n.º 11
0
        public override void Read(AssetReader reader)
        {
            base.Read(reader);

            if (IsReadDeferred(reader.Version))
            {
                Deferred.Read(reader);
            }
            if (IsReadDeferredReflections(reader.Version))
            {
                DeferredReflections.Read(reader);
            }
            if (IsReadScreenSpaceShadows(reader.Version))
            {
                ScreenSpaceShadows.Read(reader);
            }
            if (IsReadLegacyDeferred(reader.Version))
            {
                LegacyDeferred.Read(reader);
            }
            if (IsReadDepthNormals(reader.Version))
            {
                DepthNormals.Read(reader);
                MotionVectors.Read(reader);
                LightHalo.Read(reader);
                LensFlare.Read(reader);
            }

            if (IsReadAlwaysIncludedShaders(reader.Version))
            {
                m_alwaysIncludedShaders = reader.ReadArray <PPtr <Shader> >();
            }

            if (IsReadPreloadedShaders(reader.Version))
            {
                m_preloadedShaders = reader.ReadArray <PPtr <ShaderVariantCollection> >();
            }
            if (IsReadSpritesDefaultMaterial(reader.Version))
            {
                SpritesDefaultMaterial.Read(reader);
            }
            if (IsReadCustomRenderPipeline(reader.Version))
            {
                CustomRenderPipeline.Read(reader);
                TransparencySortMode = (TransparencySortMode)reader.ReadInt32();
                TransparencySortAxis.Read(reader);
            }

            if (IsReadTierSettings(reader.Version))
            {
                if (IsReadPlatformSettings(reader.Version))
                {
                    if (IsReadPlatformSettingsTiers(reader.Version))
                    {
                        m_platformSettings    = new PlatformShaderSettings[3];
                        m_platformSettings[0] = reader.Read <PlatformShaderSettings>();
                        m_platformSettings[1] = reader.Read <PlatformShaderSettings>();
                        m_platformSettings[2] = reader.Read <PlatformShaderSettings>();
                    }
                    else
                    {
                        m_platformSettings    = new PlatformShaderSettings[1];
                        m_platformSettings[0] = reader.Read <PlatformShaderSettings>();
                    }
                }
                else
                {
                    if (IsReadStaticTierGraphicsSettings(reader.Version, reader.Flags))
                    {
                        m_tierGraphicSettings    = new TierGraphicsSettings[3];
                        m_tierGraphicSettings[0] = reader.Read <TierGraphicsSettings>();
                        m_tierGraphicSettings[1] = reader.Read <TierGraphicsSettings>();
                        m_tierGraphicSettings[2] = reader.Read <TierGraphicsSettings>();
                    }
                }
            }

#if UNIVERSAL
            if (IsReadEditorSettings(reader.Flags))
            {
                if (IsReadDefaultRenderingPath(reader.Version))
                {
                    DefaultRenderingPath       = (RenderingPath)reader.ReadInt32();
                    DefaultMobileRenderingPath = (RenderingPath)reader.ReadInt32();
                }
                if (IsReadTierSettings(reader.Version))
                {
                    m_tierSettings = reader.ReadArray <TierSettings>();
                }

                if (IsReadLightmapStripping(reader.Version))
                {
                    LightmapStripping = (LightmapStrippingMode)reader.ReadInt32();
                }
                if (IsReadFogStripping(reader.Version))
                {
                    if (IsReadFogStrippingFirst(reader.Version))
                    {
                        FogStripping = (LightmapStrippingMode)reader.ReadInt32();
                    }
                }
                if (IsReadInstancingStripping(reader.Version))
                {
                    InstancingStripping = (InstancingStrippingVariant)reader.ReadInt32();
                }

                if (IsReadLightmapKeepPlain(reader.Version))
                {
                    LightmapKeepPlain       = reader.ReadBoolean();
                    LightmapKeepDirCombined = reader.ReadBoolean();
                }
                if (IsReadLightmapKeepDirSeparate(reader.Version))
                {
                    LightmapKeepDirSeparate = reader.ReadBoolean();
                }

                if (IsReadLightmapKeepDynamicPlain(reader.Version))
                {
                    if (IsReadLightmapKeepDynamic(reader.Version))
                    {
                        bool lightmapKeepDynamic = reader.ReadBoolean();
                        reader.AlignStream(AlignType.Align4);

                        LightmapKeepDynamicPlain       = lightmapKeepDynamic;
                        LightmapKeepDynamicDirCombined = lightmapKeepDynamic;
                        LightmapKeepDynamicDirSeparate = lightmapKeepDynamic;
                    }
                    else
                    {
                        LightmapKeepDynamicPlain       = reader.ReadBoolean();
                        LightmapKeepDynamicDirCombined = reader.ReadBoolean();
                    }
                }
                if (IsReadLightmapKeepDynamicDirSeparate(reader.Version))
                {
                    LightmapKeepDynamicDirSeparate = reader.ReadBoolean();
                }
                if (IsAlign(reader.Version))
                {
                    reader.AlignStream(AlignType.Align4);
                }

                if (IsReadLightmapKeepShadowMask(reader.Version))
                {
                    LightmapKeepShadowMask  = reader.ReadBoolean();
                    LightmapKeepSubtractive = reader.ReadBoolean();
                }
                if (IsReadFogStripping(reader.Version))
                {
                    if (!IsReadFogStrippingFirst(reader.Version))
                    {
                        FogStripping = (LightmapStrippingMode)reader.ReadInt32();
                    }
                }
                if (IsReadFogKeepLinear(reader.Version))
                {
                    FogKeepLinear = reader.ReadBoolean();
                    FogKeepExp    = reader.ReadBoolean();
                    FogKeepExp2   = reader.ReadBoolean();
                    reader.AlignStream(AlignType.Align4);
                }

                if (IsReadAlbedoSwatchInfos(reader.Version))
                {
                    m_albedoSwatchInfos = reader.ReadArray <AlbedoSwatchInfo>();
                }
            }
            else
#endif
            {
                if (IsReadShaderDefinesPerShaderCompiler(reader.Version))
                {
                    m_shaderDefinesPerShaderCompiler = reader.ReadArray <PlatformShaderDefines>();
                }
            }

            if (IsReadLightsUseLinearIntensity(reader.Version))
            {
                LightsUseLinearIntensity  = reader.ReadBoolean();
                LightsUseColorTemperature = reader.ReadBoolean();
            }
        }
Ejemplo n.º 12
0
        public override void Read(AssetReader reader)
        {
            base.Read(reader);

            if (IsReadDefaultStandaloneQuality(reader.Version))
            {
                QualityLevel defaultStandaloneQuality = (QualityLevel)reader.ReadInt32();
                QualityLevel defaultWebPlayerQuality  = (QualityLevel)reader.ReadInt32();
                m_perPlatformDefaultQuality = new Dictionary <string, int>();
                SetDefaultPlatformQuality(m_perPlatformDefaultQuality);
                m_perPlatformDefaultQuality[BuildTargetGroup.Standalone.ToExportString()] = (int)defaultStandaloneQuality;
                m_perPlatformDefaultQuality[BuildTargetGroup.WebPlayer.ToExportString()]  = (int)defaultStandaloneQuality;
            }
            if (IsReadDefaultMobileQuality(reader.Version))
            {
                QualityLevel defaultMobileQuality = (QualityLevel)reader.ReadInt32();
                m_perPlatformDefaultQuality[BuildTargetGroup.Android.ToExportString()] = (int)defaultMobileQuality;
                m_perPlatformDefaultQuality[BuildTargetGroup.iOS.ToExportString()]     = (int)defaultMobileQuality;
            }
            CurrentQuality = reader.ReadInt32();
            if (IsReadQualitySettingArray(reader.Version))
            {
                m_qualitySettings = reader.ReadArray <QualitySetting>();
            }
            else
            {
                m_qualitySettings = new QualitySetting[6];
                QualitySetting fastest = reader.Read <QualitySetting>();
                fastest.Name = nameof(QualityLevel.Fastest);
                m_qualitySettings[(int)QualityLevel.Fastest] = fastest;

                QualitySetting fast = reader.Read <QualitySetting>();
                fast.Name = nameof(QualityLevel.Fast);
                m_qualitySettings[(int)QualityLevel.Fast] = fast;

                QualitySetting simple = reader.Read <QualitySetting>();
                simple.Name = nameof(QualityLevel.Simple);
                m_qualitySettings[(int)QualityLevel.Simple] = simple;

                QualitySetting good = reader.Read <QualitySetting>();
                good.Name = nameof(QualityLevel.Good);
                m_qualitySettings[(int)QualityLevel.Good] = good;

                QualitySetting beautiful = reader.Read <QualitySetting>();
                beautiful.Name = nameof(QualityLevel.Beautiful);
                m_qualitySettings[(int)QualityLevel.Beautiful] = beautiful;

                QualitySetting fantastic = reader.Read <QualitySetting>();
                fantastic.Name = nameof(QualityLevel.Fantastic);
                m_qualitySettings[(int)QualityLevel.Fantastic] = fantastic;
            }
            foreach (QualitySetting setting in m_qualitySettings)
            {
                switch (setting.Name)
                {
                case nameof(QualityLevel.Fastest):
                case "Very Low":
                    QualitySetting fastest = CreateFastestSettings();
                    setting.Merge(fastest, reader.Version, reader.Flags);
                    break;

                case nameof(QualityLevel.Fast):
                case "Low":
                    QualitySetting fast = CreateFastSettings();
                    setting.Merge(fast, reader.Version, reader.Flags);
                    break;

                case nameof(QualityLevel.Simple):
                case "Medium":
                    QualitySetting simple = CreateSimpleSettings();
                    setting.Merge(simple, reader.Version, reader.Flags);
                    break;

                case nameof(QualityLevel.Good):
                case "High":
                    QualitySetting good = CreateGoodSettings();
                    setting.Merge(good, reader.Version, reader.Flags);
                    break;

                case nameof(QualityLevel.Beautiful):
                case "Very High":
                    QualitySetting beautiful = CreateBeautifulSettings();
                    setting.Merge(beautiful, reader.Version, reader.Flags);
                    break;

                case nameof(QualityLevel.Fantastic):
                case "Ultra":
                default:
                    QualitySetting fantastic = CreateFantasticSettings();
                    setting.Merge(fantastic, reader.Version, reader.Flags);
                    break;
                }
            }

            if (IsReadWebPlayer(reader.Version))
            {
                QualitySetting webPlayer = reader.Read <QualitySetting>();
                webPlayer.Name = "WebPlayer";
            }

#if UNIVERSAL
            if (IsReadPerPlatformDefaultQuality(reader.Version, reader.Flags))
            {
                m_perPlatformDefaultQuality = new Dictionary <string, int>();
                m_perPlatformDefaultQuality.Read(reader);
            }
#endif
            if (IsReadStrippedMaximumLODLevel(reader.Version, reader.Flags))
            {
                StrippedMaximumLODLevel = reader.ReadInt32();
            }
        }