Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions example_mods/gravityManipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
# window_name_override = "NMS Example gravity manipulator"
# ///

import logging
import ctypes
import logging
from dataclasses import dataclass, field

from pymhf import Mod, ModState
from pymhf.core.hooking import on_key_pressed
from pymhf.gui import FLOAT

import nmspy.data.types as nms

# A quick mod used to change the gravity multiplier on all planets simultaneously, utilizing pyMHF's auto-gui.
Expand Down Expand Up @@ -82,6 +83,4 @@ def modifyGravity(self):
# Call an in-game function directly from your mod code.
# You will need to provide the arguments for the in-game function
planet.UpdateGravity(self.state.gravity)
logger.info(
f"Set Planetary Gravity Multiplier To {self.state.gravity} For All Planets"
)
logger.info(f"Set Planetary Gravity Multiplier To {self.state.gravity} For All Planets")
7 changes: 3 additions & 4 deletions example_mods/instantScanning.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
# window_name_override = "Instant scanning"
# ///

import logging
import ctypes
import logging

from pymhf import Mod
from pymhf.core.hooking import on_key_release
from pymhf.gui.decorators import BOOLEAN

import nmspy.data.types as nms

logger = logging.getLogger("InstantScan")
Expand Down Expand Up @@ -49,8 +50,6 @@ def toggle_instantness(self):
self.should_be_instant = not self.should_be_instant

@nms.cGcBinoculars.UpdateScanBarProgress.before
def set_no_scan(
self, this: ctypes._Pointer[nms.cGcBinoculars], lfScanProgress: float
):
def set_no_scan(self, this: ctypes._Pointer[nms.cGcBinoculars], lfScanProgress: float):
if self.should_be_instant and lfScanProgress < 1:
return (this, 1)
3 changes: 1 addition & 2 deletions nmspy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from importlib.metadata import version, PackageNotFoundError

from importlib.metadata import PackageNotFoundError, version

try:
__version__ = version("nmspy")
Expand Down
13 changes: 6 additions & 7 deletions nmspy/_internal_mods/singletons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
from dataclasses import dataclass
from logging import getLogger

from pymhf import Mod, ModState
from pymhf.core._types import DetourTime
from pymhf.core.hooking import hook_manager, one_shot
from pymhf.core.memutils import get_addressof, map_struct
from pymhf.gui.decorators import no_gui
from pymhf.core.hooking import one_shot, hook_manager
from pymhf.core.memutils import map_struct, get_addressof
from pymhf import ModState
from nmspy.common import gameData
import nmspy.data.types as nms

import nmspy.data.basic_types as basic
from pymhf import Mod
import nmspy.data.types as nms
from nmspy.common import gameData
from nmspy.data.enums import StateEnum


logger = getLogger()


Expand Down
38 changes: 15 additions & 23 deletions nmspy/_internal_mods/textChatManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
import logging

from pymhf import Mod
from pymhf.gui import no_gui
from pymhf.core._types import CustomTriggerProtocol, DetourTime
from pymhf.core.hooking import hook_manager
from pymhf.core._types import DetourTime, CustomTriggerProtocol
import nmspy.data.types as nms
from pymhf.gui import no_gui

import nmspy.data.basic_types as basic
from nmspy.terminal_parser import TerminalCommand, generate_full_description, split_key
import nmspy.data.types as nms
from nmspy.decorators import terminal_command
from nmspy.terminal_parser import TerminalCommand, generate_full_description, split_key

logger = logging.getLogger("chat_bot")


MOD_OPTION = "\n<TITLE>'/mod <><TITLE_BRIGHT>name option(s)<><TITLE>': configure a mod. Enter /mod <><TITLE_BRIGHT>name<><TITLE> to see options for each mod<>"
MOD_OPTION = (
"\n<TITLE>'/mod <><TITLE_BRIGHT>name option(s)<><TITLE>': configure a mod. Enter /mod <><TITLE_BRIGHT>"
"name<><TITLE> to see options for each mod<>"
)
MOD_LIST_OPTION = "\n<TITLE>'/modlist: display list of mods which can be configured via the terminal<>"


