Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
Attack on Dragon Keep Standalone Support (#98)
Browse files Browse the repository at this point in the history
* preliminary aodk support

* fixed input eating

whoever wrote this hex edit should be ashamed of themselves
  • Loading branch information
apple1417 authored Nov 11, 2021
1 parent f5d8296 commit 9da008a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 deletions.
16 changes: 13 additions & 3 deletions Mods/ModMenu/MenuManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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"))

Expand Down Expand Up @@ -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)
Expand Down
21 changes: 13 additions & 8 deletions Mods/ModMenu/ModObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -228,7 +235,6 @@ def Enable(self) -> None:
"""
HookManager.RegisterHooks(self)
NetworkManager.RegisterNetworkMethods(self)
pass

def Disable(self) -> None:
"""
Expand All @@ -237,7 +243,6 @@ def Disable(self) -> None:
"""
HookManager.RemoveHooks(self)
NetworkManager.UnregisterNetworkMethods(self)
pass

def SettingsInputPressed(self, action: str) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion Mods/ModMenu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
11 changes: 5 additions & 6 deletions src/UnrealSDK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char *>(SetCommand)[5] = 0xFF;
static_cast<unsigned char *>(SetCommand)[5] = 0x90;
static_cast<unsigned char *>(SetCommand)[6] = 0x90;
}
}
catch (std::exception e)
Expand Down Expand Up @@ -280,9 +282,6 @@ namespace UnrealSDK
if (!strcmp(Object->GetFullName().c_str(), ObjectMap["EngineFullName"].c_str()))
gEngine = Object;
}
#ifdef _DEBUG
Logging::InitializeExtern();
#endif

initializeGameVersions();

Expand Down
10 changes: 6 additions & 4 deletions src/include/Games.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ static std::map<std::string, MemorySignature> 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", {
Expand Down Expand Up @@ -95,7 +95,8 @@ static std::map<std::string, MemorySignature> tps_signatures{ {

static std::map<std::string, std::map<std::string, MemorySignature>> game_signature_map{
{"Borderlands2", bl2_signatures},
{"BorderlandsPreSequel", tps_signatures}
{"BorderlandsPreSequel", tps_signatures},
{"TinyTina", tps_signatures}
};

static std::map<std::string, std::string> bl2_object_map{
Expand All @@ -110,4 +111,5 @@ static std::map<std::string, std::string> bl2_object_map{
static std::map<std::string, std::map<std::string, std::string>> game_object_map{
{"Borderlands2", bl2_object_map},
{"BorderlandsPreSequel", bl2_object_map},
{"TinyTina", bl2_object_map}
};
Binary file modified src/main.cpp
Binary file not shown.

0 comments on commit 9da008a

Please sign in to comment.