Skip to content

Commit

Permalink
[Sonic Origins] Various Additions and Fixes (hedge-dev#107)
Browse files Browse the repository at this point in the history
* [Sonic Origins] Fix Enable Lives Codes in Sonic 1

Due to an incorrect global variable offset for `game.playMode`, the Enable Lives Code behaved incorrectly in Sonic 1. This fixes the offset, as well as applying the Sonic 1/2 game check seen in the S1/S2 game option codes.

* [Sonic Origins] Add GetCurrentGame() to RSDK Library

* [Sonic Origins] Add GetEngineVersion() to RSDK Library

* [Sonic Origins] Set LibraryInitializer attribute for RSDK Init()

* [Sonic Origins] Rework GetCurrentGame() to check Data filepath

I had to replace the Helpers library for Origins with a copy of the one for Forces to get this to work. I'm not sure if this would cause any issues, but it works from what I tested. Maybe this library could be reworked into a Global one?

* [Sonic Origins] Include Helpers in RSDK

* [Globals] Added Helpers library

Revert "[Globals] Added Helpers library"

This reverts commit 821fc53.

[Globals] Added Helpers and StringMapOperation libraries

* [Sonic Origins] Rework S1/S2 global variable codes

Instead of constantly setting the S1/S2 global variables through separate codes, a bridge library is now used to handle which variables are set in an unmanaged function called when the game loads. This fixes the initial stage load issue with the shield/item codes.

* [Sonic Origins] Set variable normally in Disable Super Music

* [Sonic Origins] Change how GetCurrentGame() works again

The function now checks the engine version like before, but still checks the data path for S1 vs S2.

* [Sonic Origins] Enable Blue Sphere Options in Title Screen

* [Sonic Origins] Fix GetRSDKGlobalsPtr(), remove GetRSDKGlobalsOffset() and GetRSDKGlobalsAbsPtr()

* [Sonic Origins] Add PlayMode, S3KMedalMods, and S3KSecrets enums

* [Sonic Origins] Enable Super Peel Out

* [Sonic Origins] More Medal Mod/Secret codes

* [Sonic Origins] Add GetPlayMode() to RSDK Library

* Remove extra period

* [Sonic Origins] Add legacy global variable structs to RSDK library

I didn't add a struct for S3&K since I don't believe there's a full, updated list of the globals anywhere.
  • Loading branch information
MegAmi24 authored Feb 13, 2024
1 parent 4288cc0 commit 7b658c6
Show file tree
Hide file tree
Showing 25 changed files with 1,149 additions and 634 deletions.
File renamed without changes.
450 changes: 0 additions & 450 deletions Source/Sonic Forces/Libraries/Helpers.hmm

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ Notes;
#lib "RSDK"
//
{
if (RSDK.GetRSDKGlobalsAbsPtr() == 0)
if (RSDK.GetRSDKGlobalsPtr() == 0)
return;

WriteProtected<byte>(RSDK.GetRSDKGlobalsAbsPtr() - 0x08, 0x00);
}

*(byte*)(RSDK.GetRSDKGlobalsPtr() + 0x4C33FC) = 0;
}
75 changes: 39 additions & 36 deletions Source/Sonic Origins/Gameplay/Enable Lives in Anniversary Mode.hmm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Code "Enable Lives in Anniversary Mode" in "Gameplay" by "ĐeäTh" does
Code "Enable Lives in Anniversary Mode" in "Gameplay" by "ĐeäTh & MegAmi" does
/*
Disables the flag for Coins when playing in Anniversary Mode.

Expand All @@ -9,47 +9,50 @@ Notes;
#lib "RSDK"
//
{
// Check if Sonic 1 game.playMode is set to BOOT_PLAYMODE_ANNIVERSARY
// Version 1.0.0 and 1.0.4: RSDKv4DataPtr + 0x1A4
if (*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x1FC) == 1)
{
// Sonic 1 Coin Mode
*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x1FC) = 0;
}
if (RSDK.GetPlayMode() != RSDK.PlayMode.Anniversary || RSDK.GetPlayMode() == RSDK.PlayMode.Unknown)
return;

// Check if Sonic 2 game.playMode is set to BOOT_PLAYMODE_ANNIVERSARY
if (*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x23C) == 1)
if (RSDK.GetCurrentGame() == RSDK.Game.Sonic1)
{
// Sonic 2 Coin Mode
*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x288) = 0;
}
var S1Globals = RSDK.GetSonic1Globals();

// Check if RSDKv3 game.playMode is set to BOOT_PLAYMODE_ANNIVERSARY
if (*(byte*)(RSDK.GetRSDKv3DataPtr() + 0x1DC) == 1)
if (S1Globals == null)
return;

S1Globals->gameCoinMode = 0;
}
else if (RSDK.GetCurrentGame() == RSDK.Game.SonicCD)
{
// Sonic CD Coin Mode
*(byte*)(RSDK.GetRSDKv3DataPtr() + 0x220) = 0;
var SCDGlobals = RSDK.GetSonicCDGlobals();

if (SCDGlobals == null)
return;

SCDGlobals->gameCoinMode = 0;
}
else if (RSDK.GetCurrentGame() == RSDK.Game.Sonic2)
{
var S2Globals = RSDK.GetSonic2Globals();

if (S2Globals == null)
return;

// Sonic 3&K Coin Mode and HUD Update
if (RSDK.GetRSDKGlobalsAbsPtr() != 0)
S2Globals->gameCoinMode = 0;
}
else if (RSDK.GetCurrentGame() == RSDK.Game.Sonic3k)
{
// Check if game.playMode is set to BOOT_PLAYMODE_ANNIVERSARY
// Version 1.0.0: RSDKGlobalsPtr + 0x447D08
// Version 1.0.4: RSDKGlobalsPtr + 0x4C3508 (Thanks to RDC)
// Version 2.0.0: RSDKGlobalsPtr + RSDKGlobalsOffset + 0x104
if (*(byte*)(RSDK.GetRSDKGlobalsAbsPtr() + 0x10C) == 1)
{
// HUD Update
// Version 1.0.0: RSDKGlobalsPtr + 0x447D20
// Version 1.0.4: RSDKGlobalsPtr + 0x4C34D4 (Thanks to RDC)
*(byte*)(RSDK.GetRSDKGlobalsAbsPtr() + 0xD0) = 0;

// Coin Mode
// Version 1.0.0: RSDKGlobalsPtr + 0x447CD4
// Version 1.0.4: RSDKGlobalsPtr + 0x4C3520 (Thanks to RDC)
// Version 2.0.0: RSDKGlobalsPtr + RSDKGlobalsOffset + 0x124
*(byte*)(RSDK.GetRSDKGlobalsAbsPtr() + 0x124) = 0;
}
if (RSDK.GetRSDKGlobalsPtr() == 0)
return;

// HUD Update
// Version 1.0.0: RSDKGlobalsPtr + 0x447D20
// Version 1.0.4: RSDKGlobalsPtr + 0x4C34D4 (Thanks to RDC)
*(byte*)(RSDK.GetRSDKGlobalsPtr() + 0x4C34D4) = 0;

// Coin Mode
// Version 1.0.0: RSDKGlobalsPtr + 0x447CD4
// Version 1.0.4: RSDKGlobalsPtr + 0x4C3520 (Thanks to RDC)
// Version 2.0.0: RSDKGlobalsPtr + 0x4C3528
*(byte*)(RSDK.GetRSDKGlobalsPtr() + 0x4C3528) = 0;
}
}
75 changes: 39 additions & 36 deletions Source/Sonic Origins/Gameplay/Enable Lives in Mirror Mode.hmm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Code "Enable Lives in Mirror Mode" in "Gameplay" by "ĐeäTh" does
Code "Enable Lives in Mirror Mode" in "Gameplay" by "ĐeäTh & MegAmi" does
/*
Disables the flag for Coins when playing in Mirror Mode.

Expand All @@ -9,47 +9,50 @@ Notes;
#lib "RSDK"
//
{
// Check if Sonic 1 game.playMode is set to BOOT_PLAYMODE_MIRRORING
// Version 1.0.0 and 1.0.4: RSDKv4DataPtr + 0x1A4
if (*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x1FC) == 3)
{
// Sonic 1 Coin Mode
*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x1FC) = 0;
}
if (RSDK.GetPlayMode() != RSDK.PlayMode.Mirror || RSDK.GetPlayMode() == RSDK.PlayMode.Unknown)
return;

// Check if Sonic 2 game.playMode is set to BOOT_PLAYMODE_MIRRORING
if (*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x23C) == 3)
if (RSDK.GetCurrentGame() == RSDK.Game.Sonic1)
{
// Sonic 2 Coin Mode
*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x288) = 0;
}
var S1Globals = RSDK.GetSonic1Globals();

// Check if RSDKv3 game.playMode is set to BOOT_PLAYMODE_MIRRORING
if (*(byte*)(RSDK.GetRSDKv3DataPtr() + 0x1DC) == 3)
if (S1Globals == null)
return;

S1Globals->gameCoinMode = 0;
}
else if (RSDK.GetCurrentGame() == RSDK.Game.SonicCD)
{
// Sonic CD Coin Mode
*(byte*)(RSDK.GetRSDKv3DataPtr() + 0x220) = 0;
var SCDGlobals = RSDK.GetSonicCDGlobals();

if (SCDGlobals == null)
return;

SCDGlobals->gameCoinMode = 0;
}
else if (RSDK.GetCurrentGame() == RSDK.Game.Sonic2)
{
var S2Globals = RSDK.GetSonic2Globals();

if (S2Globals == null)
return;

// Sonic 3&K Coin Mode and HUD Update
if (RSDK.GetRSDKGlobalsAbsPtr() != 0)
S2Globals->gameCoinMode = 0;
}
else if (RSDK.GetCurrentGame() == RSDK.Game.Sonic3k)
{
// Check if game.playMode is set to BOOT_PLAYMODE_ANNIVERSARY
// Version 1.0.0: RSDKGlobalsPtr + 0x447D08
// Version 1.0.4: RSDKGlobalsPtr + 0x4C3508 (Thanks to RDC)
// Version 2.0.0: RSDKGlobalsPtr + RSDKGlobalsOffset + 0x104
if (*(byte*)(RSDK.GetRSDKGlobalsAbsPtr() + 0x10C) == 3)
{
// HUD Update
// Version 1.0.0: RSDKGlobalsPtr + 0x447D20
// Version 1.0.4: RSDKGlobalsPtr + 0x4C34D4 (Thanks to RDC)
*(byte*)(RSDK.GetRSDKGlobalsAbsPtr() + 0xD0) = 0;

// Coin Mode
// Version 1.0.0: RSDKGlobalsPtr + 0x447CD4
// Version 1.0.4: RSDKGlobalsPtr + 0x4C3520 (Thanks to RDC)
// Version 2.0.0: RSDKGlobalsPtr + RSDKGlobalsOffset + 0x124
*(byte*)(RSDK.GetRSDKGlobalsAbsPtr() + 0x124) = 0;
}
if (RSDK.GetRSDKGlobalsPtr() == 0)
return;

// HUD Update
// Version 1.0.0: RSDKGlobalsPtr + 0x447D20
// Version 1.0.4: RSDKGlobalsPtr + 0x4C34D4 (Thanks to RDC)
*(byte*)(RSDK.GetRSDKGlobalsPtr() + 0x4C34D4) = 0;

// Coin Mode
// Version 1.0.0: RSDKGlobalsPtr + 0x447CD4
// Version 1.0.4: RSDKGlobalsPtr + 0x4C3520 (Thanks to RDC)
// Version 2.0.0: RSDKGlobalsPtr + 0x4C3528
*(byte*)(RSDK.GetRSDKGlobalsPtr() + 0x4C3528) = 0;
}
}
12 changes: 2 additions & 10 deletions Source/Sonic Origins/Gameplay/Sonic 1/Enable 7th Chaos Emerald.hmm
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@ Notes;
- The game does not check the emeralds setting when checking if the player should transform, so collecting all seven emeralds in a save file will allow the player to transform regardless of whether or not this code is enabled.
*/
//
#lib "RSDK"
#lib "Bridge.SetGlobalVariables"
//
{
// Check if this is Sonic 1
if (*(byte*)(RSDK.GetRSDKv4DataPtr() + 0xC8) == 0xFF)
{
// Check if Super forms (options.superStates) are disabled
if (*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x38) != 0x01)
{
*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x38) = 0x01;
}
}
Bridge.SetGlobalVariables.IsEnabledSuperFormsS1 = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@ Code "Enable Elemental Shields and Insta Shield (experimental)" in "Gameplay/Son
Enables the Elemental Shields and Sonic's Insta Shield move.

