Esempio n. 1
0
    def __init__(self) -> None:
        preset_option = Options.Hidden("Presets", StartingValue=[])
        self.Options = [preset_option] + ALL_OPTIONS  # type: ignore

        # Load settings once for the set of presets
        LoadModSettings(self)

        self.CheatPresetManager = PresetManager(preset_option, ALL_CHEATS)

        # This is a kind of hacky way for the preset manager to interface with the keybinds system
        # Output from the preset manager is html-escaped, the keybind menu doesn't use html, so this
        #  stuff all has to convert it
        def AddPresetKeybind(name: str) -> None:
            self.Keybinds.append(Keybind(html.unescape(name)))
            SaveModSettings(self)

        def RenamePresetKeybind(oldName: str, newName: str) -> None:
            for bind in self.Keybinds:
                if bind.Name == html.unescape(oldName):
                    bind.Name = html.unescape(newName)
            SaveModSettings(self)

        def RemovePresetKeybind(name: str) -> None:
            for bind in self.Keybinds:
                if bind.Name == html.unescape(name):
                    self.Keybinds.remove(bind)
            SaveModSettings(self)

        self.CheatPresetManager.AddKeybind = AddPresetKeybind  # type: ignore
        self.CheatPresetManager.RenameKeybind = RenamePresetKeybind  # type: ignore
        self.CheatPresetManager.RemoveKeybind = RemovePresetKeybind  # type: ignore
        self.CheatPresetManager.SaveOptions = lambda: SaveModSettings(
            self)  # type: ignore

        self.Keybinds = []
        for cheat in ALL_CHEATS:
            self.Keybinds.append(Keybind(cheat.KeybindName))

        for preset in self.CheatPresetManager.PresetList:
            self.Keybinds.append(Keybind(html.unescape(preset.Name)))

        # Load settings again to fill in the keybinds
        LoadModSettings(self)
        self._initalized = True
Esempio n. 2
0
    def __init__(self) -> None:
        self.TaskOption = Options.Hidden(
            "Tasks",
            StartingValue={
                "OnMainMenu": {
                    "Tasks": []
                },
                "OnLaunch": {
                    "Comment": [
                        "Congratulations, you found the secret file where you can setup tasks to run on launch.",
                        " This is not editable ingame because exec-ing mods before the main menu tends to cause",
                        " a crash, but if you really want you can edit the `Tasks` array here at your own risk."
                    ],
                    "Tasks": []
                }
            })
        self.Options = [self.TaskOption]
        LoadModSettings(self)

        # Load from the legacy settings file
        config_file = os.path.join(os.path.dirname(GetSettingsFilePath(self)),
                                   "config.json")
        try:
            with open(config_file) as file:
                loaded_settings = json.load(file)

                try:
                    if loaded_settings["IsEnabled"]:
                        self.SettingsInputPressed("Enable")
                except KeyError:
                    pass

                try:
                    self.TaskOption.CurrentValue["OnMainMenu"][
                        "Tasks"] = loaded_settings["OnMainMenu"]["Tasks"]
                    self.TaskOption.CurrentValue["OnLaunch"][
                        "Tasks"] = loaded_settings["OnLaunch"]["Tasks"]
                except KeyError:
                    pass
            SaveModSettings(self)
            os.remove(config_file)
        except json.JSONDecodeError:
            os.remove(config_file)
        except FileNotFoundError:
            pass

        self.LaunchTasks = []
        self.MainMenuTasks = []

        any_errors = False
        for task in self.TaskOption.CurrentValue["OnMainMenu"]["Tasks"]:
            try:
                task_obj = Tasks.NAME_TASK_MAP[task["Type"]]()  # type: ignore
                success = task_obj.FromJSONSerializable(task["Value"])
                if not success:
                    any_errors = True
                    continue
                self.MainMenuTasks.append(task_obj)
            except KeyError:
                any_errors = True

        for task in self.TaskOption.CurrentValue["OnLaunch"]["Tasks"]:
            try:
                task_obj = Tasks.NAME_TASK_MAP[task["Type"]]()  # type: ignore
                success = task_obj.FromJSONSerializable(task["Value"])
                if not success:
                    any_errors = True
                    continue
                self.LaunchTasks.append(task_obj)
            except KeyError:
                any_errors = True

        if any_errors:
            UserFeedback.TrainingBox(
                "SDK Autorun Error",
                "One or more tasks was unable to be parsed and thus will be skipped."
            ).Show()

        if self.IsEnabled and not any_errors:
            self.Execute(self.LaunchTasks)

            def OnMainMenu(caller: unrealsdk.UObject,
                           function: unrealsdk.UFunction,
                           params: unrealsdk.FStruct) -> bool:
                self.Execute(self.MainMenuTasks)
                unrealsdk.RemoveHook("WillowGame.FrontendGFxMovie.Start",
                                     self.Name)
                return True

            unrealsdk.RegisterHook("WillowGame.FrontendGFxMovie.Start",
                                   self.Name, OnMainMenu)
Esempio n. 3
0
 def __init__(self) -> None:
     self.CompressOption = Options.Hidden("CompressSaves",
                                          StartingValue=True)
     self.Options = [self.CompressOption]
Esempio n. 4
0
 def __init__(self) -> None:
     self.CheatOptions = [Options.Hidden("Disable One Shot Mode in TPS", StartingValue=False)]