Skip to content

Commit 6f8c01b

Browse files
authored
Merge pull request #6 from monkeyman192/pattern_update
initially add patterns for some funcs as well as the internal ones
2 parents a5ff924 + a3466b3 commit 6f8c01b

35 files changed

+3980
-2987
lines changed

.github/workflows/pipeline.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: NMSpy
2+
3+
on:
4+
# Run on all branches except for the gh-pages branch
5+
push:
6+
paths-ignore:
7+
- '*.md'
8+
branches-ignore:
9+
- 'gh-pages'
10+
tags:
11+
- '*'
12+
13+
jobs:
14+
build_test:
15+
name: Build artefacts
16+
runs-on: Windows-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
py_ver: [{version: '3.9'}] # , {version: '3.10'}, {version: '3.11'}]
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
- name: Set up Python ${{ matrix.py_ver.version}}
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: "${{ matrix.py_ver.version}}"
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip uv
32+
uv sync --frozen --group dev
33+
- name: Build Python ${{ matrix.py_ver.version}} wheel
34+
run: uv build
35+
- name: Lint and format code
36+
run: uv run python -m twine check ./dist/*
37+
# uv run ruff check ./NMSpy
38+
# uv run ruff format --check ./NMSpy
39+
# uv run python -m twine check ./dist/*
40+
- name: Upload Wheels
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: python-package-distributions
44+
path: dist/
45+
release:
46+
name: Release NMSpy wheels and source build to PyPI
47+
# Only run this job if the commit was tagged.
48+
if: startsWith(github.ref, 'refs/tags')
49+
needs:
50+
- build_test
51+
runs-on: ubuntu-latest
52+
environment:
53+
name: pypi
54+
url: https://pypi.org/p/NMSpy
55+
permissions:
56+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
57+
steps:
58+
- name: Download files for release
59+
uses: actions/download-artifact@v4
60+
with:
61+
name: python-package-distributions
62+
path: dist/
63+
- name: Publish package distributions to PyPI
64+
uses: pypa/gh-action-pypi-publish@release/v1
65+
with:
66+
attestations: true
67+
68+
test-release:
69+
name: Release NMSpy wheels and source build to test-PyPI
70+
needs:
71+
- build_test
72+
runs-on: ubuntu-latest
73+
environment:
74+
name: testpypi
75+
url: https://test.pypi.org/p/NMSpy
76+
permissions:
77+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
78+
steps:
79+
- name: Download files for release
80+
uses: actions/download-artifact@v4
81+
with:
82+
name: python-package-distributions
83+
path: dist/
84+
- name: Publish package distributions to PyPI
85+
uses: pypa/gh-action-pypi-publish@release/v1
86+
with:
87+
repository-url: https://test.pypi.org/legacy/
88+
attestations: true
89+
verbose: true

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include nmspy/pymhf.cfg
1+
include nmspy/pymhf.toml

example_mods/gravityManipulator.py

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,68 @@
11
import logging
2-
import ctypes
32
from dataclasses import dataclass
43

5-
from pymhf.core.hooking import disable, on_key_pressed
6-
from pymhf.core.memutils import map_struct
4+
from pymhf.core.hooking import on_key_pressed
75
from pymhf.core.mod_loader import ModState
86
from nmspy import NMSMod
97
from pymhf.core.calling import call_function
10-
import pymhf.core.hooking
11-
from pymhf import FUNCDEF
12-
from pymhf.core.module_data import module_data
138
from pymhf.gui import FLOAT
9+
import nmspy.data.functions.hooks as hooks
1410

1511
# A quick mod used to change the gravity multiplier on all planets simultaneously, utilizing pyMHF's auto-gui.
1612

13+
logger = logging.getLogger("GravMod")
14+
15+
1716
@dataclass
18-
class gravModState(ModState): #A special class inheriting from ModState which persists between mod Hot Reloads, allowing mod developers to cache pointers, values etc.
19-
Gravity: int = 1
20-
planetAddresses= list()
17+
class gravModState(ModState):
18+
# A special class inheriting from ModState which persists between mod Hot Reloads, allowing mod developers
19+
# to cache pointers, values etc.
20+
gravity: int = 1
21+
planetAddresses: list[int] = []
22+
2123

22-
@disable
2324
class gravityManipulator(NMSMod):
24-
#General "Nice To Have"s
25+
# General "Nice To Have"s
2526
__author__ = "ThatBomberBoi"
2627
__description__ = "Gravity Manipulator"
27-
__version__ = "0.1"
28-
__NMSPY_required_version__ = "0.7.0"
28+
__version__ = "0.2"
29+
__NMSPY_required_version__ = "0.7.0"
2930

30-
#Create an instance of the persistant ModState Class in your mod class.
31-
state = gravModState()
31+
# Create an instance of the persistant ModState Class in your mod class.
32+
state = gravModState()
3233

3334
def __init__(self):
3435
super().__init__()
3536
self.should_print = False
3637

37-
#Used to define a Float Type with a label in the Mod GUI, autogenerated by pyMHF.
38+
# Used to define a Float Type with a label in the Mod GUI, autogenerated by pyMHF.
3839
@property
3940
@FLOAT("Gravity Multiplier:")
4041
def gravMult(self):
41-
return self.state.Gravity
42+
return self.state.gravity
4243

43-
#Used to actually update the persisted value with the one input by the user in the GUI.
44+
# Used to actually update the persisted value with the one input by the user in the GUI.
4445
@gravMult.setter
4546
def gravMult(self, value):
46-
self.state.Gravity = value
47-
48-
#Define the FUNCDEF for the function you want to hook, including the return-type and arguments as identified via decompilers (e.x. IDA).
49-
regionSetupFuncDef = FUNCDEF(restype=None, argtypes=[ctypes.c_ulonglong])
47+
self.state.gravity = value
5048

51-
#The decorator used to tie a hook to a function. The tied function gets called whenever the in-game function is called. Requires a Function Signature as generated by plugins such as SigMakerEx for IDA.
52-
# If the function you're hooking hasn't changed since 4.13 - Fractals, you can use this lil trick I've done here, and save yourself having to manually write out a FUNCDEF.
53-
@pymhf.core.hooking.manual_hook(name="cGcPlanet::SetupRegionMap", pattern="48 89 5C 24 10 48 89 6C 24 18 56 57 41 56 48 83 EC 40 48 8B D9 8B", func_def=module_data.FUNC_CALL_SIGS["cGcPlanet::SetupRegionMap"], detour_time="after")
54-
def onRegionMap(self, this): #Include each in-game function's arguments seperately in the function, or use *args to inspect all arguments without knowing them prior.
55-
logging.info(f"Generated A Planet!")
49+
# Functions are hooked by specifying the function to be hooked from the list of in game functions
50+
# available. You can specify whether you want your detour to run either before or after the original
51+
# function as shown below.
52+
@hooks.cGcPlanet.SetupRegionMap.after
53+
def onRegionMap(self, this):
54+
# Include each in-game function's arguments seperately in the function, or use *args to get all
55+
# arguments without knowing them prior.
56+
# In this case we know that the argument is `this` which is a pointer to the instance of `cGcPlanet`
57+
# which is automatically passed into this function by the game.
58+
logger.info(f"Generated A Planet!")
5659
self.state.planetAddresses.append(this)
57-
logging.debug(f"Found {len(self.state.planetAddresses)} Planets So Far")
60+
logger.debug(f"Found {len(self.state.planetAddresses)} Planets So Far")
5861

5962
@on_key_pressed("o")
6063
def modifyGravity(self):
61-
for i in self.state.planetAddresses:
62-
call_function("cGcPlanet::UpdateGravity", i, self.state.Gravity, pattern="40 53 48 83 EC 40 83 B9 78") #Used to call an in-game function directly from your mod code. You will need to provide the arguments for the in-game function, as well as the function signature.
63-
logging.info(f"Set Planetary Gravity Multiplier To {self.state.Gravity} For All Planets")
64+
for ptr in self.state.planetAddresses:
65+
# Call an in-game function directly from your mod code.
66+
# You will need to provide the arguments for the in-game function
67+
call_function("cGcPlanet::UpdateGravity", ptr, self.state.gravity)
68+
logger.info(f"Set Planetary Gravity Multiplier To {self.state.gravity} For All Planets")

nms-py-runner/.eslintrc.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

nms-py-runner/.vscodeignore

Lines changed: 0 additions & 10 deletions
This file was deleted.

nms-py-runner/CHANGELOG.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

nms-py-runner/README.md

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)