示例#1
0
        static IEnumerator BuildPartialWeaverCoreRoutine(FileInfo outputPath, BuildTask <BuildOutput> task)
        {
            if (task == null)
            {
                task = new BuildTask <BuildOutput>();
            }
            task.Result = new BuildOutput();
            var buildDirectory = outputPath.Directory;
            var hkFile         = new FileInfo(PathUtilities.AddSlash(buildDirectory.FullName) + "Assembly-CSharp.dll");
            var hkBuildTask    = BuildHollowKnightAsm(hkFile);

            yield return(new WaitUntil(() => hkBuildTask.Completed));

            task.Result.Success     = hkBuildTask.Result.Success;
            task.Result.OutputFiles = hkBuildTask.Result.OutputFiles;
            if (!hkBuildTask.Result.Success)
            {
                task.Completed = true;
                yield break;
            }
            yield return(BuildAssembly(new BuildParameters
            {
                BuildPath = outputPath,
                AssemblyReferences = new List <string>
                {
                    hkFile.FullName
                },
                Defines = new List <string>
                {
                    "GAME_BUILD"
                },
                ExcludedReferences = new List <string>
                {
                    "Library/ScriptAssemblies/WeaverCore.dll",
                    "Library/ScriptAssemblies/HollowKnight.dll",
                    "Library/ScriptAssemblies/WeaverCore.Editor.dll",
                    "Library/ScriptAssemblies/WeaverBuildTools.dll",
                    "Library/ScriptAssemblies/TMPro.Editor.dll",
                    "Library/ScriptAssemblies/0Harmony.dll",
                    "Library/ScriptAssemblies/Mono.Cecil.dll",
                    "Library/ScriptAssemblies/JUNK.dll"
                },
                Scripts = ScriptFinder.FindAssemblyScripts("WeaverCore")
            }, BuildPresetType.Game, task));
        }
示例#2
0
        public static string GetModBuildFolder()
        {
            string compileLocation = null;

            if (compileLocation == null)
            {
                if (!string.IsNullOrEmpty(BuildScreen.BuildSettings?.BuildLocation))
                {
                    compileLocation = BuildScreen.BuildSettings.BuildLocation;
                }
                else
                {
                    compileLocation = SelectionUtilities.SelectFolder("Select where you want to place the finished mod", "");
                    if (compileLocation == null)
                    {
                        throw new Exception("An invalid path specified for building the mod");
                    }
                }
            }
            return(PathUtilities.AddSlash(compileLocation));
        }
示例#3
0
        static IEnumerator BuildModRoutine(FileInfo outputPath, BuildTask <BuildOutput> task)
        {
            if (task == null)
            {
                task = new BuildTask <BuildOutput>();
            }
            yield return(BuildPartialModAsmRoutine(outputPath, task));

            if (!task.Result.Success)
            {
                yield break;
            }
            task.Result.Success = false;
            yield return(BuildWeaverCoreGameRoutine(null, task));

            if (!task.Result.Success)
            {
                yield break;
            }
            var weaverCoreOutputLocation = PathUtilities.AddSlash(outputPath.Directory.FullName) + "WeaverCore.dll";

            File.Copy(WeaverCoreBuildLocation.FullName, weaverCoreOutputLocation, true);
            BundleTools.BuildAndEmbedAssetBundles(outputPath, new FileInfo(weaverCoreOutputLocation), typeof(BuildTools).GetMethod(nameof(StartHollowKnight)));
        }
