├── .gitattributes ├── .gitignore ├── .gitmodules ├── sadx-super-sonic.sln └── sadx-super-sonic ├── mod.cpp ├── mod.ini ├── sadx-super-sonic.vcxproj ├── sadx-super-sonic.vcxproj.filters ├── stdafx.cpp └── stdafx.h /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | # DNX 42 | project.lock.json 43 | artifacts/ 44 | 45 | *_i.c 46 | *_p.c 47 | *_i.h 48 | *.ilk 49 | *.meta 50 | *.obj 51 | *.pch 52 | *.pdb 53 | *.pgc 54 | *.pgd 55 | *.rsp 56 | *.sbr 57 | *.tlb 58 | *.tli 59 | *.tlh 60 | *.tmp 61 | *.tmp_proj 62 | *.log 63 | *.vspscc 64 | *.vssscc 65 | .builds 66 | *.pidb 67 | *.svclog 68 | *.scc 69 | 70 | # Chutzpah Test files 71 | _Chutzpah* 72 | 73 | # Visual C++ cache files 74 | ipch/ 75 | *.aps 76 | *.ncb 77 | *.opensdf 78 | *.sdf 79 | *.cachefile 80 | 81 | # Visual Studio profiler 82 | *.psess 83 | *.vsp 84 | *.vspx 85 | 86 | # TFS 2012 Local Workspace 87 | $tf/ 88 | 89 | # Guidance Automation Toolkit 90 | *.gpState 91 | 92 | # ReSharper is a .NET coding add-in 93 | _ReSharper*/ 94 | *.[Rr]e[Ss]harper 95 | *.DotSettings.user 96 | 97 | # JustCode is a .NET coding add-in 98 | .JustCode 99 | 100 | # TeamCity is a build add-in 101 | _TeamCity* 102 | 103 | # DotCover is a Code Coverage Tool 104 | *.dotCover 105 | 106 | # NCrunch 107 | _NCrunch_* 108 | .*crunch*.local.xml 109 | 110 | # MightyMoose 111 | *.mm.* 112 | AutoTest.Net/ 113 | 114 | # Web workbench (sass) 115 | .sass-cache/ 116 | 117 | # Installshield output folder 118 | [Ee]xpress/ 119 | 120 | # DocProject is a documentation generator add-in 121 | DocProject/buildhelp/ 122 | DocProject/Help/*.HxT 123 | DocProject/Help/*.HxC 124 | DocProject/Help/*.hhc 125 | DocProject/Help/*.hhk 126 | DocProject/Help/*.hhp 127 | DocProject/Help/Html2 128 | DocProject/Help/html 129 | 130 | # Click-Once directory 131 | publish/ 132 | 133 | # Publish Web Output 134 | *.[Pp]ublish.xml 135 | *.azurePubxml 136 | ## TODO: Comment the next line if you want to checkin your 137 | ## web deploy settings but do note that will include unencrypted 138 | ## passwords 139 | #*.pubxml 140 | 141 | *.publishproj 142 | 143 | # NuGet Packages 144 | *.nupkg 145 | # The packages folder can be ignored because of Package Restore 146 | **/packages/* 147 | # except build/, which is used as an MSBuild target. 148 | !**/packages/build/ 149 | # Uncomment if necessary however generally it will be regenerated when needed 150 | #!**/packages/repositories.config 151 | 152 | # Windows Azure Build Output 153 | csx/ 154 | *.build.csdef 155 | 156 | # Windows Store app package directory 157 | AppPackages/ 158 | 159 | # Visual Studio cache files 160 | # files ending in .cache can be ignored 161 | *.[Cc]ache 162 | # but keep track of directories ending in .cache 163 | !*.[Cc]ache/ 164 | 165 | # Others 166 | ClientBin/ 167 | [Ss]tyle[Cc]op.* 168 | ~$* 169 | *~ 170 | *.dbmdl 171 | *.dbproj.schemaview 172 | *.pfx 173 | *.publishsettings 174 | node_modules/ 175 | orleans.codegen.cs 176 | 177 | # RIA/Silverlight projects 178 | Generated_Code/ 179 | 180 | # Backup & report files from converting an old project file 181 | # to a newer Visual Studio version. Backup files are not needed, 182 | # because we have git ;-) 183 | _UpgradeReport_Files/ 184 | Backup*/ 185 | UpgradeLog*.XML 186 | UpgradeLog*.htm 187 | 188 | # SQL Server files 189 | *.mdf 190 | *.ldf 191 | 192 | # Business Intelligence projects 193 | *.rdl.data 194 | *.bim.layout 195 | *.bim_*.settings 196 | 197 | # Microsoft Fakes 198 | FakesAssemblies/ 199 | 200 | # Node.js Tools for Visual Studio 201 | .ntvs_analysis.dat 202 | 203 | # Visual Studio 6 build log 204 | *.plg 205 | 206 | # Visual Studio 6 workspace options file 207 | *.opt 208 | 209 | # LightSwitch generated files 210 | GeneratedArtifacts/ 211 | _Pvt_Extensions/ 212 | ModelManifest.xml 213 | *.opendb 214 | *.db 215 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "sadx-mod-loader"] 2 | path = sadx-mod-loader 3 | url = https://github.com/sonicretro/sadx-mod-loader.git 4 | -------------------------------------------------------------------------------- /sadx-super-sonic.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sadx-super-sonic", "sadx-super-sonic\sadx-super-sonic.vcxproj", "{073FF02A-AFE3-41C5-A5A3-3268EA5492A3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x86 = Debug|x86 11 | Release|x86 = Release|x86 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {073FF02A-AFE3-41C5-A5A3-3268EA5492A3}.Debug|x86.ActiveCfg = Debug|Win32 15 | {073FF02A-AFE3-41C5-A5A3-3268EA5492A3}.Debug|x86.Build.0 = Debug|Win32 16 | {073FF02A-AFE3-41C5-A5A3-3268EA5492A3}.Release|x86.ActiveCfg = Release|Win32 17 | {073FF02A-AFE3-41C5-A5A3-3268EA5492A3}.Release|x86.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /sadx-super-sonic/mod.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | 4 | #define EXPORT __declspec(dllexport) 5 | 6 | FunctionPointer(int, _rand, (void), 0x006443BF); 7 | 8 | static int ring_timer = 0; 9 | static int super_count = 0; // Dirty hack for multitap mod compatibility 10 | static short last_level = 0; 11 | static short last_act = 0; 12 | static int level_song = 0; 13 | static Uint8 last_action[8] = {}; 14 | 15 | static const int clips[] = { 16 | 402, 17 | 508, 18 | 874, 19 | 1427, 20 | 1461 21 | }; 22 | 23 | static void set_music() 24 | { 25 | if (!Music_Enabled || CurrentSong == MusicIDs_ThemeOfSuperSonic) 26 | { 27 | return; 28 | } 29 | 30 | last_level = CurrentLevel; 31 | last_act = CurrentAct; 32 | 33 | level_song = LastSong; 34 | LastSong = CurrentSong = MusicIDs_ThemeOfSuperSonic; 35 | } 36 | static void restore_music() 37 | { 38 | if (!Music_Enabled) 39 | { 40 | return; 41 | } 42 | 43 | LastSong = CurrentSong = level_song; 44 | } 45 | 46 | static void __cdecl _Sonic_SuperPhysics_Delete(ObjectMaster* _this) 47 | { 48 | int index = *static_cast(_this->UnknownB_ptr); 49 | CharObj2* data2 = CharObj2Ptrs[index]; 50 | 51 | if (data2 != nullptr) 52 | { 53 | data2->PhysicsData = PhysicsArray[Characters_Sonic]; 54 | } 55 | } 56 | 57 | static void __cdecl SuperSonicManager_Main(ObjectMaster* _this) 58 | { 59 | if (super_count < 1) 60 | { 61 | DeleteObject_(_this); 62 | return; 63 | } 64 | 65 | if (CurrentSong != -1 && (CurrentLevel != last_level || CurrentAct != last_act)) 66 | { 67 | set_music(); 68 | } 69 | 70 | // HACK: Result screen disables P1 control. There's probably a nicer way to do this, we just need to find it. 71 | if (IsControllerEnabled(0)) 72 | { 73 | ++ring_timer %= 60; 74 | 75 | if (!ring_timer) 76 | { 77 | AddRings(-1); 78 | } 79 | } 80 | } 81 | static void __cdecl SuperSonicManager_Delete(ObjectMaster* _this) 82 | { 83 | super_count = 0; 84 | ring_timer = 0; 85 | restore_music(); 86 | } 87 | static void SuperSonicManager_Load() 88 | { 89 | ObjectMaster* obj = LoadObject(static_cast(0), 2, SuperSonicManager_Main); 90 | 91 | if (obj) 92 | { 93 | obj->DeleteSub = SuperSonicManager_Delete; 94 | } 95 | 96 | set_music(); 97 | } 98 | 99 | static int __stdcall SuperWaterCheck_C(EntityData1* data1, CharObj2* data2) 100 | { 101 | auto pad = ControllerPointers[static_cast(data1->CharIndex)]; 102 | 103 | if (data1->CharID == Characters_Sonic && (data2->Upgrades & Upgrades_SuperSonic) != 0) 104 | { 105 | return pad && !(pad->HeldButtons & AttackButtons); 106 | } 107 | 108 | return false; 109 | } 110 | 111 | static const void* surface_solid = reinterpret_cast(0x004496E7); 112 | static const void* surface_water = reinterpret_cast(0x004497B6); 113 | static void __declspec(naked) SuperWaterCheck() 114 | { 115 | __asm 116 | { 117 | // If Gamma, treat surface as solid 118 | jnz not_gamma 119 | jmp surface_solid 120 | 121 | not_gamma: 122 | // Save whatever's in EAX 123 | push eax 124 | 125 | push [esp + 6A8h + 4h + 0Ch] // CharObj2 126 | push ebx // EntityData1 127 | call SuperWaterCheck_C 128 | 129 | test eax, eax 130 | 131 | jnz is_true 132 | 133 | // Restore EAX 134 | pop eax 135 | 136 | jmp surface_water 137 | 138 | is_true: 139 | // Restore EAX 140 | pop eax 141 | jmp surface_solid 142 | } 143 | } 144 | 145 | static const PVMEntry SuperSonicPVM = { "SUPERSONIC", &SUPERSONIC_TEXLIST }; 146 | 147 | inline bool is_stage_blacklisted() 148 | { 149 | switch (CurrentLevel) 150 | { 151 | default: 152 | return false; 153 | 154 | case LevelIDs_Casinopolis: 155 | return CurrentAct == 2 || CurrentAct == 3; 156 | 157 | case LevelIDs_SpeedHighway: 158 | return CurrentAct == 1; 159 | } 160 | } 161 | 162 | extern "C" 163 | { 164 | EXPORT ModInfo SADXModInfo = { ModLoaderVer, nullptr, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0 }; 165 | 166 | void EXPORT Init(const char* path, HelperFunctions* helper) 167 | { 168 | helper->RegisterCharacterPVM(Characters_Sonic, SuperSonicPVM); 169 | WriteData(reinterpret_cast(0x004943C2), static_cast(_Sonic_SuperPhysics_Delete)); 170 | WriteJump(reinterpret_cast(0x004496E1), SuperWaterCheck); 171 | 172 | // Fixes vertical offset when completing a stage 173 | WriteData<7>(reinterpret_cast(0x00494E13), 0x90i8); 174 | 175 | // Fixes upside down water plane in Emerald Coast 2 176 | auto ec2_mesh = reinterpret_cast(0x01039E9C); 177 | NJS_OBJECT* obj = ec2_mesh->Col[1].Model; 178 | obj->ang[0] = 32768; 179 | obj->pos[1] = -3.0f; 180 | obj->pos[2] = -5850.0f; 181 | 182 | // Always initialize Super Sonic weld data. 183 | WriteData<2>(reinterpret_cast(0x0049AC6A), 0x90i8); 184 | } 185 | 186 | void EXPORT OnFrame() 187 | { 188 | if (GameState != 15 || MetalSonicFlag) 189 | { 190 | return; 191 | } 192 | 193 | #ifndef _DEBUG 194 | if (!GetEventFlag(EventFlags_SuperSonicAdventureComplete)) 195 | { 196 | return; 197 | } 198 | #endif 199 | 200 | // Don't perform custom Super Sonic checks in Super Sonic's story. 201 | if (LastStoryFlag != 0) 202 | { 203 | return; 204 | } 205 | 206 | bool is_blacklisted = is_stage_blacklisted(); 207 | 208 | for (int i = 0; i < 8; i++) 209 | { 210 | EntityData1* data1 = EntityData1Ptrs[i]; 211 | CharObj2* data2 = CharObj2Ptrs[i]; 212 | 213 | if (data1 == nullptr || data1->CharID != Characters_Sonic) 214 | { 215 | continue; 216 | } 217 | 218 | bool is_super = (data2->Upgrades & Upgrades_SuperSonic) != 0; 219 | bool toggle = (ControllerPointers[i]->PressedButtons & Buttons_B) != 0; 220 | bool action = !is_super ? (last_action[i] == 8 && data1->Action == 12) : (last_action[i] == 82 && data1->Action == 78); 221 | 222 | if (!is_super) 223 | { 224 | #ifdef _DEBUG 225 | if (!Rings) 226 | { 227 | Rings = 50; 228 | } 229 | #endif 230 | if (toggle && action) 231 | { 232 | if (is_blacklisted) 233 | { 234 | PlayVoice(clips[_rand() % LengthOfArray(clips)]); 235 | } 236 | else if (Rings >= 50) 237 | { 238 | // Transform into Super Sonic 239 | data1->Status &= ~Status_LightDash; 240 | ForcePlayerAction(i, 46); 241 | data2->Upgrades |= Upgrades_SuperSonic; 242 | PlayVoice(396); 243 | 244 | if (!super_count++) 245 | { 246 | SuperSonicManager_Load(); 247 | } 248 | } 249 | } 250 | } 251 | else 252 | { 253 | // TODO: Consider storing the queued action in the case of NextAction 13, then re-applying 254 | // the stored queued action next frame to fix the spindashy things. 255 | bool detransform = data1->Status & Status_DoNextAction && 256 | (data1->NextAction == 12 || (data1->NextAction == 13 && CurrentLevel == LevelIDs_TwinklePark)); 257 | 258 | if (is_blacklisted || detransform || (action && toggle) || !Rings) 259 | { 260 | if (detransform) 261 | { 262 | PlayVoice(clips[_rand() % LengthOfArray(clips)]); 263 | } 264 | 265 | // Change back to normal Sonic 266 | ForcePlayerAction(i, 47); 267 | data2->Upgrades &= ~Upgrades_SuperSonic; 268 | --super_count; 269 | } 270 | } 271 | 272 | last_action[i] = data1->Action; 273 | } 274 | 275 | SuperSonicFlag = super_count > 0; 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /sadx-super-sonic/mod.ini: -------------------------------------------------------------------------------- 1 | Name=Super Sonic 2 | Author=x-hax 3 | Version=1.2 4 | Description=Play as Super Sonic in any stage after completing his story! 5 | DLLFile=sadx-super-sonic.dll 6 | GitHubRepo=sonicretro/sadx-super-sonic 7 | GitHubAsset=super-sonic.7z 8 | -------------------------------------------------------------------------------- /sadx-super-sonic/sadx-super-sonic.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {073FF02A-AFE3-41C5-A5A3-3268EA5492A3} 15 | Win32Proj 16 | supersonic 17 | 8.1 18 | 19 | 20 | 21 | DynamicLibrary 22 | true 23 | v141_xp 24 | Unicode 25 | 26 | 27 | DynamicLibrary 28 | false 29 | v141_xp 30 | true 31 | Unicode 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | true 47 | 48 | 49 | false 50 | 51 | 52 | 53 | Use 54 | Level3 55 | Disabled 56 | WIN32;_DEBUG;_WINDOWS;_USRDLL;SUPERSONIC_EXPORTS;%(PreprocessorDefinitions) 57 | true 58 | ..\sadx-mod-loader\SADXModLoader\include 59 | 60 | 61 | Windows 62 | true 63 | 64 | 65 | xcopy /Y /D "$(ProjectDir)mod.ini" "$(OutDir)" 66 | 67 | 68 | 69 | 70 | Level3 71 | Use 72 | MaxSpeed 73 | true 74 | true 75 | WIN32;NDEBUG;_WINDOWS;_USRDLL;SUPERSONIC_EXPORTS;%(PreprocessorDefinitions) 76 | true 77 | ..\sadx-mod-loader\SADXModLoader\include 78 | 79 | 80 | Windows 81 | true 82 | true 83 | true 84 | 85 | 86 | xcopy /Y /D "$(ProjectDir)mod.ini" "$(OutDir)" 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | Create 96 | Create 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /sadx-super-sonic/sadx-super-sonic.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | 23 | 24 | Source Files 25 | 26 | 27 | Source Files 28 | 29 | 30 | 31 | 32 | Resource Files 33 | 34 | 35 | -------------------------------------------------------------------------------- /sadx-super-sonic/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /sadx-super-sonic/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | --------------------------------------------------------------------------------