Beispiel #1
0
        public GameCore GetGameCoreFromId(string id)
        {
            CoreModel coreModel = GetCoreModelFromId(id);

            if (coreModel == null)
            {
                return(null);
            }

            string mainJar = $"{PathHelper.GetVersionFolder(this.Root, id)}{PathHelper.X}{id}.jar";

            List <Native>  natives   = new List <Native>();
            List <Library> libraries = new List <Library>();

            StringBuilder bArg = new StringBuilder();
            StringBuilder fArg = new StringBuilder();

            if (coreModel.InheritsFrom != null)
            {
                if (GetCoreModelFromId(coreModel.InheritsFrom) == null)
                {
                    return(null);
                }

                mainJar   = $"{PathHelper.GetVersionFolder(this.Root, coreModel.InheritsFrom)}{PathHelper.X}{coreModel.InheritsFrom}.jar";
                coreModel = MergeInheritsFromCoreWithRaw(coreModel, GetCoreModelFromId(coreModel.InheritsFrom));
            }

            foreach (Library library in coreModel.Libraries)
            {
                if (RuleHelper.Parser(library.Rules))
                {
                    if (library.Natives != null)
                    {
                        natives.Add(new Native(library));
                    }
                    else
                    {
                        libraries.Add(library);
                    }
                }
            }

            if (coreModel.MinecraftArguments != null)
            {
                bArg.Append($"{coreModel.MinecraftArguments}");
            }

            if (coreModel.Arguments != null && coreModel.Arguments.Game != null)
            {
                foreach (object obj in coreModel.Arguments.Game)
                {
                    if (!obj.ToString().Contains("rules"))
                    {
                        bArg.Append($" {obj}");
                    }
                }
            }

            if (coreModel.Arguments != null && coreModel.Arguments.Jvm != null)
            {
                //fix for forge 1.17
                for (int i = 0; i < coreModel.Arguments.Jvm.Count; i++)
                {
                    object obj = coreModel.Arguments.Jvm[i];

                    if (!obj.ToString().Contains("rules"))
                    {
                        if (obj.ToString().Contains("-DignoreList"))
                        {
                            fArg.Append($" {obj.ToString().Replace("${version_name}", coreModel.InheritsFrom)}");
                            continue;
                        }
                        ;

                        if (obj.ToString().Contains("-DlibraryDirectory"))
                        {
                            fArg.Append($" {obj.ToString().Replace("${library_directory}", this.Root.Contains(" ") ? $"\"{PathHelper.GetLibrariesFolder(this.Root)}\"" : PathHelper.GetLibrariesFolder(this.Root))}");
                            continue;
                        }
                        ;

                        if (obj.ToString().Contains("${library_directory}"))
                        {
                            string value = obj.ToString().Replace("/", PathHelper.X).Replace("${library_directory}", PathHelper.GetLibrariesFolder(this.Root));
                            value = this.Root.Contains(" ") ? $"\"{value}\"" : value;
                            fArg.Append($" {value}");
                            continue;
                        }
                        ;

                        fArg.Append(obj.ToString().Contains(" ") ? $" \"{obj}\"" : $" {obj}");
                    }
                }
            }

            return(new GameCore
            {
                AsstesIndex = coreModel.AssetIndex,
                BehindArguments = bArg.ToString().Replace("  ", " "),
                Downloads = coreModel.Downloads,
                FrontArguments = fArg.ToString().Replace("  ", " "),
                Id = coreModel.Id,
                //Logging = coreModel.Logging,
                Libraries = libraries,
                MainClass = coreModel.MainClass,
                MainJar = mainJar,
                Natives = natives,
                Root = this.Root,
                Type = coreModel.Type,
                JavaVersion = coreModel.JavaVersion
            });
        }