From fa2b8b7d4738e5ee098fc105adc60e10356dd410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Mon, 28 Sep 2026 03:39:31 +0200 Subject: Move code to the TUs that match link order and rename files Rename classes and files so that they sort where their code is linked, and move code that is linked inside another TU into that TU's file. | Old | New | TU start | |---|---|---| | ActorAreaInOutSendMessage | AreaInOutSendMessage | 0x710009fa64 | | AreaTagAction | AreaActionBase | 0x7100e21e64 | | sndResource.{h,cpp} | sndSound.{h,cpp} | | | Code | From | To | |---|---|---| | SoundMgr | sndMgr.h | sndSound.h | | PlayReport | PlayReportMgr.cpp | PlayReport.cpp | | PlayReport::addPlayTimes, addPosition | PlayReportMgr.cpp | ProductReporter.cpp | (AI assisted using Claude Fable 5.1 and Claude Opus 5.5) --- src/KingSystem/System/PlayReport.cpp | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/KingSystem/System/PlayReport.cpp (limited to 'src/KingSystem/System/PlayReport.cpp') diff --git a/src/KingSystem/System/PlayReport.cpp b/src/KingSystem/System/PlayReport.cpp new file mode 100644 index 00000000..1ff33d08 --- /dev/null +++ b/src/KingSystem/System/PlayReport.cpp @@ -0,0 +1,77 @@ +#include +#include +#include "KingSystem/System/Account.h" +#include "KingSystem/System/PlayReportMgr.h" +#include "KingSystem/System/ProductReporter.h" + +namespace ksys { + +bool PlayReport::setEventId(sead::BufferedSafeString& event_id) { + if (!mHasNinPrepoReport) + return false; + + event_id.replaceCharList("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"); + return mNinPlayReport->SetEventId(event_id.cstr()).IsSuccess(); +} + +[[gnu::noinline]] bool PlayReport::add(const sead::FixedSafeString<48>& key, u32 value) { + return mHasNinPrepoReport && mNinPlayReport->Add(key.cstr(), s64(value)).IsSuccess(); +} + +[[gnu::noinline]] bool PlayReport::add(const sead::FixedSafeString<48>& key, s32 value) { + return mHasNinPrepoReport && mNinPlayReport->Add(key.cstr(), s64(value)).IsSuccess(); +} + +[[gnu::noinline]] bool PlayReport::add(const sead::FixedSafeString<48>& key, f32 value) { + return mHasNinPrepoReport && mNinPlayReport->Add(key.cstr(), value).IsSuccess(); +} + +[[gnu::noinline]] bool PlayReport::add(const sead::FixedSafeString<48>& key, + const sead::SafeString& value) { + return mHasNinPrepoReport && mNinPlayReport->Add(key.cstr(), value.cstr()).IsSuccess(); +} + +bool PlayReport::save() { + if (!mHasNinPrepoReport) + return false; + + nn::account::Uid uid; + Account::instance()->getUserId(&uid); + if (uid.IsValid()) { + static_cast(mNinPlayReport->GetCount()); + return mNinPlayReport->Save(uid).IsSuccess(); + } + static_cast(ProductReporter::getSomeBool()); + static_cast(mNinPlayReport->GetCount()); + return mNinPlayReport->Save().IsSuccess(); +} + +void PlayReport::init(s32 num_entries, sead::Heap* heap) { + if (mHasNinPrepoReport) + return; + + auto* report = new (heap) nn::prepo::PlayReport; + const u32 buffer_size = nn::prepo::PlayReport::CalcBufferSize(num_entries); + mNinPlayReport = report; + if (buffer_size > 0 && mBuffer.tryAllocBuffer(buffer_size, heap)) { + mNinPlayReport->SetBuffer(mBuffer.getBufferPtr(), buffer_size); + mHasNinPrepoReport = true; + } +} + +PlayReport::~PlayReport() { + if (!mHasNinPrepoReport) + return; + + if (mNinPlayReport) { + delete mNinPlayReport; + mNinPlayReport = nullptr; + } + + if (mHasNinPrepoReport) + mBuffer.freeBuffer(); + + mHasNinPrepoReport = false; +} + +} // namespace ksys -- cgit v1.2.3