示例#4
0
        static IEnumerator BuildXmlProjectRoutine(FileInfo xmlProjectFile, FileInfo outputPath, BuildTask <BuildOutput> task)
        {
            if (task == null)
            {
                task = new BuildTask <BuildOutput>();
            }
            using (var stream = File.OpenRead(xmlProjectFile.FullName))
            {
                using (var reader = XmlReader.Create(stream, new XmlReaderSettings {
                    IgnoreComments = true
                }))
                {
                    reader.ReadToFollowing("Project");
                    reader.ReadToDescendant("PropertyGroup");
                    reader.ReadToFollowing("PropertyGroup");
                    reader.ReadToDescendant("OutputPath");
                    //reader.NodeType == XmlNodeType.Prope
                    //reader.ReadEndElement();
                    //reader.ReadToFollowing("PropertyGroup");
                    //reader.ReadToFollowing("OutputPath");

                    if (outputPath == null)
                    {
                        var foundOutputPath = reader.ReadElementContentAsString();
                        if (Path.IsPathRooted(foundOutputPath))
                        {
                            outputPath = new FileInfo(PathUtilities.AddSlash(foundOutputPath) + "WeaverCore.Game.dll");
                        }
                        else
                        {
                            outputPath = new FileInfo(PathUtilities.AddSlash(xmlProjectFile.Directory.FullName) + PathUtilities.AddSlash(foundOutputPath) + "WeaverCore.Game.dll");
                        }
                    }
                    //Debug.Log("Output Path = " + foundOutputPath);
                    //reader.ReadEndElement();
                    reader.ReadToFollowing("ItemGroup");
                    List <XmlReference> References = new List <XmlReference>();
                    List <string>       Scripts    = new List <string>();
                    while (reader.Read())
                    {
                        if (reader.Name == "Reference")
                        {
                            var      referenceName = reader.GetAttribute("Include");
                            FileInfo hintPath      = null;
                            while (reader.Read() && reader.Name != "Reference")
                            {
                                if (reader.Name == "HintPath")
                                {
                                    var contents = reader.ReadElementContentAsString();
                                    if (Path.IsPathRooted(contents))
                                    {
                                        hintPath = new FileInfo(contents);
                                    }
                                    else
                                    {
                                        hintPath = new FileInfo(PathUtilities.AddSlash(xmlProjectFile.Directory.FullName) + contents);
                                    }
                                    //reader.ReadEndElement();
                                }
                            }
                            if (referenceName.Contains("Version=") || referenceName.Contains("Culture=") || referenceName.Contains("PublicKeyToken=") || referenceName.Contains("processorArchitecture="))
                            {
                                referenceName = new AssemblyName(referenceName).Name;
                            }
                            References.Add(new XmlReference
                            {
                                AssemblyName = referenceName,
                                HintPath     = hintPath
                            });
                        }
                        else if (reader.Name == "ItemGroup")
                        {
                            break;
                        }
                    }

                    foreach (var scriptFile in xmlProjectFile.Directory.GetFiles("*.cs", SearchOption.AllDirectories))
                    {
                        Scripts.Add(scriptFile.FullName);
                    }

                    /*reader.ReadToFollowing("ItemGroup");
                     * while (reader.Read() && reader.Name != "ItemGroup")
                     * {
                     *      if (reader.Name == "Compile")
                     *      {
                     *              var contents = reader.GetAttribute("Include");
                     *              if (Path.IsPathRooted(contents))
                     *              {
                     *                      //Scripts.Add(new FileInfo(contents).FullName);
                     *              }
                     *              else
                     *              {
                     *                      //Scripts.Add(new FileInfo(PathUtilities.AddSlash(xmlProjectFile.Directory.FullName) + contents).FullName);
                     *              }
                     *              if (!reader.IsEmptyElement)
                     *              {
                     *                      reader.ReadEndElement();
                     *              }
                     *      }
                     * }*/

                    /*Debug.Log("Results!");
                     * foreach (var r in References)
                     * {
                     *      Debug.Log($"Assembly Name = {r.AssemblyName}, Hint Path = {r.HintPath?.FullName}");
                     * }
                     *
                     * foreach (var s in Scripts)
                     * {
                     *      Debug.Log("Script = " + s);
                     * }
                     *
                     * Debug.Log("Output Path = " + outputPath);*/



                    /*while (reader.Read())
                     * {
                     *      Debug.Log("Reader Name = " + reader.Name);
                     *      Debug.Log("Reader Local Name = " + reader.LocalName);
                     *      //reader.IsStartElement()
                     * }*/

                    List <DirectoryInfo> AssemblySearchDirectories = new List <DirectoryInfo>
                    {
                        new DirectoryInfo(PathUtilities.AddSlash(GameBuildSettings.Settings.HollowKnightLocation) + "hollow_knight_Data\\Managed"),
                        new FileInfo(typeof(UnityEditor.EditorWindow).Assembly.Location).Directory
                    };

                    /*foreach (var searchDir in AssemblySearchDirectories)
                     * {
                     *      Debug.Log("Search Directory = " + searchDir.FullName);
                     * }*/

                    List <string> AssemblyReferences = new List <string>();



                    foreach (var xmlRef in References)
                    {
                        /*if (xmlRef.AssemblyName.Contains("UnityEngine"))
                         * {
                         *      continue;
                         * }*/
                        if (xmlRef.AssemblyName == "System")
                        {
                            continue;
                        }
                        if (xmlRef.HintPath != null && xmlRef.HintPath.Exists)
                        {
                            AssemblyReferences.Add(xmlRef.HintPath.FullName);
                        }
                        else
                        {
                            bool found = false;
                            foreach (var searchDir in AssemblySearchDirectories)
                            {
                                var filePath = PathUtilities.AddSlash(searchDir.FullName) + xmlRef.AssemblyName + ".dll";
                                //Debug.Log("File Path = " + filePath);
                                if (File.Exists(filePath))
                                {
                                    found = true;
                                    AssemblyReferences.Add(filePath);
                                    break;
                                }
                            }
                            if (!found)
                            {
                                Debug.LogError("Unable to find WeaverCore.Game Reference -> " + xmlRef.AssemblyName);
                            }
                        }
                    }

                    var scriptAssemblies = new DirectoryInfo("Library\\ScriptAssemblies").GetFiles("*.dll");

                    List <string> exclusions = new List <string>();

                    foreach (var sa in scriptAssemblies)
                    {
                        exclusions.Add(PathUtilities.ConvertToProjectPath(sa.FullName));
                        //Debug.Log("Exclusion = " + exclusions[exclusions.Count - 1]);
                    }

                    var weaverCoreLibraries = new DirectoryInfo("Assets\\WeaverCore\\Libraries").GetFiles("*.dll");

                    foreach (var wl in weaverCoreLibraries)
                    {
                        exclusions.Add(PathUtilities.ConvertToProjectPath(wl.FullName));
                    }

                    var editorDir = new FileInfo(typeof(UnityEditor.EditorWindow).Assembly.Location).Directory;

                    foreach (var ueFile in editorDir.Parent.GetFiles("UnityEngine.dll", SearchOption.AllDirectories))
                    {
                        exclusions.Add(ueFile.FullName);
                    }

                    //var editorUnityEngineDll = new FileInfo(PathUtilities.AddSlash(editorDir.Parent.FullName) + "UnityEngine.dll");

                    //Debug.Log("Editor Unity Engine Location = " + editorUnityEngineDll);
                    //exclusions.Add(editorUnityEngineDll.FullName);

                    //Debug.Log("Editor Location = " + );
                    //Debug.Log("System Location = " + typeof(System.Array).Assembly.Location);

                    //exclusions.Add("Library\\ScriptAssemblies\\HollowKnight.dll");

                    yield return(BuildAssembly(new BuildParameters
                    {
                        BuildPath = outputPath,
                        Scripts = Scripts,
                        Defines = new List <string>
                        {
                            "GAME_BUILD"
                        },
                        ExcludedReferences = exclusions,
                        AssemblyReferences = AssemblyReferences,
                    }, BuildPresetType.None, task));
                }
            }

            yield break;
        }
