major doc update

This commit is contained in:
Izalia Mae 2023-03-23 19:36:28 -04:00
parent 4951e606d3
commit 7cfa39a01e
18 changed files with 290 additions and 145 deletions

View file

@ -2,14 +2,14 @@ from Mods.ModMenu import ModTypes
from .enums import IntEnum, StrEnum, CurrencyType, FrameRate, KeyboardInput
from .misc import clsname, combine_flags, is_in_game
from .objects import Currency, Player, Settings
from .objects.player import Currency, Player, SkillTree
from .objects.settings import SetItem, Settings
from .sdkmod import SdkMod
class ModUtils(SdkMod):
'''
Various useful classes and functions for mod devs. See :class:`Mods.ModUtils.ModUtils` for
API usage.
Various useful classes and functions for mod devs. See :doc:`modutils/index` for API usage.
'''
Name = 'Mod Utilities'

View file

@ -1,2 +0,0 @@
from .player import Currency, Player
from .settings import Settings

View file

@ -4,7 +4,7 @@ from ..enums import CurrencyType
class Player:
'Represents a player'
'Represents a player object'
def __init__(self, player):
'''
@ -15,28 +15,37 @@ class Player:
@classmethod
def new_from_id(cls, pid):
def new_from_id(cls, pid) -> 'Mods.ModUtils.Player':
'''
Get a local player by ID
:param int pid: ID of the player to get
'''
return cls(unrealsdk.GetEngine().GamePlayers[pid])
@classmethod
def default(cls):
def default(cls) -> 'Mods.ModUtils.Player':
'Get the default player (ID:0)'
return cls.new_from_id(0)
## player objects
@property
def controller(self):
def controller(self) -> 'unrealsdk.UObject[WillowGame.WillowController]':
'A ``WillowController`` associated with the player. Alias for ``LocalPlayer.Actor``.'
return self._player.Actor
@property
def currency(self):
return Currency(self._player.Actor.PlayerReplicationInfo)
def currency(self) -> 'Mods.ModUtils.Currency':
'A ``Currency`` class associated with the player'
return Currency(self._player)
@property
def pawn(self):
def pawn(self) -> 'unrealsdk.UObject[WillowGame.WillowPawn]':
'A ``WillowPawn`` associated with the player. Alias for ``LocalPlayer.Actor.MyWillowPawn``.'
data = self.controller.MyWillowPawn
if not data:
@ -47,30 +56,35 @@ class Player:
## useful player properties
@property
def character_name(self):
def character_name(self) -> str:
'Current character\'s name'
return self.controller.GetPlayerUINamePreference()
@property
def classmod_name(self):
def classmod_name(self) -> str:
'Name of the currently equipted class mod'
return self.controller.PlayerReplicationInfo.GetClassModName()
@property
def level(self):
def level(self) -> int:
'Level of the current character. Can be modified.'
self.pawn.GetExpLevel()
@level.setter
def level(self, value):
if 1 > level > 80:
raise ValueError('Level must be anywhere from 1 to 80')
## need to adjust the max level per game
# if 1 > level > 80:
# raise ValueError('Level must be anywhere from 1 to 80')
self.pawn.SetExpLevel(value)
@property
def shield_amount(self):
def shield_amount(self) -> float:
'Current shield amount. Can be modified.'
return self.pawn.GetShieldStrength()
@ -85,29 +99,39 @@ class Player:
@property
def shield_amount_max(self):
def shield_amount_max(self) -> float:
'Max amount of the currently equipted shield'
return self.pawn.GetMaxShieldStrength()
@property
def user_name(self):
def user_name(self) -> str:
'Your account name. Usually your Steam display name.'
return self._player.GetNickname()
def get_net_speed(self):
def get_net_speed(self) -> 'tuple[int,int]':
'Currently configured speeds for ``internet`` and ``lan``. Format is ```(internet, lan)```'
player = self.controller.Player
return {
'internet': player.ConfiguredInternetSpeed,
'lan': player.ConfiguredLanSpeed
}
return player.ConfiguredInternetSpeed, player.ConfiguredLanSpeed
def golden_key_add(self, value):
'''
Add x amount of golden keys
:param int value: Number of keys to add
'''
self.controller.AddGoldenKeysFromSource(0, value)
def golden_key_remove(self, value):
'''
Remove x amount of golden keys (WARNING: untested)
:params int value: Number of keys to remove
'''
controller = self.controller
for _ in range(0, value - 1):
@ -115,23 +139,38 @@ class Player:
def console_command(self, *cmd):
'''
Run a console command. All argument values will be converted to ``str`` objects and
joined with a space before being sent.
:param tuple(typing.Any) cmd: Parts of the console command
'''
command = ' '.join(str(c) for c in cmd)
self.controller.ConsoleCommand(command)
def refill_life(self):
'Set the current character\'s life to max'
self.pawn.FullyReplenishLife()
def refill_shields(self):
'Set the current character\'s shield to max'
self.pawn.FullyReplenishShields()
def remove_status_effects(self):
'Remove all active status effects'
self.pawn.RemoveAllStatusEffects()
def set_net_speed(self, lan=None, internet=None):
def set_net_speed(self, internet=None, lan=None):
'''
Set max net speeds
:param int internet: Max speed to set for internet connections
:param int lan: Max speed to set for lan connections
'''
player = self.controller.Player
if lan == internet == None:
@ -146,16 +185,20 @@ class Player:
class Currency:
'Manage a player\'s currency'
'Manage a character\'s currency. The types can be accessed via dict items or object attributes.'
def __init__(self, repinfo):
self._repinfo = repinfo
def __init__(self, player):
'''
:param Player player: Player object to work with
'''
self._player = player
self._repinfo = player.controller.PlayerReplicationInfo
def __getattr__(self, key):
try:
get = object.__getattribute__(self, 'get')
return get(CurrencyType.parse(key))
return get(key)
except KeyError:
pass
@ -163,39 +206,125 @@ class Currency:
object.__getattribute__(self, key)
def add(self, type, value):
if not isinstance(type, CurrencyType):
type = CurrencyType[type.upper()]
def __setattr__(self, key, value):
try:
set = object.__getattribute__(self, 'set')
set(key, value)
return self._repinfo.AddCurrencyOnHand(type.value)
except KeyError:
pass
object.__setattr__(self, key, value)
def __getitem__(self, key):
return self.get(key)
def __setitem__(self, key, value):
self.set(key, value)
@classmethod
def new_from_player_id(cls, pid) -> 'Currency':
'''
Create a new ``Currency`` object for a player with the specified ID
:param int pid: ID of the player
'''
return cls(Player.new_from_id(pid))
@classmethod
def default(cls) -> 'Currency':
'Create a new ``Currency`` object for the default player (ID: 0)'
return cls(Player.default())
def add(self, type, value):
'''
Add x amount of the specified currency
:param typing.Union[CurrencyType,str] type: Type of currency to work with
:param int value: Amount to add
'''
if not isinstance(type, CurrencyType):
type = CurrencyType.parse(type)
self._repinfo.AddCurrencyOnHand(type.value)
def get(self, type):
if not isinstance(type, CurrencyType):
type = CurrencyType[type.upper()]
'''
Get the current amount of the specified currency
return self._repinfo.GetCurrencyOnHand(type.value)
:param typing.Union[CurrencyType,str] type: Type of currency to get
'''
if not isinstance(type, CurrencyType):
type = CurrencyType.parse(type)
self._repinfo.GetCurrencyOnHand(type.value)
def set(self, type, value):
'''
Set the amount of the specified currency
:param typing.Union[CurrencyType,str] type: Type of currency to work with
:param int value: Amount to set the currency to
'''
if not isinstance(type, CurrencyType):
type = CurrencyType[type.upper()]
type = CurrencyType.parse(type)
return self._repinfo.SetCurrencyOnHand(type.value, value)
self._repinfo.SetCurrencyOnHand(type.value, value)
def to_dict(self):
def subtract(self, type, value):
'''
Subtraft x amount of the specified currency
:param typing.Union[CurrencyType,str] type: Type of currency to work with
:param int value: Amount to subtract
'''
if not isinstance(type, CurrencyType):
type = CurrencyType.parse(type)
self._repinfo.AddCurrencyOnHand(type.value, value * -1)
def to_dict(self) -> 'dict[str,int]':
'Get all currencies and their amounts'
values = self._repinfo.GetAllCurrencyOnHand()
data = {}
for idx, type in enumerate(CurrencyType):
data[type] = values[idx]
data[type.name] = values[idx]
return data
class SkillTree:
'View and/or manage a character\'s skill tree'
'View and/or manage a character\'s skill tree (WIP)'
def __init__(self, player):
'''
:param Player player: Player object to work with
'''
self._player = player
self._tree = player.controller.PlayerSkillTree
@classmethod
def new_from_player_id(cls, pid) -> 'SkillTree':
'''
Create a new ``SkillTree`` object for a player with the specified ID
:param int pid: ID of the player
'''
return cls(Player.new_from_id(pid))
@classmethod
def default(cls) -> 'SkillTree':
'Create a new ``SkillTree`` object for the default player (ID: 0)'
return cls(Player.default())

View file

@ -3,7 +3,7 @@ import unrealsdk
from ..misc import is_in_game
SETTINGS = [
SETTINGS = (
'AmbientOcclusion',
'AudioFocus',
'bNVIDIA3d',
@ -21,10 +21,12 @@ SETTINGS = [
'TextureQuality',
'ViewDistance',
'VSync'
]
)
class Item:
class SetItem:
'Represents a game setting.'
def __init__(self, name, value, *options):
self.name = name
self.value = value
@ -32,7 +34,7 @@ class Item:
def __repr__(self):
return f'Item("{self.name}", "{self.value_string}")'
return f'SetItem("{self.name}", "{self.value_string}")'
def __str__(self):
@ -54,6 +56,11 @@ class Item:
class Settings:
'''
Class to manage game settings. Values can be accessed via dict items. Check the output of
:meth:`Settings.keys()` for valid setting names.
'''
def __init__(self):
self._set = unrealsdk.FindObject('WillowSystemSettings', 'WillowGame.Default__WillowSystemSettings')
@ -74,37 +81,57 @@ class Settings:
yield key
def get(self, key):
def get(self, key) -> SetItem:
'''
Get a setting with the name of the specified key
:param str key: Name of the setting to get
:raises KeyError: When the specified key does not exist
'''
for value in self._set.SystemOptions:
if key == value.Name:
return Item.new_from_option(value)
return SetItem.new_from_option(value)
raise KeyError(key)
def items(self):
def items(self) -> 'typing.Iterator[tuple[str,int]]':
'Get all the keys and their associated values'
for key in self.keys():
yield key, self.get(key).value
def keys(self):
return tuple(SETTINGS)
def keys(self) -> 'tuple[str]':
'Valid names of all the options.'
return SETTINGS
def set(self, key, new_value):
'''
Set a value for the specified key
:param str key: Name of the setting to set
:param typing.Union[str,int] new_value: Value to set for the specified key
'''
if isinstance(new_value, str):
new_value = self.get(key).options.index(new_value)
self._set.UpdateSystemOption(key, new_value)
def to_dict(self, strings=False):
def to_dict(self, strings=False) -> 'dict[str,typing.Union[int,str]]':
'''
Get all the keys and their associated values as a dict
:params bool strings: If ``True``, return the value name instead of the value index
'''
if not strings:
return {k: v for k, v in self.items()}
return {k: str(self.get(k)) for k in self.keys()}
def values(self):
def values(self) -> 'typing.Iterator[int]':
'Get all the values of each key'
for key in self.keys():
yield self.get(key).value

View file

@ -9,7 +9,7 @@ from dataclasses import dataclass, field
from unrealsdk import Log
from .misc import clsname, combine_flags, is_in_game, manifest_to_flag
from .objects import Player
from .objects.player import Player
MOD_VALUES = {

View file

@ -1,2 +1,27 @@
Izalia's PythonSDK Mods Documentation
Izalia's PythonSDK Mod Documentation
=====================================
.. autoclass:: Mods.FpsToggle.FpsToggle
:exclude-members: __init__, __new__
Download: https://static.barkshark.xyz/bl2mods/fpstoggle/fpstoggle-1.0.zip
.. autoclass:: Mods.InfiniKeys.InfiniKeys
:exclude-members: __init__, __new__
Download: https://static.barkshark.xyz/bl2mods/infinikeys/infinikeys-1.0.zip
.. autoclass:: Mods.LootSplosion.LootSplosion
:exclude-members: __init__, __new__
Download: https://static.barkshark.xyz/bl2mods/lootsplosion/lootsplosion-1.0.zip
.. autoclass:: Mods.ModUtils.ModUtils
:exclude-members: __init__, __new__
Download: https://static.barkshark.xyz/bl2mods/modutils/modutils-0.1.zip
.. autoclass:: Mods.WebPanel.WebPanel
:exclude-members: __init__, __new__
Download: https://static.barkshark.xyz/bl2mods/webpanel/webpanel-0.1.zip

View file

@ -1,35 +0,0 @@
Mods by Izalia Mae
==================
.. autoclass:: Mods.FpsToggle.FpsToggle
:members:
:exclude-members: __init__, __new__
Download: https://static.barkshark.xyz/bl2mods/fpstoggle/fpstoggle-1.0.zip
.. autoclass:: Mods.InfiniKeys.InfiniKeys
:members:
:exclude-members: __init__, __new__
Download: https://static.barkshark.xyz/bl2mods/infinikeys/infinikeys-1.0.zip
.. autoclass:: Mods.LootSplosion.LootSplosion
:members:
:exclude-members: __init__, __new__
Download: https://static.barkshark.xyz/bl2mods/lootsplosion/lootsplosion-1.0.zip
.. autoclass:: Mods.ModUtils.ModUtils
:members:
:exclude-members: __init__, __new__
:noindex:
Download: https://static.barkshark.xyz/bl2mods/modutils/modutils-0.1.zip
.. autoclass:: Mods.WebPanel.WebPanel
:members:
:exclude-members: __init__, __new__
Download: https://static.barkshark.xyz/bl2mods/webpanel/webpanel-0.1.zip

View file

@ -1,29 +0,0 @@
Mod Utilities
=============
.. autoclass:: Mods.ModUtils.ModUtils
:exclude-members: __init__, __new__
Functions
~~~~~~~~~
.. autofunction:: Mods.ModUtils.clsname
.. autofunction:: Mods.ModUtils.combine_flags
.. autofunction:: Mods.ModUtils.is_in_game
Classes
~~~~~~~
.. autoclass:: Mods.ModUtils.SdkMod
:members:
:exclude-members: __init__, __new__, NetworkDeserialize, NetworkSerialise, Disable, Enable, GameInputPressed, ModOptionChanged, SettingsInputPressed
:show-inheritance:
:no-inherited-members:
.. autoclass:: Mods.ModUtils.Player
:members:
.. autoclass:: Mods.ModUtils.Currency
:members:

View file

@ -0,0 +1,6 @@
Functions
=========
.. autofunction:: Mods.ModUtils.clsname
.. autofunction:: Mods.ModUtils.combine_flags
.. autofunction:: Mods.ModUtils.is_in_game

2
docs/modutils/index.rst Normal file
View file

@ -0,0 +1,2 @@
Mod Utilities
=============

11
docs/modutils/player.rst Normal file
View file

@ -0,0 +1,11 @@
Player
======
.. autoclass:: Mods.ModUtils.Player
:members:
.. autoclass:: Mods.ModUtils.Currency
:members:
.. autoclass:: Mods.ModUtils.SkillTree
:members:

8
docs/modutils/sdkmod.rst Normal file
View file

@ -0,0 +1,8 @@
SdkMod
======
.. autoclass:: Mods.ModUtils.SdkMod
:members:
:exclude-members: __init__, __new__, NetworkDeserialize, NetworkSerialise, Disable, Enable, GameInputPressed, ModOptionChanged, SettingsInputPressed
:show-inheritance:
:no-inherited-members:

View file

@ -0,0 +1,9 @@
Settings
========
.. autoclass:: Mods.ModUtils.Settings
:members:
:exclude-members: __init__
.. autoclass:: Mods.ModUtils.SetItem
:members:

View file

@ -1,23 +1,15 @@
root: index.rst
subtrees:
- entries:
- file: mods/index.rst
title: Mods
- file: modutils/index.rst
title: Mod Utilities
subtrees:
- entries:
- file: mods/modutils.rst
- file: mods/modutils-enums.rst
- file: unrealsdk/index.rst
title: UnrealSDK
subtrees:
- entries:
- file: unrealsdk/functions.rst
- file: unrealsdk/classes.rst
- file: ueobjects/index.rst
title: Unreal Objects
subtrees:
- entries:
- file: ueobjects/engine/actor.rst
- file: modutils/sdkmod.rst
- file: modutils/player.rst
- file: modutils/settings.rst
- file: modutils/enums.rst
- file: unrealsdk.rst
- url: https://git.barkshark.xyz/izaliamae/bl2mods
title: Git Repo
- url: https://barkshark.xyz/@izalia

View file

@ -1,6 +1,9 @@
Functions
UnrealSDK
=========
Functions
~~~~~~~~~
.. autofunction:: unrealsdk.CallPostEdit
.. autofunction:: unrealsdk.ConstructObject
.. autofunction:: unrealsdk.DoInjectedCallNext
@ -19,3 +22,12 @@ Functions
.. autofunction:: unrealsdk.RemoveHook
.. autofunction:: unrealsdk.RunHook
.. autofunction:: unrealsdk.SetLoggingLevel
Classes
~~~~~~~
.. autoclass:: unrealsdk.FName
.. autoclass:: unrealsdk.FOutputDevice
.. autoclass:: unrealsdk.PyCapsule
.. autoclass:: unrealsdk.UClass
.. autoclass:: unrealsdk.UObject

View file

@ -1,8 +0,0 @@
Classes
=======
.. autoclass:: unrealsdk.FName
.. autoclass:: unrealsdk.FOutputDevice
.. autoclass:: unrealsdk.PyCapsule
.. autoclass:: unrealsdk.UClass
.. autoclass:: unrealsdk.UObject

View file

@ -1,2 +0,0 @@
UnrealSDK
=========