Skip to content

Commit

Permalink
fixes from 1.2.0 branch, allowing scripts to be compiled
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubberduckycooly committed Feb 3, 2021
1 parent 7cdf2ac commit 2d90efb
Show file tree
Hide file tree
Showing 14 changed files with 330 additions and 98 deletions.
5 changes: 1 addition & 4 deletions Sonic12Decomp/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,7 @@ void ProcessAudioPlayback(void *userdata, Uint8 *stream, int len)
StopMusic();
}

if (LoadFile(trackPtr->fileName, &musInfo.fileInfo)) {
musInfo.fileInfo.cFileHandle = cFileHandle;
cFileHandle = nullptr;

if (LoadFile2(trackPtr->fileName, &musInfo.fileInfo)) {
musInfo.trackLoop = trackPtr->trackLoop;
musInfo.loopPoint = trackPtr->loopPoint;
musInfo.loaded = true;
Expand Down
11 changes: 2 additions & 9 deletions Sonic12Decomp/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void initDevMenu()
SetPaletteEntry(-1, 0xFF, 0xFF, 0xFF, 0xFF);
setTextMenu(DEVMENU_MAIN);
drawStageGFXHQ = false;
Engine.finishedStartMenu = true;
touchTimer = 0;
}
void initErrorMessage()
Expand All @@ -52,7 +51,6 @@ void initErrorMessage()
gameMenu[1].visibleRowOffset = 0;
stageMode = DEVMENU_SCRIPTERROR;
drawStageGFXHQ = false;
Engine.finishedStartMenu = true;
touchTimer = 0;
}
void processStageSelect()
Expand Down Expand Up @@ -331,8 +329,7 @@ void initStartMenu(int mode)
ReleaseStageSfx();
fadeMode = 0;
playerListPos = 0;
Engine.gameMode = ENGINE_MAINGAME;
Engine.finishedStartMenu = false;
Engine.gameMode = ENGINE_STARTMENU;
ClearGraphicsData();
ClearAnimationData();
SetActivePalette(0, 0, 256);
Expand Down Expand Up @@ -823,7 +820,6 @@ void processStartMenu()

// if (Engine.onlineActive)
InitStartingStage(STAGELIST_PRESENTATION, 3, 0);
Engine.finishedStartMenu = true;
}
}
}
Expand Down Expand Up @@ -888,7 +884,6 @@ void processStartMenu()
SetGlobalVariableByName("specialStage.nextZone", nextZone - 1);
InitStartingStage(STAGELIST_REGULAR, saveRAM[savePos + 4] - 1, saveRAM[savePos + 0]);
}
Engine.finishedStartMenu = true;
}
else {
// new save
Expand Down Expand Up @@ -991,7 +986,6 @@ void processStartMenu()
WriteSaveRAMData();

InitStartingStage(STAGELIST_PRESENTATION, 0, saveRAM[savePos + 0]);
Engine.finishedStartMenu = true;
}
else if (keyPress.B) {
setTextMenu(STARTMENU_SAVESEL);
Expand Down Expand Up @@ -1363,7 +1357,6 @@ void processStartMenu()

taListStore = gameMenu[1].selection2;
InitStartingStage(activeStageList, stageListPosition, 0);
Engine.finishedStartMenu = true;
}
else {
// TA
Expand Down Expand Up @@ -1423,7 +1416,7 @@ void processStartMenu()
default: break;
}

