/* nn::oe (applet), nn::account, nn::time, nn::pl, nn::err: what a game asks the system about itself. The answers describe a docked console in English (HOS_LANGUAGE / language.txt: another language) with one user, "Player". */ #include "hos.h" #include "hos_paths.h" #include #include #include #include #include /* (the exe's folder; the browser build: the Microsoft C runtime's time functions) */ #include "../gpu/vk/output_sizes.h" /* ((Triforce) the Output resolution row's sizes, the menu's too) */ #include "../gpu/vk/ultrawide_rows.h" /* ((Triforce) the Ultrawide row as an old options file holds it: output_res_read) */ #include "hos_screens.h" /* ((Triforce) the connected screens: the one the window opens on, and each one's size for the log) */ static int64_t boot_ns; /* ---- nn::oe ------------------------------------------------------------------------------------------------- */ HLE(_ZN2nn2oe10InitializeEv) { if (!boot_ns) boot_ns = hos_now_ns(); } HLE(_ZN2nn2oe17FinishStartupLogoEv) { hos_log("oe: startup logo finished"); } /* GetDesiredLanguage() -> settings::LanguageCode (char[8]) by value: the language the game shows. HOS_LANGUAGE, or language.txt beside the exe: its first line that is not blank or a comment. The file is written on the first start, with the choices: the 16 languages in romfs/Mals. After SkyboundTotk PR 16 by sardigital. */ static const struct { const char *code, *name; } languages[] = { {"en-US", "English (US)"}, {"en-GB", "English (UK)"}, {"fr", "French (France)"}, {"fr-CA", "French (Canada)"}, {"de", "German"}, {"it", "Italian"}, {"es", "Spanish (Spain)"}, {"es-419", "Spanish (Latin America)"}, {"pt-BR", "Portuguese (Brazil)"}, {"nl", "Dutch"}, {"pl", "Polish"}, {"ru", "Russian"}, {"ja", "Japanese"}, {"ko", "Korean"}, {"zh-Hans", "Chinese (Simplified)"}, {"zh-Hant", "Chinese (Traditional)"}, }; static const char *desired_language(void) { static char lang[8]; if (lang[0]) return lang; char want[32] = ""; const char *from = "the default"; if (getenv("HOS_LANGUAGE")) { snprintf(want, sizeof want, "%s", getenv("HOS_LANGUAGE")); from = "HOS_LANGUAGE"; } else { char path[300] = "language.txt"; #if !defined(__EMSCRIPTEN__) /* (linux too: host/posix) */ DWORD n = hos_game_path_a(path, 260); while (n > 0 && path[n - 1] != 92 && path[n - 1] != 47) n--; snprintf(path + n, sizeof path - n, "language.txt"); #endif FILE *f = fopen(path, "r"); if (f) { char line[80]; int whole = 1; /* (the first line is longer than this: its second piece, "ave, and start...", was taken for the code) */ while (fgets(line, sizeof line, f)) { const int starts = whole; whole = strchr(line, 10) != NULL; if (!starts) continue; const char *p = line; if ((unsigned char)p[0] == 0xEF && (unsigned char)p[1] == 0xBB && (unsigned char)p[2] == 0xBF) p += 3; /* (a BOM: Notepad's UTF-8) */ while (*p == ' ' || *p == '\t') p++; if (*p == '#' || *p == '\r' || *p == '\n' || !*p) continue; /* (only a code the game has: a stray line was taken before, and the game stayed in English, Hookshot issue 75) */ char code[32]; snprintf(code, sizeof code, "%s", p); code[strcspn(code, " \t\r\n")] = 0; int known = 0; for (size_t i = 0; i < sizeof languages / sizeof *languages; i++) if (!_stricmp(code, languages[i].code)) snprintf(code, sizeof code, "%s", languages[i].code), known = 1; if (!known) continue; snprintf(want, sizeof want, "%s", code); from = "language.txt"; break; } fclose(f); } else if ((f = fopen(path, "w")) != NULL) { fputs("# The game's language. Change the line below to one of the codes listed here, save, and start the game again.\n\nen-US\n\n", f); for (size_t i = 0; i < sizeof languages / sizeof *languages; i++) fprintf(f, "# %-8s %s\n", languages[i].code, languages[i].name); fclose(f); } } want[strcspn(want, " \t\r\n")] = 0; snprintf(lang, sizeof lang, "en-US"); int found = 0; for (size_t i = 0; want[0] && i < sizeof languages / sizeof *languages; i++) if (!_stricmp(want, languages[i].code)) snprintf(lang, sizeof lang, "%s", languages[i].code), found = 1; /* (HOS_LANGUAGE=pt-br too, as language.txt) */ if (want[0] && !found) hos_log("oe: language \"%s\" (%s) is not one the game has: English (US)", want, from); else hos_log("oe: language %s (%s)", lang, from); return lang; } /* (Triforce) prompts.c: the language the game shows (one of languages[]' codes), for the title's messages it serves */ const char *hos_desired_language(void) { return desired_language(); } HLE(_ZN2nn2oe18GetDesiredLanguageEv) { uint64_t v = 0; memcpy(&v, desired_language(), strlen(desired_language())); RET(v); } /* HOS_HANDHELD=1: handheld (the 1080p screen: 1080p output and the game's handheld resolutions) instead of docked (MKW docked composes 3840 x 2160) */ int hos_ini_option(const char *key, int otherwise); #define ini_option hos_ini_option int hos_ini_option(const char *key, int otherwise) { /* (hookshot: the Insert menu's choice, gpu/vk/vk_menu.cpp; nn_vi.c reads it too) */ char path[MAX_PATH]; const DWORD n = hos_game_path_a(path, MAX_PATH); char *slash = n ? (strrchr(path, 92) ? strrchr(path, 92) : strrchr(path, 47)) : NULL; /* (linux: '/'; the game folder's, not bin\\'s) */ if (!slash) return otherwise; snprintf(slash + 1, (size_t)(path + MAX_PATH - slash - 1), "triforce_options.ini"); FILE *f = fopen(path, "r"); if (!f) return otherwise; char line[80]; const size_t len = strlen(key); while (fgets(line, sizeof line, f)) if (!strncmp(line, key, len) && line[len] == '=') otherwise = atoi(line + len + 1); fclose(f); return otherwise; } /* ((Triforce, options_version 7) The Insert menu's handheld profile is the Output resolution row's 1536 x 864: output_res=7, or HOS_OUTPUT_RES=7. handheld_profile=1 is a file's from before version 7, the row that was, until the menu writes the file again (gpu/vk/merged_rows.h migrate: it becomes output_res=7) */ static int output_size_fields(void) { return ini_option("output_width", -1) != -1 || ini_option("output_height", -1) != -1 || ini_option("output_custom_size", -1) != -1; } static int output_row(void) { if (getenv("HOS_OUTPUT_RES")) return atoi(getenv("HOS_OUTPUT_RES")); return output_file_read(ini_option("output_res", 0), ini_option("options_version", 0), 0, output_size_fields()); } static int handheld(void) { static int v = -1; if (v < 0) v = getenv("HOS_HANDHELD") ? atoi(getenv("HOS_HANDHELD")) != 0 : output_row() == 7 || ((output_legacy_file(ini_option("options_version", 0), output_size_fields()) || ini_option("options_version", 0) == 9) && ini_option("handheld_profile", 0) != 0); return v; } /* (hookshot) The Insert menu's Output resolution (output_res=, HOS_OUTPUT_RES over it), docked only: 0 the game's 2048 x 1152, 1 2560 x 1440, 2 3840 x 2160, 3 1920 x 1080, 4 5120 x 1440, 5 5120 x 2880, 6 5120 x 2160 ((Triforce) after the others: a saved number keeps its size), 7 handheld, 8 Screen, 9 Custom (gpu/vk/output_sizes.h, with the rule: the size is the picture's, the game's frame 16:9 at its height). The game's frame is its display size (2560 x 1440 as shipped; nx2/oot_patches.py apply_output_size asks hos_output_size) times its graphics scale (GetCurrentGraphicsScale: 0 x1, 1 x0.8, 2 x0.667). Here it saw scale 1 (x0 left at the call before's answer), so 2048 x 1152; each explicit size uses x1. A size that is not 16:9 (5120 x 1440, 5120 x 2160, and Screen or Custom of such a shape) is the widescreen picture's (hos_output_ratio, host/hos_main.c). The menu lists every connected screen's size as a choice and saves the one chosen as Custom's size (9 with output_width= and output_height=): a size, which means the same whichever screens are connected at the next start. 8, Screen, is what an options file from before that has, and HOS_OUTPUT_RES=8: the size of the screen the window opens on, as it always was; the menu saves it as that size */ static unsigned flex_wh[2][2]; /* (Triforce) Screen's and Custom's sizes as used, 0 x 0 for none: flex_read */ static void flex_read(void) { static int done; if (done) return; done = 1; int sw = 0, sh = 0; hos_screen_size(&sw, &sh); long w = sw, h = sh; if (!output_size_used(w, h, &flex_wh[0][0], &flex_wh[0][1])) flex_wh[0][0] = flex_wh[0][1] = 0; else if ((long)flex_wh[0][0] != w || (long)flex_wh[0][1] != h) hos_log("oe: the screen's %ldx%ld is taken as %ux%u (gpu/vk/output_sizes.h: the sides, the shape and the pixels a picture can have)", w, h, flex_wh[0][0], flex_wh[0][1]); const char *e = getenv("HOS_OUTPUT_SIZE"); w = h = 0; if (e) { if (!output_parse_size(e, &w, &h)) hos_log("oe: HOS_OUTPUT_SIZE=%s is not x: not taken", e); } else { /* (the file's two numbers, as the menu reads them: gpu/vk/vk_menu.cpp custom_rows_read) */ w = ini_option("output_width", 0), h = ini_option("output_height", 0); output_custom_read(&w, &h); } if (!output_size_used(w, h, &flex_wh[1][0], &flex_wh[1][1])) flex_wh[1][0] = flex_wh[1][1] = 0; else if ((long)flex_wh[1][0] != w || (long)flex_wh[1][1] != h) hos_log("oe: the custom output size %ldx%ld is taken as %ux%u (gpu/vk/output_sizes.h: the sides, the shape and the pixels a picture can have)", w, h, flex_wh[1][0], flex_wh[1][1]); } /* (the log: every connected screen with the size the game would take it at, and whether Custom's size is one of them) */ static void screens_log(int custom) { HosScreen list[16]; const int n = hos_screens(list, 16); int found = 0; for (int i = 0; i < n; i++) { unsigned w = 0, h = 0; if (!output_size_used(list[i].w, list[i].h, &w, &h)) continue; hos_log("oe: screen %dx%d%s%s%s%s", list[i].w, list[i].h, list[i].name[0] ? " \"" : "", list[i].name, list[i].name[0] ? "\"" : "", list[i].opens ? ", the one the window opens on" : ""); if (custom && w == flex_wh[1][0] && h == flex_wh[1][1]) found = 1; } if (custom && n && !found) hos_log("oe: output resolution Custom %ux%u is no connected screen's size: taken as it is", flex_wh[1][0], flex_wh[1][1]); } static unsigned out_wh[2]; /* (the Output resolution's size, the picture's: output_mode) */ static int output_mode(void) { static int v = -1; if (v < 0) { static const char *const names[] = {"2048x1152 (the game's)", "2560x1440", "3840x2160", "1920x1080", "5120x1440", "5120x2880", "5120x2160", "1536x864 (handheld)", "Screen", "Custom"}; if (getenv("HOS_OUTPUT_RES")) { v = atoi(getenv("HOS_OUTPUT_RES")); } else { /* (a file from before options_version 8: 5120 x 1440 and 5120 x 2160 as it had them, output_res_read) */ const int version = ini_option("options_version", 0); const int row = ultrawide_row_read(ini_option("ultrawide", 0), version, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); const int saved = ini_option("output_res", 0); v = output_file_read(saved, version, row, output_size_fields()); if (v != saved) { if (saved == 7 || saved == 8) hos_log("oe: output resolution %s (%d) from native 0.5.2: now %d under options_version %d, the same choice", saved == 7 ? "Screen" : "Custom", saved, v, OUTPUT_OPTIONS_VERSION); else hos_log("oe: output resolution %s with Ultrawide on another shape, from before options_version %d: %s now, the same picture", names[saved], OUTPUT_OPTIONS_VERSION, names[v]); } } if ((unsigned)v > OUTPUT_LAST || handheld()) v = 0; if (v >= OUTPUT_SCREEN) { flex_read(); const unsigned *s = flex_wh[v - OUTPUT_SCREEN]; if (!s[1]) { /* (no size: the screen's not known, or HOS_OUTPUT_SIZE is not one) */ hos_log("oe: output resolution %s: %s, so 2560x1440", names[v], v == OUTPUT_SCREEN ? "the screen's size is not known" : "HOS_OUTPUT_SIZE is not a size"); v = 1; } else { out_wh[0] = s[0], out_wh[1] = s[1]; } } /* (0, the game's own 2048 x 1152: its display size 2560 x 1440 at its graphics scale x0.8, above) */ if (v < OUTPUT_SCREEN) out_wh[0] = output_fixed_size(v ? v : 1, 0), out_wh[1] = output_fixed_size(v ? v : 1, 1); if (v >= OUTPUT_SCREEN) hos_log("oe: output resolution %s %ux%u", names[v], out_wh[0], out_wh[1]); else hos_log("oe: output resolution %s", names[v]); screens_log(v == OUTPUT_CUSTOM); if (output_size_shaped(out_wh[0], out_wh[1])) hos_log("oe: %ux%u is the picture: the game's frame is %ux%u in its middle", out_wh[0], out_wh[1], output_frame_width(out_wh[1]), out_wh[1]); } return v; } /* The game's frame: the Output resolution's size, or 16:9 at its height when the size has another shape */ uint32_t hos_output_size(int height) { output_mode(); if (height) return out_wh[1]; return output_size_shaped(out_wh[0], out_wh[1]) ? output_frame_width(out_wh[1]) : out_wh[0]; } /* (Triforce, host/hos_main.c) The Output resolution's own shape, width over height, when it is not 16:9: the picture is then that size, and the Ultrawide row does not apply. 0 for a 16:9 size (the row's shape, or the game's own picture) */ float hos_output_ratio(void) { output_mode(); return output_size_shaped(out_wh[0], out_wh[1]) ? (float)((double)out_wh[0] / (double)out_wh[1]) : 0.0f; } /* (hookshot) The render targets' GPU pool (nx2/oot_patches.py), 0x13100000 bytes as shipped, for 2560 x 1440: a 3840x2160 3D at the 4K output ran out of it. Scaled with the output's pixels, or the widescreen picture's when it has more (host/hos_main.c: hos_wide_out, the output's height at the screen's shape: 7680 x 2160 for a 32:9 screen at the 4K output, twice the pixels the pool was scaled for, and the game crashed as Kokiri Forest loaded, a null pointer or "texture handle ids -1", issue 1031); Castle Town's guard-house conversation/camera test crashed with 305 MB at 2560 x 1440 and passed with 512 MB. Keep at least 512 MB by default; larger scaled pools and an explicit HOS_RT_POOL_MB= still win. The 5120 x 2880 output's pool is kept to 900 MB: scaled, it is 1220 MB, and 1220 and 1000 MB both failed the game's own reservation at boot; at 900 MB it boots and plays with the 3D at the full 5120 x 2880. Every other output keeps its whole scaled pool. That 900 MB is the most for the whole pool there, the RGBA16F scene's 128 MB counted in: the 5120 x 2880 output with RenoDX HDR asked 900 + 128 = 1028 MB, and the game stopped at boot in f_83b7b340, where the "Graphics" heap is made larger by as much as the pool (nx2/oot_patches.py): a null pointer (a player's log, v0.3.7). With the 900 MB, 11-15 on an RTX 4070 SUPER: that output with RenoDX HDR boots and played in the world, 17,160 presents at about 50 fps, RenoDX's four shaders in place, no error from the pool (one short session, not every area; its scene target and each copy are 118 MB there). */ /* ((Triforce, 11-21, the performance audit's TEX-85) Whether the render targets' heap is held to a size, with no room to give: HOS_RT_POOL_MB set, or a picture limited to the 900 MB cap. -1 until hos_rt_pool_size has run. host/shadow_slot.h reserves no stepped storage there unless asked to) */ static int rt_pool_pinned = -1; int hos_rt_pool_pinned(void) { return __atomic_load_n(&rt_pool_pinned, __ATOMIC_RELAXED); } uint64_t hos_rt_pool_size(uint64_t game) { const char *e = getenv("HOS_RT_POOL_MB"); extern volatile uint64_t hos_wide_out; const uint64_t wide = hos_wide_out, wide_px = (wide >> 32) * (wide & 0xffffffffULL); uint64_t px = (uint64_t)hos_output_size(0) * hos_output_size(1); if (wide_px > px) px = wide_px; const uint64_t scaled = px > 2560 * 1440 ? (game * px / (2560 * 1440) + 0xfffff) & ~0xfffffULL : game; const uint64_t minimum = 512ULL << 20, five_k = 900ULL << 20; /* ((Triforce) and the 5120 x 2160 output: scaled, its pool is 915 MB, more than any pool known to pass the game's reservation at a 5120-wide output; 900 MB ran the 3D at the full 5120 x 2880, a third more pixels. So any output of more pixels than 3840 x 2160's, whether they are the frame's or the widescreen picture's: a 5120 x 2160 picture has the frame 3840 x 2160, and scaled for the picture its pool would be those 915 MB (the 1.4 GB of a 7680 x 2160 picture failed the reservation too, host/hos_main.c). gpu/vk/output_sizes.h keeps a picture to 5120 x 2880's pixels, the most the 900 MB are known to hold) */ const int is_five_k = px > 3840ull * 2160ull; extern int hos_scene_rgba16f(void); /* (local, RenoDX port) the scene's colour target at 8 bytes a pixel in place of 4: room for it and its copies, at 3840 x 2160 33 MB each */ const uint64_t rgba16f = hos_scene_rgba16f() ? 128ULL << 20 : 0; const uint64_t asked = (e ? strtoull(e, NULL, 0) << 20 : scaled < minimum ? minimum : is_five_k && scaled > five_k ? five_k : scaled) + (e ? 0 : rgba16f); /* (the 5120 x 2880 output: 900 MB for the whole pool, see above; an explicit HOS_RT_POOL_MB still wins) */ const uint64_t v = !e && is_five_k && asked > five_k ? five_k : asked; __atomic_store_n(&rt_pool_pinned, e != NULL || (is_five_k && v == five_k), __ATOMIC_RELAXED); /* ((Triforce, 11-21, TEX-85)) */ static int logged; if (!logged++) { hos_log("applet: render target pool %llu MB (the game's %llu MB)", (unsigned long long)(v >> 20), (unsigned long long)(game >> 20)); if (v != asked) hos_log("applet: render target pool: %llu MB asked (%llu pixels), kept to %llu MB: more fails the game's reservation at boot", (unsigned long long)(asked >> 20), (unsigned long long)px, (unsigned long long)(v >> 20)); } return v; } HLE(_ZN2nn2oe16GetOperationModeEv) { RET(handheld() ? 0 : 1); } /* OperationMode_Handheld / _Console (docked) */ HLE(_ZN2nn2oe18GetPerformanceModeEv) { RET(handheld() ? 0 : 1); } /* PerformanceMode_Normal / _Boost (docked) */ HLE(_ZN2nn2oe20GetCurrentFocusStateEv) { RET(1); } /* FocusState_InFocus */ HLE(_ZN2nn2oe25GetProgramTotalActiveTimeEv) { RET(hos_now_ns() - boot_ns); } HLE(_ZN2nn2oe24GetExpectedVolumeBalanceEPfS1_) { float one = 1.0f; memcpy(GP(ARG(0)), &one, 4); memcpy(GP(ARG(1)), &one, 4); } HLE(_ZN2nn2oe24SetExpectedVolumeBalanceEff) {} HLE(_ZN2nn2oe15SetCpuBoostModeENS0_12CpuBoostModeE) {} HLE(_ZN2nn2oe20SetFocusHandlingModeENS0_17FocusHandlingModeE) {} HLE(_ZN2nn2oe27SetPerformanceConfigurationENS0_15PerformanceModeEi) {} HLE(_ZN2nn2oe42SetOperationModeChangedNotificationEnabledEb) {} HLE(_ZN2nn2oe44SetPerformanceModeChangedNotificationEnabledEb) {} HLE(_ZN2nn2oe28SetResumeNotificationEnabledEb) {} HLE(_ZN2nn2oe38SetUserInactivityDetectionTimeExtendedEb) {} /* No system notifications ever arrive: TryPop says none, Pop waits forever (as it would on a quiet console). */ HLE(_ZN2nn2oe25TryPopNotificationMessageEPj) { RET(0); } HLE(_ZN2nn2oe22PopNotificationMessageEv) { for (;;) hos_sleep_ns(1000000000LL); } /* ---- nn::account: one user ------------------------------------------------------------------------------------ */ static const uint64_t user_uid[2] = {0x0000000000000001ULL, 0x5a3c9e1f0b7d2468ULL}; HLE(_ZN2nn7account10InitializeEv) {} /* TryOpenPreselectedUser(UserHandle*) -> bool. A handle is three words; ours carries the uid. */ HLE(_ZN2nn7account22TryOpenPreselectedUserEPNS0_10UserHandleE) { G64(ARG(0)) = user_uid[0]; G64(ARG(0) + 8) = user_uid[1]; G64(ARG(0) + 16) = 1; RET(1); } HLE(_ZN2nn7account9CloseUserERKNS0_10UserHandleE) {} /* GetUserId(Uid*, UserHandle const&) -> Result */ HLE(_ZN2nn7account9GetUserIdEPNS0_3UidERKNS0_10UserHandleE) { G64(ARG(0)) = user_uid[0]; G64(ARG(0) + 8) = user_uid[1]; RET(0); } /* GetNickname(Nickname*, Uid const&) -> Result: Nickname is char[33] */ HLE(_ZN2nn7account11GetNicknameEPNS0_8NicknameERKNS0_3UidE) { memset(GP(ARG(0)), 0, 33); memcpy(GP(ARG(0)), "Player", 6); RET(0); } HLE(_ZN2nn7account16GetUserExistenceEPbRKNS0_3UidE) { *(uint8_t *)GP(ARG(0)) = G64(ARG(1)) == user_uid[0] && G64(ARG(1) + 8) == user_uid[1]; RET(0); } /* ---- nn::time: the host clock --------------------------------------------------------------------------------- */ HLE(_ZN2nn4time10InitializeEv) { RET(0); } HLE(_ZN2nn4time8FinalizeEv) { RET(0); } HLE(_ZN2nn4time13IsInitializedEv) { RET(1); } /* HOS_FIXED_TIME=: the clock starts there at boot (runs that can be compared: what the title shows follows the time) */ static uint64_t now_posix(void) { static int64_t fixed = -1; if (fixed < 0) fixed = getenv("HOS_FIXED_TIME") ? _atoi64(getenv("HOS_FIXED_TIME")) : 0; return fixed ? (uint64_t)(fixed + hos_now_ns() / 1000000000LL) : (uint64_t)time(NULL); } HLE(_ZN2nn4time23StandardUserSystemClock14GetCurrentTimeEPNS0_9PosixTimeE) { G64(ARG(0)) = now_posix(); RET(0); } HLE(_ZN2nn4time26StandardNetworkSystemClock14GetCurrentTimeEPNS0_9PosixTimeE) { G64(ARG(0)) = now_posix(); RET(0); } /* StandardSteadyClock::now() -> time_point (std::chrono, rep int64, period seconds): one register, x0. (hookshot) It was a 24-byte SteadyClockTimePoint written through x8; OoT reads x0 and leaves x8 unset (it was 0: the write faulted at guest 0). MKW does not import it. */ HLE(_ZN2nn4time19StandardSteadyClock3nowEv) { RET((uint64_t)(hos_now_ns() / 1000000000LL)); } /* (hookshot) nn::socket::detail::Poll(pollfd* fds, unsigned long n, int timeout_ms): offline, no descriptor is ever ready. OoT's gRPC poll engine (nn.npln.GrpcDispatcher) calls it through a function pointer, past the socket imports the runtime stubs, and the SDK's own Poll aborted on the uninitialized socket layer. It waits out the timeout (an infinite one in 50 ms steps, which the poll loop takes as a spurious wake) and reports a timeout. */ static void socket_poll(Ctx *c) { const uint64_t fds = ARG(0), n = ARG(1); const int timeout = (int)ARG(2); for (uint64_t i = 0; fds && i < n && i < 4096; i++) *(uint16_t *)GP(fds + 8 * i + 6) = 0; /* revents */ if (timeout != 0) { const int away = hos_vcore_away(); hos_sleep_ns((int64_t)(timeout < 0 || timeout > 50 ? 50 : timeout) * 1000000); if (away) hos_vcore_back(); } RET(0); } HLE(_ZN2nn6socket6detail4PollEP6pollfdmi) { socket_poll(c); } HLE(_ZN2nn6socket6detail4PollEPNS0_6PollFdEmi) { socket_poll(c); } /* (hookshot) nn::account::EnsureNetworkServiceAccountIdTokenCacheAsync(AsyncContext*, UserHandle const&): offline, so no network service account. The generic stub's 0 said the task started, and OoT's npln worker (main 0x8214eac0) then waited on the AsyncContext nothing had set up. This failure (account module 124, description 280) takes the game's error branch right after the call. */ HLE(_ZN2nn7account44EnsureNetworkServiceAccountIdTokenCacheAsyncEPNS0_12AsyncContextERKNS0_10UserHandleE) { RET(124 | (280 << 9)); } /* (hookshot) nn::nsd::GetEnvironmentIdentifier(EnvironmentIdentifier* out): char[8]; retail units say "lp1". OoT (main 0x8243f490) only checks for a "t-" test prefix. Left to the SDK it asks the nsd service over HIPC. */ HLE(_ZN2nn3nsd24GetEnvironmentIdentifierEPNS0_21EnvironmentIdentifierE) { if (ARG(0)) { memset(GP(ARG(0)), 0, 8); memcpy(GP(ARG(0)), "lp1", 3); } } static void calendar(uint64_t out, uint64_t info, int64_t posix, int local) { time_t t = (time_t)posix; struct tm tmv = {0}; /* (hookshot: a time the C library cannot convert left it as the stack had it) */ if (local) localtime_s(&tmv, &t); else gmtime_s(&tmv, &t); /* CalendarTime { s16 year; s8 month, day, hour, minute, second; pad } */ uint8_t ct[8] = {0}; int16_t year = (int16_t)(tmv.tm_year + 1900); memcpy(ct, &year, 2); ct[2] = (uint8_t)(tmv.tm_mon + 1); ct[3] = (uint8_t)tmv.tm_mday; ct[4] = (uint8_t)tmv.tm_hour; ct[5] = (uint8_t)tmv.tm_min; ct[6] = (uint8_t)tmv.tm_sec; memcpy(GP(out), ct, 8); if (info) { /* CalendarAdditionalInfo { s32 dayOfWeek, dayOfYear; char tz[8]; s32 isDst; s32 utcOffset } */ memset(GP(info), 0, 0x18); G32(info) = (uint32_t)tmv.tm_wday; G32(info + 4) = (uint32_t)tmv.tm_yday; memcpy(GP(info + 8), "UTC", 3); } } /* ToCalendarTime(CalendarTime*, CalendarAdditionalInfo*, PosixTime const&) -> Result */ HLE(_ZN2nn4time14ToCalendarTimeEPNS0_12CalendarTimeEPNS0_22CalendarAdditionalInfoERKNS0_9PosixTimeE) { calendar(ARG(0), ARG(1), (int64_t)G64(ARG(2)), 1); RET(0); } /* ToCalendarTimeInUtc(PosixTime const&) -> CalendarTime (8 bytes, in x0) */ HLE(_ZN2nn4time19ToCalendarTimeInUtcERKNS0_9PosixTimeE) { static _Thread_local uint64_t tmp; if (!tmp) tmp = hos_sys_alloc(8, 8); calendar(tmp, 0, (int64_t)G64(ARG(0)), 0); RET(G64(tmp)); } /* ToPosixTimeFromUtc(CalendarTime const&) -> PosixTime */ HLE(_ZN2nn4time18ToPosixTimeFromUtcERKNS0_12CalendarTimeE) { uint8_t ct[8]; memcpy(ct, GP(ARG(0)), 8); struct tm tmv = {0}; int16_t year; memcpy(&year, ct, 2); tmv.tm_year = year - 1900; tmv.tm_mon = ct[2] - 1; tmv.tm_mday = ct[3]; tmv.tm_hour = ct[4]; tmv.tm_min = ct[5]; tmv.tm_sec = ct[6]; RET((uint64_t)_mkgmtime(&tmv)); } /* ClockSnapshot: an opaque 0xD0-byte record; ours holds the POSIX time at +0 */ HLE(_ZN2nn4time13ClockSnapshotC1Ev) { memset(GP(ARG(0)), 0, 0xD0); } HLE(_ZN2nn4time13ClockSnapshot29CreateWithStandardSystemClockEPS1_) { memset(GP(ARG(0)), 0, 0xD0); G64(ARG(0)) = now_posix(); RET(0); } /* CalculateSpanBetween(TimeSpan*, ClockSnapshot const& a, ClockSnapshot const& b) -> Result */ HLE(_ZN2nn4time20CalculateSpanBetweenEPNS_8TimeSpanERKNS0_13ClockSnapshotES5_) { G64(ARG(0)) = (uint64_t)(((int64_t)G64(ARG(2)) - (int64_t)G64(ARG(1))) * 1000000000LL); RET(0); } HLE(_ZN2nn4time48CalculateStandardUserSystemClockDifferenceByUserERKNS0_13ClockSnapshotES3_) { RET(0); } /* ---- nn::pl: system shared fonts. We have none; report an empty one, loaded. ------------------------------------ */ static uint64_t empty_font; HLE(_ZN2nn2pl22GetSharedFontLoadStateENS0_14SharedFontTypeE) { RET(1); } /* SharedFontLoadState_Loaded */ HLE(_ZN2nn2pl20GetSharedFontAddressENS0_14SharedFontTypeE) { if (!empty_font) empty_font = hos_sys_alloc(0x1000, 0x1000); RET(empty_font); } HLE(_ZN2nn2pl17GetSharedFontSizeENS0_14SharedFontTypeE) { RET(0); } /* ---- nn::err ------------------------------------------------------------------------------------------------- */ HLE(_ZN2nn3err9ShowErrorENS_6ResultE) { hos_log("err: the game shows error %#x (module %u, description %u)", (uint32_t)ARG(0), (uint32_t)ARG(0) & 0x1FF, ((uint32_t)ARG(0) >> 9) & 0x1FFF); } /* ---- nn::prepo: play reports. The PlayReport builder (Add*, SetEventId) is the SDK's own code; saving one would send it to the prepo service. Reports are dropped. ---------------------------------------------------------- */ HLE(_ZN2nn5prepo10PlayReport4SaveEv) { RET(0); } HLE(_ZN2nn5prepo10PlayReport4SaveERKNS_7account3UidE) { RET(0); } /* (hookshot) PlayReport::Send(Uid const&), SDK 22's: kept nowhere, as Save. Left to the SDK it opened the prepo service through sm: and aborted on the empty reply (OoT's PlayReporter thread, ~5 minutes into a game). */ HLE(_ZN2nn5prepo10PlayReport4SendERKNS_7account3UidE) { RET(0); } /* (hookshot) prepo::AsyncContext: the report "sent" at once. GetCompletionEvent(SystemEvent* out) gives an event already signaled (the SDK's own aborted on the context the empty IPC reply left), GetResult success. */ void hos_system_event_init(uint64_t key, int autoclear); /* nn_os_sync.c */ void hos_system_event_signal(uint64_t key); HLE(_ZN2nn5prepo12AsyncContext18GetCompletionEventEPNS_2os11SystemEventE) { if (ARG(1)) { hos_system_event_init(ARG(1), 0); hos_system_event_signal(ARG(1)); } RET(0); } HLE(_ZN2nn5prepo12AsyncContext9GetResultEv) { RET(0); } HLE(_ZN2nn5prepo12AsyncContextD1Ev) {} /* ---- (mkw-recomp) MKW's account and oe calls TOTK never made: the one user, offline ------------------------- */ /* ListAllUsers(int* count, Uid* out, int max) -> Result */ HLE(_ZN2nn7account12ListAllUsersEPiPNS0_3UidEi) { const int n = (int)ARG(2) > 0 ? 1 : 0; if (n && ARG(1)) { G64(ARG(1)) = user_uid[0]; G64(ARG(1) + 8) = user_uid[1]; } if (ARG(0)) G32(ARG(0)) = (uint32_t)n; RET(0); } /* OpenUser(UserHandle*, Uid const&) -> Result */ HLE(_ZN2nn7account8OpenUserEPNS0_10UserHandleERKNS0_3UidE) { G64(ARG(0)) = G64(ARG(1)); G64(ARG(0) + 8) = G64(ARG(1) + 8); G64(ARG(0) + 16) = 0; RET(0); } /* the network service account: not available (the game stays offline) */ HLE(_ZN2nn7account32IsNetworkServiceAccountAvailableEPbRKNS0_10UserHandleE) { *(uint8_t *)GP(ARG(0)) = 0; RET(0); } HLE(_ZN2nn7account36EnsureNetworkServiceAccountAvailableERKNS0_10UserHandleE) { RET(0x7C7C); } /* (an account error) */ HLE(_ZN2nn7account26GetNetworkServiceAccountIdEPNS0_23NetworkServiceAccountIdERKNS0_10UserHandleE) { G64(ARG(0)) = 0; RET(0x7C7C); } /* nn::oe::GetCurrentGraphicsScale() -> float (docked/handheld render scale): 1.0 */ HLE(_ZN2nn2oe23GetCurrentGraphicsScaleEv) { /* (hookshot) HOS_GRAPHICS_SCALE=: another scale, a test of whether the game sizes its picture by it (4K, issue 68) */ static float scale = 0; static volatile LONG told; if (scale == 0) scale = getenv("HOS_GRAPHICS_SCALE") ? (float)atof(getenv("HOS_GRAPHICS_SCALE")) : 1.0f; if (scale <= 0) scale = 1.0f; if (InterlockedIncrement(&told) <= 3) hos_log("oe: GetCurrentGraphicsScale -> %.2f", scale); const float one = scale; uint32_t bits; memcpy(&bits, &one, 4); c->vreg[0][0] = bits, c->vreg[0][1] = 0; c->x[0] = output_mode() ? 0 : 1; /* (the scale enum the game reads, w0: x1 for a chosen output, x0.8 as before) */ } HLE(_ZN2nn2oe42SetGraphicsScaleChangedNotificationEnabledEb) {} HLE(_ZN2nn2oe31EnterExitRequestHandlingSectionEv) {} HLE(_ZN2nn2oe31LeaveExitRequestHandlingSectionEv) {} HLE(_ZN2nn2oe15EnableRecordingEv) {} HLE(_ZN2nn2oe16DisableRecordingEv) {} HLE(_ZN2nn2oe16EnableScreenShotEv) {} HLE(_ZN2nn2oe17DisableScreenShotEv) {} /* GetDisplayVersion(DisplayVersion*): a 16-byte string */ HLE(_ZN2nn2oe17GetDisplayVersionEPNS0_14DisplayVersionE) { memset(GP(ARG(0)), 0, 16); memcpy(GP(ARG(0)), "1.8.0", 5); } /* nn::camera::sdk::CreateCameraContext(gsdrv::UniqueNativeHandle*) -> Result: no camera (GameChat's video), so the game does not open the camera service through a handle it never got */ HLE(_ZN2nn6camera3sdk19CreateCameraContextEPNS_5gsdrv18UniqueNativeHandleE) { /* the game aborts unless this succeeds: a session handle that hos_svc.c's SendSyncRequest answers generically */ if (ARG(0)) G32(ARG(0)) = 0xC0FE0001u; RET(0); } /* StandardNetworkSystemClock::IsAccuracySufficient(): offline, so no (the lifted SDK version aborted, with no time service session) */ HLE(_ZN2nn4time26StandardNetworkSystemClock20IsAccuracySufficientEv) { RET(0); }