Skip to content

Commit

Permalink
Remove playOption from gSettingsContext, auto detect on game start in…
Browse files Browse the repository at this point in the history
…stead (#721)

Allows safer sharing of seeds between console and emulator.
  • Loading branch information
Kewlan authored Mar 17, 2024
1 parent 61741bf commit 7b58656
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 19 deletions.
2 changes: 2 additions & 0 deletions code/src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "3ds/svc.h"
#include "lib/printf.h"

u8 playingOnCitra = 0;

s8 BitCompare(u32 value1, u32 value2, u8 bit) {
if ((value1 & (1 << bit)) > (value2 & (1 << bit))) {
return 1;
Expand Down
1 change: 1 addition & 0 deletions code/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define TICKS_PER_SEC 268123480
#define SEQ_AUDIO_BLANK 0x1000142

extern u8 playingOnCitra;
extern u32 rGameplayFrames; // globalCtx->gameplayFrames is not accurate, it doesn't increment on file 3

/// Returns 1 if the bit is set in value1 but not in value2, -1 if vice versa, and 0 if they're the same
Expand Down
14 changes: 7 additions & 7 deletions code/src/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ static void Gfx_ShowMenu(void) {
pressed = 0;

Draw_ClearFramebuffer();
if (gSettingsContext.playOption == PLAY_ON_CONSOLE) {
if (!playingOnCitra) {
Draw_FlushFramebuffer();
}

Expand Down Expand Up @@ -968,7 +968,7 @@ static void Gfx_ShowMenu(void) {
showingLegend = false;
Draw_ClearBackbuffer();
Draw_CopyBackBuffer();
if (gSettingsContext.playOption == PLAY_ON_CONSOLE) {
if (!playingOnCitra) {
Draw_FlushFramebuffer();
}
break;
Expand Down Expand Up @@ -1005,7 +1005,7 @@ static void Gfx_ShowMenu(void) {
Gfx_DrawButtonPrompts();
Gfx_DrawHeader();
Draw_CopyBackBuffer();
if (gSettingsContext.playOption == PLAY_ON_CONSOLE) {
if (!playingOnCitra) {
Draw_FlushFramebuffer();
}

Expand All @@ -1016,7 +1016,7 @@ static void Gfx_ShowMenu(void) {

static void Gfx_ShowMultiplayerSyncMenu(void) {
Draw_ClearFramebuffer();
if (gSettingsContext.playOption == PLAY_ON_CONSOLE) {
if (!playingOnCitra) {
Draw_FlushFramebuffer();
}

Expand Down Expand Up @@ -1059,7 +1059,7 @@ static void Gfx_ShowMultiplayerSyncMenu(void) {

Draw_ClearBackbuffer();
Draw_CopyBackBuffer();
if (gSettingsContext.playOption == PLAY_ON_CONSOLE) {
if (!playingOnCitra) {
Draw_FlushFramebuffer();
}
mp_isSyncing = false;
Expand All @@ -1080,7 +1080,7 @@ static void Gfx_ShowMultiplayerSyncMenu(void) {

Draw_ClearBackbuffer();
Draw_CopyBackBuffer();
if (gSettingsContext.playOption == PLAY_ON_CONSOLE) {
if (!playingOnCitra) {
Draw_FlushFramebuffer();
}
mp_isSyncing = false;
Expand All @@ -1090,7 +1090,7 @@ static void Gfx_ShowMultiplayerSyncMenu(void) {
}

Draw_CopyBackBuffer();
if (gSettingsContext.playOption == PLAY_ON_CONSOLE) {
if (!playingOnCitra) {
Draw_FlushFramebuffer();
}

Expand Down
5 changes: 5 additions & 0 deletions code/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "z3D/z3D.h"
#include "3ds/extdata.h"
#include "3ds/services/irrst.h"
#include "3ds/svc.h"

GlobalContext* gGlobalContext = NULL;
static u8 rRandomizerInit = 0;
Expand All @@ -39,6 +40,10 @@ void before_GlobalContext_Update(GlobalContext* globalCtx) {
Randomizer_Init();
set_GlobalContext(globalCtx);
rRandomizerInit = 1;

s64 output = 0;
svcGetSystemInfo(&output, 0x20000, 0);
playingOnCitra = (output != 0);
}
rGameplayFrames++;
ItemOverride_Update();
Expand Down
4 changes: 2 additions & 2 deletions code/src/multiplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void Multiplayer_Run(void) {
break;
case 1:
// Connect or host: Scan for a bit before creating a network
if (netScanChecks < (gSettingsContext.playOption == PLAY_ON_CONSOLE ? 3 : 30)) {
if (netScanChecks < (playingOnCitra ? 30 : 3)) {
netScanChecks++;

size_t total_networks = 0;
Expand Down Expand Up @@ -380,7 +380,7 @@ void Multiplayer_Run(void) {
} else {
u8 max_players = UDS_MAXNODES;
// Citra crashes when allowing too many nodes
if (gSettingsContext.playOption == PLAY_ON_CITRA) {
if (playingOnCitra) {
max_players /= 2;
}
udsNetworkStruct networkstruct;
Expand Down
6 changes: 0 additions & 6 deletions code/src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,13 @@ typedef enum {
MIRRORWORLD_RANDOM,
} MirrorWorld;

typedef enum {
PLAY_ON_CONSOLE,
PLAY_ON_CITRA,
} PlayOption;

typedef enum {
REGION_NA,
REGION_EUR
} REGION;

typedef struct {
u8 hashIndexes[5];
u8 playOption;
u8 region;

u8 logic;
Expand Down
7 changes: 4 additions & 3 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ int main() {

// launch oot3d directly by holding L and R (cartridge only)
if (kHeld & KEY_L && kHeld & KEY_R) {
s64 output = 0;
svcGetSystemInfo(&output, 0x20000, 0); // This checks if the app is running on Citra
if (!output) {
s64 playingOnCitra = 0;
// Type 0x20000 only exists on Citra, where parameter 0 returns 1
svcGetSystemInfo(&playingOnCitra, 0x20000, 0);
if (!playingOnCitra) {
if (Settings::Region == REGION_NA) {
aptSetChainloader(0x0004000000033500, 2);
} else if (Settings::Region == REGION_EUR) {
Expand Down
1 change: 0 additions & 1 deletion source/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,6 @@ SettingsContext FillContext() {
ctx.hashIndexes[2] = hashIconIndexes[2];
ctx.hashIndexes[3] = hashIconIndexes[3];
ctx.hashIndexes[4] = hashIconIndexes[4];
ctx.playOption = PlayOption;
ctx.region = Region;

ctx.logic = Logic.Value<u8>();
Expand Down

0 comments on commit 7b58656

Please sign in to comment.