Exemplo n.º 1
0
        public LauncherWindow()
        {
            InitializeComponent();

            launcherDirectory         = Path.GetDirectoryName(PatchUtils.GetCurrentExecutablePath());
            mainAppDirectory          = Path.Combine(launcherDirectory, MAINAPP_SUBDIRECTORY);
            selfPatcherExecutablePath = Path.Combine(launcherDirectory, PatchParameters.SELF_PATCHER_DIRECTORY + Path.DirectorySeparatorChar + "SelfPatcher.exe");

            patchNotesText.Text = string.Empty;
            statusText.Text     = string.Empty;
            progressText.Text   = string.Empty;
            progressBar.Value   = 0;
            patchButton.Enabled = false;

            playButton.Click   += (s, e) => PlayButtonClicked();
            patchButton.Click  += (s, e) => PatchButtonClicked();
            repairButton.Click += (s, e) => RepairButtonClicked();

            if (!string.IsNullOrEmpty(PATCH_NOTES_URL))
            {
                FetchPatchNotes();
            }

            if (!StartLauncherPatch())
            {
                StartMainAppPatch(true);
            }
        }
Exemplo n.º 2
0
        private void xvmPathButton_Click(object sender, EventArgs e)
        {
            //convert actual newlines to "newlines"
            string newReg = Regex.Replace(xvmReplaceBox.Text, @"\n", "newline");

            if (xvmPatchRB.Checked)
            {
                //PatchUtils.XVMPatch(xvmFilePathBox.Text, xvmPathBox.Text, xvmSearchBox.Text, newReg, XVMMode, "", "", true, xvmFilePathBox.Text);
                PatchUtils.XVMPatch(new Patch()
                {
                    completePath = xvmFilePathBox.Text, path = xvmPathBox.Text, search = xvmSearchBox.Text, replace = newReg, mode = XVMMode
                }, true, xvmFilePathBox.Text);
            }
            else if (PMODPatchRB.Checked)
            {
                //PatchUtils.PMODPatch(xvmFilePathBox.Text, xvmPathBox.Text, xvmSearchBox.Text, newReg, XVMMode, "", "", true, xvmFilePathBox.Text);
                PatchUtils.PMODPatch(new Patch()
                {
                    completePath = xvmFilePathBox.Text, path = xvmPathBox.Text, search = xvmSearchBox.Text, replace = newReg, mode = XVMMode
                }, true, xvmFilePathBox.Text);
            }
            else
            {
                //do nothing
            }
        }
 static IEnumerable <CodeInstruction> Draw_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(instructions, typeof(ShopMenu_Patches), new Dictionary <string, string> {
         { nameof(Color.Wheat), nameof(GetSelectedColor) },
         { nameof(Color.Blue), nameof(GetQiSelectedColor) },
     }));
 }
Exemplo n.º 4
0
        private void InitializePatcher()
        {
            patcher = SPTUtils.CreatePatcher(Path.GetDirectoryName(PatchUtils.GetCurrentExecutablePath()), versionInfoURL);

            if (!string.IsNullOrEmpty(versionInfoRSA))
            {
                patcher.UseVersionInfoVerifier(( ref string xml ) => XMLSigner.VerifyXMLContents(xml, versionInfoRSA));
            }

            if (!string.IsNullOrEmpty(patchInfoRSA))
            {
                patcher.UsePatchInfoVerifier(( ref string xml ) => XMLSigner.VerifyXMLContents(xml, patchInfoRSA));
            }

            // = checkVersionOnly =
            // true (default): only version number (e.g. 1.0) is compared against VersionInfo to see if there is an update
            // false: hashes and sizes of the local files are compared against VersionInfo (if there are any different/missing files, we'll patch the app)
            if (patcher.CheckForUpdates(checkVersionOnly))
            {
                StartCoroutine(CheckForUpdatesCoroutine());
            }
            else
            {
                Debug.LogError("Something went wrong");
            }
        }
