@@ -77,6 +77,9 @@ [ HookDef( BaseGame.Mr2, Region.Us, "51 56 8B F1 8B 0D ?? ?? ?? ??" )]
7777[ Function ( CallingConventions . Fastcall ) ]
7878public delegate void H_LoadingRanch ( int unk1 , int unk2 , nuint unk3 , nuint unk4 ) ;
7979
80+ [ HookDef ( BaseGame . Mr2 , Region . Us , "55 8B EC 83 E4 F8 83 EC 24 A1 ?? ?? ?? ?? 33 C4 89 44 24 ?? 53" ) ]
81+ [ Function ( CallingConventions . MicrosoftThiscall ) ]
82+ public delegate void H_WormCocoonStart ( nuint unk1 , nuint unk2 , nuint unk3ptr ) ;
8083
8184
8285public class Mod : ModBase // <= Do not Remove.
@@ -96,14 +99,16 @@ public class Mod : ModBase // <= Do not Remove.
9699
97100 // Offsets are exact for monster values. For Freezer Data, add +2.
98101 public static short memory_mm_version = 1 ; // Versioning starts at 1, with 0.5.0
99- public static nuint offset_mm_version { get { return 0x15C ; } }
102+ public static nuint offset_mm_version { get { return 0x159 ; } }
103+ public static nuint offset_mm_wormsub { get { return 0x162 ; } }
100104 public static nuint offset_mm_truemain { get { return 0x163 ; } }
101105 public static nuint offset_mm_alternate { get { return 0x164 ; } }
102106 public static nuint offset_mm_scaling { get { return 0x165 ; } }
103107 public static nuint offset_mm_truesub { get { return 0x166 ; } }
104108 public static nuint offset_mm_trueguts { get { return 0x167 ; } }
105109
106110 public static nuint address_monster_mm_version { get { return address_monster + offset_mm_version ; } }
111+ public static nuint address_monster_mm_wormsub { get { return address_monster + offset_mm_wormsub ; } }
107112 public static nuint address_monster_mm_truemain { get { return address_monster + offset_mm_truemain ; } }
108113 public static nuint address_monster_mm_alternate { get { return address_monster + offset_mm_alternate ; } }
109114 public static nuint address_monster_mm_scaling { get { return address_monster + offset_mm_scaling ; } }
@@ -139,6 +144,8 @@ public class Mod : ModBase // <= Do not Remove.
139144 private IHook < H_FileSave > _hook_fileSave ;
140145 private IHook < H_LoadingRanch > _hook_loadingRanch ;
141146
147+ private IHook < H_WormCocoonStart > _hook_wormCocoonStart ;
148+
142149 private IHook < H_ShrineMonsterUnlockedChecker > _hook_shrineMonsterUnlockedChecker ;
143150
144151 private int _loadedFileCorrectFreezer = 0 ;
@@ -150,7 +157,6 @@ public class Mod : ModBase // <= Do not Remove.
150157
151158 private Dictionary < int , ( MMBreed , byte ) > _songIDMapping = new Dictionary < int , ( MMBreed , byte ) > ( ) ;
152159
153-
154160 private IHook < H_GetMonsterBreedName > _hook_monsterBreedNames ;
155161
156162 public CombinationHandler handlerCombination ;
@@ -235,6 +241,8 @@ public Mod(ModContext context)
235241
236242 _iHooks . AddHook < H_LoadingRanch > ( HFLoadingRanch ) . ContinueWith ( result => _hook_loadingRanch = result . Result ) ;
237243
244+ //_iHooks.AddHook<H_WormCocoonStart>( HF_WormCocoonStart ).ContinueWith( result => _hook_wormCocoonStart = result.Result );
245+
238246 _iHooks . AddHook < H_ShrineMonsterUnlockedChecker > ( CheckShrineMonsterUnlocked ) . ContinueWith ( result => _hook_shrineMonsterUnlockedChecker = result . Result ) ;
239247
240248 handlerFreezer = new FreezerHandler ( this , _iHooks , _monsterCurrent ) ;
@@ -598,14 +606,18 @@ private int SetupMysteryStat ( nuint self ) {
598606 var ret = _hook_statUpdate ! . OriginalFunction ( self ) ;
599607
600608 if ( shrineReplacementActive ) {
601- // TODO - Choose Random Variant or something akin to that. _shrineReplacementMonster._monsterVariants[ 0 ];
602609 var variant = MonsterBreed . GetBreed ( _shrineReplacementMonster . _genusNewMain , _shrineReplacementMonster . _genusNewSub ) ;
603610 WriteMonsterData ( variant ) ;
604611
605612 Memory . Instance . Write ( address_monster_mm_alternate , _shrineMonsterAlternate ) ;
606613
607614 shrineReplacementActive = false ;
608615 }
616+
617+ if ( _monsterCurrent . GenusMain == MonsterGenus . Worm ) { // Handle Worm Info
618+ Memory . Instance . WriteRaw ( Mod . address_monster_mm_wormsub , [ ( byte ) ( _monsterCurrent . GenusSub + 1 ) ] ) ;
619+ }
620+
609621 return ret ;
610622 }
611623
@@ -764,6 +776,7 @@ private void VersionUpdateFreezerMonster_V0x5x0_MM1 ( byte freezerSlot ) {
764776 var mainPosMM = startPos + offset_mm_truemain + 0x8 ;
765777 var subPosMM = startPos + offset_mm_truesub + 0x8 ;
766778 var gutsPosMM = startPos + offset_mm_trueguts + 0x8 ;
779+ var wormPosMM = startPos + offset_mm_wormsub + 0x8 ;
767780
768781 byte mmMain = ( byte ) ( mainA + 1 ) ;
769782 byte mmSub = ( byte ) ( subA + 1 ) ;
@@ -782,6 +795,11 @@ private void VersionUpdateFreezerMonster_V0x5x0_MM1 ( byte freezerSlot ) {
782795 Memory . Instance . Write < Byte > ( gutsPosMM , ref gutsA ) ;
783796 }
784797
798+ // Handle Worm
799+ if ( ( MonsterGenus ) mainA == MonsterGenus . Worm ) {
800+ Memory . Instance . Write < byte > ( wormPosMM , ref mmSub ) ;
801+ }
802+
785803 Logger . Info ( $ "Monster in Freezer Slot { freezerSlot } updated to Version 0.5.0 Standards (v1)." ) ;
786804 }
787805
@@ -880,6 +898,25 @@ private void HFLoadingRanch ( int unk1, int unk2, nuint unk3, nuint unk4 ) {
880898 Memory . Instance . WriteRaw ( address_game + 0x571470 , rawSoundData ) ;
881899 }
882900
901+ /// <summary>
902+ /// This function refuses to hook properly so we're doing it another way for now. Leaving it in as this is the PROPER way to do things.
903+ /// THis should be writing the Worm's Sub ON Cocoon, instead it crashes the game. Cool!
904+ /// </summary>
905+ /// <param name="self"></param>
906+ /// <param name="unk1"></param>
907+ /// <param name="unk2"></param>
908+ /// <param name="unk3ptr"></param>
909+ public void HF_WormCocoonStart ( nuint unk1 , nuint unk2 , nuint unk3ptr ) {
910+
911+ Logger . Debug ( $ "Worm Cocoon Starting with { unk1 } , { unk2 } , { unk3ptr } .", Color . WhiteSmoke ) ;
912+ byte wormSub = ( byte ) ( ( byte ) _monsterCurrent . GenusSub + 1 ) ;
913+ Memory . Instance . Write < byte > ( address_monster_mm_wormsub , ref wormSub ) ;
914+
915+ _hook_wormCocoonStart ! . OriginalFunction ( unk1 , unk2 , unk3ptr ) ;
916+ Logger . Debug ( $ "Worm Sub : { wormSub } written to MM Data.", Color . WhiteSmoke ) ;
917+
918+
919+ }
883920 /// <summary>
884921 /// This function replaces the location where the game is looking for sound data when wandering around on the ranch.
885922 /// Errantry files can only be of length 0x7EF.
0 commit comments