if (!Engine.finishedStartMenu) {
if (Engine.gameMode == ENGINE_STARTMENU) {
#if defined RETRO_USING_MOUSE || defined RETRO_USING_TOUCH
DrawSprite(32, 0x42, 16, 16, 78, 240, textMenuSurfaceNo);
DrawSprite(32, 0xB2, 16, 16, 95, 240, textMenuSurfaceNo);
Expand Down
32 changes: 29 additions & 3 deletions Sonic12Decomp/Ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ IniParser::IniParser(const char *filename)
if (sscanf(buf, "[%[^][]]", section) == 1) {
hasSection = true;
}
else if (sscanf(buf, "%[^ =]= %s", key, value) == 2 || sscanf(buf, "%[^ =]=%s", key, value) == 2
|| sscanf(buf, "%[^ =] = %s", key, value) == 2 || sscanf(buf, "%[^ =] =%s", key, value) == 2) {
else if (sscanf(buf, "%[^ =]= %[^\t\r\n]", key, value) == 2 || sscanf(buf, "%[^ =]=%[^\t\r\n]", key, value) == 2
|| sscanf(buf, "%[^ =] = %[^\t\r\n]", key, value) == 2 || sscanf(buf, "%[^ =] =%[^\t\r\n]", key, value) == 2) {
if (hasSection)
sprintf(items[count].section, "%s", section);
else
sprintf(items[count].section, "", section);

sprintf(items[count].key, "%s", key);
sprintf(items[count].value, "%s", value);
Expand Down Expand Up @@ -270,6 +272,30 @@ void IniParser::Write(const char *filename)
}

char buffer[0x100];

// Sectionless items
for (int i = 0; i < count; ++i) {
if (strcmp("", items[i].section) == 0) {
switch (items[i].type) {
default:
case INI_ITEM_STRING:
case INI_ITEM_INT:
case INI_ITEM_FLOAT:
case INI_ITEM_BOOL:
sprintf(buffer, "%s=%s\n", items[i].key, items[i].value);
fWrite(&buffer, 1, StrLength(buffer), f);
break;
case INI_ITEM_COMMENT:
sprintf(buffer, "; %s\n", items[i].value);
fWrite(&buffer, 1, StrLength(buffer), f);
break;
}
}
}
sprintf(buffer, "\n");
fWrite(&buffer, StrLength(buffer), 1, f);

// Sections
for (int s = 0; s < c; ++s) {
sprintf(buffer, "[%s]\n", sections[s]);
fWrite(&buffer, 1, StrLength(buffer), f);
Expand Down Expand Up @@ -299,4 +325,4 @@ void IniParser::Write(const char *filename)
}

fClose(f);
}
}
2 changes: 1 addition & 1 deletion Sonic12Decomp/Ini.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ class IniParser

int count = 0;
};
#endif // !INI_H
#endif // !INI_H
93 changes: 93 additions & 0 deletions Sonic12Decomp/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ bool LoadFile(const char *filePath, FileInfo *fileInfo)
fileInfo->readPos = readPos;
bufferPosition = 0;
readSize = 0;
useEncryption = false;

printLog("Loaded File '%s'", filePath);
return true;
Expand Down Expand Up @@ -414,6 +415,98 @@ bool ReachedEndOfFile()
return bufferPosition + readPos - readSize >= fileSize;
}