Exemplo n.º 5
0
        private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> original)
        {
            var ins       = original.ToList();
            var propArray = ins.SkipWhile(x => !x.Calls(typeof(string).Method("Split"))).First(x => PatchUtils.IsLdLoc(x.opcode));
            var endLabel  = ins
                            .SkipWhile(x =>
                                       !x.Calls(typeof(ArrayList).Method("AddRange")))
                            .SkipWhile(x => x.opcode != OpCodes.Br).First().operand;
            var patched = false;

            foreach (var i in ins)
            {
                if (!patched && i.opcode == OpCodes.Ldarg_2)
                {
                    patched = true;
                    foreach (var e in PatchUtils.FireEvent(typeof(PropertyOperationEvent), false,
                                                           new CodeInstruction(OpCodes.Ldarg_0),
                                                           new CodeInstruction(OpCodes.Ldarg_1),
                                                           new CodeInstruction(OpCodes.Ldarg_2),
                                                           propArray
                                                           ))
                    {
                        yield return(e);
                    }

                    yield return(new CodeInstruction(OpCodes.Brfalse, endLabel));
                }
                yield return(i);
            }
        }
Exemplo n.º 6
0
 static IEnumerable <CodeInstruction> Draw_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(instructions, typeof(MineElevatorMenu_Patches), new Dictionary <string, string> {
         { nameof(Color.Gray), nameof(GetCurrentFloorColor) },
         { nameof(Color.Gold), nameof(GetFloorColor) },
     }));
 }
 private static void GetBuildablePrefix(TechType recipe)
 {
     if (CustomBuildables.Contains(recipe) && !CraftData.buildables.Contains(recipe))
     {
         PatchUtils.PatchList(CraftData.buildables, CustomBuildables);
     }
 }
Exemplo n.º 8
0
 private void PatchResultButtonClicked()
 {
     if (Patcher.IsRunning)
     {
         Patcher.Cancel();
         patcherButton.interactable = false;
     }
     //else if( patcher.Result == PatchResult.Failed )
     //{
     //	patcher.Run( patcher.Operation == PatchOperation.SelfPatching );
     //	Initialize( patcher );
     //}
     else if (Patcher.Result == PatchResult.Success && Patcher.Operation == PatchOperation.SelfPatching)
     {
         string selfPatcherPath = SPTUtils.SelfPatcherExecutablePath;
         if (!string.IsNullOrEmpty(selfPatcherPath) && File.Exists(selfPatcherPath))
         {
             Patcher.ApplySelfPatch(selfPatcherPath, PatchUtils.GetCurrentExecutablePath());
         }
         else
         {
             patchResultText.text = "Self patcher does not exist!";
         }
     }
     else
     {
         Destroy(gameObject);
     }
 }
Exemplo n.º 9
0
 private void jsonPatchButton_Click(object sender, EventArgs e)
 {
     //PatchUtils.JSONPatch(jsonFilePathBox.Text, jsonPathBox.Text, jsonSearchBox.Text, jsonReplaceBox.Text, JSONMode, "", "", true, xvmFilePathBox.Text);
     PatchUtils.JSONPatch(new Patch()
     {
         completePath = jsonFilePathBox.Text, path = jsonPathBox.Text, search = jsonSearchBox.Text, replace = jsonReplaceBox.Text, mode = JSONMode
     }, true, xvmFilePathBox.Text);
 }
Exemplo n.º 10
0
        internal static void Patch()
        {
            // Direct access to private fields made possible by https://github.com/CabbageCrow/AssemblyPublicizer/
            // See README.md for details.
            PatchUtils.PatchDictionary(BaseBioReactor.charge, CustomBioreactorCharges);

            Logger.Log("BaseBioReactorPatcher is done.", LogLevel.Debug);
        }
Exemplo n.º 11
0
 static IEnumerable <CodeInstruction> Draw_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(
                instructions: instructions,
                type: typeof(CharacterCustomization_Patches),
                replacements: new Dictionary <string, string> {
         { nameof(Color.Red), nameof(GetErrorTextColor) }
     }
                ));
 }
Exemplo n.º 12
0
 static IEnumerable <CodeInstruction> Draw_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(
                instructions: instructions,
                type: typeof(SpecialOrdersBoard_Patches),
                replacements: new Dictionary <string, string> {
         { nameof(Color.LightPink), nameof(GetHoverColor) }
     }
                ));
 }
 static IEnumerable <CodeInstruction> DrawVersionMismatch_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(
                instructions: instructions,
                type: typeof(LoadGameMenu_Patches),
                replacements: new Dictionary <string, string> {
         { nameof(Color.Red), nameof(GetErrorColor) }
     }
                ));
 }
Exemplo n.º 14
0
 static IEnumerable <CodeInstruction> Draw_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(
                instructions: instructions,
                type: typeof(ExitPage_Patches),
                replacements: new Dictionary <string, string> {
         { nameof(Color.Wheat), nameof(GetHoverColor) }
     }
                ));
 }
