Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thesupersonic16 committed Jul 13, 2024
0 parents commit ab01e60
Show file tree
Hide file tree
Showing 18 changed files with 4,053 additions and 0 deletions.
215 changes: 215 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
bin/
[Bb]in/
[Oo]bj/

# Visual Studio 2015 cache/options directory
.vs/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
artifacts/

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
## TODO: Comment the next line if you want to checkin your
## web deploy settings but do note that will include unencrypted
## passwords
#*.pubxml

*.publishproj

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config

# Windows Azure Build Output
csx/
*.build.csdef

# Windows Store app package directory
AppPackages/

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml

Ignored/
25 changes: 25 additions & 0 deletions S3KOEditorLink.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33723.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "S3KOEditorLink", "S3KOEditorLink\S3KOEditorLink.vcxproj", "{AF540CCC-DFB0-4EC4-A302-AF115FD31F8F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AF540CCC-DFB0-4EC4-A302-AF115FD31F8F}.Debug|x64.ActiveCfg = Debug|x64
{AF540CCC-DFB0-4EC4-A302-AF115FD31F8F}.Debug|x64.Build.0 = Debug|x64
{AF540CCC-DFB0-4EC4-A302-AF115FD31F8F}.Release|x64.ActiveCfg = Release|x64
{AF540CCC-DFB0-4EC4-A302-AF115FD31F8F}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {44F8BC84-64B7-48AC-80E0-BD9B04B75DE0}
EndGlobalSection
EndGlobal
102 changes: 102 additions & 0 deletions S3KOEditorLink/Game.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include "S3KOEditorLink.h"
#include "GamePatches.h"

// RSDK
int32 RSDKRevision = RETRO_REVISION;
RSDKFunctionTable RSDK;
RSDKSceneInfo *SceneInfo = NULL;

// Handles
HMODULE LinkModule = NULL;
HMODULE OriginsModule = NULL;

HMODULE LoadLocalOrigins()
{
if (OriginsModule)
return OriginsModule;

// Backup
char oldWorkingDirectory[MAX_PATH];
GetCurrentDirectoryA(MAX_PATH, oldWorkingDirectory);

char modulePath[MAX_PATH];
if (GetModuleFileNameA(LinkModule, modulePath, MAX_PATH) == 0)
return OriginsModule;

// Path
char* pos = strrchr(modulePath, '\\');
if (pos == NULL)
return OriginsModule;
pos[0] = '\0';

SetCurrentDirectoryA(modulePath);
OriginsModule = LoadLibraryA("SonicOrigins.exe");
SetCurrentDirectoryA(oldWorkingDirectory);
return OriginsModule;
}

HMODULE LoadOriginsModule()
{
// Check if the module is already loaded
OriginsModule = GetModuleHandleA("SonicOrigins.exe");
if (OriginsModule)
return OriginsModule;

// Load module
OriginsModule = LoadLibraryA("SonicOrigins.exe");
if (!OriginsModule)
OriginsModule = LoadLocalOrigins();

if (!OriginsModule)
{
MessageBoxA(NULL, "Failed to load SonicOrigins.exe", "Error", MB_ICONERROR | MB_OK);
OriginsModule = NULL;
}

return OriginsModule;
}

void RegisterAllObjects()
{
// Aslong as it works
intptr_t start = (intptr_t)ORIGINS_ADDR(0xAA5C50);
intptr_t end = (intptr_t)ORIGINS_ADDR(0xAAD0F8);
while (start < end)
{
if (*(void**)start)
{
if ((*(unsigned short**)start)[0] == 0x158B &&
(*(unsigned short**)start)[3] == 0xFA81 &&
(*(unsigned short**)start)[4] == 0x0400 &&
(*(unsigned short**)start)[5] == 0x0000)
((void(__fastcall*)())((*(void**)start)))();
}
start += sizeof(void*);
}
}

void LinkGameLogicDLL(EngineInfo* info)
{
// Engine
memset(&RSDK, 0, sizeof(RSDKFunctionTable));
if (info->functionTable)
memcpy(&RSDK, info->functionTable, sizeof(RSDKFunctionTable));
SceneInfo = info->sceneInfo;

if (LoadOriginsModule())
{
// Globals
((void(__fastcall*)(void*, int, void*))(ORIGINS_ADDR(0xAD730)))(ORIGINS_ADDR(0x4000210), 0x4C35B0, ORIGINS_ADDR(0x3A86E0));

// Register objects
int32 objectCount = *(int32*)(ORIGINS_ADDR(0x28BDC78));
if (objectCount == 0)
{
ApplyPatches();
RegisterAllObjects();
}

// Call link
((void(__fastcall*)(EngineInfo*))((EngineInfo*)ORIGINS_ADDR(0xAD750)))(info);
}
}
Loading

0 comments on commit ab01e60

Please sign in to comment.