This repository has been archived by the owner on Jan 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some stuff with the init & add my mods cause why not
* Add Logging for imports * Have `ModOptionChanged` fire on mod enable * Changing a hidden value should save the mod settings * Fix mod saving * Add my 3 *whole* mods
- Loading branch information
FromDarkHell
authored and
FromDarkHell
committed
Jun 18, 2019
1 parent
6f5d41a
commit 05fd359
Showing
7 changed files
with
277 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from bl2sdk import * | ||
from ..ModManager import BL2MOD, RegisterMod | ||
from ..OptionManager import Options | ||
|
||
class BackpackManager(BL2MOD): | ||
Name = "Backpack Manager" | ||
Description = "Customize the size of your character's backpack on the fly!" | ||
Types = [ModTypes.Gameplay] | ||
Author = "FromDarkHell" | ||
|
||
Options = [ | ||
Options.Slider("Backpack", "Change the size of your character's backpack<br>Default is 39", 39,0,200,1) | ||
] | ||
|
||
backpackSpace = 39 | ||
|
||
def Enable(self): | ||
def HookCreateWeaponScopeMovie(caller: UObject, function: UFunction, params: FStruct) -> bool: | ||
PC = GetEngine().GamePlayers[0].Actor | ||
if PC and PC.Pawn: | ||
pawn = PC.Pawn | ||
pawn.InvManager.InventorySlotMax_Misc = self.backpackSpace | ||
return True | ||
|
||
RegisterHook("WillowGame.WillowHUD.CreateWeaponScopeMovie", "HookCreateWeaponScopeMovie", HookCreateWeaponScopeMovie) | ||
|
||
def Disable(self): | ||
RemoveHook("WillowGame.WillowHUD.CreateWeaponScopeMovie", "HookCreateWeaponScopeMovie") | ||
|
||
|
||
def ModOptionChanged(self, option, newValue): | ||
if option.Caption == "Backpack": | ||
self.backpackSpace = int(newValue) | ||
PC = GetEngine().GamePlayers[0].Actor | ||
if PC and PC.Pawn: | ||
pawn = PC.Pawn | ||
pawn.InvManager.InventorySlotMax_Misc = self.backpackSpace | ||
|
||
RegisterMod(BackpackManager()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
from bl2sdk import * | ||
|
||
|
||
class MapLoader(BL2MOD): | ||
Name = "Borderlands 2 Map Reloader" | ||
Description = "Quickly Farm Items in Borderlands 2!" | ||
Types = [ModTypes.Utility] | ||
Author = "FromDarkHell" | ||
|
||
def __init__(self): | ||
# Our rotation etc etc | ||
self.X = 0 | ||
self.Y = 0 | ||
self.Z = 0 | ||
self.Pitch = 0 | ||
self.Yaw = 0 | ||
self.Roll = 0 | ||
|
||
# It might be a good idea to restore our position after a load. | ||
self.saveLocation = True | ||
self.loading = False | ||
self.consistentLocation = False | ||
self.toggledLocation = False | ||
|
||
# Store some data that we can use to reload the map | ||
self.currentSelectedDifficulty = 0 | ||
self.currentSelectedOverpowerLevel = 0 | ||
|
||
self.DefaultGameInfo = UObject.FindObjectsContaining("WillowCoopGameInfo WillowGame.Default__WillowCoopGameInfo")[0] | ||
|
||
Keybinds = [ | ||
["Quickload w/o Saving", "F7"], | ||
["Quickload w/ Saving", "F8"], | ||
["Toggle Quickload Save States", "F10"], | ||
["Consistent Location States", "F5"] | ||
] | ||
|
||
def reloadCurrentMap(self, skipSave): | ||
PC = GetEngine().GamePlayers[0].Actor | ||
if self.toggledLocation: | ||
if self.consistentLocation: | ||
locale = PC.Pawn.Location | ||
self.X = locale.X | ||
self.Y = locale.Y | ||
self.Z = locale.Z | ||
rotate = PC.Rotation | ||
self.Pitch = rotate.Pitch | ||
self.Yaw = rotate.Yaw | ||
self.Roll = rotate.Roll | ||
else: | ||
if not self.consistentLocation: | ||
locale = PC.Pawn.Location | ||
self.X = locale.X | ||
self.Y = locale.Y | ||
self.Z = locale.Z | ||
rotate = PC.Rotation | ||
self.Pitch = rotate.Pitch | ||
self.Yaw = rotate.Yaw | ||
self.Roll = rotate.Roll | ||
|
||
self.toggledLocation = False | ||
# Our currently selected difficulty for the main menu | ||
self.currentSelectedDifficulty = PC.GetCurrentPlaythrough() | ||
# Get our current save game we'll need it for the OP levels | ||
wsg = PC.GetCachedSaveGame() | ||
# Our current OP level if we need it, game is weird | ||
if wsg.LastOverpowerChoice and wsg.NumOverpowerLevelsUnlocked: | ||
self.currentSelectedOverpowerLevel = max(min(wsg.LastOverpowerChoice, wsg.NumOverpowerLevelsUnlocked), 0) | ||
else: | ||
self.currentSelectedOverpowerLevel = -1 | ||
|
||
# Load Map | ||
self.loading = True | ||
# This is the function that BL2 uses for save quits. | ||
PC.ReturnToTitleScreen(skipSave, False) | ||
|
||
def GameInputPressed(self, input): | ||
name = input.Name | ||
if name == "Quickload w/o Saving" or name == "Quickload w/ Saving": | ||
self.reloadCurrentMap(name == "Quickload w/o Saving") | ||
elif name == "Toggle Quickload Save States": | ||
self.saveLocation = not self.saveLocation | ||
state = "Location Saving is now {}".format("enabled" if self.saveLocation else "disabled") | ||
Log(state) | ||
pc = GetEngine().GamePlayers[0].Actor | ||
HUDMovie = pc.myHUD.HUDMovie | ||
# Show a training text for our location state. | ||
HUDMovie.ClearTrainingText() | ||
HUDMovie.AddTrainingText(state, "Map Loader", 2.0 * self.DefaultGameInfo.GameSpeed, (), "", False, 0, pc.PlayerReplicationInfo, True, 0, 0) | ||
elif name == "Consistent Location States": | ||
self.toggledLocation = True | ||
self.consistentLocation = not self.consistentLocation | ||
state = "Consistent Location States is now {}".format("enabled" if self.consistentLocation else "disabled") | ||
Log(state) | ||
pc = GetEngine().GamePlayers[0].Actor | ||
HUDMovie = pc.myHUD.HUDMovie | ||
# Show a training text for our location state. | ||
HUDMovie.ClearTrainingText() | ||
HUDMovie.AddTrainingText(state, "Map Loader", 2.0 * self.DefaultGameInfo.GameSpeed, (), "", False, 0, pc.PlayerReplicationInfo, True, 0, 0) | ||
|
||
def GameInputRebound(self, name, key): | ||
"""Invoked by the SDK when one of the inputs we have registered for is | ||
rebound by the user. Use it to save our settings for the key binding.""" | ||
pass | ||
|
||
def Enable(self): | ||
|
||
def map_load_hook(caller: UObject, function: UFunction, params: FStruct): | ||
if self.saveLocation and self.loading: | ||
pc = GetEngine().GamePlayers[0].Actor | ||
HUDMovie = pc.myHUD.HUDMovie | ||
# PC is sometimes none when the hooked function is called, this means this execution of the hook is running to early. | ||
# Same thing with the HUDMovie. | ||
if pc.Pawn is None or HUDMovie is None: | ||
return True | ||
# Restore our location. | ||
locale = pc.Pawn.Location | ||
locale.X = self.X | ||
locale.Y = self.Y | ||
locale.Z = self.Z | ||
rotate = pc.Rotation | ||
rotate.Roll = self.Roll | ||
rotate.Pitch = self.Pitch | ||
rotate.Yaw = self.Yaw | ||
|
||
HUDMovie.ClearTrainingText() | ||
HUDMovie.AddTrainingText("Farming Location Restored", "Map Loader", 3.0 * self.DefaultGameInfo.GameSpeed, (), "", False, 0, pc.PlayerReplicationInfo, True, 0, 0) | ||
# Restore our rotation to the saved values. | ||
|
||
self.loading = False | ||
return True | ||
|
||
def main_menu_hook(caller: UObject, function: UFunction, params: FStruct): | ||
try: | ||
if self.loading: | ||
PC = GetEngine().GamePlayers[0].Actor | ||
# We'll need this to reload to the current difficulty. | ||
gfx = UObject.FindObjectsContaining("FrontendGFxMovie ")[1] | ||
if gfx is None or PC is None: | ||
return True | ||
# This is how the game knows what OP level we're on. | ||
if self.currentSelectedOverpowerLevel != -1: | ||
PC.OnSelectOverpowerLevel(PC.GetCachedSaveGame(), self.currentSelectedOverpowerLevel) | ||
# I don't *think* this does anything, might want to do it just in case. Weird Game. | ||
gfx.CurrentSelectedOverpowerLevel = self.currentSelectedOverpowerLevel | ||
Log("[Map Loader] Loading WSG on playthrough %s at OP %s" % (self.currentSelectedDifficulty, self.currentSelectedOverpowerLevel)) | ||
# Here we reload our save, like how the `Continue` button does. | ||
gfx.LaunchSaveGame(self.currentSelectedDifficulty) | ||
except: pass | ||
return True | ||
|
||
# This is how we know that we're in the main menu. Its slightly janky, but it works. | ||
RegisterHook("WillowGame.FrontendGFxMovie.OnTick", "HookMainMenu", main_menu_hook) | ||
# This is how we know that we've loaded a new map. Once again, janky. | ||
RegisterHook("WillowGame.WillowHUD.CreateWeaponScopeMovie", "MapHookLoad", map_load_hook) | ||
|
||
def Disable(self): | ||
RemoveHook("WillowGame.FrontendGFxMovie.OnTick", "HookMainMenu") | ||
RemoveHook("WillowGame.WillowHUD.CreateWeaponScopeMovie", "MapHookLoad") | ||
|
||
|
||
RegisterMod(MapLoader()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from bl2sdk import * | ||
from ..ModManager import BL2MOD, RegisterMod | ||
import math | ||
|
||
class ReadOnly(BL2MOD): | ||
Name = "Borderlands Easy Read Only" | ||
Description = "Toggle Read Only on a button press" | ||
readOnly = False | ||
toggledReadOnly = False | ||
|
||
DefaultGameInfo = UObject.FindObjectsContaining("WillowCoopGameInfo WillowGame.Default__WillowCoopGameInfo")[0] | ||
Keybinds = [["Toggle Read Only", "F2"]] | ||
|
||
def displayFeedback(self): | ||
PC = GetEngine().GamePlayers[0].Actor | ||
HUDMovie = PC.myHUD.HUDMovie | ||
try: | ||
if PC is None or HUDMovie is None: | ||
return True | ||
if self.readOnly: | ||
HUDMovie.AddTrainingText("Read Only: Enabled", "Read Only", math.inf, (), "", False, 0, PC.PlayerReplicationInfo, True, 0, 0) | ||
elif self.toggledReadOnly: | ||
self.toggledReadOnly = False | ||
HUDMovie.ClearTrainingText() | ||
except: | ||
return True | ||
return True | ||
|
||
def GameInputPressed(self, input): | ||
if input.Name == "Toggle Read Only": | ||
self.toggledReadOnly = True | ||
self.readOnly = not self.readOnly | ||
self.displayFeedback() | ||
|
||
def Enable(self): | ||
|
||
def hookCanSaveGame(caller: UObject, function: UFunction, params: FStruct) -> bool: | ||
if self.readOnly: | ||
return False | ||
return True | ||
|
||
def hookTrainingText(caller: UObject, function: UFunction, params: FStruct): | ||
self.displayFeedback() | ||
return True | ||
|
||
RegisterHook("WillowGame.WillowPlayerController.CanSaveGame", "HookSaveGame", hookCanSaveGame) | ||
RegisterHook("WillowGame.WillowHUDGFxMovie.DrawTrainingText", "HookTrainingText", hookTrainingText) | ||
RegisterHook("WillowGame.WillowHUD.CreateWeaponScopeMovie", "HookTrainingText", hookTrainingText) | ||
|
||
def Disable(self): | ||
RemoveHook("WillowGame.WillowPlayerController.CanSaveGame", "HookSaveGame") | ||
RemoveHook("WillowGame.WillowHUDGFxMovie.DrawTrainingText", "HookTrainingText") | ||
RemoveHook("WillowGame.WillowHUD.CreateWeaponScopeMovie", "HookTrainingText") | ||
|
||
RegisterMod(ReadOnly()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters