11import logging
2- from dataclasses import dataclass
2+ import ctypes
3+ from dataclasses import dataclass , field
34
45from pymhf .core .hooking import on_key_pressed
56from pymhf .core .mod_loader import ModState
6- from nmspy import NMSMod
7- from pymhf .core .calling import call_function
7+ from pymhf import Mod
88from pymhf .gui import FLOAT
9- import nmspy .data .functions . hooks as hooks
9+ import nmspy .data .types as nms
1010
1111# A quick mod used to change the gravity multiplier on all planets simultaneously, utilizing pyMHF's auto-gui.
1212
1717class gravModState (ModState ):
1818 # A special class inheriting from ModState which persists between mod Hot Reloads, allowing mod developers
1919 # to cache pointers, values etc.
20- gravity : int = 1
21- planetAddresses : list [int ] = []
20+ gravity : float = 1
21+ planets : list [nms . cGcPlanet ] = field ( default_factory = list )
2222
2323
24- class gravityManipulator (NMSMod ):
24+ class gravityManipulator (Mod ):
2525 # General "Nice To Have"s
26- __author__ = "ThatBomberBoi"
26+ __author__ = [ "ThatBomberBoi" , "monkeyman192" ]
2727 __description__ = "Gravity Manipulator"
2828 __version__ = "0.2"
2929 __NMSPY_required_version__ = "0.7.0"
@@ -49,20 +49,22 @@ def gravMult(self, value):
4949 # Functions are hooked by specifying the function to be hooked from the list of in game functions
5050 # available. You can specify whether you want your detour to run either before or after the original
5151 # function as shown below.
52- @hooks .cGcPlanet .SetupRegionMap .after
53- def onRegionMap (self , this ):
52+ @nms .cGcPlanet .SetupRegionMap .after
53+ def onRegionMap (self , this : ctypes . _Pointer [ nms . cGcPlanet ] ):
5454 # Include each in-game function's arguments seperately in the function, or use *args to get all
5555 # arguments without knowing them prior.
5656 # In this case we know that the argument is `this` which is a pointer to the instance of `cGcPlanet`
5757 # which is automatically passed into this function by the game.
58- logger .info (f"Generated A Planet!" )
59- self .state .planetAddresses .append (this )
60- logger .debug (f"Found { len (self .state .planetAddresses )} Planets So Far" )
58+ planet = this .contents
59+ self .state .planets .append (this .contents )
60+ biome = planet .mPlanetGenerationInputData .Biome
61+ logger .info (f"Generated a { biome .name } Planet!" )
62+ logger .debug (f"Found { len (self .state .planets )} Planets So Far" )
6163
6264 @on_key_pressed ("o" )
6365 def modifyGravity (self ):
64- for ptr in self .state .planetAddresses :
66+ for planet in self .state .planets :
6567 # Call an in-game function directly from your mod code.
6668 # You will need to provide the arguments for the in-game function
67- call_function ( "cGcPlanet:: UpdateGravity" , ptr , self .state .gravity )
69+ planet . UpdateGravity ( self .state .gravity )
6870 logger .info (f"Set Planetary Gravity Multiplier To { self .state .gravity } For All Planets" )
0 commit comments