From 9da008adcad456b3e99eefbe4a0e7e828c2f3053 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 +- src/UnrealSDK.cpp | 11 +++++------ src/include/Games.h | 10 ++++++---- src/main.cpp | Bin 5254 -> 5362 bytes 6 files changed, 38 insertions(+), 22 deletions(-) diff --git a/Mods/ModMenu/MenuManager.py b/Mods/ModMenu/MenuManager.py index adafd3df..83e102ad 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 f9e672b0..46188d8f 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 60f2aef4..4286ba48 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}") diff --git a/src/UnrealSDK.cpp b/src/UnrealSDK.cpp index d47520cc..1cd6375b 100644 --- a/src/UnrealSDK.cpp +++ b/src/UnrealSDK.cpp @@ -196,14 +196,16 @@ namespace UnrealSDK try { void* SetCommand = sigscan.Scan(Signatures::SetCommand); - DWORD near out = 0; - if (!VirtualProtectEx(GetCurrentProcess(), SetCommand, 5, 0x40, &out)) + Logging::LogF("[Internal] SetCommand = 0x%p\n", SetCommand); + DWORD oldProtect = 0; + if (!VirtualProtectEx(GetCurrentProcess(), SetCommand, 7, PAGE_EXECUTE_READWRITE, &oldProtect)) { Logging::LogF("WINAPI Error when enabling 'SET' commands: %d\n", GetLastError()); } else { - static_cast(SetCommand)[5] = 0xFF; + static_cast(SetCommand)[5] = 0x90; + static_cast(SetCommand)[6] = 0x90; } } catch (std::exception e) @@ -280,9 +282,6 @@ namespace UnrealSDK if (!strcmp(Object->GetFullName().c_str(), ObjectMap["EngineFullName"].c_str())) gEngine = Object; } -#ifdef _DEBUG - Logging::InitializeExtern(); -#endif initializeGameVersions(); diff --git a/src/include/Games.h b/src/include/Games.h index 9885881c..27347f43 100644 --- a/src/include/Games.h +++ b/src/include/Games.h @@ -19,9 +19,9 @@ static std::map bl2_signatures{{ }}, { "SetCommand", { - "\xFF\x83\xC4\x0C\x85\xC0\x75\x1A\x6A\x01\x8D", - "xxxxxxxxxxx", - 11 + "\x83\xC4\x0C\x85\xC0\x75\x1A\x6A\x01\x8D", + "xxxxxxxxxx", + 10 }}, { "ProcessEvent", { @@ -95,7 +95,8 @@ static std::map tps_signatures{ { static std::map> game_signature_map{ {"Borderlands2", bl2_signatures}, - {"BorderlandsPreSequel", tps_signatures} + {"BorderlandsPreSequel", tps_signatures}, + {"TinyTina", tps_signatures} }; static std::map bl2_object_map{ @@ -110,4 +111,5 @@ static std::map bl2_object_map{ static std::map> game_object_map{ {"Borderlands2", bl2_object_map}, {"BorderlandsPreSequel", bl2_object_map}, + {"TinyTina", bl2_object_map} }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ea2a176c2fd7e8d5880e59d6285ab3bef1131198..f1b9abec59f6128afb15a82eac0d19a34ca5dc67 100644 GIT binary patch delta 80 zcmZqE{G_?z5x=A|LncESLkdGGkW^rZXK-O~WpH8$WpJPTkY93g2fv7-D? eA&)_WL6gCnftP`cK^Z8L2h<1Dz4R#0zE7MJ(C7c