Known issues;
- The elemental shield monitors will not appear upon initial stage load when starting the game from the main menu. This is fixed upon loading the stage again or loading a different one.
- Progress in save files will not be saved.
*/
//
#lib "RSDK"
#lib "Bridge.SetGlobalVariables"
//
{
// Check if this is Sonic 1
if (*(byte*)(RSDK.GetRSDKv4DataPtr() + 0xC8) == 0xFF)
{
// Check if elemental shields (second bit of options.shieldType) are disabled
if ((*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x34) & 2) == 0)
{
*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x34) |= 2;
}
}
Bridge.SetGlobalVariables.IsEnabledElementalS1 = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@ Code "Enable Sonic 2 Style Items (experimental)" in "Gameplay/Sonic 1" by "MegAm
Enables the Sonic 2 style Blue Shield and invincibility stars.

Known issues;
- The Sonic 1 style items will still appear upon initial stage load when starting the game from the main menu. This is fixed upon loading the stage again or loading a different one.
- Progress in save files will not be saved.
*/
//
#lib "RSDK"
#lib "Bridge.SetGlobalVariables"
//
{
// Check if this is Sonic 1
if (*(byte*)(RSDK.GetRSDKv4DataPtr() + 0xC8) == 0xFF)
{
// Check if S2 items (first bit of options.shieldType) are disabled
if ((*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x34) & 1) == 0)
{
*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x34) |= 1;
}
}
Bridge.SetGlobalVariables.IsEnabledS2ItemsS1 = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@ Code "Enable Elemental Shields and Insta Shield (experimental)" in "Gameplay/Son
Enables the Elemental Shields and Sonic's Insta Shield move.

