diff --git a/soh/soh/Network/Anchor/Packets/GiveItem.cpp b/soh/soh/Network/Anchor/Packets/GiveItem.cpp index f957eef0226..814637551ab 100644 --- a/soh/soh/Network/Anchor/Packets/GiveItem.cpp +++ b/soh/soh/Network/Anchor/Packets/GiveItem.cpp @@ -8,6 +8,9 @@ #include "soh/Enhancements/item-tables/ItemTableManager.h" #include "soh/OTRGlobals.h" +#include +#include + extern "C" { #include "functions.h" extern PlayState* gPlayState; @@ -37,6 +40,7 @@ void Anchor::SendPacket_GiveItem(u16 modId, s16 getItemId) { nlohmann::json payload; payload["type"] = GIVE_ITEM; payload["targetTeamId"] = CVarGetString(CVAR_REMOTE_ANCHOR("TeamId"), "default"); + payload["name"] = CVarGetString(CVAR_REMOTE_ANCHOR("Name"), ""); payload["addToQueue"] = true; payload["modId"] = modId; payload["getItemId"] = getItemId; @@ -75,6 +79,36 @@ void Anchor::HandlePacket_GiveItem(nlohmann::json payload) { } } + if (getItemEntry.modIndex == MOD_RANDOMIZER) { + if (getItemEntry.getItemId == RG_TRIFORCE_PIECE) { + Notification::Emit({ .prefix = payload["name"], .message = "Triforce Piece" }); + + std::string filename = Ship::Context::GetPathRelativeToAppDirectory("cheesehunt.json"); + nlohmann::json saveFile; + std::ifstream inputFile(filename); + if (inputFile.is_open()) { + inputFile >> saveFile; + inputFile.close(); + } + + std::string playerName = payload["name"].get(); + if (saveFile.contains(playerName)) { + int32_t currentCount = saveFile[playerName]["count"].get(); + currentCount++; + + saveFile[playerName]["count"] = currentCount; + } else { + saveFile[playerName]["count"] = 1; + } + + std::ofstream outputFile(filename); + if (outputFile.is_open()) { + outputFile << saveFile.dump(4); + outputFile.close(); + } + } + } + // Full heal if getting a heart container or piece if (getItemEntry.gid == GID_HEART_CONTAINER || getItemEntry.gid == GID_HEART_PIECE) { gSaveContext.healthAccumulator = 0x140;