示例#1
0
        private static void ConvertPatchFile(string otherExe)
        {
            UserFeedback.Info(@"Converting RootPatch file to a patch file for '{0}'", otherExe);
            var rootPatchFilePath = FindRootPatchFile();

            UserFeedback.Trace(@"Reading the root patch file");
            var patch = Patcher.ReadPatch(rootPatchFilePath, true);

            UserFeedback.Trace(@"Locating the root executable file");
            var rootExePath = FindExeFile(patch.FileSize, patch.Md5);

            UserFeedback.Trace(@"Reading the target executable");
            var exe2 = File.ReadAllBytes(otherExe);

            UserFeedback.Trace(@"Reading root executable");
            var exe1 = File.ReadAllBytes(rootExePath);

            var md5 = GetChecksum(exe2);

            UserFeedback.Trace(@"Detecting version from filename and/or md5");
            string version = GetVersion(otherExe, md5);
            UserFeedback.Trace(@"Version: '{0}'", version);

            var rootMd5 = GetChecksum(exe1);
            Patch newPatch;
            if (rootMd5.Equals(md5))
            {
                UserFeedback.Trace(@"Executable is equal; leaving patch file as-is");
                newPatch = new Patch
                               {
                                   FileSize = patch.FileSize,
                                   InterfaceDrsPosition = patch.InterfaceDrsPosition,
                                   Items = patch.Items,
                                   Md5 = patch.Md5
                               };
            }
            else
            {
                UserFeedback.Trace(@"Locating comparable locations, this may take a while");
                newPatch = Patcher.ConvertPatch(exe1, exe2, patch);
                newPatch.FileSize = exe2.Length;
                newPatch.Md5 = md5;
            }
            newPatch.Version = version;

            var patchFileName = @"AoE2Wide_" + version + @".patch";

            var patchOutput = Path.Combine(Path.GetDirectoryName(otherExe), patchFileName);
            UserFeedback.Trace("Writing the patch file '{0}'", patchOutput);
            Patcher.WritePatch(newPatch, patchOutput);
        }
示例#2
0
        private static Patch FindPatchForExe(int exeFileSize, string exeMd5, string exeFilenameForFeedback)
        {
            if (patchFiles == null)
                patchFiles = FindPatchFiles();

            if (allPatches == null)
                allPatches = patchFiles.Select(patchFile => Patcher.TryReadPatch(patchFile, true)).ToArray();

            var matchingPatches = allPatches.Where(patch => patch.FileSize == exeFileSize && patch.Md5.Equals(exeMd5)).ToArray();

            if (matchingPatches.Length == 0)
                return null;

            if (matchingPatches.Length == 1)
                return matchingPatches[0];

            UserFeedback.Warning("Multiple matching patches found for executable '{0}', using first:", exeFilenameForFeedback);
            foreach (var mp in matchingPatches)
                UserFeedback.Trace("* {0}", mp.PatchFilepath);

            return matchingPatches[0];
        }
示例#3
0
        private static void AddAsmToRootPatchFile()
        {
            UserFeedback.Info(@"Locating listing file");
            var lstFile = FindFile("listing file", "age2_x1*.lst", null, null);

            UserFeedback.Info(@"Locating RootPatch file");
            var rootPatchFilePath = FindRootPatchFile();

            UserFeedback.Trace(@"Reading the root patch file");
            var patch = Patcher.ReadPatch(rootPatchFilePath, false);

            UserFeedback.Trace(@"Reading the listing file");
            var asmMap = Patcher.ReadAsmMap(lstFile);

            UserFeedback.Trace(@"Adding Asm to the patch data");
            Patcher.AddAsm(patch, asmMap);

            var outputRootPatchFilePath = rootPatchFilePath + "2";

            UserFeedback.Trace("Writing the patch file '{0}'", outputRootPatchFilePath);
            Patcher.WritePatch(patch, outputRootPatchFilePath);
        }
