the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#ifdef __PS3__
2
3
4#include "stdafx.h"
5#include <libsn.h>
6#include <cell/cell_fs.h>
7#include <sys/vm.h>
8#include <sys/memory.h>
9#undef __in
10#undef __out
11#include <cell/atomic.h>
12#include <sysutil/sysutil_gamecontent.h>
13#include <np.h>
14#include <np/drm.h>
15#include <sysutil/sysutil_common.h>
16#include <sysutil/sysutil_sysparam.h>
17
18#include "ShutdownManager.h"
19
20
21static char dirName[CELL_GAME_PATH_MAX];
22static char contentInfoPath[CELL_GAME_PATH_MAX];
23static char usrdirPath[CELL_GAME_PATH_MAX];
24static char contentInfoPathBDPatch[CELL_GAME_PATH_MAX];
25static char usrdirPathBDPatch[CELL_GAME_PATH_MAX];
26//static char sc_loadPath[] = {"/app_home/"};
27//static char sc_loadPath[CELL_GAME_PATH_MAX];
28static int iFilesOpen=0;
29vector<int> vOpenFileHandles;
30
31namespace boost
32{
33 void assertion_failed(char const * expr,
34 char const * function, char const * file, long line)
35 {
36#ifndef _CONTENT_PACKAGE
37 printf("Assert failed!!!\n");
38 printf(expr);
39 printf("\n");
40 printf("----------------------\n %s failed. File %s at line %d \n----------------------\n", function, file, line);
41 snPause();
42#endif
43 } // user defined
44} // namespace boost
45
46 char* getConsoleHomePath()
47 {
48 return contentInfoPath;
49 }
50
51char* getUsrDirPath()
52{
53 return usrdirPath;
54}
55
56char* getConsoleHomePathBDPatch()
57{
58 return contentInfoPathBDPatch;
59}
60
61char* getUsrDirPathBDPatch()
62{
63 return usrdirPathBDPatch;
64}
65
66
67char* getDirName()
68{
69 return dirName;
70}
71
72int _wcsicmp( const wchar_t * dst, const wchar_t * src )
73{
74 wchar_t f,l;
75
76 // validation section
77 // _VALIDATE_RETURN(dst != NULL, EINVAL, _NLSCMPERROR);
78 // _VALIDATE_RETURN(src != NULL, EINVAL, _NLSCMPERROR);
79
80 do {
81 f = towlower(*dst);
82 l = towlower(*src);
83 dst++;
84 src++;
85 } while ( (f) && (f == l) );
86 return (int)(f - l);
87}
88
89size_t wcsnlen(const wchar_t *wcs, size_t maxsize)
90{
91 size_t n;
92
93// Note that we do not check if s == NULL, because we do not
94// return errno_t...
95
96 for (n = 0; n < maxsize && *wcs; n++, wcs++)
97 ;
98
99 return n;
100}
101
102Cnullptr nullptr;
103
104VOID GetSystemTime( LPSYSTEMTIME lpSystemTime)
105{
106 CellRtcDateTime dateTime;
107 int err = cellRtcGetCurrentClock(&dateTime, 0);
108 assert(err == CELL_OK);
109
110 lpSystemTime->wYear = cellRtcGetYear(&dateTime);
111 lpSystemTime->wMonth = cellRtcGetMonth(&dateTime);
112 lpSystemTime->wDay = cellRtcGetDay(&dateTime);
113 lpSystemTime->wDayOfWeek = cellRtcGetDayOfWeek(lpSystemTime->wYear, lpSystemTime->wMonth, lpSystemTime->wDay);
114 lpSystemTime->wHour = cellRtcGetHour(&dateTime);
115 lpSystemTime->wMinute = cellRtcGetMinute(&dateTime);
116 lpSystemTime->wSecond = cellRtcGetSecond(&dateTime);
117 lpSystemTime->wMilliseconds = cellRtcGetMicrosecond(&dateTime)/1000;
118}
119BOOL FileTimeToSystemTime(CONST FILETIME *lpFileTime, LPSYSTEMTIME lpSystemTime) { PS3_STUBBED; return false; }
120BOOL SystemTimeToFileTime(CONST SYSTEMTIME *lpSystemTime, LPFILETIME lpFileTime) { PS3_STUBBED; return false; }
121VOID GetLocalTime(LPSYSTEMTIME lpSystemTime)
122{
123 CellRtcDateTime dateTime;
124 int err = cellRtcGetCurrentClockLocalTime(&dateTime);
125 assert(err == CELL_OK);
126
127 lpSystemTime->wYear = cellRtcGetYear(&dateTime);
128 lpSystemTime->wMonth = cellRtcGetMonth(&dateTime);
129 lpSystemTime->wDay = cellRtcGetDay(&dateTime);
130 lpSystemTime->wDayOfWeek = cellRtcGetDayOfWeek(lpSystemTime->wYear, lpSystemTime->wMonth, lpSystemTime->wDay);
131 lpSystemTime->wHour = cellRtcGetHour(&dateTime);
132 lpSystemTime->wMinute = cellRtcGetMinute(&dateTime);
133 lpSystemTime->wSecond = cellRtcGetSecond(&dateTime);
134 lpSystemTime->wMilliseconds = cellRtcGetMicrosecond(&dateTime)/1000;
135}
136
137HANDLE CreateEvent(void* lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName) { PS3_STUBBED; return NULL; }
138VOID Sleep(DWORD dwMilliseconds)
139{
140 C4JThread::Sleep(dwMilliseconds);
141}
142
143BOOL SetThreadPriority(HANDLE hThread, int nPriority) { PS3_STUBBED; return FALSE; }
144DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds) { PS3_STUBBED; return false; }
145
146LONG InterlockedCompareExchangeRelease(LONG volatile *Destination, LONG Exchange,LONG Comperand )
147{
148 return cellAtomicCompareAndSwap32((uint32_t*)Destination, (uint32_t)Comperand, (uint32_t)Exchange);
149}
150
151LONG64 InterlockedCompareExchangeRelease64(LONG64 volatile *Destination, LONG64 Exchange, LONG64 Comperand)
152{
153 return cellAtomicCompareAndSwap64((uint64_t*)Destination, (uint64_t)Comperand, (uint64_t)Exchange);
154}
155
156
157VOID InitializeCriticalSection(PCRITICAL_SECTION CriticalSection)
158{
159 sys_lwmutex_attribute_t attr;
160 // from the defaults in sys_lwmutex_attribute_initialize
161 attr.attr_protocol = SYS_SYNC_PRIORITY;
162 attr.attr_recursive = SYS_SYNC_RECURSIVE;
163 attr.name[0] = '\0';
164
165 int err = sys_lwmutex_create(CriticalSection, &attr);
166 PS3_ASSERT_CELL_ERROR(err);
167}
168
169
170VOID InitializeCriticalSectionAndSpinCount(PCRITICAL_SECTION CriticalSection, ULONG SpinCount)
171{
172 // no spin count on PS3
173 InitializeCriticalSection(CriticalSection);
174}
175
176VOID DeleteCriticalSection(PCRITICAL_SECTION CriticalSection)
177{
178 int err = sys_lwmutex_destroy(CriticalSection);
179 PS3_ASSERT_CELL_ERROR(err);
180}
181
182extern CRITICAL_SECTION g_singleThreadCS;
183
184VOID EnterCriticalSection(PCRITICAL_SECTION CriticalSection)
185{
186// if(CriticalSection != &g_singleThreadCS &&(C4JThread::isMainThread() == false) )
187// LeaveCriticalSection(&g_singleThreadCS);
188 int err = sys_lwmutex_lock(CriticalSection, 0); // timeout, in microsecs - 0 here
189 PS3_ASSERT_CELL_ERROR(err);
190// if(CriticalSection != &g_singleThreadCS && !C4JThread::isMainThread())
191// EnterCriticalSection(&g_singleThreadCS);
192}
193
194
195VOID LeaveCriticalSection(PCRITICAL_SECTION CriticalSection)
196{
197 int err = sys_lwmutex_unlock(CriticalSection);
198 PS3_ASSERT_CELL_ERROR(err);
199}
200
201ULONG TryEnterCriticalSection(PCRITICAL_SECTION CriticalSection)
202{
203 int err = sys_lwmutex_trylock(CriticalSection);
204 if(err == CELL_OK)
205 return true;
206 return false;
207}
208DWORD WaitForMultipleObjects(DWORD nCount, CONST HANDLE *lpHandles,BOOL bWaitAll,DWORD dwMilliseconds) { PS3_STUBBED; return 0; }
209
210
211
212BOOL CloseHandle(HANDLE hObject)
213{
214 if(hObject==INVALID_HANDLE_VALUE)
215 {
216 //printf("\n\nTRYING TO CLOSE AN INVALID FILE HANDLE\n\n");
217 return false;
218 }
219 else
220 {
221 CellFsErrno err;
222 err=cellFsClose(int(hObject));
223 if(err==CELL_FS_SUCCEEDED)
224 {
225 iFilesOpen--;
226
227 AUTO_VAR(itEnd, vOpenFileHandles.end());
228 for (AUTO_VAR(it, vOpenFileHandles.begin()); it != itEnd; it++)
229 {
230 int iFH=(int)*it;
231 if(iFH==(int)hObject)
232 {
233 vOpenFileHandles.erase(it);
234 break;
235 }
236 }
237 //printf("\n\nFiles Open - %d\n\n",iFilesOpen);
238 return true;
239 }
240 else
241 {
242 return false;
243 }
244 }
245
246}
247
248BOOL SetEvent(HANDLE hEvent) { PS3_STUBBED; return false; }
249
250HMODULE GetModuleHandle(LPCSTR lpModuleName) { PS3_STUBBED; return 0; }
251
252sys_ppu_thread_t GetCurrentThreadId(VOID)
253{
254 sys_ppu_thread_t id;
255 int err = sys_ppu_thread_get_id(&id);
256 PS3_ASSERT_CELL_ERROR(err);
257 return id;
258}
259DWORD WaitForMultipleObjectsEx(DWORD nCount,CONST HANDLE *lpHandles,BOOL bWaitAll,DWORD dwMilliseconds,BOOL bAlertable ) { PS3_STUBBED; return 0; }
260BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode) { PS3_STUBBED; return FALSE; }
261
262DWORD TlsAlloc(VOID) { return TLSStoragePS3::Instance()->Alloc(); }
263BOOL TlsFree(DWORD dwTlsIndex) { return TLSStoragePS3::Instance()->Free(dwTlsIndex); }
264LPVOID TlsGetValue(DWORD dwTlsIndex) { return TLSStoragePS3::Instance()->GetValue(dwTlsIndex); }
265BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue) { return TLSStoragePS3::Instance()->SetValue(dwTlsIndex, lpTlsValue); }
266
267LPVOID VirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect)
268{
269 int err;
270 sys_addr_t newAddress = NULL;
271 if(lpAddress == NULL)
272 {
273 // reserve, and possibly commit also
274 int commitSize = 0;
275 if(flAllocationType == MEM_RESERVE)
276 commitSize = 1024*1024; // has to be a min of 1mb
277 else if(flAllocationType == MEM_COMMIT)
278 commitSize = dwSize;
279 else
280 {
281 PS3_ASSERT(0);
282 }
283 err = sys_vm_memory_map(dwSize, commitSize, SYS_MEMORY_CONTAINER_ID_INVALID,
284 SYS_MEMORY_PAGE_SIZE_64K, SYS_VM_POLICY_AUTO_RECOMMENDED, &newAddress);
285 PS3_ASSERT(err == CELL_OK);
286 }
287 else
288 {
289 // reserved already, so just commit
290 sys_vm_statistics_t stat;
291 err = sys_vm_get_statistics((sys_addr_t)lpAddress, &stat);
292 PS3_ASSERT(err == CELL_OK);
293 int memToAdd = dwSize - stat.pmem_total;
294
295 err = sys_vm_append_memory((sys_addr_t)lpAddress, memToAdd);
296 PS3_ASSERT(err == CELL_OK);
297 newAddress = (sys_addr_t)lpAddress;
298 }
299 return (LPVOID)newAddress;
300}
301
302BOOL VirtualFree(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType)
303{
304 if(dwFreeType == MEM_DECOMMIT)
305 {
306 int err;
307 sys_vm_statistics_t stat;
308 err = sys_vm_get_statistics((sys_addr_t)lpAddress, &stat);
309 PS3_ASSERT(err == CELL_OK);
310
311 // 4J Stu - We can only return what we have actually committed on PS3
312 // From PS3 Docs:
313 // The maximum amount of memory that can be returned is the difference of the total amount of physical memory used by the virtual memory area minus 1MB. When an amount exceeding this value is specified, EBUSY will return.
314 SIZE_T memToFree = stat.pmem_total - (1024 * 1024);
315 if(dwSize < memToFree)
316 memToFree = dwSize;
317
318 app.DebugPrintf("VirtualFree: Requested size - %d, Actual size - %d\n", dwSize, memToFree);
319 err = sys_vm_return_memory((sys_addr_t)lpAddress, memToFree);
320 PS3_ASSERT_CELL_ERROR(err);
321 return FALSE;
322 }
323 else
324 {
325 assert(dwFreeType == MEM_RELEASE);
326 assert(0); // not implemented yet
327 }
328 return TRUE;
329}
330
331DWORD GetFileSize( HANDLE hFile, LPDWORD lpFileSizeHigh )
332{
333 // check if the file exists first
334 //printf("GetFileSize\n");
335
336 CellFsStat statData;
337 if(cellFsFstat((int)hFile, &statData) != CELL_FS_SUCCEEDED)
338 return 0;
339 if(statData.st_mode == CELL_FS_S_IFDIR)
340 return 0;
341 //printf("+++GetFileSize - %ll\n",statData.st_size);
342
343 return statData.st_size;
344}
345BOOL GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize ) { PS3_STUBBED; return false; }
346BOOL WriteFile( HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped )
347{
348 int fd = (int)hFile;
349 uint64_t bytesWritten;
350 CellFsErrno err = cellFsWrite(fd, lpBuffer, nNumberOfBytesToWrite, &bytesWritten);
351 *lpNumberOfBytesWritten = (DWORD)bytesWritten;
352 return (err == CELL_FS_OK);
353}
354
355BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped )
356{
357 int fd = (int)hFile;
358 uint64_t bytesRead;
359 CellFsErrno err = cellFsRead(fd, lpBuffer, nNumberOfBytesToRead, &bytesRead);
360 *lpNumberOfBytesRead = (DWORD)bytesRead;
361
362 // fake a read error due to disc eject
363
364 //err=CELL_FS_EBADF;
365
366 switch(err)
367 {
368 case CELL_FS_EBADF: // disc eject
369 CloseHandle((HANDLE)fd);
370 // sys message will come in and flag to start a shutdown
371 //ShutdownManager::StartShutdown();
372 break;
373 default:
374 break;
375 }
376
377 return (err==CELL_FS_SUCCEEDED);
378}
379
380BOOL SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
381{
382 int fd = (int) hFile;
383 uint64_t pos = 0, bitsToMove = (int64_t) lDistanceToMove;
384
385 if (lpDistanceToMoveHigh != NULL)
386 bitsToMove |= ((uint64_t) (*lpDistanceToMoveHigh)) << 32;
387
388 int whence = 0;
389 switch(dwMoveMethod)
390 {
391 case FILE_BEGIN: whence = CELL_FS_SEEK_SET; break;
392 case FILE_CURRENT: whence = CELL_FS_SEEK_CUR; break;
393 case FILE_END: whence = CELL_FS_SEEK_END; break;
394 };
395
396 CellFsErrno err = cellFsLseek(fd, (int64_t) lDistanceToMove, whence, &pos);
397
398 return (err == CELL_FS_SUCCEEDED);
399}
400void replaceBackslashes(char* szFilename)
401{
402 int len = strlen(szFilename);
403 for(int i=0;i<len;i++)
404 {
405 if(szFilename[i] == '\\')
406 szFilename[i] = '/';
407 }
408}
409
410HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
411{
412 char filePath[256];
413 std::string mountedPath;
414
415 // 4J-PB - If we are running from the blu ray patch , then we need to check if we should load a file from the blu ray or the patch dir
416
417 if(app.GetBootedFromDiscPatch() && app.IsFileInPatchList(lpFileName))
418 {
419 // does this file need to be loaded from the patch directory?
420#ifndef _CONTENT_PACKAGE
421 printf("*** Found a patched file %s\n",lpFileName);
422#endif
423 char *pchPatchPath = app.GetDiscPatchUsrDir();
424 if(lpFileName[0] == '/') // already fully qualified path
425 strcpy(filePath, lpFileName );
426 else
427 sprintf(filePath,"%s/%s",pchPatchPath, lpFileName );
428 }
429 else
430 {
431 mountedPath = StorageManager.GetMountedPath(lpFileName);
432 if(mountedPath.length() > 0)
433 {
434 strcpy(filePath, mountedPath.c_str());
435 }
436 else if(lpFileName[0] == '/') // already fully qualified path
437 strcpy(filePath, lpFileName );
438 else
439 sprintf(filePath,"%s/%s",usrdirPath, lpFileName ); // set to load from host
440 }
441
442
443 replaceBackslashes(filePath);
444
445 int fd = 0;
446 int flags = 0;
447 switch(dwDesiredAccess)
448 {
449 case GENERIC_READ:
450 flags = CELL_FS_O_RDONLY; break;
451 case GENERIC_WRITE:
452 flags = CELL_FS_O_WRONLY; break;
453 default:
454 flags = CELL_FS_O_RDWR; break;
455 }
456
457 switch(dwCreationDisposition)
458 {
459 case CREATE_ALWAYS:
460 flags |= CELL_FS_O_CREAT; break;
461 case CREATE_NEW:
462 flags |= CELL_FS_O_EXCL; break;
463 case OPEN_ALWAYS:
464 flags |= CELL_FS_O_CREAT; break;
465 case OPEN_EXISTING:
466 break;
467 case TRUNCATE_EXISTING:
468 break;
469 }
470
471 CellFsErrno err;
472
473#ifndef _CONTENT_PACKAGE
474 printf("*** Opening %s\n",filePath);
475#endif
476
477 // check if it's a DRM edat file
478 int filePathLen = strlen(filePath);
479 if( (filePath[filePathLen-5] == '.' || filePath[filePathLen-4] == '.') &&
480 (filePath[filePathLen-4] == 'e' || filePath[filePathLen-4] == 'E') &&
481 (filePath[filePathLen-3] == 'd' || filePath[filePathLen-3] == 'D') &&
482 (filePath[filePathLen-2] == 'a' || filePath[filePathLen-2] == 'A') &&
483 (filePath[filePathLen-1] == 't' || filePath[filePathLen-1] == 'T') )
484 {
485 SceNpDrmOpenArg arg;
486 arg.flag = SCE_NP_DRM_OPEN_FLAG;
487 err = cellFsOpen(filePath, flags, &fd, &arg, sizeof(arg));
488 iFilesOpen++;
489 //printf("\n\nNPDRM Files Open - %d\n\n",iFilesOpen);
490 }
491 else
492 {
493 err = cellFsOpen(filePath, flags, &fd ,NULL, 0);
494 iFilesOpen++;
495 //printf("\n\nFiles Open - %d\n\n",iFilesOpen);
496 }
497 //PS3_ASSERT(err == CELL_FS_OK);
498
499 CellFsStat statData;
500
501 err = cellFsFstat(fd,&statData);
502
503 // fake a disc eject
504 //err=CELL_FS_EBADF;
505#ifndef _CONTENT_PACKAGE
506 printf("*** Open error %d\n",err);
507#endif
508 switch(err)
509 {
510 case CELL_FS_SUCCEEDED:
511 {
512 app.DebugPrintf("CELL_FS_SUCCEEDED\n");
513 DWORD dwFileSize = (DWORD)statData.st_size;
514
515 app.DebugPrintf("Filesize is %d\n", dwFileSize);
516
517 // 4J-PB - push the file handle on to a vector
518 vOpenFileHandles.push_back(fd);
519 }
520 break;
521 case CELL_FS_EBADF:
522 // fd is invalid or the file system on a removable media has been unmounted
523
524 // When cellFsFstat() returns CELL_FS_EBADF, it can be deduced that the above error occurred because a disc was ejected.
525 // Explicitly call cellFsClose() and close the applicable file. When using stream supporting APIs, call cellFsStReadFinish() before calling cellFsClose().
526
527 app.DebugPrintf("CELL_FS_EBADF\n");
528 CloseHandle((HANDLE)fd);
529
530 // sys message will come in to start shutdown
531 //ShutdownManager::StartShutdown();
532
533 return INVALID_HANDLE_VALUE;
534
535 case CELL_FS_EIO:
536 app.DebugPrintf("CELL_FS_EIO\n");
537 break;
538 case CELL_FS_ENOMEM:
539 app.DebugPrintf("CELL_FS_ENOMEM\n");
540 break;
541 case CELL_FS_EFSSPECIFIC:
542 app.DebugPrintf("CELL_FS_EFSSPECIFIC\n");
543 break;
544 case CELL_FS_EFAULT:
545 app.DebugPrintf("CELL_FS_EFAULT\n");
546 break;
547 }
548
549
550 return (void*)fd;
551}
552
553BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
554{
555 char filePath[256];
556 sprintf(filePath,"%s/%s",usrdirPath, lpPathName );
557 CellFsErrno err = cellFsMkdir(filePath, CELL_FS_DEFAULT_CREATE_MODE_1);
558 if(err == CELL_FS_SUCCEEDED)
559 return true;
560 //printf("cellFsMkdir failed with error 0x%08x\n", err);
561 return false;
562}
563
564BOOL DeleteFileA(LPCSTR lpFileName) { PS3_STUBBED; return false; }
565
566// BOOL XCloseHandle(HANDLE a)
567// {
568// cellFsClose(int(a));
569// }
570
571DWORD GetFileAttributesA(LPCSTR lpFileName)
572{
573 char filePath[256];
574 std::string mountedPath = StorageManager.GetMountedPath(lpFileName);
575 if(mountedPath.length() > 0)
576 {
577 strcpy(filePath, mountedPath.c_str());
578 }
579 else if(lpFileName[0] == '/') // already fully qualified path
580 strcpy(filePath, lpFileName );
581 else
582 sprintf(filePath,"%s/%s",usrdirPath, lpFileName ); // set to load from host
583
584 //strcat(filePath,".edat");
585
586 //printf("GetFileAttributesA - %s\n",filePath);
587
588 // check if the file exists first
589 CellFsStat statData;
590 if(cellFsStat(filePath, &statData) != CELL_FS_SUCCEEDED)
591 {
592 //printf("GetFileAttributesA FAIL\n");
593 return -1;
594 }
595 if( statData.st_mode & CELL_FS_S_IFDIR )
596 return FILE_ATTRIBUTE_DIRECTORY;
597 else
598 return FILE_ATTRIBUTE_NORMAL;
599}
600
601
602BOOL MoveFileA(LPCSTR lpExistingFileName, LPCSTR lpNewFileName) { PS3_STUBBED; return false; }
603
604void __debugbreak() { snPause(); }
605VOID DebugBreak(VOID) { snPause(); }
606
607
608DWORD GetLastError(VOID) { PS3_STUBBED; return 0; }
609VOID GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
610{
611 malloc_managed_size stat;
612 int err = malloc_stats(&stat);
613 if(err != 0)
614 {
615 //printf("Failed to get mem stats\n");
616 }
617
618 lpBuffer->dwTotalPhys = stat.max_system_size;
619 lpBuffer->dwAvailPhys = stat.max_system_size - stat.current_system_size;
620 lpBuffer->dwAvailVirtual = stat.max_system_size - stat.current_inuse_size;
621}
622
623DWORD GetTickCount()
624{
625 // This function returns the current system time at this function is called.
626 // The system time is represented the time elapsed since the system starts up in microseconds.
627 system_time_t sysTime = sys_time_get_system_time();
628 return sysTime / 1000;
629}
630
631// we should really use libperf for this kind of thing, but this will do for now.
632BOOL QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency)
633{
634 // microseconds
635 lpFrequency->QuadPart = (1000 * 1000);
636 return false;
637}
638BOOL QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount)
639{
640 sys_time_sec_t sec;
641 sys_time_nsec_t nsec;
642 sys_time_get_current_time(&sec, &nsec);
643 // microseconds
644 lpPerformanceCount->QuadPart = (sec * (1000 * 1000)) + (nsec / 1000);
645 return true;
646}
647
648#ifndef _FINAL_BUILD
649VOID OutputDebugStringW(LPCWSTR lpOutputString)
650{
651 wprintf(lpOutputString);
652}
653
654VOID OutputDebugString(LPCSTR lpOutputString)
655{
656 printf(lpOutputString);
657}
658
659VOID OutputDebugStringA(LPCSTR lpOutputString)
660{
661 printf(lpOutputString);
662}
663#endif // _CONTENT_PACKAGE
664
665BOOL GetFileAttributesExA(LPCSTR lpFileName,GET_FILEEX_INFO_LEVELS fInfoLevelId,LPVOID lpFileInformation)
666{
667 PS3_STUBBED;
668 return false;
669}
670HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData) { PS3_STUBBED; return 0;}
671BOOL FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData) { PS3_STUBBED; return false;}
672
673errno_t _itoa_s(int _Value, char * _DstBuf, size_t _Size, int _Radix) { if(_Radix==10) sprintf(_DstBuf,"%d",_Value); else if(_Radix==16) sprintf(_DstBuf,"%lx",_Value); else return -1; return 0; }
674errno_t _i64toa_s(__int64 _Val, char * _DstBuf, size_t _Size, int _Radix) { if(_Radix==10) sprintf(_DstBuf,"%lld",_Val); else return -1; return 0; }
675
676int _wtoi(const wchar_t *_Str)
677{
678 return wcstol(_Str, NULL, 10);
679}
680
681
682
683DWORD XGetLanguage()
684{
685 unsigned char ucLang = app.GetMinecraftLanguage(0);
686 int iLang;
687
688 // check if we should override the system language or not
689 if(ucLang==MINECRAFT_LANGUAGE_DEFAULT)
690 {
691 cellSysutilGetSystemParamInt(CELL_SYSUTIL_SYSTEMPARAM_ID_LANG,&iLang);
692 }
693 else
694 {
695 return (DWORD)ucLang;
696 }
697
698 switch(iLang)
699 {
700 case CELL_SYSUTIL_LANG_JAPANESE : return XC_LANGUAGE_JAPANESE;
701 case CELL_SYSUTIL_LANG_ENGLISH_US : return XC_LANGUAGE_ENGLISH;
702 case CELL_SYSUTIL_LANG_FRENCH : return XC_LANGUAGE_FRENCH;
703
704 case CELL_SYSUTIL_LANG_SPANISH :
705 if(app.IsAmericanSKU())
706 {
707 return XC_LANGUAGE_LATINAMERICANSPANISH;
708 }
709 else
710 {
711 return XC_LANGUAGE_SPANISH;
712 }
713
714 case CELL_SYSUTIL_LANG_GERMAN : return XC_LANGUAGE_GERMAN;
715 case CELL_SYSUTIL_LANG_ITALIAN : return XC_LANGUAGE_ITALIAN;
716 case CELL_SYSUTIL_LANG_PORTUGUESE_PT : return XC_LANGUAGE_PORTUGUESE;
717
718 case CELL_SYSUTIL_LANG_RUSSIAN : return XC_LANGUAGE_RUSSIAN;
719 case CELL_SYSUTIL_LANG_KOREAN : return XC_LANGUAGE_KOREAN;
720 case CELL_SYSUTIL_LANG_CHINESE_T : return XC_LANGUAGE_TCHINESE;
721 case CELL_SYSUTIL_LANG_PORTUGUESE_BR : return XC_LANGUAGE_PORTUGUESE;
722 case CELL_SYSUTIL_LANG_ENGLISH_GB : return XC_LANGUAGE_ENGLISH;
723
724 case CELL_SYSUTIL_LANG_DUTCH : return XC_LANGUAGE_DUTCH;
725 case CELL_SYSUTIL_LANG_FINNISH : return XC_LANGUAGE_FINISH;
726 case CELL_SYSUTIL_LANG_SWEDISH : return XC_LANGUAGE_SWEDISH;
727 case CELL_SYSUTIL_LANG_DANISH : return XC_LANGUAGE_DANISH;
728 case CELL_SYSUTIL_LANG_NORWEGIAN : return XC_LANGUAGE_BNORWEGIAN;
729 case CELL_SYSUTIL_LANG_POLISH : return XC_LANGUAGE_POLISH;
730 case CELL_SYSUTIL_LANG_TURKISH : return XC_LANGUAGE_TURKISH;
731
732
733 case CELL_SYSUTIL_LANG_CHINESE_S : return XC_LANGUAGE_SCHINESE;
734 default : return XC_LANGUAGE_ENGLISH;
735 }
736
737}
738DWORD XGetLocale()
739{
740 int iLang;
741 cellSysutilGetSystemParamInt(CELL_SYSUTIL_SYSTEMPARAM_ID_LANG,&iLang);
742 switch(iLang)
743 {
744 case CELL_SYSUTIL_LANG_JAPANESE : return XC_LOCALE_JAPAN;
745 case CELL_SYSUTIL_LANG_ENGLISH_US : return XC_LOCALE_UNITED_STATES;
746 case CELL_SYSUTIL_LANG_FRENCH : return XC_LOCALE_FRANCE;
747
748 case CELL_SYSUTIL_LANG_SPANISH :
749 if(app.IsAmericanSKU())
750 {
751 return XC_LOCALE_LATIN_AMERICA;
752 }
753 else
754 {
755 return XC_LOCALE_SPAIN;
756 }
757 return XC_LOCALE_SPAIN;
758
759 case CELL_SYSUTIL_LANG_GERMAN : return XC_LOCALE_GERMANY;
760 case CELL_SYSUTIL_LANG_ITALIAN : return XC_LOCALE_ITALY;
761 case CELL_SYSUTIL_LANG_PORTUGUESE_PT : return XC_LOCALE_PORTUGAL;
762
763 case CELL_SYSUTIL_LANG_RUSSIAN : return XC_LOCALE_RUSSIAN_FEDERATION;
764 case CELL_SYSUTIL_LANG_KOREAN : return XC_LOCALE_KOREA;
765 case CELL_SYSUTIL_LANG_CHINESE_T : return XC_LOCALE_CHINA;
766 case CELL_SYSUTIL_LANG_PORTUGUESE_BR : return XC_LOCALE_BRAZIL;
767 case CELL_SYSUTIL_LANG_ENGLISH_GB : return XC_LOCALE_GREAT_BRITAIN;
768
769 case CELL_SYSUTIL_LANG_DUTCH : return XC_LOCALE_NETHERLANDS;
770 case CELL_SYSUTIL_LANG_FINNISH : return XC_LOCALE_FINLAND;
771 case CELL_SYSUTIL_LANG_SWEDISH : return XC_LOCALE_SWEDEN;
772 case CELL_SYSUTIL_LANG_DANISH : return XC_LOCALE_DENMARK;
773 case CELL_SYSUTIL_LANG_NORWEGIAN : return XC_LOCALE_NORWAY;
774 case CELL_SYSUTIL_LANG_POLISH : return XC_LOCALE_POLAND;
775 case CELL_SYSUTIL_LANG_TURKISH : return XC_LOCALE_TURKEY;
776
777
778 case CELL_SYSUTIL_LANG_CHINESE_S : return XC_LOCALE_CHINA;
779 default : return XC_LOCALE_UNITED_STATES;
780 }
781}
782DWORD XEnableGuestSignin(BOOL fEnable)
783{
784 return 0;
785}
786
787#endif // __PS3__
788