示例#5
0
        void BuildInternal(buildCompleteAction onComplete)
        {
            Output = null;
            if (!BuildDirectory.Exists)
            {
                BuildDirectory.Create();
            }
            var outputPath = PathUtilities.AddSlash(BuildDirectory.FullName) + FileName;
            //Debug.Log("Build Output Path = " + outputPath);
            //Debug.Log("Build Directory = " + BuildDirectory.FullName);
            //Debug.Log("Filename = " + FileName);
            AssemblyBuilder builder = new AssemblyBuilder(outputPath, Scripts.ToArray());

            builder.additionalDefines    = Defines.ToArray();
            builder.additionalReferences = References.ToArray();
            builder.buildTarget          = Target;
            builder.buildTargetGroup     = TargetGroup;
            builder.excludeReferences    = VerifyPaths(ExcludedReferences);
            builder.flags = Flags;
            Action <string, CompilerMessage[]> buildCompleteAction = null;
            var outputInfo = new OutputDetails();

            outputInfo.OutputPath = outputPath;
            buildCompleteAction   = (dest, messages) =>
            {
                //Debug.Log("---------Dest = " + dest);
                outputInfo.CompilerMessages = messages;
                Building = false;
                if (messages.Any(cm => cm.type == CompilerMessageType.Error))
                {
                    Debug.LogError("Error building assembly = " + FileName);
                    string assemblyReferences = "References: " + Environment.NewLine;
                    foreach (var reference in References.Concat(GetDefaultReferences()))
                    {
                        assemblyReferences += reference + Environment.NewLine;
                    }
                    Debug.LogError(assemblyReferences);

                    string assemblyExclusions = "Exclusions: " + Environment.NewLine;
                    foreach (var exclusion in ExcludedReferences)
                    {
                        assemblyExclusions += exclusion + Environment.NewLine;
                    }
                    Debug.LogError(assemblyExclusions);
                    outputInfo.Success = false;
                    foreach (var message in messages)
                    {
                        if (message.type == CompilerMessageType.Error)
                        {
                            Debug.LogError(message.message);
                        }
                        else
                        {
                            //Debug.LogWarning(message.message);
                        }
                    }
                }
                else
                {
                    outputInfo.Success = true;
                }
                //Debug.Log("_____SUCCESS = " + outputInfo.Success);
                builder.buildFinished -= buildCompleteAction;
                Output = outputInfo;
                if (onComplete != null)
                {
                    onComplete(Output);
                }
            };
            Building = true;
            try
            {
                builder.buildFinished += buildCompleteAction;
                builder.Build();
            }
            catch (Exception)
            {
                builder.buildFinished -= buildCompleteAction;
                Building = false;
                throw;
            }
        }