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
+
17
+
@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()
21
+
22
+
@disable
23
+
classgravityManipulator(NMSMod):
24
+
#General "Nice To Have"s
25
+
__author__="ThatBomberBoi"
26
+
__description__="Gravity Manipulator"
27
+
__version__="0.1"
28
+
__NMSPY_required_version__="0.7.0"
29
+
30
+
#Create an instance of the persistant ModState Class in your mod class.
31
+
state=gravModState()
32
+
33
+
def__init__(self):
34
+
super().__init__()
35
+
self.should_print=False
36
+
37
+
#Used to define a Float Type with a label in the Mod GUI, autogenerated by pyMHF.
38
+
@property
39
+
@FLOAT("Gravity Multiplier:")
40
+
defgravMult(self):
41
+
returnself.state.Gravity
42
+
43
+
#Used to actually update the persisted value with the one input by the user in the GUI.
44
+
@gravMult.setter
45
+
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!")
56
+
self.state.planetAddresses.append(this)
57
+
logging.debug(f"Found {len(self.state.planetAddresses)} Planets So Far")
58
+
59
+
@on_key_pressed("o")
60
+
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")
0 commit comments