コード例 #1
0
        /// <summary>
        /// Checks if the game is not patched
        /// </summary>
        /// <returns>True if the game is not patched or false if it is. Null is returned if the game file can not be found or if neither the original or patched bytes are found.</returns>
        public bool?GetIsOriginal()
        {
            RL.Logger?.LogInformationSource("Getting if game file is patched or original...");

            try
            {
                // Get the file size
                var fileSize = (uint)GameFile.GetSize().Bytes;

                // Find matching patch
                var patch = Patches.FirstOrDefault(x => x.FileSize == fileSize);

                if (patch == null)
                {
                    RL.Logger?.LogWarningSource("The game file size does not match any available patch");
                    return(null);
                }

                // Create a buffer
                byte[] currentBytes = new byte[patch.OriginalBytes.Length];

                // Open the file as a stream
                using (Stream stream = File.Open(GameFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    // Set the position
                    stream.Position = patch.PatchOffset;

                    // Read the bytes
                    var read = stream.Read(currentBytes, 0, currentBytes.Length);

                    RL.Logger?.LogInformationSource($"{read}/{currentBytes.Length} bytes were read from the game file");
                }

                // Check if they match
                if (currentBytes.SequenceEqual(patch.OriginalBytes))
                {
                    RL.Logger?.LogInformationSource("The game file was detected as original");
                    return(true);
                }
                else if (currentBytes.SequenceEqual(patch.PatchedBytes))
                {
                    RL.Logger?.LogInformationSource("The game file was detected as patched");
                    return(false);
                }
                else
                {
                    RL.Logger?.LogWarningSource("The game file was detected as unknown");
                    return(null);
                }
            }
            catch (Exception ex)
            {
                ex.HandleError("Getting if game is patched");
                return(null);
            }
        }
コード例 #2
0
    public PatchState GetPatchState()
    {
        Logger.Info("Getting if game file is patched or original");

        try
        {
            // Get the file size
            uint fileSize = (uint)GameFile.GetSize().Bytes;

            // Find matching patch
            int patchIndex = Patches.FindItemIndex(x => x.FileSize == fileSize);

            if (patchIndex == -1)
            {
                Logger.Warn("The game file size does not match any available patch");
                return(null);
            }

            FilePatcher_Patch patch = Patches[patchIndex];

            // IDEA: Check all patch entries?
            // Check the first patch entry
            FilePatcher_Patch.PatchEntry patchEntry = patch.PatchEntries[0];

            // Create a buffer
            byte[] currentBytes = new byte[patchEntry.OriginalBytes.Length];

            // Open the file as a stream
            using (Stream stream = File.Open(GameFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                // Set the position
                stream.Position = patchEntry.PatchOffset;

                // Read the bytes
                int read = stream.Read(currentBytes, 0, currentBytes.Length);

                Logger.Info("{0}/{1} bytes were read from the game file", read, currentBytes.Length);
            }

            // Check if they match the original
            if (currentBytes.SequenceEqual(patchEntry.OriginalBytes))
            {
                Logger.Info("The game file was detected as original");
                return(new PatchState(patchIndex, false));
            }

            // Check if it's patches, checking revisions starting with newest first
            bool isOutdated = false;
            foreach (FilePatcher_Patch.PatchedBytesRevision revision in patchEntry.PatchRevisions.OrderByDescending(x => x.Version))
            {
                if (currentBytes.SequenceEqual(revision.Bytes))
                {
                    Logger.Info($"The game file was detected as patched with version {revision.Version}");
                    return(new PatchState(patchIndex, true, revision.Version, isOutdated));
                }

                isOutdated = true;
            }

            Logger.Warn("The game file patch state could not be determined");
            return(null);
        }
        catch (Exception ex)
        {
            Logger.Error(ex, "Getting if game is patched");
            return(null);
        }
    }