From b526c8ef0cb7a4f5946613b035ef0e54158541f6 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Mon, 24 Jun 2024 00:49:43 -0700 Subject: [PATCH] =?UTF-8?q?Add=20`Switch.version.emummc`=20to=20determine?= =?UTF-8?q?=20if=20Atmosph=C3=A8re=20is=20running=20from=20emuMMC=20or=20s?= =?UTF-8?q?ysMMC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/red-rocks-teach.md | 5 +++++ packages/runtime/src/switch.ts | 4 ++++ source/main.c | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 .changeset/red-rocks-teach.md diff --git a/.changeset/red-rocks-teach.md b/.changeset/red-rocks-teach.md new file mode 100644 index 00000000..b60251dc --- /dev/null +++ b/.changeset/red-rocks-teach.md @@ -0,0 +1,5 @@ +--- +"nxjs-runtime": patch +--- + +Add `Switch.version.emummc` to determine if Atmosphère is running from emuMMC or sysMMC diff --git a/packages/runtime/src/switch.ts b/packages/runtime/src/switch.ts index c563bd22..e79e8c15 100644 --- a/packages/runtime/src/switch.ts +++ b/packages/runtime/src/switch.ts @@ -31,6 +31,10 @@ export interface Versions { */ ams: string | undefined; cairo: string; + /** + * `true` if the Switch is running Atmosphère from emuMMC, `false` if running sysMMC, or `undefined` if not running Atmosphère. + */ + emummc: boolean | undefined; freetype2: string; harfbuzz: string; hos: string; diff --git a/source/main.c b/source/main.c index 7fa7dcce..82abf585 100644 --- a/source/main.c +++ b/source/main.c @@ -452,6 +452,29 @@ static JSValue nx_version_get_ams(JSContext *ctx, JSValueConst this_val, int arg return JS_NewString(ctx, version_str); } +static JSValue nx_version_get_emummc(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) +{ + if (!hosversionIsAtmosphere()) + { + return JS_UNDEFINED; + } + + nx_context_t *nx_ctx = JS_GetContextOpaque(ctx); + if (!nx_ctx->spl_initialized) + { + nx_ctx->spl_initialized = true; + splInitialize(); + } + + u64 is_emummc; + Result rc = splGetConfig((SplConfigItem)65007, &is_emummc); + if (R_FAILED(rc)) + { + return nx_throw_libnx_error(ctx, rc, "splGetConfig(ExosphereEmummcType)"); + } + return JS_NewBool(ctx, is_emummc ? true : false); +} + int nx_module_set_import_meta(JSContext *ctx, JSValueConst func_val, const char *url, JS_BOOL is_main) { @@ -632,6 +655,7 @@ int main(int argc, char *argv[]) JSValue version_obj = JS_NewObject(ctx); NX_DEF_GET_(version_obj, "ams", nx_version_get_ams, JS_PROP_C_W_E); JS_SetPropertyStr(ctx, version_obj, "cairo", JS_NewString(ctx, cairo_version_string())); + NX_DEF_GET_(version_obj, "emummc", nx_version_get_emummc, JS_PROP_C_W_E); JS_SetPropertyStr(ctx, version_obj, "freetype2", JS_NewString(ctx, FREETYPE_VERSION_STR)); JS_SetPropertyStr(ctx, version_obj, "harfbuzz", JS_NewString(ctx, HB_VERSION_STRING)); u32 hos_version = hosversionGet();