aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/PS3/4JLibs/STO_TitleSmallStorage.cpp
blob: bb7c88c7e5f061b6e980788aba441417b0bf91bf (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include "stdafx.h"


#include <stdlib.h>
#include <string.h>
#include <cell/l10n.h>
#include <cell/pad.h>
#include <cell/cell_fs.h>
#include <sys/process.h>
#include <sys/ppu_thread.h>
#include <cell/sysmodule.h>
#include <cell/rtc.h>

#include <libsn.h>

#include <sysutil/sysutil_common.h>
#include <sysutil/sysutil_sysparam.h>
#include <sysutil/sysutil_savedata.h>

#include "STO_TitleSmallStorage.h"
#include "../Passphrase/ps3__np_conf.h"



#if 0

int32_t	CTSS::TssSizeCheck(size_t	size)
{
	printf("=======Tss Data size = %d\n", size);

	//E Recommendation: The data's size should be checked against for the server operation mistake.
	//E If it is necessary, implement size check based on your data format, please.

	if (size == 0)
	{
		printf("Tss File size is 0 byte. Maybe, data isn't set on the server.\n\n");
		printf("\tThe data is set with scp. The account is generable in PS3 Developer Network.\n");
		printf("\tThere are three server environments. for development, environment for test, and product.\n");
	}
	return 0;
}

int32_t	CTSS::TssHashCheck(void *data, size_t size)
{
	//E Recommendation: The data format should be include it's hash against for operation mistakes and crack.
	//E If it is necessary, implement hash check based on your data format, please.
	return 0;
}

int32_t	CTSS::TssVersionCheck(void *data, size_t size)
{
	//E Recommendation: The data format should be include it's version for changes of the format.
	//E If it is necessary, implement version check based on your data format, please.
	return 0;
}

int32_t CTSS::doLookupTitleSmallStorage(void)
{
	int32_t ret = 0;
	int32_t transId = 0;
	void *data=nullptr;
	size_t dataSize=0;

	SceNpId npId;
	ret = sceNpManagerGetNpId(&npId);
	if(ret < 0){
		return ret;
	}
	
	ret = sceNpLookupInit();
	if (ret < 0) 
	{
		printf("sceNpLookupInit() failed. ret = 0x%x\n", ret);
		goto error;
	}
	ret = sceNpTusInit(0);
	if (ret < 0) 
	{
		printf("sceNpTusInit() failed. ret = 0x%x\n", ret);
		goto error;
	}

	ret = sceNpLookupCreateTitleCtx(&s_npCommunicationId, &npId);
	if (ret < 0) 
	{
		printf("sceNpLookupCreateTitleCtx() failed. ret = 0x%x\n", ret);
		goto error;
	}
	m_lookupTitleCtxId = ret;

	ret = sceNpTusCreateTitleCtx(&s_npCommunicationId, &s_npCommunicationPassphrase, &npId);
	if (ret < 0) 
	{
		printf("sceNpTusCreateTitleCtx() failed. ret = 0x%x\n", ret);
		goto error;
	}
	printf("sceNpTusCreateTitleCtx() return %x\n", ret);
	m_tusTitleCtxId = ret;

	//memset(&npclient_info, 0x00, sizeof(npclient_info));

	data = malloc(SCE_NET_NP_TSS_MAX_SIZE);
	if (data == nullptr)
	{
		printf("out of memory: can't allocate memory for titleSmallStorage\n");
		ret = -1;
		goto error;
	}
	memset(data, 0x00, SCE_NET_NP_TSS_MAX_SIZE);

	ret = sceNpLookupCreateTransactionCtx(m_lookupTitleCtxId);
	if (ret < 0) 
	{
		printf("sceNpLookupCreateTransactionCtx() failed. ret = 0x%x\n", ret);
		goto error;
	}
	transId = ret;


// 	ret = sceNpLookupTitleSmallStorage(transId, 
// 		data,
// 		SCE_NET_NP_TSS_MAX_SIZE,
// 		&dataSize,
// 		nullptr);
// 	if (ret < 0)
// 	{
// 		printf("sceNpLookupTitleSmallStorage() failed. ret = 0x%x\n", ret);
// 		goto error;
// 	}
// 
// 	ret = TssSizeCheck(dataSize);
// 	if (ret < 0)
// 	{
// 		goto error;
// 	}
// 	ret = TssHashCheck(data, dataSize);
// 	if (ret < 0)
// 	{
// 		goto error;
// 	}
// 	ret = TssVersionCheck(data, dataSize);
// 	if (ret < 0)
// 	{
// 		goto error;
// 	}

/*
	// Process communication
	void *data;
	size_t dataSize;
	SceNpTssSlotId slotId=SLOTID;
	SceNpTssDataStatus dataStatus;
	const char *ptr =nullptr;
	size_t recvdSize=0;
	size_t totalSize=0;
	size_t recvSize=0;

	do {
		ret = sceNpTssGetData(
			transId,
			slotId,
			&dataStatus,
			sizeof(SceNpTssDataStatus),
			ptr,
			recvSize,
			nullptr);
		if (ret < 0) 
		{
			// Error handling
			goto error;
		}
		if (dataStatus.contentLength == 0)
		{
			// Processing when there is no data
			goto finish;
		}
		if (ptr == nullptr)
		{
			ptr = malloc(dataStatus.contentLength);
			if (ptr == nullptr){
				// Error handling
				goto error;
			}
			recvSize = BLOCKSIZE;
		}
		recvedSize += ret;
		ptr += ret;
	} while (recvedSize < dataStatus.contentLength);

*/



error:
	if (transId > 0) 
	{
		ret = sceNpLookupDestroyTransactionCtx(transId);
		printf("sceNpLookupDestroyTransactionCtx() done. ret = 0x%x\n", ret);
	}
	if (data != nullptr)
	{
		free(data);
	}

	sceNpTusTerm();

	return 0;
}

#endif