示例#4
0
        private static void PatchExecutable(int newWidth, int newHeight, Patch patch)
        {
            try
            {
                int oldWidth, oldHeight;
                GetOldWidthHeight(newWidth, newHeight, out oldWidth, out oldHeight);

                UserFeedback.Info(string.Format(@"Changing {0}x{1} to {2}x{3}", oldWidth, oldHeight, newWidth, newHeight));

                UserFeedback.Trace(@"Reading original executable");
                var exe = File.ReadAllBytes(_orgExePath);

                var versionString = patch.Version.Length == 0 ? "" : patch.Version + "_";

                var newDrsName = Path.Combine(Path.Combine(_gameDirectory, @"Data"), string.Format(@"{0:D4}{1:D4}.drs", newWidth, newHeight));
                var newX1DrsName = Path.Combine(Path.Combine(_gameDirectory, @"Data"), string.Format(@"{0:D4}{1:D4}_x1.drs", newWidth, newHeight));
                var newExeName = Path.Combine(_gameDirectory,
                                              string.Format(@"age2_x1_{2}{0}x{1}.exe", newWidth, newHeight,
                                                            versionString));

                var batchName = Path.Combine(_gameDirectory,
                                              string.Format(@"AoC{2} {0}x{1}.bat", newWidth, newHeight,
                                                            patch.Version));

                var desktopBatchName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                                              string.Format(@"AoC{2} {0}x{1}.bat", newWidth, newHeight,
                                                            patch.Version));
                //Trace(@"Writing file with all occurrences of resolutions");
                //Patcher.ListEm(bytes);

                UserFeedback.Trace("Patching the executable: DRS reference");
                Patcher.PatchDrsRefInExe(exe, Path.GetFileName(newDrsName), patch);

                if (patch.InterfaceX1DrsPosition > 0)
                {
                    UserFeedback.Trace("Patching the executable: X1 DRS reference");
                    Patcher.PatchX1DrsRefInExe(exe, Path.GetFileName(newX1DrsName), patch);
                }

                UserFeedback.Trace("Patching the executable: resolutions");
                Patcher.PatchResolutions(exe, oldWidth, oldHeight, newWidth, newHeight, patch);

                UserFeedback.Trace(string.Format(@"Writing the patched executable '{0}'", newExeName));
                File.WriteAllBytes(newExeName, exe);

                if (skipExistingFiles && File.Exists(batchName))
                {
                    UserFeedback.Trace(@"Skipping existing convenience batch file '{0}'", batchName);
                }
                else
                {
                    UserFeedback.Trace(@"Writing convenience batch file '{0}'", batchName);
                    var batContent = new List<string> {@"@echo off"};

                    var processExe = IsVistaOrHigher ? FindProcessExe() : null;

                    if (processExe != null)
                    {
                        batContent.Add(
                            @"ECHO Using process.exe to suspend explorer.exe (win7, vista palette fix)");
                        batContent.Add(string.Format("\"{0}\" -s explorer.exe", processExe));
                    }

                    batContent.Add(@"ECHO Starting Age of Empires II - The Conquerers in the correct screen mode");
                    batContent.Add(string.Format("\"{0}\" {1}", Path.GetFileName(newExeName), oldWidth));

                    if (processExe != null)
                    {
                        batContent.Add(@"ECHO Resuming explorer (was suspended before)");
                        batContent.Add(string.Format("\"{0}\" -r explorer.exe", processExe));
                    }

                    File.WriteAllLines(batchName, batContent.ToArray());
                }

                if (skipExistingFiles && File.Exists(desktopBatchName))
                {
                    UserFeedback.Trace(@"Skipping existing convenience desktop batch file '{0}'", desktopBatchName);
                }
                else
                {
                    var driveLetter = Path.GetPathRoot(_gameDirectory);
                    driveLetter = driveLetter.Replace(Path.DirectorySeparatorChar, ' ');
                    UserFeedback.Trace(@"Writing convenience desktop batch file '{0}'", desktopBatchName);
                    var batContent = new List<string>
                                         {
                                             @"@echo off",
                                             driveLetter,
                                             string.Format("cd \"{0}\"", _gameDirectory)
                                         };

                    var processExe = IsVistaOrHigher ? FindProcessExe() : null;

                    if (processExe != null)
                    {
                        batContent.Add(
                            @"ECHO Using process.exe to suspend explorer.exe (win7, vista palette fix)");
                        batContent.Add(string.Format("\"{0}\" -s explorer.exe", processExe));
                    }

                    batContent.Add(@"ECHO Starting Age of Empires II - The Conquerers in the correct screen mode");
                    batContent.Add(string.Format("\"{0}\" {1}", Path.GetFileName(newExeName), oldWidth));

                    if (processExe != null)
                    {
                        batContent.Add(@"ECHO Resuming explorer (was suspended before)");
                        batContent.Add(string.Format("\"{0}\" -r explorer.exe", processExe));
                    }

                    File.WriteAllLines(desktopBatchName, batContent.ToArray());
                }

                if (skipExistingFiles && File.Exists(newDrsName))
                {
                    UserFeedback.Info(@"Patched drs file '{0}' exists already, skipping.", newDrsName);
                }
                else
                {
                    PatchADrs(_orgDrsPath, newDrsName, oldWidth, oldHeight, newWidth, newHeight);
                }

                if (patch.InterfaceX1DrsPosition > 0)
                {
                    if (skipExistingFiles && File.Exists(newX1DrsName))
                    {
                        UserFeedback.Info(@"Patched X1 drs file '{0}' exists already, skipping.", newX1DrsName);
                    }
                    else
                    {
                        PatchADrs(_orgX1DrsPath, newX1DrsName, oldWidth, oldHeight, newWidth, newHeight);
                    }
                }

                try
                {
                    var pubDir = Path.Combine(_gameDirectory, @"donePatches");
                    if (Directory.Exists(pubDir))
                    {
                        var specificPubDir = Path.Combine(pubDir, string.Format(@"{0}x{1}", newWidth, newHeight));
                        if (!Directory.Exists(specificPubDir))
                            Directory.CreateDirectory(specificPubDir);

                        var specificPubDataDir = Path.Combine(specificPubDir, @"Data");
                        if (!Directory.Exists(specificPubDataDir))
                            Directory.CreateDirectory(specificPubDataDir);

                        var pubExePath = Path.Combine(specificPubDir, Path.GetFileName(newExeName));
                        var pubDrsPath = Path.Combine(specificPubDataDir, Path.GetFileName(newDrsName));

                        File.Copy(newExeName, pubExePath, true);
                        File.Copy(newDrsName, pubDrsPath, true);
                    }
                }
                catch (Exception e)
                {
                    UserFeedback.Warning("Couldn't publish: {0}", e.ToString());
                }

                UserFeedback.Trace("Done");
            }
            catch (Exception e)
            {
                UserFeedback.Error(e);
            }
        }