From 48973ecf36c160eecb4bf0e0aa26c2d856f378aa Mon Sep 17 00:00:00 2001 From: apple1417 Date: Thu, 11 Nov 2021 22:10:22 +1300 Subject: [PATCH] Attack on Dragon Keep Standalone Support (#98) * preliminary aodk support * fixed input eating whoever wrote this hex edit should be ashamed of themselves --- Mods/ModMenu/MenuManager.py | 16 +++++++++++++--- Mods/ModMenu/ModObjects.py | 21 +++++++++++++-------- Mods/ModMenu/__init__.py | 2 +- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Mods/ModMenu/MenuManager.py b/Mods/ModMenu/MenuManager.py index adafd3d..83e102a 100644 --- a/Mods/ModMenu/MenuManager.py +++ b/Mods/ModMenu/MenuManager.py @@ -65,6 +65,9 @@ class _General(ModObjects.SDKMod): ) Version: str = f"{VERSION_MAJOR}.{VERSION_MINOR}" + SupportedGames: ModObjects.Game = ( + ModObjects.Game.BL2 | ModObjects.Game.TPS | ModObjects.Game.AoDK + ) Types: ModObjects.ModTypes = ModObjects.ModTypes.All Status: str = "" @@ -75,7 +78,7 @@ class _General(ModObjects.SDKMod): def SettingsInputPressed(self, action: str) -> None: if action == "Help": - webbrowser.open("http://borderlandsmodding.com/sdk-mods/") + webbrowser.open("http://bl-sdk.github.io/") elif action == "Open Mods Folder": os.startfile(os.path.join(os.path.dirname(sys.executable), "Mods")) @@ -157,10 +160,17 @@ def AddListItem(caller: unrealsdk.UObject, function: unrealsdk.UFunction, params Using it cause it simplifies the code to replace the caption. """ if params.Caption == "$WillowMenu.WillowScrollingListDataProviderFrontEnd.DLC": - unrealsdk.DoInjectedCallNext() - caller.AddListItem(_MODS_EVENT_ID, _MODS_MENU_NAME, False, False) return False + inject_now = False + if unrealsdk.GetEngine().GetCurrentWorldInfo().NetMode == 3: # NM_Client + inject_now = params.Caption == "$WillowMenu.WillowScrollingListDataProviderFrontEnd.Disconnect" + else: + inject_now = params.Caption == "$WillowMenu.WillowScrollingListDataProviderFrontEnd.Quit" + + if inject_now: + caller.AddListItem(_MODS_EVENT_ID, _MODS_MENU_NAME, False, False) + return True unrealsdk.RunHook("WillowGame.WillowScrollingList.AddListItem", "ModMenu.MenuManager", AddListItem) diff --git a/Mods/ModMenu/ModObjects.py b/Mods/ModMenu/ModObjects.py index f9e672b..46188d8 100644 --- a/Mods/ModMenu/ModObjects.py +++ b/Mods/ModMenu/ModObjects.py @@ -5,6 +5,7 @@ import json import sys from abc import ABCMeta +from functools import lru_cache from os import path from typing import Any, Callable, Dict, List, Optional, Sequence, Set, Tuple, cast @@ -78,17 +79,23 @@ class EnabledSaveType(enum.Enum): class Game(enum.Flag): BL2 = enum.auto() TPS = enum.auto() + AoDK = enum.auto() @staticmethod + @lru_cache(None) def GetCurrent() -> Game: """ Gets the current game. """ + lower_exe_names: Dict[str, Game] = { + "borderlands2.exe": Game.BL2, + "borderlandspresequel.exe": Game.TPS, + "tinytina.exe": Game.AoDK, + } + exe = path.basename(sys.executable) exe_lower = exe.lower() - if exe_lower == "borderlands2.exe": - return Game.BL2 - elif exe_lower == "borderlandspresequel.exe": - return Game.TPS - raise RuntimeError(f"Unknown executable name '{exe}'!") + if exe_lower not in lower_exe_names: + raise RuntimeError(f"Unknown executable name '{exe}'!") + return lower_exe_names[exe_lower] class _ModMeta(ABCMeta): @@ -172,7 +179,7 @@ class SDKMod(metaclass=_ModMeta): Description: str = "" Version: str = "Unknown Version" - SupportedGames: Game = Game.BL2 | Game.TPS + SupportedGames: Game = Game.BL2 | Game.TPS | Game.AoDK Types: ModTypes = ModTypes.NONE Priority: int = ModPriorities.Standard SaveEnabledState: EnabledSaveType = EnabledSaveType.NotSaved @@ -228,7 +235,6 @@ def Enable(self) -> None: """ HookManager.RegisterHooks(self) NetworkManager.RegisterNetworkMethods(self) - pass def Disable(self) -> None: """ @@ -237,7 +243,6 @@ def Disable(self) -> None: """ HookManager.RemoveHooks(self) NetworkManager.UnregisterNetworkMethods(self) - pass def SettingsInputPressed(self, action: str) -> None: """ diff --git a/Mods/ModMenu/__init__.py b/Mods/ModMenu/__init__.py index 60f2aef..4286ba4 100644 --- a/Mods/ModMenu/__init__.py +++ b/Mods/ModMenu/__init__.py @@ -37,7 +37,7 @@ # Need to define these up here so that they're accessable when importing the other files VERSION_MAJOR = 2 -VERSION_MINOR = 4 +VERSION_MINOR = 5 unrealsdk.Log(f"[ModMenu] Version: {VERSION_MAJOR}.{VERSION_MINOR}")