1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
#include "KingSystem/System/PlayReportMgr.h"
#include <nn/account.h>
#include <nn/prepo.h>
#include "KingSystem/System/Account.h"
#include "KingSystem/System/ProductReporter.h"
namespace ksys {
SEAD_SINGLETON_DISPOSER_IMPL(PlayReportMgr)
PlayReportMgr::~PlayReportMgr() {
if (mReporter)
delete mReporter;
}
void PlayReportMgr::calc() {
if (!_30 && mReporter)
mReporter->updateTimers();
}
void PlayReportMgr::reportDebug(const sead::SafeString& message, const sead::SafeString& data) {
// Stubbed in release builds
}
bool PlayReportMgr::auto0() const {
return true;
}
PlayerTrackReporter* PlayReportMgr::getPlayerTrackReporter() const {
if (!mReporter)
return nullptr;
return mReporter->getPlayerTrackReporter();
}
void PlayReportMgr::setPlayerTrackReporter28() {
if (auto* reporter = getPlayerTrackReporter())
reporter->_28 = true;
}
void PlayReportMgr::setPlayerTrackReporter29() {
if (auto* reporter = getPlayerTrackReporter())
reporter->_29 = true;
}
void PlayReportMgr::setPlayerTrackReporter30() {
if (auto* reporter = getPlayerTrackReporter())
reporter->_30 = true;
}
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();
}
void PlayReport::addPlayTimes() {
if (!gdt::Manager::instance())
return;
if (!PlayReportMgr::instance())
return;
if (!PlayReportMgr::instance()->getReporter())
return;
s32 playTime =
PlayReportMgr::instance()->getReporter()->getS32(PlayReportKey::PlayReport_PlayTime);
s32 allPlayTime =
PlayReportMgr::instance()->getReporter()->getS32(PlayReportKey::PlayReport_AllPlayTime);
add(sead::SafeString("PlayTime"), u32(playTime));
add(sead::SafeString("AllPlayTime"), u32(allPlayTime));
}
void PlayReport::addPosition(const sead::Vector2f& position) {
add(sead::SafeString("PosX"), position.x);
add(sead::SafeString("PosZ"), position.y);
}
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
|