Known issues;
- The elemental shield monitors will not appear upon initial stage load when starting the game from the main menu. This is fixed upon loading the stage again or loading a different one.
- Progress in save files will not be saved.
*/
//
#lib "RSDK"
#lib "Bridge.SetGlobalVariables"
//
{
// Check if this is Sonic 2
if (*(byte*)(RSDK.GetRSDKv4DataPtr() + 0xC8) != 0xFF)
{
// Check if elemental shields (first bit of options.shieldType) are disabled
if ((*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x30) & 1) == 0)
{
*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x30) |= 1;
}
}
Bridge.SetGlobalVariables.IsEnabledElementalS2 = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@ Code "Enable Random Monitors (experimental)" in "Gameplay/Sonic 2" by "MegAmi" d
Replaces all monitors in the stages with random monitors.

Known issues;
- The random monitors will not appear upon initial stage load when starting the game from the main menu. This is fixed upon loading the stage again or loading a different one.
- Progress in save files will not be saved.
*/
//
#lib "RSDK"
#lib "Bridge.SetGlobalVariables"
//
{
// Check if this is Sonic 2
if (*(byte*)(RSDK.GetRSDKv4DataPtr() + 0xC8) != 0xFF)
{
// Check if random monitors (second bit of options.shieldType) are disabled
if ((*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x30) & 2) == 0)
{
*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x30) |= 2;
}
}
Bridge.SetGlobalVariables.IsEnabledRandomS2 = true;
}
12 changes: 2 additions & 10 deletions Source/Sonic Origins/Gameplay/Sonic 2/Enable Super Tails.hmm
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@ Notes;
- Due to using the same palette colors as Tails, the Coins icon will flash along with Tails when in his Super form.
*/
//
#lib "RSDK"
#lib "Bridge.SetGlobalVariables"
//
{
// Check if this is Sonic 2
if (*(byte*)(RSDK.GetRSDKv4DataPtr() + 0xC8) != 0xFF)
{
// Check if Super Tails (options.superTails) is disabled
if (*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x40) != 0x01)
{
*(byte*)(RSDK.GetRSDKv4DataPtr() + 0x40) = 0x01;
}
}
Bridge.SetGlobalVariables.IsEnabledSuperTailsS2 = true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Code "Enable Super Dash" in "Gameplay/Sonic 3 & Knuckles/Abilities" by "MegAmi" does "Allows the player to fly and dash in any cardinal direction when in Super/Hyper form, similar to Sonic Mania's Egg Reverie Zone."
//
#lib "RSDK"
//
{
if (RSDK.GetRSDKGlobalsPtr() == 0)
return;

*(int*)(RSDK.GetRSDKGlobalsPtr() + 0x4C33F0) |= (int)RSDK.S3KSecret.SuperDash;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Code "Disable Drop Dash" in "Gameplay/Sonic 3 & Knuckles/Abilities/Sonic" by "MegAmi"
//
#lib "RSDK"
//
{
if (RSDK.GetRSDKGlobalsPtr() == 0)
return;

*(int*)(RSDK.GetRSDKGlobalsPtr() + 0xC2CB4) |= (int)RSDK.S3KMedalMod.NoDropDash;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Code "Disable Insta-Shield" in "Gameplay/Sonic 3 & Knuckles/Abilities/Sonic" by "MegAmi"
//
#lib "RSDK"
//
{
if (RSDK.GetRSDKGlobalsPtr() == 0)
return;

*(int*)(RSDK.GetRSDKGlobalsPtr() + 0xC2CB4) &= ~(int)RSDK.S3KMedalMod.InstaShield;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Code "Enable Super Peel Out" in "Gameplay/Sonic 3 & Knuckles/Abilities/Sonic" by "MegAmi" does
/*
Enables Sonic's Super Peel Out move from Sonic CD.

Notes;
- Super/Hyper Sonic doesn't have an animation for the Super Peel Out, instead defaulting to his rolling animation.
*/
//
#lib "RSDK"
//
{
if (RSDK.GetRSDKGlobalsPtr() == 0)
return;

*(int*)(RSDK.GetRSDKGlobalsPtr() + 0xC2CB4) |= (int)RSDK.S3KMedalMod.SuperPeelOut;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Code "Enable Banana Mode" in "Gameplay/Sonic 3 & Knuckles/Items" by "MegAmi" does "Replaces all monitors in the stages with Banana monitors."
//
#lib "RSDK"
//
{
if (RSDK.GetRSDKGlobalsPtr() == 0)
return;

*(int*)(RSDK.GetRSDKGlobalsPtr() + 0x4C33F0) |= (int)RSDK.S3KSecret.BananaMode;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Code "Enable Blue Shield Monitors" in "Gameplay/Sonic 3 & Knuckles/Items" by "MegAmi" does "Replaces all Elemental Shield monitors with Blue Shield monitors."
//
#lib "RSDK"
//
{
if (RSDK.GetRSDKGlobalsPtr() == 0)
return;

*(int*)(RSDK.GetRSDKGlobalsPtr() + 0x4C33F0) |= (int)RSDK.S3KSecret.BlueShield;
}
Loading

0 comments on commit 7b658c6

Please sign in to comment.