From 139ea16fda284d304d0327eb09d3b6a4a96ea936 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 9 Sep 2023 11:51:36 +0300 Subject: [PATCH] Captain Toad now thinks we load amiibos --- include/services/nfc.hpp | 4 +++ src/core/services/nfc.cpp | 53 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/include/services/nfc.hpp b/include/services/nfc.hpp index 151d8408..8eea8a41 100644 --- a/include/services/nfc.hpp +++ b/include/services/nfc.hpp @@ -45,13 +45,17 @@ class NFCService { void communicationGetResult(u32 messagePointer); void communicationGetStatus(u32 messagePointer); void initialize(u32 messagePointer); + void getModelInfo(u32 messagePointer); + void getTagInfo(u32 messagePointer); void getTagInRangeEvent(u32 messagePointer); void getTagOutOfRangeEvent(u32 messagePointer); void getTagState(u32 messagePointer); + void loadAmiiboPartially(u32 messagePointer); void shutdown(u32 messagePointer); void startCommunication(u32 messagePointer); void startTagScanning(u32 messagePointer); void stopCommunication(u32 messagePointer); + void stopTagScanning(u32 messagePointer); public: NFCService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {} diff --git a/src/core/services/nfc.cpp b/src/core/services/nfc.cpp index c0ed52c6..2ad20910 100644 --- a/src/core/services/nfc.cpp +++ b/src/core/services/nfc.cpp @@ -10,11 +10,15 @@ namespace NFCCommands { StartCommunication = 0x00030000, StopCommunication = 0x00040000, StartTagScanning = 0x00050040, + StopTagScanning = 0x00060000, GetTagInRangeEvent = 0x000B0000, GetTagOutOfRangeEvent = 0x000C0000, GetTagState = 0x000D0000, CommunicationGetStatus = 0x000F0000, + GetTagInfo = 0x00110000, CommunicationGetResult = 0x00120000, + LoadAmiiboPartially = 0x001A0000, + GetModelInfo = 0x001B0000, }; } @@ -34,27 +38,28 @@ void NFCService::handleSyncRequest(u32 messagePointer) { case NFCCommands::CommunicationGetResult: communicationGetResult(messagePointer); break; case NFCCommands::CommunicationGetStatus: communicationGetStatus(messagePointer); break; case NFCCommands::Initialize: initialize(messagePointer); break; + case NFCCommands::GetModelInfo: getModelInfo(messagePointer); break; + case NFCCommands::GetTagInfo: getTagInfo(messagePointer); break; case NFCCommands::GetTagInRangeEvent: getTagInRangeEvent(messagePointer); break; case NFCCommands::GetTagOutOfRangeEvent: getTagOutOfRangeEvent(messagePointer); break; case NFCCommands::GetTagState: getTagState(messagePointer); break; + case NFCCommands::LoadAmiiboPartially: loadAmiiboPartially(messagePointer); break; case NFCCommands::Shutdown: shutdown(messagePointer); break; case NFCCommands::StartCommunication: startCommunication(messagePointer); break; case NFCCommands::StartTagScanning: startTagScanning(messagePointer); break; case NFCCommands::StopCommunication: stopCommunication(messagePointer); break; + case NFCCommands::StopTagScanning: stopTagScanning(messagePointer); break; default: Helpers::panic("NFC service requested. Command: %08X\n", command); } } bool NFCService::loadAmiibo(const std::filesystem::path& path) { - IOFile file(path, "rb"); - if (!initialized || tagStatus != TagStatus::Scanning) { Helpers::warn("It's not the correct time to load an amiibo! Make sure to load amiibi when the game is searching for one!"); - file.close(); - return false; } + IOFile file(path, "rb"); if (!file.isOpen()) { printf("Failed to open Amiibo file"); file.close(); @@ -185,12 +190,28 @@ void NFCService::startCommunication(u32 messagePointer) { void NFCService::startTagScanning(u32 messagePointer) { log("NFC::StartTagScanning\n"); + if (!initialized) { + Helpers::warn("Scanning for NFC tags before NFC service is initialized"); + } + tagStatus = TagStatus::Scanning; mem.write32(messagePointer, IPC::responseHeader(0x5, 1, 0)); mem.write32(messagePointer + 4, Result::Success); } +void NFCService::stopTagScanning(u32 messagePointer) { + log("NFC::StopTagScanning\n"); + if (!initialized) { + Helpers::warn("Stopping scanning for NFC tags before NFC service is initialized"); + } + + tagStatus = TagStatus::Initialized; + + mem.write32(messagePointer, IPC::responseHeader(0x6, 1, 0)); + mem.write32(messagePointer + 4, Result::Success); +} + void NFCService::stopCommunication(u32 messagePointer) { log("NFC::StopCommunication\n"); adapterStatus = Old3DSAdapterStatus::InitializationComplete; @@ -198,4 +219,28 @@ void NFCService::stopCommunication(u32 messagePointer) { mem.write32(messagePointer, IPC::responseHeader(0x4, 1, 0)); mem.write32(messagePointer + 4, Result::Success); +} + +void NFCService::getTagInfo(u32 messagePointer) { + log("NFC::GetTagInfo\n"); + Helpers::warn("Unimplemented NFC::GetTagInfo"); + + mem.write32(messagePointer, IPC::responseHeader(0x11, 12, 0)); + mem.write32(messagePointer + 4, Result::Success); +} + +void NFCService::loadAmiiboPartially(u32 messagePointer) { + log("NFC::LoadAmiiboPartially\n"); + Helpers::warn("Unimplemented NFC::LoadAmiiboPartially"); + + mem.write32(messagePointer, IPC::responseHeader(0x1A, 1, 0)); + mem.write32(messagePointer + 4, Result::Success); +} + +void NFCService::getModelInfo(u32 messagePointer) { + log("NFC::GetModelInfo\n"); + Helpers::warn("Unimplemented NFC::GetModelInfo"); + + mem.write32(messagePointer, IPC::responseHeader(0x1B, 14, 0)); + mem.write32(messagePointer + 4, Result::Success); } \ No newline at end of file