bool LoadFile2(const char *filePath, FileInfo *fileInfo)
{

if (fileInfo->cFileHandle)
fClose(fileInfo->cFileHandle);

MEM_ZEROP(fileInfo);
if (Engine.usingDataFile) {
StringLowerCase(fileInfo->fileName, filePath);
StrCopy(fileName, fileInfo->fileName);
byte buffer[0x10];
int len = StrLength(fileInfo->fileName);
GenerateMD5FromString(fileInfo->fileName, len, buffer);

for (int f = 0; f < rsdkContainer.fileCount; ++f) {
RSDKFileInfo *file = &rsdkContainer.files[f];

bool match = true;
for (int h = 0; h < 0x10; ++h) {
if (buffer[h] != file->hash[h]) {
match = false;
break;
}
}
if (!match)
continue;

fileInfo->cFileHandle = fOpen(rsdkName, "rb");
fSeek(fileInfo->cFileHandle, 0, SEEK_END);
fileSize = (int)fTell(fileInfo->cFileHandle);

vFileSize = file->filesize;
virtualFileOffset = file->offset;
readPos = file->offset;
readSize = 0;
bufferPosition = 0;
fSeek(fileInfo->cFileHandle, virtualFileOffset, SEEK_SET);

useEncryption = file->encrypted;
memset(fileInfo->encryptionStringA, 0, 0x10 * sizeof(byte));
memset(fileInfo->encryptionStringB, 0, 0x10 * sizeof(byte));
if (useEncryption) {
GenerateELoadKeys(vFileSize, (vFileSize >> 1) + 1);
eStringNo = (vFileSize & 0x1FC) >> 2;
eStringPosA = 0;
eStringPosB = 8;
eNybbleSwap = 0;
memcpy(fileInfo->encryptionStringA, encryptionStringA, 0x10 * sizeof(byte));
memcpy(fileInfo->encryptionStringB, encryptionStringB, 0x10 * sizeof(byte));
}

fileInfo->readPos = readPos;
fileInfo->fileSize = fileSize;
fileInfo->vfileSize = vFileSize;
fileInfo->virtualFileOffset = virtualFileOffset;
fileInfo->eStringNo = eStringNo;
fileInfo->eStringPosB = eStringPosB;
fileInfo->eStringPosA = eStringPosA;
fileInfo->eNybbleSwap = eNybbleSwap;
fileInfo->bufferPosition = bufferPosition;
fileInfo->useEncryption = useEncryption;
printLog("Loaded File '%s'", filePath);
return true;
}
printLog("Couldn't load file '%s'", filePath);
return false;
}
else {
StrCopy(fileInfo->fileName, filePath);
StrCopy(fileName, fileInfo->fileName);

fileInfo->cFileHandle = fOpen(fileInfo->fileName, "rb");
if (!fileInfo->cFileHandle) {
printLog("Couldn't load file '%s'", filePath);
return false;
}
virtualFileOffset = 0;
fSeek(fileInfo->cFileHandle, 0, SEEK_END);
fileInfo->fileSize = (int)fTell(fileInfo->cFileHandle);
fileSize = fileInfo->vfileSize = fileInfo->fileSize;
fSeek(fileInfo->cFileHandle, 0, SEEK_SET);
readPos = 0;
fileInfo->readPos = readPos;
bufferPosition = 0;
readSize = 0;
useEncryption = false;

printLog("Loaded File '%s'", filePath);
return true;
}
}

size_t FileRead2(FileInfo *info, void *dest, int size)
{
byte *data = (byte *)dest;
Expand Down
2 changes: 1 addition & 1 deletion Sonic12Decomp/Reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ size_t GetFilePosition();
void SetFilePosition(int newPos);
bool ReachedEndOfFile();


bool LoadFile2(const char *filePath, FileInfo *fileInfo);
size_t FileRead2(FileInfo *info, void *dest, int size); // For Music Streaming
inline bool CloseFile2(FileInfo *info)
{
Expand Down
10 changes: 4 additions & 6 deletions Sonic12Decomp/RetroEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void RetroEngine::Init()

gameMode = ENGINE_MAINGAME;
running = false;
finishedStartMenu = false;
bool skipStart = skipStartMenu;
if (LoadGameConfig("Data/Game/GameConfig.bin")) {
if (InitRenderDevice()) {
if (InitAudioPlayback()) {
Expand All @@ -315,7 +315,7 @@ void RetroEngine::Init()
running = true;

if ((startList != 0xFF && startList) || (startStage != 0xFF && startStage) || startPlayer != 0xFF) {
finishedStartMenu = true;
skipStart = true;
InitStartingStage(startList == 0xFF ? 0 : startList, startStage == 0xFF ? 0 : startStage, startPlayer == 0xFF ? 0 : startPlayer);
}
else if (startSave != 0xFF && startSave < 4) {
Expand Down Expand Up @@ -376,7 +376,7 @@ void RetroEngine::Init()
InitStartingStage(STAGELIST_REGULAR, 0, 0);
}
}
finishedStartMenu = true;
skipStart = true;
}
}
}
Expand Down Expand Up @@ -445,9 +445,7 @@ void RetroEngine::Init()
StrCopy(achievements[11].name, "Beat the Clock");
}

SetGlobalVariableByName("Engine.PlatformID", RETRO_GAMEPLATFORM); // note to future rdc (or anyone else): what does this do? no vars are named this

if (!finishedStartMenu)
if (!skipStart)
initStartMenu(0);
}