Expand Down Expand Up @@ -41,9 +45,7 @@ def intercept_chat_message(
# List the available mods which have commands.
# Filter the keys then generate a set
mod_command_keys = list(
filter(
lambda x: x.startswith("tc::"), hook_manager.custom_callbacks.keys()
)
filter(lambda x: x.startswith("tc::"), hook_manager.custom_callbacks.keys())
)
mod_names = list(set(split_key(x)[0] for x in mod_command_keys))
mod_names.sort()
Expand Down Expand Up @@ -76,9 +78,7 @@ def intercept_chat_message(
else:
command_funcs: dict[str, CustomTriggerProtocol] = {}
for key in mod_command_keys:
funcs = hook_manager.custom_callbacks[key].get(
DetourTime.NONE, []
)
funcs = hook_manager.custom_callbacks[key].get(DetourTime.NONE, [])
if len(funcs) > 1:
logger.warning(
f"Multiple terminal commands have been defined with the key {key}"
Expand All @@ -89,17 +89,13 @@ def intercept_chat_message(
mod_desc = f"<TITLE>{mod_name!r} mod options:<>"
for key, func in command_funcs.items():
_, command = split_key(key)
mod_desc += "\n" + generate_full_description(
command, func._description
)
mod_desc += "\n" + generate_full_description(command, func._description)
lMessageText.contents.set(mod_desc)
return
elif len(split_msg) == 2:
parsed_command = TerminalCommand(split_msg[0], split_msg[1], [])
elif len(split_msg) > 2:
parsed_command = TerminalCommand(
split_msg[0], split_msg[1], split_msg[2:]
)
parsed_command = TerminalCommand(split_msg[0], split_msg[1], split_msg[2:])
try:
# Call the custom callback with the generated key.
# If it doesn't exist we raise an exception which we catch and then show a message in the
Expand Down Expand Up @@ -131,9 +127,7 @@ def intercept_chat_message(
else:
command_funcs: dict[str, CustomTriggerProtocol] = {}
for key in mod_command_keys:
funcs = hook_manager.custom_callbacks[key].get(
DetourTime.NONE, []
)
funcs = hook_manager.custom_callbacks[key].get(DetourTime.NONE, [])
if len(funcs) > 1:
logger.warning(
f"Multiple terminal commands have been defined with the key {key}"
Expand All @@ -144,9 +138,7 @@ def intercept_chat_message(
mod_desc = f"<TITLE>{parsed_command.mod_name!r} mod options:<>"
for key, func in command_funcs.items():
_, command = split_key(key)
mod_desc += "\n" + generate_full_description(
command, func._description
)
mod_desc += "\n" + generate_full_description(command, func._description)
lMessageText.contents.set(mod_desc)

@nms.cGcTextChatManager.Say.before
Expand Down
7 changes: 2 additions & 5 deletions nmspy/caching.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# A collection of functions which will hash and cache things.

import hashlib
from io import BufferedReader
import json
import os
import os.path as op
from io import BufferedReader
from typing import Optional

import pymhf.core._internal as _internal


CACHE_DIR = ".cache"


Expand All @@ -35,9 +34,7 @@ def __init__(self, path: str):

@property
def path(self) -> str:
return op.join(
_internal.CWD, CACHE_DIR, f"{self._binary_hash}_{self._path}.json"
)
return op.join(_internal.CWD, CACHE_DIR, f"{self._binary_hash}_{self._path}.json")

def load(self, binary_hash: str):
"""Load the data."""
Expand Down
4 changes: 1 addition & 3 deletions nmspy/data/audiokinetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

class AK(Structure):
class SoundEngine(Structure):
@static_function_hook(
exported_name="?RegisterGameObj@SoundEngine@AK@@YA?AW4AKRESULT@@_KPEBD@Z"
)
@static_function_hook(exported_name="?RegisterGameObj@SoundEngine@AK@@YA?AW4AKRESULT@@_KPEBD@Z")
@staticmethod
def RegisterGameObj(
in_GameObj: ctypes.c_uint64,
Expand Down
Loading