fix(runtime): clean amiibo platform portability, default path, and dump validation

This commit is contained in:
leonelalej committed 2026-10-31 14:11:46 +00:00
1 parent 7d62cbfa85
commit 2bcfc2ef39
13 files changed
+1116 -26

No files matched your search

+377
View File
@@ -0,0 +1,377 @@
// Amiibo dump loader and Horizon OS NFP state emulation.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "amiibo.h"
#include "host.h"
#include "platform/platform.h"
static PlatMutex g_amiibo_lock = PLAT_MUTEX_INIT;
// 540-byte raw NTAG215 binary dump
static uint8_t g_dump[AMIIBO_DUMP_SIZE];
static bool g_has_dump = false;
static AmiiboInfo g_info;
static bool g_device_present = true;
static bool g_detecting = false;
static bool g_tag_present = false;
static bool g_mounted = false;
static bool g_auto_remove = true;
static float g_auto_remove_delay_s = 2.5f;
static uint64_t g_tap_timestamp_ns = 0;
static bool g_timer_active = false;
static bool amiibo_validate_dump(const uint8_t *data, uint64_t size) {
if (size != AMIIBO_DUMP_SIZE) {
return false;
}
// NTAG215 Capability Container (CC) at page 3 (offset 0x0C).
// Byte 0x0C must be 0xE1 (NDEF Magic / Type 2 Tag CC container byte).
if (data[0x0C] != 0xE1) {
return false;
}
// UID sanity: UID (bytes 0..2 and 4..7) cannot be all zeroes or all 0xFF.
if ((data[0] == 0 && data[1] == 0 && data[2] == 0 && data[4] == 0 &&
data[5] == 0 && data[6] == 0 && data[7] == 0) ||
(data[0] == 0xFF && data[1] == 0xFF && data[2] == 0xFF && data[4] == 0xFF &&
data[5] == 0xFF && data[6] == 0xFF && data[7] == 0xFF)) {
return false;
}
// ISO 14443-3 / NTAG215 Bit Check Character (BCC) verification.
// Page 0 byte 3 (BCC0) = 0x88 ^ UID[0] ^ UID[1] ^ UID[2]
// Page 2 byte 0 (BCC1) = UID[3] ^ UID[4] ^ UID[5] ^ UID[6]
uint8_t bcc0 = (uint8_t)(0x88 ^ data[0] ^ data[1] ^ data[2]);
uint8_t bcc1 = (uint8_t)(data[4] ^ data[5] ^ data[6] ^ data[7]);
if (data[3] != bcc0 || data[8] != bcc1) {
return false;
}
return true;
}
static void parse_dump_info(const char *path) {
memset(&g_info, 0, sizeof(g_info));
if (path) {
snprintf(g_info.path, sizeof(g_info.path), "%s", path);
const char *slash = strrchr(path, '\\');
const char *fslash = strrchr(path, '/');
const char *name = slash ? slash + 1 : (fslash ? fslash + 1 : path);
if (slash && fslash) {
name = (slash > fslash ? slash : fslash) + 1;
}
snprintf(g_info.filename, sizeof(g_info.filename), "%s", name);
}
// UID: bytes 0..6 (7 bytes) or up to 9
memcpy(g_info.uuid, g_dump, 7);
g_info.uuid_len = 7;
// Amiibo ID at offset 0x54 (8 bytes)
memcpy(g_info.character_id, g_dump + 0x54, 3);
g_info.series_id = g_dump[0x57];
g_info.numbering_id = ((uint16_t)g_dump[0x58] << 8) | g_dump[0x59];
g_info.nfp_type = g_dump[0x5A];
g_info.version = g_dump[0x5B];
}
void amiibo_init(void) {
plat_mutex_lock(&g_amiibo_lock);
g_device_present = true;
g_detecting = false;
g_tag_present = false;
g_mounted = false;
g_has_dump = false;
g_timer_active = false;
memset(g_dump, 0, sizeof(g_dump));
memset(&g_info, 0, sizeof(g_info));
plat_mutex_unlock(&g_amiibo_lock);
}
void amiibo_set_device_present(bool present) {
plat_mutex_lock(&g_amiibo_lock);
g_device_present = present;
plat_mutex_unlock(&g_amiibo_lock);
}
bool amiibo_is_device_present(void) {
plat_mutex_lock(&g_amiibo_lock);
bool res = g_device_present;
plat_mutex_unlock(&g_amiibo_lock);
return res;
}
void amiibo_start_detection(void) {
plat_mutex_lock(&g_amiibo_lock);
g_detecting = true;
rt_log("amiibo: start detection");
plat_mutex_unlock(&g_amiibo_lock);
}
void amiibo_stop_detection(void) {
plat_mutex_lock(&g_amiibo_lock);
g_detecting = false;
rt_log("amiibo: stop detection");
plat_mutex_unlock(&g_amiibo_lock);
}
bool amiibo_is_detecting(void) {
plat_mutex_lock(&g_amiibo_lock);
bool res = g_detecting;
plat_mutex_unlock(&g_amiibo_lock);
return res;
}
bool amiibo_mount(void) {
plat_mutex_lock(&g_amiibo_lock);
if (!g_device_present || !g_tag_present) {
plat_mutex_unlock(&g_amiibo_lock);
return false;
}
g_mounted = true;
rt_log("amiibo: mounted tag '%s'", g_info.filename[0] ? g_info.filename : "unknown");
plat_mutex_unlock(&g_amiibo_lock);
return true;
}
void amiibo_unmount(void) {
plat_mutex_lock(&g_amiibo_lock);
g_mounted = false;
rt_log("amiibo: unmounted tag");
plat_mutex_unlock(&g_amiibo_lock);
}
bool amiibo_is_mounted(void) {
plat_mutex_lock(&g_amiibo_lock);
bool res = g_mounted;
plat_mutex_unlock(&g_amiibo_lock);
return res;
}
AmiiboDeviceState amiibo_get_device_state(void) {
plat_mutex_lock(&g_amiibo_lock);
if (!g_device_present) {
plat_mutex_unlock(&g_amiibo_lock);
return AMIIBO_DEV_STATE_UNAVAILABLE;
}
if (g_mounted) {
plat_mutex_unlock(&g_amiibo_lock);
return AMIIBO_DEV_STATE_TAG_MOUNTED;
}
if (g_tag_present) {
plat_mutex_unlock(&g_amiibo_lock);
return AMIIBO_DEV_STATE_TAG_FOUND;
}
if (g_detecting) {
plat_mutex_unlock(&g_amiibo_lock);
return AMIIBO_DEV_STATE_SEARCHING;
}
plat_mutex_unlock(&g_amiibo_lock);
return AMIIBO_DEV_STATE_INITIALIZED;
}
bool amiibo_load_file(const char *path) {
if (!path || !*path) return false;
uint64_t size = 0;
uint8_t *data = plat_file_read(path, &size);
if (!data) {
rt_log("amiibo: failed to read file: %s", path);
return false;
}
if (size != AMIIBO_DUMP_SIZE) {
rt_log("amiibo: invalid dump size (%llu bytes, expected exactly %d): %s",
(unsigned long long)size, AMIIBO_DUMP_SIZE, path);
free(data);
return false;
}
if (!amiibo_validate_dump(data, size)) {
rt_log("amiibo: dump failed NTAG215 structure sanity checks: %s", path);
free(data);
return false;
}
plat_mutex_lock(&g_amiibo_lock);
memcpy(g_dump, data, AMIIBO_DUMP_SIZE);
g_has_dump = true;
parse_dump_info(path);
plat_mutex_unlock(&g_amiibo_lock);
free(data);
rt_log("amiibo: loaded dump '%s' (char_id: %02x%02x%02x, series: %02x, num: %04x)",
g_info.filename, g_info.character_id[0], g_info.character_id[1], g_info.character_id[2],
g_info.series_id, g_info.numbering_id);
return true;
}
void amiibo_tap_tag(void) {
plat_mutex_lock(&g_amiibo_lock);
if (!g_has_dump) {
plat_mutex_unlock(&g_amiibo_lock);
return;
}
g_tag_present = true;
g_tap_timestamp_ns = plat_now_ns();
if (g_auto_remove) {
g_timer_active = true;
}
rt_log("amiibo: tag tapped on reader ('%s')", g_info.filename);
plat_mutex_unlock(&g_amiibo_lock);
}
bool amiibo_scan_and_tap(const char *path) {
if (!amiibo_load_file(path)) return false;
amiibo_tap_tag();
return true;
}
void amiibo_remove_tag(void) {
plat_mutex_lock(&g_amiibo_lock);
if (g_tag_present || g_mounted) {
g_tag_present = false;
g_mounted = false;
g_timer_active = false;
rt_log("amiibo: tag removed from reader");
}
plat_mutex_unlock(&g_amiibo_lock);
}
void amiibo_tick(void) {
plat_mutex_lock(&g_amiibo_lock);
if (g_timer_active && g_tag_present) {
uint64_t now = plat_now_ns();
uint64_t diff = now > g_tap_timestamp_ns ? now - g_tap_timestamp_ns : 0;
uint64_t limit_ns = (uint64_t)(g_auto_remove_delay_s * 1000000000.0f);
if (diff >= limit_ns) {
g_tag_present = false;
g_mounted = false;
g_timer_active = false;
rt_log("amiibo: auto-removed tag after %.1fs timeout", (double)g_auto_remove_delay_s);
}
}
plat_mutex_unlock(&g_amiibo_lock);
}
void amiibo_set_auto_remove(bool enable) {
plat_mutex_lock(&g_amiibo_lock);
g_auto_remove = enable;
if (!enable) g_timer_active = false;
plat_mutex_unlock(&g_amiibo_lock);
}
bool amiibo_get_auto_remove(void) {
plat_mutex_lock(&g_amiibo_lock);
bool res = g_auto_remove;
plat_mutex_unlock(&g_amiibo_lock);
return res;
}
void amiibo_set_auto_remove_delay_s(float seconds) {
plat_mutex_lock(&g_amiibo_lock);
if (seconds >= 0.5f && seconds <= 10.0f) g_auto_remove_delay_s = seconds;
plat_mutex_unlock(&g_amiibo_lock);
}
float amiibo_get_auto_remove_delay_s(void) {
plat_mutex_lock(&g_amiibo_lock);
float res = g_auto_remove_delay_s;
plat_mutex_unlock(&g_amiibo_lock);
return res;
}
bool amiibo_has_tag(void) {
plat_mutex_lock(&g_amiibo_lock);
bool res = g_has_dump && g_tag_present;
plat_mutex_unlock(&g_amiibo_lock);
return res;
}
const AmiiboInfo *amiibo_get_current_info(void) {
return &g_info;
}
const uint8_t *amiibo_get_raw_data(void) {
return g_dump;
}
void amiibo_get_tag_info(void *out_tag_info) {
plat_mutex_lock(&g_amiibo_lock);
uint8_t *out = (uint8_t *)out_tag_info;
memset(out, 0, 0x58);
// UUID: offset 0x00, 10 bytes max
memcpy(out + 0x00, g_dump, 7);
out[0x0A] = 7; // UUID length
// Protocol at offset 0x20: TypeA = 1
*(uint32_t *)(out + 0x20) = 1;
// TagType at offset 0x24: Type2 / NTAG215 = 2
*(uint32_t *)(out + 0x24) = 2;
plat_mutex_unlock(&g_amiibo_lock);
}
void amiibo_get_model_info(void *out_model_info) {
plat_mutex_lock(&g_amiibo_lock);
uint8_t *out = (uint8_t *)out_model_info;
memset(out, 0, 0x40);
// Character ID at 0x00 (3 bytes)
memcpy(out + 0x00, g_dump + 0x54, 3);
// Series ID at 0x03 (1 byte)
out[0x03] = g_dump[0x57];
// Numbering ID at 0x04 (2 bytes, big-endian from 0x58)
out[0x04] = g_dump[0x58];
out[0x05] = g_dump[0x59];
// NFP Type at 0x06 (1 byte)
out[0x06] = g_dump[0x5A];
plat_mutex_unlock(&g_amiibo_lock);
}
void amiibo_get_common_info(void *out_common_info) {
plat_mutex_lock(&g_amiibo_lock);
uint8_t *out = (uint8_t *)out_common_info;
memset(out, 0, 0x40);
// Last write date: 0x00..0x03
out[0x00] = 0x07; out[0x01] = 0xE7; // 2023
out[0x02] = 0x05; out[0x03] = 0x0C; // May 12
// Write counter: 0x04..0x05
out[0x04] = 0x00; out[0x05] = 0x01;
// Version: 0x06
out[0x06] = 0x02;
// Application area size: 0x08..0x0B = 0xD8 (216 bytes)
*(uint32_t *)(out + 0x08) = 0xD8;
plat_mutex_unlock(&g_amiibo_lock);
}
void amiibo_get_register_info(void *out_register_info) {
plat_mutex_lock(&g_amiibo_lock);
uint8_t *out = (uint8_t *)out_register_info;
memset(out, 0, 0x100);
// Mii CharInfo at 0x00..0x57 (dummy valid mii)
out[0x00] = 0x03; // version 3
// First write date at 0x58..0x5B
out[0x58] = 0x07; out[0x59] = 0xE7;
out[0x5A] = 0x05; out[0x5B] = 0x0C;
// Amiibo Name at 0x5C: copy up to 40 bytes NUL-terminated
const char *name = g_info.filename[0] ? g_info.filename : "Amiibo";
snprintf((char *)(out + 0x5C), 0x29, "%s", name);
plat_mutex_unlock(&g_amiibo_lock);
}
int amiibo_get_application_area(void *out_buf, uint32_t max_size) {
plat_mutex_lock(&g_amiibo_lock);
if (!g_has_dump || !out_buf) {
plat_mutex_unlock(&g_amiibo_lock);
return 0;
}
uint32_t to_copy = max_size < 0xD8 ? max_size : 0xD8;
// Decrypted/payload application area starts at offset 0xDC (or 0x0A0..0x178 in raw dump)
if (0xDC + to_copy <= AMIIBO_DUMP_SIZE) {
memcpy(out_buf, g_dump + 0xDC, to_copy);
} else {
memset(out_buf, 0, to_copy);
}
plat_mutex_unlock(&g_amiibo_lock);
return (int)to_copy;
}
+84
View File
@@ -0,0 +1,84 @@
// Amiibo loader and state management subsystem (540-byte NTAG215 binary dumps).
#pragma once
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define AMIIBO_DUMP_SIZE 540
// Device state corresponding to nn::nfp / nn::nfc DeviceState
typedef enum {
AMIIBO_DEV_STATE_INITIALIZED = 0,
AMIIBO_DEV_STATE_SEARCHING = 1,
AMIIBO_DEV_STATE_TAG_FOUND = 2,
AMIIBO_DEV_STATE_TAG_REMOVED = 3,
AMIIBO_DEV_STATE_TAG_MOUNTED = 4,
AMIIBO_DEV_STATE_UNAVAILABLE = 5
} AmiiboDeviceState;
// Amiibo identification info
typedef struct {
uint8_t uuid[10];
uint8_t uuid_len;
uint8_t character_id[3];
uint8_t series_id;
uint16_t numbering_id;
uint8_t nfp_type;
uint8_t version;
char path[512];
char filename[128];
} AmiiboInfo;
// Subsystem lifecycle
void amiibo_init(void);
// Hardware / device emulation status
void amiibo_set_device_present(bool present);
bool amiibo_is_device_present(void);
// Tag detection & lifecycle
void amiibo_start_detection(void);
void amiibo_stop_detection(void);
bool amiibo_is_detecting(void);
// Tag mounting
bool amiibo_mount(void);
void amiibo_unmount(void);
bool amiibo_is_mounted(void);
// State query
AmiiboDeviceState amiibo_get_device_state(void);
// File loading & triggering actions
bool amiibo_load_file(const char *path);
bool amiibo_scan_and_tap(const char *path);
void amiibo_tap_tag(void);
void amiibo_remove_tag(void);
// Timer tick called during menu / frame updates
void amiibo_tick(void);
// Options
void amiibo_set_auto_remove(bool enable);
bool amiibo_get_auto_remove(void);
void amiibo_set_auto_remove_delay_s(float seconds);
float amiibo_get_auto_remove_delay_s(void);
// Tag inspection
bool amiibo_has_tag(void);
const AmiiboInfo *amiibo_get_current_info(void);
const uint8_t *amiibo_get_raw_data(void);
// Horizon OS buffers extraction (called by NFP IPC/override services)
void amiibo_get_tag_info(void *out_tag_info);
void amiibo_get_model_info(void *out_model_info);
void amiibo_get_common_info(void *out_common_info);
void amiibo_get_register_info(void *out_register_info);
int amiibo_get_application_area(void *out_buf, uint32_t max_size);
#ifdef __cplusplus
}
#endif
+2 -1
View File
@@ -30,7 +30,7 @@ static int save_ok = 1; // the last cfg_save_to wrote (o
// Every name the runtime reads (and the patch sets in generated/), without the prefix. A file key outside this list is
// logged as unknown. A new variable goes here too, or its ini key logs a harmless "unknown key" line.
static const char *const known[] = {
"AB", "APP_POOL", "ASPECT", "ASPECT_PATCH", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_OFF", "AUDIO_PREFILL_MS",
"AB", "AMIIBO_DIR", "APP_POOL", "ASPECT", "ASPECT_PATCH", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_OFF", "AUDIO_PREFILL_MS",
"BACKGROUND_WINDOW", "BIND_A", "BIND_B", "BIND_DOWN", "BIND_L", "BIND_LCLICK", "BIND_LEFT", "BIND_LSTICK_DOWN", "BIND_LSTICK_LEFT",
"BIND_LSTICK_RIGHT", "BIND_LSTICK_UP", "BIND_MINUS",
"BIND_PLUS", "BIND_R", "BIND_RCLICK", "BIND_RIGHT", "BIND_RSTICK_DOWN", "BIND_RSTICK_LEFT", "BIND_RSTICK_RIGHT", "BIND_RSTICK_UP",
@@ -110,6 +110,7 @@ static const CfgMeta metas[] = {
{"RUMBLE_TRIGGERS", "0", "0|1", LIVE}, {"PAD_LAYOUT", "auto", "auto|nintendo|xbox|xbox_prompts", LIVE},
{"STICK_DEADZONE", "8", "0..50", LIVE}, {"MOUSE_SENS", "1", "0..10", LIVE},
{"MENU_LANG", "", "en|ru", LIVE},
{"AMIIBO_DIR", "", NULL, LIVE},
// Advanced: scheduling
{"ASYNC_PREEMPT", "1", "0|1|2", RESTART}, {"REPLAY_ASYNC", "0", "0|1", RESTART},
{"FREE_CORES", "0", "0|1", RESTART}, {"TIMER_1MS", "1", "0|1", RESTART},
+2
View File
@@ -11,6 +11,7 @@
#include "audren.h"
#include "host.h"
#include "ipc.h"
#include "nfp.h"
#include "platform/platform.h"
#define CMIF_IN_MAGIC 0x49434653u // "SFCI"
@@ -25,6 +26,7 @@ enum { T_CLOSE = 2, T_REQUEST = 4, T_CONTROL = 5, T_REQUEST_CTX = 6, T_CONTROL_C
// Services sm: hands out. Anything else is a named fatal.
static const struct { const char *name; IpcHandler handler; } services[] = {
{"audren:u", audren_manager_handler},
{"nfp:user", nfp_user_manager_handler},
};
static volatile int32_t g_live;
+230
View File
@@ -0,0 +1,230 @@
// Horizon OS nfp:user IPC service implementation (nn::nfp::detail::IUserManager & IUser).
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "amiibo.h"
#include "host.h"
#include "ipc.h"
#include "kernel.h"
#include "nfp.h"
// Simulated NFC device handle: ID 1
static const uint8_t g_device_handle[8] = { 1, 0, 0, 0, 0, 0, 0, 0 };
typedef struct {
uint32_t activate_event; // writable handle
uint32_t deactivate_event; // writable handle
uint32_t avail_event; // writable handle
} NfpUserState;
static void nfp_user_close(void *p) {
NfpUserState *st = p;
if (st) {
if (st->activate_event) kern_handle_close(st->activate_event);
if (st->deactivate_event) kern_handle_close(st->deactivate_event);
if (st->avail_event) kern_handle_close(st->avail_event);
free(st);
}
rt_log("nfp: IUser session closed");
}
// Handler for nn::nfp::detail::IUser
static void nfp_user_handler(IpcSession *s, const IpcRequest *rq, IpcResponse *rs) {
NfpUserState *st = (NfpUserState *)s->state;
switch (rq->cmd) {
case 0: { // InitializeNfp(u64 aruid, u64 m_pid, pid, buffer<unknown, 5>)
rt_log("nfp: Initialize");
rs->result = 0;
return;
}
case 1: { // FinalizeNfp()
rt_log("nfp: Finalize");
amiibo_stop_detection();
amiibo_unmount();
rs->result = 0;
return;
}
case 2: { // ListDevicesNfp() -> (s32 total_out, buffer<DeviceHandle, 0xa>)
int32_t count = amiibo_is_device_present() ? 1 : 0;
IPC_OUT(rs, count);
if (count > 0 && rq->nb > 0 && rq->b[0].size >= sizeof(g_device_handle)) {
void *dst = ipc_guest(rq->b[0].addr, sizeof(g_device_handle));
memcpy(dst, g_device_handle, sizeof(g_device_handle));
}
rs->result = 0;
return;
}
case 3: { // StartDetectionNfp(DeviceHandle)
amiibo_start_detection();
if (amiibo_has_tag() && st && st->activate_event) {
kern_event_signal(st->activate_event);
}
rs->result = 0;
return;
}
case 4: { // StopDetectionNfp(DeviceHandle)
amiibo_stop_detection();
rs->result = 0;
return;
}
case 5: { // MountNfp(DeviceHandle, u32 ModelType, u32 MountTarget)
if (!amiibo_has_tag()) {
rs->result = 0x8073u; // Device/Tag not found
return;
}
amiibo_mount();
rs->result = 0;
return;
}
case 6: { // UnmountNfp(DeviceHandle)
amiibo_unmount();
if (st && st->deactivate_event) {
kern_event_signal(st->deactivate_event);
}
rs->result = 0;
return;
}
case 7: { // OpenApplicationAreaNfp(DeviceHandle, u32 access_id)
if (!amiibo_is_mounted()) {
rs->result = 0x927Fu; // not mounted
return;
}
rs->result = 0;
return;
}
case 8: { // GetApplicationAreaNfp(DeviceHandle) -> (u32 size, buffer<data, 0x6>)
if (!amiibo_is_mounted()) {
rs->result = 0x927Fu;
return;
}
uint32_t area_size = 0xD8;
if (rq->nb > 0 && rq->b[0].size > 0) {
void *dst = ipc_guest(rq->b[0].addr, rq->b[0].size);
area_size = (uint32_t)amiibo_get_application_area(dst, (uint32_t)rq->b[0].size);
}
IPC_OUT(rs, area_size);
rs->result = 0;
return;
}
case 13: { // GetTagInfoNfp(DeviceHandle) -> buffer<TagInfo, 0x1a>
if (!amiibo_has_tag() && !amiibo_is_mounted()) {
rs->result = 0x8073u;
return;
}
if (rq->nb > 0 && rq->b[0].size >= 0x58) {
void *dst = ipc_guest(rq->b[0].addr, 0x58);
amiibo_get_tag_info(dst);
}
rs->result = 0;
return;
}
case 14: { // GetRegisterInfoNfp(DeviceHandle) -> buffer<RegisterInfo, 0x1a>
if (!amiibo_is_mounted()) {
rs->result = 0x927Fu;
return;
}
if (rq->nb > 0 && rq->b[0].size >= 0x100) {
void *dst = ipc_guest(rq->b[0].addr, 0x100);
amiibo_get_register_info(dst);
}
rs->result = 0;
return;
}
case 15: { // GetCommonInfoNfp(DeviceHandle) -> buffer<CommonInfo, 0x1a>
if (!amiibo_is_mounted()) {
rs->result = 0x927Fu;
return;
}
if (rq->nb > 0 && rq->b[0].size >= 0x40) {
void *dst = ipc_guest(rq->b[0].addr, 0x40);
amiibo_get_common_info(dst);
}
rs->result = 0;
return;
}
case 16: { // GetModelInfoNfp(DeviceHandle) -> buffer<ModelInfo, 0x1a>
if (!amiibo_is_mounted()) {
rs->result = 0x927Fu;
return;
}
if (rq->nb > 0 && rq->b[0].size >= 0x40) {
void *dst = ipc_guest(rq->b[0].addr, 0x40);
amiibo_get_model_info(dst);
}
rs->result = 0;
return;
}
case 17: { // GetActivateEventHandleNfp(DeviceHandle) -> handle<copy>
if (st && st->activate_event) {
rs->copy[rs->ncopy++] = kern_event_readable(st->activate_event);
}
rs->result = 0;
return;
}
case 18: { // GetDeactivateEventHandleNfp(DeviceHandle) -> handle<copy>
if (st && st->deactivate_event) {
rs->copy[rs->ncopy++] = kern_event_readable(st->deactivate_event);
}
rs->result = 0;
return;
}
case 19: { // GetStateNfp() -> u32 state
uint32_t state = 1; // Initialized
IPC_OUT(rs, state);
rs->result = 0;
return;
}
case 20: { // GetDeviceStateNfp(DeviceHandle) -> u32 device_state
uint32_t dev_state = (uint32_t)amiibo_get_device_state();
IPC_OUT(rs, dev_state);
rs->result = 0;
return;
}
case 21: { // GetNpadIdNfp(DeviceHandle) -> u32 npad_id
uint32_t npad_id = 0; // Handheld / Player 1
IPC_OUT(rs, npad_id);
rs->result = 0;
return;
}
case 22: { // GetApplicationAreaSizeNfp(DeviceHandle) -> u32 size
uint32_t size = 0xD8;
IPC_OUT(rs, size);
rs->result = 0;
return;
}
case 23: { // GetAvailabilityChangeEventHandleNfp() -> handle<copy>
if (st && st->avail_event) {
rs->copy[rs->ncopy++] = kern_event_readable(st->avail_event);
}
rs->result = 0;
return;
}
default:
ipc_unimplemented(s, rq);
}
}
// Handler for nn::nfp::detail::IUserManager (nfp:user)
void nfp_user_manager_handler(IpcSession *s, const IpcRequest *rq, IpcResponse *rs) {
switch (rq->cmd) {
case 0: { // CreateUserInterface() -> move handle to IUser
NfpUserState *st = calloc(1, sizeof(*st));
if (!st) rt_fatal("nfp: failed to allocate user state");
st->activate_event = kern_event_new();
st->deactivate_event = kern_event_new();
st->avail_event = kern_event_new();
// Signal availability immediately so game detects reader
kern_event_signal(st->avail_event);
uint32_t user_session = ipc_session_new("nfp:IUser", nfp_user_handler, st, nfp_user_close);
rs->move[rs->nmove++] = user_session;
rs->result = 0;
rt_log("nfp: created IUser session handle %#x", user_session);
return;
}
default:
ipc_unimplemented(s, rq);
}
}
+14
View File
@@ -0,0 +1,14 @@
// Nintendo Figurine Platform (nfp:user) Horizon OS IPC service emulation.
#pragma once
#include "ipc.h"
#ifdef __cplusplus
extern "C" {
#endif
// sm: handler for "nfp:user" (nn::nfp::detail::IUserManager)
void nfp_user_manager_handler(IpcSession *s, const IpcRequest *rq, IpcResponse *rs);
#ifdef __cplusplus
}
#endif
+7 -5
View File
@@ -357,21 +357,23 @@ static void probe_applet(void) {
"AddInternetConnectionStatus");
CHECK(CALL("nfp.Initialize", 0) == 0 && (uint32_t)CALL("nfp.GetState", 0) == 1, "nfp initialize");
uint8_t handles[64];
int32_t count = 7;
CHECK((uint32_t)CALL("nfp.ListDevices", U(handles), U(&count), 4) == 0x8073 && count == 0, "nfp ListDevices");
int32_t count = 0;
CHECK((uint32_t)CALL("nfp.ListDevices", U(handles), U(&count), 4) == 0 && count == 1, "nfp ListDevices");
uint64_t ev = U(guest_alloc(0x100));
CHECK(CALL("nfp.AttachAvailabilityChangeEvent", ev) == 0, "AttachAvailabilityChangeEvent");
int nfp_event = event_works(ev, 0);
CHECK(nfp_event, "the nfp availability event does not work as a manual-clear system event");
CHECK((uint32_t)CALL("nfp.GetDeviceState", U(handles)) == 0, "nfp device state");
static const char *const none[] = {"nfp.Mount", "nfp.GetNpadId", "nfp.AttachActivateEvent", "nfp.AttachDeactivateEvent",
"nfp.StartDetection", "nfp.StopDetection", "nfp.GetTagInfo", "nfp.GetModelInfo"};
static const char *const none[] = {"nfp.Mount", "nfp.GetTagInfo", "nfp.GetModelInfo"};
uint8_t out[0x100];
for (size_t i = 0; i < sizeof none / sizeof *none; i++) {
int first_is_handle = !strcmp(none[i], "nfp.Mount") || strstr(none[i], "Detection");
int first_is_handle = !strcmp(none[i], "nfp.Mount");
uint64_t r = first_is_handle ? CALL(none[i], U(handles), 0, 0) : CALL(none[i], U(out), U(handles));
CHECK((uint32_t)r == 0x8073, "%s: %#x, not device-not-found", none[i], (uint32_t)r);
}
CHECK((uint32_t)CALL("nfp.GetNpadId", U(out), U(handles)) == 0, "nfp GetNpadId");
CHECK((uint32_t)CALL("nfp.StartDetection", U(handles)) == 0, "nfp StartDetection");
CHECK((uint32_t)CALL("nfp.StopDetection", U(handles)) == 0, "nfp StopDetection");
CHECK(CALL("nfp.Finalize", 0) == 0 && (uint32_t)CALL("nfp.GetState", 0) == 0, "nfp finalize");
CALL("err.ShowError", 0x2a8);
CALL("nndiagStartup", 0);
+112 -13
View File
@@ -19,6 +19,7 @@
#include <string.h>
#include <time.h>
#include "amiibo.h"
#include "cfg.h"
#include "fs.h"
#include "host.h"
@@ -266,26 +267,124 @@ static void ov_report_save(Cpu *c) { // Result PlayReport::Save() and Save(con
}
static void ov_result_ok(Cpu *c) { ret_x(c, 0); } // RequestImmediateTransmission, AddInternetConnectionStatus
// nn::nfp: no NFC reader
// nn::nfp: NFC reader & amiibo support
static volatile int32_t nfp_state;
static void ov_nfp_initialize(Cpu *c) { plat_xchg32(&nfp_state, 1); ret_x(c, 0); }
static void ov_nfp_finalize(Cpu *c) { plat_xchg32(&nfp_state, 0); ret_x(c, 0); }
static void ov_nfp_finalize(Cpu *c) {
plat_xchg32(&nfp_state, 0);
amiibo_stop_detection();
amiibo_unmount();
ret_x(c, 0);
}
static void ov_nfp_state(Cpu *c) { ret_x(c, (uint64_t)nfp_state); }
// Result ListDevices(DeviceHandle *out, int *count, int max)
static void ov_nfp_list(Cpu *c) {
void *out = arg_p(c, 0);
int32_t *count = arg_p(c, 1);
if (count) *count = 0;
ret_x(c, NFP_R_DEVICE_NOT_FOUND);
int32_t max = (int32_t)arg_x(c, 2);
if (!amiibo_is_device_present()) {
if (count) *count = 0;
ret_x(c, NFP_R_DEVICE_NOT_FOUND);
return;
}
if (out && max > 0) {
static const uint8_t dev[8] = { 1, 0, 0, 0, 0, 0, 0, 0 };
memcpy(out, dev, sizeof dev);
}
if (count) *count = 1;
ret_x(c, 0);
}
// Result AttachAvailabilityChangeEvent(os::SystemEventType *event)
static void ov_nfp_availability(Cpu *c) {
uint64_t ev = arg_x(c, 0);
if (!ev) rt_fatal("nn::nfp::AttachAvailabilityChangeEvent: null event");
kern_bind_system_event(c, ev, 0);
kern_signal_system_event(ev);
ret_x(c, 0);
}
// DeviceState GetDeviceState(const DeviceHandle &)
static void ov_nfp_device_state(Cpu *c) {
(void)c;
ret_x(c, (uint64_t)amiibo_get_device_state());
}
// Result Mount(const DeviceHandle &, ModelType, MountTarget)
static void ov_nfp_mount(Cpu *c) {
(void)c;
if (!amiibo_has_tag()) {
ret_x(c, NFP_R_DEVICE_NOT_FOUND);
return;
}
amiibo_mount();
ret_x(c, 0);
}
// Result GetNpadId(u32 *npad_id, const DeviceHandle &)
static void ov_nfp_get_npad_id(Cpu *c) {
uint32_t *npad = arg_p(c, 0);
if (npad) *npad = 0; // Handheld / Player 1
ret_x(c, 0);
}
// Result AttachActivateEvent(os::SystemEventType *event, const DeviceHandle &)
static void ov_nfp_attach_activate(Cpu *c) {
uint64_t ev = arg_x(c, 0);
if (ev) {
kern_bind_system_event(c, ev, 0);
if (amiibo_has_tag()) kern_signal_system_event(ev);
}
ret_x(c, 0);
}
// Result AttachDeactivateEvent(os::SystemEventType *event, const DeviceHandle &)
static void ov_nfp_attach_deactivate(Cpu *c) {
uint64_t ev = arg_x(c, 0);
if (ev) {
kern_bind_system_event(c, ev, 0);
}
ret_x(c, 0);
}
// Result StartDetection(const DeviceHandle &)
static void ov_nfp_start_detection(Cpu *c) {
(void)c;
amiibo_start_detection();
ret_x(c, 0);
}
// Result StopDetection(const DeviceHandle &)
static void ov_nfp_stop_detection(Cpu *c) {
(void)c;
amiibo_stop_detection();
ret_x(c, 0);
}
// Result GetTagInfo(TagInfo *out, const DeviceHandle &)
static void ov_nfp_get_tag_info(Cpu *c) {
void *out = arg_p(c, 0);
if (!amiibo_has_tag() && !amiibo_is_mounted()) {
ret_x(c, NFP_R_DEVICE_NOT_FOUND);
return;
}
if (out) amiibo_get_tag_info(out);
ret_x(c, 0);
}
// Result GetModelInfo(ModelInfo *out, const DeviceHandle &)
static void ov_nfp_get_model_info(Cpu *c) {
void *out = arg_p(c, 0);
if (!amiibo_is_mounted() && !amiibo_has_tag()) {
ret_x(c, NFP_R_DEVICE_NOT_FOUND);
return;
}
if (out) amiibo_get_model_info(out);
ret_x(c, 0);
}
static void ov_nfp_no_device(Cpu *c) { ret_x(c, NFP_R_DEVICE_NOT_FOUND); }
static void ov_nfp_device_state(Cpu *c) { ret_x(c, 0); } // DeviceState GetDeviceState(const DeviceHandle &): none
// void err::ShowError(Result): the game's error dialog, logged
static void ov_show_error(Cpu *c) {
@@ -795,14 +894,14 @@ HOST_OVERRIDE("_ZN2nn3nfp8GetStateEv", ov_nfp_state);
HOST_OVERRIDE("_ZN2nn3nfp11ListDevicesEPNS0_12DeviceHandleEPii", ov_nfp_list);
HOST_OVERRIDE("_ZN2nn3nfp29AttachAvailabilityChangeEventEPNS_2os15SystemEventTypeE", ov_nfp_availability);
HOST_OVERRIDE("_ZN2nn3nfp14GetDeviceStateERKNS0_12DeviceHandleE", ov_nfp_device_state);
HOST_OVERRIDE("_ZN2nn3nfp5MountERKNS0_12DeviceHandleENS0_9ModelTypeENS0_11MountTargetE", ov_nfp_no_device);
HOST_OVERRIDE("_ZN2nn3nfp9GetNpadIdEPjRKNS0_12DeviceHandleE", ov_nfp_no_device);
HOST_OVERRIDE("_ZN2nn3nfp19AttachActivateEventEPNS_2os15SystemEventTypeERKNS0_12DeviceHandleE", ov_nfp_no_device);
HOST_OVERRIDE("_ZN2nn3nfp21AttachDeactivateEventEPNS_2os15SystemEventTypeERKNS0_12DeviceHandleE", ov_nfp_no_device);
HOST_OVERRIDE("_ZN2nn3nfp14StartDetectionERKNS0_12DeviceHandleE", ov_nfp_no_device);
HOST_OVERRIDE("_ZN2nn3nfp13StopDetectionERKNS0_12DeviceHandleE", ov_nfp_no_device);
HOST_OVERRIDE("_ZN2nn3nfp10GetTagInfoEPNS0_7TagInfoERKNS0_12DeviceHandleE", ov_nfp_no_device);
HOST_OVERRIDE("_ZN2nn3nfp12GetModelInfoEPNS0_9ModelInfoERKNS0_12DeviceHandleE", ov_nfp_no_device);
HOST_OVERRIDE("_ZN2nn3nfp5MountERKNS0_12DeviceHandleENS0_9ModelTypeENS0_11MountTargetE", ov_nfp_mount);
HOST_OVERRIDE("_ZN2nn3nfp9GetNpadIdEPjRKNS0_12DeviceHandleE", ov_nfp_get_npad_id);
HOST_OVERRIDE("_ZN2nn3nfp19AttachActivateEventEPNS_2os15SystemEventTypeERKNS0_12DeviceHandleE", ov_nfp_attach_activate);
HOST_OVERRIDE("_ZN2nn3nfp21AttachDeactivateEventEPNS_2os15SystemEventTypeERKNS0_12DeviceHandleE", ov_nfp_attach_deactivate);
HOST_OVERRIDE("_ZN2nn3nfp14StartDetectionERKNS0_12DeviceHandleE", ov_nfp_start_detection);
HOST_OVERRIDE("_ZN2nn3nfp13StopDetectionERKNS0_12DeviceHandleE", ov_nfp_stop_detection);
HOST_OVERRIDE("_ZN2nn3nfp10GetTagInfoEPNS0_7TagInfoERKNS0_12DeviceHandleE", ov_nfp_get_tag_info);
HOST_OVERRIDE("_ZN2nn3nfp12GetModelInfoEPNS0_9ModelInfoERKNS0_12DeviceHandleE", ov_nfp_get_model_info);
HOST_OVERRIDE("_ZN2nn3err9ShowErrorENS_6ResultE", ov_show_error);
HOST_OVERRIDE("nndiagStartup", ov_diag_startup);
+272
View File
@@ -0,0 +1,272 @@
// Amiibo / NFC menu page (Dear ImGui): browser and scan controls.
#include <algorithm>
#include <cctype>
#include <filesystem>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <string_view>
#include <vector>
#include "imgui.h"
#include "ui/amiibo_page.h"
extern "C" {
#include "amiibo.h"
#include "cfg.h"
#include "platform/platform.h"
}
namespace fs = std::filesystem;
struct FileEntry {
std::string name;
bool is_dir;
};
static const char kDefaultAmiiboDir[] = "./amiibo";
static std::string g_current_dir = kDefaultAmiiboDir;
static char g_dir_input[512] = "./amiibo";
static std::vector<FileEntry> g_entries;
static int g_selected_entry = -1;
static std::string g_status_msg = "Ready";
static bool iequals(std::string_view a, std::string_view b) {
if (a.size() != b.size()) return false;
for (size_t i = 0; i < a.size(); ++i) {
if (std::tolower(static_cast<unsigned char>(a[i])) !=
std::tolower(static_cast<unsigned char>(b[i]))) {
return false;
}
}
return true;
}
static void set_current_dir(const std::string &path) {
g_current_dir = path;
snprintf(g_dir_input, sizeof(g_dir_input), "%s", g_current_dir.c_str());
cfg_set("TOTK_AMIIBO_DIR", g_current_dir.c_str());
}
static void refresh_dir(void) {
g_entries.clear();
g_selected_entry = -1;
std::error_code ec;
fs::path dir_path(g_current_dir);
// Fall back to "." if directory does not exist or is not a directory
if (!fs::exists(dir_path, ec) || !fs::is_directory(dir_path, ec)) {
if (g_current_dir != ".") {
set_current_dir(".");
dir_path = fs::path(g_current_dir);
}
}
if (!fs::exists(dir_path, ec) || !fs::is_directory(dir_path, ec)) {
g_status_msg = "Cannot open directory: " + g_current_dir;
return;
}
// Add parent navigation if not at root
if (dir_path.has_parent_path() && dir_path != dir_path.parent_path()) {
g_entries.push_back({"..", true});
}
for (const auto &entry : fs::directory_iterator(dir_path, fs::directory_options::skip_permission_denied, ec)) {
if (ec) break;
std::error_code status_ec;
bool is_dir = entry.is_directory(status_ec);
if (status_ec) continue;
std::string filename = entry.path().filename().string();
if (filename.empty() || filename == "." || filename == "..") continue;
if (!is_dir) {
std::string ext = entry.path().extension().string();
if (!iequals(ext, ".bin") && !iequals(ext, ".nfc")) {
continue;
}
}
g_entries.push_back({std::move(filename), is_dir});
}
std::sort(g_entries.begin(), g_entries.end(), [](const FileEntry &a, const FileEntry &b) {
if (a.name == "..") return true;
if (b.name == "..") return false;
if (a.is_dir != b.is_dir) return a.is_dir;
return a.name < b.name;
});
}
void tab_amiibo(float scale) {
static bool s_inited = false;
if (!s_inited) {
const char *cfg_dir = cfg_get("TOTK_AMIIBO_DIR");
if (cfg_dir && *cfg_dir) {
g_current_dir = cfg_dir;
} else {
g_current_dir = kDefaultAmiiboDir;
}
snprintf(g_dir_input, sizeof(g_dir_input), "%s", g_current_dir.c_str());
refresh_dir();
s_inited = true;
}
// Two panes: Left (Directory Browser & Tag List), Right (Amiibo Tag Details & Controls)
const float content_h = ImGui::GetContentRegionAvail().y - 20.0f;
const float left_w = ImGui::GetContentRegionAvail().x * 0.58f;
const float right_w = ImGui::GetContentRegionAvail().x - left_w - ImGui::GetStyle().ItemSpacing.x;
// ---- Left Pane: Explorer & List ----
ImGui::BeginChild("##amiibo_explorer", ImVec2(left_w, content_h), true);
ImGui::TextColored(ImVec4(0.93f, 0.76f, 0.33f, 1.0f), "Amiibo NFC Directory:");
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (ImGui::InputText("##amiibo_dir_input", g_dir_input, sizeof(g_dir_input), ImGuiInputTextFlags_EnterReturnsTrue)) {
set_current_dir(g_dir_input);
refresh_dir();
}
ImGui::Spacing();
if (ImGui::Button("Set Directory")) {
set_current_dir(g_dir_input);
refresh_dir();
}
ImGui::SameLine();
if (ImGui::Button("Default (./amiibo)")) {
set_current_dir(kDefaultAmiiboDir);
refresh_dir();
}
ImGui::SameLine();
if (ImGui::Button("Refresh")) {
refresh_dir();
}
ImGui::Separator();
ImGui::TextDisabled("Select an Amiibo file (.bin / .nfc):");
ImGui::BeginChild("##file_list", ImVec2(0, 0), true);
for (size_t i = 0; i < g_entries.size(); i++) {
const auto &e = g_entries[i];
std::string label = (e.is_dir ? "[DIR] " : " ") + e.name;
bool selected = ((int)i == g_selected_entry);
if (ImGui::Selectable(label.c_str(), selected, ImGuiSelectableFlags_AllowDoubleClick)) {
g_selected_entry = (int)i;
if (e.is_dir) {
if (ImGui::IsMouseDoubleClicked(0) || ImGui::IsKeyPressed(ImGuiKey_GamepadFaceDown)) {
if (e.name == "..") {
fs::path cur(g_current_dir);
if (cur.has_parent_path() && cur != cur.parent_path()) {
set_current_dir(cur.parent_path().string());
} else {
set_current_dir(".");
}
} else {
set_current_dir((fs::path(g_current_dir) / e.name).string());
}
refresh_dir();
break;
}
} else {
std::string full_path = (fs::path(g_current_dir) / e.name).string();
if (ImGui::IsMouseDoubleClicked(0)) {
if (amiibo_scan_and_tap(full_path.c_str())) {
g_status_msg = "Scanned & Tapped: " + e.name;
} else {
g_status_msg = "Error loading " + e.name;
}
}
}
}
}
ImGui::EndChild();
ImGui::EndChild();
ImGui::SameLine();
// ---- Right Pane: Controls & Status ----
ImGui::BeginChild("##amiibo_controls", ImVec2(right_w, content_h), true);
ImGui::TextColored(ImVec4(0.93f, 0.76f, 0.33f, 1.0f), "NFC Reader & Tag Actions");
ImGui::Separator();
AmiiboDeviceState state = amiibo_get_device_state();
const char *state_str = "Initialized";
ImVec4 state_col = ImVec4(0.8f, 0.8f, 0.8f, 1.0f);
switch (state) {
case AMIIBO_DEV_STATE_INITIALIZED: state_str = "Idle / Ready"; break;
case AMIIBO_DEV_STATE_SEARCHING: state_str = "Game Searching for Tag..."; state_col = ImVec4(1.0f, 0.8f, 0.2f, 1.0f); break;
case AMIIBO_DEV_STATE_TAG_FOUND: state_str = "Tag Present / Detected"; state_col = ImVec4(0.3f, 0.9f, 0.3f, 1.0f); break;
case AMIIBO_DEV_STATE_TAG_MOUNTED: state_str = "Tag Mounted (Reading Area)"; state_col = ImVec4(0.2f, 0.9f, 1.0f, 1.0f); break;
case AMIIBO_DEV_STATE_UNAVAILABLE: state_str = "NFC Reader Disabled"; state_col = ImVec4(0.9f, 0.3f, 0.3f, 1.0f); break;
default: break;
}
ImGui::Text("Reader Status: ");
ImGui::SameLine();
ImGui::TextColored(state_col, "%s", state_str);
ImGui::Spacing();
ImGui::Separator();
ImGui::Text("Selected File:");
if (g_selected_entry >= 0 && g_selected_entry < (int)g_entries.size() && !g_entries[g_selected_entry].is_dir) {
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.4f, 1.0f), "%s", g_entries[g_selected_entry].name.c_str());
if (ImGui::Button("Scan / Tap Amiibo", ImVec2(ImGui::GetContentRegionAvail().x, 32 * scale))) {
std::string full_path = (fs::path(g_current_dir) / g_entries[g_selected_entry].name).string();
if (amiibo_scan_and_tap(full_path.c_str())) {
g_status_msg = "Tapped " + g_entries[g_selected_entry].name;
} else {
g_status_msg = "Failed to load dump!";
}
}
} else {
ImGui::TextDisabled("(No file selected)");
ImGui::BeginDisabled();
ImGui::Button("Scan / Tap Amiibo", ImVec2(ImGui::GetContentRegionAvail().x, 32 * scale));
ImGui::EndDisabled();
}
ImGui::Spacing();
if (ImGui::Button("Remove Tag (Pull away)", ImVec2(ImGui::GetContentRegionAvail().x, 28 * scale))) {
amiibo_remove_tag();
g_status_msg = "Tag removed";
}
ImGui::Spacing();
ImGui::Separator();
bool auto_remove = amiibo_get_auto_remove();
if (ImGui::Checkbox("Auto-remove tag after scan (CEMU style)", &auto_remove)) {
amiibo_set_auto_remove(auto_remove);
}
if (auto_remove) {
float delay = amiibo_get_auto_remove_delay_s();
if (ImGui::SliderFloat("Hold duration", &delay, 1.0f, 6.0f, "%.1f s")) {
amiibo_set_auto_remove_delay_s(delay);
}
}
ImGui::Spacing();
ImGui::Separator();
ImGui::Text("Loaded Tag Information:");
if (amiibo_has_tag()) {
const AmiiboInfo *info = amiibo_get_current_info();
ImGui::Text("File: %s", info->filename);
ImGui::Text("Char ID: %02x%02x%02x | Series: %02x",
info->character_id[0], info->character_id[1], info->character_id[2], info->series_id);
ImGui::Text("Amiibo Number: %04x | Type: %02x", info->numbering_id, info->nfp_type);
ImGui::Text("UID: %02x:%02x:%02x:%02x:%02x:%02x:%02x",
info->uuid[0], info->uuid[1], info->uuid[2], info->uuid[3],
info->uuid[4], info->uuid[5], info->uuid[6]);
} else {
ImGui::TextDisabled("No active tag on reader.");
}
ImGui::Spacing();
ImGui::Separator();
ImGui::TextDisabled("Status: %s", g_status_msg.c_str());
ImGui::EndChild();
}
+4
View File
@@ -0,0 +1,4 @@
// Amiibo / NFC menu page (ui/amiibo_page.cpp).
#pragma once
void tab_amiibo(float scale);
+8 -3
View File
@@ -19,10 +19,12 @@
#include "imgui.h"
#include "imgui_internal.h" // SetFocusID, NavCursorVisible
#include "backends/imgui_impl_vulkan.h"
#include "ui/amiibo_page.h"
#include "ui/binds_page.h"
#include "ui/option_rows.h"
extern "C" {
#include "amiibo.h"
#include "cfg.h"
#include "input.h"
#include "input_map.h"
@@ -307,7 +309,7 @@ extern "C" void menu_vk_release(void) {
// TOTK_MENU_TEST_SET=<frame>:<key>=<value>[,<key>=<value>...][;<frame>:...]: cfg_set of each key (TOTK_ prefix
// optional) at that presented frame; changes live settings with no input, menu open or not. totk.ini is written only by
// the pseudo-key SAVE=1 (cfg_save, as a row change does; a failed write shows the menu's save note).
enum { TAB_SCREEN, TAB_GAME, TAB_SOUND, TAB_CONTROLS, TAB_MENU, TAB_ADVANCED, TAB_COUNT };
enum { TAB_SCREEN, TAB_GAME, TAB_SOUND, TAB_CONTROLS, TAB_AMIIBO, TAB_MENU, TAB_ADVANCED, TAB_COUNT };
enum { TEST_PAGE_FRAMES = 30, TEST_SETS = 16 };
struct TestSet { uint64_t frame; char key[64], value[64]; };
static struct {
@@ -764,8 +766,9 @@ static void tab_advanced(float scale) {
}
}
static const UiTextId kTabNames[TAB_COUNT] = {UI_MENU_TAB_SCREEN, UI_MENU_TAB_GAME, UI_MENU_TAB_SOUND,
UI_MENU_TAB_CONTROLS, UI_MENU_TAB_MENU, UI_MENU_TAB_ADVANCED};
static const UiTextId kTabNames[TAB_COUNT] = {UI_MENU_TAB_SCREEN, UI_MENU_TAB_GAME, UI_MENU_TAB_SOUND,
UI_MENU_TAB_CONTROLS, UI_MENU_TAB_AMIIBO, UI_MENU_TAB_MENU,
UI_MENU_TAB_ADVANCED};
static int g_tab; // the tab shown
static int g_tab_request = -1; // select this tab at the next layout; -1 none
static int g_focus_page = -1; // this tab's first row takes the cursor once it is shown; -1 none
@@ -816,6 +819,7 @@ static void layout_menu(uint32_t w, uint32_t h, float scale) {
case TAB_GAME: tab_game(scale); break;
case TAB_SOUND: tab_sound(scale); break;
case TAB_CONTROLS: tab_controls(scale); break;
case TAB_AMIIBO: tab_amiibo(scale); break;
case TAB_MENU: tab_menu(scale); break;
case TAB_ADVANCED: tab_advanced(scale); break;
}
@@ -1097,6 +1101,7 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
if (g_test.next_set < g_test.n_sets && frame >= g_test.sets[g_test.next_set].frame) test_apply_sets(frame);
if (g_perf_save.exchange(0)) cfg_save();
perf_tick(plat_now_ns(), t);
amiibo_tick();
bool open = g_open.load(std::memory_order_relaxed);
if (!open) {
if (g_save_pending) g_save_pending = opt_save_tick(1); // closed: the last change goes to totk.ini now
+2 -2
View File
@@ -28,7 +28,7 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_TITLE] = "Settings",
[UI_MENU_TAB_SCREEN] = "Screen", [UI_MENU_TAB_GAME] = "Game", [UI_MENU_TAB_SOUND] = "Sound",
[UI_MENU_TAB_CONTROLS] = "Controls", [UI_MENU_TAB_MENU] = "Menu", [UI_MENU_TAB_ADVANCED] = "Advanced",
[UI_MENU_TAB_CONTROLS] = "Controls", [UI_MENU_TAB_AMIIBO] = "Amiibo", [UI_MENU_TAB_MENU] = "Menu", [UI_MENU_TAB_ADVANCED] = "Advanced",
[UI_MENU_CONTINUE] = "Continue", [UI_MENU_QUIT] = "Quit game",
[UI_MENU_ON] = "On", [UI_MENU_OFF] = "Off", [UI_MENU_AUTO] = "Automatic", [UI_MENU_DEFAULT_MARK] = "default",
[UI_MENU_AFTER_RESTART] = "after restart", [UI_MENU_SET_BY_ENV] = "set by environment variable",
@@ -271,7 +271,7 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_TITLE] = "Настройки",
[UI_MENU_TAB_SCREEN] = "Экран", [UI_MENU_TAB_GAME] = "Игра", [UI_MENU_TAB_SOUND] = "Звук",
[UI_MENU_TAB_CONTROLS] = "Управление", [UI_MENU_TAB_MENU] = "Меню", [UI_MENU_TAB_ADVANCED] = "Дополнительно",
[UI_MENU_TAB_CONTROLS] = "Управление", [UI_MENU_TAB_AMIIBO] = "Amiibo", [UI_MENU_TAB_MENU] = "Меню", [UI_MENU_TAB_ADVANCED] = "Дополнительно",
[UI_MENU_CONTINUE] = "Продолжить", [UI_MENU_QUIT] = "Выйти из игры",
[UI_MENU_ON] = "Вкл.", [UI_MENU_OFF] = "Выкл.", [UI_MENU_AUTO] = "Автоматически",
[UI_MENU_DEFAULT_MARK] = "по умолчанию",
+2 -2
View File
@@ -14,8 +14,8 @@ typedef enum {
// Menu: window, tabs, bottom row. UI_MENU_FIRST..UI_MENU_LAST_ID carry English and Russian texts.
UI_MENU_FIRST,
UI_MENU_TITLE = UI_MENU_FIRST,
UI_MENU_TAB_SCREEN, UI_MENU_TAB_GAME, UI_MENU_TAB_SOUND, UI_MENU_TAB_CONTROLS, UI_MENU_TAB_MENU,
UI_MENU_TAB_ADVANCED,
UI_MENU_TAB_SCREEN, UI_MENU_TAB_GAME, UI_MENU_TAB_SOUND, UI_MENU_TAB_CONTROLS, UI_MENU_TAB_AMIIBO,
UI_MENU_TAB_MENU, UI_MENU_TAB_ADVANCED,
UI_MENU_CONTINUE, UI_MENU_QUIT,
UI_MENU_ON, UI_MENU_OFF, UI_MENU_AUTO, UI_MENU_DEFAULT_MARK, // "default" beside the default value
UI_MENU_AFTER_RESTART, // note on a setting that is read at start