Exemplo n.º 15
0
        private IEnumerator ExecutePatch()
        {
            patchButton.interactable = false;
            playButton.interactable  = false;

            patcher.LogProgress(true);
            if (patcher.Run(isPatchingLauncher))
            {
                Debug.Log("Executing patch...");

                while (patcher.IsRunning)
                {
                    FetchLogsFromPatcher();
                    yield return(null);
                }

                FetchLogsFromPatcher();
                playButton.interactable = true;

                if (patcher.Result == PatchResult.AlreadyUpToDate)
                {
                    // If launcher is already up-to-date, check if there is an update for the main app
                    if (isPatchingLauncher)
                    {
                        StartMainAppPatch(true);
                    }
                }
                else if (patcher.Result == PatchResult.Success)
                {
                    // If patcher was self patching the launcher, start the self patcher executable
                    // Otherwise, we have just updated the main app successfully!
                    if (patcher.Operation == PatchOperation.SelfPatching)
                    {
                        string selfPatcherPath = SPTUtils.SelfPatcherExecutablePath;
                        if (!string.IsNullOrEmpty(selfPatcherPath) && File.Exists(selfPatcherPath))
                        {
                            patcher.ApplySelfPatch(selfPatcherPath, PatchUtils.GetCurrentExecutablePath());
                        }
                        else
                        {
                            patcherLogText.text = "Self patcher does not exist!";
                        }
                    }
                }
                else
                {
                    // An error occurred, user can click the Patch button to try again
                    patchButton.interactable = true;
                }
            }
            else
            {
                Debug.LogWarning("Operation could not be started; maybe it is already executing?");
            }
        }
Exemplo n.º 16
0
        private void Awake()
        {
            launcherVersionInfoURL = launcherVersionInfoURL.Trim();
            patchNotesURL          = patchNotesURL.Trim();
            forumURL       = forumURL.Trim();
            websiteURL     = websiteURL.Trim();
            versionInfoRSA = versionInfoRSA.Trim();
            patchInfoRSA   = patchInfoRSA.Trim();

            patchNotesText.text             = "";
            patcherLogText.text             = "";
            patcherProgressText.text        = "";
            patcherProgressbar.value        = 0;
            patcherOverallProgressbar.value = 0;

            forumButton.onClick.AddListener(ForumButtonClicked);
            websiteButton.onClick.AddListener(WebsiteButtonClicked);

            launcherDirectory = Path.GetDirectoryName(PatchUtils.GetCurrentExecutablePath());
            gamesDirectory    = Path.Combine(launcherDirectory, gamesSubdirectory);
            selfPatcherPath   = PatchUtils.GetDefaultSelfPatcherExecutablePath(selfPatcherExecutable);

            string currentVersion = PatchUtils.GetCurrentAppVersion();

            versionCodeText.text = string.IsNullOrEmpty(currentVersion) ? "" : ("v" + currentVersion);

            gameHolders = new MultiGameLauncherGameHolder[games.Length];
            for (int i = 0; i < games.Length; i++)
            {
                games[i].TrimLinks();

                MultiGameLauncherGameHolder gameHolder = (MultiGameLauncherGameHolder)Instantiate(gameHolderPrefab, gameHolderParent, false);
                gameHolder.Initialize(games[i]);
                gameHolder.OnPlayButtonClicked  += PlayButtonClicked;
                gameHolder.OnPatchButtonClicked += PatchButtonClicked;
                gameHolder.PlayButtonSetEnabled(File.Exists(Path.Combine(gamesDirectory, games[i].ExecutablePath)));
                gameHolders[i] = gameHolder;

                StartCoroutine(CheckForUpdates(gameHolder));
            }

            // To resolve a Unity bug
            gamesPanel.gameObject.SetActive(false);
            gamesPanel.gameObject.SetActive(true);

            if (!string.IsNullOrEmpty(patchNotesURL))
            {
                StartCoroutine(FetchPatchNotes());
            }

            // Can't test the launcher on Editor
#if !UNITY_EDITOR
            StartLauncherPatch();
#endif
        }
Exemplo n.º 17
0
 static IEnumerable <CodeInstruction> Draw_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(
                instructions: instructions,
                type: typeof(MoneyDial_Patches),
                replacements: new Dictionary <string, string> {
         { nameof(Color.Gold), nameof(GetSparkleColor) },
         { nameof(Color.Maroon), nameof(GetMoneyColor) }
     }
                ));
 }
