summaryrefslogtreecommitdiff
path: root/src/KingSystem/System/PlayReport.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2026-09-28 03:39:31 +0200
committerLéo Lam <leo@leolam.fr>2026-10-13 01:53:08 +0200
commitfa2b8b7d4738e5ee098fc105adc60e10356dd410 (patch)
tree2c8e3a8180401385f6e24c1e26ac58ef839d30c6 /src/KingSystem/System/PlayReport.cpp
parentb26086477c7d8897c76e328c89d718b3c02a9ae9 (diff)
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)
Diffstat (limited to 'src/KingSystem/System/PlayReport.cpp')
-rw-r--r--src/KingSystem/System/PlayReport.cpp77
1 files changed, 77 insertions, 0 deletions
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 <nn/account.h>
+#include <nn/prepo.h>
+#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<void>(mNinPlayReport->GetCount());
+ return mNinPlayReport->Save(uid).IsSuccess();
+ }
+ static_cast<void>(ProductReporter::getSomeBool());
+ static_cast<void>(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