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

Commit 2c3cd47

Browse files
authored
Improved installation instructions, fixed disconnected player message crashes (#85)
1 parent 9b1c716 commit 2c3cd47

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

Mods/ModMenu/NetworkManager.py

+39-3
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,45 @@ def send(self) -> None:
7474

7575
def _PlayerTick(caller: unrealsdk.UObject, function: unrealsdk.UFunction, params: unrealsdk.FStruct) -> bool:
7676
timeout = _message_queue[0].timeout
77-
if timeout is not None and timeout < time():
77+
if timeout is None:
78+
_message_queue[0].send()
79+
elif timeout < time():
7880
_dequeue_message()
7981
return True
8082

8183

84+
def _Logout(caller: unrealsdk.UObject, function: unrealsdk.UFunction, params: unrealsdk.FStruct) -> bool:
85+
global _message_queue
86+
# If there are no queued messages, we have nothing to do.
87+
if len(_message_queue) == 0:
88+
return True
89+
90+
# Filter the messages destined to the logged out player out of our message queue.
91+
purged_queue = deque(message for message in _message_queue if message.PC is not params.Exiting)
92+
93+
# If there are no more messages left in the queue, we may cease observing message timeouts.
94+
if len(purged_queue) == 0:
95+
unrealsdk.RemoveHook("Engine.PlayerController.PlayerTick", "ModMenu.NetworkManager")
96+
97+
# If the first message in the filtered queue is different from the previous one, send it.
98+
elif purged_queue[0] is not _message_queue[0]:
99+
purged_queue[0].send()
100+
101+
_message_queue = purged_queue
102+
return True
103+
104+
105+
def _GameSessionEnded(caller: unrealsdk.UObject, function: unrealsdk.UFunction, params: unrealsdk.FStruct) -> bool:
106+
global _message_queue
107+
# If there are no queued messages, we have nothing to do.
108+
if len(_message_queue) == 0:
109+
return True
110+
# Cease observing message timeouts and empty the message queue.
111+
unrealsdk.RemoveHook("Engine.PlayerController.PlayerTick", "ModMenu.NetworkManager")
112+
_message_queue = deque()
113+
return True
114+
115+
82116
def _enqueue_message(message: _Message) -> None:
83117
""" Add a message to the message queue, sending it if message queue is empty. """
84118
_message_queue.append(message)
@@ -328,7 +362,7 @@ def _server_speech(caller: unrealsdk.UObject, function: unrealsdk.UFunction, par
328362
# Check if the message type indicates an acknowledgement from a client for the previous message
329363
# we had sent. If so, and its ID matches that of our last message, dequeue it and we are done.
330364
if message_type == "unrealsdk.__clientack__":
331-
if message == _message_queue[0].ID:
365+
if len(_message_queue) > 0 and _message_queue[0].ID == message:
332366
_dequeue_message()
333367
return False
334368

@@ -390,7 +424,7 @@ def _client_message(caller: unrealsdk.UObject, function: unrealsdk.UFunction, pa
390424
return True
391425

392426
if message_type == "unrealsdk.__serverack__":
393-
if message == _message_queue[0].ID:
427+
if len(_message_queue) > 0 and _message_queue[0].ID == message:
394428
_dequeue_message()
395429
return False
396430

@@ -431,3 +465,5 @@ def _client_message(caller: unrealsdk.UObject, function: unrealsdk.UFunction, pa
431465

432466
unrealsdk.RunHook("Engine.PlayerController.ServerSpeech", "ModMenu.NetworkManager", _server_speech)
433467
unrealsdk.RunHook("WillowGame.WillowPlayerController.ClientMessage", "ModMenu.NetworkManager", _client_message)
468+
unrealsdk.RunHook("Engine.GameInfo.Logout", "ModMenu.NetworkManager", _Logout)
469+
unrealsdk.RunHook("Engine.GameViewportClient.GameSessionEnded", "ModMenu.NetworkManager", _GameSessionEnded)

README.md

+17-7
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,29 @@ An UnrealEngine Plugin enabling using Python to write plugins that interact dire
77

88
## Installation
99

10-
Begin by [downloading the latest version of `PythonSDK.zip` here](https://github.com/Matt-Hurd/BL2-SDK/releases).
10+
1. [Download the latest version of `PythonSDK.zip`.](https://github.com/Matt-Hurd/BL2-SDK/releases) Ensure you download `PythonSDK.zip` from that page:
1111

12+
![PythonSDK Download Page](https://i.imgur.com/tBlidGi.png)
1213

13-
For PythonSDK to be able to interact with the game, you must add a few things to the game's Win32 folder. If you already have PluginLoader installed, you'll need to overwrite some files.
14+
2. Open `PythonSDK.zip`. It should contain 4 items:
1415

15-
1. Quit the game if it is running.
16+
![PythonSDK.zip Contents](https://i.imgur.com/jd77dnB.png)
1617

17-
2. Extract all of the contents of the folder in the PythonSDK.zip into your `Borderlands 2\Binaries\Win32` directory, overwriting files if necessary.
18-
You want there to be a file `Win32\ddraw.dll`, *not* `Win32\PythonSDK\ddraw.dll`.
18+
3. Locate your game's files. In Steam, this can be done by right-clicking on the game in your library, selecting "Properties," then in the "Local Files" section, clicking "Browse":
1919

20-
3. If you have installed an older version of the SDK, delete any extra old files that weren't overwritten.
20+
![Steam Contextual Menu](https://i.imgur.com/eyfn3ht.png) ![Steam Local Files Properties](https://i.imgur.com/wok2ZUA.png)
2121

22-
4. Download and install [this](https://aka.ms/vs/16/release/vc_redist.x86.exe) Mircosoft Visual C++ Redistributable. Most of the time this will already be installed.
22+
4. In the game's files, navigate to the `Binaries`, then the `Win32` folder. This folder should contain the `.exe` for your game (i.e. `Borderlands2.exe` or `BorderlandsPreSequel.exe`).
23+
24+
5. Copy the 4 items from `PythonSDK.zip` **exactly as they** are to the `Win32` folder. Note that `pythonXX.zip` should *not* be un-zipped:
25+
26+
![Win32 Folder Contents](https://i.imgur.com/hIvNi7w.png)
27+
28+
6. If you had previously installed an older version of the SDK, delete any old files that weren't overwritten by the ones in the latest `PythonSDK.zip`.
29+
30+
7. You are done, and may launch the game (if it is running, relaunch it now). You should see a "Mods" menu in the main menu!
31+
32+
8. If the SDK fails to run with the files correctly in place as described above, you may need to [download and install Mircosoft Visual C++ Redistributable](https://aka.ms/vs/16/release/vc_redist.x86.exe).
2333

2434
### Linux (SteamPlay/Proton and Wine)
2535

0 commit comments

Comments
 (0)