Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/Dialog/PSPNpSigninDialog.cpp
5663 views
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include <algorithm>
19
#include "Common/TimeUtil.h"
20
#include "Common/Data/Text/I18n.h"
21
#include "Common/Serialize/Serializer.h"
22
#include "Common/Serialize/SerializeFuncs.h"
23
#include "Core/MemMapHelpers.h"
24
#include "Core/Util/PPGeDraw.h"
25
#include "Core/HLE/sceKernelMemory.h"
26
#include "Core/HLE/sceCtrl.h"
27
#include "Core/HLE/sceUtility.h"
28
#include "Core/HLE/sceNp.h"
29
#include "Core/HLE/ErrorCodes.h"
30
#include "Core/Dialog/PSPNpSigninDialog.h"
31
#include "Common/Data/Encoding/Utf8.h"
32
#include "Core/Reporting.h"
33
34
// Needs testing.
35
const static int NP_INIT_DELAY_US = 200000;
36
const static int NP_SHUTDOWN_DELAY_US = 501000;
37
const static int NP_RUNNING_DELAY_US = 1000000; // faked delay to simulate signin process to give chance for players to read the text on the dialog
38
39
int PSPNpSigninDialog::Init(u32 paramAddr) {
40
// Already running
41
if (ReadStatus() != SCE_UTILITY_STATUS_NONE)
42
return SCE_ERROR_UTILITY_INVALID_STATUS;
43
44
requestAddr = paramAddr;
45
int size = Memory::Read_U32(paramAddr);
46
memset(&request, 0, sizeof(request));
47
// Only copy the right size to support different request format
48
Memory::Memcpy(&request, paramAddr, size);
49
50
WARN_LOG_REPORT_ONCE(PSPNpSigninDialogInit, Log::sceNet, "NpSignin Init Params: %08x, %08x, %08x, %08x", request.npSigninStatus, request.unknown1, request.unknown2, request.unknown3);
51
52
ChangeStatusInit(NP_INIT_DELAY_US);
53
54
// Eat any keys pressed before the dialog inited.
55
UpdateButtons();
56
InitCommon();
57
58
//npSigninResult = -1;
59
startTime = (u64)(time_now_d() * 1000000.0);
60
step = 0;
61
62
StartFade(true);
63
return 0;
64
}
65
66
void PSPNpSigninDialog::DrawBanner() {
67
PPGeDrawRect(0, 0, 480, 22, CalcFadedColor(0x65636358));
68
69
PPGeStyle textStyle = FadedStyle(PPGeAlign::BOX_VCENTER, 0.6f);
70
textStyle.hasShadow = false;
71
72
// TODO: Draw a hexagon icon
73
PPGeDrawImage(10, 5, 11.0f, 10.0f, 1, 10, 1, 10, 10, 10, FadedImageStyle());
74
auto di = GetI18NCategory(I18NCat::DIALOG);
75
PPGeDrawText(di->T("Sign In"), 31, 10, textStyle);
76
}
77
78
void PSPNpSigninDialog::DrawIndicator() {
79
// TODO: Draw animated circle as processing indicator
80
PPGeDrawImage(456, 248, 20.0f, 20.0f, 1, 10, 1, 10, 10, 10, FadedImageStyle());
81
}
82
83
void PSPNpSigninDialog::DrawLogo() {
84
// TODO: Draw OpenDNAS logo
85
PPGeDrawImage(416, 22, 64.0f, 64.0f, 1, 10, 1, 10, 64, 64, FadedImageStyle());
86
}
87
88
int PSPNpSigninDialog::Update(int animSpeed) {
89
if (ReadStatus() != SCE_UTILITY_STATUS_RUNNING) {
90
return SCE_ERROR_UTILITY_INVALID_STATUS;
91
}
92
93
UpdateButtons();
94
UpdateCommon();
95
auto err = GetI18NCategory(I18NCat::ERRORS);
96
u64 now = (u64)(time_now_d() * 1000000.0);
97
98
if (request.npSigninStatus == NP_SIGNIN_STATUS_NONE) {
99
auto di = GetI18NCategory(I18NCat::DIALOG);
100
UpdateFade(animSpeed);
101
StartDraw();
102
103
PPGeDrawRect(0, 0, 480, 272, CalcFadedColor(0xC0C8B2AC));
104
DrawBanner();
105
DrawIndicator();
106
107
// TODO: Not sure what should happen here.. may be something like this https://pastebin.com/1eW48zBb ? but we can do test on Open DNAS Server later https://dnas.hashsploit.net/us-gw/
108
// DNAS dialog
109
if (step >= 2 && now - startTime > NP_RUNNING_DELAY_US) {
110
DrawLogo();
111
DisplayMessage2(di->T("PleaseWait", "Please wait..."));
112
step++;
113
}
114
// Signin dialog
115
else {
116
// Skipping the Select Connection screen since we only have 1 fake profile
117
DisplayMessage2(di->T("SigninPleaseWait", "Signing in...\nPlease wait."));
118
}
119
DisplayButtons(DS_BUTTON_CANCEL, di->T("Cancel"));
120
121
if (step >= 2 && now - startTime > NP_RUNNING_DELAY_US*2) {
122
if (pendingStatus != SCE_UTILITY_STATUS_FINISHED) {
123
StartFade(false);
124
ChangeStatus(SCE_UTILITY_STATUS_FINISHED, NP_SHUTDOWN_DELAY_US);
125
step++;
126
}
127
}
128
129
else if (step == 1 && now - startTime > NP_RUNNING_DELAY_US) {
130
// Switch to the next message (with DNAS logo)
131
StartFade(true);
132
step++;
133
}
134
135
else if (step == 0) {
136
/*if (npAuthResult < 0 && request.NpSigninData.IsValid()) {
137
npAuthResult = sceNpAuthCreateStartRequest(request.NpSigninData->paramAddr);
138
}*/
139
step++;
140
}
141
142
if (/*npAuthResult >= 0 &&*/ IsButtonPressed(cancelButtonFlag)) {
143
StartFade(false);
144
//sceNpAuthAbortRequest(npAuthResult);
145
//sceNpAuthDestroyRequest(npAuthResult);
146
ChangeStatus(SCE_UTILITY_STATUS_FINISHED, NP_SHUTDOWN_DELAY_US);
147
request.common.result = SCE_UTILITY_DIALOG_RESULT_ABORT;
148
request.npSigninStatus = NP_SIGNIN_STATUS_CANCELED;
149
//step = 0;
150
}
151
152
EndDraw();
153
}
154
155
if (ReadStatus() == SCE_UTILITY_STATUS_FINISHED || pendingStatus == SCE_UTILITY_STATUS_FINISHED) {
156
npSigninState = NP_SIGNIN_STATUS_SUCCESS;
157
__RtcTimeOfDay(&npSigninTimestamp);
158
request.npSigninStatus = npSigninState;
159
}
160
return 0;
161
}
162
163
int PSPNpSigninDialog::Shutdown(bool force) {
164
if (ReadStatus() != SCE_UTILITY_STATUS_FINISHED && !force)
165
return SCE_ERROR_UTILITY_INVALID_STATUS;
166
167
PSPDialog::Shutdown(force);
168
if (!force) {
169
ChangeStatusShutdown(NP_SHUTDOWN_DELAY_US);
170
}
171
172
// FIXME: This should probably be done within FinishShutdown to prevent some games (ie. UNO) from progressing further while the Dialog is still being faded-out, since we can't override non-virtual method... so here is the closes one to FinishShutdown.
173
if (Memory::IsValidAddress(requestAddr)) // Need to validate first to prevent Invalid address when the game is being Shutdown/Exited to menu
174
Memory::Memcpy(requestAddr, &request, request.common.size, "NpSigninDialogParam");
175
176
return 0;
177
}
178
179
void PSPNpSigninDialog::DoState(PointerWrap &p) {
180
PSPDialog::DoState(p);
181
182
auto s = p.Section("PSPNpSigninDialog", 1, 1);
183
if (!s)
184
return;
185
186
Do(p, request);
187
Do(p, step);
188
//Do(p, npSigninResult);
189
190
if (p.mode == p.MODE_READ) {
191
startTime = 0;
192
}
193
}
194
195
pspUtilityDialogCommon* PSPNpSigninDialog::GetCommonParam()
196
{
197
return &request.common;
198
}
199
200