Exemplo n.º 18
0
        private static void Initialize()
        {
            PatcherEditor window = GetWindow <PatcherEditor>();

            window.titleContent = new GUIContent("Patcher");
            window.minSize      = new Vector2(300f, 275f);

            window.c_Name    = PatchUtils.IsProjectNameValid(Application.productName) ? Application.productName : "MyProject";
            window.c_Version = Application.version;

            window.Show();
        }
Exemplo n.º 19
0
 static IEnumerable <CodeInstruction> Draw_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(
                instructions: instructions,
                type: typeof(CarpenterMenu_Patches),
                replacements: new Dictionary <string, string> {
         { nameof(Color.Red), nameof(GetErrorTextColor) },
         { nameof(Color.PaleGoldenrod), nameof(GetMagicTextColor) },
         { nameof(Color.RoyalBlue), nameof(GetMagicBackgroundColor) },
     }
                ));
 }
 static IEnumerable <CodeInstruction> Draw_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(
                instructions: instructions,
                type: typeof(OptionsDropDown_Patches),
                replacements: new Dictionary <string, string> {
         { nameof(Color.Wheat), nameof(GetHoverColor) },
     },
                fieldReplacements: new Dictionary <string, string> {
         { nameof(Game1.textColor), nameof(GetTextColor) },
     }.HydrateFieldKeys(typeof(Game1)).HydrateMethodValues(typeof(OptionsDropDown_Patches))
                ));
 }
Exemplo n.º 21
0
        internal static void PrePatch(Harmony harmony)
        {
            PatchUtils.PatchClass(harmony);

#if !SUBNAUTICA_STABLE
            // patching iterator method ProtobufSerializer.DeserializeObjectsAsync
            MethodInfo DeserializeObjectsAsync = typeof(ProtobufSerializer).GetMethod(
                nameof(ProtobufSerializer.DeserializeObjectsAsync), BindingFlags.NonPublic | BindingFlags.Instance);
            harmony.Patch(PatchUtils.GetIteratorMethod(DeserializeObjectsAsync), transpiler:
                          new HarmonyMethod(AccessTools.Method(typeof(PrefabDatabasePatcher), nameof(DeserializeObjectsAsync_Transpiler))));
#endif
            Logger.Log("PrefabDatabasePatcher is done.", LogLevel.Debug);
        }
 static IEnumerable <CodeInstruction> Draw_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(
                instructions: instructions,
                type: typeof(DayTimeMoneyBox_Patches),
                replacements: new Dictionary <string, string> {
         { nameof(Color.Red), nameof(GetAfterMidnightColor) }
     },
                fieldReplacements: new Dictionary <string, string> {
         { nameof(Game1.textColor), nameof(GetTextColor) }
     }.HydrateFieldKeys(typeof(Game1)).HydrateMethodValues(typeof(DayTimeMoneyBox_Patches))
                ));
 }
Exemplo n.º 23
0
        private void ExecutePatch()
        {
            StartThread(() =>
            {
                ButtonSetEnabled(patchButton, false);
                ButtonSetEnabled(playButton, false);

                patcher.LogProgress(true);
                if (patcher.Run(isPatchingLauncher))
                {
                    while (patcher.IsRunning)
                    {
                        FetchLogsFromPatcher();
                        Thread.Sleep(500);
                    }

                    FetchLogsFromPatcher();
                    ButtonSetEnabled(playButton, true);

                    if (patcher.Result == PatchResult.AlreadyUpToDate)
                    {
                        // If launcher is already up-to-date, check if there is an update for the main app
                        if (isPatchingLauncher)
                        {
                            StartMainAppPatch(true);
                        }
                    }
                    else if (patcher.Result == PatchResult.Success)
                    {
                        // If patcher was self patching the launcher, start the self patcher executable
                        // Otherwise, we have just updated the main app successfully!
                        if (patcher.Operation == PatchOperation.SelfPatching)
                        {
                            if (!string.IsNullOrEmpty(selfPatcherExecutablePath) && File.Exists(selfPatcherExecutablePath))
                            {
                                patcher.ApplySelfPatch(selfPatcherExecutablePath, PatchUtils.GetCurrentExecutablePath());
                            }
                            else
                            {
                                UpdateLabel(progressText, "Self patcher does not exist!");
                            }
                        }
                    }
                    else
                    {
                        // An error occurred, user can click the Patch button to try again
                        ButtonSetEnabled(patchButton, true);
                    }
                }
            });
        }
