Beispiel #1
0
        private static UnityVersion GetBestCandidate(UnityVersion target, List <UnityVersion> unityVersions)
        {
            if (unityVersions == null || unityVersions.Count == 0)
            {
                throw new ArgumentException("UnityVersions must contain at least one element");
            }

            UnityVersion bestCandidate = unityVersions[0];

            if (unityVersions.Count > 1)
            {
                int bestCandidateYearDistance =
                    Math.Abs(target.Year - bestCandidate.Year);
                int bestCandidateVersionWithinYearDistance =
                    Math.Abs(target.VersionWithinYear - bestCandidate.VersionWithinYear);
                int bestCandidateSubversionWithinYearDistance =
                    Math.Abs(target.SubversionWithinYear - bestCandidate.SubversionWithinYear);
                for (int i = 1; i < unityVersions.Count; i++)
                {
                    UnityVersion candidateVersion = unityVersions[i];
                    if (
                        Math.Abs(target.Year - candidateVersion.Year) < bestCandidateYearDistance ||
                        (
                            Math.Abs(target.Year - candidateVersion.Year) == bestCandidateYearDistance &&
                            (
                                Math.Abs(target.VersionWithinYear - candidateVersion.VersionWithinYear)
                                < bestCandidateVersionWithinYearDistance ||
                                (
                                    Math.Abs(target.VersionWithinYear - candidateVersion.VersionWithinYear)
                                    == bestCandidateVersionWithinYearDistance &&
                                    (
                                        Math.Abs(target.SubversionWithinYear - candidateVersion.SubversionWithinYear)
                                        < bestCandidateSubversionWithinYearDistance
                                    )
                                )
                            )
                        )
                        )
                    {
                        bestCandidate             = unityVersions[i];
                        bestCandidateYearDistance =
                            Math.Abs(target.Year - candidateVersion.Year);
                        bestCandidateVersionWithinYearDistance =
                            Math.Abs(target.VersionWithinYear - candidateVersion.VersionWithinYear);
                        bestCandidateSubversionWithinYearDistance =
                            Math.Abs(target.SubversionWithinYear - candidateVersion.SubversionWithinYear);
                    }
                }
            }

            return(bestCandidate);
        }
Beispiel #2
0
        private static MonoLibraryOffsets GetOffsets(UnityVersion unityVersion, bool is64Bits, BinaryFormat format, bool force = true)
        {
            MonoLibraryOffsets monoLibraryOffsets = SupportedVersions.Find(
                offsets => offsets.Is64Bits == is64Bits &&
                offsets.Format == format &&
                offsets.UnityVersions.Contains(unityVersion));

            UnityVersion selectedUnityVersion = unityVersion;

            if (monoLibraryOffsets == null)
            {
                string mode           = is64Bits ? "in 64 bits mode" : "in 32 bits mode";
                string unsupportedMsg = $"The unity version the process is running " +
                                        $"({unityVersion} {mode}) is not supported.";
                if (force)
                {
                    List <MonoLibraryOffsets> matchingArchitectureSupportedVersion = SupportedVersions.FindAll(v =>
                                                                                                               v.Is64Bits == is64Bits && v.Format == format);

                    if (matchingArchitectureSupportedVersion.Count > 0)
                    {
                        MonoLibraryOffsets bestCandidate             = matchingArchitectureSupportedVersion[0];
                        UnityVersion       bestCandidateUnityVersion = GetBestCandidate(unityVersion, bestCandidate.UnityVersions);

                        if (matchingArchitectureSupportedVersion.Count > 1)
                        {
                            int bestCandidateYearDistance =
                                Math.Abs(unityVersion.Year - bestCandidateUnityVersion.Year);
                            int bestCandidateVersionWithinYearDistance =
                                Math.Abs(unityVersion.VersionWithinYear - bestCandidateUnityVersion.VersionWithinYear);
                            int bestCandidateSubversionWithinYearDistance =
                                Math.Abs(unityVersion.SubversionWithinYear - bestCandidateUnityVersion.SubversionWithinYear);
                            for (int i = 1; i < matchingArchitectureSupportedVersion.Count; i++)
                            {
                                UnityVersion candidateVersion = GetBestCandidate(unityVersion, matchingArchitectureSupportedVersion[i].UnityVersions);
                                if (
                                    Math.Abs(unityVersion.Year - candidateVersion.Year) < bestCandidateYearDistance ||
                                    (
                                        Math.Abs(unityVersion.Year - candidateVersion.Year) == bestCandidateYearDistance &&
                                        (
                                            Math.Abs(unityVersion.VersionWithinYear - candidateVersion.VersionWithinYear)
                                            < bestCandidateVersionWithinYearDistance ||
                                            (
                                                Math.Abs(unityVersion.VersionWithinYear - candidateVersion.VersionWithinYear)
                                                == bestCandidateVersionWithinYearDistance &&
                                                (
                                                    Math.Abs(unityVersion.SubversionWithinYear - candidateVersion.SubversionWithinYear)
                                                    < bestCandidateSubversionWithinYearDistance
                                                )
                                            )
                                        )
                                    )
                                    )
                                {
                                    bestCandidate             = matchingArchitectureSupportedVersion[i];
                                    bestCandidateYearDistance =
                                        Math.Abs(unityVersion.Year - candidateVersion.Year);
                                    bestCandidateVersionWithinYearDistance =
                                        Math.Abs(unityVersion.VersionWithinYear - candidateVersion.VersionWithinYear);
                                    bestCandidateSubversionWithinYearDistance =
                                        Math.Abs(unityVersion.SubversionWithinYear - candidateVersion.SubversionWithinYear);
                                }
                            }
                        }

                        Console.WriteLine(unsupportedMsg);
                        Console.WriteLine($"Offsets of {bestCandidateUnityVersion.ToString()} selected instead.");

                        return(bestCandidate);
                    }
                }

                throw new NotSupportedException(unsupportedMsg);
            }

            return(monoLibraryOffsets);
        }
Beispiel #3
0
 public static MonoLibraryOffsets GetOffsets(string unityVersion, bool is64Bits, BinaryFormat format, bool force = true)
 {
     return(GetOffsets(UnityVersion.Parse(unityVersion), is64Bits, format, force));
 }