-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils.c
135 lines (118 loc) · 2.39 KB
/
utils.c
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
#include <pspsdk.h>
#include <pspkernel.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <pspreg.h>
#include <psprtc.h>
#include "main.h"
int GetRegistryValue(const char *dir, const char *name, void *buf, int bufsize, int inttype)
{
int ret = 0;
struct RegParam reg;
REGHANDLE h;
memset(®, 0, sizeof(reg));
reg.regtype = 1;
reg.namelen = strlen("/system");
reg.unk2 = 1;
reg.unk3 = 1;
strcpy(reg.name, "/system");
if(sceRegOpenRegistry(®, 2, &h) == 0)
{
REGHANDLE hd;
if(!sceRegOpenCategory(h, dir, 2, &hd))
{
REGHANDLE hk;
unsigned int type, size;
if(!sceRegGetKeyInfo(hd, name, &hk, &type, &size))
if(!sceRegGetKeyValue(hd, hk, buf, bufsize))
{
ret = inttype ? 1 : (int)buf;
sceRegFlushCategory(hd);
}
sceRegCloseCategory(hd);
}
sceRegFlushRegistry(h);
sceRegCloseRegistry(h);
}
return ret;
}
int Random(int min, int max)
{
u64 tick;
SceKernelUtilsMt19937Context ctx;
sceRtcGetCurrentTick(&tick);
sceKernelUtilsMt19937Init(&ctx, (u32)tick);
return min + (sceKernelUtilsMt19937UInt(&ctx) % max);
}
int utf82unicode(wchar_t *dest, char *src)
{
int i, x;
unsigned char *usrc = (unsigned char *)src;
for(i = 0, x = 0; usrc[i];)
{
wchar_t ch;
if((usrc[i] & 0xE0) == 0xE0)
{
ch = ((usrc[i] & 0x0F) << 12) | ((usrc[i + 1] & 0x3F) << 6) | (usrc[i + 2] & 0x3F);
i += 3;
}
else if((usrc[i] & 0xC0) == 0xC0)
{
ch = ((usrc[i] & 0x1F) << 6) | (usrc[i+1] & 0x3F);
i += 2;
}
else
{
ch = usrc[i];
i += 1;
}
dest[x++] = ch;
}
dest[x++] = '\0';
return x;
}
void ascii2unicode(char *unicode, const char *ascii)
{
while(*ascii != '\0')
{
if((unsigned char)*ascii >= 0xC0)
{
*unicode++ = (unsigned char)*ascii - 0xB0;
*unicode++ = 0x04;
}
else if((unsigned char)*ascii == 0x99)
{
*unicode++ = 0x22;
*unicode++ = 0x21;
}
else if((unsigned char)*ascii == 0xB8)
{
*unicode++ = 0x51;
*unicode++ = 0x04;
}
else if((unsigned char)*ascii == 0xA8)
{
*unicode++ = 0x01;
*unicode++ = 0x04;
}
else
{
*unicode++ = *ascii;
*unicode++ = '\0';
}
ascii++;
}
*unicode++ = '\0';
*unicode++ = '\0';
}
VlfText pspEverestPrintf(int x, int y, const char *text, ...)
{
char ascii[256], unicode[256];
va_list list;
va_start(list, text);
vsprintf(ascii, text, list);
va_end(list);
ascii2unicode(unicode, ascii);
return vlfGuiAddTextW(x, y, (u16 *)unicode);
}