Captain Toad now thinks we load amiibos

This commit is contained in:
wheremyfoodat 2023-09-09 11:51:36 +03:00
parent 5930a3d843
commit 139ea16fda
2 changed files with 53 additions and 4 deletions

View file

@ -45,13 +45,17 @@ class NFCService {
void communicationGetResult(u32 messagePointer); void communicationGetResult(u32 messagePointer);
void communicationGetStatus(u32 messagePointer); void communicationGetStatus(u32 messagePointer);
void initialize(u32 messagePointer); void initialize(u32 messagePointer);
void getModelInfo(u32 messagePointer);
void getTagInfo(u32 messagePointer);
void getTagInRangeEvent(u32 messagePointer); void getTagInRangeEvent(u32 messagePointer);
void getTagOutOfRangeEvent(u32 messagePointer); void getTagOutOfRangeEvent(u32 messagePointer);
void getTagState(u32 messagePointer); void getTagState(u32 messagePointer);
void loadAmiiboPartially(u32 messagePointer);
void shutdown(u32 messagePointer); void shutdown(u32 messagePointer);
void startCommunication(u32 messagePointer); void startCommunication(u32 messagePointer);
void startTagScanning(u32 messagePointer); void startTagScanning(u32 messagePointer);
void stopCommunication(u32 messagePointer); void stopCommunication(u32 messagePointer);
void stopTagScanning(u32 messagePointer);
public: public:
NFCService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {} NFCService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {}

View file

@ -10,11 +10,15 @@ namespace NFCCommands {
StartCommunication = 0x00030000, StartCommunication = 0x00030000,
StopCommunication = 0x00040000, StopCommunication = 0x00040000,
StartTagScanning = 0x00050040, StartTagScanning = 0x00050040,
StopTagScanning = 0x00060000,
GetTagInRangeEvent = 0x000B0000, GetTagInRangeEvent = 0x000B0000,
GetTagOutOfRangeEvent = 0x000C0000, GetTagOutOfRangeEvent = 0x000C0000,
GetTagState = 0x000D0000, GetTagState = 0x000D0000,
CommunicationGetStatus = 0x000F0000, CommunicationGetStatus = 0x000F0000,
GetTagInfo = 0x00110000,
CommunicationGetResult = 0x00120000, CommunicationGetResult = 0x00120000,
LoadAmiiboPartially = 0x001A0000,
GetModelInfo = 0x001B0000,
}; };
} }
@ -34,27 +38,28 @@ void NFCService::handleSyncRequest(u32 messagePointer) {
case NFCCommands::CommunicationGetResult: communicationGetResult(messagePointer); break; case NFCCommands::CommunicationGetResult: communicationGetResult(messagePointer); break;
case NFCCommands::CommunicationGetStatus: communicationGetStatus(messagePointer); break; case NFCCommands::CommunicationGetStatus: communicationGetStatus(messagePointer); break;
case NFCCommands::Initialize: initialize(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::GetTagInRangeEvent: getTagInRangeEvent(messagePointer); break;
case NFCCommands::GetTagOutOfRangeEvent: getTagOutOfRangeEvent(messagePointer); break; case NFCCommands::GetTagOutOfRangeEvent: getTagOutOfRangeEvent(messagePointer); break;
case NFCCommands::GetTagState: getTagState(messagePointer); break; case NFCCommands::GetTagState: getTagState(messagePointer); break;
case NFCCommands::LoadAmiiboPartially: loadAmiiboPartially(messagePointer); break;
case NFCCommands::Shutdown: shutdown(messagePointer); break; case NFCCommands::Shutdown: shutdown(messagePointer); break;
case NFCCommands::StartCommunication: startCommunication(messagePointer); break; case NFCCommands::StartCommunication: startCommunication(messagePointer); break;
case NFCCommands::StartTagScanning: startTagScanning(messagePointer); break; case NFCCommands::StartTagScanning: startTagScanning(messagePointer); break;
case NFCCommands::StopCommunication: stopCommunication(messagePointer); break; case NFCCommands::StopCommunication: stopCommunication(messagePointer); break;
case NFCCommands::StopTagScanning: stopTagScanning(messagePointer); break;
default: Helpers::panic("NFC service requested. Command: %08X\n", command); default: Helpers::panic("NFC service requested. Command: %08X\n", command);
} }
} }
bool NFCService::loadAmiibo(const std::filesystem::path& path) { bool NFCService::loadAmiibo(const std::filesystem::path& path) {
IOFile file(path, "rb");
if (!initialized || tagStatus != TagStatus::Scanning) { 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!"); 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; return false;
} }
IOFile file(path, "rb");
if (!file.isOpen()) { if (!file.isOpen()) {
printf("Failed to open Amiibo file"); printf("Failed to open Amiibo file");
file.close(); file.close();
@ -185,12 +190,28 @@ void NFCService::startCommunication(u32 messagePointer) {
void NFCService::startTagScanning(u32 messagePointer) { void NFCService::startTagScanning(u32 messagePointer) {
log("NFC::StartTagScanning\n"); log("NFC::StartTagScanning\n");
if (!initialized) {
Helpers::warn("Scanning for NFC tags before NFC service is initialized");
}
tagStatus = TagStatus::Scanning; tagStatus = TagStatus::Scanning;
mem.write32(messagePointer, IPC::responseHeader(0x5, 1, 0)); mem.write32(messagePointer, IPC::responseHeader(0x5, 1, 0));
mem.write32(messagePointer + 4, Result::Success); 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) { void NFCService::stopCommunication(u32 messagePointer) {
log("NFC::StopCommunication\n"); log("NFC::StopCommunication\n");
adapterStatus = Old3DSAdapterStatus::InitializationComplete; adapterStatus = Old3DSAdapterStatus::InitializationComplete;
@ -198,4 +219,28 @@ void NFCService::stopCommunication(u32 messagePointer) {
mem.write32(messagePointer, IPC::responseHeader(0x4, 1, 0)); mem.write32(messagePointer, IPC::responseHeader(0x4, 1, 0));
mem.write32(messagePointer + 4, Result::Success); 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);
} }