You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# A quick mod used to change the gravity multiplier on all planets simultaneously, utilizing pyMHF's auto-gui.
16
12
13
+
logger=logging.getLogger("GravMod")
14
+
15
+
17
16
@dataclass
18
-
classgravModState(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
+
classgravModState(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
+
21
23
22
-
@disable
23
24
classgravityManipulator(NMSMod):
24
-
#General "Nice To Have"s
25
+
#General "Nice To Have"s
25
26
__author__="ThatBomberBoi"
26
27
__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"
29
30
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()
32
33
33
34
def__init__(self):
34
35
super().__init__()
35
36
self.should_print=False
36
37
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.
38
39
@property
39
40
@FLOAT("Gravity Multiplier:")
40
41
defgravMult(self):
41
-
returnself.state.Gravity
42
+
returnself.state.gravity
42
43
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.
44
45
@gravMult.setter
45
46
defgravMult(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).
#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.
defonRegionMap(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
+
defonRegionMap(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!")
56
59
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")
58
61
59
62
@on_key_pressed("o")
60
63
defmodifyGravity(self):
61
-
foriinself.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
+
forptrinself.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
0 commit comments