Exemplo n.º 24
0
 static IEnumerable <CodeInstruction> Draw_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(
                instructions: instructions,
                type: typeof(SkillsPage_Patches),
                replacements: new Dictionary <string, string> {
         { nameof(Color.LightGreen), nameof(GetModifiedNumberColor) },
         { nameof(Color.SandyBrown), nameof(GetNumberColor) }
     },
                fieldReplacements: new Dictionary <string, string> {
         { nameof(Game1.textColor), nameof(GetTextColor) }
     }.HydrateFieldKeys(typeof(Game1)).HydrateMethodValues(typeof(SkillsPage_Patches))
                ));
 }
Exemplo n.º 25
0
        internal static void Patch(Harmony harmony)
        {
            PatchUtils.PatchClass(harmony);
            PatchUtils.PatchClass(harmony, typeof(ScrollPosKeeper));

            if (QModServices.Main.FindModById("ModsOptionsAdjusted")?.Enable == true)
            {
                V2.Logger.Log("ModOptionsAdjuster is not inited (ModsOptionsAdjusted mod is active)", LogLevel.Warn);
            }
            else
            {
                PatchUtils.PatchClass(harmony, typeof(ModOptionsHeadingsToggle));
            }
        }
Exemplo n.º 26
0
 static IEnumerable <CodeInstruction> CraftingRecipe_drawDescription_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(
                instructions: instructions,
                type: typeof(IClickableMenu_Patches),
                replacements: new Dictionary <string, string> {
         { nameof(Color.Red), nameof(GetInsufficientColor) }
     },
                fieldReplacements: new Dictionary <string, string> {
         { nameof(Game1.textColor), nameof(GetTextColor) },
         { nameof(Game1.textShadowColor), nameof(GetShadowColor) }
     }.HydrateFieldKeys(typeof(Game1)).HydrateMethodValues(typeof(IClickableMenu_Patches))
                ));
 }
Exemplo n.º 27
0
 static IEnumerable <CodeInstruction> DrawHoverText_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(
                instructions: instructions,
                type: typeof(IClickableMenu_Patches),
                replacements: new Dictionary <string, string> {
         { nameof(Color.DimGray), nameof(GetForgeCountTextColor) },
         { nameof(Color.DarkRed), nameof(GetForgedTextColor) }
     },
                fieldReplacements: new Dictionary <string, string> {
         { nameof(Game1.textColor), nameof(GetTextColor) },
         { nameof(Game1.textShadowColor), nameof(GetShadowColor) }
     }.HydrateFieldKeys(typeof(Game1)).HydrateMethodValues(typeof(IClickableMenu_Patches))
                ));
 }
Exemplo n.º 28
0
 static IEnumerable <CodeInstruction> Draw_Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(PatchUtils.ReplaceColors(
                instructions,
                typeof(Billboard_Patches),
                new Dictionary <string, string> {
         { nameof(Color.Gray), nameof(GetDimColor) },
         { nameof(Color.Blue), nameof(GetTodayColor) },
         { nameof(Color.LightPink), nameof(GetHoverColor) },
     },
                fieldReplacements: new Dictionary <string, string> {
         { nameof(Game1.textColor), nameof(GetTextColor) }
     }.HydrateFieldKeys(typeof(Game1)).HydrateMethodValues(typeof(Billboard_Patches))
                ));
 }
 private static void DictionaryPrefix <T>(TechType techType, IDictionary <TechType, T> smlCollection, IDictionary <TechType, T> craftDataCollection)
 {
     if (smlCollection.TryGetValue(techType, out T sml))
     {
         if (craftDataCollection.TryGetValue(techType, out T gameVal))
         {
             if (!sml.Equals(gameVal))
             {
                 craftDataCollection[techType] = sml;
             }
         }
         else
         {
             PatchUtils.PatchDictionary(craftDataCollection, smlCollection);
         }
     }
 }
Exemplo n.º 30
0
        public void RunSelfPatcherExecutable()
        {
            if (!IsSelfPatchingApp)
            {
                return;
            }

#if UNITY_EDITOR
            Debug.LogError("Can't self patch while testing on editor");
#else
            string postSelfPatchExecutable = RestartAppAfterSelfPatching ? PatchUtils.GetCurrentExecutablePath() : null;
            if (!Patcher.ApplySelfPatch(PatchUtils.GetDefaultSelfPatcherExecutablePath(SelfPatcherExecutable), postSelfPatchExecutable))
            {
                Debug.LogError("Patcher is already running or something went wrong");
            }
#endif
        }