Expand Down
7 changes: 3 additions & 4 deletions Sonic12Decomp/RetroEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ enum RetroStates {
ENGINE_RESETGAME = 8,

// Custom GameModes (required to make some features work
ENGINE_CONNECT2PVS = 0x80,
ENGINE_STARTMENU = 0x80,
ENGINE_CONNECT2PVS = 0x81,
};

enum RetroGameType {
Expand Down Expand Up @@ -253,11 +254,9 @@ class RetroEngine
int waitValue = 0;
void Callback(int callbackID);

bool finishedStartMenu = false;

char gameWindowText[0x40];
char gameDescriptionText[0x100];
const char *gameVersion = "1.1.0";
const char *gameVersion = "1.1.1";
const char *gamePlatform = nullptr;

#if RETRO_RENDERTYPE == RETRO_SW_RENDER
Expand Down
32 changes: 15 additions & 17 deletions Sonic12Decomp/RetroGameLoop.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "RetroEngine.hpp"

void RetroGameLoop_Create(void *objPtr) {
void RetroGameLoop_Create(void *objPtr)
{
NativeEntity_RetroGameLoop *entity = (NativeEntity_RetroGameLoop *)objPtr;
entity->pauseMenu = nullptr;
}
Expand All @@ -9,18 +10,14 @@ void RetroGameLoop_Main(void *objPtr)
NativeEntity_RetroGameLoop *entity = (NativeEntity_RetroGameLoop *)objPtr;

switch (Engine.gameMode) {
case ENGINE_DEVMENU:
case ENGINE_DEVMENU:
if (entity->pauseMenu && nativeEntityCount > 1) // dumb fix but yknow how it is
RemoveNativeObject(entity->pauseMenu);
entity->pauseMenu = nullptr;

processStageSelect(); break;
case ENGINE_MAINGAME:
if (Engine.finishedStartMenu)
ProcessStage();
else
processStartMenu();
processStageSelect();
break;
case ENGINE_MAINGAME: ProcessStage(); break;
case ENGINE_INITDEVMENU:
Engine.LoadGameConfig("Data/Game/GameConfig.bin");
initDevMenu();
Expand All @@ -34,12 +31,12 @@ void RetroGameLoop_Main(void *objPtr)
break;
case ENGINE_INITPAUSE:
PauseSound();
//ClearNativeObjects();
Engine.gameMode = ENGINE_WAIT; //temp (maybe?) so pause menu renders on top
// ClearNativeObjects();
Engine.gameMode = ENGINE_WAIT; // temp (maybe?) so pause menu renders on top
// CreateNativeObject(MenuBG_Create, MenuBG_Main); // temp until/if nativeObjs are fully complete
if (entity->pauseMenu && nativeEntityCount > 1)
RemoveNativeObject(entity->pauseMenu);
entity->pauseMenu = (NativeEntity_PauseMenu*)CreateNativeObject(PauseMenu_Create, PauseMenu_Main);
entity->pauseMenu = (NativeEntity_PauseMenu *)CreateNativeObject(PauseMenu_Create, PauseMenu_Main);
break;
case ENGINE_EXITPAUSE:
Engine.gameMode = ENGINE_MAINGAME;
Expand All @@ -50,19 +47,20 @@ void RetroGameLoop_Main(void *objPtr)
break;
case ENGINE_ENDGAME:
ClearScreen(1);
//RestoreNativeObjects();
// RestoreNativeObjects();
Engine.LoadGameConfig("Data/Game/GameConfig.bin");
activeStageList = 0;
stageListPosition = 0;
initStartMenu(0);
break;
case ENGINE_RESETGAME: //Also called when 2P VS disconnects
ClearScreen(1);
//RestoreNativeObjects();
case ENGINE_RESETGAME: // Also called when 2P VS disconnects
ClearScreen(1);
// RestoreNativeObjects();
initStartMenu(1);
break;
case ENGINE_CONNECT2PVS:
//connect screen goes here
case ENGINE_STARTMENU: processStartMenu(); break;
case ENGINE_CONNECT2PVS:
// connect screen goes here
break;
default:
printLog("GameMode '%d' Called", Engine.gameMode);
Expand Down
Loading

0 comments on commit 2d90efb

Please sign in to comment.